Index: trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevs.class.php |
— | — | @@ -397,7 +397,7 @@ |
398 | 398 | */ |
399 | 399 | public static function diffOnlyCGI() { |
400 | 400 | $val = trim( wfMsgForContent( 'flaggedrevs-diffonly' ) ); |
401 | | - if ( $val === '' || $val === '&diffonly=1' || $val === '&diffonly=0' ) { |
| 401 | + if ( $val === '&diffonly=1' || $val === '&diffonly=0' ) { |
402 | 402 | return $val; |
403 | 403 | } |
404 | 404 | return ''; |
— | — | @@ -629,7 +629,7 @@ |
630 | 630 | } |
631 | 631 | # Update template/file version cache... |
632 | 632 | if ( $sv->getRevId() != $editInfo->revid ) { |
633 | | - RevisionReviewForm::setRevIncludes( $title, $editInfo->revid, $editInfo->output ); |
| 633 | + FRInclusionCache::setRevIncludes( $title, $editInfo->revid, $editInfo->output ); |
634 | 634 | } |
635 | 635 | } |
636 | 636 | # Lazily rebuild dependancies on next parse (we invalidate below) |
Index: trunk/extensions/FlaggedRevs/dataclasses/FRInclusionCache.php |
— | — | @@ -0,0 +1,93 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Class containing draft template/file version usage for |
| 5 | + * Parser based on the source text of a revision ID & title. |
| 6 | + */ |
| 7 | +class FRInclusionCache { |
| 8 | + /** |
| 9 | + * Get template and image versions from parsing a revision |
| 10 | + * @param Article $article |
| 11 | + * @param Revision $rev |
| 12 | + * @param User $user |
| 13 | + * @param string $regen use 'regen' to force regeneration |
| 14 | + * @return array( templateIds, fileSHA1Keys ) |
| 15 | + * templateIds like ParserOutput->mTemplateIds |
| 16 | + * fileSHA1Keys like ParserOutput->mImageTimeKeys |
| 17 | + */ |
| 18 | + public static function getRevIncludes( |
| 19 | + Article $article, Revision $rev, User $user, $regen = '' |
| 20 | + ) { |
| 21 | + global $wgParser, $wgMemc; |
| 22 | + wfProfileIn( __METHOD__ ); |
| 23 | + $versions = false; |
| 24 | + $hash = md5( $article->getTitle()->getPrefixedDBkey() ); |
| 25 | + $key = wfMemcKey( 'flaggedrevs', 'revIncludes', $rev->getId(), $hash ); |
| 26 | + if ( $regen !== 'regen' ) { // check cache |
| 27 | + $versions = FlaggedRevs::getMemcValue( $wgMemc->get( $key ), $article, 'allowStale' ); |
| 28 | + } |
| 29 | + if ( !is_array( $versions ) ) { // cache miss |
| 30 | + $pOut = false; |
| 31 | + if ( $rev->isCurrent() ) { |
| 32 | + $parserCache = ParserCache::singleton(); |
| 33 | + # Try current version parser cache (as anon)... |
| 34 | + $pOut = $parserCache->get( $article, $article->makeParserOptions( $user ) ); |
| 35 | + if ( $pOut == false && $rev->getUser() ) { // try the user who saved the change |
| 36 | + $author = User::newFromId( $rev->getUser() ); |
| 37 | + $pOut = $parserCache->get( $article, $article->makeParserOptions( $author ) ); |
| 38 | + } |
| 39 | + } |
| 40 | + if ( $pOut == false ) { |
| 41 | + $title = $article->getTitle(); |
| 42 | + $pOpts = ParserOptions::newFromUser( $user ); // Note: tidy off |
| 43 | + # Disable slow crap that doesn't matter for getting templates/files... |
| 44 | + $parser = clone $wgParser; |
| 45 | + $parser->clearTagHook( 'ref' ); |
| 46 | + $parser->clearTagHook( 'references' ); |
| 47 | + $pOut = $parser->parse( |
| 48 | + $rev->getText(), $title, $pOpts, true, true, $rev->getId() ); |
| 49 | + } |
| 50 | + # Get the template/file versions used... |
| 51 | + $versions = array( $pOut->getTemplateIds(), $pOut->getImageTimeKeys() ); |
| 52 | + # Save to cache... |
| 53 | + $data = FlaggedRevs::makeMemcObj( $versions ); |
| 54 | + $wgMemc->set( $key, $data, 24*3600 ); // inclusions may be dynamic |
| 55 | + } else { |
| 56 | + # Do a link batch query for page_latest... |
| 57 | + $lb = new LinkBatch(); |
| 58 | + foreach ( $versions as $ns => $tmps ) { |
| 59 | + foreach ( $tmps as $dbKey => $revIdDraft ) { |
| 60 | + $lb->add( $ns, $dbKey ); |
| 61 | + } |
| 62 | + } |
| 63 | + $lb->execute(); |
| 64 | + # Update array with the current page_latest values. |
| 65 | + # This kludge is there since $newTemplates (thus $revIdDraft) is cached. |
| 66 | + foreach ( $versions as $ns => $tmps ) { |
| 67 | + foreach ( $tmps as $dbKey => &$revIdDraft ) { |
| 68 | + $title = new Title( $ns, $dbKey ); |
| 69 | + $revIdDraft = (int)$title->getLatestRevID(); |
| 70 | + } |
| 71 | + } |
| 72 | + } |
| 73 | + wfProfileOut( __METHOD__ ); |
| 74 | + return $versions; |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * Set template and image versions from parsing a revision |
| 79 | + * @param Title $title |
| 80 | + * @param int $revId |
| 81 | + * @param ParserOutput $rev |
| 82 | + * @return void |
| 83 | + */ |
| 84 | + public static function setRevIncludes( Title $title, $revId, ParserOutput $pOut ) { |
| 85 | + global $wgMemc; |
| 86 | + $hash = md5( $title->getPrefixedDBkey() ); |
| 87 | + $key = wfMemcKey( 'flaggedrevs', 'revIncludes', $revId, $hash ); |
| 88 | + # Get the template/file versions used... |
| 89 | + $versions = array( $pOut->getTemplateIds(), $pOut->getImageTimeKeys() ); |
| 90 | + # Save to cache... |
| 91 | + $data = FlaggedRevs::makeMemcObj( $versions ); |
| 92 | + $wgMemc->set( $key, $data, 24*3600 ); // inclusions may be dynamic |
| 93 | + } |
| 94 | +} |
Property changes on: trunk/extensions/FlaggedRevs/dataclasses/FRInclusionCache.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 95 | + native |
Index: trunk/extensions/FlaggedRevs/dataclasses/FRInclusionManager.php |
— | — | @@ -2,9 +2,9 @@ |
3 | 3 | /** |
4 | 4 | * Class containing template/file version usage requirements for |
5 | 5 | * Parser based on the source text (being parsed) revision ID. |
6 | | - * If no requirements are set, the page is parsed as normal. |
7 | 6 | * |
8 | 7 | * Parser hooks check this to determine what template/file version to use. |
| 8 | + * If no requirements are set, the page is parsed as normal. |
9 | 9 | */ |
10 | 10 | class FRInclusionManager { |
11 | 11 | protected $reviewedVersions = null; // files/templates at review time |
Index: trunk/extensions/FlaggedRevs/api/actions/ApiReview.php |
— | — | @@ -69,7 +69,7 @@ |
70 | 70 | $article = new FlaggedPage( $title ); |
71 | 71 | // Now get the template and image parameters needed |
72 | 72 | list( $templateIds, $fileTimeKeys ) = |
73 | | - RevisionReviewForm::getRevIncludes( $article, $rev, $wgUser ); |
| 73 | + FRInclusionCache::getRevIncludes( $article, $rev, $wgUser ); |
74 | 74 | // Get version parameters for review submission (flat strings) |
75 | 75 | list( $templateParams, $imageParams, $fileVersion ) = |
76 | 76 | RevisionReviewForm::getIncludeParams( $article, $templateIds, $fileTimeKeys ); |
Index: trunk/extensions/FlaggedRevs/presentation/FlaggedPageView.php |
— | — | @@ -1370,7 +1370,7 @@ |
1371 | 1371 | } |
1372 | 1372 | # Otherwise, check for includes pending on top of edits pending... |
1373 | 1373 | } else { |
1374 | | - $incs = RevisionReviewForm::getRevIncludes( $this->article, $newRev, $wgUser ); |
| 1374 | + $incs = FRInclusionCache::getRevIncludes( $this->article, $newRev, $wgUser ); |
1375 | 1375 | # Add a list of links to each changed template... |
1376 | 1376 | $changeList = self::fetchTemplateChanges( $srev, $incs[0] ); |
1377 | 1377 | # Add a list of links to each changed file... |
Index: trunk/extensions/FlaggedRevs/presentation/RevisionReviewFormUI.php |
— | — | @@ -386,7 +386,7 @@ |
387 | 387 | # Do we need to get inclusion IDs from parser output? |
388 | 388 | if ( $this->templateIDs === null || $this->imageSHA1Keys === null ) { |
389 | 389 | list( $this->templateIDs, $this->imageSHA1Keys ) = |
390 | | - RevisionReviewForm::getRevIncludes( $this->article, $this->rev, $this->user ); |
| 390 | + FRInclusionCache::getRevIncludes( $this->article, $this->rev, $this->user ); |
391 | 391 | } |
392 | 392 | return array( $this->templateIDs, $this->imageSHA1Keys ); |
393 | 393 | } |