Index: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php |
— | — | @@ -382,8 +382,7 @@ |
383 | 383 | return true; |
384 | 384 | } |
385 | 385 | $file = null; |
386 | | - $isKnownLocal = false; // local file on this wiki? |
387 | | - $dbr = wfGetDB( DB_SLAVE ); |
| 386 | + $isKnownLocal = $isLocalFile = false; // local file on this wiki? |
388 | 387 | # Normalize NS_MEDIA to NS_FILE |
389 | 388 | if( $nt->getNamespace() == NS_MEDIA ) { |
390 | 389 | $title = Title::makeTitle( NS_FILE, $nt->getDBKey() ); |
— | — | @@ -397,8 +396,8 @@ |
398 | 397 | $sha1 = ''; |
399 | 398 | if( FlaggedRevs::isPageReviewable( $title ) ) { |
400 | 399 | $srev = FlaggedRevision::newFromStable( $title ); |
401 | | - if( $srev ) { |
402 | | - $time = $srev->getFileTimestamp(); |
| 400 | + if( $srev && $srev->getFileTimestamp() ) { |
| 401 | + $time = $srev->getFileTimestamp(); // TS or null |
403 | 402 | $sha1 = $srev->getFileSha1(); |
404 | 403 | $isKnownLocal = true; // must be local |
405 | 404 | } |
— | — | @@ -417,6 +416,7 @@ |
418 | 417 | # If there is no stable version (or that feature is not enabled), use |
419 | 418 | # the image revision during review time. If both, use the newest one. |
420 | 419 | if( $parser->getRevisionId() && !FlaggedRevs::useProcessCache( $parser->getRevisionId() ) ) { |
| 420 | + $dbr = wfGetDB( DB_SLAVE ); |
421 | 421 | $row = $dbr->selectRow( 'flaggedimages', |
422 | 422 | array( 'fi_img_timestamp', 'fi_img_sha1' ), |
423 | 423 | array( 'fi_rev_id' => $parser->getRevisionId(), 'fi_name' => $title->getDBkey() ), |
— | — | @@ -437,13 +437,13 @@ |
438 | 438 | if( $time === false ) { |
439 | 439 | $parser->mOutput->fr_includeErrors[] = $title->getPrefixedDBKey(); // May want to give an error |
440 | 440 | if( !$wgUseCurrentImages ) { |
441 | | - $time = "0"; |
| 441 | + $time = "0"; // no image |
442 | 442 | } else { |
443 | 443 | $file = wfFindFile( $title ); |
444 | 444 | $time = $file ? $file->getTimestamp() : "0"; // Use current |
445 | 445 | } |
446 | 446 | } else { |
447 | | - $time = "0"; |
| 447 | + $time = "0"; // no image (may trigger on review) |
448 | 448 | } |
449 | 449 | } |
450 | 450 | # Add image metadata to parser output |
— | — | @@ -452,7 +452,8 @@ |
453 | 453 | # Check if this file is local or on a foreign repo... |
454 | 454 | if( $isKnownLocal ) { |
455 | 455 | $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" ) { |
457 | 458 | $file = $file ? $file : self::getLocalFile( $title, $time ); # FIXME: would be nice not to double fetch! |
458 | 459 | $isLocalFile = $file && $file->exists() && $file->isLocal(); |
459 | 460 | } |
— | — | @@ -473,16 +474,15 @@ |
474 | 475 | return true; |
475 | 476 | } |
476 | 477 | $file = null; |
477 | | - $isKnownLocal = false; // local file on this wiki? |
478 | | - $dbr = wfGetDB( DB_SLAVE ); |
| 478 | + $isKnownLocal = $isLocalFile = false; // local file on this wiki? |
479 | 479 | # Check for stable version of image if this feature is enabled. |
480 | 480 | # Should be in reviewable namespace, this saves unneeded DB checks as |
481 | 481 | # well as enforce site settings if they are later changed. |
482 | 482 | $sha1 = ""; |
483 | 483 | if( FlaggedRevs::isPageReviewable( $nt ) ) { |
484 | 484 | $srev = FlaggedRevision::newFromStable( $nt ); |
485 | | - if( $srev ) { |
486 | | - $time = $srev->getFileTimestamp(); |
| 485 | + if( $srev && $srev->getFileTimestamp() ) { |
| 486 | + $time = $srev->getFileTimestamp(); // TS or null |
487 | 487 | $sha1 = $srev->getFileSha1(); |
488 | 488 | $isKnownLocal = true; // must be local |
489 | 489 | } |
— | — | @@ -501,6 +501,7 @@ |
502 | 502 | # If there is no stable version (or that feature is not enabled), use |
503 | 503 | # the image revision during review time. If both, use the newest one. |
504 | 504 | if( $ig->mRevisionId && !FlaggedRevs::useProcessCache( $ig->mRevisionId ) ) { |
| 505 | + $dbr = wfGetDB( DB_SLAVE ); |
505 | 506 | $row = $dbr->selectRow( 'flaggedimages', |
506 | 507 | array( 'fi_img_timestamp', 'fi_img_sha1' ), |
507 | 508 | array('fi_rev_id' => $ig->mRevisionId, 'fi_name' => $nt->getDBkey() ), |
— | — | @@ -521,13 +522,13 @@ |
522 | 523 | if( $time === false ) { |
523 | 524 | $ig->mParser->mOutput->fr_includeErrors[] = $nt->getPrefixedDBKey(); // May want to give an error |
524 | 525 | if( !$wgUseCurrentImages ) { |
525 | | - $time = "0"; |
| 526 | + $time = "0"; // no image |
526 | 527 | } else { |
527 | 528 | $file = wfFindFile( $nt ); |
528 | 529 | $time = $file ? $file->getTimestamp() : "0"; |
529 | 530 | } |
530 | 531 | } else { |
531 | | - $time = "0"; |
| 532 | + $time = "0"; // no image (may trigger on review) |
532 | 533 | } |
533 | 534 | } |
534 | 535 | # Add image metadata to parser output |
— | — | @@ -536,7 +537,8 @@ |
537 | 538 | # Check if this file is local or on a foreign repo... |
538 | 539 | if( $isKnownLocal ) { |
539 | 540 | $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" ) { |
541 | 543 | $file = $file ? $file : self::getLocalFile( $nt, $time ); # FIXME: would be nice not to double fetch! |
542 | 544 | $isLocalFile = $file && $file->exists() && $file->isLocal(); |
543 | 545 | } |