Index: trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevision.php |
— | — | @@ -6,22 +6,22 @@ |
7 | 7 | * of templates and files (to determine template inclusion and thumbnails) |
8 | 8 | */ |
9 | 9 | 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 |
26 | 26 | |
27 | 27 | /** |
28 | 28 | * @param Row|array $row (DB row or array) |
— | — | @@ -102,10 +102,10 @@ |
103 | 103 | self::selectFields(), |
104 | 104 | array( |
105 | 105 | 'fr_page_id' => $pageId, |
106 | | - 'fr_rev_id' => $revId, |
| 106 | + 'fr_rev_id' => $revId, |
107 | 107 | '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' |
110 | 110 | ), |
111 | 111 | __METHOD__, |
112 | 112 | $options |
— | — | @@ -121,6 +121,8 @@ |
122 | 122 | |
123 | 123 | /** |
124 | 124 | * 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. |
125 | 127 | * @param Title $title, page title |
126 | 128 | * @param int $flags (FR_MASTER, FR_FOR_UPDATE) |
127 | 129 | * @return FlaggedRevision|null (null on failure) |
— | — | @@ -148,9 +150,10 @@ |
149 | 151 | self::selectFields(), |
150 | 152 | array( |
151 | 153 | 'fp_page_id' => $pageId, |
152 | | - 'fr_page_id = fp_page_id', |
153 | 154 | '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 |
155 | 158 | ), |
156 | 159 | __METHOD__, |
157 | 160 | $options |
— | — | @@ -164,6 +167,47 @@ |
165 | 168 | } |
166 | 169 | |
167 | 170 | /** |
| 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 | + /** |
168 | 212 | * Get the ID of the stable version of a title. |
169 | 213 | * @param Title $title, page title |
170 | 214 | * @param int $flags (FR_MASTER, FR_FOR_UPDATE) |