r107769 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107768‎ | r107769 | r107770 >
Date:12:23, 1 January 2012
Author:ialex
Status:reverted (Comments)
Tags:
Comment:
Turn Title::isNewPage() into something useful by caching its result and preload it from Title::loadFromRow()
Modified paths:
  • /trunk/phase3/includes/Title.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Title.php
@@ -64,6 +64,7 @@
6565 var $mArticleID = -1; // /< Article ID, fetched from the link cache on demand
6666 var $mLatestID = false; // /< ID of most recent revision
6767 var $mCounter = -1; // /< Number of times this page has been viewed (-1 means "not loaded")
 68+ private $mIsNew; // /< Whether this is a "new page" (i.e. it has only one revision)
6869 private $mEstimateRevisions; // /< Estimated number of revisions; null of not loaded
6970 var $mRestrictions = array(); // /< Array of groups allowed to edit this article
7071 var $mOldRestrictions = false;
@@ -276,6 +277,8 @@
277278 $this->mLatestID = (int)$row->page_latest;
278279 if ( isset( $row->page_counter ) )
279280 $this->mCounter = (int)$row->page_counter;
 281+ if ( isset( $row->page_is_new ) )
 282+ $this->mIsNew = (bool)$row->page_is_new;
280283 } else { // page not found
281284 $this->mArticleID = 0;
282285 $this->mLength = 0;
@@ -2784,6 +2787,27 @@
27852788 }
27862789
27872790 /**
 2791+ * Check if this is a new page (i.e. it has only one revision)
 2792+ *
 2793+ * @return bool
 2794+ */
 2795+ public function isNewPage() {
 2796+ if ( $this->mIsNew === null ) {
 2797+ if ( $this->exists() ) {
 2798+ $dbr = wfGetDB( DB_SLAVE );
 2799+ $this->mIsNew = (bool)$dbr->selectField( 'page',
 2800+ 'page_is_new',
 2801+ array( 'page_id' => $this->getArticleID() ),
 2802+ __METHOD__
 2803+ );
 2804+ } else {
 2805+ $this->mIsNew = false;
 2806+ }
 2807+ }
 2808+ return $this->mIsNew;
 2809+ }
 2810+
 2811+ /**
27882812 * Get the article ID for this Title from the link cache,
27892813 * adding it if necessary
27902814 *
@@ -3992,16 +4016,6 @@
39934017 }
39944018
39954019 /**
3996 - * Check if this is a new page
3997 - *
3998 - * @return bool
3999 - */
4000 - public function isNewPage() {
4001 - $dbr = wfGetDB( DB_SLAVE );
4002 - return (bool)$dbr->selectField( 'page', 'page_is_new', $this->pageCond(), __METHOD__ );
4003 - }
4004 -
4005 - /**
40064020 * Check whether the number of revisions of this page surpasses $wgDeleteRevisionsLimit
40074021 *
40084022 * @return bool

Follow-up revisions

RevisionCommit summaryAuthorDate
r107771Follow-up r107769:...ialex12:44, 1 January 2012
r107945Revert r107769, r107771, r107825, r107840, r107927, r107934...brion21:44, 3 January 2012

Comments

#Comment by Brion VIBBER (talk | contribs)   21:23, 3 January 2012

This adds more internal state to the Title object which I'd rather not see...

doesn't appear to clear its state when the page changes or anything like that.

Status & tagging log