http://www.mediawiki.org/wiki/Special:Code/MediaWiki/68342
Revision: 68342 Author: conrad Date: 2010-06-20 23:43:39 +0000 (Sun, 20 Jun 2010) Log Message: ----------- (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 trunk/phase3/includes/parser/CoreParserFunctions.php trunk/phase3/includes/parser/Parser.php trunk/phase3/maintenance/parserTests.txt Modified: trunk/phase3/RELEASE-NOTES =================================================================== --- trunk/phase3/RELEASE-NOTES 2010-06-20 22:24:47 UTC (rev 68341) +++ trunk/phase3/RELEASE-NOTES 2010-06-20 23:43:39 UTC (rev 68342) @@ -86,6 +86,7 @@ * (bug 23621) New Special:ComparePages to compare (diff) two articles. * (bug 4597) Provide support in Special:Contributions to show only "current" contributions +* (bug 17857) {{anchorencode}} acts more like how the parser creates section ids. === Bug fixes in 1.17 === * (bug 17560) Half-broken deletion moved image files to deletion archive Modified: trunk/phase3/includes/parser/CoreParserFunctions.php =================================================================== --- trunk/phase3/includes/parser/CoreParserFunctions.php 2010-06-20 22:24:47 UTC (rev 68341) +++ trunk/phase3/includes/parser/CoreParserFunctions.php 2010-06-20 23:43:39 UTC (rev 68342) @@ -582,11 +582,7 @@ } static function anchorencode( $parser, $text ) { - $a = urlencode( $text ); - $a = strtr( $a, array( '%' => '.', '+' => '_' ) ); - # leave colons alone, however - $a = str_replace( '.3A', ':', $a ); - return $a; + return substr( $parser->guessSectionNameFromWikiText( $text ), 1); } static function special( $parser, $text ) { Modified: trunk/phase3/includes/parser/Parser.php =================================================================== --- trunk/phase3/includes/parser/Parser.php 2010-06-20 22:24:47 UTC (rev 68341) +++ trunk/phase3/includes/parser/Parser.php 2010-06-20 23:43:39 UTC (rev 68342) @@ -5172,19 +5172,8 @@ public function guessSectionNameFromWikiText( $text ) { # Strip out wikitext links(they break the anchor) $text = $this->stripSectionName( $text ); - $headline = Sanitizer::decodeCharReferences( $text ); - # strip out HTML - $headline = StringUtils::delimiterReplace( '<', '>', '', $headline ); - $headline = trim( $headline ); - $sectionanchor = '#' . urlencode( str_replace( ' ', '_', $headline ) ); - $replacearray = array( - '%3A' => ':', - '%' => '.' - ); - return str_replace( - array_keys( $replacearray ), - array_values( $replacearray ), - $sectionanchor ); + $text = trim( preg_replace( '/[ _]+/', ' ', $text ) ); + return '#' . Sanitizer::escapeId( $text, 'noninitial' ); } /** Modified: trunk/phase3/maintenance/parserTests.txt =================================================================== --- trunk/phase3/maintenance/parserTests.txt 2010-06-20 22:24:47 UTC (rev 68341) +++ trunk/phase3/maintenance/parserTests.txt 2010-06-20 23:43:39 UTC (rev 68342) @@ -6920,8 +6920,46 @@ </p> !! end +!! test +anchorencode trims spaces +!! input +{{anchorencode: __pretty__please__}} +!! result +<p>pretty_please +</p> +!! end !! test +anchorencode deals with links +!! input +{{anchorencode: [[hello|world]] [[hi]]}} +!! result +<p>world_hi +</p> +!! end + +!! test +anchorencode deals with templates +!! input +{{anchorencode: {{Foo}} }} +!! result +<p>FOO +</p> +!! end + +!! test +anchorencode encodes like the TOC generator: (bug 18431) +!! input +=== _ +:.3A%3A&&]] === +{{anchorencode: _ +:.3A%3A&&]] }} +__NOEDITSECTION__ +!! result +<h3> <span class="mw-headline" id=".2B:.3A.253A.26.26.5D.5D"> _ +:.3A%3A&&]] </span></h3> +<p>.2B:.3A.253A.26.26.5D.5D +</p> +!! end + +!! test Bug 8293: Use of center tag ruins paragraph formatting !! input <center> _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs