Index: trunk/phase3/docs/hooks.txt |
— | — | @@ -596,10 +596,11 @@ |
597 | 597 | 'BeforeParserFetchFileAndTitle': before an image is rendered by Parser |
598 | 598 | $parser: Parser object |
599 | 599 | $nt: the image title |
600 | | -&$time: the image timestamp (use '0' to force a broken thumbnail) |
601 | | -&$sha1: image base 36 sha1 (used to specify the file, $nt will be ignored if this is set) |
| 600 | +&$options: array of options to RepoGroup::findFile |
602 | 601 | &$descQuery: query string to add to thumbnail URL |
603 | 602 | |
| 603 | +If 'broken' is a key in $options then the file will appear as a broken thumbnail. |
| 604 | + |
604 | 605 | 'BeforeParserFetchTemplateAndtitle': before a template is fetched by Parser |
605 | 606 | $parser: Parser object |
606 | 607 | $title: title of the template |
Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -2067,11 +2067,12 @@ |
2068 | 2068 | if ( $ns == NS_MEDIA ) { |
2069 | 2069 | wfProfileIn( __METHOD__."-media" ); |
2070 | 2070 | # Give extensions a chance to select the file revision for us |
2071 | | - $time = $sha1 = $descQuery = false; |
| 2071 | + $options = array(); |
| 2072 | + $descQuery = false; |
2072 | 2073 | wfRunHooks( 'BeforeParserFetchFileAndTitle', |
2073 | | - array( $this, $nt, &$time, &$sha1, &$descQuery ) ); |
| 2074 | + array( $this, $nt, &$options, &$descQuery ) ); |
2074 | 2075 | # Fetch and register the file (file title may be different via hooks) |
2075 | | - list( $file, $nt ) = $this->fetchFileAndTitle( $nt, $time, $sha1 ); |
| 2076 | + list( $file, $nt ) = $this->fetchFileAndTitle( $nt, $options ); |
2076 | 2077 | # Cloak with NOPARSE to avoid replacement in replaceExternalLinks |
2077 | 2078 | $s .= $prefix . $this->armorLinks( |
2078 | 2079 | Linker::makeMediaLinkFile( $nt, $file, $text ) ) . $trail; |
— | — | @@ -3641,30 +3642,30 @@ |
3642 | 3643 | |
3643 | 3644 | /** |
3644 | 3645 | * Fetch a file and its title and register a reference to it. |
| 3646 | + * If 'broken' is a key in $options then the file will appear as a broken thumbnail. |
3645 | 3647 | * @param Title $title |
3646 | | - * @param string $time MW timestamp |
3647 | | - * @param string $sha1 base 36 SHA-1 |
| 3648 | + * @param Array $options Array of options to RepoGroup::findFile |
3648 | 3649 | * @return File|false |
3649 | 3650 | */ |
3650 | | - function fetchFile( $title, $time = false, $sha1 = false ) { |
3651 | | - $res = $this->fetchFileAndTitle( $title, $time, $sha1 ); |
| 3651 | + function fetchFile( $title, $options = array() ) { |
| 3652 | + $res = $this->fetchFileAndTitle( $title, $options ); |
3652 | 3653 | return $res[0]; |
3653 | 3654 | } |
3654 | 3655 | |
3655 | 3656 | /** |
3656 | 3657 | * Fetch a file and its title and register a reference to it. |
| 3658 | + * If 'broken' is a key in $options then the file will appear as a broken thumbnail. |
3657 | 3659 | * @param Title $title |
3658 | | - * @param string $time MW timestamp |
3659 | | - * @param string $sha1 base 36 SHA-1 |
| 3660 | + * @param Array $options Array of options to RepoGroup::findFile |
3660 | 3661 | * @return Array ( File or false, Title of file ) |
3661 | 3662 | */ |
3662 | | - function fetchFileAndTitle( $title, $time = false, $sha1 = false ) { |
3663 | | - if ( $time === '0' ) { |
| 3663 | + function fetchFileAndTitle( $title, $options = array() ) { |
| 3664 | + if ( isset( $options['broken'] ) ) { |
3664 | 3665 | $file = false; // broken thumbnail forced by hook |
3665 | | - } elseif ( $sha1 ) { // get by (sha1,timestamp) |
3666 | | - $file = RepoGroup::singleton()->findFileFromKey( $sha1, array( 'time' => $time ) ); |
| 3666 | + } elseif ( isset( $options['sha1'] ) ) { // get by (sha1,timestamp) |
| 3667 | + $file = RepoGroup::singleton()->findFileFromKey( $options['sha1'], $options ); |
3667 | 3668 | } else { // get by (name,timestamp) |
3668 | | - $file = wfFindFile( $title, array( 'time' => $time ) ); |
| 3669 | + $file = wfFindFile( $title, $options ); |
3669 | 3670 | } |
3670 | 3671 | $time = $file ? $file->getTimestamp() : false; |
3671 | 3672 | $sha1 = $file ? $file->getSha1() : false; |
— | — | @@ -5010,11 +5011,12 @@ |
5011 | 5012 | $parts = StringUtils::explode( "|", $options ); |
5012 | 5013 | |
5013 | 5014 | # Give extensions a chance to select the file revision for us |
5014 | | - $time = $sha1 = $descQuery = false; |
| 5015 | + $options = array(); |
| 5016 | + $descQuery = false; |
5015 | 5017 | wfRunHooks( 'BeforeParserFetchFileAndTitle', |
5016 | | - array( $this, $title, &$time, &$sha1, &$descQuery ) ); |
| 5018 | + array( $this, $title, &$options, &$descQuery ) ); |
5017 | 5019 | # Fetch and register the file (file title may be different via hooks) |
5018 | | - list( $file, $title ) = $this->fetchFileAndTitle( $title, $time, $sha1 ); |
| 5020 | + list( $file, $title ) = $this->fetchFileAndTitle( $title, $options ); |
5019 | 5021 | |
5020 | 5022 | # Get parameter map |
5021 | 5023 | $handler = $file ? $file->getHandler() : false; |
— | — | @@ -5174,6 +5176,7 @@ |
5175 | 5177 | wfRunHooks( 'ParserMakeImageParams', array( $title, $file, &$params ) ); |
5176 | 5178 | |
5177 | 5179 | # Linker does the rest |
| 5180 | + $time = isset( $options['time'] ) ? $options['time'] : false; |
5178 | 5181 | $ret = Linker::makeImageLink2( $title, $file, $params['frame'], $params['handler'], |
5179 | 5182 | $time, $descQuery, $this->mOptions->getThumbSize() ); |
5180 | 5183 | |
Index: trunk/phase3/includes/ImageGallery.php |
— | — | @@ -249,11 +249,11 @@ |
250 | 250 | # Get the file... |
251 | 251 | if ( $this->mParser instanceof Parser ) { |
252 | 252 | # Give extensions a chance to select the file revision for us |
253 | | - $time = $sha1 = false; |
| 253 | + $options = array(); |
254 | 254 | wfRunHooks( 'BeforeParserFetchFileAndTitle', |
255 | | - array( $this->mParser, $nt, &$time, &$sha1, &$descQuery ) ); |
| 255 | + array( $this->mParser, $nt, &$options, &$descQuery ) ); |
256 | 256 | # Fetch and register the file (file title may be different via hooks) |
257 | | - list( $img, $nt ) = $this->mParser->fetchFileAndTitle( $nt, $time, $sha1 ); |
| 257 | + list( $img, $nt ) = $this->mParser->fetchFileAndTitle( $nt, $options ); |
258 | 258 | } else { |
259 | 259 | $img = wfFindFile( $nt ); |
260 | 260 | } |
Index: trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevs.hooks.php |
— | — | @@ -180,7 +180,7 @@ |
181 | 181 | /** |
182 | 182 | * Select the desired images based on the selected stable version time/SHA-1 |
183 | 183 | */ |
184 | | - public static function parserFetchStableFile( $parser, Title $title, &$time, &$sha1, &$query ) { |
| 184 | + public static function parserFetchStableFile( $parser, Title $title, &$options, &$query ) { |
185 | 185 | if ( !( $parser instanceof Parser ) ) { |
186 | 186 | return true; // nothing to do |
187 | 187 | } |
— | — | @@ -216,6 +216,12 @@ |
217 | 217 | if ( $query != '' ) $query .= '&'; |
218 | 218 | $query = "filetimestamp=" . urlencode( wfTimestamp( TS_MW, $time ) ); |
219 | 219 | } |
| 220 | + $options['time'] = $time; |
| 221 | + $options['sha1'] = $sha1; |
| 222 | + if ( $time === '0' ) { |
| 223 | + $options['broken'] = true; |
| 224 | + } |
| 225 | + |
220 | 226 | return true; |
221 | 227 | } |
222 | 228 | |