r68342 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68341‎ | r68342 | r68343 >
Date:23:43, 20 June 2010
Author:conrad
Status:ok
Tags:
Comment:
(bug 17857) Make {{anchorencode}} work in a manner more similar to the way that
section links are created by the parser. Also useful for (bug 18431).
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/parser/CoreParserFunctions.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/maintenance/parserTests.txt (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/parserTests.txt
@@ -6920,8 +6920,46 @@
69216921 </p>
69226922 !! end
69236923
 6924+!! test
 6925+anchorencode trims spaces
 6926+!! input
 6927+{{anchorencode: __pretty__please__}}
 6928+!! result
 6929+<p>pretty_please
 6930+</p>
 6931+!! end
69246932
69256933 !! test
 6934+anchorencode deals with links
 6935+!! input
 6936+{{anchorencode: [[hello|world]] [[hi]]}}
 6937+!! result
 6938+<p>world_hi
 6939+</p>
 6940+!! end
 6941+
 6942+!! test
 6943+anchorencode deals with templates
 6944+!! input
 6945+{{anchorencode: {{Foo}} }}
 6946+!! result
 6947+<p>FOO
 6948+</p>
 6949+!! end
 6950+
 6951+!! test
 6952+anchorencode encodes like the TOC generator: (bug 18431)
 6953+!! input
 6954+=== _ +:.3A%3A&&amp;]] ===
 6955+{{anchorencode: _ +:.3A%3A&&amp;]] }}
 6956+__NOEDITSECTION__
 6957+!! result
 6958+<h3> <span class="mw-headline" id=".2B:.3A.253A.26.26.5D.5D"> _ +:.3A%3A&amp;&amp;]] </span></h3>
 6959+<p>.2B:.3A.253A.26.26.5D.5D
 6960+</p>
 6961+!! end
 6962+
 6963+!! test
69266964 Bug 8293: Use of center tag ruins paragraph formatting
69276965 !! input
69286966 <center>
Index: trunk/phase3/includes/parser/Parser.php
@@ -5172,19 +5172,8 @@
51735173 public function guessSectionNameFromWikiText( $text ) {
51745174 # Strip out wikitext links(they break the anchor)
51755175 $text = $this->stripSectionName( $text );
5176 - $headline = Sanitizer::decodeCharReferences( $text );
5177 - # strip out HTML
5178 - $headline = StringUtils::delimiterReplace( '<', '>', '', $headline );
5179 - $headline = trim( $headline );
5180 - $sectionanchor = '#' . urlencode( str_replace( ' ', '_', $headline ) );
5181 - $replacearray = array(
5182 - '%3A' => ':',
5183 - '%' => '.'
5184 - );
5185 - return str_replace(
5186 - array_keys( $replacearray ),
5187 - array_values( $replacearray ),
5188 - $sectionanchor );
 5176+ $text = trim( preg_replace( '/[ _]+/', ' ', $text ) );
 5177+ return '#' . Sanitizer::escapeId( $text, 'noninitial' );
51895178 }
51905179
51915180 /**
Index: trunk/phase3/includes/parser/CoreParserFunctions.php
@@ -582,11 +582,7 @@
583583 }
584584
585585 static function anchorencode( $parser, $text ) {
586 - $a = urlencode( $text );
587 - $a = strtr( $a, array( '%' => '.', '+' => '_' ) );
588 - # leave colons alone, however
589 - $a = str_replace( '.3A', ':', $a );
590 - return $a;
 586+ return substr( $parser->guessSectionNameFromWikiText( $text ), 1);
591587 }
592588
593589 static function special( $parser, $text ) {
Index: trunk/phase3/RELEASE-NOTES
@@ -86,6 +86,7 @@
8787 * (bug 23621) New Special:ComparePages to compare (diff) two articles.
8888 * (bug 4597) Provide support in Special:Contributions to show only "current"
8989 contributions
 90+* (bug 17857) {{anchorencode}} acts more like how the parser creates section ids.
9091
9192 === Bug fixes in 1.17 ===
9293 * (bug 17560) Half-broken deletion moved image files to deletion archive

Follow-up revisions

RevisionCommit summaryAuthorDate
r68358(bug 18431) Remove initial whitespace from fragment in Title::secureAndSplit()conrad14:08, 21 June 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r68272The rendering of autosummary in History and Diff pages did not properly escap...hartman13:40, 19 June 2010

Status & tagging log