r96357 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96356‎ | r96357 | r96358 >
Date:18:11, 6 September 2011
Author:aaron
Status:ok
Tags:
Comment:
Cleanup to r84610 per CR: changed BeforeParserMakeImageLinkObj hook to use a RepoGroup style param array that also excepts a 'broken' parameter. This new parameter replaces the odd "use timestamp '0' to make a broken thumbnail' convention. No other callers are using this hook other than FR, so the old time/sha1 params where removed.
Modified paths:
  • /trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevs.hooks.php (modified) (history)
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/ImageGallery.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/hooks.txt
@@ -596,10 +596,11 @@
597597 'BeforeParserFetchFileAndTitle': before an image is rendered by Parser
598598 $parser: Parser object
599599 $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
602601 &$descQuery: query string to add to thumbnail URL
603602
 603+If 'broken' is a key in $options then the file will appear as a broken thumbnail.
 604+
604605 'BeforeParserFetchTemplateAndtitle': before a template is fetched by Parser
605606 $parser: Parser object
606607 $title: title of the template
Index: trunk/phase3/includes/parser/Parser.php
@@ -2067,11 +2067,12 @@
20682068 if ( $ns == NS_MEDIA ) {
20692069 wfProfileIn( __METHOD__."-media" );
20702070 # Give extensions a chance to select the file revision for us
2071 - $time = $sha1 = $descQuery = false;
 2071+ $options = array();
 2072+ $descQuery = false;
20722073 wfRunHooks( 'BeforeParserFetchFileAndTitle',
2073 - array( $this, $nt, &$time, &$sha1, &$descQuery ) );
 2074+ array( $this, $nt, &$options, &$descQuery ) );
20742075 # 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 );
20762077 # Cloak with NOPARSE to avoid replacement in replaceExternalLinks
20772078 $s .= $prefix . $this->armorLinks(
20782079 Linker::makeMediaLinkFile( $nt, $file, $text ) ) . $trail;
@@ -3641,30 +3642,30 @@
36423643
36433644 /**
36443645 * 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.
36453647 * @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
36483649 * @return File|false
36493650 */
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 );
36523653 return $res[0];
36533654 }
36543655
36553656 /**
36563657 * 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.
36573659 * @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
36603661 * @return Array ( File or false, Title of file )
36613662 */
3662 - function fetchFileAndTitle( $title, $time = false, $sha1 = false ) {
3663 - if ( $time === '0' ) {
 3663+ function fetchFileAndTitle( $title, $options = array() ) {
 3664+ if ( isset( $options['broken'] ) ) {
36643665 $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 );
36673668 } else { // get by (name,timestamp)
3668 - $file = wfFindFile( $title, array( 'time' => $time ) );
 3669+ $file = wfFindFile( $title, $options );
36693670 }
36703671 $time = $file ? $file->getTimestamp() : false;
36713672 $sha1 = $file ? $file->getSha1() : false;
@@ -5010,11 +5011,12 @@
50115012 $parts = StringUtils::explode( "|", $options );
50125013
50135014 # Give extensions a chance to select the file revision for us
5014 - $time = $sha1 = $descQuery = false;
 5015+ $options = array();
 5016+ $descQuery = false;
50155017 wfRunHooks( 'BeforeParserFetchFileAndTitle',
5016 - array( $this, $title, &$time, &$sha1, &$descQuery ) );
 5018+ array( $this, $title, &$options, &$descQuery ) );
50175019 # 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 );
50195021
50205022 # Get parameter map
50215023 $handler = $file ? $file->getHandler() : false;
@@ -5174,6 +5176,7 @@
51755177 wfRunHooks( 'ParserMakeImageParams', array( $title, $file, &$params ) );
51765178
51775179 # Linker does the rest
 5180+ $time = isset( $options['time'] ) ? $options['time'] : false;
51785181 $ret = Linker::makeImageLink2( $title, $file, $params['frame'], $params['handler'],
51795182 $time, $descQuery, $this->mOptions->getThumbSize() );
51805183
Index: trunk/phase3/includes/ImageGallery.php
@@ -249,11 +249,11 @@
250250 # Get the file...
251251 if ( $this->mParser instanceof Parser ) {
252252 # Give extensions a chance to select the file revision for us
253 - $time = $sha1 = false;
 253+ $options = array();
254254 wfRunHooks( 'BeforeParserFetchFileAndTitle',
255 - array( $this->mParser, $nt, &$time, &$sha1, &$descQuery ) );
 255+ array( $this->mParser, $nt, &$options, &$descQuery ) );
256256 # 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 );
258258 } else {
259259 $img = wfFindFile( $nt );
260260 }
Index: trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevs.hooks.php
@@ -180,7 +180,7 @@
181181 /**
182182 * Select the desired images based on the selected stable version time/SHA-1
183183 */
184 - public static function parserFetchStableFile( $parser, Title $title, &$time, &$sha1, &$query ) {
 184+ public static function parserFetchStableFile( $parser, Title $title, &$options, &$query ) {
185185 if ( !( $parser instanceof Parser ) ) {
186186 return true; // nothing to do
187187 }
@@ -216,6 +216,12 @@
217217 if ( $query != '' ) $query .= '&';
218218 $query = "filetimestamp=" . urlencode( wfTimestamp( TS_MW, $time ) );
219219 }
 220+ $options['time'] = $time;
 221+ $options['sha1'] = $sha1;
 222+ if ( $time === '0' ) {
 223+ $options['broken'] = true;
 224+ }
 225+
220226 return true;
221227 }
222228

Follow-up revisions

RevisionCommit summaryAuthorDate
r112282Fixes to parserFetchStableFile() hook:...aaron01:13, 24 February 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r84610* Put parser output file version tracking to core...aaron17:35, 23 March 2011

Status & tagging log