Fix the regression Brion noticed (not caused by me!) with special page links getting fragments eaten. I noticed that additionally, all nonexistent pages with fragments eat the fragment, and fixed that. Added three new passing parser tests.
This commit is contained in:
parent
b5759288a6
commit
b348260b7b
2 changed files with 39 additions and 8 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1322,6 +1322,33 @@ Broken link
|
|||
</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
|
||||
|
|
@ -7011,6 +7038,8 @@ Line two
|
|||
</div></blockquote>
|
||||
|
||||
!! end
|
||||
|
||||
|
||||
#
|
||||
#
|
||||
#
|
||||
|
|
|
|||
Loading…
Reference in a new issue