Fix the regression Brion noticed (not caused by me!) with special page links getting...
authorAryeh Gregor <simetrical@users.mediawiki.org>
Fri, 1 Aug 2008 22:44:11 +0000 (22:44 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Fri, 1 Aug 2008 22:44:11 +0000 (22:44 +0000)
includes/Linker.php
maintenance/parserTests.txt

index 29e51cd..f9eb94b 100644 (file)
@@ -168,18 +168,13 @@ class Linker {
         */
        public function link( $target, $text = null, $customAttribs = array(), $query = array(), $options = array() ) {
                wfProfileIn( __METHOD__ );
-               if( !($target instanceof Title) ) {
+               if( !$target instanceof Title ) {
                        throw new MWException( 'Linker::link passed invalid target' );
                }
                $options = (array)$options;
 
                # Normalize the Title if it's a special page
-               if( $target->getNamespace() == NS_SPECIAL ) {
-                       list( $name, $subpage ) = SpecialPage::resolveAliasWithSubpage( $target->getDBkey() );
-                       if( $name ) {
-                               $target = SpecialPage::getTitleFor( $name, $subpage );
-                       }
-               }
+               $target = $this->normaliseSpecialPage( $target );
 
                # If we don't know whether the page exists, let's find out.
                wfProfileIn( __METHOD__ . '-checkPageExistence' );
@@ -523,6 +518,11 @@ class Linker {
                        $q = 'action=edit&redlink=1&'.$query;
                }
                $u = $nt->escapeLocalURL( $q );
+               if( $nt->getFragmentForURL() !== '' ) {
+                       # Might seem pointless to have a fragment on a redlink, but let's
+                       # be obedient.
+                       $u .= $nt->getFragmentForURL();
+               }
 
                $titleText = $nt->getPrefixedText();
                if ( '' == $text ) {
@@ -610,7 +610,9 @@ class Linker {
                if ( $title->getNamespace() == NS_SPECIAL ) {
                        list( $name, $subpage ) = SpecialPage::resolveAliasWithSubpage( $title->getDBkey() );
                        if ( !$name ) return $title;
-                       return SpecialPage::getTitleFor( $name, $subpage );
+                       $ret = SpecialPage::getTitleFor( $name, $subpage );
+                       $ret->mFragment = $title->getFragment();
+                       return $ret;
                } else {
                        return $title;
                }
index b8ef259..fd17ca6 100644 (file)
@@ -1322,6 +1322,33 @@ Broken link
 </p>
 !! end
 
+!! test
+Broken link with fragment
+!! input
+[[Zigzagzogzagzig#zug]]
+!! result
+<p><a href="/index.php?title=Zigzagzogzagzig&amp;action=edit&amp;redlink=1#zug" class="new" title="Zigzagzogzagzig (not yet written)">Zigzagzogzagzig#zug</a>
+</p>
+!! end
+
+!! test
+Special page link with fragment
+!! input
+[[Special:Version#anchor]]
+!! result
+<p><a href="/wiki/Special:Version#anchor" title="Special:Version">Special:Version#anchor</a>
+</p>
+!! end
+
+!! test
+Nonexistent special page link with fragment
+!! input
+[[Special:ThisNameWillHopefullyNeverBeUsed#anchor]]
+!! result
+<p><a href="/wiki/Special:ThisNameWillHopefullyNeverBeUsed#anchor" class="new" title="Special:ThisNameWillHopefullyNeverBeUsed (not yet written)">Special:ThisNameWillHopefullyNeverBeUsed#anchor</a>
+</p>
+!! end
+
 !! test
 Link with prefix
 !! input
@@ -7011,6 +7038,8 @@ Line two
 </div></blockquote>
 
 !! end
+
+
 #
 #
 #