Restore backwards-compatibility for old types of restrictions; wipe page_restrictions...
authorAndrew Garrett <werdna@users.mediawiki.org>
Fri, 12 Jan 2007 01:44:33 +0000 (01:44 +0000)
committerAndrew Garrett <werdna@users.mediawiki.org>
Fri, 12 Jan 2007 01:44:33 +0000 (01:44 +0000)
includes/Article.php
includes/ProtectionForm.php
includes/Title.php
maintenance/updaters.inc

index 9a7d629..cda171c 100644 (file)
@@ -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 ) );
        
index 6004d04..066054f 100644 (file)
@@ -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();
                }
 
index 1c28a9b..11a6940 100644 (file)
@@ -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 );
                }
        }
 
index 0468de7..e781df0 100644 (file)
@@ -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 ) {