From 00f2a3c47de36478ea7b0db9b0cfd0a6ee238d0b Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Sun, 1 Jan 2012 12:23:17 +0000 Subject: [PATCH] Turn Title::isNewPage() into something useful by caching its result and preload it from Title::loadFromRow() --- includes/Title.php | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/includes/Title.php b/includes/Title.php index 87f97b62a2..5d62ca89f4 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -64,6 +64,7 @@ class Title { var $mArticleID = -1; // /< Article ID, fetched from the link cache on demand var $mLatestID = false; // /< ID of most recent revision var $mCounter = -1; // /< Number of times this page has been viewed (-1 means "not loaded") + private $mIsNew; // /< Whether this is a "new page" (i.e. it has only one revision) private $mEstimateRevisions; // /< Estimated number of revisions; null of not loaded var $mRestrictions = array(); // /< Array of groups allowed to edit this article var $mOldRestrictions = false; @@ -276,6 +277,8 @@ class Title { $this->mLatestID = (int)$row->page_latest; if ( isset( $row->page_counter ) ) $this->mCounter = (int)$row->page_counter; + if ( isset( $row->page_is_new ) ) + $this->mIsNew = (bool)$row->page_is_new; } else { // page not found $this->mArticleID = 0; $this->mLength = 0; @@ -2783,6 +2786,27 @@ class Title { return $this->mCounter; } + /** + * Check if this is a new page (i.e. it has only one revision) + * + * @return bool + */ + public function isNewPage() { + if ( $this->mIsNew === null ) { + if ( $this->exists() ) { + $dbr = wfGetDB( DB_SLAVE ); + $this->mIsNew = (bool)$dbr->selectField( 'page', + 'page_is_new', + array( 'page_id' => $this->getArticleID() ), + __METHOD__ + ); + } else { + $this->mIsNew = false; + } + } + return $this->mIsNew; + } + /** * Get the article ID for this Title from the link cache, * adding it if necessary @@ -3991,16 +4015,6 @@ class Title { return $rev ? $rev->getTimestamp() : null; } - /** - * Check if this is a new page - * - * @return bool - */ - public function isNewPage() { - $dbr = wfGetDB( DB_SLAVE ); - return (bool)$dbr->selectField( 'page', 'page_is_new', $this->pageCond(), __METHOD__ ); - } - /** * Check whether the number of revisions of this page surpasses $wgDeleteRevisionsLimit * -- 2.20.1