Index: trunk/phase3/maintenance/parserTests.txt |
— | — | @@ -7816,6 +7816,17 @@ |
7817 | 7817 | <a href="https://www.mediawiki.org/wiki/Main_Page#section" title="Main Page">#section</a> |
7818 | 7818 | !! end |
7819 | 7819 | |
| 7820 | +!! test |
| 7821 | +Space normalisation on autocomment (bug 22784) |
| 7822 | +!! options |
| 7823 | +comment |
| 7824 | +title=[[Main Page]] |
| 7825 | +!!input |
| 7826 | +/* __hello__world__ */ |
| 7827 | +!! result |
| 7828 | +<span class="autocomment"><a href="https://www.mediawiki.org/wiki/Main_Page#hello_world" title="Main Page">→</a>__hello__world__</span> |
| 7829 | +!! end |
| 7830 | + |
7820 | 7831 | !!article |
7821 | 7832 | MediaWiki:bad image list |
7822 | 7833 | !!text |
Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -3859,8 +3859,7 @@ |
3860 | 3860 | |
3861 | 3861 | # For the anchor, strip out HTML-y stuff period |
3862 | 3862 | $safeHeadline = preg_replace( '/<.*?'.'>/', '', $safeHeadline ); |
3863 | | - $safeHeadline = preg_replace( '/[ _]+/', ' ', $safeHeadline ); |
3864 | | - $safeHeadline = trim( $safeHeadline ); |
| 3863 | + $safeHeadline = Sanitizer::normalizeSectionNameWhitespace( $safeHeadline ); |
3865 | 3864 | |
3866 | 3865 | # Save headline for section edit hint before it's escaped |
3867 | 3866 | $headlineHint = $safeHeadline; |
— | — | @@ -5172,7 +5171,7 @@ |
5173 | 5172 | public function guessSectionNameFromWikiText( $text ) { |
5174 | 5173 | # Strip out wikitext links(they break the anchor) |
5175 | 5174 | $text = $this->stripSectionName( $text ); |
5176 | | - $text = trim( preg_replace( '/[ _]+/', ' ', $text ) ); |
| 5175 | + $text = Sanitizer::normalizeSectionNameWhitespace( $text ); |
5177 | 5176 | return '#' . Sanitizer::escapeId( $text, 'noninitial' ); |
5178 | 5177 | } |
5179 | 5178 | |
Index: trunk/phase3/includes/Linker.php |
— | — | @@ -1018,17 +1018,13 @@ |
1019 | 1019 | if ( $title ) { |
1020 | 1020 | $section = $auto; |
1021 | 1021 | |
1022 | | - # Generate a valid anchor name from the section title. |
1023 | | - # Hackish, but should generally work - we strip wiki |
1024 | | - # syntax, including the magic [[: that is used to |
1025 | | - # "link rather than show" in case of images and |
1026 | | - # interlanguage links. |
| 1022 | + # Remove links that a user may have manually put in the autosummary |
| 1023 | + # This could be improved by copying as much of Parser::stripSectionName as desired. |
1027 | 1024 | $section = str_replace( '[[:', '', $section ); |
1028 | 1025 | $section = str_replace( '[[', '', $section ); |
1029 | 1026 | $section = str_replace( ']]', '', $section ); |
1030 | 1027 | |
1031 | | - # Most of Title:: expects fragments to be escaped |
1032 | | - $section = Title::escapeFragmentForURL( $section ); |
| 1028 | + $section = Sanitizer::normalizeSectionNameWhitespace( $section ); # bug 22784 |
1033 | 1029 | if ( $local ) { |
1034 | 1030 | $sectionTitle = Title::newFromText( '#' . $section ); |
1035 | 1031 | } else { |
Index: trunk/phase3/includes/Sanitizer.php |
— | — | @@ -1167,6 +1167,18 @@ |
1168 | 1168 | } |
1169 | 1169 | |
1170 | 1170 | /** |
| 1171 | + * Normalizes whitespace in a section name, such as might be returned |
| 1172 | + * by Parser::stripSectionName(), for use in the id's that are used for |
| 1173 | + * section links. |
| 1174 | + * |
| 1175 | + * @param $section String |
| 1176 | + * @return String |
| 1177 | + */ |
| 1178 | + static function normalizeSectionNameWhitespace( $section ) { |
| 1179 | + return trim( preg_replace( '/[ _]+/', ' ', $section ) ); |
| 1180 | + } |
| 1181 | + |
| 1182 | + /** |
1171 | 1183 | * Ensure that any entities and character references are legal |
1172 | 1184 | * for XML and XHTML specifically. Any stray bits will be |
1173 | 1185 | * &-escaped to result in a valid text fragment. |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -208,6 +208,7 @@ |
209 | 209 | Special:Upload after following a red link |
210 | 210 | * Correct the escaping of the autosummary URI fragments. |
211 | 211 | * (bug 23642) Recognize mime types of MS OpenXML documents. |
| 212 | +* (bug 22784) Normalise underscores and spaces in autocomments. |
212 | 213 | |
213 | 214 | === API changes in 1.17 === |
214 | 215 | * (bug 22738) Allow filtering by action type on query=logevent. |