From b348260b7b7d93be03b877c6d05e7f74c7dfa56d Mon Sep 17 00:00:00 2001
From: Aryeh Gregor
Date: Fri, 1 Aug 2008 22:44:11 +0000
Subject: [PATCH] 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.
---
includes/Linker.php | 18 ++++++++++--------
maintenance/parserTests.txt | 29 +++++++++++++++++++++++++++++
2 files changed, 39 insertions(+), 8 deletions(-)
diff --git a/includes/Linker.php b/includes/Linker.php
index 29e51cdf84..f9eb94b533 100644
--- a/includes/Linker.php
+++ b/includes/Linker.php
@@ -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;
}
diff --git a/maintenance/parserTests.txt b/maintenance/parserTests.txt
index b8ef2590fa..fd17ca66fc 100644
--- a/maintenance/parserTests.txt
+++ b/maintenance/parserTests.txt
@@ -1322,6 +1322,33 @@ Broken link
!! end
+!! test
+Broken link with fragment
+!! input
+[[Zigzagzogzagzig#zug]]
+!! result
+Zigzagzogzagzig#zug
+
+!! end
+
+!! test
+Special page link with fragment
+!! input
+[[Special:Version#anchor]]
+!! result
+Special:Version#anchor
+
+!! end
+
+!! test
+Nonexistent special page link with fragment
+!! input
+[[Special:ThisNameWillHopefullyNeverBeUsed#anchor]]
+!! result
+Special:ThisNameWillHopefullyNeverBeUsed#anchor
+
+!! end
+
!! test
Link with prefix
!! input
@@ -7011,6 +7038,8 @@ Line two
!! end
+
+
#
#
#
--
2.20.1