r84849 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84848‎ | r84849 | r84850 >
Date:14:57, 27 March 2011
Author:aaron
Status:ok
Tags:
Comment:
* Removed fr_includeErrors from parser output
* Merged in helper function for parserFetchStableFile(), which no longer had two callers
* Minor code cleanups
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.class.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -434,7 +434,6 @@
435435
436436 # ######## Parser #########
437437 # Parser hooks, selects the desired images/templates
438 -$wgHooks['ParserClearState'][] = 'FlaggedRevsHooks::parserAddFields';
439438 $wgHooks['BeforeParserFetchTemplateAndtitle'][] = 'FlaggedRevsHooks::parserFetchStableTemplate';
440439 $wgHooks['BeforeParserFetchFileAndTitle'][] = 'FlaggedRevsHooks::parserFetchStableFile';
441440 # ########
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php
@@ -476,11 +476,11 @@
477477 # ################ Parsing functions #################
478478
479479 /**
480 - * All included pages/arguments are expanded out
 480+ * All templates and arguments in $text are expanded out
481481 * @param Title $title
482 - * @param string $text
 482+ * @param string $text wikitext
483483 * @param int $id Source revision Id
484 - * @return array( string, array, array )
 484+ * @return array( string wikitext, array of template versions )
485485 */
486486 public static function expandText( Title $title, $text, $id ) {
487487 global $wgParser;
@@ -500,13 +500,13 @@
501501 }
502502 $options = self::makeParserOptions(); // default options
503503 $outputText = $wgParser->preprocess( $text, $title, $options, $id );
504 - $out = $wgParser->mOutput;
 504+ $pOutput = $wgParser->getOutput();
505505 # Stable parse done!
506506 if ( $resetManager ) {
507507 $incManager->clear(); // reset the FRInclusionManager as needed
508508 }
509509 # Return data array
510 - return array( $outputText, $out->mTemplateIds, $out->fr_includeErrors );
 510+ return array( $outputText, $pOutput->getTemplateIds() );
511511 }
512512
513513 /**
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php
@@ -285,14 +285,6 @@
286286 }
287287
288288 /**
289 - * Add special fields to parser.
290 - */
291 - public static function parserAddFields( Parser $parser ) {
292 - $parser->getOutput()->fr_includeErrors = array();
293 - return true;
294 - }
295 -
296 - /**
297289 * Select the desired templates based on the selected stable revision IDs
298290 * Note: $parser can be false
299291 */
@@ -305,12 +297,12 @@
306298 return true; // trigger for stable version parsing only
307299 }
308300 $id = false; // current
309 - # Check for the version of this template used when reviewed.
 301+ # Check for the version of this template used when reviewed...
310302 $maybeId = $incManager->getReviewedTemplateVersion( $title );
311303 if ( $maybeId !== null ) {
312304 $id = (int)$maybeId; // use if specified (even 0)
313305 }
314 - # Check for stable version of template if this feature is enabled.
 306+ # Check for stable version of template if this feature is enabled...
315307 if ( FlaggedRevs::inclusionSetting() == FR_INCLUDES_STABLE ) {
316308 $maybeId = $incManager->getStableTemplateVersion( $title );
317309 # Take the newest of these two...
@@ -318,11 +310,8 @@
319311 $id = (int)$maybeId;
320312 }
321313 }
322 - # If $id not specified, see if we are allowed to use the current revision
323 - if ( $id === false ) {
324 - $parser->getOutput()->fr_includeErrors[] = $title->getPrefixedDBKey(); // unspecified
325 - # If $id is zero, don't bother loading it
326 - } elseif ( !$id ) {
 314+ # If $id is zero, don't bother loading it (use blue/red link)
 315+ if ( $id === 0 ) {
327316 $skip = true;
328317 }
329318 return true;
@@ -335,7 +324,8 @@
336325 if ( !( $parser instanceof Parser ) ) {
337326 return true; // nothing to do
338327 }
339 - if ( !FRInclusionManager::singleton()->parserOutputIsStabilized() ) {
 328+ $incManager = FRInclusionManager::singleton();
 329+ if ( !$incManager->parserOutputIsStabilized() ) {
340330 return true; // trigger for stable version parsing only
341331 }
342332 # Normalize NS_MEDIA to NS_FILE
@@ -345,30 +335,15 @@
346336 } else {
347337 $title =& $nt;
348338 }
349 - # Get version, update mImageTimeKeys...
350 - list( $time, $sha1 ) = self::parserFindStableFile( $parser, $title );
351 - # Stabilize the file link
352 - if ( $time ) {
353 - if ( $query != '' ) $query .= '&';
354 - $query = "filetimestamp=" . urlencode( wfTimestamp( TS_MW, $time ) );
355 - }
356 - return true;
357 - }
358 -
359 - /**
360 - * Select the desired images based on the selected stable version time/SHA-1
361 - */
362 - protected static function parserFindStableFile( Parser $parser, Title $title ) {
363339 $time = false; // current version
364340 $sha1 = false; // corresponds to $time
365 - # Check for the version of this file used when reviewed.
366 - $incManager = FRInclusionManager::singleton();
 341+ # Check for the version of this file used when reviewed...
367342 list( $maybeTS, $maybeSha1 ) = $incManager->getReviewedFileVersion( $title );
368343 if ( $maybeTS !== null ) {
369344 $time = $maybeTS; // use if specified (even "0")
370345 $sha1 = $maybeSha1;
371346 }
372 - # Check for stable version of file if this feature is enabled.
 347+ # Check for stable version of file if this feature is enabled...
373348 if ( FlaggedRevs::inclusionSetting() == FR_INCLUDES_STABLE ) {
374349 list( $maybeTS, $maybeSha1 ) = $incManager->getStableFileVersion( $title );
375350 # Take the newest of these two...
@@ -377,14 +352,12 @@
378353 $sha1 = $maybeSha1;
379354 }
380355 }
381 - # If $time not specified, see if we are allowed to use the current revision
382 - if ( $time === false ) {
383 - # May want to give an error, so track these...
384 - $parser->getOutput()->fr_includeErrors[] = $title->getPrefixedDBKey();
385 - } elseif ( !$time ) {
386 - $time = "0"; // make sure this the string '0'
 356+ # Stabilize the file link
 357+ if ( $time ) {
 358+ if ( $query != '' ) $query .= '&';
 359+ $query = "filetimestamp=" . urlencode( wfTimestamp( TS_MW, $time ) );
387360 }
388 - return array( $time, $sha1 );
 361+ return true;
389362 }
390363
391364 public static function onParserFirstCallInit( &$parser ) {

Status & tagging log