Index: trunk/phase3/maintenance/parserTests.txt |
— | — | @@ -1323,6 +1323,33 @@ |
1324 | 1324 | !! end |
1325 | 1325 | |
1326 | 1326 | !! test |
| 1327 | +Broken link with fragment |
| 1328 | +!! input |
| 1329 | +[[Zigzagzogzagzig#zug]] |
| 1330 | +!! result |
| 1331 | +<p><a href="https://www.mediawiki.org/index.php?title=Zigzagzogzagzig&action=edit&redlink=1#zug" class="new" title="Zigzagzogzagzig (not yet written)">Zigzagzogzagzig#zug</a> |
| 1332 | +</p> |
| 1333 | +!! end |
| 1334 | + |
| 1335 | +!! test |
| 1336 | +Special page link with fragment |
| 1337 | +!! input |
| 1338 | +[[Special:Version#anchor]] |
| 1339 | +!! result |
| 1340 | +<p><a href="https://www.mediawiki.org/wiki/Special:Version#anchor" title="Special:Version">Special:Version#anchor</a> |
| 1341 | +</p> |
| 1342 | +!! end |
| 1343 | + |
| 1344 | +!! test |
| 1345 | +Nonexistent special page link with fragment |
| 1346 | +!! input |
| 1347 | +[[Special:ThisNameWillHopefullyNeverBeUsed#anchor]] |
| 1348 | +!! result |
| 1349 | +<p><a href="https://www.mediawiki.org/wiki/Special:ThisNameWillHopefullyNeverBeUsed#anchor" class="new" title="Special:ThisNameWillHopefullyNeverBeUsed (not yet written)">Special:ThisNameWillHopefullyNeverBeUsed#anchor</a> |
| 1350 | +</p> |
| 1351 | +!! end |
| 1352 | + |
| 1353 | +!! test |
1327 | 1354 | Link with prefix |
1328 | 1355 | !! input |
1329 | 1356 | xxx[[main Page]], xxx[[Main Page]], Xxx[[main Page]] XXX[[main Page]], XXX[[Main Page]] |
— | — | @@ -7011,6 +7038,8 @@ |
7012 | 7039 | </div></blockquote> |
7013 | 7040 | |
7014 | 7041 | !! end |
| 7042 | + |
| 7043 | + |
7015 | 7044 | # |
7016 | 7045 | # |
7017 | 7046 | # |
Index: trunk/phase3/includes/Linker.php |
— | — | @@ -168,18 +168,13 @@ |
169 | 169 | */ |
170 | 170 | public function link( $target, $text = null, $customAttribs = array(), $query = array(), $options = array() ) { |
171 | 171 | wfProfileIn( __METHOD__ ); |
172 | | - if( !($target instanceof Title) ) { |
| 172 | + if( !$target instanceof Title ) { |
173 | 173 | throw new MWException( 'Linker::link passed invalid target' ); |
174 | 174 | } |
175 | 175 | $options = (array)$options; |
176 | 176 | |
177 | 177 | # Normalize the Title if it's a special page |
178 | | - if( $target->getNamespace() == NS_SPECIAL ) { |
179 | | - list( $name, $subpage ) = SpecialPage::resolveAliasWithSubpage( $target->getDBkey() ); |
180 | | - if( $name ) { |
181 | | - $target = SpecialPage::getTitleFor( $name, $subpage ); |
182 | | - } |
183 | | - } |
| 178 | + $target = $this->normaliseSpecialPage( $target ); |
184 | 179 | |
185 | 180 | # If we don't know whether the page exists, let's find out. |
186 | 181 | wfProfileIn( __METHOD__ . '-checkPageExistence' ); |
— | — | @@ -523,6 +518,11 @@ |
524 | 519 | $q = 'action=edit&redlink=1&'.$query; |
525 | 520 | } |
526 | 521 | $u = $nt->escapeLocalURL( $q ); |
| 522 | + if( $nt->getFragmentForURL() !== '' ) { |
| 523 | + # Might seem pointless to have a fragment on a redlink, but let's |
| 524 | + # be obedient. |
| 525 | + $u .= $nt->getFragmentForURL(); |
| 526 | + } |
527 | 527 | |
528 | 528 | $titleText = $nt->getPrefixedText(); |
529 | 529 | if ( '' == $text ) { |
— | — | @@ -610,7 +610,9 @@ |
611 | 611 | if ( $title->getNamespace() == NS_SPECIAL ) { |
612 | 612 | list( $name, $subpage ) = SpecialPage::resolveAliasWithSubpage( $title->getDBkey() ); |
613 | 613 | if ( !$name ) return $title; |
614 | | - return SpecialPage::getTitleFor( $name, $subpage ); |
| 614 | + $ret = SpecialPage::getTitleFor( $name, $subpage ); |
| 615 | + $ret->mFragment = $title->getFragment(); |
| 616 | + return $ret; |
615 | 617 | } else { |
616 | 618 | return $title; |
617 | 619 | } |