r91435 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91434‎ | r91435 | r91436 >
Date:05:23, 5 July 2011
Author:aaron
Status:resolved (Comments)
Tags:
Comment:
* Added getFileVersion()/setFileVersion() functions to OutputPage
* Removed getDisplayedFile() from FlaggedPage and simplified getFile()
* Cleaned up getIncludeParams() to just do formatting
* Made template/file IDs mandatory for RevisionReviewFormUI
Modified paths:
  • /trunk/extensions/FlaggedRevs/api/actions/ApiReview.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/business/RevisionReviewForm.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/dataclasses/FRInclusionCache.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/dataclasses/FlaggedPage.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevs.class.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/presentation/FlaggedPageView.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/presentation/RevisionReviewFormUI.php (modified) (history)
  • /trunk/phase3/includes/ImagePage.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/ImagePage.php
@@ -474,6 +474,7 @@
475475 $wgRequest->response()->header( 'HTTP/1.1 404 Not Found' );
476476 }
477477 }
 478+ $wgOut->setFileVersion( $this->displayImg );
478479 }
479480
480481 /**
Index: trunk/phase3/includes/OutputPage.php
@@ -190,6 +190,8 @@
191191 /// should be private. To include the variable {{REVISIONID}}
192192 var $mRevisionId = null;
193193
 194+ var $mFileVersion = null;
 195+
194196 private $mContext;
195197
196198 /**
@@ -1290,7 +1292,7 @@
12911293 }
12921294
12931295 /**
1294 - * Get the current revision ID
 1296+ * Get the displayed revision ID
12951297 *
12961298 * @return Integer
12971299 */
@@ -1299,6 +1301,28 @@
13001302 }
13011303
13021304 /**
 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+ /**
13031327 * Get the templates used on this page
13041328 *
13051329 * @return Array (namespace => dbKey => revId)
Index: trunk/extensions/FlaggedRevs/api/actions/ApiReview.php
@@ -67,18 +67,25 @@
6868 }
6969 if ( $form->getAction() === 'approve' ) {
7070 $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+ }
7178 // Now get the template and image parameters needed
7279 list( $templateIds, $fileTimeKeys ) =
7380 FRInclusionCache::getRevIncludes( $article, $rev, $wgUser );
7481 // 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 );
7784 // Set the version parameters...
7885 $form->setTemplateParams( $templateParams );
7986 $form->setFileParams( $imageParams );
80 - $form->setFileVersion( $fileVersion );
 87+ $form->setFileVersion( $fileParam );
8188 $key = RevisionReviewForm::validationKey(
82 - $templateParams, $imageParams, $fileVersion, $revid );
 89+ $templateParams, $imageParams, $fileParam, $revid );
8390 $form->setValidatedParams( $key ); # always OK
8491 }
8592 $status = $form->ready(); // all params set
Index: trunk/extensions/FlaggedRevs/business/RevisionReviewForm.php
@@ -499,15 +499,15 @@
500500
501501 /**
502502 * 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)
506506 * @return array( templateParams, imageParams, fileVersion )
507507 */
508508 public static function getIncludeParams(
509 - FlaggedPage $article, array $templateIDs, array $imageSHA1Keys
 509+ array $templateIDs, array $imageSHA1Keys, $fileVersion
510510 ) {
511 - $templateParams = $imageParams = $fileVersion = '';
 511+ $templateParams = $imageParams = $fileParam = '';
512512 # NS -> title -> rev ID mapping
513513 foreach ( $templateIDs as $namespace => $t ) {
514514 foreach ( $t as $dbKey => $revId ) {
@@ -519,14 +519,11 @@
520520 foreach ( $imageSHA1Keys as $dbKey => $timeAndSHA1 ) {
521521 $imageParams .= $dbKey . "|" . $timeAndSHA1['time'] . "|" . $timeAndSHA1['sha1'] . "#";
522522 }
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'];
529526 }
530 - return array( $templateParams, $imageParams, $fileVersion );
 527+ return array( $templateParams, $imageParams, $fileParam );
531528 }
532529
533530 /**
Index: trunk/extensions/FlaggedRevs/presentation/FlaggedPageView.php
@@ -1082,13 +1082,22 @@
10831083 }
10841084 # Review notice box goes in top of form
10851085 $form->setTopNotice( $this->diffNoticeBox );
 1086+
 1087+ # Set the file version we are viewing (for File: pages)
 1088+ $form->setFileVersion( $this->out->getFileVersion() );
10861089 # $wgOut may not already have the inclusion IDs, such as for diffonly=1.
10871090 # RevisionReviewForm will fetch them as needed however.
10881091 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 );
10921099 }
 1100+ $form->setIncludeVersions( $tmpVers, $fileVers );
 1101+
10931102 list( $html, $status ) = $form->getHtml();
10941103 # Diff action: place the form at the top of the page
10951104 if ( $this->diffRevs ) {
@@ -1379,11 +1388,11 @@
13801389 # Otherwise, check for includes pending on top of edits pending...
13811390 } else {
13821391 $incs = FRInclusionCache::getRevIncludes( $this->article, $newRev, $wgUser );
 1392+ $this->oldRevIncludes = $incs; // process cache
13831393 # Add a list of links to each changed template...
13841394 $changeList = self::fetchTemplateChanges( $srev, $incs[0] );
13851395 # Add a list of links to each changed file...
13861396 $changeList = array_merge( $changeList, self::fetchFileChanges( $srev, $incs[1] ) );
1387 - $this->oldRevIncludes = $incs; // process cache
13881397 }
13891398 # If there are pending revs or templates/files changes, notify the user...
13901399 if ( $this->article->revsArePending() || count( $changeList ) ) {
Index: trunk/extensions/FlaggedRevs/presentation/RevisionReviewFormUI.php
@@ -8,7 +8,9 @@
99 protected $user, $article, $rev;
1010 protected $refRev = null;
1111 protected $topNotice = '';
12 - protected $templateIDs = null, $imageSHA1Keys = null;
 12+ protected $fileVersion = null;
 13+ protected $templateIDs = null;
 14+ protected $imageSHA1Keys = null;
1315
1416 /**
1517 * Generates a brief review form for a page
@@ -41,7 +43,15 @@
4244 }
4345
4446 /*
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
4656 * @param string $topNotice Text to
4757 */
4858 public function setIncludeVersions( array $templateIDs, array $imageSHA1Keys ) {
@@ -153,11 +163,13 @@
154164 $form .= self::ratingInputs( $this->user, $flags, (bool)$disabled, (bool)$frev );
155165 $form .= Xml::closeElement( 'span' ) . "\n";
156166
 167+ # Get the file version used for File: pages as needed
 168+ $fileKey = $this->getFileVersion();
157169 # Get template/file version info as needed
158170 list( $templateIDs, $imageSHA1Keys ) = $this->getIncludeVersions();
159171 # Convert these into flat string params
160172 list( $templateParams, $imageParams, $fileVersion ) =
161 - RevisionReviewForm::getIncludeParams( $article, $templateIDs, $imageSHA1Keys );
 173+ RevisionReviewForm::getIncludeParams( $templateIDs, $imageSHA1Keys, $fileKey );
162174
163175 $form .= Xml::openElement( 'span',
164176 array( 'style' => 'white-space: nowrap;' ) ) . "\n";
@@ -395,11 +407,16 @@
396408 return $s;
397409 }
398410
 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+
399418 protected function getIncludeVersions() {
400 - # Do we need to get inclusion IDs from parser output?
401419 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()." );
404421 }
405422 return array( $this->templateIDs, $this->imageSHA1Keys );
406423 }
Index: trunk/extensions/FlaggedRevs/dataclasses/FlaggedPage.php
@@ -13,7 +13,7 @@
1414 protected $pageConfig = null;
1515 protected $syncedInTracking = null;
1616
17 - protected $imagePage = null; // for file pages
 17+ protected $file = null; // for file pages
