r47597 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47596‎ | r47597 | r47598 >
Date:05:02, 21 February 2009
Author:aaron
Status:deferred
Tags:
Comment:
Type cleanup and more optimizations to image hooks
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php
@@ -382,8 +382,7 @@
383383 return true;
384384 }
385385 $file = null;
386 - $isKnownLocal = false; // local file on this wiki?
387 - $dbr = wfGetDB( DB_SLAVE );
 386+ $isKnownLocal = $isLocalFile = false; // local file on this wiki?
388387 # Normalize NS_MEDIA to NS_FILE
389388 if( $nt->getNamespace() == NS_MEDIA ) {
390389 $title = Title::makeTitle( NS_FILE, $nt->getDBKey() );
@@ -397,8 +396,8 @@
398397 $sha1 = '';
399398 if( FlaggedRevs::isPageReviewable( $title ) ) {
400399 $srev = FlaggedRevision::newFromStable( $title );
401 - if( $srev ) {
402 - $time = $srev->getFileTimestamp();
 400+ if( $srev && $srev->getFileTimestamp() ) {
 401+ $time = $srev->getFileTimestamp(); // TS or null
403402 $sha1 = $srev->getFileSha1();
404403 $isKnownLocal = true; // must be local
405404 }
@@ -417,6 +416,7 @@
418417 # If there is no stable version (or that feature is not enabled), use
419418 # the image revision during review time. If both, use the newest one.
420419 if( $parser->getRevisionId() && !FlaggedRevs::useProcessCache( $parser->getRevisionId() ) ) {
 420+ $dbr = wfGetDB( DB_SLAVE );
421421 $row = $dbr->selectRow( 'flaggedimages',
422422 array( 'fi_img_timestamp', 'fi_img_sha1' ),
423423 array( 'fi_rev_id' => $parser->getRevisionId(), 'fi_name' => $title->getDBkey() ),
@@ -437,13 +437,13 @@
438438 if( $time === false ) {
439439 $parser->mOutput->fr_includeErrors[] = $title->getPrefixedDBKey(); // May want to give an error
440440 if( !$wgUseCurrentImages ) {
441 - $time = "0";
 441+ $time = "0"; // no image
442442 } else {
443443 $file = wfFindFile( $title );
444444 $time = $file ? $file->getTimestamp() : "0"; // Use current
445445 }
446446 } else {
447 - $time = "0";
 447+ $time = "0"; // no image (may trigger on review)
448448 }
449449 }
450450 # Add image metadata to parser output
@@ -452,7 +452,8 @@
453453 # Check if this file is local or on a foreign repo...
454454 if( $isKnownLocal ) {
455455 $isLocalFile = true; // no need to check
456 - } else {
 456+ # Load the image if needed (note that time === '0' means we have no image)
 457+ } else if( $time !== "0" ) {
457458 $file = $file ? $file : self::getLocalFile( $title, $time ); # FIXME: would be nice not to double fetch!
458459 $isLocalFile = $file && $file->exists() && $file->isLocal();
459460 }
@@ -473,16 +474,15 @@
474475 return true;
475476 }
476477 $file = null;
477 - $isKnownLocal = false; // local file on this wiki?
478 - $dbr = wfGetDB( DB_SLAVE );
 478+ $isKnownLocal = $isLocalFile = false; // local file on this wiki?
479479 # Check for stable version of image if this feature is enabled.
480480 # Should be in reviewable namespace, this saves unneeded DB checks as
481481 # well as enforce site settings if they are later changed.
482482 $sha1 = "";
483483 if( FlaggedRevs::isPageReviewable( $nt ) ) {
484484 $srev = FlaggedRevision::newFromStable( $nt );
485 - if( $srev ) {
486 - $time = $srev->getFileTimestamp();
 485+ if( $srev && $srev->getFileTimestamp() ) {
 486+ $time = $srev->getFileTimestamp(); // TS or null
487487 $sha1 = $srev->getFileSha1();
488488 $isKnownLocal = true; // must be local
489489 }
@@ -501,6 +501,7 @@
502502 # If there is no stable version (or that feature is not enabled), use
503503 # the image revision during review time. If both, use the newest one.
504504 if( $ig->mRevisionId && !FlaggedRevs::useProcessCache( $ig->mRevisionId ) ) {
 505+ $dbr = wfGetDB( DB_SLAVE );
505506 $row = $dbr->selectRow( 'flaggedimages',
506507 array( 'fi_img_timestamp', 'fi_img_sha1' ),
507508 array('fi_rev_id' => $ig->mRevisionId, 'fi_name' => $nt->getDBkey() ),
@@ -521,13 +522,13 @@
522523 if( $time === false ) {
523524 $ig->mParser->mOutput->fr_includeErrors[] = $nt->getPrefixedDBKey(); // May want to give an error
524525 if( !$wgUseCurrentImages ) {
525 - $time = "0";
 526+ $time = "0"; // no image
526527 } else {
527528 $file = wfFindFile( $nt );
528529 $time = $file ? $file->getTimestamp() : "0";
529530 }
530531 } else {
531 - $time = "0";
 532+ $time = "0"; // no image (may trigger on review)
532533 }
533534 }
534535 # Add image metadata to parser output
@@ -536,7 +537,8 @@
537538 # Check if this file is local or on a foreign repo...
538539 if( $isKnownLocal ) {
539540 $isLocalFile = true; // no need to check
540 - } else {
 541+ # Load the image if needed (note that time === '0' means we have no image)
 542+ } else if( $time !== "0" ) {
541543 $file = $file ? $file : self::getLocalFile( $nt, $time ); # FIXME: would be nice not to double fetch!
542544 $isLocalFile = $file && $file->exists() && $file->isLocal();
543545 }

Status & tagging log