Merge "build: Add 'svgmin' Grunt task and crush SVGs"
[lhc/web/wiklou.git] / includes / Title.php
index d1f2fd9..9112855 100644 (file)
@@ -1609,11 +1609,15 @@ class Title implements LinkTarget, IDBAccessObject {
        public function getFragmentForURL() {
                if ( !$this->hasFragment() ) {
                        return '';
-               } elseif ( $this->isExternal()
-                       && !self::getInterwikiLookup()->fetch( $this->mInterwiki )->isLocal()
-               ) {
-                       return '#' . Sanitizer::escapeIdForExternalInterwiki( $this->mFragment );
+               } elseif ( $this->isExternal() ) {
+                       // Note: If the interwiki is unknown, it's treated as a namespace on the local wiki,
+                       // so we treat it like a local interwiki.
+                       $interwiki = self::getInterwikiLookup()->fetch( $this->mInterwiki );
+                       if ( $interwiki && !$interwiki->isLocal() ) {
+                               return '#' . Sanitizer::escapeIdForExternalInterwiki( $this->mFragment );
+                       }
                }
+
                return '#' . Sanitizer::escapeIdForLink( $this->mFragment );
        }
 
@@ -1831,7 +1835,7 @@ class Title implements LinkTarget, IDBAccessObject {
         * @endcode
         *
         * @param string $text The subpage name to add to the title
-        * @return Title Subpage title
+        * @return Title|null Subpage title, or null on an error
         * @since 1.20
         */
        public function getSubpage( $text ) {
@@ -2691,14 +2695,42 @@ class Title implements LinkTarget, IDBAccessObject {
                }
 
                $useReplica = ( $rigor !== 'secure' );
-               if ( ( $action == 'edit' || $action == 'create' )
-                       && !$user->isBlockedFrom( $this, $useReplica )
-               ) {
-                       // Don't block the user from editing their own talk page unless they've been
-                       // explicitly blocked from that too.
-               } elseif ( $user->isBlocked() && $user->getBlock()->prevents( $action ) !== false ) {
+               $block = $user->getBlock( $useReplica );
+
+               // The block may explicitly allow an action (like "read" or "upload").
+               if ( $block && $block->prevents( $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 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().
+                       $page = WikiPage::factory( clone $this );
+                       // 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.
-                       $errors[] = $user->getBlock()->getPermissionsError( RequestContext::getMain() );
+                       $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 ( !$actionObj || $actionObj->requiresUnblock() ) {
+                       if ( $user->isBlockedFrom( $this, $useReplica ) ) {
+                               // @todo FIXME: Pass the relevant context into this function.
+                               $errors[] = $block
+                                       ? $block->getPermissionsError( RequestContext::getMain() )
+                                       : [ 'actionblockedtext' ];
+                       }
                }
 
                return $errors;