1818
1919 /**
2020 * Get a FlaggedPage for a given title
@@ -48,40 +48,22 @@
4949 $this->pendingRevCount = null;
5050 $this->pageConfig = null;
5151 $this->syncedInTracking = null;
52 - $this->imagePage = null;
 52+ $this->file = null;
5353 parent::clear(); // call super!
5454 }
5555
5656 /**
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
6060 */
6161 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 );
6464 }
65 - if ( is_null( $this->imagePage ) ) {
66 - $this->imagePage = new ImagePage( $this->mTitle );
67 - }
68 - return $this->imagePage->getFile();
 65+ return $this->file;
6966 }
7067
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 -
8668 /**
8769 * Is the stable version shown by default for this page?
8870 * @return bool
Index: trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevs.class.php
@@ -963,8 +963,10 @@
964964 # If this is an image page, store corresponding file info
965965 $fileData = array( 'name' => null, 'timestamp' => null, 'sha1' => null );
966966 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 );
969971 if ( is_object( $file ) && $file->exists() ) {
970972 $fileData['name'] = $title->getDBkey();
971973 $fileData['timestamp'] = $file->getTimestamp();
Index: trunk/extensions/FlaggedRevs/dataclasses/FRInclusionCache.php
@@ -68,7 +68,7 @@
6969 $revIdDraft = (int)$title->getLatestRevID();
7070 }
7171 }
72 - }
 72+ }
7373 wfProfileOut( __METHOD__ );
7474 return $versions;
7575 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r91567setFileVersion (r91435) was missing default $valaaron17:27, 6 July 2011

Comments

#Comment by Bawolff (talk | contribs)   15:58, 6 July 2011

Viewing a non-existant file:
Notice: Undefined variable: val in /var/www/w/phase3/includes/OutputPage.php on line 1313

Status & tagging log