(bug 22784) Fix normalization of whitespace in autocomment links
authorConrad Irwin <conrad@users.mediawiki.org>
Mon, 21 Jun 2010 01:17:36 +0000 (01:17 +0000)
committerConrad Irwin <conrad@users.mediawiki.org>
Mon, 21 Jun 2010 01:17:36 +0000 (01:17 +0000)
put this specific normalisation into Sanitizer::normalizeSectionNameWhitespace
instead of repeating it three times.

RELEASE-NOTES
includes/Linker.php
includes/Sanitizer.php
includes/parser/Parser.php
maintenance/parserTests.txt

index 1310543..b8de16d 100644 (file)
@@ -208,6 +208,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   Special:Upload after following a red link
 * Correct the escaping of the autosummary URI fragments.
 * (bug 23642) Recognize mime types of MS OpenXML documents.
+* (bug 22784) Normalise underscores and spaces in autocomments.
 
 === API changes in 1.17 ===
 * (bug 22738) Allow filtering by action type on query=logevent.
index f6e45d1..c7f7df9 100644 (file)
@@ -1018,17 +1018,13 @@ class Linker {
                if ( $title ) {
                        $section = $auto;
 
-                       # Generate a valid anchor name from the section title.
-                       # Hackish, but should generally work - we strip wiki
-                       # syntax, including the magic [[: that is used to
-                       # "link rather than show" in case of images and
-                       # interlanguage links.
+                       # Remove links that a user may have manually put in the autosummary
+                       # This could be improved by copying as much of Parser::stripSectionName as desired.
                        $section = str_replace( '[[:', '', $section );
                        $section = str_replace( '[[', '', $section );
                        $section = str_replace( ']]', '', $section );
 
-                       # Most of Title:: expects fragments to be escaped
-                       $section = Title::escapeFragmentForURL( $section );
+                       $section = Sanitizer::normalizeSectionNameWhitespace( $section ); # bug 22784
                        if ( $local ) {
                                $sectionTitle = Title::newFromText( '#' . $section );
                        } else {
index 00837fd..2a3f847 100644 (file)
@@ -1166,6 +1166,18 @@ class Sanitizer {
                        $text );
        }
 
+       /**
+        * Normalizes whitespace in a section name, such as might be returned
+        * by Parser::stripSectionName(), for use in the id's that are used for
+        * section links.
+        *
+        * @param $section String
+        * @return String
+        */
+       static function normalizeSectionNameWhitespace( $section ) {
+               return trim( preg_replace( '/[ _]+/', ' ', $section ) );
+       }
+
        /**
         * Ensure that any entities and character references are legal
         * for XML and XHTML specifically. Any stray bits will be
index 7b28c14..2a68198 100644 (file)
@@ -3859,8 +3859,7 @@ class Parser {
 
                        # For the anchor, strip out HTML-y stuff period
                        $safeHeadline = preg_replace( '/<.*?'.'>/', '', $safeHeadline );
-                       $safeHeadline = preg_replace( '/[ _]+/', ' ', $safeHeadline );
-                       $safeHeadline = trim( $safeHeadline );
+                       $safeHeadline = Sanitizer::normalizeSectionNameWhitespace( $safeHeadline );
 
                        # Save headline for section edit hint before it's escaped
                        $headlineHint = $safeHeadline;
@@ -5172,7 +5171,7 @@ class Parser {
        public function guessSectionNameFromWikiText( $text ) {
                # Strip out wikitext links(they break the anchor)
                $text = $this->stripSectionName( $text );
-               $text = trim( preg_replace( '/[ _]+/', ' ', $text ) );
+               $text = Sanitizer::normalizeSectionNameWhitespace( $text );
                return '#' . Sanitizer::escapeId( $text, 'noninitial' );
        }
 
index e3612b1..89a9587 100644 (file)
@@ -7816,6 +7816,17 @@ title=[[Main Page]]
 <a href="/wiki/Main_Page#section" title="Main Page">#section</a>
 !! end
 
+!! test
+Space normalisation on autocomment (bug 22784)
+!! options
+comment
+title=[[Main Page]]
+!!input
+/* __hello__world__ */
+!! result
+<span class="autocomment"><a href="/wiki/Main_Page#hello_world" title="Main Page">→</a>__hello__world__</span>
+!! end
+
 !!article
 MediaWiki:bad image list
 !!text