Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php |
— | — | @@ -462,24 +462,23 @@ |
463 | 463 | * @param string $text |
464 | 464 | * @param Title $title |
465 | 465 | * @param integer $id, revision id |
466 | | - * @return array( string, array, array, array, int ) |
| 466 | + * @return array( string, array, array ) |
467 | 467 | * All included pages/arguments are expanded out |
468 | 468 | */ |
469 | 469 | public static function expandText( $text = '', Title $title, $id ) { |
470 | 470 | global $wgParser; |
471 | 471 | # Make our hooks trigger (force unstub so setting doesn't get lost) |
472 | 472 | $wgParser->firstCallInit(); |
| 473 | + # Begin stable parse |
473 | 474 | $wgParser->fr_isStable = ( self::inclusionSetting() != FR_INCLUDES_CURRENT ); |
474 | 475 | # Parse with default options |
475 | 476 | $options = self::makeParserOptions(); |
476 | 477 | $outputText = $wgParser->preprocess( $text, $title, $options, $id ); |
477 | 478 | $out =& $wgParser->mOutput; |
478 | | - $data = array( $outputText, $out->mTemplates, $out->mTemplateIds, |
479 | | - $out->fr_includeErrors, $out->fr_newestTemplateID ); |
480 | | - # Done! |
| 479 | + # Stable parse done! |
481 | 480 | $wgParser->fr_isStable = false; |
482 | 481 | # Return data array |
483 | | - return $data; |
| 482 | + return array( $outputText, $out->mTemplateIds, $out->fr_includeErrors ); |
484 | 483 | } |
485 | 484 | |
486 | 485 | /** |
— | — | @@ -686,11 +685,12 @@ |
687 | 686 | } |
688 | 687 | return null; // cache not found |
689 | 688 | } |
690 | | - |
| 689 | + |
691 | 690 | # ################ Synchronization and link update functions ################# |
692 | 691 | |
693 | 692 | /** |
694 | | - * Check if all includes in $stableOutput are the same as those in $currentOutput |
| 693 | + * Check if all includes in $stableOutput are the same as those in $currentOutput. |
| 694 | + * Only use this if both outputs are from the same source text. |
695 | 695 | * @param ParserOutput $stableOutput |
696 | 696 | * @param ParserOutput $currentOutput |
697 | 697 | * @return bool |
— | — | @@ -698,19 +698,27 @@ |
699 | 699 | public static function includesAreSynced( |
700 | 700 | ParserOutput $stableOutput, ParserOutput $currentOutput |
701 | 701 | ) { |
702 | | - $sTmpls = $stableOutput->mTemplateIds; |
703 | | - $cTmpls = $currentOutput->mTemplateIds; |
704 | | - foreach ( $sTmpls as $name => $revId ) { |
705 | | - if ( isset( $cTmpls[$name] ) && $cTmpls[$name] != $revId ) { |
706 | | - return false; // updated/created |
| 702 | + if ( isset( $stableOutput->mTemplateIds ) // sanity check |
| 703 | + && isset( $currentOutput->mTemplateIds ) ) |
| 704 | + { |
| 705 | + $sTmpls = $stableOutput->mTemplateIds; |
| 706 | + $cTmpls = $currentOutput->mTemplateIds; |
| 707 | + foreach ( $sTmpls as $name => $revId ) { |
| 708 | + if ( isset( $cTmpls[$name] ) && $cTmpls[$name] != $revId ) { |
| 709 | + return false; // updated/created |
| 710 | + } |
707 | 711 | } |
708 | 712 | } |
709 | | - $sFiles = $stableOutput->fr_ImageSHA1Keys; |
710 | | - $cFiles = $currentOutput->fr_ImageSHA1Keys; |
711 | | - foreach ( $sFiles as $name => $timeKey ) { |
712 | | - foreach ( $timeKey as $sTs => $sSha1 ) { |
713 | | - if ( isset( $cFiles[$name] ) && !isset( $cFiles[$name][$sTs] ) ) { |
714 | | - return false; // updated/created |
| 713 | + if ( isset( $stableOutput->fr_ImageSHA1Keys ) // sanity check |
| 714 | + && isset( $currentOutput->fr_ImageSHA1Keys ) ) |
| 715 | + { |
| 716 | + $sFiles = $stableOutput->fr_ImageSHA1Keys; |
| 717 | + $cFiles = $currentOutput->fr_ImageSHA1Keys; |
| 718 | + foreach ( $sFiles as $name => $timeKey ) { |
| 719 | + foreach ( $timeKey as $sTs => $sSha1 ) { |
| 720 | + if ( isset( $cFiles[$name] ) && !isset( $cFiles[$name][$sTs] ) ) { |
| 721 | + return false; // updated/created |
| 722 | + } |
715 | 723 | } |
716 | 724 | } |
717 | 725 | } |
Index: trunk/extensions/FlaggedRevs/forms/RevisionReviewForm.php |
— | — | @@ -482,8 +482,8 @@ |
483 | 483 | $parserCache = ParserCache::singleton(); |
484 | 484 | $poutput = $parserCache->get( $article, $this->user ); |
485 | 485 | if ( !$poutput |
486 | | - || !isset( $poutput->fr_newestTemplateID ) |
487 | | - || !isset( $poutput->fr_newestImageTime ) ) |
| 486 | + || !isset( $poutput->fr_ImageSHA1Keys ) |
| 487 | + || !isset( $poutput->mTemplateIds ) ) |
488 | 488 | { |
489 | 489 | $source = $article->getContent(); |
490 | 490 | $options = FlaggedRevs::makeParserOptions(); |
— | — | @@ -503,19 +503,15 @@ |
504 | 504 | if ( !Title::newFromRedirect( $text ) ) { |
505 | 505 | FlaggedRevs::updatePageCache( $article, $this->user, $stableOutput ); |
506 | 506 | } |
507 | | - # We can set the sync cache key already |
508 | | - $includesSynced = true; |
509 | | - if ( $poutput->fr_newestImageTime > $stableOutput->fr_newestImageTime ) { |
510 | | - $includesSynced = false; |
511 | | - } elseif ( $poutput->fr_newestTemplateID > $stableOutput->fr_newestTemplateID ) { |
512 | | - $includesSynced = false; |
513 | | - } |
514 | 507 | $u->fr_stableRev = $sv; // no need to re-fetch this! |
515 | 508 | $u->fr_stableParserOut = $stableOutput; // no need to re-fetch this! |
516 | | - # We can set the sync cache key already. |
517 | | - $key = wfMemcKey( 'flaggedrevs', 'includesSynced', $article->getId() ); |
518 | | - $data = FlaggedRevs::makeMemcObj( $includesSynced ? "true" : "false" ); |
519 | | - $wgMemc->set( $key, $data, $wgParserCacheExpireTime ); |
| 509 | + # We can set the sync cache key already... |
| 510 | + if ( $rev->isCurrent() ) { |
| 511 | + $includesSynced = FlaggedRevs::includesAreSynced( $stableOutput, $poutput ); |
| 512 | + $key = wfMemcKey( 'flaggedrevs', 'includesSynced', $article->getId() ); |
| 513 | + $data = FlaggedRevs::makeMemcObj( $includesSynced ? "true" : "false" ); |
| 514 | + $wgMemc->set( $key, $data, $wgParserCacheExpireTime ); |
| 515 | + } |
520 | 516 | } else { |
521 | 517 | # Get the old stable cache |
522 | 518 | $stableOutput = FlaggedRevs::getPageCache( $article, $this->user ); |
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php |
— | — | @@ -371,8 +371,6 @@ |
372 | 372 | */ |
373 | 373 | public static function parserAddFields( Parser $parser ) { |
374 | 374 | $parser->mOutput->fr_ImageSHA1Keys = array(); |
375 | | - $parser->mOutput->fr_newestImageTime = "0"; |
376 | | - $parser->mOutput->fr_newestTemplateID = 0; |
377 | 375 | $parser->mOutput->fr_includeErrors = array(); |
378 | 376 | return true; |
379 | 377 | } |
— | — | @@ -433,9 +431,6 @@ |
434 | 432 | $skip = true; // If ID is zero, don't load it |
435 | 433 | } |
436 | 434 | } |
437 | | - if ( $id > $parser->mOutput->fr_newestTemplateID ) { |
438 | | - $parser->mOutput->fr_newestTemplateID = $id; |
439 | | - } |
440 | 435 | return true; |
441 | 436 | } |
442 | 437 | |
— | — | @@ -450,7 +445,6 @@ |
451 | 446 | return true; |
452 | 447 | } |
453 | 448 | $file = null; |
454 | | - $isKnownLocal = $isLocalFile = false; // local file on this wiki? |
455 | 449 | # Normalize NS_MEDIA to NS_FILE |
456 | 450 | if ( $nt->getNamespace() == NS_MEDIA ) { |
457 | 451 | $title = Title::makeTitle( NS_FILE, $nt->getDBkey() ); |
— | — | @@ -469,7 +463,6 @@ |
470 | 464 | if ( $srev && $srev->getFileTimestamp() ) { |
471 | 465 | $time = $srev->getFileTimestamp(); // TS or null |
472 | 466 | $sha1 = $srev->getFileSha1(); |
473 | | - $isKnownLocal = true; // must be local |
474 | 467 | } |
475 | 468 | } |
476 | 469 | # Check cache before doing another DB hit... |
— | — | @@ -481,7 +474,6 @@ |
482 | 475 | if ( !$time || $timeP > $time ) { |
483 | 476 | $time = $timeP; |
484 | 477 | $sha1 = $sha1P; |
485 | | - $isKnownLocal = false; // up in the air...possibly a commons image |
486 | 478 | } |
487 | 479 | } |
488 | 480 | # If there is no stable version (or that feature is not enabled), use |
— | — | @@ -499,7 +491,6 @@ |
500 | 492 | if ( $row && ( $time === false || $reviewedTS > $time ) ) { |
501 | 493 | $time = $reviewedTS; |
502 | 494 | $sha1 = $row->fi_img_sha1; |
503 | | - $isKnownLocal = false; // up in the air...possibly a commons image |
504 | 495 | } |
505 | 496 | } |
506 | 497 | $query = $time ? "filetimestamp=" . urlencode( wfTimestamp( TS_MW, $time ) ) : ""; |
— | — | @@ -523,20 +514,6 @@ |
524 | 515 | # Add image metadata to parser output |
525 | 516 | $parser->mOutput->fr_ImageSHA1Keys[$title->getDBkey()] = array(); |
526 | 517 | $parser->mOutput->fr_ImageSHA1Keys[$title->getDBkey()][$time] = $sha1; |
527 | | - # Check if this file is local or on a foreign repo... |
528 | | - if ( $isKnownLocal ) { |
529 | | - $isLocalFile = true; // no need to check |
530 | | - # Load the image if needed (note that time === '0' means we have no image) |
531 | | - } elseif ( $time !== "0" ) { |
532 | | - # FIXME: would be nice not to double fetch! |
533 | | - $file = $file ? $file : self::getLocalFile( $title, $time ); |
534 | | - $isLocalFile = $file && $file->exists() && $file->isLocal(); |
535 | | - } |
536 | | - # Bug 15748, be lax about commons image sync status... |
537 | | - # When getting the max timestamp, just ignore the commons image timestamps. |
538 | | - if ( $isLocalFile && $time > $parser->mOutput->fr_newestImageTime ) { |
539 | | - $parser->mOutput->fr_newestImageTime = $time; |
540 | | - } |
541 | 518 | return true; |
542 | 519 | } |
543 | 520 | |
— | — | @@ -552,7 +529,6 @@ |
553 | 530 | return true; // nothing to do |
554 | 531 | } |
555 | 532 | $file = null; |
556 | | - $isKnownLocal = $isLocalFile = false; // local file on this wiki? |
557 | 533 | # Check for stable version of image if this feature is enabled. |
558 | 534 | # Should be in reviewable namespace, this saves unneeded DB checks as |
559 | 535 | # well as enforce site settings if they are later changed. |
— | — | @@ -564,7 +540,6 @@ |
565 | 541 | if ( $srev && $srev->getFileTimestamp() ) { |
566 | 542 | $time = $srev->getFileTimestamp(); // TS or null |
567 | 543 | $sha1 = $srev->getFileSha1(); |
568 | | - $isKnownLocal = true; // must be local |
569 | 544 | } |
570 | 545 | } |
571 | 546 | # Check cache before doing another DB hit... |
— | — | @@ -575,7 +550,6 @@ |
576 | 551 | if ( !$time || $timeP > $time ) { |
577 | 552 | $time = $timeP; |
578 | 553 | $sha1 = $sha1P; |
579 | | - $isKnownLocal = false; // up in the air...possibly a commons image |
580 | 554 | } |
581 | 555 | } |
582 | 556 | # If there is no stable version (or that feature is not enabled), use |
— | — | @@ -592,7 +566,6 @@ |
593 | 567 | if ( $row && ( $time === false || $reviewedTS > $time ) ) { |
594 | 568 | $time = $reviewedTS; |
595 | 569 | $sha1 = $row->fi_img_sha1; |
596 | | - $isKnownLocal = false; // up in the air...possibly a commons image |
597 | 570 | } |
598 | 571 | } |
599 | 572 | $query = $time ? "filetimestamp=" . urlencode( wfTimestamp( TS_MW, $time ) ) : ""; |
— | — | @@ -616,19 +589,6 @@ |
617 | 590 | # Add image metadata to parser output |
618 | 591 | $parser->mOutput->fr_ImageSHA1Keys[$nt->getDBkey()] = array(); |
619 | 592 | $parser->mOutput->fr_ImageSHA1Keys[$nt->getDBkey()][$time] = $sha1; |
620 | | - # Check if this file is local or on a foreign repo... |
621 | | - if ( $isKnownLocal ) { |
622 | | - $isLocalFile = true; // no need to check |
623 | | - # Load the image if needed (note that time === '0' means we have no image) |
624 | | - } elseif ( $time !== "0" ) { |
625 | | - # FIXME: would be nice not to double fetch! |
626 | | - $file = $file ? $file : self::getLocalFile( $nt, $time ); |
627 | | - $isLocalFile = $file && $file->exists() && $file->isLocal(); |
628 | | - } |
629 | | - # Bug 15748, be lax about commons image sync status |
630 | | - if ( $isLocalFile && $time > $parser->mOutput->fr_newestImageTime ) { |
631 | | - $parser->mOutput->fr_newestImageTime = $time; |
632 | | - } |
633 | 593 | return true; |
634 | 594 | } |
635 | 595 | |
— | — | @@ -636,43 +596,29 @@ |
637 | 597 | * Insert image timestamps/SHA-1 keys into parser output |
638 | 598 | */ |
639 | 599 | public static function parserInjectTimestamps( Parser $parser ) { |
640 | | - # Don't trigger this for stable version parsing...it will do it separately. |
641 | | - if ( !empty( $parser->fr_isStable ) ) { |
642 | | - return true; |
| 600 | + $pOutput =& $parser->mOutput; // convenience |
| 601 | + if ( !isset( $pOutput->mImages ) ) { |
| 602 | + return true; // sanity check |
643 | 603 | } |
644 | | - $maxRevision = 0; |
645 | | - # Record the max template revision ID |
646 | | - if ( !empty( $parser->mOutput->mTemplateIds ) ) { |
647 | | - foreach ( $parser->mOutput->mTemplateIds as $namespace => $DBKeyRev ) { |
648 | | - foreach ( $DBKeyRev as $DBkey => $revID ) { |
649 | | - if ( $revID > $maxRevision ) { |
650 | | - $maxRevision = $revID; |
651 | | - } |
652 | | - } |
653 | | - } |
654 | | - } |
655 | | - $parser->mOutput->fr_newestTemplateID = $maxRevision; |
| 604 | + $stableOut = !empty( $parser->fr_isStable ); |
656 | 605 | # Fetch the current timestamps of the images. |
657 | | - $maxTimestamp = "0"; |
658 | | - if ( !empty( $parser->mOutput->mImages ) ) { |
659 | | - foreach ( $parser->mOutput->mImages as $filename => $x ) { |
660 | | - # FIXME: it would be nice not to double fetch these! |
661 | | - $file = wfFindFile( Title::makeTitleSafe( NS_FILE, $filename ) ); |
662 | | - $parser->mOutput->fr_ImageSHA1Keys[$filename] = array(); |
663 | | - if ( $file ) { |
664 | | - $ts = $file->getTimestamp(); |
665 | | - # Bug 15748, be lax about commons image sync status |
666 | | - if ( $file->isLocal() && $ts > $maxTimestamp ) { |
667 | | - $maxTimestamp = $ts; |
668 | | - } |
669 | | - $parser->mOutput->fr_ImageSHA1Keys[$filename][$ts] = $file->getSha1(); |
670 | | - } else { |
671 | | - $parser->mOutput->fr_ImageSHA1Keys[$filename]["0"] = ''; |
| 606 | + foreach ( $pOutput->mImages as $filename => $x ) { |
| 607 | + # FIXME: it would be nice not to double fetch these! |
| 608 | + $time = false; // current |
| 609 | + if ( $stableOut && isset( $pOutput->fr_ImageSHA1Keys[$filename] ) ) { |
| 610 | + foreach( $pOutput->fr_ImageSHA1Keys[$filename] as $time => $sha1 ) { |
| 611 | + // Fetch file with $time to confirm the specified version exists |
672 | 612 | } |
673 | 613 | } |
| 614 | + $title = Title::makeTitleSafe( NS_FILE, $filename ); |
| 615 | + $file = wfFindFile( $title, array( 'time' => $time ) ); |
| 616 | + $pOutput->fr_ImageSHA1Keys[$filename] = array(); |
| 617 | + if ( $file ) { |
| 618 | + $pOutput->fr_ImageSHA1Keys[$filename][$file->getTimestamp()] = $file->getSha1(); |
| 619 | + } else { |
| 620 | + $pOutput->fr_ImageSHA1Keys[$filename]["0"] = ''; |
| 621 | + } |
674 | 622 | } |
675 | | - # Record the max timestamp |
676 | | - $parser->mOutput->fr_newestImageTime = $maxTimestamp; |
677 | 623 | return true; |
678 | 624 | } |
679 | 625 | |
Index: trunk/extensions/FlaggedRevs/FlaggedArticleView.php |
— | — | @@ -1793,23 +1793,24 @@ |
1794 | 1794 | public function maybeUpdateMainCache( &$outputDone, &$pcache ) { |
1795 | 1795 | global $wgUser, $wgRequest; |
1796 | 1796 | $this->load(); |
1797 | | - |
1798 | 1797 | $action = $wgRequest->getVal( 'action', 'view' ); |
1799 | | - if ( $action == 'purge' ) |
| 1798 | + if ( $action == 'purge' ) { |
1800 | 1799 | return true; // already purging! |
| 1800 | + } |
1801 | 1801 | # Only trigger on article view for content pages, not for protect/delete/hist |
1802 | | - if ( !self::isViewAction( $action ) || !$wgUser->isAllowed( 'review' ) ) |
| 1802 | + if ( !self::isViewAction( $action ) || !$wgUser->isAllowed( 'review' ) ) { |
1803 | 1803 | return true; |
1804 | | - if ( !$this->article->exists() || !$this->article->isReviewable() ) |
| 1804 | + } |
| 1805 | + if ( !$this->article->exists() || !$this->article->isReviewable() ) { |
1805 | 1806 | return true; |
1806 | | - |
| 1807 | + } |
1807 | 1808 | $parserCache = ParserCache::singleton(); |
1808 | 1809 | $parserOut = $parserCache->get( $this->article, $wgUser ); |
1809 | 1810 | if ( $parserOut ) { |
1810 | 1811 | # Clear older, incomplete, cached versions |
1811 | 1812 | # We need the IDs of templates and timestamps of images used |
1812 | | - if ( !isset( $parserOut->fr_newestTemplateID ) |
1813 | | - || !isset( $parserOut->fr_newestImageTime ) ) |
| 1813 | + if ( !isset( $parserOut->fr_ImageSHA1Keys ) |
| 1814 | + || !isset( $parserOut->mTemplateIds ) ) |
1814 | 1815 | { |
1815 | 1816 | $this->article->getTitle()->invalidateCache(); |
1816 | 1817 | } |