From 814f8a80c2a4e326676684551e536da589c80bdb Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Thu, 16 Mar 2006 02:32:30 +0000 Subject: [PATCH] Don't require an existence check before calling loadPageData(). Added an accessor for page_latest, faster than getRevIdFetched() when it's needed for the permalink in the sidebar. Added shortcut calling convention for loadPageData(). --- includes/Article.php | 68 ++++++++++++++++++++++++++++++-------------- includes/Wiki.php | 13 +++------ 2 files changed, 50 insertions(+), 31 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index cd7ff017de..18e5f8db78 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -37,6 +37,7 @@ class Article { var $mRevIdFetched; var $mRevision; var $mRedirectUrl; + var $mLatest; /**#@-*/ /** @@ -125,6 +126,7 @@ class Article { $this->mIsRedirect = false; $this->mRevIdFetched = 0; $this->mRedirectUrl = false; + $this->mLatest = false; } /** @@ -416,15 +418,28 @@ class Article { * @param object $data * @access private */ - function loadPageData( $data ) { - $this->mTitle->mArticleID = $data->page_id; - $this->mTitle->loadRestrictions( $data->page_restrictions ); - $this->mTitle->mRestrictionsLoaded = true; + function loadPageData( $data = 'fromdb' ) { + if ( $data === 'fromdb' ) { + $dbr =& $this->getDB(); + $data = $this->pageDataFromId( $dbr, $this->getId() ); + } + + $lc =& LinkCache::singleton(); + if ( $data ) { + $lc->addGoodLinkObj( $data->page_id, $this->mTitle ); - $this->mCounter = $data->page_counter; - $this->mTouched = wfTimestamp( TS_MW, $data->page_touched ); - $this->mIsRedirect = $data->page_is_redirect; - $this->mLatest = $data->page_latest; + $this->mTitle->mArticleID = $data->page_id; + $this->mTitle->loadRestrictions( $data->page_restrictions ); + $this->mTitle->mRestrictionsLoaded = true; + + $this->mCounter = $data->page_counter; + $this->mTouched = wfTimestamp( TS_MW, $data->page_touched ); + $this->mIsRedirect = $data->page_is_redirect; + $this->mLatest = $data->page_latest; + } else { + $lc->addBadLinkObj( $this->mTitle ); + $this->mTitle->mArticleID = 0; + } $this->mDataLoaded = true; } @@ -557,9 +572,13 @@ class Article { function getCount() { if ( -1 == $this->mCounter ) { $id = $this->getID(); - $dbr =& wfGetDB( DB_SLAVE ); - $this->mCounter = $dbr->selectField( 'page', 'page_counter', array( 'page_id' => $id ), - 'Article::getCount', $this->getSelectOptions() ); + if ( $id == 0 ) { + $this->mCounter = 0; + } else { + $dbr =& wfGetDB( DB_SLAVE ); + $this->mCounter = $dbr->selectField( 'page', 'page_counter', array( 'page_id' => $id ), + 'Article::getCount', $this->getSelectOptions() ); + } } return $this->mCounter; } @@ -633,7 +652,10 @@ class Article { } function getTimestamp() { - $this->loadLastEdit(); + // Check if the field has been filled by ParserCache::get() + if ( !$this->mTimestamp ) { + $this->loadLastEdit(); + } return wfTimestamp(TS_MW, $this->mTimestamp); } @@ -2363,11 +2385,7 @@ class Article { function checkTouched() { $fname = 'Article::checkTouched'; if( !$this->mDataLoaded ) { - $dbr =& $this->getDB(); - $data = $this->pageDataFromId( $dbr, $this->getId() ); - if( $data ) { - $this->loadPageData( $data ); - } + $this->loadPageData(); } return !$this->mIsRedirect; } @@ -2378,15 +2396,21 @@ class Article { function getTouched() { # Ensure that page data has been loaded if( !$this->mDataLoaded ) { - $dbr =& $this->getDB(); - $data = $this->pageDataFromId( $dbr, $this->getId() ); - if( $data ) { - $this->loadPageData( $data ); - } + $this->loadPageData(); } return $this->mTouched; } + /** + * Get the page_latest field + */ + function getLatest() { + if ( !$this->mDataLoaded ) { + $this->loadPageData(); + } + return $this->mLatest; + } + /** * Edit an article without doing all that other stuff * The article must already exist; link tables etc diff --git a/includes/Wiki.php b/includes/Wiki.php index 0a0bd42eb3..be3a8b41c7 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -204,15 +204,10 @@ class MediaWiki { // Namespace might change when using redirects if( $action == 'view' && !$request->getVal( 'oldid' ) && $request->getVal( 'redirect' ) != 'no' ) { - $dbr=&wfGetDB(DB_SLAVE); - - // If we don't check for existance we'll get "Trying to get - // property of non-object" E_NOTICE in Article::loadPageData() when - // viewing a page that does not exist - if ( $article->exists() ) { - $article->loadPageData($article->pageDataFromTitle($dbr,$title)); - } - + + $dbr =& wfGetDB(DB_SLAVE); + $article->loadPageData($article->pageDataFromTitle($dbr, $title)); + /* Follow redirects only for... redirects */ if ($article->mIsRedirect) { $target = $article->followRedirect(); -- 2.20.1