Index: trunk/extensions/DataTransfer/specials/DT_ImportCSV.php |
— | — | @@ -73,19 +73,25 @@ |
74 | 74 | if ($wgRequest->getCheck('import_file')) { |
75 | 75 | $text = "<p>" . wfMsg('dt_import_importing') . "</p>\n"; |
76 | 76 | $source = ImportStreamSource::newFromUpload( "csv_file" ); |
| 77 | + $encoding = $wgRequest->getVal('encoding'); |
77 | 78 | $pages = array(); |
78 | | - $error_msg = self::getCSVData($source->mHandle, $pages); |
| 79 | + $error_msg = self::getCSVData($source->mHandle, $encoding, $pages); |
79 | 80 | if (! is_null($error_msg)) |
80 | 81 | $text .= $error_msg; |
81 | 82 | else |
82 | 83 | $text .= self::modifyPages($pages); |
83 | 84 | } else { |
84 | 85 | $select_file_label = wfMsg('dt_import_selectfile', 'CSV'); |
| 86 | + $encoding_type_label = wfMsg('dt_import_encodingtype'); |
85 | 87 | $import_button = wfMsg('import-interwiki-submit'); |
86 | 88 | $text =<<<END |
87 | 89 | <p>$select_file_label</p> |
88 | 90 | <form enctype="multipart/form-data" action="" method="post"> |
89 | 91 | <p><input type="file" name="csv_file" size="25" /></p> |
| 92 | + <p>$encoding_type_label: <select name="encoding"> |
| 93 | + <option selected value="utf8">UTF-8</option> |
| 94 | + <option value="utf16">UTF-16</option> |
| 95 | + </select> |
90 | 96 | <p><input type="Submit" name="import_file" value="$import_button"></p> |
91 | 97 | </form> |
92 | 98 | |
— | — | @@ -96,14 +102,18 @@ |
97 | 103 | } |
98 | 104 | |
99 | 105 | |
100 | | - static function getCSVData($csv_file, &$pages) { |
| 106 | + static function getCSVData($csv_file, $encoding, &$pages) { |
| 107 | + if (is_null($csv_file)) |
| 108 | + return wfMsg('emptyfile'); |
101 | 109 | $table = array(); |
102 | 110 | while ($line = fgetcsv($csv_file)) { |
103 | | - // fix values in case the file wasn't UTF-8 encoded - |
| 111 | + // fix values if the file wasn't UTF-8 encoded - |
104 | 112 | // hopefully the UTF-8 value will work across all |
105 | 113 | // database encodings |
106 | | - $encoded_line = array_map('utf8_encode', $line); |
107 | | - array_push($table, $encoded_line); |
| 114 | + if ($encoding == 'utf16') { |
| 115 | + $line = array_map('utf8_encode', $line); |
| 116 | + } |
| 117 | + array_push($table, $line); |
108 | 118 | } |
109 | 119 | fclose($csv_file); |
110 | 120 | // check header line to make sure every term is in the |