r86173 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86172‎ | r86173 | r86174 >
Date:02:07, 16 April 2011
Author:aaron
Status:ok
Tags:
Comment:
* Improved FlaggedRevision constructor. Revision object is always set now.
* Added extra sanity checks in insertOn()
Modified paths:
  • /trunk/extensions/FlaggedRevs/business/RevisionReviewForm.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevision.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevs.class.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevs.class.php
@@ -957,10 +957,9 @@
958958
959959 # Our review entry
960960 $flaggedRevision = new FlaggedRevision( array(
961 - 'page_id' => $rev->getPage(),
962 - 'rev_id' => $rev->getId(),
963 - 'user' => $user->getId(),
964 - 'timestamp' => $rev->getTimestamp(),
 961+ 'rev' => $rev,
 962+ 'user_id' => $user->getId(),
 963+ 'timestamp' => $rev->getTimestamp(), // same as edit time
965964 'quality' => $quality,
966965 'tags' => FlaggedRevision::flattenRevisionTags( $flags ),
967966 'img_name' => $fileData['name'],
Index: trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevision.php
@@ -12,27 +12,22 @@
1313 private $mFileSha1; // file version sha-1 (for revisions of File pages)
1414 private $mFileTimestamp; // file version timestamp (for revisions of File pages)
1515 /* Flagging metadata */
16 - private $mTimestamp;
17 - private $mQuality;
18 - private $mTags;
19 - private $mFlags;
 16+ private $mTimestamp; // review timestamp
 17+ private $mQuality; // review tier
 18+ private $mTags; // review tags
 19+ private $mFlags; // flags (for auto-review ect...)
2020 private $mUser; // reviewing user
2121 private $mFileName; // file name when reviewed
2222 /* Redundant fields for lazy-loading */
2323 private $mTitle;
24 - private $mPageId;
25 - private $mRevId;
26 - private $mStableTemplates;
27 - private $mStableFiles;
28 -
 24+ private $mStableTemplates; // template version used
 25+ private $mStableFiles; // file versions used
2926 /**
3027 * @param Row|array $row (DB row or array)
3128 * @return void
3229 */
3330 public function __construct( $row ) {
3431 if ( is_object( $row ) ) {
35 - $this->mRevId = intval( $row->fr_rev_id );
36 - $this->mPageId = intval( $row->fr_page_id );
3732 $this->mTimestamp = $row->fr_timestamp;
3833 $this->mQuality = intval( $row->fr_quality );
3934 $this->mTags = self::expandRevisionTags( strval( $row->fr_tags ) );
@@ -50,13 +45,13 @@
5146 ? Title::makeTitleSafe( $row->page_namespace, $row->page_title )
5247 : null;
5348 } elseif ( is_array( $row ) ) {
54 - $this->mRevId = intval( $row['rev_id'] );
55 - $this->mPageId = intval( $row['page_id'] );
5649 $this->mTimestamp = $row['timestamp'];
5750 $this->mQuality = intval( $row['quality'] );
5851 $this->mTags = self::expandRevisionTags( strval( $row['tags'] ) );
5952 $this->mFlags = explode( ',', $row['flags'] );
60 - $this->mUser = intval( $row['user'] );
 53+ $this->mUser = intval( $row['user_id'] );
 54+ # Base Revision object
 55+ $this->mRevision = $row['rev'];
6156 # Image page revision relevant params
6257 $this->mFileName = $row['img_name'] ? $row['img_name'] : null;
6358 $this->mFileSha1 = $row['img_sha1'] ? $row['img_sha1'] : null;
@@ -70,6 +65,9 @@
7166 } else {
7267 throw new MWException( 'FlaggedRevision constructor passed invalid row format.' );
7368 }
 69+ if ( !( $this->mRevision instanceof Revision ) ) {
 70+ throw new MWException( 'FlaggedRevision constructor passed invalid Revision object.' );
 71+ }
7472 }
7573
7674 /**
@@ -290,7 +288,11 @@
291289 $dbw->timestamp( $timeSHA1['time'] ) : null
292290 );
293291 }
294 - # Our review entry
 292+ # Sanity check for partial revisions
 293+ if ( !$this->getPage() || !$this->getRevId() ) {
 294+ return false; // bogus entry
 295+ }
 296+ # Our new review entry
295297 $revRow = array(
296298 'fr_page_id' => $this->getPage(),
297299 'fr_rev_id' => $this->getRevId(),
@@ -341,32 +343,41 @@
342344 * @return integer revision ID
343345 */
344346 public function getRevId() {
345 - return $this->mRevId;
 347+ return $this->mRevision->getId();
346348 }
347349
348350 /**
 351+ * @return integer page ID
 352+ */
 353+ public function getPage() {
 354+ return $this->mRevision->getPage();
 355+ }
 356+
 357+ /**
349358 * @return Title title
350359 */
351360 public function getTitle() {
352361 if ( is_null( $this->mTitle ) ) {
353 - $this->mTitle = Title::newFromId( $this->mPageId );
 362+ $this->mTitle = $this->mRevision->getTitle();
354363 }
355364 return $this->mTitle;
356365 }
357366
358367 /**
359 - * @return integer page ID
 368+ * Get timestamp of review
 369+ * @return string revision timestamp in MW format
360370 */
361 - public function getPage() {
362 - return $this->mPageId;
 371+ public function getTimestamp() {
 372+ return wfTimestamp( TS_MW, $this->mTimestamp );
363373 }
364374
365375 /**
366 - * Get timestamp of review
 376+ * Get timestamp of the corresponding revision
 377+ * Note: here for convenience
367378 * @return string revision timestamp in MW format
368379 */
369 - public function getTimestamp() {
370 - return wfTimestamp( TS_MW, $this->mTimestamp );
 380+ public function getRevTimestamp() {
 381+ return $this->mRevision->getTimestamp();
371382 }
372383
373384 /**
@@ -374,12 +385,6 @@
375386 * @return Revision
376387 */
377388 public function getRevision() {
378 - if ( is_null( $this->mRevision ) ) {
379 - # Get corresponding revision
380 - $rev = Revision::newFromId( $this->mRevId );
381 - # Save to cache
382 - $this->mRevision = $rev ? $rev : false;
383 - }
384389 return $this->mRevision;
385390 }
386391
@@ -389,18 +394,16 @@
390395 * @return bool
391396 */
392397 public function revIsCurrent() {
393 - $rev = $this->getRevision(); // corresponding revision
394 - return ( $rev ? $rev->isCurrent() : false );
 398+ return $this->mRevision->isCurrent();
395399 }
396400
397401 /**
398 - * Get timestamp of the corresponding revision
 402+ * Get text of the corresponding revision
399403 * Note: here for convenience
400 - * @return string revision timestamp in MW format
 404+ * @return string|false revision timestamp in MW format
401405 */
402 - public function getRevTimestamp() {
403 - $rev = $this->getRevision(); // corresponding revision
404 - return ( $rev ? $rev->getTimestamp() : "0" );
 406+ public function getRevText() {
 407+ return $this->mRevision->getText();
405408 }
406409
407410 /**
@@ -736,17 +739,6 @@
737740 }
738741
739742 /**
740 - * Get text of the corresponding revision
741 - * @return string|false revision timestamp in MW format
742 - */
743 - public function getRevText() {
744 - # Get corresponding revision
745 - $rev = $this->getRevision();
746 - $text = $rev ? $rev->getText() : false;
747 - return $text;
748 - }
749 -
750 - /**
751743 * Get flags for a revision
752744 * @param Title $title
753745 * @param int $rev_id
Index: trunk/extensions/FlaggedRevs/business/RevisionReviewForm.php
@@ -363,9 +363,8 @@
364364
365365 # Insert the review entry...
366366 $flaggedRevision = new FlaggedRevision( array(
367 - 'rev_id' => $rev->getId(),
368 - 'page_id' => $rev->getPage(),
369 - 'user' => $this->user->getId(),
 367+ 'rev' => $rev,
 368+ 'user_id' => $this->user->getId(),
370369 'timestamp' => wfTimestampNow(),
371370 'quality' => $quality,
372371 'tags' => FlaggedRevision::flattenRevisionTags( $flags ),

Status & tagging log