*/
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' );
$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 ) {
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;
}
</p>
!! end
+!! test
+Broken link with fragment
+!! input
+[[Zigzagzogzagzig#zug]]
+!! result
+<p><a href="/index.php?title=Zigzagzogzagzig&action=edit&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
</div></blockquote>
!! end
+
+
#
#
#