r68343 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68342‎ | r68343 | r68344 >
Date:01:17, 21 June 2010
Author:conrad
Status:ok (Comments)
Tags:
Comment:
(bug 22784) Fix normalization of whitespace in autocomment links

put this specific normalisation into Sanitizer::normalizeSectionNameWhitespace
instead of repeating it three times.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Linker.php (modified) (history)
  • /trunk/phase3/includes/Sanitizer.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
@@ -7816,6 +7816,17 @@
78177817 <a href="https://www.mediawiki.org/wiki/Main_Page#section" title="Main Page">#section</a>
78187818 !! end
78197819
 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+
78207831 !!article
78217832 MediaWiki:bad image list
78227833 !!text
Index: trunk/phase3/includes/parser/Parser.php
@@ -3859,8 +3859,7 @@
38603860
38613861 # For the anchor, strip out HTML-y stuff period
38623862 $safeHeadline = preg_replace( '/<.*?'.'>/', '', $safeHeadline );
3863 - $safeHeadline = preg_replace( '/[ _]+/', ' ', $safeHeadline );
3864 - $safeHeadline = trim( $safeHeadline );
 3863+ $safeHeadline = Sanitizer::normalizeSectionNameWhitespace( $safeHeadline );
38653864
38663865 # Save headline for section edit hint before it's escaped
38673866 $headlineHint = $safeHeadline;
@@ -5172,7 +5171,7 @@
51735172 public function guessSectionNameFromWikiText( $text ) {
51745173 # Strip out wikitext links(they break the anchor)
51755174 $text = $this->stripSectionName( $text );
5176 - $text = trim( preg_replace( '/[ _]+/', ' ', $text ) );
 5175+ $text = Sanitizer::normalizeSectionNameWhitespace( $text );
51775176 return '#' . Sanitizer::escapeId( $text, 'noninitial' );
51785177 }
51795178
Index: trunk/phase3/includes/Linker.php
@@ -1018,17 +1018,13 @@
10191019 if ( $title ) {
10201020 $section = $auto;
10211021
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.
10271024 $section = str_replace( '[[:', '', $section );
10281025 $section = str_replace( '[[', '', $section );
10291026 $section = str_replace( ']]', '', $section );
10301027
1031 - # Most of Title:: expects fragments to be escaped
1032 - $section = Title::escapeFragmentForURL( $section );
 1028+ $section = Sanitizer::normalizeSectionNameWhitespace( $section ); # bug 22784
10331029 if ( $local ) {
10341030 $sectionTitle = Title::newFromText( '#' . $section );
10351031 } else {
Index: trunk/phase3/includes/Sanitizer.php
@@ -1167,6 +1167,18 @@
11681168 }
11691169
11701170 /**
 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+ /**
11711183 * Ensure that any entities and character references are legal
11721184 * for XML and XHTML specifically. Any stray bits will be
11731185 * &amp;-escaped to result in a valid text fragment.
Index: trunk/phase3/RELEASE-NOTES
@@ -208,6 +208,7 @@
209209 Special:Upload after following a red link
210210 * Correct the escaping of the autosummary URI fragments.
211211 * (bug 23642) Recognize mime types of MS OpenXML documents.
 212+* (bug 22784) Normalise underscores and spaces in autocomments.
212213
213214 === API changes in 1.17 ===
214215 * (bug 22738) Allow filtering by action type on query=logevent.

Follow-up revisions

RevisionCommit summaryAuthorDate
r74824Revert RELEASE-NOTES change from r68272, which was reverted in r68343.platonides23:02, 15 October 2010

Comments

#Comment by Platonides (talk | contribs)   22:37, 15 October 2010

Shouldn't Title::escapeFragmentForURL be kept?

#Comment by Conrad.Irwin (talk | contribs)   22:54, 15 October 2010

No, it was erroneously added just before: http://www.mediawiki.org/wiki/Special:Code/MediaWiki/68272 (see Title#getFragmentForUrl). I should have done two separate commits, would have been clearer.

#Comment by Platonides (talk | contribs)   23:02, 15 October 2010

Oh, fine.

Status & tagging log