Index: trunk/phase3/includes/ImagePage.php |
— | — | @@ -474,6 +474,7 @@ |
475 | 475 | $wgRequest->response()->header( 'HTTP/1.1 404 Not Found' ); |
476 | 476 | } |
477 | 477 | } |
| 478 | + $wgOut->setFileVersion( $this->displayImg ); |
478 | 479 | } |
479 | 480 | |
480 | 481 | /** |
Index: trunk/phase3/includes/OutputPage.php |
— | — | @@ -190,6 +190,8 @@ |
191 | 191 | /// should be private. To include the variable {{REVISIONID}} |
192 | 192 | var $mRevisionId = null; |
193 | 193 | |
| 194 | + var $mFileVersion = null; |
| 195 | + |
194 | 196 | private $mContext; |
195 | 197 | |
196 | 198 | /** |
— | — | @@ -1290,7 +1292,7 @@ |
1291 | 1293 | } |
1292 | 1294 | |
1293 | 1295 | /** |
1294 | | - * Get the current revision ID |
| 1296 | + * Get the displayed revision ID |
1295 | 1297 | * |
1296 | 1298 | * @return Integer |
1297 | 1299 | */ |
— | — | @@ -1299,6 +1301,28 @@ |
1300 | 1302 | } |
1301 | 1303 | |
1302 | 1304 | /** |
| 1305 | + * Set the displayed file version |
| 1306 | + * |
| 1307 | + * @param $file File|false |
| 1308 | + * @return Mixed: previous value |
| 1309 | + */ |
| 1310 | + public function setFileVersion( $file ) { |
| 1311 | + if ( $file instanceof File && $file->exists() ) { |
| 1312 | + $val = array( 'time' => $file->getTimestamp(), 'sha1' => $file->getSha1() ); |
| 1313 | + } |
| 1314 | + return wfSetVar( $this->mFileVersion, $val ); |
| 1315 | + } |
| 1316 | + |
| 1317 | + /** |
| 1318 | + * Get the displayed file version |
| 1319 | + * |
| 1320 | + * @return Array|null ('time' => MW timestamp, 'sha1' => sha1) |
| 1321 | + */ |
| 1322 | + public function getFileVersion() { |
| 1323 | + return $this->mFileVersion; |
| 1324 | + } |
| 1325 | + |
| 1326 | + /** |
1303 | 1327 | * Get the templates used on this page |
1304 | 1328 | * |
1305 | 1329 | * @return Array (namespace => dbKey => revId) |
Index: trunk/extensions/FlaggedRevs/api/actions/ApiReview.php |
— | — | @@ -67,18 +67,25 @@ |
68 | 68 | } |
69 | 69 | if ( $form->getAction() === 'approve' ) { |
70 | 70 | $article = new FlaggedPage( $title ); |
| 71 | + // Get the file version used for File: pages |
| 72 | + $file = $article->getFile(); |
| 73 | + if ( $file ) { |
| 74 | + $fileVer = array( 'time' => $file->getTimestamp(), 'sha1' => $file->getSha1() ); |
| 75 | + } else { |
| 76 | + $fileVer = null; |
| 77 | + } |
71 | 78 | // Now get the template and image parameters needed |
72 | 79 | list( $templateIds, $fileTimeKeys ) = |
73 | 80 | FRInclusionCache::getRevIncludes( $article, $rev, $wgUser ); |
74 | 81 | // Get version parameters for review submission (flat strings) |
75 | | - list( $templateParams, $imageParams, $fileVersion ) = |
76 | | - RevisionReviewForm::getIncludeParams( $article, $templateIds, $fileTimeKeys ); |
| 82 | + list( $templateParams, $imageParams, $fileParam ) = |
| 83 | + RevisionReviewForm::getIncludeParams( $templateIds, $fileTimeKeys, $fileVer ); |
77 | 84 | // Set the version parameters... |
78 | 85 | $form->setTemplateParams( $templateParams ); |
79 | 86 | $form->setFileParams( $imageParams ); |
80 | | - $form->setFileVersion( $fileVersion ); |
| 87 | + $form->setFileVersion( $fileParam ); |
81 | 88 | $key = RevisionReviewForm::validationKey( |
82 | | - $templateParams, $imageParams, $fileVersion, $revid ); |
| 89 | + $templateParams, $imageParams, $fileParam, $revid ); |
83 | 90 | $form->setValidatedParams( $key ); # always OK |
84 | 91 | } |
85 | 92 | $status = $form->ready(); // all params set |
Index: trunk/extensions/FlaggedRevs/business/RevisionReviewForm.php |
— | — | @@ -499,15 +499,15 @@ |
500 | 500 | |
501 | 501 | /** |
502 | 502 | * Get template and image parameters from parser output to use on forms. |
503 | | - * @param FlaggedPage $article |
504 | | - * @param array $templateIDs (from ParserOutput/OutputPage->mTemplateIds) |
505 | | - * @param array $imageSHA1Keys (from ParserOutput/OutputPage->mImageTimeKeys) |
| 503 | + * @param $templateIDs Array (from ParserOutput/OutputPage->mTemplateIds) |
| 504 | + * @param $imageSHA1Keys Array (from ParserOutput/OutputPage->mImageTimeKeys) |
| 505 | + * @param $fileVersion Array|null version of file for File: pages (time,sha1) |
506 | 506 | * @return array( templateParams, imageParams, fileVersion ) |
507 | 507 | */ |
508 | 508 | public static function getIncludeParams( |
509 | | - FlaggedPage $article, array $templateIDs, array $imageSHA1Keys |
| 509 | + array $templateIDs, array $imageSHA1Keys, $fileVersion |
510 | 510 | ) { |
511 | | - $templateParams = $imageParams = $fileVersion = ''; |
| 511 | + $templateParams = $imageParams = $fileParam = ''; |
512 | 512 | # NS -> title -> rev ID mapping |
513 | 513 | foreach ( $templateIDs as $namespace => $t ) { |
514 | 514 | foreach ( $t as $dbKey => $revId ) { |
— | — | @@ -519,14 +519,11 @@ |
520 | 520 | foreach ( $imageSHA1Keys as $dbKey => $timeAndSHA1 ) { |
521 | 521 | $imageParams .= $dbKey . "|" . $timeAndSHA1['time'] . "|" . $timeAndSHA1['sha1'] . "#"; |
522 | 522 | } |
523 | | - # For image pages, note the displayed image version |
524 | | - if ( $article->getTitle()->getNamespace() == NS_FILE ) { |
525 | | - $file = $article->getDisplayedFile(); // File obj |
526 | | - if ( $file ) { |
527 | | - $fileVersion = $file->getTimestamp() . "#" . $file->getSha1(); |
528 | | - } |
| 523 | + # For File: pages, note the displayed image version |
| 524 | + if ( is_array( $fileVersion ) ) { |
| 525 | + $fileParam = $fileVersion['time'] . "#" . $fileVersion['sha1']; |
529 | 526 | } |
530 | | - return array( $templateParams, $imageParams, $fileVersion ); |
| 527 | + return array( $templateParams, $imageParams, $fileParam ); |
531 | 528 | } |
532 | 529 | |
533 | 530 | /** |
Index: trunk/extensions/FlaggedRevs/presentation/FlaggedPageView.php |
— | — | @@ -1082,13 +1082,22 @@ |
1083 | 1083 | } |
1084 | 1084 | # Review notice box goes in top of form |
1085 | 1085 | $form->setTopNotice( $this->diffNoticeBox ); |
| 1086 | + |
| 1087 | + # Set the file version we are viewing (for File: pages) |
| 1088 | + $form->setFileVersion( $this->out->getFileVersion() ); |
1086 | 1089 | # $wgOut may not already have the inclusion IDs, such as for diffonly=1. |
1087 | 1090 | # RevisionReviewForm will fetch them as needed however. |
1088 | 1091 | if ( $this->out->getRevisionId() == $rev->getId() ) { |
1089 | | - $form->setIncludeVersions( $this->out->getTemplateIds(), $this->out->getImageTimeKeys() ); |
1090 | | - } elseif ( $this->oldRevIncludes ) { |
1091 | | - $form->setIncludeVersions( $this->oldRevIncludes[0], $this->oldRevIncludes[1] ); |
| 1092 | + $tmpVers = $this->out->getTemplateIds(); |
| 1093 | + $fileVers = $this->out->getImageTimeKeys(); |
| 1094 | + } elseif ( $this->oldRevIncludes ) { // e.g. diffonly=1, stable diff |
| 1095 | + list( $tmpVers, $fileVers ) = $this->oldRevIncludes; |
| 1096 | + } else { // e.g. diffonly=1, other diffs |
| 1097 | + list( $tmpVers, $fileVers ) = |
| 1098 | + FRInclusionCache::getRevIncludes( $this->article, $rev, $wgUser ); |
1092 | 1099 | } |
| 1100 | + $form->setIncludeVersions( $tmpVers, $fileVers ); |
| 1101 | + |
1093 | 1102 | list( $html, $status ) = $form->getHtml(); |
1094 | 1103 | # Diff action: place the form at the top of the page |
1095 | 1104 | if ( $this->diffRevs ) { |
— | — | @@ -1379,11 +1388,11 @@ |
1380 | 1389 | # Otherwise, check for includes pending on top of edits pending... |
1381 | 1390 | } else { |
1382 | 1391 | $incs = FRInclusionCache::getRevIncludes( $this->article, $newRev, $wgUser ); |
| 1392 | + $this->oldRevIncludes = $incs; // process cache |
1383 | 1393 | # Add a list of links to each changed template... |
1384 | 1394 | $changeList = self::fetchTemplateChanges( $srev, $incs[0] ); |
1385 | 1395 | # Add a list of links to each changed file... |
1386 | 1396 | $changeList = array_merge( $changeList, self::fetchFileChanges( $srev, $incs[1] ) ); |
1387 | | - $this->oldRevIncludes = $incs; // process cache |
1388 | 1397 | } |
1389 | 1398 | # If there are pending revs or templates/files changes, notify the user... |
1390 | 1399 | if ( $this->article->revsArePending() || count( $changeList ) ) { |
Index: trunk/extensions/FlaggedRevs/presentation/RevisionReviewFormUI.php |
— | — | @@ -8,7 +8,9 @@ |
9 | 9 | protected $user, $article, $rev; |
10 | 10 | protected $refRev = null; |
11 | 11 | protected $topNotice = ''; |
12 | | - protected $templateIDs = null, $imageSHA1Keys = null; |
| 12 | + protected $fileVersion = null; |
| 13 | + protected $templateIDs = null; |
| 14 | + protected $imageSHA1Keys = null; |
13 | 15 | |
14 | 16 | /** |
15 | 17 | * Generates a brief review form for a page |
— | — | @@ -41,7 +43,15 @@ |
42 | 44 | } |
43 | 45 | |
44 | 46 | /* |
45 | | - * Set the template/file version parameters corresponding to what the user is viewing |
| 47 | + * Set the file version parameters of what the user is viewing |
| 48 | + * @param Array|null $version ('time' => MW timestamp, 'sha1' => sha1) |
| 49 | + */ |
| 50 | + public function setFileVersion( $version ) { |
| 51 | + $this->fileVersion = is_array( $version ) ? $version : false; |
| 52 | + } |
| 53 | + |
| 54 | + /* |
| 55 | + * Set the template/file version parameters of what the user is viewing |
46 | 56 | * @param string $topNotice Text to |
47 | 57 | */ |
48 | 58 | public function setIncludeVersions( array $templateIDs, array $imageSHA1Keys ) { |
— | — | @@ -153,11 +163,13 @@ |
154 | 164 | $form .= self::ratingInputs( $this->user, $flags, (bool)$disabled, (bool)$frev ); |
155 | 165 | $form .= Xml::closeElement( 'span' ) . "\n"; |
156 | 166 | |
| 167 | + # Get the file version used for File: pages as needed |
| 168 | + $fileKey = $this->getFileVersion(); |
157 | 169 | # Get template/file version info as needed |
158 | 170 | list( $templateIDs, $imageSHA1Keys ) = $this->getIncludeVersions(); |
159 | 171 | # Convert these into flat string params |
160 | 172 | list( $templateParams, $imageParams, $fileVersion ) = |
161 | | - RevisionReviewForm::getIncludeParams( $article, $templateIDs, $imageSHA1Keys ); |
| 173 | + RevisionReviewForm::getIncludeParams( $templateIDs, $imageSHA1Keys, $fileKey ); |
162 | 174 | |
163 | 175 | $form .= Xml::openElement( 'span', |
164 | 176 | array( 'style' => 'white-space: nowrap;' ) ) . "\n"; |
— | — | @@ -395,11 +407,16 @@ |
396 | 408 | return $s; |
397 | 409 | } |
398 | 410 | |
| 411 | + protected function getFileVersion() { |
| 412 | + if ( $this->fileVersion === null ) { |
| 413 | + throw new MWException( "File page file version not provided to review form; call setFileVersion()." ); |
| 414 | + } |
| 415 | + return $this->fileVersion; |
| 416 | + } |
| 417 | + |
399 | 418 | protected function getIncludeVersions() { |
400 | | - # Do we need to get inclusion IDs from parser output? |
401 | 419 | if ( $this->templateIDs === null || $this->imageSHA1Keys === null ) { |
402 | | - list( $this->templateIDs, $this->imageSHA1Keys ) = |
403 | | - FRInclusionCache::getRevIncludes( $this->article, $this->rev, $this->user ); |
| 420 | + throw new MWException( "Template or file versions not provided to review form; call setIncludeVersions()." ); |
404 | 421 | } |
405 | 422 | return array( $this->templateIDs, $this->imageSHA1Keys ); |
406 | 423 | } |
Index: trunk/extensions/FlaggedRevs/dataclasses/FlaggedPage.php |
— | — | @@ -13,7 +13,7 @@ |
14 | 14 | protected $pageConfig = null; |
15 | 15 | protected $syncedInTracking = null; |
16 | 16 | |
17 | | - protected $imagePage = null; // for file pages |
| 17 | + protected $file = null; // for file pages |
18 | 18 | |
19 | 19 | /** |
20 | 20 | * Get a FlaggedPage for a given title |
— | — | @@ -48,40 +48,22 @@ |
49 | 49 | $this->pendingRevCount = null; |
50 | 50 | $this->pageConfig = null; |
51 | 51 | $this->syncedInTracking = null; |
52 | | - $this->imagePage = null; |
| 52 | + $this->file = null; |
53 | 53 | parent::clear(); // call super! |
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
57 | | - * Get the current file version of this file page |
58 | | - * @TODO: kind of hacky |
59 | | - * @return mixed (File/false) |
| 57 | + * Get the current file version (null if this not a File page) |
| 58 | + * |
| 59 | + * @return File|null|false |
60 | 60 | */ |
61 | 61 | public function getFile() { |
62 | | - if ( $this->mTitle->getNamespace() != NS_FILE ) { |
63 | | - return false; // not a file page |
| 62 | + if ( $this->file === null && $this->mTitle->getNamespace() == NS_FILE ) { |
| 63 | + $this->file = wfFindFile( $this->mTitle ); |
64 | 64 | } |
65 | | - if ( is_null( $this->imagePage ) ) { |
66 | | - $this->imagePage = new ImagePage( $this->mTitle ); |
67 | | - } |
68 | | - return $this->imagePage->getFile(); |
| 65 | + return $this->file; |
69 | 66 | } |
70 | 67 | |
71 | | - /** |
72 | | - * Get the displayed file version of this file page |
73 | | - * @TODO: kind of hacky |
74 | | - * @return mixed (File/false) |
75 | | - */ |
76 | | - public function getDisplayedFile() { |
77 | | - if ( $this->mTitle->getNamespace() != NS_FILE ) { |
78 | | - return false; // not a file page |
79 | | - } |
80 | | - if ( is_null( $this->imagePage ) ) { |
81 | | - $this->imagePage = new ImagePage( $this->mTitle ); |
82 | | - } |
83 | | - return $this->imagePage->getDisplayedFile(); |
84 | | - } |
85 | | - |
86 | 68 | /** |
87 | 69 | * Is the stable version shown by default for this page? |
88 | 70 | * @return bool |
Index: trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevs.class.php |
— | — | @@ -963,8 +963,10 @@ |
964 | 964 | # If this is an image page, store corresponding file info |
965 | 965 | $fileData = array( 'name' => null, 'timestamp' => null, 'sha1' => null ); |
966 | 966 | if ( $title->getNamespace() == NS_FILE ) { |
967 | | - $file = $article instanceof ImagePage ? |
968 | | - $article->getFile() : wfFindFile( $title ); |
| 967 | + # We must use ImagePage process cache on upload or get bitten by slave lag |
| 968 | + $file = $article instanceof ImagePage |
| 969 | + ? $article->getFile() |
| 970 | + : wfFindFile( $title ); |
969 | 971 | if ( is_object( $file ) && $file->exists() ) { |
970 | 972 | $fileData['name'] = $title->getDBkey(); |
971 | 973 | $fileData['timestamp'] = $file->getTimestamp(); |
Index: trunk/extensions/FlaggedRevs/dataclasses/FRInclusionCache.php |
— | — | @@ -68,7 +68,7 @@ |
69 | 69 | $revIdDraft = (int)$title->getLatestRevID(); |
70 | 70 | } |
71 | 71 | } |
72 | | - } |
| 72 | + } |
73 | 73 | wfProfileOut( __METHOD__ ); |
74 | 74 | return $versions; |
75 | 75 | } |