Merge "Convert Special:DeletedContributions to use OOUI."
[lhc/web/wiklou.git] / includes / Title.php
index 16c715d..3c51bae 100644 (file)
@@ -1104,7 +1104,7 @@ class Title implements LinkTarget {
        /**
         * Returns true if the title is inside one of the specified namespaces.
         *
-        * @param int $namespaces,... The namespaces to check for
+        * @param int|int[] $namespaces,... The namespaces to check for
         * @return bool
         * @since 1.19
         */
@@ -1412,7 +1412,6 @@ class Title implements LinkTarget {
                        $fragment,
                        $this->getInterwiki()
                );
-
        }
 
        /**
@@ -2873,23 +2872,6 @@ class Title implements LinkTarget {
                return $this->mCascadeRestriction;
        }
 
-       /**
-        * Loads a string into mRestrictions array
-        *
-        * @param ResultWrapper $res Resource restrictions as an SQL result.
-        * @param string $oldFashionedRestrictions Comma-separated list of page
-        *        restrictions from page table (pre 1.10)
-        */
-       private function loadRestrictionsFromResultWrapper( $res, $oldFashionedRestrictions = null ) {
-               $rows = [];
-
-               foreach ( $res as $row ) {
-                       $rows[] = $row;
-               }
-
-               $this->loadRestrictionsFromRows( $rows, $oldFashionedRestrictions );
-       }
-
        /**
         * Compiles list of active page restrictions from both page table (pre 1.10)
         * and page_restrictions table for this existing page.
@@ -2943,7 +2925,6 @@ class Title implements LinkTarget {
 
                        # Cycle through all the restrictions.
                        foreach ( $rows as $row ) {
-
                                // Don't take care of restrictions types that aren't allowed
                                if ( !in_array( $row->pr_type, $restrictionTypes ) ) {
                                        continue;
@@ -2973,36 +2954,53 @@ class Title implements LinkTarget {
         *   restrictions from page table (pre 1.10)
         */
        public function loadRestrictions( $oldFashionedRestrictions = null ) {
-               if ( !$this->mRestrictionsLoaded ) {
-                       $dbr = wfGetDB( DB_REPLICA );
-                       if ( $this->exists() ) {
-                               $res = $dbr->select(
-                                       'page_restrictions',
-                                       [ 'pr_type', 'pr_expiry', 'pr_level', 'pr_cascade' ],
-                                       [ 'pr_page' => $this->getArticleID() ],
-                                       __METHOD__
-                               );
+               if ( $this->mRestrictionsLoaded ) {
+                       return;
+               }
 
-                               $this->loadRestrictionsFromResultWrapper( $res, $oldFashionedRestrictions );
-                       } else {
-                               $title_protection = $this->getTitleProtection();
-
-                               if ( $title_protection ) {
-                                       $now = wfTimestampNow();
-                                       $expiry = $dbr->decodeExpiry( $title_protection['expiry'] );
-
-                                       if ( !$expiry || $expiry > $now ) {
-                                               // Apply the restrictions
-                                               $this->mRestrictionsExpiry['create'] = $expiry;
-                                               $this->mRestrictions['create'] = explode( ',', trim( $title_protection['permission'] ) );
-                                       } else { // Get rid of the old restrictions
-                                               $this->mTitleProtection = false;
-                                       }
-                               } else {
-                                       $this->mRestrictionsExpiry['create'] = 'infinity';
+               $id = $this->getArticleID();
+               if ( $id ) {
+                       $cache = ObjectCache::getMainWANInstance();
+                       $rows = $cache->getWithSetCallback(
+                               // Page protections always leave a new null revision
+                               $cache->makeKey( 'page-restrictions', $id, $this->getLatestRevID() ),
+                               $cache::TTL_DAY,
+                               function ( $curValue, &$ttl, array &$setOpts ) {
+                                       $dbr = wfGetDB( DB_REPLICA );
+
+                                       $setOpts += Database::getCacheSetOptions( $dbr );
+
+                                       return iterator_to_array(
+                                               $dbr->select(
+                                                       'page_restrictions',
+                                                       [ 'pr_type', 'pr_expiry', 'pr_level', 'pr_cascade' ],
+                                                       [ 'pr_page' => $this->getArticleID() ],
+                                                       __METHOD__
+                                               )
+                                       );
                                }
-                               $this->mRestrictionsLoaded = true;
+                       );
+
+                       $this->loadRestrictionsFromRows( $rows, $oldFashionedRestrictions );
+               } else {
+                       $title_protection = $this->getTitleProtection();
+
+                       if ( $title_protection ) {
+                               $now = wfTimestampNow();
+                               $expiry = wfGetDB( DB_REPLICA )->decodeExpiry( $title_protection['expiry'] );
+
+                               if ( !$expiry || $expiry > $now ) {
+                                       // Apply the restrictions
+                                       $this->mRestrictionsExpiry['create'] = $expiry;
+                                       $this->mRestrictions['create'] =
+                                               explode( ',', trim( $title_protection['permission'] ) );
+                               } else { // Get rid of the old restrictions
+                                       $this->mTitleProtection = false;
+                               }
+                       } else {
+                               $this->mRestrictionsExpiry['create'] = 'infinity';
                        }
+                       $this->mRestrictionsLoaded = true;
                }
        }
 
@@ -3283,7 +3281,7 @@ class Title implements LinkTarget {
         * This clears some fields in this object, and clears any associated
         * keys in the "bad links" section of the link cache.
         *
-        * - This is called from WikiPage::doEdit() and WikiPage::insertOn() to allow
+        * - This is called from WikiPage::doEditContent() and WikiPage::insertOn() to allow
         * loading of the new page_id. It's also called from
         * WikiPage::doDeleteArticleReal()
         *
@@ -4391,16 +4389,19 @@ class Title implements LinkTarget {
        public function invalidateCache( $purgeTime = null ) {
                if ( wfReadOnly() ) {
                        return false;
-               }
-
-               if ( $this->mArticleID === 0 ) {
+               } elseif ( $this->mArticleID === 0 ) {
                        return true; // avoid gap locking if we know it's not there
                }
 
+               $dbw = wfGetDB( DB_MASTER );
+               $dbw->onTransactionPreCommitOrIdle( function () {
+                       ResourceLoaderWikiModule::invalidateModuleCache( $this, null, null, wfWikiID() );
+               } );
+
                $conds = $this->pageCond();
                DeferredUpdates::addUpdate(
                        new AutoCommitUpdate(
-                               wfGetDB( DB_MASTER ),
+                               $dbw,
                                __METHOD__,
                                function ( IDatabase $dbw, $fname ) use ( $conds, $purgeTime ) {
                                        $dbTimestamp = $dbw->timestamp( $purgeTime ?: time() );
@@ -4597,7 +4598,6 @@ class Title implements LinkTarget {
                        : $wgExemptFromUserRobotsControl;
 
                return !in_array( $this->mNamespace, $bannedNamespaces );
-
        }
 
        /**