r101246 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101245‎ | r101246 | r101247 >
Date:09:07, 29 October 2011
Author:aaron
Status:ok (Comments)
Tags:
Comment:
* In FlaggedRevision::newFromStable(): Removed redundant fr_page_id = fp_page_id cond as fr_rev_id is the PK now. Also added some sanity conditions.
* Cleaned up rev_deleted query to use bitAnd().
* Added FlaggedRevision::newFromId() function.
Modified paths:
  • /trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevision.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevision.php
@@ -6,22 +6,22 @@
77 * of templates and files (to determine template inclusion and thumbnails)
88 */
99 class FlaggedRevision {
10 - private $mRevision; // base revision
11 - private $mTemplates; // included template versions
12 - private $mFiles; // included file versions
13 - private $mFileSha1; // file version sha-1 (for revisions of File pages)
14 - private $mFileTimestamp; // file version timestamp (for revisions of File pages)
15 - /* Flagging metadata */
16 - private $mTimestamp; // review timestamp
17 - private $mQuality; // review tier
18 - private $mTags; // review tags
19 - private $mFlags; // flags (for auto-review ect...)
20 - private $mUser; // reviewing user
21 - private $mFileName; // file name when reviewed
22 - /* Redundant fields for lazy-loading */
23 - private $mTitle; // page title
24 - private $mStableTemplates; // stable versions of template version used
25 - private $mStableFiles; // stable versions of file versions used
 10+ private $mRevision; // base revision
 11+ private $mTemplates; // included template versions
 12+ private $mFiles; // included file versions
 13+ private $mFileSha1; // file version sha-1 (for revisions of File pages)
 14+ private $mFileTimestamp; // file version timestamp (for revisions of File pages)
 15+ /* Flagging metadata */
 16+ private $mTimestamp; // review timestamp
 17+ private $mQuality; // review tier
 18+ private $mTags; // review tags
 19+ private $mFlags; // flags (for auto-review ect...)
 20+ private $mUser; // reviewing user
 21+ private $mFileName; // file name when reviewed
 22+ /* Redundant fields for lazy-loading */
 23+ private $mTitle; // page title
 24+ private $mStableTemplates; // stable versions of template version used
 25+ private $mStableFiles; // stable versions of file versions used
2626
2727 /**
2828 * @param Row|array $row (DB row or array)
@@ -102,10 +102,10 @@
103103 self::selectFields(),
104104 array(
105105 'fr_page_id' => $pageId,
106 - 'fr_rev_id' => $revId,
 106+ 'fr_rev_id' => $revId,
107107 'rev_id = fr_rev_id',
108 - 'rev_page = fr_page_id',
109 - 'rev_deleted & ' . Revision::DELETED_TEXT => 0
 108+ 'rev_page = fr_page_id', // sanity
 109+ $db->bitAnd( 'rev_deleted', Revision::DELETED_TEXT ) . ' = 0'
110110 ),
111111 __METHOD__,
112112 $options
@@ -121,6 +121,8 @@
122122
123123 /**
124124 * Get a FlaggedRevision of the stable version of a title.
 125+ * Note: will return NULL if the revision is deleted, though this
 126+ * should never happen as fp_stable is updated as revs are deleted.
125127 * @param Title $title, page title
126128 * @param int $flags (FR_MASTER, FR_FOR_UPDATE)
127129 * @return FlaggedRevision|null (null on failure)
@@ -148,9 +150,10 @@
149151 self::selectFields(),
150152 array(
151153 'fp_page_id' => $pageId,
152 - 'fr_page_id = fp_page_id',
153154 'fr_rev_id = fp_stable',
154 - 'rev_id = fr_rev_id'
 155+ 'rev_id = fr_rev_id',
 156+ 'rev_page = fr_page_id', // sanity
 157+ $db->bitAnd( 'rev_deleted', Revision::DELETED_TEXT ) . ' = 0', // sanity
155158 ),
156159 __METHOD__,
157160 $options
@@ -164,6 +167,47 @@
165168 }
166169
167170 /**
 171+ * Get a FlaggedRevision for a rev ID.
 172+ * Note: will return NULL if the revision is deleted.
 173+ * @param int $revId
 174+ * @param int $flags (FR_MASTER, FR_FOR_UPDATE)
 175+ * @return FlaggedRevision|null (null on failure)
 176+ */
 177+ public static function newFromId( $revId, $flags = 0 ) {
 178+ $options = array();
 179+ # User master/slave as appropriate...
 180+ if ( $flags & FR_FOR_UPDATE || $flags & FR_MASTER ) {
 181+ $db = wfGetDB( DB_MASTER );
 182+ if ( $flags & FR_FOR_UPDATE ) $options[] = 'FOR UPDATE';
 183+ } else {
 184+ $db = wfGetDB( DB_SLAVE );
 185+ }
 186+ if ( !$revId ) {
 187+ return null; // short-circuit query
 188+ }
 189+ # Skip deleted revisions
 190+ $row = $db->selectRow(
 191+ array( 'flaggedrevs', 'revision', 'page' ),
 192+ self::selectFields(),
 193+ array(
 194+ 'fr_rev_id' => $revId,
 195+ 'rev_id = fr_rev_id',
 196+ 'rev_page = fr_page_id', // sanity
 197+ 'page_id = rev_page',
 198+ $db->bitAnd( 'rev_deleted', Revision::DELETED_TEXT ) . ' = 0',
 199+ ),
 200+ __METHOD__,
 201+ $options
 202+ );
 203+ if ( $row ) {
 204+ $frev = new self( $row );
 205+ $frev->mTitle = Title::newFromRow( $row );
 206+ return $frev;
 207+ }
 208+ return null;
 209+ }
 210+
 211+ /**
168212 * Get the ID of the stable version of a title.
169213 * @param Title $title, page title
170214 * @param int $flags (FR_MASTER, FR_FOR_UPDATE)

Comments

#Comment by Johnduhart (talk | contribs)   17:04, 5 January 2012
+    private $mRevision;         // base revision
+    private $mTemplates;        // included template versions
+    private $mFiles;            // included file versions
+    private $mFileSha1;         // file version sha-1 (for revisions of File pages)
+    private $mFileTimestamp;    // file version timestamp (for revisions of File pages)
+    /* Flagging metadata */
+    private $mTimestamp;        // review timestamp
+    private $mQuality;          // review tier
+    private $mTags;             // review tags
+    private $mFlags;            // flags (for auto-review ect...)
+    private $mUser;             // reviewing user
+    private $mFileName;         // file name when reviewed
+    /* Redundant fields for lazy-loading */
+    private $mTitle;            // page title
+    private $mStableTemplates;  // stable versions of template version used
+    private $mStableFiles;      // stable versions of file versions used

Spaces?

Status & tagging log