Fix NS_MEDIA link handling
authorAaron Schulz <aaron@users.mediawiki.org>
Sat, 19 Apr 2008 21:29:19 +0000 (21:29 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Sat, 19 Apr 2008 21:29:19 +0000 (21:29 +0000)
includes/Linker.php
includes/Parser.php

index acaaf07..037d12c 100644 (file)
@@ -755,27 +755,28 @@ class Linker {
        }
 
        /** @deprecated use Linker::makeMediaLinkObj() */
-       function makeMediaLink( $name, $unused = '', $text = '' ) {
+       function makeMediaLink( $name, $unused = '', $text = '', $time = false ) {
                $nt = Title::makeTitleSafe( NS_IMAGE, $name );
-               return $this->makeMediaLinkObj( $nt, $text );
+               return $this->makeMediaLinkObj( $nt, $text, $time );
        }
 
        /**
         * Create a direct link to a given uploaded file.
         *
         * @param $title Title object.
-        * @param $text  String: pre-sanitized HTML
+        * @param $text String: pre-sanitized HTML
+        * @param $time string: time image was created
         * @return string HTML
         *
         * @public
         * @todo Handle invalid or missing images better.
         */
-       function makeMediaLinkObj( $title, $text = '' ) {
+       function makeMediaLinkObj( $title, $text = '', $time = false ) {
                if( is_null( $title ) ) {
                        ### HOTFIX. Instead of breaking, return empty string.
                        return $text;
                } else {
-                       $img  = wfFindFile( $title );
+                       $img  = wfFindFile( $title, $time );
                        if( $img ) {
                                $url  = $img->getURL();
                                $class = 'internal';
index 28619e8..4d2bd38 100644 (file)
@@ -1755,7 +1755,14 @@ class Parser
 
                        # Special and Media are pseudo-namespaces; no pages actually exist in them
                        if( $ns == NS_MEDIA ) {
-                               $link = $sk->makeMediaLinkObj( $nt, $text );
+                               # Give extensions a chance to select the file revision for us
+                               $skip = $time = false;
+                               wfRunHooks( 'BeforeParserMakeImageLinkObj', array( &$this, &$nt, &$skip, &$time ) );
+                               if ( $skip ) {
+                                       $link = $sk->makeLinkObj( $nt );
+                               } else {
+                                       $link = $sk->makeMediaLinkObj( $nt, $text, $time );
+                               }
                                # Cloak with NOPARSE to avoid replacement in replaceExternalLinks
                                $s .= $prefix . $this->armorLinks( $link ) . $trail;
                                $this->mOutput->addImage( $nt->getDBkey() );