* 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
}
}
} 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;
}
* 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 ) {
$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 {
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)
*/
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
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 );
$this->mLatest = intval( $data->page_latest );
} else {
$lc->addBadLinkObj( $this->mTitle );
- $this->mTitle->mArticleID = 0;
+
+ $this->mTitle->loadFromRow( false );
}
$this->mDataLoaded = true;
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 );
}
}
# 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;
}
}
if ( !$this->mDataLoaded ) {
$this->loadPageData();
}
-
return !$this->mIsRedirect;
}
if ( !$this->mDataLoaded ) {
$this->loadPageData();
}
-
return $this->mTouched;
}
if ( !$this->mDataLoaded ) {
$this->loadPageData();
}
-
return (int)$this->mLatest;
}