Address my r76242 fixme.
authorPlatonides <platonides@users.mediawiki.org>
Thu, 6 Jan 2011 21:26:20 +0000 (21:26 +0000)
committerPlatonides <platonides@users.mediawiki.org>
Thu, 6 Jan 2011 21:26:20 +0000 (21:26 +0000)
Remove invalidateTitleProtectionCache().
Set $mTitleProtection to the proper value when we change it instead of forcing a reload via the protected_titles table.
Make Title::loadRestrictionsFromRows() private since it is only called by the private loadRestrictionsFromResultWrapper() and nobody should be fiddling with such title internals anyway  (follow up to r54527).
Removed the invalidateTitleProtectionCache() from getCascadeProtectionSources() since that function only deals with titles which do exist. There's nothing to invalidate there.

includes/Title.php

index f8215b9..429130c 100644 (file)
@@ -72,7 +72,7 @@ class Title {
        var $mCascadeSources;             ///< Where are the cascading restrictions coming from on this page?
        var $mRestrictionsLoaded = false; ///< Boolean for initialisation on demand
        var $mPrefixedText;               ///< Text form including namespace/interwiki, initialised on demand
-       var $mTitleProtection;            ///< Cached value of getTitleProtection
+       var $mTitleProtection;            ///< Cached value for getTitleProtection (create protection)
        # Don't change the following default, NS_MAIN is hardcoded in several
        # places.  See bug 696.
        var $mDefaultNamespace = NS_MAIN; // /< Namespace index when there is no namespace
@@ -1629,6 +1629,7 @@ class Title {
 
        /**
         * Is this title subject to title protection?
+        * Title protection is the one applied against creation of such title.
         *
         * @return Mixed An associative array representing any existent title
         *   protection, or false if there's none.
@@ -1656,10 +1657,6 @@ class Title {
                return $this->mTitleProtection;
        }
 
-       private function invalidateTitleProtectionCache() {
-               unset( $this->mTitleProtection );
-       }
-
        /**
         * Update the title protection status
         *
@@ -1693,8 +1690,7 @@ class Title {
 
                # Update protection table
                if ( $create_perm != '' ) {
-                       $dbw->replace( 'protected_titles', array( array( 'pt_namespace', 'pt_title' ) ),
-                               array(
+                       $this->mTitleProtection = array(
                                        'pt_namespace' => $namespace,
                                        'pt_title' => $title,
                                        'pt_create_perm' => $create_perm,
@@ -1702,13 +1698,14 @@ class Title {
                                        'pt_expiry' => $encodedExpiry,
                                        'pt_user' => $wgUser->getId(),
                                        'pt_reason' => $reason,
-                               ), __METHOD__
-                       );
+                               );
+                       $dbw->replace( 'protected_titles', array( array( 'pt_namespace', 'pt_title' ) ),
+                               $this->mTitleProtection, __METHOD__     );
                } else {
                        $dbw->delete( 'protected_titles', array( 'pt_namespace' => $namespace,
                                'pt_title' => $title ), __METHOD__ );
+                       $this->mTitleProtection = false;
                }
-               $this->invalidateTitleProtectionCache();
 
                # Update the protection log
                if ( $dbw->affectedRows() ) {
@@ -1736,7 +1733,7 @@ class Title {
                        array( 'pt_namespace' => $this->getNamespace(), 'pt_title' => $this->getDBkey() ),
                        __METHOD__
                );
-               $this->invalidateTitleProtectionCache();
+               $this->mTitleProtection = false;
        }
 
        /**
@@ -2110,7 +2107,6 @@ class Title {
                }
                if ( $purgeExpired ) {
                        Title::purgeExpiredRestrictions();
-                       $this->invalidateTitleProtectionCache();
                }
 
                wfProfileOut( __METHOD__ );
@@ -2157,13 +2153,13 @@ class Title {
 
        /**
         * Compiles list of active page restrictions from both page table (pre 1.10)
-        * and page_restrictions table
+        * and page_restrictions table for this existing page
         *
         * @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 ) {
+       private function loadRestrictionsFromRows( $rows, $oldFashionedRestrictions = null ) {
                $dbr = wfGetDB( DB_SLAVE );
 
                $restrictionTypes = $this->getRestrictionTypes();
@@ -2230,7 +2226,6 @@ class Title {
 
                        if ( $purgeExpired ) {
                                Title::purgeExpiredRestrictions();
-                               $this->invalidateTitleProtectionCache();
                        }
                }
 
@@ -2265,7 +2260,7 @@ class Title {
                                                $this->mRestrictions['create'] = explode( ',', trim( $title_protection['pt_create_perm'] ) );
                                        } else { // Get rid of the old restrictions
                                                Title::purgeExpiredRestrictions();
-                                               $this->invalidateTitleProtectionCache();
+                                               $this->mTitleProtection = false;
                                        }
                                } else {
                                        $this->mRestrictionsExpiry['create'] = Block::decodeExpiry( '' );