Hopefully slightly saner handling of character entities in links; now will
authorBrion Vibber <brion@users.mediawiki.org>
Thu, 18 Dec 2003 11:31:03 +0000 (11:31 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Thu, 18 Dec 2003 11:31:03 +0000 (11:31 +0000)
use UTF-8 characters on a UTF-8 wiki for the Latin-1 named entities; this
prevents corrupt in-wiki links for cases such as [[Wei&szlig; kreuz]] or
[[Br&ucirc;ker:Foo]]. There is a small chance this will harm interwiki
links to latin-1 wikis that don't accept UTF-8 incoming URLs, but on
balance this is a lesser harm. Raw bytes in such links can still be used
(%XX) if need be.

This shouldn't change behavior on Latin-1 wikis.

includes/Title.php

index d0300ed..2b3da1f 100644 (file)
@@ -1,7 +1,6 @@
 <?
 # See title.doc
 
-/* private static */ $title_html_translation_table = array_flip( get_html_translation_table( HTML_ENTITIES ) );
 /* private static */ $title_interwiki_cache = array();
 
 class Title {
@@ -34,13 +33,19 @@ class Title {
        
        function newFromText( $text )
        {       
-               global $title_html_translation_table;
+               static $trans;
                $fname = "Title::newFromText";
                wfProfileIn( $fname );
                
                # Note - mixing latin1 named entities and unicode numbered
                # ones will result in a bad link.
-               $trans =& $title_html_translation_table;
+               if( !isset( $trans ) ) {
+                       global $wgInputEncoding;
+                       $trans = array_flip( get_html_translation_table( HTML_ENTITIES ) );
+                       if( strcasecmp( "utf-8", $wgInputEncoding ) == 0 ) {
+                           $trans = array_map( "utf8_encode", $trans );
+                       }
+               }
 
                $text = strtr( $text, $trans );