http://www.mediawiki.org/wiki/Special:Code/MediaWiki/84619
Revision: 84619
Author: aaron
Date: 2011-03-23 18:27:50 +0000 (Wed, 23 Mar 2011)
Log Message:
-----------
Follow-up r84610: removed fr_fileSHA1Keys and use core file version tracking
instead. Handles query spam FIXME in code.
Modified Paths:
--------------
trunk/extensions/FlaggedRevs/FRInclusionManager.php
trunk/extensions/FlaggedRevs/FlaggedArticleView.php
trunk/extensions/FlaggedRevs/FlaggedRevision.php
trunk/extensions/FlaggedRevs/FlaggedRevs.class.php
trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php
trunk/extensions/FlaggedRevs/FlaggedRevs.php
trunk/extensions/FlaggedRevs/api/ApiReview.php
trunk/extensions/FlaggedRevs/forms/RevisionReviewForm.php
trunk/extensions/FlaggedRevs/maintenance/tests/FRInclusionManagerTest.php
Modified: trunk/extensions/FlaggedRevs/FRInclusionManager.php
===================================================================
--- trunk/extensions/FlaggedRevs/FRInclusionManager.php 2011-03-23 18:23:55 UTC
(rev 84618)
+++ trunk/extensions/FlaggedRevs/FRInclusionManager.php 2011-03-23 18:27:50 UTC
(rev 84619)
@@ -39,7 +39,7 @@
* (a) Stabilize inclusions in Parser output
* (b) Set the template/image versions used in the flagged version of a
revision
* @param array $tmpParams (ns => dbKey => revId )
- * @param array $imgParams (dbKey => array('ts' => MW timestamp,'sha1'
=> sha1) )
+ * @param array $imgParams (dbKey => array('time' => MW
timestamp,'sha1' => sha1) )
*/
public function setReviewedVersions( array $tmpParams, array $imgParams
) {
$this->reviewedVersions = array();
@@ -50,7 +50,7 @@
/**
* Set the stable versions of some template/images
* @param array $tmpParams (ns => dbKey => revId )
- * @param array $imgParams (dbKey => array('ts' => MW timestamp,'sha1'
=> sha1) )
+ * @param array $imgParams (dbKey => array('time' => MW
timestamp,'sha1' => sha1) )
*/
public function setStableVersionCache( array $tmpParams, array
$imgParams ) {
$this->stableVersions['templates'] = $tmpParams;
@@ -116,7 +116,7 @@
$dbKey = $title->getDBkey();
# All NS_FILE, no need to check namespace
if ( isset( $this->reviewedVersions['files'][$dbKey] ) ) {
- $time = $this->reviewedVersions['files'][$dbKey]['ts'];
+ $time =
$this->reviewedVersions['files'][$dbKey]['time'];
$sha1 =
$this->reviewedVersions['files'][$dbKey]['sha1'];
return array( $time, $sha1 );
}
@@ -154,7 +154,7 @@
$sha1 = '';
# All NS_FILE, no need to check namespace
if ( isset( $this->stableVersions['files'][$dbKey] ) ) {
- $time = $this->stableVersions['files'][$dbKey]['ts'];
+ $time = $this->stableVersions['files'][$dbKey]['time'];
$sha1 = $this->stableVersions['files'][$dbKey]['sha1'];
return array( $time, $sha1 );
}
@@ -164,7 +164,7 @@
$sha1 = $srev->getFileSha1();
}
$this->stableVersions['files'][$dbKey] = array();
- $this->stableVersions['files'][$dbKey]['ts'] = $time;
+ $this->stableVersions['files'][$dbKey]['time'] = $time;
$this->stableVersions['files'][$dbKey]['sha1'] = $sha1;
return array( $time, $sha1 );
}
Modified: trunk/extensions/FlaggedRevs/FlaggedArticleView.php
===================================================================
--- trunk/extensions/FlaggedRevs/FlaggedArticleView.php 2011-03-23 18:23:55 UTC
(rev 84618)
+++ trunk/extensions/FlaggedRevs/FlaggedArticleView.php 2011-03-23 18:27:50 UTC
(rev 84619)
@@ -1083,10 +1083,10 @@
$templateIDs = $fileSHA1Keys = null;
if ( $wgOut->getRevisionId() == $rev->getId()
&& isset( $wgOut->mTemplateIds )
- && isset( $wgOut->fr_fileSHA1Keys ) )
+ && isset( $wgOut->mImageTimeKeys ) )
{
$templateIDs = $wgOut->mTemplateIds;
- $fileSHA1Keys = $wgOut->fr_fileSHA1Keys;
+ $fileSHA1Keys = $wgOut->mImageTimeKeys;
}
# Review notice box goes in top of form
$form = RevisionReviewForm::buildQuickReview(
Modified: trunk/extensions/FlaggedRevs/FlaggedRevision.php
===================================================================
--- trunk/extensions/FlaggedRevs/FlaggedRevision.php 2011-03-23 18:23:55 UTC
(rev 84618)
+++ trunk/extensions/FlaggedRevs/FlaggedRevision.php 2011-03-23 18:27:50 UTC
(rev 84619)
@@ -292,7 +292,8 @@
'fi_name' => $dbkey,
'fi_img_sha1' => strval(
$timeSHA1['sha1'] ),
// b/c: fi_img_timestamp DEFAULT either NULL
(new) or '' (old)
- 'fi_img_timestamp' => $timeSHA1['ts'] ?
$dbw->timestamp( $timeSHA1['ts'] ) : ''
+ 'fi_img_timestamp' => $timeSHA1['time'] ?
+ $dbw->timestamp( $timeSHA1['time'] ) :
''
);
}
# Our review entry
@@ -496,7 +497,7 @@
/**
* Get original template versions at time of review
* @param int $flags FR_MASTER
- * @return Array file versions (dbKey => array('ts' => MW
timestamp,'sha1' => sha1) )
+ * @return Array file versions (dbKey => array('time' => MW
timestamp,'sha1' => sha1) )
* Note: '0' used for file timestamp if it didn't exist ('' for sha1)
*/
public function getFileVersions( $flags = 0 ) {
@@ -513,7 +514,7 @@
$reviewedTS = trim( $row->fi_img_timestamp );
// may be ''/NULL
$reviewedTS = $reviewedTS ? wfTimestamp( TS_MW,
$reviewedTS ) : '0';
$this->mFiles[$row->fi_name] = array();
- $this->mFiles[$row->fi_name]['ts'] =
$reviewedTS;
+ $this->mFiles[$row->fi_name]['time'] =
$reviewedTS;
$this->mFiles[$row->fi_name]['sha1'] =
$row->fi_img_sha1;
}
}
@@ -557,7 +558,7 @@
/**
* Get the current stable version of the files used at time of review
* @param int $flags FR_MASTER
- * @return Array file versions (dbKey => array('ts' => MW
timestamp,'sha1' => sha1) )
+ * @return Array file versions (dbKey => array('time' => MW
timestamp,'sha1' => sha1) )
* Note: '0' used for file timestamp if it doesn't exist ('' for sha1)
*/
public function getStableFileVersions( $flags = 0 ) {
@@ -587,7 +588,7 @@
$reviewedSha1 = strval(
$row->fr_img_sha1 );
}
$this->mStableFiles[$row->fi_name] = array();
- $this->mStableFiles[$row->fi_name]['ts'] =
$reviewedTS;
+ $this->mStableFiles[$row->fi_name]['time'] =
$reviewedTS;
$this->mStableFiles[$row->fi_name]['sha1'] =
$reviewedSha1;
}
}
@@ -714,7 +715,7 @@
if ( FlaggedRevs::inclusionSetting() ==
FR_INCLUDES_STABLE ) {
$stableTS = wfTimestampOrNull( TS_MW,
$row->fr_img_timestamp );
# Select newest of (stable rev, rev when
reviewed) as "version used"
- $tsStable = ( $stableTS >= $reviewedTS ) ?
$stableTS : $reviewedTS;
+ $tsStable = max( $stableTS, $reviewedTS );
} else {
$tsStable = $reviewedTS;
}
Modified: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php
===================================================================
--- trunk/extensions/FlaggedRevs/FlaggedRevs.class.php 2011-03-23 18:23:55 UTC
(rev 84618)
+++ trunk/extensions/FlaggedRevs/FlaggedRevs.class.php 2011-03-23 18:27:50 UTC
(rev 84619)
@@ -652,7 +652,7 @@
/**
* @param Article $article
* @param parserOutput $parserOut
- * Updates the stable-only cache dependancy table
+ * Updates the stable-only cache dependency table
*/
public static function updateCacheTracking( Article $article,
ParserOutput $stableOut ) {
wfProfileIn( __METHOD__ );
@@ -1269,7 +1269,7 @@
'img_timestamp' => $fileData['timestamp'],
'img_sha1' => $fileData['sha1'],
'templateVersions' => $poutput->mTemplateIds,
- 'fileVersions' => $poutput->fr_fileSHA1Keys
+ 'fileVersions' => $poutput->mImageTimeKeys
) );
$flaggedRevision->insertOn( $auto );
# Update the article review log
Modified: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php
===================================================================
--- trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php 2011-03-23 18:23:55 UTC
(rev 84618)
+++ trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php 2011-03-23 18:27:50 UTC
(rev 84619)
@@ -288,8 +288,7 @@
* Add special fields to parser.
*/
public static function parserAddFields( Parser $parser ) {
- $parser->mOutput->fr_fileSHA1Keys = array();
- $parser->mOutput->fr_includeErrors = array();
+ $parser->getOutput()->fr_includeErrors = array();
return true;
}
@@ -321,7 +320,7 @@
}
# If $id not specified, see if we are allowed to use the
current revision
if ( $id === false ) {
- $parser->mOutput->fr_includeErrors[] =
$title->getPrefixedDBKey(); // unspecified
+ $parser->getOutput()->fr_includeErrors[] =
$title->getPrefixedDBKey(); // unspecified
# If $id is zero, don't bother loading it
} elseif ( !$id ) {
$skip = true;
@@ -331,7 +330,7 @@
/**
* (a) Select the desired images based on the selected stable version
time/SHA-1
- * (b) Set specified versions in fr_fileSHA1Keys
+ * (b) Set specified versions in mImageTimeKeys
*/
public static function parserFetchStableFile(
$parser, Title $nt, &$skip, &$time, &$query, &$sha1
@@ -349,7 +348,7 @@
} else {
$title =& $nt;
}
- # Get version, update fr_fileSHA1Keys...
+ # Get version, update mImageTimeKeys...
list( $time, $sha1 ) = self::parserFindStableFile( $parser,
$title );
# Stabilize the file link
if ( $time ) {
@@ -361,7 +360,7 @@
/**
* (a) Select the desired images based on the selected stable version
time/SHA-1
- * (b) Set specified versions in fr_fileSHA1Keys
+ * (b) Set specified versions in mImageTimeKeys
*/
public static function galleryFetchStableFile( $ig, Title $nt, &$time,
&$query, &$sha1 ) {
$parser =& $ig->mParser; // convenience
@@ -371,7 +370,7 @@
if (
!FRInclusionManager::singleton()->parserOutputIsStabilized() ) {
return true; // trigger for stable version parsing only
}
- # Get version, update fr_fileSHA1Keys...
+ # Get version, update mImageTimeKeys...
list( $time, $sha1 ) = self::parserFindStableFile( $parser, $nt
);
# Stabilize the file link
if ( $time ) {
@@ -383,7 +382,7 @@
/**
* (a) Select the desired images based on the selected stable version
time/SHA-1
- * (b) Set specified versions in fr_fileSHA1Keys
+ * (b) Set specified versions in mImageTimeKeys
*/
protected static function parserFindStableFile( Parser $parser, Title
$title ) {
$time = false; // current version
@@ -407,72 +406,13 @@
# If $time not specified, see if we are allowed to use the
current revision
if ( $time === false ) {
# May want to give an error, so track these...
- $parser->mOutput->fr_includeErrors[] =
$title->getPrefixedDBKey();
+ $parser->getOutput()->fr_includeErrors[] =
$title->getPrefixedDBKey();
} elseif ( !$time ) {
$time = "0"; // make sure this the string '0'
}
- # Add specified image metadata to parser output
- if ( $time !== false ) {
- $parser->mOutput->fr_fileSHA1Keys[$title->getDBkey()] =
array();
-
$parser->mOutput->fr_fileSHA1Keys[$title->getDBkey()]['ts'] = $time;
-
$parser->mOutput->fr_fileSHA1Keys[$title->getDBkey()]['sha1'] = $sha1;
- }
return array( $time, $sha1 );
}
- /**
- * Insert image timestamps/SHA-1 keys into parser output
- */
- public static function parserInjectTimestamps( Parser $parser ) {
- $pOutput =& $parser->mOutput; // convenience
- if ( !isset( $pOutput->mImages ) ) {
- return true; // sanity check
- }
- # Fetch the current timestamps of the images.
- foreach ( $pOutput->mImages as $filename => $x ) {
- # Stable output with versions specified
- if ( isset( $pOutput->fr_fileSHA1Keys[$filename] ) ) {
- // Fetch file with $time to confirm the
specified version exists
- $time =
$pOutput->fr_fileSHA1Keys[$filename]['ts'];
- $sha1 =
$pOutput->fr_fileSHA1Keys[$filename]['sha1'];
- # FIXME: don't double fetch these (Parser just
did)!!!
- $file = RepoGroup::singleton()->findFileFromKey(
- $sha1, array( 'time' => $time ) );
- } else {
- $title = Title::makeTitleSafe( NS_FILE,
$filename );
- # FIXME: don't double fetch these (Parser just
did)!!!
- $file = wfFindFile( $title );
- }
- # Update tracking vars...
- $pOutput->fr_fileSHA1Keys[$filename] = array();
- if ( $file ) {
- $pOutput->fr_fileSHA1Keys[$filename]['ts'] =
$file->getTimestamp();
- $pOutput->fr_fileSHA1Keys[$filename]['sha1'] =
$file->getSha1();
- } else {
- $pOutput->fr_fileSHA1Keys[$filename]['ts'] =
'0';
- $pOutput->fr_fileSHA1Keys[$filename]['sha1'] =
'';
- }
- }
- return true;
- }
-
- /**
- * Insert image timestamps/SHA-1s into page output
- */
- public static function outputInjectTimestamps( OutputPage $out,
ParserOutput $parserOut ) {
- # Set first time
- if ( !isset( $out->fr_fileSHA1Keys ) ) {
- $out->fr_fileSHA1Keys = array();
- }
- # Leave as defaults if missing. Relevant things will be updated
only when needed.
- # We don't want to go around resetting caches all over the
place if avoidable...
- $fileSHA1Keys = isset( $parserOut->fr_fileSHA1Keys ) ?
- $parserOut->fr_fileSHA1Keys : array();
- # Add on any new items
- $out->fr_fileSHA1Keys = wfArrayMerge( $out->fr_fileSHA1Keys,
$fileSHA1Keys );
- return true;
- }
-
public static function onParserFirstCallInit( &$parser ) {
$parser->setFunctionHook( 'pagesusingpendingchanges',
'FlaggedRevsHooks::parserPagesUsingPendingChanges' );
@@ -488,9 +428,9 @@
}
public static function onParserGetVariableValueSwitch( &$parser,
&$cache, &$word, &$ret ) {
- if( $word == 'pendingchangelevel' ) {
+ if ( $word == 'pendingchangelevel' ) {
$title = $parser->getTitle();
- if( !FlaggedRevs::inReviewNamespace( $title ) ) {
+ if ( !FlaggedRevs::inReviewNamespace( $title ) ) {
$ret = '';
} else {
$config =
FlaggedPageConfig::getPageStabilitySettings( $title );
@@ -2034,4 +1974,4 @@
}
return true;
}
-}
\ No newline at end of file
+}
Modified: trunk/extensions/FlaggedRevs/FlaggedRevs.php
===================================================================
--- trunk/extensions/FlaggedRevs/FlaggedRevs.php 2011-03-23 18:23:55 UTC
(rev 84618)
+++ trunk/extensions/FlaggedRevs/FlaggedRevs.php 2011-03-23 18:27:50 UTC
(rev 84619)
@@ -438,9 +438,6 @@
$wgHooks['BeforeParserFetchTemplateAndtitle'][] =
'FlaggedRevsHooks::parserFetchStableTemplate';
$wgHooks['BeforeParserMakeImageLinkObj'][] =
'FlaggedRevsHooks::parserFetchStableFile';
$wgHooks['BeforeGalleryFindFile'][] =
'FlaggedRevsHooks::galleryFetchStableFile';
-# Additional parser versioning
-$wgHooks['ParserAfterTidy'][] = 'FlaggedRevsHooks::parserInjectTimestamps';
-$wgHooks['OutputPageParserOutput'][] =
'FlaggedRevsHooks::outputInjectTimestamps';
# ########
# ######## DB write operations #########
@@ -631,4 +628,4 @@
}
# B/C ...
-$wgLogActions['rights/erevoke'] = 'rights-editor-revoke';
+$wgLogActions['rights/erevoke'] = 'rights-editor-revoke';
\ No newline at end of file
Modified: trunk/extensions/FlaggedRevs/api/ApiReview.php
===================================================================
--- trunk/extensions/FlaggedRevs/api/ApiReview.php 2011-03-23 18:23:55 UTC
(rev 84618)
+++ trunk/extensions/FlaggedRevs/api/ApiReview.php 2011-03-23 18:27:50 UTC
(rev 84619)
@@ -72,7 +72,7 @@
$parserCache = ParserCache::singleton();
$parserOutput = $parserCache->get( $article,
$wgOut->parserOptions() );
}
- if ( !$parserOutput || !isset(
$parserOutput->fr_fileSHA1Keys ) ) {
+ if ( !$parserOutput || !isset(
$parserOutput->mImageTimeKeys ) ) {
// Miss, we have to reparse the page
$text = $article->getContent();
$options = FlaggedRevs::makeParserOptions();
@@ -82,7 +82,7 @@
// Set version parameters for review submission
list( $templateParams, $imageParams, $fileVersion ) =
RevisionReviewForm::getIncludeParams( $article,
- $parserOutput->mTemplateIds,
$parserOutput->fr_fileSHA1Keys );
+ $parserOutput->mTemplateIds,
$parserOutput->mImageTimeKeys );
$form->setTemplateParams( $templateParams );
$form->setFileParams( $imageParams );
$form->setFileVersion( $fileVersion );
Modified: trunk/extensions/FlaggedRevs/forms/RevisionReviewForm.php
===================================================================
--- trunk/extensions/FlaggedRevs/forms/RevisionReviewForm.php 2011-03-23
18:23:55 UTC (rev 84618)
+++ trunk/extensions/FlaggedRevs/forms/RevisionReviewForm.php 2011-03-23
18:27:50 UTC (rev 84619)
@@ -542,7 +542,7 @@
* Get template and image parameters from parser output to use on forms.
* @param FlaggedArticle $article
* @param array $templateIDs (from
ParserOutput/OutputPage->mTemplateIds)
- * @param array $imageSHA1Keys (from
ParserOutput/OutputPage->fr_fileSHA1Keys)
+ * @param array $imageSHA1Keys (from
ParserOutput/OutputPage->mImageTimeKeys)
* @returns array( templateParams, imageParams, fileVersion )
*/
public static function getIncludeParams(
@@ -558,7 +558,7 @@
}
# Image -> timestamp -> sha1 mapping
foreach ( $imageSHA1Keys as $dbKey => $timeAndSHA1 ) {
- $imageParams .= $dbKey . "|" . $timeAndSHA1['ts'];
+ $imageParams .= $dbKey . "|" . $timeAndSHA1['time'];
$imageParams .= "|" . $timeAndSHA1['sha1'] . "#";
}
# For image pages, note the displayed image version
@@ -577,7 +577,7 @@
* @param string $imageParams
* @returns array( templateIds, fileSHA1Keys )
* templateIds like ParserOutput->mTemplateIds
- * fileSHA1Keys like ParserOutput->fr_fileSHA1Keys
+ * fileSHA1Keys like ParserOutput->mImageTimeKeys
*/
public static function getIncludeVersions( $templateParams,
$imageParams ) {
$templateIds = array();
@@ -613,15 +613,15 @@
if ( !isset( $m[0] ) || !isset( $m[1] ) || !isset(
$m[2] ) || !$m[0] ) {
continue;
}
- list( $dbkey, $timestamp, $key ) = $m;
+ list( $dbkey, $time, $key ) = $m;
# Get the file title
$img_title = Title::makeTitle( NS_IMAGE, $dbkey ); //
Normalize
if ( is_null( $img_title ) ) {
continue; // Page must be valid!
}
$fileSHA1Keys[$img_title->getDBkey()] = array();
- $fileSHA1Keys[$img_title->getDBkey()]['ts'] =
$timestamp;
- $fileSHA1Keys[$img_title->getDBkey()]['sha1'] = $key;
+ $fileSHA1Keys[$img_title->getDBkey()]['time'] = $time ?
$time : '0';
+ $fileSHA1Keys[$img_title->getDBkey()]['sha1'] = $key ?
$key : '';
}
return array( $templateIds, $fileSHA1Keys );
}
@@ -753,7 +753,7 @@
$pOutput = $parserCache->get( $article,
$wgOut->parserOptions() );
}
# Otherwise (or on cache miss), parse the rev text...
- if ( !$pOutput || !isset( $pOutput->fr_fileSHA1Keys ) )
{
+ if ( !$pOutput || !isset( $pOutput->mImageTimeKeys ) ) {
$text = $rev->getText();
$title = $article->getTitle();
$options = FlaggedRevs::makeParserOptions();
@@ -765,7 +765,7 @@
}
}
$templateIDs = $pOutput->mTemplateIds;
- $imageSHA1Keys = $pOutput->fr_fileSHA1Keys;
+ $imageSHA1Keys = $pOutput->mImageTimeKeys;
}
list( $templateParams, $imageParams, $fileVersion ) =
RevisionReviewForm::getIncludeParams( $article,
$templateIDs, $imageSHA1Keys );
Modified:
trunk/extensions/FlaggedRevs/maintenance/tests/FRInclusionManagerTest.php
===================================================================
--- trunk/extensions/FlaggedRevs/maintenance/tests/FRInclusionManagerTest.php
2011-03-23 18:23:55 UTC (rev 84618)
+++ trunk/extensions/FlaggedRevs/maintenance/tests/FRInclusionManagerTest.php
2011-03-23 18:27:50 UTC (rev 84619)
@@ -8,11 +8,11 @@
0 => array('ZZ' => 464, '0' => 13)
);
protected static $inputFiles = array(
- 'FileXX' => array('ts' => '20100405192110', 'sha1' => 'abc1'),
- 'FileYY' => array('ts' => '20000403101300', 'sha1' => 1134),
- 'FileZZ' => array('ts' => '0', 'sha1' => ''),
- 'Filele' => array('ts' => 0, 'sha1' => ''),
- '0' => array('ts' => '20000203101350', 'sha1' => 'ae33'),
+ 'FileXX' => array('time' => '20100405192110', 'sha1' => 'abc1'),
+ 'FileYY' => array('time' => '20000403101300', 'sha1' => 1134),
+ 'FileZZ' => array('time' => '0', 'sha1' => ''),
+ 'Filele' => array('time' => 0, 'sha1' => ''),
+ '0' => array('time' => '20000203101350', 'sha1' => 'ae33'),
);
/* output to test against (<test,NS,dbkey,expected rev ID>) */
protected static $reviewedOutputTemplates = array(
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs