From 65e8acdf0a1ad11834ea2a0e8e73125cf67f3059 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Thu, 5 Aug 2010 20:16:43 +0000 Subject: [PATCH] Improve $wgExperimentalHtmlIds support 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 | 4 ++-- includes/parser/Parser.php | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index c9b18ebf25..77627cbc5b 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -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' ); diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 610ebecf54..51ef092aae 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -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 * -- 2.20.1