Reverting r45341 " Use Sanitizer::escapeId() in another place Reduce code duplication...
authorBrion Vibber <brion@users.mediawiki.org>
Wed, 7 Jan 2009 00:00:45 +0000 (00:00 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Wed, 7 Jan 2009 00:00:45 +0000 (00:00 +0000)
when $wgEnforceHtmlIds is off."

This produces non-matching stuff like "#_Rock_on_dudes_" for == ''Rock on'' dudes ==.

includes/parser/Parser.php

index e3ee5e7..7fcfb90 100644 (file)
@@ -4736,11 +4736,21 @@ class Parser
         * "== Header ==".
         */
        public function guessSectionNameFromWikiText( $text ) {
-               global $wgEnforceHtmlIds;
                # Strip out wikitext links(they break the anchor)
                $text = $this->stripSectionName( $text );
-               return '#' . Sanitizer::escapeId( $text,
-                       $wgEnforceHtmlIds ? 'noninitial' : 'xml' );
+               $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 );
        }
 
        /**