From 19cca14f697370469b119a428be164a98fce0603 Mon Sep 17 00:00:00 2001 From: Andrew Garrett Date: Fri, 12 Jan 2007 01:44:33 +0000 Subject: [PATCH] Restore backwards-compatibility for old types of restrictions; wipe page_restrictions column in update for page_restrictions and on updateRestrictions --- includes/Article.php | 9 +++++++ includes/ProtectionForm.php | 1 + includes/Title.php | 54 ++++++++++++++++++++++++++----------- maintenance/updaters.inc | 3 +++ 4 files changed, 52 insertions(+), 15 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 9a7d629ca6..cda171ceb4 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -252,6 +252,7 @@ class Article { 'page_id', 'page_namespace', 'page_title', + 'page_restrictions', 'page_counter', 'page_is_redirect', 'page_is_new', @@ -305,6 +306,9 @@ class Article { $this->mTitle->mArticleID = $data->page_id; + # Old-fashioned restrictions. + $this->mTitle->loadRestrictions( $data->page_restrictions ); + $this->mCounter = $data->page_counter; $this->mTouched = wfTimestamp( TS_MW, $data->page_touched ); $this->mIsRedirect = $data->page_is_redirect; @@ -1682,6 +1686,11 @@ class Article { 'pr_type' => $action ), __METHOD__ ); } } + + # Blank page_restrictions on page record if they're being used. + if ($this->mTitle->mOldRestrictions) { + $dbw->update( 'page', array ( 'page_restrictions' => '' ), array ( 'page_id' => $id ), __METHOD__ ); + } wfRunHooks( 'ArticleProtectComplete', array( &$this, &$wgUser, $limit, $reason ) ); diff --git a/includes/ProtectionForm.php b/includes/ProtectionForm.php index 6004d046fe..066054fc4d 100644 --- a/includes/ProtectionForm.php +++ b/includes/ProtectionForm.php @@ -39,6 +39,7 @@ class ProtectionForm { // but the db allows multiples separated by commas. $this->mRestrictions[$action] = implode( '', $this->mTitle->getRestrictions( $action ) ); } + $this->mCascade = $this->mTitle->areRestrictionsCascading(); } diff --git a/includes/Title.php b/includes/Title.php index 1c28a9b489..11a694096d 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -59,6 +59,7 @@ class Title { var $mDefaultNamespace; # Namespace index when there is no namespace # Zero except in {{transclusion}} tags var $mWatched; # Is $wgUser watching this page? NULL if unfilled, accessed through userIsWatching() + var $mOldRestrictions; # Is the page using old-fashioned page_restrictions column? /**#@-*/ @@ -78,6 +79,7 @@ class Title { $this->mDefaultNamespace = NS_MAIN; $this->mWatched = NULL; $this->mLatestID = false; + $this->mOldRestrictions = false; } /** @@ -1370,7 +1372,7 @@ class Title { $dbr =& wfGetDb( DB_SLAVE ); - $cols = array( 'tl_namespace', 'tl_title'/*, 'pr_level', 'pr_type'*/ ); + $cols = array( 'tl_namespace', 'tl_title' ); $tables = array ('templatelinks', 'page_restrictions'); $where_clauses = array( 'tl_namespace' => $this->getNamespace(), 'tl_title' => $this->getDBkey(), 'tl_from=pr_page', 'pr_cascade' => 1 ); @@ -1398,36 +1400,58 @@ class Title { * @param resource $res restrictions as an SQL result. * @access public */ - function loadRestrictionsFromRow( $res ) { + function loadRestrictionsFromRow( $res, $oldFashionedRestrictions = NULL ) { $dbr =& wfGetDb( DB_SLAVE ); - if (!$dbr->numRows( $res ) ) { - # No restrictions - $this->mRestrictionsLoaded = true; - return; - } - $this->mRestrictions['edit'] = array(); $this->mRestrictions['move'] = array(); - while ($row = $dbr->fetchObject( $res ) ) { - # Cycle through all the restrictions. + # Backwards-compatibility: also load the restrictions from the page record (old format). + + if ( $oldFashionedRestrictions == NULL ) { + $oldFashionedRestrictions = $dbr->selectField( 'page', 'page_restrictions', array( 'page_id' => $this->getArticleId() ), __METHOD__ ); + } + + if ($oldFashionedRestrictions != '') { + + foreach( explode( ':', trim( $oldFashionedRestrictions ) ) as $restrict ) { + $temp = explode( '=', trim( $restrict ) ); + if(count($temp) == 1) { + // old old format should be treated as edit/move restriction + $this->mRestrictions["edit"] = explode( ',', trim( $temp[0] ) ); + $this->mRestrictions["move"] = explode( ',', trim( $temp[0] ) ); + } else { + $this->mRestrictions[$temp[0]] = explode( ',', trim( $temp[1] ) ); + } + } + + $this->mOldRestrictions = true; + $this->mCascadeRestriction = false; - $this->mRestrictions[$row->pr_type] = explode( ',', trim( $row->pr_level ) ); + } - $this->mCascadeRestriction |= $row->pr_cascade; + if ($dbr->numRows( $res) ) { + # Current system - load second to make them override. + while ($row = $dbr->fetchObject( $res ) ) { + # Cycle through all the restrictions. + + $this->mRestrictions[$row->pr_type] = explode( ',', trim( $row->pr_level ) ); + + $this->mCascadeRestriction |= $row->pr_cascade; + } } - $this->mRestrictionsLoaded = true; + $this->mLoadedRestrictions = true; } - function loadRestrictions() { + function loadRestrictions( $oldFashionedRestrictions = NULL ) { if( !$this->mRestrictionsLoaded ) { $dbr =& wfGetDB( DB_SLAVE ); $res = $dbr->select( 'page_restrictions', '*', array ( 'pr_page' => $this->getArticleId() ), __METHOD__ ); - $this->loadRestrictionsFromRow( $res ); + + $this->loadRestrictionsFromRow( $res, $oldFashionedRestrictions ); } } diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index 0468de7b7c..e781df0d54 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -982,6 +982,9 @@ function do_restrictions_update() { $restrictions[$type] = $level; } } + + $wgDatabase->update( 'page', array ( 'page_restrictions' => ''), array( 'page_id' => $id ), __METHOD__ ); + } foreach( $restrictions as $type => $level ) { -- 2.20.1