Re-normalize titles after html entity decoding when necessary (bug 14952)
authorConrad Irwin <conrad@users.mediawiki.org>
Sun, 28 Mar 2010 03:10:10 +0000 (03:10 +0000)
committerConrad Irwin <conrad@users.mediawiki.org>
Sun, 28 Mar 2010 03:10:10 +0000 (03:10 +0000)
RELEASE-NOTES
includes/Sanitizer.php
includes/Title.php
maintenance/parserTests.txt

index 04c9f5c..c64ab37 100644 (file)
@@ -62,6 +62,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   themselves unless they are given the 'unblockself' permission.
 * (bug 22876) Avoid possible PHP Notice if $wgDefaultUserOptions is not
   correctly set
+* (bug 14952) Page titles are renormalized after html entities are removed so that
+  links with non-NFC character references work correctly.
 
 == API changes in 1.17 ==
 * (bug 22738) Allow filtering by action type on query=logevent
index 45b2cf6..01cd5b9 100644 (file)
@@ -1176,6 +1176,30 @@ class Sanitizer {
                        $text );
        }
 
+       /**
+        * Decode any character references, numeric or named entities,
+        * in the next and normalize the resulting string. (bug 14952)
+        *
+        * This is useful for page titles, not for text to be displayed,
+        * MediaWiki allows HTML entities to escape normalization as a feature.
+        *
+        * @param $text String (already normalized, containing entities)
+        * @return String (still normalized, without entities)
+        */
+       public static function decodeCharReferencesAndNormalize( $text ) {
+               global $wgContLang;
+               $text = preg_replace_callback(
+                       MW_CHAR_REFS_REGEX,
+                       array( 'Sanitizer', 'decodeCharReferencesCallback' ),
+                       $text, /* limit */ -1, $count );
+
+               if ( $count ) {
+                       return $wgContLang->normalize( $text );
+               } else {
+                       return $text;
+               }
+       }
+
        /**
         * @param $matches String
         * @return String
index ea5373c..d3bd6ec 100644 (file)
@@ -127,9 +127,9 @@ class Title {
                }
 
                /**
-                * Convert things like &eacute; &#257; or &#x3017; into real text...
+                * Convert things like &eacute; &#257; or &#x3017; into normalized(bug 14952) text
                 */
-               $filteredText = Sanitizer::decodeCharReferences( $text );
+               $filteredText = Sanitizer::decodeCharReferencesAndNormalize( $text );
 
                $t = new Title();
                $t->mDbkeyform = str_replace( ' ', '_', $filteredText );
index aed2f05..e34d126 100644 (file)
@@ -4114,6 +4114,31 @@ Character reference normalization in link text (bug 1938)
 </p>
 !!end
 
+!! article
+אַ
+!! text
+Test for unicode normalization
+
+The page's name is U+05d0 U+05b7, with non-canonical form U+FB2E
+!! endarticle
+
+!! test
+(bug 19451) Links should refer to the normalized form.
+!! input
+[[&#xFB2E;]]
+[[&#x5d0;&#x5b7;]]
+[[&#x5d0;ַ]]
+[[א&#x5b7;]]
+[[אַ]]
+!! result
+<p><a href="/wiki/%D7%90%D6%B7" title="אַ">&#xfb2e;</a>
+<a href="/wiki/%D7%90%D6%B7" title="אַ">&#x5d0;&#x5b7;</a>
+<a href="/wiki/%D7%90%D6%B7" title="אַ">&#x5d0;ַ</a>
+<a href="/wiki/%D7%90%D6%B7" title="אַ">א&#x5b7;</a>
+<a href="/wiki/%D7%90%D6%B7" title="אַ">אַ</a>
+</p>
+!! end
+
 !! test
 Empty attribute crash test (bug 2067)
 !! input