Cleanup to r84610 per CR: changed BeforeParserMakeImageLinkObj hook to use a RepoGrou...
authorAaron Schulz <aaron@users.mediawiki.org>
Tue, 6 Sep 2011 18:11:53 +0000 (18:11 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Tue, 6 Sep 2011 18:11:53 +0000 (18:11 +0000)
docs/hooks.txt
includes/ImageGallery.php
includes/parser/Parser.php

index 9877950..c2a5f6d 100644 (file)
@@ -596,10 +596,11 @@ $mediaWiki: Mediawiki object
 'BeforeParserFetchFileAndTitle': before an image is rendered by Parser
 $parser: Parser object
 $nt: the image title
-&$time: the image timestamp (use '0' to force a broken thumbnail)
-&$sha1: image base 36 sha1 (used to specify the file, $nt will be ignored if this is set)
+&$options: array of options to RepoGroup::findFile
 &$descQuery: query string to add to thumbnail URL
 
+If 'broken' is a key in $options then the file will appear as a broken thumbnail.
+
 'BeforeParserFetchTemplateAndtitle': before a template is fetched by Parser
 $parser: Parser object
 $title: title of the template
index 8d3b6d6..a40a685 100644 (file)
@@ -249,11 +249,11 @@ class ImageGallery {
                                # Get the file...
                                if ( $this->mParser instanceof Parser ) {
                                        # Give extensions a chance to select the file revision for us
-                                       $time = $sha1 = false;
+                                       $options = array();
                                        wfRunHooks( 'BeforeParserFetchFileAndTitle',
-                                               array( $this->mParser, $nt, &$time, &$sha1, &$descQuery ) );
+                                               array( $this->mParser, $nt, &$options, &$descQuery ) );
                                        # Fetch and register the file (file title may be different via hooks)
-                                       list( $img, $nt ) = $this->mParser->fetchFileAndTitle( $nt, $time, $sha1 );
+                                       list( $img, $nt ) = $this->mParser->fetchFileAndTitle( $nt, $options );
                                } else {
                                        $img = wfFindFile( $nt );
                                }
index 6ff1e44..2e8a07d 100644 (file)
@@ -2067,11 +2067,12 @@ class Parser {
                        if ( $ns == NS_MEDIA ) {
                                wfProfileIn( __METHOD__."-media" );
                                # Give extensions a chance to select the file revision for us
-                               $time = $sha1 = $descQuery = false;
+                               $options = array();
+                               $descQuery = false;
                                wfRunHooks( 'BeforeParserFetchFileAndTitle',
-                                       array( $this, $nt, &$time, &$sha1, &$descQuery ) );
+                                       array( $this, $nt, &$options, &$descQuery ) );
                                # Fetch and register the file (file title may be different via hooks)
-                               list( $file, $nt ) = $this->fetchFileAndTitle( $nt, $time, $sha1 );
+                               list( $file, $nt ) = $this->fetchFileAndTitle( $nt, $options );
                                # Cloak with NOPARSE to avoid replacement in replaceExternalLinks
                                $s .= $prefix . $this->armorLinks(
                                        Linker::makeMediaLinkFile( $nt, $file, $text ) ) . $trail;
@@ -3641,30 +3642,30 @@ class Parser {
 
        /**
         * Fetch a file and its title and register a reference to it.
+        * If 'broken' is a key in $options then the file will appear as a broken thumbnail.
         * @param Title $title
-        * @param string $time MW timestamp
-        * @param string $sha1 base 36 SHA-1
+        * @param Array $options Array of options to RepoGroup::findFile
         * @return File|false
         */
-       function fetchFile( $title, $time = false, $sha1 = false ) {
-               $res = $this->fetchFileAndTitle( $title, $time, $sha1 );
+       function fetchFile( $title, $options = array() ) {
+               $res = $this->fetchFileAndTitle( $title, $options );
                return $res[0];
        }
 
        /**
         * Fetch a file and its title and register a reference to it.
+        * If 'broken' is a key in $options then the file will appear as a broken thumbnail.
         * @param Title $title
-        * @param string $time MW timestamp
-        * @param string $sha1 base 36 SHA-1
+        * @param Array $options Array of options to RepoGroup::findFile
         * @return Array ( File or false, Title of file )
         */
-       function fetchFileAndTitle( $title, $time = false, $sha1 = false ) {
-               if ( $time === '0' ) {
+       function fetchFileAndTitle( $title, $options = array() ) {
+               if ( isset( $options['broken'] ) ) {
                        $file = false; // broken thumbnail forced by hook
-               } elseif ( $sha1 ) { // get by (sha1,timestamp)
-                       $file = RepoGroup::singleton()->findFileFromKey( $sha1, array( 'time' => $time ) );
+               } elseif ( isset( $options['sha1'] ) ) { // get by (sha1,timestamp)
+                       $file = RepoGroup::singleton()->findFileFromKey( $options['sha1'], $options );
                } else { // get by (name,timestamp)
-                       $file = wfFindFile( $title, array( 'time' => $time ) );
+                       $file = wfFindFile( $title, $options );
                }
                $time = $file ? $file->getTimestamp() : false;
                $sha1 = $file ? $file->getSha1() : false;
@@ -5010,11 +5011,12 @@ class Parser {
                $parts = StringUtils::explode( "|", $options );
 
                # Give extensions a chance to select the file revision for us
-               $time = $sha1 = $descQuery = false;
+               $options = array();
+               $descQuery = false;
                wfRunHooks( 'BeforeParserFetchFileAndTitle',
-                       array( $this, $title, &$time, &$sha1, &$descQuery ) );
+                       array( $this, $title, &$options, &$descQuery ) );
                # Fetch and register the file (file title may be different via hooks)
-               list( $file, $title ) = $this->fetchFileAndTitle( $title, $time, $sha1 );
+               list( $file, $title ) = $this->fetchFileAndTitle( $title, $options );
 
                # Get parameter map
                $handler = $file ? $file->getHandler() : false;
@@ -5174,6 +5176,7 @@ class Parser {
                wfRunHooks( 'ParserMakeImageParams', array( $title, $file, &$params ) );
 
                # Linker does the rest
+               $time = isset( $options['time'] ) ? $options['time'] : false;
                $ret = Linker::makeImageLink2( $title, $file, $params['frame'], $params['handler'],
                        $time, $descQuery, $this->mOptions->getThumbSize() );