From: Aaron Schulz Date: Fri, 1 Jul 2011 23:33:34 +0000 (+0000) Subject: * Fixed getLatest() check in Article X-Git-Tag: 1.31.0-rc.0~29115 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmes_infos.php?a=commitdiff_plain;h=893d84b6aa0fa48d5c5eba47701c058326d64615;p=lhc%2Fweb%2Fwiklou.git * Fixed getLatest() check in Article * Added Title::loadFromRow() function and made WikiPage::loadPageData() use it; avoids raw Title field accessing * Added Revision::newFromPageId() function and changed WikiPage::loadLastEdit() to use it. This makes it try a slave first instead of always hitting the master. It also makes it more consistent with getLatest() for sanity. * Made WikiPage::loadPageData() use accessor for Title::mRestrictionsExpiry --- diff --git a/includes/Article.php b/includes/Article.php index 76d419e3ba..47c540df16 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -294,7 +294,7 @@ class Article extends Page { } } } else { - if ( $this->mPage->getLatest() === false ) { + if ( !$this->mPage->getLatest() ) { wfDebug( __METHOD__ . " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n" ); return false; } diff --git a/includes/Revision.php b/includes/Revision.php index 8496683970..fa560d30d4 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -34,7 +34,7 @@ class Revision { * to that title, will return null. * * @param $title Title - * @param $id Integer + * @param $id Integer (optional) * @return Revision or null */ public static function newFromTitle( $title, $id = 0 ) { @@ -50,8 +50,7 @@ class Revision { $dbw = wfGetDB( DB_MASTER ); $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__ ); if ( $latest === false ) { - // Page does not exist - return null; + return null; // page does not exist } $conds['rev_id'] = $latest; } else { @@ -62,6 +61,33 @@ class Revision { return Revision::newFromConds( $conds ); } + /** + * Load either the current, or a specified, revision + * that's attached to a given page ID. + * Returns null if no such revision can be found. + * + * @param $revId Integer + * @param $pageId Integer (optional) + * @return Revision or null + */ + public static function newFromPageId( $pageId, $revId = 0 ) { + $conds = array( 'page_id' => $pageId ); + if ( $revId ) { + $conds['rev_id'] = $pageId; + } elseif ( wfGetLB()->getServerCount() > 1 ) { + // Get the latest revision ID from the master + $dbw = wfGetDB( DB_MASTER ); + $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__ ); + if ( $latest === false ) { + return null; // page does not exist + } + $conds['rev_id'] = $latest; + } else { + $conds[] = 'rev_id = page_latest'; + } + return Revision::newFromConds( $conds ); + } + /** * Make a fake revision object from an archive table row. This is queried * for permissions or even inserted (as in Special:Undelete) diff --git a/includes/Title.php b/includes/Title.php index 63d690ee17..f170213c7c 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -252,15 +252,35 @@ class Title { */ public static function newFromRow( $row ) { $t = self::makeTitle( $row->page_namespace, $row->page_title ); - - $t->mArticleID = isset( $row->page_id ) ? intval( $row->page_id ) : -1; - $t->mLength = isset( $row->page_len ) ? intval( $row->page_len ) : -1; - $t->mRedirect = isset( $row->page_is_redirect ) ? (bool)$row->page_is_redirect : null; - $t->mLatestID = isset( $row->page_latest ) ? intval( $row->page_latest ) : false; - + $t->loadFromRow( $row ); return $t; } + /** + * Load Title object fields from a DB row. + * If false is given, the title will be treated as non-existing. + * + * @param $row Object|false database row + * @return void + */ + public function loadFromRow( $row ) { + if ( $row ) { // page found + if ( isset( $row->page_id ) ) + $this->mArticleID = (int)$row->page_id; + if ( isset( $row->page_len ) ) + $this->mLength = (int)$row->page_len; + if ( isset( $row->page_is_redirect ) ) + $this->mRedirect = (bool)$row->page_is_redirect; + if ( isset( $row->page_latest ) ) + $this->mLatestID = (int)$row->page_latest; + } else { // page not found + $this->mArticleID = 0; + $this->mLength = 0; + $this->mRedirect = false; + $this->mLatestID = 0; + } + } + /** * Create a new Title from a namespace index and a DB key. * It's assumed that $ns and $title are *valid*, for instance when diff --git a/includes/WikiPage.php b/includes/WikiPage.php index 656bce8470..d1e9b7012e 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -326,7 +326,7 @@ class WikiPage extends Page { if ( $data ) { $lc->addGoodLinkObj( $data->page_id, $this->mTitle, $data->page_len, $data->page_is_redirect, $data->page_latest ); - $this->mTitle->mArticleID = intval( $data->page_id ); + $this->mTitle->loadFromRow( $data ); # Old-fashioned restrictions $this->mTitle->loadRestrictions( $data->page_restrictions ); @@ -337,7 +337,8 @@ class WikiPage extends Page { $this->mLatest = intval( $data->page_latest ); } else { $lc->addBadLinkObj( $this->mTitle ); - $this->mTitle->mArticleID = 0; + + $this->mTitle->loadFromRow( false ); } $this->mDataLoaded = true; @@ -461,14 +462,13 @@ class WikiPage extends Page { return; // already loaded } - # New or non-existent articles have no user information - $id = $this->getId(); - if ( 0 == $id ) { - return; + $latest = $this->getLatest(); + if ( !$latest ) { + return; // page doesn't exist or is missing page_latest info } - $revision = Revision::loadFromPageId( wfGetDB( DB_MASTER ), $id ); - if ( $revision ) { + $revision = Revision::newFromPageId( $this->getId(), $latest ); + if ( $revision ) { // sanity $this->setLastEdit( $revision ); } } @@ -1279,7 +1279,9 @@ class WikiPage extends Page { # If something changed, we need to log it. Checking $aRChanged # assures that "unprotecting" a page that is not protected does # not log just because the expiry was "changed". - if ( $aRChanged && $this->mTitle->mRestrictionsExpiry[$action] != $expiry[$action] ) { + if ( $aRChanged && + $this->mTitle->getRestrictionExpiry( $action ) != $expiry[$action] ) + { $changed = true; } } @@ -2076,7 +2078,6 @@ class WikiPage extends Page { if ( !$this->mDataLoaded ) { $this->loadPageData(); } - return !$this->mIsRedirect; } @@ -2088,7 +2089,6 @@ class WikiPage extends Page { if ( !$this->mDataLoaded ) { $this->loadPageData(); } - return $this->mTouched; } @@ -2100,7 +2100,6 @@ class WikiPage extends Page { if ( !$this->mDataLoaded ) { $this->loadPageData(); } - return (int)$this->mLatest; }