Index: trunk/phase3/includes/MacBinary.php |
— | — | @@ -1,274 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * MacBinary signature checker and data fork extractor, for files |
5 | | - * uploaded from Internet Explorer for Mac. |
6 | | - * |
7 | | - * Copyright (C) 2005 Brion Vibber <brion@pobox.com> |
8 | | - * Portions based on Convert::BinHex by Eryq et al |
9 | | - * http://www.mediawiki.org/ |
10 | | - * |
11 | | - * This program is free software; you can redistribute it and/or modify |
12 | | - * it under the terms of the GNU General Public License as published by |
13 | | - * the Free Software Foundation; either version 2 of the License, or |
14 | | - * (at your option) any later version. |
15 | | - * |
16 | | - * This program is distributed in the hope that it will be useful, |
17 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 | | - * GNU General Public License for more details. |
20 | | - * |
21 | | - * You should have received a copy of the GNU General Public License along |
22 | | - * with this program; if not, write to the Free Software Foundation, Inc., |
23 | | - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
24 | | - * http://www.gnu.org/copyleft/gpl.html |
25 | | - * |
26 | | - * @file |
27 | | - */ |
28 | | - |
29 | | -class MacBinary { |
30 | | - function __construct( $filename ) { |
31 | | - $this->open( $filename ); |
32 | | - $this->loadHeader(); |
33 | | - } |
34 | | - |
35 | | - private $valid, $version, $filename, $dataLength, $resourceLength, $handle; |
36 | | - |
37 | | - /** |
38 | | - * The file must be seekable, such as local filesystem. |
39 | | - * Remote URLs probably won't work. |
40 | | - * |
41 | | - * @param $filename String |
42 | | - */ |
43 | | - function open( $filename ) { |
44 | | - $this->valid = false; |
45 | | - $this->version = 0; |
46 | | - $this->filename = ''; |
47 | | - $this->dataLength = 0; |
48 | | - $this->resourceLength = 0; |
49 | | - $this->handle = fopen( $filename, 'rb' ); |
50 | | - } |
51 | | - |
52 | | - /** |
53 | | - * Does this appear to be a valid MacBinary archive? |
54 | | - * |
55 | | - * @return Boolean |
56 | | - */ |
57 | | - function isValid() { |
58 | | - return $this->valid; |
59 | | - } |
60 | | - |
61 | | - /** |
62 | | - * Get length of data fork |
63 | | - * |
64 | | - * @return Integer |
65 | | - */ |
66 | | - function dataForkLength() { |
67 | | - return $this->dataLength; |
68 | | - } |
69 | | - |
70 | | - /** |
71 | | - * Copy the data fork to an external file or resource. |
72 | | - * |
73 | | - * @param $destination Ressource |
74 | | - * @return Boolean |
75 | | - */ |
76 | | - function extractData( $destination ) { |
77 | | - if( !$this->isValid() ) { |
78 | | - return false; |
79 | | - } |
80 | | - |
81 | | - // Data fork appears immediately after header |
82 | | - fseek( $this->handle, 128 ); |
83 | | - return $this->copyBytesTo( $destination, $this->dataLength ); |
84 | | - } |
85 | | - |
86 | | - /** |
87 | | - * |
88 | | - */ |
89 | | - function close() { |
90 | | - fclose( $this->handle ); |
91 | | - } |
92 | | - |
93 | | - // -------------------------------------------------------------- |
94 | | - |
95 | | - /** |
96 | | - * Check if the given file appears to be MacBinary-encoded, |
97 | | - * as Internet Explorer on Mac OS may provide for unknown types. |
98 | | - * http://www.lazerware.com/formats/macbinary/macbinary_iii.html |
99 | | - * If ok, load header data. |
100 | | - * |
101 | | - * @return bool |
102 | | - * @access private |
103 | | - */ |
104 | | - function loadHeader() { |
105 | | - $fname = 'MacBinary::loadHeader'; |
106 | | - |
107 | | - fseek( $this->handle, 0 ); |
108 | | - $head = fread( $this->handle, 128 ); |
109 | | - #$this->hexdump( $head ); |
110 | | - |
111 | | - if( strlen( $head ) < 128 ) { |
112 | | - wfDebug( "$fname: couldn't read full MacBinary header\n" ); |
113 | | - return false; |
114 | | - } |
115 | | - |
116 | | - if( $head[0] != "\x00" || $head[74] != "\x00" ) { |
117 | | - wfDebug( "$fname: header bytes 0 and 74 not null\n" ); |
118 | | - return false; |
119 | | - } |
120 | | - |
121 | | - $signature = substr( $head, 102, 4 ); |
122 | | - $a = unpack( "ncrc", substr( $head, 124, 2 ) ); |
123 | | - $storedCRC = $a['crc']; |
124 | | - $calculatedCRC = $this->calcCRC( substr( $head, 0, 124 ) ); |
125 | | - if( $storedCRC == $calculatedCRC ) { |
126 | | - if( $signature == 'mBIN' ) { |
127 | | - $this->version = 3; |
128 | | - } else { |
129 | | - $this->version = 2; |
130 | | - } |
131 | | - } else { |
132 | | - $crc = sprintf( "%x != %x", $storedCRC, $calculatedCRC ); |
133 | | - if( $storedCRC == 0 && $head[82] == "\x00" && |
134 | | - substr( $head, 101, 24 ) == str_repeat( "\x00", 24 ) ) { |
135 | | - wfDebug( "$fname: no CRC, looks like MacBinary I\n" ); |
136 | | - $this->version = 1; |
137 | | - } elseif( $signature == 'mBIN' && $storedCRC == 0x185 ) { |
138 | | - // Mac IE 5.0 seems to insert this value in the CRC field. |
139 | | - // 5.2.3 works correctly; don't know about other versions. |
140 | | - wfDebug( "$fname: CRC doesn't match ($crc), looks like Mac IE 5.0\n" ); |
141 | | - $this->version = 3; |
142 | | - } else { |
143 | | - wfDebug( "$fname: CRC doesn't match ($crc) and not MacBinary I\n" ); |
144 | | - return false; |
145 | | - } |
146 | | - } |
147 | | - |
148 | | - $nameLength = ord( $head[1] ); |
149 | | - if( $nameLength < 1 || $nameLength > 63 ) { |
150 | | - wfDebug( "$fname: invalid filename size $nameLength\n" ); |
151 | | - return false; |
152 | | - } |
153 | | - $this->filename = substr( $head, 2, $nameLength ); |
154 | | - |
155 | | - $forks = unpack( "Ndata/Nresource", substr( $head, 83, 8 ) ); |
156 | | - $this->dataLength = $forks['data']; |
157 | | - $this->resourceLength = $forks['resource']; |
158 | | - $maxForkLength = 0x7fffff; |
159 | | - |
160 | | - if( $this->dataLength < 0 || $this->dataLength > $maxForkLength ) { |
161 | | - wfDebug( "$fname: invalid data fork length $this->dataLength\n" ); |
162 | | - return false; |
163 | | - } |
164 | | - |
165 | | - if( $this->resourceLength < 0 || $this->resourceLength > $maxForkLength ) { |
166 | | - wfDebug( "$fname: invalid resource fork size $this->resourceLength\n" ); |
167 | | - return false; |
168 | | - } |
169 | | - |
170 | | - wfDebug( "$fname: appears to be MacBinary $this->version, data length $this->dataLength\n" ); |
171 | | - $this->valid = true; |
172 | | - return true; |
173 | | - } |
174 | | - |
175 | | - /** |
176 | | - * Calculate a 16-bit CRC value as for MacBinary headers. |
177 | | - * Adapted from perl5 Convert::BinHex by Eryq, |
178 | | - * based on the mcvert utility (Doug Moore, April '87), |
179 | | - * with magic array thingy by Jim Van Verth. |
180 | | - * http://search.cpan.org/~eryq/Convert-BinHex-1.119/lib/Convert/BinHex.pm |
181 | | - * |
182 | | - * @param $data String |
183 | | - * @param $seed Integer |
184 | | - * @return Integer |
185 | | - * @access private |
186 | | - */ |
187 | | - function calcCRC( $data, $seed = 0 ) { |
188 | | - # An array useful for CRC calculations that use 0x1021 as the "seed": |
189 | | - $MAGIC = array( |
190 | | - 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, |
191 | | - 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, |
192 | | - 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, |
193 | | - 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, |
194 | | - 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, |
195 | | - 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, |
196 | | - 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, |
197 | | - 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, |
198 | | - 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, |
199 | | - 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, |
200 | | - 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, |
201 | | - 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, |
202 | | - 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, |
203 | | - 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, |
204 | | - 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, |
205 | | - 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, |
206 | | - 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, |
207 | | - 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, |
208 | | - 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, |
209 | | - 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, |
210 | | - 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, |
211 | | - 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, |
212 | | - 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, |
213 | | - 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, |
214 | | - 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, |
215 | | - 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, |
216 | | - 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, |
217 | | - 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, |
218 | | - 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, |
219 | | - 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, |
220 | | - 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, |
221 | | - 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 |
222 | | - ); |
223 | | - $len = strlen( $data ); |
224 | | - $crc = $seed; |
225 | | - for( $i = 0; $i < $len; $i++ ) { |
226 | | - $crc ^= ord( $data[$i] ) << 8; |
227 | | - $crc &= 0xFFFF; |
228 | | - $crc = ($crc << 8) ^ $MAGIC[$crc >> 8]; |
229 | | - $crc &= 0xFFFF; |
230 | | - } |
231 | | - return $crc; |
232 | | - } |
233 | | - |
234 | | - /** |
235 | | - * @param $destination Resource |
236 | | - * @param $bytesToCopy Integer |
237 | | - * @return Boolean |
238 | | - * @access private |
239 | | - */ |
240 | | - function copyBytesTo( $destination, $bytesToCopy ) { |
241 | | - $bufferSize = 65536; |
242 | | - for( $remaining = $bytesToCopy; $remaining > 0; $remaining -= $bufferSize ) { |
243 | | - $thisChunkSize = min( $remaining, $bufferSize ); |
244 | | - $buffer = fread( $this->handle, $thisChunkSize ); |
245 | | - fwrite( $destination, $buffer ); |
246 | | - } |
247 | | - } |
248 | | - |
249 | | - /** |
250 | | - * Hex dump of the header for debugging |
251 | | - * @access private |
252 | | - */ |
253 | | - function hexdump( $data ) { |
254 | | - global $wgDebugLogFile; |
255 | | - if( !$wgDebugLogFile ) return; |
256 | | - |
257 | | - $width = 16; |
258 | | - $at = 0; |
259 | | - for( $remaining = strlen( $data ); $remaining > 0; $remaining -= $width ) { |
260 | | - $line = sprintf( "%04x:", $at ); |
261 | | - $printable = ''; |
262 | | - for( $i = 0; $i < $width && $remaining - $i > 0; $i++ ) { |
263 | | - $byte = ord( $data[$at++] ); |
264 | | - $line .= sprintf( " %02x", $byte ); |
265 | | - $printable .= ($byte >= 32 && $byte <= 126 ) |
266 | | - ? chr( $byte ) |
267 | | - : '.'; |
268 | | - } |
269 | | - if( $i < $width ) { |
270 | | - $line .= str_repeat( ' ', $width - $i ); |
271 | | - } |
272 | | - wfDebug( "MacBinary: $line $printable\n" ); |
273 | | - } |
274 | | - } |
275 | | -} |
Index: trunk/phase3/includes/upload/UploadBase.php |
— | — | @@ -368,7 +368,6 @@ |
369 | 369 | $this->getTitle(); |
370 | 370 | |
371 | 371 | $this->mFileProps = File::getPropsFromPath( $this->mTempPath, $this->mFinalExtension ); |
372 | | - $this->checkMacBinary(); |
373 | 372 | |
374 | 373 | # check mime type, if desired |
375 | 374 | $mime = $this->mFileProps[ 'file-mime' ]; |
— | — | @@ -1113,30 +1112,6 @@ |
1114 | 1113 | } |
1115 | 1114 | |
1116 | 1115 | /** |
1117 | | - * Check if the temporary file is MacBinary-encoded, as some uploads |
1118 | | - * from Internet Explorer on Mac OS Classic and Mac OS X will be. |
1119 | | - * If so, the data fork will be extracted to a second temporary file, |
1120 | | - * which will then be checked for validity and either kept or discarded. |
1121 | | - */ |
1122 | | - private function checkMacBinary() { |
1123 | | - $macbin = new MacBinary( $this->mTempPath ); |
1124 | | - if( $macbin->isValid() ) { |
1125 | | - $dataFile = tempnam( wfTempDir(), 'WikiMacBinary' ); |
1126 | | - $dataHandle = fopen( $dataFile, 'wb' ); |
1127 | | - |
1128 | | - wfDebug( __METHOD__ . ": Extracting MacBinary data fork to $dataFile\n" ); |
1129 | | - $macbin->extractData( $dataHandle ); |
1130 | | - |
1131 | | - $this->mTempPath = $dataFile; |
1132 | | - $this->mFileSize = $macbin->dataForkLength(); |
1133 | | - |
1134 | | - // We'll have to manually remove the new file if it's not kept. |
1135 | | - $this->mRemoveTempFile = true; |
1136 | | - } |
1137 | | - $macbin->close(); |
1138 | | - } |
1139 | | - |
1140 | | - /** |
1141 | 1116 | * Check if there's an overwrite conflict and, if so, if restrictions |
1142 | 1117 | * forbid this user from performing the upload. |
1143 | 1118 | * |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -141,7 +141,6 @@ |
142 | 142 | 'LogEventsList' => 'includes/LogEventsList.php', |
143 | 143 | 'LogPage' => 'includes/LogPage.php', |
144 | 144 | 'LogPager' => 'includes/LogEventsList.php', |
145 | | - 'MacBinary' => 'includes/MacBinary.php', |
146 | 145 | 'MagicWord' => 'includes/MagicWord.php', |
147 | 146 | 'MagicWordArray' => 'includes/MagicWord.php', |
148 | 147 | 'MailAddress' => 'includes/UserMailer.php', |
Index: trunk/extensions/SemanticForms/specials/SF_UploadWindow.php |
— | — | @@ -465,7 +465,6 @@ |
466 | 466 | */ |
467 | 467 | if ( !$this->mStashed ) { |
468 | 468 | $this->mFileProps = File::getPropsFromPath( $this->mTempPath, $finalExt ); |
469 | | - $this->checkMacBinary(); |
470 | 469 | $veri = $this->verify( $this->mTempPath, $finalExt ); |
471 | 470 | |
472 | 471 | if ( $veri !== true ) { // it's a wiki error... |
— | — | @@ -1446,32 +1445,6 @@ |
1447 | 1446 | } |
1448 | 1447 | |
1449 | 1448 | /** |
1450 | | - * Check if the temporary file is MacBinary-encoded, as some uploads |
1451 | | - * from Internet Explorer on Mac OS Classic and Mac OS X will be. |
1452 | | - * If so, the data fork will be extracted to a second temporary file, |
1453 | | - * which will then be checked for validity and either kept or discarded. |
1454 | | - * |
1455 | | - * @access private |
1456 | | - */ |
1457 | | - function checkMacBinary() { |
1458 | | - $macbin = new MacBinary( $this->mTempPath ); |
1459 | | - if ( $macbin->isValid() ) { |
1460 | | - $dataFile = tempnam( wfTempDir(), "WikiMacBinary" ); |
1461 | | - $dataHandle = fopen( $dataFile, 'wb' ); |
1462 | | - |
1463 | | - wfDebug( "SpecialUpload::checkMacBinary: Extracting MacBinary data fork to $dataFile\n" ); |
1464 | | - $macbin->extractData( $dataHandle ); |
1465 | | - |
1466 | | - $this->mTempPath = $dataFile; |
1467 | | - $this->mFileSize = $macbin->dataForkLength(); |
1468 | | - |
1469 | | - // We'll have to manually remove the new file if it's not kept. |
1470 | | - $this->mRemoveTempFile = true; |
1471 | | - } |
1472 | | - $macbin->close(); |
1473 | | - } |
1474 | | - |
1475 | | - /** |
1476 | 1449 | * If we've modified the upload file we need to manually remove it |
1477 | 1450 | * on exit to clean up. |
1478 | 1451 | * @access private |
Index: trunk/extensions/DSMW/api/upload/UploadBase.php |
— | — | @@ -230,7 +230,6 @@ |
231 | 231 | */ |
232 | 232 | protected function verifyFile() { |
233 | 233 | $this->mFileProps = File::getPropsFromPath( $this->mTempPath, $this->mFinalExtension ); |
234 | | - $this->checkMacBinary(); |
235 | 234 | |
236 | 235 | # magically determine mime type |
237 | 236 | $magic = MimeMagic::singleton(); |
— | — | @@ -880,30 +879,6 @@ |
881 | 880 | } |
882 | 881 | |
883 | 882 | /** |
884 | | - * Check if the temporary file is MacBinary-encoded, as some uploads |
885 | | - * from Internet Explorer on Mac OS Classic and Mac OS X will be. |
886 | | - * If so, the data fork will be extracted to a second temporary file, |
887 | | - * which will then be checked for validity and either kept or discarded. |
888 | | - */ |
889 | | - private function checkMacBinary() { |
890 | | - $macbin = new MacBinary( $this->mTempPath ); |
891 | | - if ( $macbin->isValid() ) { |
892 | | - $dataFile = tempnam( wfTempDir(), 'WikiMacBinary' ); |
893 | | - $dataHandle = fopen( $dataFile, 'wb' ); |
894 | | - |
895 | | - wfDebug( __METHOD__ . ": Extracting MacBinary data fork to $dataFile\n" ); |
896 | | - $macbin->extractData( $dataHandle ); |
897 | | - |
898 | | - $this->mTempPath = $dataFile; |
899 | | - $this->mFileSize = $macbin->dataForkLength(); |
900 | | - |
901 | | - // We'll have to manually remove the new file if it's not kept. |
902 | | - $this->mRemoveTempFile = true; |
903 | | - } |
904 | | - $macbin->close(); |
905 | | - } |
906 | | - |
907 | | - /** |
908 | 883 | * Check if there's an overwrite conflict and, if so, if restrictions |
909 | 884 | * forbid this user from performing the upload. |
910 | 885 | * |