Index: trunk/phase3/maintenance/parserTests.txt |
— | — | @@ -6920,8 +6920,46 @@ |
6921 | 6921 | </p> |
6922 | 6922 | !! end |
6923 | 6923 | |
| 6924 | +!! test |
| 6925 | +anchorencode trims spaces |
| 6926 | +!! input |
| 6927 | +{{anchorencode: __pretty__please__}} |
| 6928 | +!! result |
| 6929 | +<p>pretty_please |
| 6930 | +</p> |
| 6931 | +!! end |
6924 | 6932 | |
6925 | 6933 | !! 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&&]] === |
| 6955 | +{{anchorencode: _ +:.3A%3A&&]] }} |
| 6956 | +__NOEDITSECTION__ |
| 6957 | +!! result |
| 6958 | +<h3> <span class="mw-headline" id=".2B:.3A.253A.26.26.5D.5D"> _ +:.3A%3A&&]] </span></h3> |
| 6959 | +<p>.2B:.3A.253A.26.26.5D.5D |
| 6960 | +</p> |
| 6961 | +!! end |
| 6962 | + |
| 6963 | +!! test |
6926 | 6964 | Bug 8293: Use of center tag ruins paragraph formatting |
6927 | 6965 | !! input |
6928 | 6966 | <center> |
Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -5172,19 +5172,8 @@ |
5173 | 5173 | public function guessSectionNameFromWikiText( $text ) { |
5174 | 5174 | # Strip out wikitext links(they break the anchor) |
5175 | 5175 | $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' ); |
5189 | 5178 | } |
5190 | 5179 | |
5191 | 5180 | /** |
Index: trunk/phase3/includes/parser/CoreParserFunctions.php |
— | — | @@ -582,11 +582,7 @@ |
583 | 583 | } |
584 | 584 | |
585 | 585 | 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); |
591 | 587 | } |
592 | 588 | |
593 | 589 | static function special( $parser, $text ) { |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -86,6 +86,7 @@ |
87 | 87 | * (bug 23621) New Special:ComparePages to compare (diff) two articles. |
88 | 88 | * (bug 4597) Provide support in Special:Contributions to show only "current" |
89 | 89 | contributions |
| 90 | +* (bug 17857) {{anchorencode}} acts more like how the parser creates section ids. |
90 | 91 | |
91 | 92 | === Bug fixes in 1.17 === |
92 | 93 | * (bug 17560) Half-broken deletion moved image files to deletion archive |