|
[MediaWiki-CVS] SVN: [54102] trunk/extensions/DataTransfer/specials/DT_Impo: msg#01480mediawiki-cvs
http://www.mediawiki.org/wiki/Special:Code/MediaWiki/54102 Revision: 54102 Author: yaron Date: 2009-07-31 15:16:04 +0000 (Fri, 31 Jul 2009) Log Message: ----------- Patrick Nagel's fix for UTF-16 handling Modified Paths: -------------- trunk/extensions/DataTransfer/specials/DT_ImportCSV.php Modified: trunk/extensions/DataTransfer/specials/DT_ImportCSV.php =================================================================== --- trunk/extensions/DataTransfer/specials/DT_ImportCSV.php 2009-07-31 15:00:29 UTC (rev 54101) +++ trunk/extensions/DataTransfer/specials/DT_ImportCSV.php 2009-07-31 15:16:04 UTC (rev 54102) @@ -110,14 +110,25 @@ if (is_null($csv_file)) return wfMsg('emptyfile'); $table = array(); - while ($line = fgetcsv($csv_file)) { - // fix values if the file wasn't UTF-8 encoded - - // hopefully the UTF-8 value will work across all - // database encodings - if ($encoding == 'utf16') { - $line = array_map('utf8_encode', $line); + if ($encoding == 'utf16') { + // change encoding to UTF-8 + // Starting with PHP 5.3 we could use str_getcsv(), + // which would save the tempfile hassle + $tempfile = tmpfile(); + $csv_string = ''; + while (!feof($csv_file)) { + $csv_string .= fgets($csv_file, 65535); + } + fwrite($tempfile, iconv('UTF-16', 'UTF-8', $csv_string)); + fseek($tempfile, 0); + while ($line = fgetcsv($tempfile)) { + array_push($table, $line); } - array_push($table, $line); + fclose($tempfile); + } else { + while ($line = fgetcsv($csv_file)) { + array_push($table, $line); + } } fclose($csv_file); // check header line to make sure every term is in the _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@xxxxxxxxxxxxxxxxxxx https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs
|
|
||||||||||||||||||||||||||
|
|
|
| News | Mail Home | sitemap | FAQ | advertise |