Index: trunk/phase3/includes/Article.php |
— | — | @@ -294,7 +294,7 @@ |
295 | 295 | } |
296 | 296 | } |
297 | 297 | } else { |
298 | | - if ( $this->mPage->getLatest() === false ) { |
| 298 | + if ( !$this->mPage->getLatest() ) { |
299 | 299 | wfDebug( __METHOD__ . " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n" ); |
300 | 300 | return false; |
301 | 301 | } |
Index: trunk/phase3/includes/Revision.php |
— | — | @@ -34,7 +34,7 @@ |
35 | 35 | * to that title, will return null. |
36 | 36 | * |
37 | 37 | * @param $title Title |
38 | | - * @param $id Integer |
| 38 | + * @param $id Integer (optional) |
39 | 39 | * @return Revision or null |
40 | 40 | */ |
41 | 41 | public static function newFromTitle( $title, $id = 0 ) { |
— | — | @@ -50,8 +50,7 @@ |
51 | 51 | $dbw = wfGetDB( DB_MASTER ); |
52 | 52 | $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__ ); |
53 | 53 | if ( $latest === false ) { |
54 | | - // Page does not exist |
55 | | - return null; |
| 54 | + return null; // page does not exist |
56 | 55 | } |
57 | 56 | $conds['rev_id'] = $latest; |
58 | 57 | } else { |
— | — | @@ -63,6 +62,33 @@ |
64 | 63 | } |
65 | 64 | |
66 | 65 | /** |
| 66 | + * Load either the current, or a specified, revision |
| 67 | + * that's attached to a given page ID. |
| 68 | + * Returns null if no such revision can be found. |
| 69 | + * |
| 70 | + * @param $revId Integer |
| 71 | + * @param $pageId Integer (optional) |
| 72 | + * @return Revision or null |
| 73 | + */ |
| 74 | + public static function newFromPageId( $pageId, $revId = 0 ) { |
| 75 | + $conds = array( 'page_id' => $pageId ); |
| 76 | + if ( $revId ) { |
| 77 | + $conds['rev_id'] = $pageId; |
| 78 | + } elseif ( wfGetLB()->getServerCount() > 1 ) { |
| 79 | + // Get the latest revision ID from the master |
| 80 | + $dbw = wfGetDB( DB_MASTER ); |
| 81 | + $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__ ); |
| 82 | + if ( $latest === false ) { |
| 83 | + return null; // page does not exist |
| 84 | + } |
| 85 | + $conds['rev_id'] = $latest; |
| 86 | + } else { |
| 87 | + $conds[] = 'rev_id = page_latest'; |
| 88 | + } |
| 89 | + return Revision::newFromConds( $conds ); |
| 90 | + } |
| 91 | + |
| 92 | + /** |
67 | 93 | * Make a fake revision object from an archive table row. This is queried |
68 | 94 | * for permissions or even inserted (as in Special:Undelete) |
69 | 95 | * @todo FIXME: Should be a subclass for RevisionDelete. [TS] |
Index: trunk/phase3/includes/Title.php |
— | — | @@ -252,16 +252,36 @@ |
253 | 253 | */ |
254 | 254 | public static function newFromRow( $row ) { |
255 | 255 | $t = self::makeTitle( $row->page_namespace, $row->page_title ); |
256 | | - |
257 | | - $t->mArticleID = isset( $row->page_id ) ? intval( $row->page_id ) : -1; |
258 | | - $t->mLength = isset( $row->page_len ) ? intval( $row->page_len ) : -1; |
259 | | - $t->mRedirect = isset( $row->page_is_redirect ) ? (bool)$row->page_is_redirect : null; |
260 | | - $t->mLatestID = isset( $row->page_latest ) ? intval( $row->page_latest ) : false; |
261 | | - |
| 256 | + $t->loadFromRow( $row ); |
262 | 257 | return $t; |
263 | 258 | } |
264 | 259 | |
265 | 260 | /** |
| 261 | + * Load Title object fields from a DB row. |
| 262 | + * If false is given, the title will be treated as non-existing. |
| 263 | + * |
| 264 | + * @param $row Object|false database row |
| 265 | + * @return void |
| 266 | + */ |
| 267 | + public function loadFromRow( $row ) { |
| 268 | + if ( $row ) { // page found |
| 269 | + if ( isset( $row->page_id ) ) |
| 270 | + $this->mArticleID = (int)$row->page_id; |
| 271 | + if ( isset( $row->page_len ) ) |
| 272 | + $this->mLength = (int)$row->page_len; |
| 273 | + if ( isset( $row->page_is_redirect ) ) |
| 274 | + $this->mRedirect = (bool)$row->page_is_redirect; |
| 275 | + if ( isset( $row->page_latest ) ) |
| 276 | + $this->mLatestID = (int)$row->page_latest; |
| 277 | + } else { // page not found |
| 278 | + $this->mArticleID = 0; |
| 279 | + $this->mLength = 0; |
| 280 | + $this->mRedirect = false; |
| 281 | + $this->mLatestID = 0; |
| 282 | + } |
| 283 | + } |
| 284 | + |
| 285 | + /** |
266 | 286 | * Create a new Title from a namespace index and a DB key. |
267 | 287 | * It's assumed that $ns and $title are *valid*, for instance when |
268 | 288 | * they came directly from the database or a special page name. |
Index: trunk/phase3/includes/WikiPage.php |
— | — | @@ -326,7 +326,7 @@ |
327 | 327 | if ( $data ) { |
328 | 328 | $lc->addGoodLinkObj( $data->page_id, $this->mTitle, $data->page_len, $data->page_is_redirect, $data->page_latest ); |
329 | 329 | |
330 | | - $this->mTitle->mArticleID = intval( $data->page_id ); |
| 330 | + $this->mTitle->loadFromRow( $data ); |
331 | 331 | |
332 | 332 | # Old-fashioned restrictions |
333 | 333 | $this->mTitle->loadRestrictions( $data->page_restrictions ); |
— | — | @@ -337,7 +337,8 @@ |
338 | 338 | $this->mLatest = intval( $data->page_latest ); |
339 | 339 | } else { |
340 | 340 | $lc->addBadLinkObj( $this->mTitle ); |
341 | | - $this->mTitle->mArticleID = 0; |
| 341 | + |
| 342 | + $this->mTitle->loadFromRow( false ); |
342 | 343 | } |
343 | 344 | |
344 | 345 | $this->mDataLoaded = true; |
— | — | @@ -461,14 +462,13 @@ |
462 | 463 | return; // already loaded |
463 | 464 | } |
464 | 465 | |
465 | | - # New or non-existent articles have no user information |
466 | | - $id = $this->getId(); |
467 | | - if ( 0 == $id ) { |
468 | | - return; |
| 466 | + $latest = $this->getLatest(); |
| 467 | + if ( !$latest ) { |
| 468 | + return; // page doesn't exist or is missing page_latest info |
469 | 469 | } |
470 | 470 | |
471 | | - $revision = Revision::loadFromPageId( wfGetDB( DB_MASTER ), $id ); |
472 | | - if ( $revision ) { |
| 471 | + $revision = Revision::newFromPageId( $this->getId(), $latest ); |
| 472 | + if ( $revision ) { // sanity |
473 | 473 | $this->setLastEdit( $revision ); |
474 | 474 | } |
475 | 475 | } |
— | — | @@ -1279,7 +1279,9 @@ |
1280 | 1280 | # If something changed, we need to log it. Checking $aRChanged |
1281 | 1281 | # assures that "unprotecting" a page that is not protected does |
1282 | 1282 | # not log just because the expiry was "changed". |
1283 | | - if ( $aRChanged && $this->mTitle->mRestrictionsExpiry[$action] != $expiry[$action] ) { |
| 1283 | + if ( $aRChanged && |
| 1284 | + $this->mTitle->getRestrictionExpiry( $action ) != $expiry[$action] ) |
| 1285 | + { |
1284 | 1286 | $changed = true; |
1285 | 1287 | } |
1286 | 1288 | } |
— | — | @@ -2076,7 +2078,6 @@ |
2077 | 2079 | if ( !$this->mDataLoaded ) { |
2078 | 2080 | $this->loadPageData(); |
2079 | 2081 | } |
2080 | | - |
2081 | 2082 | return !$this->mIsRedirect; |
2082 | 2083 | } |
2083 | 2084 | |
— | — | @@ -2088,7 +2089,6 @@ |
2089 | 2090 | if ( !$this->mDataLoaded ) { |
2090 | 2091 | $this->loadPageData(); |
2091 | 2092 | } |
2092 | | - |
2093 | 2093 | return $this->mTouched; |
2094 | 2094 | } |
2095 | 2095 | |
— | — | @@ -2100,7 +2100,6 @@ |
2101 | 2101 | if ( !$this->mDataLoaded ) { |
2102 | 2102 | $this->loadPageData(); |
2103 | 2103 | } |
2104 | | - |
2105 | 2104 | return (int)$this->mLatest; |
2106 | 2105 | } |
2107 | 2106 | |