r30818 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r30817‎ | r30818 | r30819 >
Date:02:38, 11 February 2008
Author:aaron
Status:old
Tags:
Comment:
Various fixes
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevsPage.i18n.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/flaggedrevs.css (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -224,6 +224,7 @@
225225 # Clean up after undeletion
226226 $wgHooks['ArticleRevisionUndeleted'][] = 'FlaggedRevs::updateFromRestore';
227227 # Parser hooks, selects the desired images/templates
 228+ $wgHooks['ParserBeforeStrip'][] = 'FlaggedRevs::parserAddFields';
228229 $wgHooks['BeforeParserrenderImageGallery'][] = 'FlaggedRevs::parserMakeGalleryStable';
229230 $wgHooks['BeforeGalleryFindFile'][] = 'FlaggedRevs::galleryFindStableFileTime';
230231 $wgHooks['BeforeParserFetchTemplateAndtitle'][] = 'FlaggedRevs::parserFetchStableTemplate';
@@ -351,7 +352,6 @@
352353 $wgParser->fr_isStable = true;
353354 $wgParser->fr_includesMatched = true;
354355 # Don't show section-edit links, they can be old and misleading
355 - $options->setEditSection(false);
356356 $options->setEditSection( $id==$article->getLatest() );
357357 # Parse the new body, wikitext -> html
358358 $title = $article->getTitle(); // avoid pass-by-reference error
@@ -380,11 +380,14 @@
381381 global $wgMemc;
382382 # Try the cache. Uses format <page ID>-<UNIX timestamp>.
383383 $key = wfMemcKey( 'flaggedrevs', 'syncStatus', $article->getId() . '-' . $article->getTouched() );
384 - $syncData = $wgMemc->get($key);
 384+ $syncvalue = $wgMemc->get($key);
385385 # Convert string value to boolean and return it
386 - if( $syncData ) {
387 - list($syncvalue,$timestamp) = explode('-',$syncData,2);
388 - return ( $syncvalue === 'true' ) ? true : false;
 386+ if( $syncvalue ) {
 387+ if( $syncvalue == "true" ) {
 388+ return true;
 389+ } else if( $syncvalue == "false" ) {
 390+ return false;
 391+ }
389392 }
390393 # If parseroutputs not given, fetch them...
391394 if( is_null($flaggedOutput) || !isset($flaggedOutput->fr_newestTemplateID) ) {
@@ -428,8 +431,7 @@
429432 # Save to cache. This will be updated whenever the page is re-parsed as well. This means
430433 # that MW can check a light-weight key first. Uses format <page ID>-<UNIX timestamp>.
431434 global $wgParserCacheExpireTime;
432 - $syncData = $synced ? 'true' : 'false';
433 - $syncData .= '-' . $article->getTouched();
 435+ $syncData = $synced ? "true" : "false";
434436 $wgMemc->set( $key, $syncData, $wgParserCacheExpireTime );
435437
436438 return $synced;
@@ -1185,6 +1187,17 @@
11861188 wfProfileOut( __METHOD__ );
11871189 return true;
11881190 }
 1191+
 1192+ /**
 1193+ * Add special fields to parser
 1194+ */
 1195+ public static function parserAddFields( $parser, $text, $stripState ) {
 1196+ $parser->mOutput->fr_ImageSHA1Keys = array();
 1197+ $parser->mOutput->fr_newestImageTime = "0";
 1198+ $parser->mOutput->fr_newestTemplateID = 0;
 1199+
 1200+ return true;
 1201+ }
11891202
11901203 /**
11911204 * Select the desired templates based on the selected stable revision IDs
@@ -1245,23 +1258,29 @@
12461259 # Check for stable version of image if this feature is enabled.
12471260 # Should be in reviewable namespace, this saves unneeded DB checks as
12481261 # well as enforce site settings if they are later changed.
 1262+ $sha1 = '';
12491263 global $wgUseStableImages, $wgFlaggedRevsNamespaces;
12501264 if( $wgUseStableImages && in_array($nt->getNamespace(),$wgFlaggedRevsNamespaces) ) {
1251 - $time = $dbw->selectField( array('page', 'flaggedimages'),
1252 - 'fi_img_timestamp',
 1265+ $row = $dbw->selectRow( array('page', 'flaggedimages'),
 1266+ array( 'fi_img_timestamp', 'fi_img_sha1' ),
12531267 array( 'page_namespace' => $nt->getNamespace(),
12541268 'page_title' => $nt->getDBkey(),
12551269 'page_ext_stable = fi_rev_id',
12561270 'fi_name' => $nt->getDBkey() ),
12571271 __METHOD__ );
 1272+ $time = $row ? $row->fi_img_timestamp : $time;
 1273+ $sha1 = $row ? $row->fi_img_sha1 : $sha1;
12581274 }
12591275 # If there is no stable version (or that feature is not enabled), use
12601276 # the image revision during review time.
12611277 if( !$time ) {
1262 - $time = $dbw->selectField( 'flaggedimages', 'fi_img_timestamp',
1263 - array('fi_rev_id' => $parser->mRevisionId,
 1278+ $row = $dbw->selectRow( 'flaggedimages',
 1279+ array( 'fi_img_timestamp', 'fi_img_sha1' ),
 1280+ array( 'fi_rev_id' => $parser->mRevisionId,
12641281 'fi_name' => $nt->getDBkey() ),
12651282 __METHOD__ );
 1283+ $time = $row ? $row->fi_img_timestamp : $time;
 1284+ $sha1 = $row ? $row->fi_img_sha1 : $sha1;
12661285 }
12671286 # If none specified, see if we are allowed to use the current revision
12681287 if( !$time ) {
@@ -1271,11 +1290,22 @@
12721291 $parser->fr_includesMatched = false; // May want to give an error
12731292 if( !$wgUseCurrentImages ) {
12741293 $time = -1;
 1294+ } else {
 1295+ $file = wFindFile( $nt );
 1296+ $time = $file ? $file->getTimestamp() : "0";
12751297 }
12761298 } else {
12771299 $time = -1;
12781300 }
12791301 }
 1302+ # Add image metadata to parser output
 1303+ $parser->mOutput->fr_ImageSHA1Keys[$nt->getDBkey()] = array();
 1304+ $parser->mOutput->fr_ImageSHA1Keys[$nt->getDBkey()][$time] = $sha1;
 1305+
 1306+ if( $time > $parser->mOutput->fr_newestImageTime ) {
 1307+ $parser->mOutput->fr_newestImageTime = $time;
 1308+ }
 1309+
12801310 return true;
12811311 }
12821312
@@ -1293,27 +1323,45 @@
12941324 # well as enforce site settings if they are later changed.
12951325 global $wgUseStableImages, $wgFlaggedRevsNamespaces;
12961326 if( $wgUseStableImages && in_array($nt->getNamespace(),$wgFlaggedRevsNamespaces) ) {
1297 - $time = $dbw->selectField( array('page', 'flaggedimages'),
1298 - 'fi_img_timestamp',
 1327+ $row = $dbw->selectRow( array('page', 'flaggedimages'),
 1328+ array( 'fi_img_timestamp', 'fi_img_sha1' ),
12991329 array( 'page_namespace' => $nt->getNamespace(),
13001330 'page_title' => $nt->getDBkey(),
13011331 'page_ext_stable = fi_rev_id',
13021332 'fi_name' => $nt->getDBkey() ),
13031333 __METHOD__ );
 1334+ $time = $row ? $row->fi_img_timestamp : $time;
 1335+ $sha1 = $row ? $row->fi_img_sha1 : $sha1;
13041336 }
13051337 # If there is no stable version (or that feature is not enabled), use
13061338 # the image revision during review time.
13071339 if( !$time ) {
1308 - $time = $dbw->selectField( 'flaggedimages', 'fi_img_timestamp',
 1340+ $row = $dbw->selectRow( 'flaggedimages',
 1341+ array( 'fi_img_timestamp', 'fi_img_sha1' ),
13091342 array('fi_rev_id' => $ig->mRevisionId,
13101343 'fi_name' => $nt->getDBkey() ),
13111344 __METHOD__ );
 1345+ $time = $row ? $row->fi_img_timestamp : $time;
 1346+ $sha1 = $row ? $row->fi_img_sha1 : $sha1;
13121347 }
 1348+ # If none specified, see if we are allowed to use the current revision
13131349 if( !$time ) {
 1350+ $ig->fr_parentParser->fr_includesMatched = false; // May want to give an error
13141351 global $wgUseCurrentImages;
1315 -
1316 - $time = $wgUseCurrentImages ? $time : -1;
 1352+ if( !$wgUseCurrentImages ) {
 1353+ $time = -1;
 1354+ } else {
 1355+ $file = wFindFile( $nt );
 1356+ $time = $file ? $file->getTimestamp() : "0";
 1357+ }
13171358 }
 1359+ # Add image metadata to parser output
 1360+ $ig->fr_parentParser->mOutput->fr_ImageSHA1Keys[$nt->getDBkey()] = array();
 1361+ $ig->fr_parentParser->mOutput->fr_ImageSHA1Keys[$nt->getDBkey()][$time] = $sha1;
 1362+
 1363+ if( $time > $ig->fr_parentParser->mOutput->fr_newestImageTime ) {
 1364+ $ig->fr_parentParser->mOutput->fr_newestImageTime = $time;
 1365+ }
13181366
13191367 return true;
13201368 }
@@ -1327,6 +1375,7 @@
13281376 return true;
13291377
13301378 $ig->fr_isStable = true;
 1379+ $ig->fr_parentParser =& $parser; // hack
13311380
13321381 return true;
13331382 }
@@ -1365,10 +1414,25 @@
13661415 * Insert image timestamps/SHA-1 keys into parser output
13671416 */
13681417 public static function parserInjectTimestamps( $parser, &$text ) {
1369 - $parser->mOutput->fr_ImageSHA1Keys = array();
 1418+ $maxRevision = 0;
 1419+ # Record the max template revision ID
 1420+ if( !empty($parser->mOutput->mTemplateIds) ) {
 1421+ foreach( $parser->mOutput->mTemplateIds as $namespace => $DBkey_rev ) {
 1422+ foreach( $DBkey_rev as $DBkey => $revID ) {
 1423+ if( $revID > $maxRevision ) {
 1424+ $maxRevision = $revID;
 1425+ }
 1426+ }
 1427+ }
 1428+ }
 1429+ # Don't trigger image stuff for stable version parsing.
 1430+ # It will do it on separately.
 1431+ if( isset($parser->fr_isStable) && $parser->fr_isStable )
 1432+ return true;
 1433+
13701434 $maxTimestamp = "0";
1371 - $maxRevision = 0;
1372 - # Fetch the timestamps of the images
 1435+ # Fetch the current timestamps of the images.
 1436+ # Don't do this for stable versions
13731437 if( !empty($parser->mOutput->mImages) ) {
13741438 $filenames = array_keys($parser->mOutput->mImages);
13751439 foreach( $filenames as $filename ) {
@@ -1386,17 +1450,6 @@
13871451 }
13881452 # Record the max timestamp
13891453 $parser->mOutput->fr_newestImageTime = $maxTimestamp;
1390 - # Record the max template revision ID
1391 - if( !empty($parser->mOutput->mTemplateIds) ) {
1392 - foreach( $parser->mOutput->mTemplateIds as $namespace => $DBkey_rev ) {
1393 - foreach( $DBkey_rev as $DBkey => $revID ) {
1394 - if( $revID > $maxRevision ) {
1395 - $maxRevision = $revID;
1396 - }
1397 - }
1398 - }
1399 - }
1400 - $parser->mOutput->fr_newestTemplateID = $maxRevision;
14011454
14021455 return true;
14031456 }
@@ -1572,7 +1625,7 @@
15731626 $s = "\n<select id='namespace' name='namespace' class='namespaceselector'>\n";
15741627 $arr = $wgContLang->getFormattedNamespaces();
15751628
1576 - foreach($arr as $index => $name) {
 1629+ foreach( $arr as $index => $name ) {
15771630 # Content only
15781631 if($index < NS_MAIN || !in_array($index, $wgFlaggedRevsNamespaces) )
15791632 continue;
Index: trunk/extensions/FlaggedRevs/flaggedrevs.css
@@ -92,7 +92,7 @@
9393 margin-bottom: 0px;
9494 text-align: left;
9595 float: right;
96 - width: 320px;
 96+ width: 330px;
9797 clear: both;
9898 }
9999
Index: trunk/extensions/FlaggedRevs/FlaggedRevsPage.i18n.php
@@ -36,8 +36,8 @@
3737 'validationpage' => '{{ns:help}}:Article validation',
3838
3939 'revreview-quick-none' => '\'\'\'Current\'\'\' (no reviewed revisions)',
40 - 'revreview-quick-see-quality' => '\'\'\'Draft\'\'\' [[{{fullurl:{{FULLPAGENAMEE}}|stable=1}} view stable article]] ($2 [{{fullurl:{{FULLPAGENAMEE}}|oldid=$1&diff=cur&editreview=1}} {{plural:$2|change|changes}}])',
41 - 'revreview-quick-see-basic' => '\'\'\'Draft\'\'\' [[{{fullurl:{{FULLPAGENAMEE}}|stable=1}} view stable article]] ($2 [{{fullurl:{{FULLPAGENAMEE}}|oldid=$1&diff=cur&editreview=1}} {{plural:$2|change|changes}}])',
 40+ 'revreview-quick-see-quality' => '\'\'\'Draft\'\'\' [[{{fullurl:{{FULLPAGENAMEE}}|stable=1}} view stable page]] ($2 [{{fullurl:{{FULLPAGENAMEE}}|oldid=$1&diff=cur&editreview=1}} {{plural:$2|change|changes}}])',
 41+ 'revreview-quick-see-basic' => '\'\'\'Draft\'\'\' [[{{fullurl:{{FULLPAGENAMEE}}|stable=1}} view stable page]] ($2 [{{fullurl:{{FULLPAGENAMEE}}|oldid=$1&diff=cur&editreview=1}} {{plural:$2|change|changes}}])',
4242 'revreview-quick-basic' => '\'\'\'[[{{MediaWiki:Validationpage}}|Sighted]]\'\'\' [[{{fullurl:{{FULLPAGENAMEE}}|stable=0}} view draft]] ($2 [{{fullurl:{{FULLPAGENAMEE}}|oldid=$1&diff=cur&editreview=1}} {{plural:$2|change|changes}}])',
4343 'revreview-quick-quality' => '\'\'\'[[{{MediaWiki:Validationpage}}|Quality]]\'\'\' [[{{fullurl:{{FULLPAGENAMEE}}|stable=0}} view draft]] ($2 [{{fullurl:{{FULLPAGENAMEE}}|oldid=$1&diff=cur&editreview=1}} {{plural:$2|change|changes}}])',
4444 'revreview-quick-basic-same' => '\'\'\'[[{{MediaWiki:Validationpage}}|Sighted]]\'\'\' (no unreviewed changes)',

Status & tagging log