r89124 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89123‎ | r89124 | r89125 >
Date:18:44, 29 May 2011
Author:aaron
Status:resolved
Tags:
Comment:
* Moved *RevIncludes functions to new FRInclusionCache class
* Doc tweaks
Modified paths:
  • /trunk/extensions/FlaggedRevs/api/actions/ApiReview.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/dataclasses/FRInclusionCache.php (added) (history)
  • /trunk/extensions/FlaggedRevs/dataclasses/FRInclusionManager.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevs.class.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/presentation/FlaggedPageView.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/presentation/RevisionReviewFormUI.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevs.class.php
@@ -397,7 +397,7 @@
398398 */
399399 public static function diffOnlyCGI() {
400400 $val = trim( wfMsgForContent( 'flaggedrevs-diffonly' ) );
401 - if ( $val === '' || $val === '&diffonly=1' || $val === '&diffonly=0' ) {
 401+ if ( $val === '&diffonly=1' || $val === '&diffonly=0' ) {
402402 return $val;
403403 }
404404 return '';
@@ -629,7 +629,7 @@
630630 }
631631 # Update template/file version cache...
632632 if ( $sv->getRevId() != $editInfo->revid ) {
633 - RevisionReviewForm::setRevIncludes( $title, $editInfo->revid, $editInfo->output );
 633+ FRInclusionCache::setRevIncludes( $title, $editInfo->revid, $editInfo->output );
634634 }
635635 }
636636 # 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
195 + native
Index: trunk/extensions/FlaggedRevs/dataclasses/FRInclusionManager.php
@@ -2,9 +2,9 @@
33 /**
44 * Class containing template/file version usage requirements for
55 * Parser based on the source text (being parsed) revision ID.
6 - * If no requirements are set, the page is parsed as normal.
76 *
87 * Parser hooks check this to determine what template/file version to use.
 8+ * If no requirements are set, the page is parsed as normal.
99 */
1010 class FRInclusionManager {
1111 protected $reviewedVersions = null; // files/templates at review time
Index: trunk/extensions/FlaggedRevs/api/actions/ApiReview.php
@@ -69,7 +69,7 @@
7070 $article = new FlaggedPage( $title );
7171 // Now get the template and image parameters needed
7272 list( $templateIds, $fileTimeKeys ) =
73 - RevisionReviewForm::getRevIncludes( $article, $rev, $wgUser );
 73+ FRInclusionCache::getRevIncludes( $article, $rev, $wgUser );
7474 // Get version parameters for review submission (flat strings)
7575 list( $templateParams, $imageParams, $fileVersion ) =
7676 RevisionReviewForm::getIncludeParams( $article, $templateIds, $fileTimeKeys );
Index: trunk/extensions/FlaggedRevs/presentation/FlaggedPageView.php
@@ -1370,7 +1370,7 @@
13711371 }
13721372 # Otherwise, check for includes pending on top of edits pending...
13731373 } else {
1374 - $incs = RevisionReviewForm::getRevIncludes( $this->article, $newRev, $wgUser );
 1374+ $incs = FRInclusionCache::getRevIncludes( $this->article, $newRev, $wgUser );
13751375 # Add a list of links to each changed template...
13761376 $changeList = self::fetchTemplateChanges( $srev, $incs[0] );
13771377 # Add a list of links to each changed file...
Index: trunk/extensions/FlaggedRevs/presentation/RevisionReviewFormUI.php
@@ -386,7 +386,7 @@
387387 # Do we need to get inclusion IDs from parser output?
388388 if ( $this->templateIDs === null || $this->imageSHA1Keys === null ) {
389389 list( $this->templateIDs, $this->imageSHA1Keys ) =
390 - RevisionReviewForm::getRevIncludes( $this->article, $this->rev, $this->user );
 390+ FRInclusionCache::getRevIncludes( $this->article, $this->rev, $this->user );
391391 }
392392 return array( $this->templateIDs, $this->imageSHA1Keys );
393393 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r89125Missing file change from r89124 (trying to tiptoe around uncommitted changes....aaron18:45, 29 May 2011
r89130More missing changes from r89124...wtfaaron19:24, 29 May 2011

Status & tagging log