r30600 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r30599‎ | r30600 | r30601 >
Date:23:13, 5 February 2008
Author:brion
Status:old
Tags:
Comment:
While we're in there, let's remove a dependency on iconv(). Do the UTF-16 to ASCII merging in the XML checks manually.
Modified paths:
  • /trunk/phase3/includes/MimeMagic.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/MimeMagic.php
@@ -479,9 +479,17 @@
480480 */
481481 }
482482
483 - if ( $xml_type ) {
484 - if ( $xml_type !== "UTF-8" && $xml_type !== "ASCII" ) {
485 - $head = iconv( $xml_type, "ASCII//IGNORE", $head );
 483+ if( $xml_type == 'UTF-16BE' || $xml_type == 'UTF-16LE' ) {
 484+ // Quick and dirty fold down to ASCII!
 485+ $pack = array( 'UTF-16BE' => 'n*', 'UTF-16LE' => 'v*' );
 486+ $chars = unpack( $pack[$xml_type], substr( $head, 2 ) );
 487+ $head = '';
 488+ foreach( $chars as $codepoint ) {
 489+ if( $codepoint < 128 ) {
 490+ $head .= chr( $codepoint );
 491+ } else {
 492+ $head .= '?';
 493+ }
486494 }
487495 }
488496

Status & tagging log