Merge "Update OOUI to v0.30.4"
[lhc/web/wiklou.git] / includes / Title.php
index f5904e2..82e79b3 100644 (file)
@@ -37,8 +37,8 @@ use MediaWiki\MediaWikiServices;
  *       and does not rely on global state or the database.
  */
 class Title implements LinkTarget, IDBAccessObject {
-       /** @var MapCacheLRU */
-       static private $titleCache = null;
+       /** @var MapCacheLRU|null */
+       private static $titleCache = null;
 
        /**
         * Title::newFromText maintains a cache to avoid expensive re-normalization of
@@ -140,7 +140,7 @@ class Title implements LinkTarget, IDBAccessObject {
         * Only public to share cache with TitleFormatter
         *
         * @private
-        * @var string
+        * @var string|null
         */
        public $prefixedText = null;
 
@@ -173,10 +173,10 @@ class Title implements LinkTarget, IDBAccessObject {
         * the database or false if not loaded, yet. */
        private $mDbPageLanguage = false;
 
-       /** @var TitleValue A corresponding TitleValue object */
+       /** @var TitleValue|null A corresponding TitleValue object */
        private $mTitleValue = null;
 
-       /** @var bool Would deleting this page be a big deletion? */
+       /** @var bool|null Would deleting this page be a big deletion? */
        private $mIsBigDeletion = null;
        // @}
 
@@ -205,7 +205,7 @@ class Title implements LinkTarget, IDBAccessObject {
        }
 
        /**
-        * @access protected
+        * @protected
         */
        function __construct() {
        }
@@ -219,7 +219,7 @@ class Title implements LinkTarget, IDBAccessObject {
         * @return Title|null Title, or null on an error
         */
        public static function newFromDBkey( $key ) {
-               $t = new Title();
+               $t = new self();
                $t->mDbkeyform = $key;
 
                try {
@@ -287,7 +287,7 @@ class Title implements LinkTarget, IDBAccessObject {
                }
 
                try {
-                       return self::newFromTextThrow( strval( $text ), $defaultNamespace );
+                       return self::newFromTextThrow( (string)$text, $defaultNamespace );
                } catch ( MalformedTitleException $ex ) {
                        return null;
                }
@@ -337,7 +337,7 @@ class Title implements LinkTarget, IDBAccessObject {
 
                $t = new Title();
                $t->mDbkeyform = strtr( $filteredText, ' ', '_' );
-               $t->mDefaultNamespace = intval( $defaultNamespace );
+               $t->mDefaultNamespace = (int)$defaultNamespace;
 
                $t->secureAndSplit();
                if ( $defaultNamespace == NS_MAIN ) {
@@ -385,7 +385,7 @@ class Title implements LinkTarget, IDBAccessObject {
         * @return MapCacheLRU
         */
        private static function getTitleCache() {
-               if ( self::$titleCache == null ) {
+               if ( self::$titleCache === null ) {
                        self::$titleCache = new MapCacheLRU( self::CACHE_MAX );
                }
                return self::$titleCache;
@@ -499,7 +499,7 @@ class Title implements LinkTarget, IDBAccessObject {
                                $this->mLatestID = (int)$row->page_latest;
                        }
                        if ( !$this->mForcedContentModel && isset( $row->page_content_model ) ) {
-                               $this->mContentModel = strval( $row->page_content_model );
+                               $this->mContentModel = (string)$row->page_content_model;
                        } elseif ( !$this->mForcedContentModel ) {
                                $this->mContentModel = false; # initialized lazily in getContentModel()
                        }
@@ -546,7 +546,7 @@ class Title implements LinkTarget, IDBAccessObject {
                $t = new Title();
                $t->mInterwiki = $interwiki;
                $t->mFragment = $fragment;
-               $t->mNamespace = $ns = intval( $ns );
+               $t->mNamespace = $ns = (int)$ns;
                $t->mDbkeyform = strtr( $title, ' ', '_' );
                $t->mArticleID = ( $ns >= 0 ) ? -1 : 0;
                $t->mUrlform = wfUrlencode( $t->mDbkeyform );
@@ -767,23 +767,6 @@ class Title implements LinkTarget, IDBAccessObject {
                return $name;
        }
 
-       /**
-        * Escape a text fragment, say from a link, for a URL
-        *
-        * @deprecated since 1.30, use Sanitizer::escapeIdForLink() or escapeIdForExternalInterwiki()
-        *
-        * @param string $fragment Containing a URL or link fragment (after the "#")
-        * @return string Escaped string
-        */
-       static function escapeFragmentForURL( $fragment ) {
-               wfDeprecated( __METHOD__, '1.30' );
-               # Note that we don't urlencode the fragment.  urlencoded Unicode
-               # fragments appear not to work in IE (at least up to 7) or in at least
-               # one version of Opera 9.x.  The W3C validator, for one, doesn't seem
-               # to care if they aren't encoded.
-               return Sanitizer::escapeId( $fragment, 'noninitial' );
-       }
-
        /**
         * Callback for usort() to do title sorts by (namespace, title)
         *
@@ -1071,17 +1054,6 @@ class Title implements LinkTarget, IDBAccessObject {
                        getNsText( MWNamespace::getTalk( $this->mNamespace ) );
        }
 
-       /**
-        * Can this title have a corresponding talk page?
-        *
-        * @deprecated since 1.30, use canHaveTalkPage() instead.
-        *
-        * @return bool True if this title either is a talk page or can have a talk page associated.
-        */
-       public function canTalk() {
-               return $this->canHaveTalkPage();
-       }
-
        /**
         * Can this title have a corresponding talk page?
         *
@@ -1308,17 +1280,6 @@ class Title implements LinkTarget, IDBAccessObject {
                );
        }
 
-       /**
-        * @return bool
-        * @deprecated Since 1.31; use ::isSiteConfigPage() instead (which also checks for JSON pages)
-        */
-       public function isCssOrJsPage() {
-               wfDeprecated( __METHOD__, '1.31' );
-               return ( NS_MEDIAWIKI == $this->mNamespace
-                               && ( $this->hasContentModel( CONTENT_MODEL_CSS )
-                                       || $this->hasContentModel( CONTENT_MODEL_JAVASCRIPT ) ) );
-       }
-
        /**
         * Is this a "config" (.css, .json, or .js) sub-page of a user page?
         *
@@ -1333,17 +1294,6 @@ class Title implements LinkTarget, IDBAccessObject {
                );
        }
 
-       /**
-        * @return bool
-        * @deprecated Since 1.31; use ::isUserConfigPage() instead (which also checks for JSON pages)
-        */
-       public function isCssJsSubpage() {
-               wfDeprecated( __METHOD__, '1.31' );
-               return ( NS_USER == $this->mNamespace && $this->isSubpage()
-                               && ( $this->hasContentModel( CONTENT_MODEL_CSS )
-                                       || $this->hasContentModel( CONTENT_MODEL_JAVASCRIPT ) ) );
-       }
-
        /**
         * Trim down a .css, .json, or .js subpage title to get the corresponding skin name
         *
@@ -1360,15 +1310,6 @@ class Title implements LinkTarget, IDBAccessObject {
                return substr( $subpage, 0, $lastdot );
        }
 
-       /**
-        * @deprecated Since 1.31; use ::getSkinFromConfigSubpage() instead
-        * @return string Containing skin name from .css, .json, or .js subpage title
-        */
-       public function getSkinFromCssJsSubpage() {
-               wfDeprecated( __METHOD__, '1.31' );
-               return $this->getSkinFromConfigSubpage();
-       }
-
        /**
         * Is this a CSS "config" sub-page of a user page?
         *
@@ -1383,15 +1324,6 @@ class Title implements LinkTarget, IDBAccessObject {
                );
        }
 
-       /**
-        * @deprecated Since 1.31; use ::isUserCssConfigPage()
-        * @return bool
-        */
-       public function isCssSubpage() {
-               wfDeprecated( __METHOD__, '1.31' );
-               return $this->isUserCssConfigPage();
-       }
-
        /**
         * Is this a JSON "config" sub-page of a user page?
         *
@@ -1420,15 +1352,6 @@ class Title implements LinkTarget, IDBAccessObject {
                );
        }
 
-       /**
-        * @deprecated Since 1.31; use ::isUserJsConfigPage()
-        * @return bool
-        */
-       public function isJsSubpage() {
-               wfDeprecated( __METHOD__, '1.31' );
-               return $this->isUserJsConfigPage();
-       }
-
        /**
         * Is this a sitewide CSS "config" page?
         *
@@ -2697,16 +2620,18 @@ class Title implements LinkTarget, IDBAccessObject {
                $useReplica = ( $rigor !== 'secure' );
                $block = $user->getBlock( $useReplica );
 
-               // The block may explicitly allow an action (like "read" or "upload").
-               if ( $block && $block->prevents( $action ) === false ) {
+               // If the user does not have a block, or the block they do have explicitly
+               // allows the action (like "read" or "upload").
+               if ( !$block || $block->appliesToRight( $action ) === false ) {
                        return $errors;
                }
 
                // Determine if the user is blocked from this action on this page.
-               // What gets passed into this method is a user right, not an action nmae.
+               // What gets passed into this method is a user right, not an action name.
                // There is no way to instantiate an action by restriction. However, this
                // will get the action where the restriction is the same. This may result
                // in actions being blocked that shouldn't be.
+               $actionObj = null;
                if ( Action::exists( $action ) ) {
                        // Clone the title to prevent mutations to this object which is done
                        // by Title::loadFromRow() in WikiPage::loadFromRow().
@@ -2714,19 +2639,19 @@ class Title implements LinkTarget, IDBAccessObject {
                        // Creating an action will perform several database queries to ensure that
                        // the action has not been overridden by the content type.
                        // @todo FIXME: Pass the relevant context into this function.
-                       $action = Action::factory( $action, $page, RequestContext::getMain() );
-               } else {
-                       $action = null;
+                       $actionObj = Action::factory( $action, $page, RequestContext::getMain() );
+                       // Ensure that the retrieved action matches the restriction.
+                       if ( $actionObj && $actionObj->getRestriction() !== $action ) {
+                               $actionObj = null;
+                       }
                }
 
                // If no action object is returned, assume that the action requires unblock
                // which is the default.
-               if ( !$action || $action->requiresUnblock() ) {
+               if ( !$actionObj || $actionObj->requiresUnblock() ) {
                        if ( $user->isBlockedFrom( $this, $useReplica ) ) {
                                // @todo FIXME: Pass the relevant context into this function.
-                               $errors[] = $block
-                                       ? $block->getPermissionsError( RequestContext::getMain() )
-                                       : [ 'actionblockedtext' ];
+                               $errors[] = $block->getPermissionsError( RequestContext::getMain() );
                        }
                }
 
@@ -3412,7 +3337,7 @@ class Title implements LinkTarget, IDBAccessObject {
                                $dbr = wfGetDB( DB_MASTER );
                                $rows = $loadRestrictionsFromDb( $dbr );
                        } else {
-                               $cache = ObjectCache::getMainWANInstance();
+                               $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                                $rows = $cache->getWithSetCallback(
                                        // Page protections always leave a new null revision
                                        $cache->makeKey( 'page-restrictions', $id, $this->getLatestRevID() ),
@@ -4017,13 +3942,6 @@ class Title implements LinkTarget, IDBAccessObject {
                return $urls;
        }
 
-       /**
-        * @deprecated since 1.27 use getCdnUrls()
-        */
-       public function getSquidURLs() {
-               return $this->getCdnUrls();
-       }
-
        /**
         * Purge all applicable CDN URLs
         */
@@ -4065,28 +3983,6 @@ class Title implements LinkTarget, IDBAccessObject {
                return $errors ?: true;
        }
 
-       /**
-        * Check if the requested move target is a valid file move target
-        * @todo move this to MovePage
-        * @param Title $nt Target title
-        * @return array List of errors
-        */
-       protected function validateFileMoveOperation( $nt ) {
-               global $wgUser;
-
-               $errors = [];
-
-               $destFile = wfLocalFile( $nt );
-               $destFile->load( File::READ_LATEST );
-               if ( !$wgUser->isAllowed( 'reupload-shared' )
-                       && !$destFile->exists() && wfFindFile( $nt )
-               ) {
-                       $errors[] = [ 'file-exists-sharedrepo' ];
-               }
-
-               return $errors;
-       }
-
        /**
         * Move a title to a new location
         *