Merge "wdio-mediawiki: Release 0.3.0"
[lhc/web/wiklou.git] / includes / Title.php
index 3496668..6ada9b3 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 );
        }
 
@@ -2704,8 +2708,13 @@ class Title implements LinkTarget, IDBAccessObject {
                // will get the action where the restriction is the same. This may result
                // in actions being blocked that shouldn't be.
                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.
-                       $action = Action::factory( $action, WikiPage::factory( $this ), RequestContext::getMain() );
+                       $action = Action::factory( $action, $page, RequestContext::getMain() );
                } else {
                        $action = null;
                }