Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php |
— | — | @@ -224,6 +224,7 @@ |
225 | 225 | # Clean up after undeletion |
226 | 226 | $wgHooks['ArticleRevisionUndeleted'][] = 'FlaggedRevs::updateFromRestore'; |
227 | 227 | # Parser hooks, selects the desired images/templates |
| 228 | + $wgHooks['ParserBeforeStrip'][] = 'FlaggedRevs::parserAddFields'; |
228 | 229 | $wgHooks['BeforeParserrenderImageGallery'][] = 'FlaggedRevs::parserMakeGalleryStable'; |
229 | 230 | $wgHooks['BeforeGalleryFindFile'][] = 'FlaggedRevs::galleryFindStableFileTime'; |
230 | 231 | $wgHooks['BeforeParserFetchTemplateAndtitle'][] = 'FlaggedRevs::parserFetchStableTemplate'; |
— | — | @@ -351,7 +352,6 @@ |
352 | 353 | $wgParser->fr_isStable = true; |
353 | 354 | $wgParser->fr_includesMatched = true; |
354 | 355 | # Don't show section-edit links, they can be old and misleading |
355 | | - $options->setEditSection(false); |
356 | 356 | $options->setEditSection( $id==$article->getLatest() ); |
357 | 357 | # Parse the new body, wikitext -> html |
358 | 358 | $title = $article->getTitle(); // avoid pass-by-reference error |
— | — | @@ -380,11 +380,14 @@ |
381 | 381 | global $wgMemc; |
382 | 382 | # Try the cache. Uses format <page ID>-<UNIX timestamp>. |
383 | 383 | $key = wfMemcKey( 'flaggedrevs', 'syncStatus', $article->getId() . '-' . $article->getTouched() ); |
384 | | - $syncData = $wgMemc->get($key); |
| 384 | + $syncvalue = $wgMemc->get($key); |
385 | 385 | # 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 | + } |
389 | 392 | } |
390 | 393 | # If parseroutputs not given, fetch them... |
391 | 394 | if( is_null($flaggedOutput) || !isset($flaggedOutput->fr_newestTemplateID) ) { |
— | — | @@ -428,8 +431,7 @@ |
429 | 432 | # Save to cache. This will be updated whenever the page is re-parsed as well. This means |
430 | 433 | # that MW can check a light-weight key first. Uses format <page ID>-<UNIX timestamp>. |
431 | 434 | global $wgParserCacheExpireTime; |
432 | | - $syncData = $synced ? 'true' : 'false'; |
433 | | - $syncData .= '-' . $article->getTouched(); |
| 435 | + $syncData = $synced ? "true" : "false"; |
434 | 436 | $wgMemc->set( $key, $syncData, $wgParserCacheExpireTime ); |
435 | 437 | |
436 | 438 | return $synced; |
— | — | @@ -1185,6 +1187,17 @@ |
1186 | 1188 | wfProfileOut( __METHOD__ ); |
1187 | 1189 | return true; |
1188 | 1190 | } |
| 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 | + } |
1189 | 1202 | |
1190 | 1203 | /** |
1191 | 1204 | * Select the desired templates based on the selected stable revision IDs |
— | — | @@ -1245,23 +1258,29 @@ |
1246 | 1259 | # Check for stable version of image if this feature is enabled. |
1247 | 1260 | # Should be in reviewable namespace, this saves unneeded DB checks as |
1248 | 1261 | # well as enforce site settings if they are later changed. |
| 1262 | + $sha1 = ''; |
1249 | 1263 | global $wgUseStableImages, $wgFlaggedRevsNamespaces; |
1250 | 1264 | 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' ), |
1253 | 1267 | array( 'page_namespace' => $nt->getNamespace(), |
1254 | 1268 | 'page_title' => $nt->getDBkey(), |
1255 | 1269 | 'page_ext_stable = fi_rev_id', |
1256 | 1270 | 'fi_name' => $nt->getDBkey() ), |
1257 | 1271 | __METHOD__ ); |
| 1272 | + $time = $row ? $row->fi_img_timestamp : $time; |
| 1273 | + $sha1 = $row ? $row->fi_img_sha1 : $sha1; |
1258 | 1274 | } |
1259 | 1275 | # If there is no stable version (or that feature is not enabled), use |
1260 | 1276 | # the image revision during review time. |
1261 | 1277 | 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, |
1264 | 1281 | 'fi_name' => $nt->getDBkey() ), |
1265 | 1282 | __METHOD__ ); |
| 1283 | + $time = $row ? $row->fi_img_timestamp : $time; |
| 1284 | + $sha1 = $row ? $row->fi_img_sha1 : $sha1; |
1266 | 1285 | } |
1267 | 1286 | # If none specified, see if we are allowed to use the current revision |
1268 | 1287 | if( !$time ) { |
— | — | @@ -1271,11 +1290,22 @@ |
1272 | 1291 | $parser->fr_includesMatched = false; // May want to give an error |
1273 | 1292 | if( !$wgUseCurrentImages ) { |
1274 | 1293 | $time = -1; |
| 1294 | + } else { |
| 1295 | + $file = wFindFile( $nt ); |
| 1296 | + $time = $file ? $file->getTimestamp() : "0"; |
1275 | 1297 | } |
1276 | 1298 | } else { |
1277 | 1299 | $time = -1; |
1278 | 1300 | } |
1279 | 1301 | } |
| 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 | + |
1280 | 1310 | return true; |
1281 | 1311 | } |
1282 | 1312 | |
— | — | @@ -1293,27 +1323,45 @@ |
1294 | 1324 | # well as enforce site settings if they are later changed. |
1295 | 1325 | global $wgUseStableImages, $wgFlaggedRevsNamespaces; |
1296 | 1326 | 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' ), |
1299 | 1329 | array( 'page_namespace' => $nt->getNamespace(), |
1300 | 1330 | 'page_title' => $nt->getDBkey(), |
1301 | 1331 | 'page_ext_stable = fi_rev_id', |
1302 | 1332 | 'fi_name' => $nt->getDBkey() ), |
1303 | 1333 | __METHOD__ ); |
| 1334 | + $time = $row ? $row->fi_img_timestamp : $time; |
| 1335 | + $sha1 = $row ? $row->fi_img_sha1 : $sha1; |
1304 | 1336 | } |
1305 | 1337 | # If there is no stable version (or that feature is not enabled), use |
1306 | 1338 | # the image revision during review time. |
1307 | 1339 | if( !$time ) { |
1308 | | - $time = $dbw->selectField( 'flaggedimages', 'fi_img_timestamp', |
| 1340 | + $row = $dbw->selectRow( 'flaggedimages', |
| 1341 | + array( 'fi_img_timestamp', 'fi_img_sha1' ), |
1309 | 1342 | array('fi_rev_id' => $ig->mRevisionId, |
1310 | 1343 | 'fi_name' => $nt->getDBkey() ), |
1311 | 1344 | __METHOD__ ); |
| 1345 | + $time = $row ? $row->fi_img_timestamp : $time; |
| 1346 | + $sha1 = $row ? $row->fi_img_sha1 : $sha1; |
1312 | 1347 | } |
| 1348 | + # If none specified, see if we are allowed to use the current revision |
1313 | 1349 | if( !$time ) { |
| 1350 | + $ig->fr_parentParser->fr_includesMatched = false; // May want to give an error |
1314 | 1351 | 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 | + } |
1317 | 1358 | } |
| 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 | + } |
1318 | 1366 | |
1319 | 1367 | return true; |
1320 | 1368 | } |
— | — | @@ -1327,6 +1375,7 @@ |
1328 | 1376 | return true; |
1329 | 1377 | |
1330 | 1378 | $ig->fr_isStable = true; |
| 1379 | + $ig->fr_parentParser =& $parser; // hack |
1331 | 1380 | |
1332 | 1381 | return true; |
1333 | 1382 | } |
— | — | @@ -1365,10 +1414,25 @@ |
1366 | 1415 | * Insert image timestamps/SHA-1 keys into parser output |
1367 | 1416 | */ |
1368 | 1417 | 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 | + |
1370 | 1434 | $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 |
1373 | 1437 | if( !empty($parser->mOutput->mImages) ) { |
1374 | 1438 | $filenames = array_keys($parser->mOutput->mImages); |
1375 | 1439 | foreach( $filenames as $filename ) { |
— | — | @@ -1386,17 +1450,6 @@ |
1387 | 1451 | } |
1388 | 1452 | # Record the max timestamp |
1389 | 1453 | $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; |
1401 | 1454 | |
1402 | 1455 | return true; |
1403 | 1456 | } |
— | — | @@ -1572,7 +1625,7 @@ |
1573 | 1626 | $s = "\n<select id='namespace' name='namespace' class='namespaceselector'>\n"; |
1574 | 1627 | $arr = $wgContLang->getFormattedNamespaces(); |
1575 | 1628 | |
1576 | | - foreach($arr as $index => $name) { |
| 1629 | + foreach( $arr as $index => $name ) { |
1577 | 1630 | # Content only |
1578 | 1631 | if($index < NS_MAIN || !in_array($index, $wgFlaggedRevsNamespaces) ) |
1579 | 1632 | continue; |
Index: trunk/extensions/FlaggedRevs/flaggedrevs.css |
— | — | @@ -92,7 +92,7 @@ |
93 | 93 | margin-bottom: 0px; |
94 | 94 | text-align: left; |
95 | 95 | float: right; |
96 | | - width: 320px; |
| 96 | + width: 330px; |
97 | 97 | clear: both; |
98 | 98 | } |
99 | 99 | |
Index: trunk/extensions/FlaggedRevs/FlaggedRevsPage.i18n.php |
— | — | @@ -36,8 +36,8 @@ |
37 | 37 | 'validationpage' => '{{ns:help}}:Article validation', |
38 | 38 | |
39 | 39 | '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}}])', |
42 | 42 | '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}}])', |
43 | 43 | '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}}])', |
44 | 44 | 'revreview-quick-basic-same' => '\'\'\'[[{{MediaWiki:Validationpage}}|Sighted]]\'\'\' (no unreviewed changes)', |