Index: trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevs.class.php |
— | — | @@ -957,10 +957,9 @@ |
958 | 958 | |
959 | 959 | # Our review entry |
960 | 960 | $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 |
965 | 964 | 'quality' => $quality, |
966 | 965 | 'tags' => FlaggedRevision::flattenRevisionTags( $flags ), |
967 | 966 | 'img_name' => $fileData['name'], |
Index: trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevision.php |
— | — | @@ -12,27 +12,22 @@ |
13 | 13 | private $mFileSha1; // file version sha-1 (for revisions of File pages) |
14 | 14 | private $mFileTimestamp; // file version timestamp (for revisions of File pages) |
15 | 15 | /* 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...) |
20 | 20 | private $mUser; // reviewing user |
21 | 21 | private $mFileName; // file name when reviewed |
22 | 22 | /* Redundant fields for lazy-loading */ |
23 | 23 | 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 |
29 | 26 | /** |
30 | 27 | * @param Row|array $row (DB row or array) |
31 | 28 | * @return void |
32 | 29 | */ |
33 | 30 | public function __construct( $row ) { |
34 | 31 | if ( is_object( $row ) ) { |
35 | | - $this->mRevId = intval( $row->fr_rev_id ); |
36 | | - $this->mPageId = intval( $row->fr_page_id ); |
37 | 32 | $this->mTimestamp = $row->fr_timestamp; |
38 | 33 | $this->mQuality = intval( $row->fr_quality ); |
39 | 34 | $this->mTags = self::expandRevisionTags( strval( $row->fr_tags ) ); |
— | — | @@ -50,13 +45,13 @@ |
51 | 46 | ? Title::makeTitleSafe( $row->page_namespace, $row->page_title ) |
52 | 47 | : null; |
53 | 48 | } elseif ( is_array( $row ) ) { |
54 | | - $this->mRevId = intval( $row['rev_id'] ); |
55 | | - $this->mPageId = intval( $row['page_id'] ); |
56 | 49 | $this->mTimestamp = $row['timestamp']; |
57 | 50 | $this->mQuality = intval( $row['quality'] ); |
58 | 51 | $this->mTags = self::expandRevisionTags( strval( $row['tags'] ) ); |
59 | 52 | $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']; |
61 | 56 | # Image page revision relevant params |
62 | 57 | $this->mFileName = $row['img_name'] ? $row['img_name'] : null; |
63 | 58 | $this->mFileSha1 = $row['img_sha1'] ? $row['img_sha1'] : null; |
— | — | @@ -70,6 +65,9 @@ |
71 | 66 | } else { |
72 | 67 | throw new MWException( 'FlaggedRevision constructor passed invalid row format.' ); |
73 | 68 | } |
| 69 | + if ( !( $this->mRevision instanceof Revision ) ) { |
| 70 | + throw new MWException( 'FlaggedRevision constructor passed invalid Revision object.' ); |
| 71 | + } |
74 | 72 | } |
75 | 73 | |
76 | 74 | /** |
— | — | @@ -290,7 +288,11 @@ |
291 | 289 | $dbw->timestamp( $timeSHA1['time'] ) : null |
292 | 290 | ); |
293 | 291 | } |
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 |
295 | 297 | $revRow = array( |
296 | 298 | 'fr_page_id' => $this->getPage(), |
297 | 299 | 'fr_rev_id' => $this->getRevId(), |
— | — | @@ -341,32 +343,41 @@ |
342 | 344 | * @return integer revision ID |
343 | 345 | */ |
344 | 346 | public function getRevId() { |
345 | | - return $this->mRevId; |
| 347 | + return $this->mRevision->getId(); |
346 | 348 | } |
347 | 349 | |
348 | 350 | /** |
| 351 | + * @return integer page ID |
| 352 | + */ |
| 353 | + public function getPage() { |
| 354 | + return $this->mRevision->getPage(); |
| 355 | + } |
| 356 | + |
| 357 | + /** |
349 | 358 | * @return Title title |
350 | 359 | */ |
351 | 360 | public function getTitle() { |
352 | 361 | if ( is_null( $this->mTitle ) ) { |
353 | | - $this->mTitle = Title::newFromId( $this->mPageId ); |
| 362 | + $this->mTitle = $this->mRevision->getTitle(); |
354 | 363 | } |
355 | 364 | return $this->mTitle; |
356 | 365 | } |
357 | 366 | |
358 | 367 | /** |
359 | | - * @return integer page ID |
| 368 | + * Get timestamp of review |
| 369 | + * @return string revision timestamp in MW format |
360 | 370 | */ |
361 | | - public function getPage() { |
362 | | - return $this->mPageId; |
| 371 | + public function getTimestamp() { |
| 372 | + return wfTimestamp( TS_MW, $this->mTimestamp ); |
363 | 373 | } |
364 | 374 | |
365 | 375 | /** |
366 | | - * Get timestamp of review |
| 376 | + * Get timestamp of the corresponding revision |
| 377 | + * Note: here for convenience |
367 | 378 | * @return string revision timestamp in MW format |
368 | 379 | */ |
369 | | - public function getTimestamp() { |
370 | | - return wfTimestamp( TS_MW, $this->mTimestamp ); |
| 380 | + public function getRevTimestamp() { |
| 381 | + return $this->mRevision->getTimestamp(); |
371 | 382 | } |
372 | 383 | |
373 | 384 | /** |
— | — | @@ -374,12 +385,6 @@ |
375 | 386 | * @return Revision |
376 | 387 | */ |
377 | 388 | 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 | | - } |
384 | 389 | return $this->mRevision; |
385 | 390 | } |
386 | 391 | |
— | — | @@ -389,18 +394,16 @@ |
390 | 395 | * @return bool |
391 | 396 | */ |
392 | 397 | public function revIsCurrent() { |
393 | | - $rev = $this->getRevision(); // corresponding revision |
394 | | - return ( $rev ? $rev->isCurrent() : false ); |
| 398 | + return $this->mRevision->isCurrent(); |
395 | 399 | } |
396 | 400 | |
397 | 401 | /** |
398 | | - * Get timestamp of the corresponding revision |
| 402 | + * Get text of the corresponding revision |
399 | 403 | * Note: here for convenience |
400 | | - * @return string revision timestamp in MW format |
| 404 | + * @return string|false revision timestamp in MW format |
401 | 405 | */ |
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(); |
405 | 408 | } |
406 | 409 | |
407 | 410 | /** |
— | — | @@ -736,17 +739,6 @@ |
737 | 740 | } |
738 | 741 | |
739 | 742 | /** |
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 | | - /** |
751 | 743 | * Get flags for a revision |
752 | 744 | * @param Title $title |
753 | 745 | * @param int $rev_id |
Index: trunk/extensions/FlaggedRevs/business/RevisionReviewForm.php |
— | — | @@ -363,9 +363,8 @@ |
364 | 364 | |
365 | 365 | # Insert the review entry... |
366 | 366 | $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(), |
370 | 369 | 'timestamp' => wfTimestampNow(), |
371 | 370 | 'quality' => $quality, |
372 | 371 | 'tags' => FlaggedRevision::flattenRevisionTags( $flags ), |