r38400 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r38399‎ | r38400 | r38401 >
Date:22:44, 1 August 2008
Author:simetrical
Status:old
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/includes/Linker.php (modified) (history)
  • /trunk/phase3/maintenance/parserTests.txt (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/parserTests.txt
@@ -1323,6 +1323,33 @@
13241324 !! end
13251325
13261326 !! 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&amp;action=edit&amp;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
13271354 Link with prefix
13281355 !! input
13291356 xxx[[main Page]], xxx[[Main Page]], Xxx[[main Page]] XXX[[main Page]], XXX[[Main Page]]
@@ -7011,6 +7038,8 @@
70127039 </div></blockquote>
70137040
70147041 !! end
 7042+
 7043+
70157044 #
70167045 #
70177046 #
Index: trunk/phase3/includes/Linker.php
@@ -168,18 +168,13 @@
169169 */
170170 public function link( $target, $text = null, $customAttribs = array(), $query = array(), $options = array() ) {
171171 wfProfileIn( __METHOD__ );
172 - if( !($target instanceof Title) ) {
 172+ if( !$target instanceof Title ) {
173173 throw new MWException( 'Linker::link passed invalid target' );
174174 }
175175 $options = (array)$options;
176176
177177 # 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 );
184179
185180 # If we don't know whether the page exists, let's find out.
186181 wfProfileIn( __METHOD__ . '-checkPageExistence' );
@@ -523,6 +518,11 @@
524519 $q = 'action=edit&redlink=1&'.$query;
525520 }
526521 $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+ }
527527
528528 $titleText = $nt->getPrefixedText();
529529 if ( '' == $text ) {
@@ -610,7 +610,9 @@
611611 if ( $title->getNamespace() == NS_SPECIAL ) {
612612 list( $name, $subpage ) = SpecialPage::resolveAliasWithSubpage( $title->getDBkey() );
613613 if ( !$name ) return $title;
614 - return SpecialPage::getTitleFor( $name, $subpage );
 614+ $ret = SpecialPage::getTitleFor( $name, $subpage );
 615+ $ret->mFragment = $title->getFragment();
 616+ return $ret;
615617 } else {
616618 return $title;
617619 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r38525Change test case added in r38400...brion03:00, 4 August 2008
r38534Followup to r38525 (tweaks from r38400) -- don't put fragments on redlinks; t...brion05:15, 4 August 2008

Status & tagging log