Improve $wgExperimentalHtmlIds support
authorAryeh Gregor <simetrical@users.mediawiki.org>
Thu, 5 Aug 2010 20:16:43 +0000 (20:16 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Thu, 5 Aug 2010 20:16:43 +0000 (20:16 +0000)
Now works (again?) in IE6.  That didn't like getting non-legacy ID's on
redirects -- it doesn't interpret them as UTF-8, so anything non-ASCII
breaks.  If this works in all the browsers I test in, I'll enable it --
it will produce *much* nicer-looking anchors for non-English wikis, and
also section names with English punctuation.

includes/EditPage.php
includes/parser/Parser.php

index c9b18eb..77627cb 100644 (file)
@@ -1025,7 +1025,7 @@ class EditPage {
                                return self::AS_TEXTBOX_EMPTY;
                        }
                        if ( $this->summary != '' ) {
-                               $sectionanchor = $wgParser->guessSectionNameFromWikiText( $this->summary );
+                               $sectionanchor = $wgParser->guessLegacySectionNameFromWikiText( $this->summary );
                                # This is a new section, so create a link to the new section
                                # in the revision summary.
                                $cleanSummary = $wgParser->stripSectionName( $this->summary );
@@ -1039,7 +1039,7 @@ class EditPage {
                        # we can't deal with anchors, includes, html etc in the header for now,
                        # headline would need to be parsed to improve this
                        if ( $hasmatch and strlen( $matches[2] ) > 0 ) {
-                               $sectionanchor = $wgParser->guessSectionNameFromWikiText( $matches[2] );
+                               $sectionanchor = $wgParser->guessLegacySectionNameFromWikiText( $matches[2] );
                        }
                }
                wfProfileOut( __METHOD__ . '-sectionanchor' );
index 610ebec..51ef092 100644 (file)
@@ -5080,6 +5080,21 @@ class Parser {
                return '#' . Sanitizer::escapeId( $text, 'noninitial' );
        }
 
+       /**
+        * Same as guessSectionNameFromWikiText(), but produces legacy anchors
+        * instead.  For use in redirects, since IE6 interprets Redirect: headers
+        * as something other than UTF-8 (apparently?), resulting in breakage.
+        *
+        * @param $text String: The section name
+        * @return string An anchor
+        */
+       public function guessLegacySectionNameFromWikiText( $text ) {
+               # Strip out wikitext links(they break the anchor)
+               $text = $this->stripSectionName( $text );
+               $text = Sanitizer::normalizeSectionNameWhitespace( $text );
+               return '#' . Sanitizer::escapeId( $text, array( 'noninitial', 'legacy' ) );
+       }
+
        /**
         * Strips a text string of wikitext for use in a section anchor
         *