Index: trunk/extensions/FlaggedRevs/maintenance/tests/FRInclusionManagerTest.php |
— | — | @@ -3,7 +3,7 @@ |
4 | 4 | class FRInclusionManagerTest extends PHPUnit_Framework_TestCase { |
5 | 5 | /* starting input */ |
6 | 6 | protected static $inputTemplates = array( |
7 | | - 10 => array('XX' => '1242', 'YY' => '0'), |
| 7 | + 10 => array('XX' => '1242', 'YY' => '0', 'KK' => false), |
8 | 8 | 4 => array('Cite' => '30', 'Moo' => 0), |
9 | 9 | 0 => array('ZZ' => 464, '0' => 13) |
10 | 10 | ); |
— | — | @@ -12,45 +12,50 @@ |
13 | 13 | 'FileYY' => array('time' => '20000403101300', 'sha1' => 1134), |
14 | 14 | 'FileZZ' => array('time' => '0', 'sha1' => ''), |
15 | 15 | 'Filele' => array('time' => 0, 'sha1' => ''), |
| 16 | + 'FileKK' => array('time' => false, 'sha1' => false), |
16 | 17 | '0' => array('time' => '20000203101350', 'sha1' => 'ae33'), |
17 | 18 | ); |
18 | 19 | /* output to test against (<test,NS,dbkey,expected rev ID>) */ |
19 | 20 | protected static $reviewedOutputTemplates = array( |
20 | | - array( "Output version when given '1224'", 10, 'XX', 1242 ), |
21 | | - array( "Output version when given '0'", 10, 'YY', 0 ), |
22 | | - array( "Output version when given '30'", 4, 'Cite', 30 ), |
23 | | - array( "Output version when given 0", 4, 'Moo', 0 ), |
24 | | - array( "Output version when given 464", 0, 'ZZ', 464 ), |
25 | | - array( "Output version when given 13", 0, '0', 13 ), |
26 | | - array( "Output version when not given", 0, 'Notexists', null ), |
| 21 | + array( "Output template version when given '1224'", 10, 'XX', 1242 ), |
| 22 | + array( "Output template version when given '0'", 10, 'YY', 0 ), |
| 23 | + array( "Output template version when given false", 10, 'KK', 0 ), |
| 24 | + array( "Output template version when given '30'", 4, 'Cite', 30 ), |
| 25 | + array( "Output template version when given 0", 4, 'Moo', 0 ), |
| 26 | + array( "Output template version when given 464", 0, 'ZZ', 464 ), |
| 27 | + array( "Output template version when given 13", 0, '0', 13 ), |
| 28 | + array( "Output template version when not given", 0, 'Notexists', null ), |
27 | 29 | ); |
28 | 30 | protected static $stableOutputTemplates = array( |
29 | | - array( "Output version when given '1224'", 10, 'XX', 1242 ), |
30 | | - array( "Output version when given '0'", 10, 'YY', 0 ), |
31 | | - array( "Output version when given '30'", 4, 'Cite', 30 ), |
32 | | - array( "Output version when given 0", 4, 'Moo', 0 ), |
33 | | - array( "Output version when given 464", 0, 'ZZ', 464 ), |
34 | | - array( "Output version when given 13", 0, '0', 13 ), |
35 | | - array( "Output version when not given", 0, 'NotexistsPage1111', 0 ), |
| 31 | + array( "Output template version when given '1224'", 10, 'XX', 1242 ), |
| 32 | + array( "Output template version when given '0'", 10, 'YY', 0 ), |
| 33 | + array( "Output template version when given false", 10, 'KK', 0 ), |
| 34 | + array( "Output template version when given '30'", 4, 'Cite', 30 ), |
| 35 | + array( "Output template version when given 0", 4, 'Moo', 0 ), |
| 36 | + array( "Output template version when given 464", 0, 'ZZ', 464 ), |
| 37 | + array( "Output template version when given 13", 0, '0', 13 ), |
| 38 | + array( "Output template version when not given", 0, 'NotexistsPage1111', 0 ), |
36 | 39 | ); |
37 | 40 | /* output to test against (<test,dbkey,expected TS,expected sha1>) */ |
38 | 41 | protected static $reviewedOutputFiles = array( |
39 | | - array( "Output version when given '20100405192110'/'abc1'", |
| 42 | + array( "Output file version when given '20100405192110'/'abc1'", |
40 | 43 | 'FileXX', '20100405192110', 'abc1'), |
41 | | - array( "Output version when given '20000403101300'/'ffc2'", |
| 44 | + array( "Output file version when given '20000403101300'/'ffc2'", |
42 | 45 | 'FileYY', '20000403101300', '1134'), |
43 | | - array( "Output version when given '0'/''", 'FileZZ', '0', ''), |
44 | | - array( "Output version when given 0/''", 'Filele', '0', ''), |
45 | | - array( "Output version when not given", 'Notgiven', null, null), |
| 46 | + array( "Output file version when given '0'/''", 'FileZZ', '0', false), |
| 47 | + array( "Output file version when given false/''", 'FileKK', '0', false), |
| 48 | + array( "Output file version when given 0/''", 'Filele', '0', false), |
| 49 | + array( "Output file version when not given", 'Notgiven', null, null), |
46 | 50 | ); |
47 | 51 | protected static $stableOutputFiles = array( |
48 | | - array( "Output version when given '20100405192110'/'abc1'", |
| 52 | + array( "Output file version when given '20100405192110'/'abc1'", |
49 | 53 | 'FileXX', '20100405192110', 'abc1'), |
50 | | - array( "Output version when given '20000403101300'/'ffc2'", |
| 54 | + array( "Output file version when given '20000403101300'/'ffc2'", |
51 | 55 | 'FileYY', '20000403101300', '1134'), |
52 | | - array( "Output version when given '0'/''", 'FileZZ', '0', ''), |
53 | | - array( "Output version when given 0/''", 'Filele', '0', ''), |
54 | | - array( "Output version when not given", 'NotexistsPage1111', '0', ''), |
| 56 | + array( "Output file version when given '0'/''", 'FileZZ', '0', false), |
| 57 | + array( "Output file version when given false/''", 'FileKK', '0', false), |
| 58 | + array( "Output file version when given 0/''", 'Filele', '0', false), |
| 59 | + array( "Output file version when not given", 'NotexistsPage1111', '0', false), |
55 | 60 | ); |
56 | 61 | |
57 | 62 | /** |
Index: trunk/extensions/FlaggedRevs/forms/RevisionReviewForm.php |
— | — | @@ -606,8 +606,8 @@ |
607 | 607 | continue; // Page must be valid! |
608 | 608 | } |
609 | 609 | $fileSHA1Keys[$img_title->getDBkey()] = array(); |
610 | | - $fileSHA1Keys[$img_title->getDBkey()]['time'] = $time ? $time : '0'; |
611 | | - $fileSHA1Keys[$img_title->getDBkey()]['sha1'] = $key ? $key : ''; |
| 610 | + $fileSHA1Keys[$img_title->getDBkey()]['time'] = $time ? $time : false; |
| 611 | + $fileSHA1Keys[$img_title->getDBkey()]['sha1'] = strlen( $key ) ? $key : false; |
612 | 612 | } |
613 | 613 | return array( $templateIds, $fileSHA1Keys ); |
614 | 614 | } |
Index: trunk/extensions/FlaggedRevs/FlaggedRevision.php |
— | — | @@ -281,7 +281,7 @@ |
282 | 282 | 'fi_rev_id' => $this->getRevId(), |
283 | 283 | 'fi_name' => $dbkey, |
284 | 284 | 'fi_img_sha1' => strval( $timeSHA1['sha1'] ), |
285 | | - 'fi_img_timestamp' => $timeSHA1['time'] ? // '0' => NULL |
| 285 | + 'fi_img_timestamp' => $timeSHA1['time'] ? // false => NULL |
286 | 286 | $dbw->timestamp( $timeSHA1['time'] ) : null |
287 | 287 | ); |
288 | 288 | } |
— | — | @@ -479,7 +479,7 @@ |
480 | 480 | * Get original template versions at time of review |
481 | 481 | * @param int $flags FR_MASTER |
482 | 482 | * @return Array file versions (dbKey => array('time' => MW timestamp,'sha1' => sha1) ) |
483 | | - * Note: '0' used for file timestamp if it didn't exist ('' for sha1) |
| 483 | + * Note: false used for file timestamp/sha1 if it didn't exist |
484 | 484 | */ |
485 | 485 | public function getFileVersions( $flags = 0 ) { |
486 | 486 | if ( $this->mFiles == null ) { |
— | — | @@ -492,11 +492,15 @@ |
493 | 493 | __METHOD__ |
494 | 494 | ); |
495 | 495 | foreach ( $res as $row ) { |
496 | | - $reviewedTS = trim( $row->fi_img_timestamp ); // may be ''/NULL |
497 | | - $reviewedTS = $reviewedTS ? wfTimestamp( TS_MW, $reviewedTS ) : '0'; |
| 496 | + $reviewedTS = $reviewedSha1 = false; |
| 497 | + $fi_img_timestamp = trim( $row->fi_img_timestamp ); // may have \0's |
| 498 | + if ( $fi_img_timestamp ) { |
| 499 | + $reviewedTS = wfTimestamp( TS_MW, $fi_img_timestamp ); |
| 500 | + $reviewedSha1 = strval( $row->fi_img_sha1 ); |
| 501 | + } |
498 | 502 | $this->mFiles[$row->fi_name] = array(); |
499 | 503 | $this->mFiles[$row->fi_name]['time'] = $reviewedTS; |
500 | | - $this->mFiles[$row->fi_name]['sha1'] = $row->fi_img_sha1; |
| 504 | + $this->mFiles[$row->fi_name]['sha1'] = $reviewedSha1; |
501 | 505 | } |
502 | 506 | } |
503 | 507 | return $this->mFiles; |
— | — | @@ -540,7 +544,7 @@ |
541 | 545 | * Get the current stable version of the files used at time of review |
542 | 546 | * @param int $flags FR_MASTER |
543 | 547 | * @return Array file versions (dbKey => array('time' => MW timestamp,'sha1' => sha1) ) |
544 | | - * Note: '0' used for file timestamp if it doesn't exist ('' for sha1) |
| 548 | + * Note: false used for file timestamp/sha1 if it didn't exist |
545 | 549 | */ |
546 | 550 | public function getStableFileVersions( $flags = 0 ) { |
547 | 551 | if ( $this->mStableFiles == null ) { |
— | — | @@ -558,12 +562,11 @@ |
559 | 563 | 'page_namespace = ' . NS_FILE . ' AND page_title = fi_name' ), |
560 | 564 | 'flaggedpages' => array( 'LEFT JOIN', 'fp_page_id = page_id' ), |
561 | 565 | 'flaggedrevs' => array( 'LEFT JOIN', |
562 | | - 'fr_page_id = fp_page_id AND fr_rev_id = fp_stable' ) |
| 566 | + 'fr_page_id = fp_page_id AND fr_rev_id = fp_stable' ) |
563 | 567 | ) |
564 | 568 | ); |
565 | 569 | foreach ( $res as $row ) { |
566 | | - $reviewedTS = '0'; |
567 | | - $reviewedSha1 = ''; |
| 570 | + $reviewedTS = $reviewedSha1 = false; |
568 | 571 | if ( $row->fr_img_timestamp ) { |
569 | 572 | $reviewedTS = wfTimestamp( TS_MW, $row->fr_img_timestamp ); |
570 | 573 | $reviewedSha1 = strval( $row->fr_img_sha1 ); |
— | — | @@ -691,7 +694,7 @@ |
692 | 695 | $fileChanges = array(); |
693 | 696 | foreach ( $ret as $row ) { |
694 | 697 | $title = Title::makeTitleSafe( NS_FILE, $row->il_to ); |
695 | | - $reviewedTS = trim( $row->fi_img_timestamp ); // may be ''/NULL |
| 698 | + $reviewedTS = trim( $row->fi_img_timestamp ); // may have \0's |
696 | 699 | $reviewedTS = $reviewedTS ? wfTimestamp( TS_MW, $reviewedTS ) : null; |
697 | 700 | if ( FlaggedRevs::inclusionSetting() == FR_INCLUDES_STABLE ) { |
698 | 701 | $stableTS = wfTimestampOrNull( TS_MW, $row->fr_img_timestamp ); |
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php |
— | — | @@ -296,7 +296,7 @@ |
297 | 297 | if ( !$incManager->parserOutputIsStabilized() ) { |
298 | 298 | return true; // trigger for stable version parsing only |
299 | 299 | } |
300 | | - $id = false; // current |
| 300 | + $id = false; // current version |
301 | 301 | # Check for the version of this template used when reviewed... |
302 | 302 | $maybeId = $incManager->getReviewedTemplateVersion( $title ); |
303 | 303 | if ( $maybeId !== null ) { |
— | — | @@ -320,7 +320,7 @@ |
321 | 321 | /** |
322 | 322 | * Select the desired images based on the selected stable version time/SHA-1 |
323 | 323 | */ |
324 | | - public static function parserFetchStableFile( $parser, Title $nt, &$time, &$sha1, &$query ) { |
| 324 | + public static function parserFetchStableFile( $parser, Title $title, &$time, &$sha1, &$query ) { |
325 | 325 | if ( !( $parser instanceof Parser ) ) { |
326 | 326 | return true; // nothing to do |
327 | 327 | } |
— | — | @@ -329,18 +329,17 @@ |
330 | 330 | return true; // trigger for stable version parsing only |
331 | 331 | } |
332 | 332 | # Normalize NS_MEDIA to NS_FILE |
333 | | - if ( $nt->getNamespace() == NS_MEDIA ) { |
334 | | - $title = Title::makeTitle( NS_FILE, $nt->getDBkey() ); |
335 | | - $title->resetArticleId( $nt->getArticleId() ); // avoid extra queries |
| 333 | + if ( $title->getNamespace() == NS_MEDIA ) { |
| 334 | + $title = Title::makeTitle( NS_FILE, $title->getDBkey() ); |
| 335 | + $title->resetArticleId( $title->getArticleId() ); // avoid extra queries |
336 | 336 | } else { |
337 | | - $title =& $nt; |
| 337 | + $title =& $title; |
338 | 338 | } |
339 | | - $time = false; // current version |
340 | | - $sha1 = false; // corresponds to $time |
| 339 | + $time = $sha1 = false; // current version |
341 | 340 | # Check for the version of this file used when reviewed... |
342 | 341 | list( $maybeTS, $maybeSha1 ) = $incManager->getReviewedFileVersion( $title ); |
343 | 342 | if ( $maybeTS !== null ) { |
344 | | - $time = $maybeTS; // use if specified (even "0") |
| 343 | + $time = $maybeTS; // use if specified (even '0') |
345 | 344 | $sha1 = $maybeSha1; |
346 | 345 | } |
347 | 346 | # Check for stable version of file if this feature is enabled... |
Index: trunk/extensions/FlaggedRevs/FRInclusionManager.php |
— | — | @@ -34,7 +34,7 @@ |
35 | 35 | $this->stableVersions['templates'] = array(); |
36 | 36 | $this->stableVersions['files'] = array(); |
37 | 37 | } |
38 | | - |
| 38 | + |
39 | 39 | /** |
40 | 40 | * (a) Stabilize inclusions in Parser output |
41 | 41 | * (b) Set the template/image versions used in the flagged version of a revision |
— | — | @@ -43,8 +43,8 @@ |
44 | 44 | */ |
45 | 45 | public function setReviewedVersions( array $tmpParams, array $imgParams ) { |
46 | 46 | $this->reviewedVersions = array(); |
47 | | - $this->reviewedVersions['templates'] = $tmpParams; |
48 | | - $this->reviewedVersions['files'] = $imgParams; |
| 47 | + $this->reviewedVersions['templates'] = self::formatTemplateArray( $tmpParams ); |
| 48 | + $this->reviewedVersions['files'] = self::formatFileArray( $imgParams ); |
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
— | — | @@ -53,11 +53,46 @@ |
54 | 54 | * @param array $imgParams (dbKey => array('time' => MW timestamp,'sha1' => sha1) ) |
55 | 55 | */ |
56 | 56 | public function setStableVersionCache( array $tmpParams, array $imgParams ) { |
57 | | - $this->stableVersions['templates'] = $tmpParams; |
58 | | - $this->stableVersions['files'] = $imgParams; |
| 57 | + $this->stableVersions['templates'] = self::formatTemplateArray( $tmpParams ); |
| 58 | + $this->stableVersions['files'] = self::formatFileArray( $imgParams ); |
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
| 62 | + * Clean up a template version array |
| 63 | + * @param array $tmpParams (ns => dbKey => revId ) |
| 64 | + * @returns Array |
| 65 | + */ |
| 66 | + protected function formatTemplateArray( array $params ) { |
| 67 | + $res = array(); |
| 68 | + foreach ( $params as $ns => $templates ) { |
| 69 | + $res[$ns] = array(); |
| 70 | + foreach ( $templates as $dbKey => $revId ) { |
| 71 | + $res[$ns][$dbKey] = (int)$revId; |
| 72 | + } |
| 73 | + } |
| 74 | + return $res; |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * Clean up a file version array |
| 79 | + * @param array $imgParams (dbKey => array('time' => MW timestamp,'sha1' => sha1) ) |
| 80 | + * @returns Array |
| 81 | + */ |
| 82 | + protected function formatFileArray( array $params ) { |
| 83 | + $res = array(); |
| 84 | + foreach ( $params as $dbKey => $timeKey ) { |
| 85 | + $time = '0'; // missing |
| 86 | + $sha1 = false; |
| 87 | + if ( $timeKey['time'] ) { |
| 88 | + $time = $timeKey['time']; |
| 89 | + $sha1 = strval( $timeKey['sha1'] ); |
| 90 | + } |
| 91 | + $res[$dbKey] = array( 'time' => $time, 'sha1' => $sha1 ); |
| 92 | + } |
| 93 | + return $res; |
| 94 | + } |
| 95 | + |
| 96 | + /** |
62 | 97 | * (a) Stabilize inclusions in Parser output |
63 | 98 | * (b) Load all of the "at review time" versions of template/files |
64 | 99 | * (c) Load their stable version counterparts (avoids DB hits) |
— | — | @@ -150,8 +185,8 @@ |
151 | 186 | */ |
152 | 187 | public function getStableFileVersion( Title $title ) { |
153 | 188 | $dbKey = $title->getDBkey(); |
154 | | - $time = '0'; |
155 | | - $sha1 = ''; |
| 189 | + $time = '0'; // missing |
| 190 | + $sha1 = false; |
156 | 191 | # All NS_FILE, no need to check namespace |
157 | 192 | if ( isset( $this->stableVersions['files'][$dbKey] ) ) { |
158 | 193 | $time = $this->stableVersions['files'][$dbKey]['time']; |
— | — | @@ -160,7 +195,7 @@ |
161 | 196 | } |
162 | 197 | $srev = FlaggedRevision::newFromStable( $title ); |
163 | 198 | if ( $srev && $srev->getFileTimestamp() ) { |
164 | | - $time = $srev->getFileTimestamp(); // TS or null |
| 199 | + $time = $srev->getFileTimestamp(); |
165 | 200 | $sha1 = $srev->getFileSha1(); |
166 | 201 | } |
167 | 202 | $this->stableVersions['files'][$dbKey] = array(); |