From 68bf1a77b4b1f1465a72ae3edffb19ae28da2765 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Mon, 2 Jan 2012 12:49:50 +0000 Subject: [PATCH] * Store the value of the page.page_restrictions field in Title::loadFromRow() and defers loading restrictions until when it's really needed; this reuses the Title::$mOldRestrictions member which is not used anywhere yet * Removed $oldFashionedRestrictions parameter from Title::loadRestrictions*(); the only extension using it is LiquidThreads and it's using Title::newFromRow() to create the Title object, so the field is already cached (and this even allows to cache that field when there's no row for that page in the page_restrictions table) * Also reset $mTouched and $mIsNew members on resetArticleId() calls * Updated FakeTitle a bit --- includes/FakeTitle.php | 6 +++--- includes/Title.php | 36 ++++++++++++++++-------------------- includes/WikiPage.php | 3 --- 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/includes/FakeTitle.php b/includes/FakeTitle.php index f9138396c7..d32c9369b3 100644 --- a/includes/FakeTitle.php +++ b/includes/FakeTitle.php @@ -65,8 +65,8 @@ class FakeTitle extends Title { function isCascadeProtected() { $this->error(); } function getCascadeProtectionSources( $get_pages = true ) { $this->error(); } function areRestrictionsCascading() { $this->error(); } - function loadRestrictionsFromRows( $rows, $oldFashionedRestrictions = null ) { $this->error(); } - function loadRestrictions( $res = null ) { $this->error(); } + function loadRestrictionsFromRows( $rows ) { $this->error(); } + function loadRestrictions() { $this->error(); } function getRestrictions( $action ) { $this->error(); } function getRestrictionExpiry( $action ) { $this->error(); } function isDeleted() { $this->error(); } @@ -109,7 +109,7 @@ class FakeTitle extends Title { function isKnown() { $this->error(); } function canExist() { $this->error(); } function touchLinks() { $this->error(); } - function getTouched( $db = null ) { $this->error(); } + function getTouched() { $this->error(); } function getNotificationTimestamp( $user = null ) { $this->error(); } function getNamespaceKey( $prepend = 'nstab-' ) { $this->error(); } function isSpecialPage() { $this->error(); } diff --git a/includes/Title.php b/includes/Title.php index 68b2e7871d..5af374167d 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -68,7 +68,7 @@ class Title { 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; + var $mOldRestrictions; var $mCascadeRestriction; ///< Cascade restrictions on this page to included templates and images? var $mCascadingRestrictions; // Caching the results of getCascadeProtectionSources var $mRestrictionsExpiry = array(); ///< When do the restrictions on this page expire? @@ -236,6 +236,7 @@ class Title { 'page_namespace', 'page_title', 'page_id', 'page_len', 'page_is_redirect', 'page_latest', 'page_counter', 'page_touched', 'page_is_new', + 'page_restrictions', ), array( 'page_id' => $ids ), __METHOD__ @@ -283,6 +284,8 @@ class Title { $this->mTouched = $row->page_touched; if ( isset( $row->page_is_new ) ) $this->mIsNew = (bool)$row->page_is_new; + if ( isset( $row->page_restrictions ) ) + $this->mOldRestrictions = $row->page_restrictions; } else { // page not found $this->mArticleID = 0; $this->mLength = 0; @@ -291,6 +294,7 @@ class Title { $this->mCounter = 0; $this->mTouched = '19700101000000'; $this->mIsNew = false; + $this->mOldRestrictions = false; } } @@ -2502,17 +2506,15 @@ class Title { * Loads a string into mRestrictions array * * @param $res Resource restrictions as an SQL result. - * @param $oldFashionedRestrictions String comma-separated list of page - * restrictions from page table (pre 1.10) */ - private function loadRestrictionsFromResultWrapper( $res, $oldFashionedRestrictions = null ) { + private function loadRestrictionsFromResultWrapper( $res ) { $rows = array(); foreach ( $res as $row ) { $rows[] = $row; } - $this->loadRestrictionsFromRows( $rows, $oldFashionedRestrictions ); + $this->loadRestrictionsFromRows( $rows ); } /** @@ -2521,10 +2523,8 @@ class Title { * Public for usage by LiquidThreads. * * @param $rows array of db result objects - * @param $oldFashionedRestrictions string comma-separated list of page - * restrictions from page table (pre 1.10) */ - public function loadRestrictionsFromRows( $rows, $oldFashionedRestrictions = null ) { + public function loadRestrictionsFromRows( $rows ) { global $wgContLang; $dbr = wfGetDB( DB_SLAVE ); @@ -2539,13 +2539,12 @@ class Title { # Backwards-compatibility: also load the restrictions from the page record (old format). - if ( $oldFashionedRestrictions === null ) { - $oldFashionedRestrictions = $dbr->selectField( 'page', 'page_restrictions', + if ( $this->mOldRestrictions === null ) { + $this->mOldRestrictions = $dbr->selectField( 'page', 'page_restrictions', array( 'page_id' => $this->getArticleId() ), __METHOD__ ); } - if ( $oldFashionedRestrictions != '' ) { - + if ( $this->mOldRestrictions !== false && $this->mOldRestrictions !== '' ) { foreach ( explode( ':', trim( $oldFashionedRestrictions ) ) as $restrict ) { $temp = explode( '=', trim( $restrict ) ); if ( count( $temp ) == 1 ) { @@ -2556,9 +2555,6 @@ class Title { $this->mRestrictions[$temp[0]] = explode( ',', trim( $temp[1] ) ); } } - - $this->mOldRestrictions = true; - } if ( count( $rows ) ) { @@ -2599,11 +2595,8 @@ class Title { /** * Load restrictions from the page_restrictions table - * - * @param $oldFashionedRestrictions String comma-separated list of page - * restrictions from page table (pre 1.10) */ - public function loadRestrictions( $oldFashionedRestrictions = null ) { + public function loadRestrictions() { global $wgContLang; if ( !$this->mRestrictionsLoaded ) { if ( $this->exists() ) { @@ -2616,7 +2609,7 @@ class Title { __METHOD__ ); - $this->loadRestrictionsFromResultWrapper( $res, $oldFashionedRestrictions ); + $this->loadRestrictionsFromResultWrapper( $res ); } else { $title_protection = $this->getTitleProtection(); @@ -2944,10 +2937,13 @@ class Title { } $this->mRestrictionsLoaded = false; $this->mRestrictions = array(); + $this->mOldRestrictions = null; $this->mRedirect = null; $this->mLength = -1; $this->mLatestID = false; $this->mCounter = -1; + $this->mTouched = '19700101000000'; + $this->mIsNew = null; $this->mEstimateRevisions = null; } diff --git a/includes/WikiPage.php b/includes/WikiPage.php index 6aa0c72ed3..cc0555cf5e 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -375,9 +375,6 @@ class WikiPage extends Page { $this->mTitle->loadFromRow( $data ); - # Old-fashioned restrictions - $this->mTitle->loadRestrictions( $data->page_restrictions ); - $this->mTouched = wfTimestamp( TS_MW, $data->page_touched ); $this->mIsRedirect = intval( $data->page_is_redirect ); $this->mLatest = intval( $data->page_latest ); -- 2.20.1