Index: trunk/phase3/tests/phpunit/includes/HttpTest.php |
— | — | @@ -48,7 +48,7 @@ |
49 | 49 | |
50 | 50 | /** |
51 | 51 | * Test Http::isValidURI() |
52 | | - * @bug 27854 : Http::isValidURI is to lax |
| 52 | + * @bug 27854 : Http::isValidURI is too lax |
53 | 53 | * @dataProvider provideURI |
54 | 54 | */ |
55 | 55 | function testIsValidUri( $expect, $URI, $message = '' ) { |
— | — | @@ -76,7 +76,7 @@ |
77 | 77 | array( false, '\\host\directory', 'CIFS share' ), |
78 | 78 | array( false, 'gopher://host/dir', 'Reject gopher scheme' ), |
79 | 79 | array( false, 'telnet://host', 'Reject telnet scheme' ), |
80 | | - |
| 80 | + |
81 | 81 | # :\/\/ - double slashes |
82 | 82 | array( false, 'http//example.org', 'Reject missing colon in protocol' ), |
83 | 83 | array( false, 'http:/example.org', 'Reject missing slash in protocol' ), |
Index: trunk/phase3/includes/diff/DairikiDiff.php |
— | — | @@ -24,10 +24,16 @@ |
25 | 25 | trigger_error( 'pure virtual', E_USER_ERROR ); |
26 | 26 | } |
27 | 27 | |
| 28 | + /** |
| 29 | + * @return int |
| 30 | + */ |
28 | 31 | function norig() { |
29 | 32 | return $this->orig ? sizeof( $this->orig ) : 0; |
30 | 33 | } |
31 | 34 | |
| 35 | + /** |
| 36 | + * @return int |
| 37 | + */ |
32 | 38 | function nclosing() { |
33 | 39 | return $this->closing ? sizeof( $this->closing ) : 0; |
34 | 40 | } |
— | — | @@ -49,6 +55,9 @@ |
50 | 56 | $this->closing = $closing; |
51 | 57 | } |
52 | 58 | |
| 59 | + /** |
| 60 | + * @return _DiffOp_Copy |
| 61 | + */ |
53 | 62 | function reverse() { |
54 | 63 | return new _DiffOp_Copy( $this->closing, $this->orig ); |
55 | 64 | } |
— | — | @@ -67,6 +76,9 @@ |
68 | 77 | $this->closing = false; |
69 | 78 | } |
70 | 79 | |
| 80 | + /** |
| 81 | + * @return _DiffOp_Add |
| 82 | + */ |
71 | 83 | function reverse() { |
72 | 84 | return new _DiffOp_Add( $this->orig ); |
73 | 85 | } |
— | — | @@ -85,6 +97,9 @@ |
86 | 98 | $this->orig = false; |
87 | 99 | } |
88 | 100 | |
| 101 | + /** |
| 102 | + * @return _DiffOp_Delete |
| 103 | + */ |
89 | 104 | function reverse() { |
90 | 105 | return new _DiffOp_Delete( $this->closing ); |
91 | 106 | } |
— | — | @@ -103,6 +118,9 @@ |
104 | 119 | $this->closing = $closing; |
105 | 120 | } |
106 | 121 | |
| 122 | + /** |
| 123 | + * @return _DiffOp_Change |
| 124 | + */ |
107 | 125 | function reverse() { |
108 | 126 | return new _DiffOp_Change( $this->closing, $this->orig ); |
109 | 127 | } |
— | — | @@ -145,6 +163,11 @@ |
146 | 164 | |
147 | 165 | protected $lcs = 0; |
148 | 166 | |
| 167 | + /** |
| 168 | + * @param $from_lines |
| 169 | + * @param $to_lines |
| 170 | + * @return array |
| 171 | + */ |
149 | 172 | function diff ( $from_lines, $to_lines ) { |
150 | 173 | wfProfileIn( __METHOD__ ); |
151 | 174 | |
— | — | @@ -199,6 +222,10 @@ |
200 | 223 | return $edits; |
201 | 224 | } |
202 | 225 | |
| 226 | + /** |
| 227 | + * @param $from_lines |
| 228 | + * @param $to_lines |
| 229 | + */ |
203 | 230 | function diff_local ( $from_lines, $to_lines ) { |
204 | 231 | global $wgExternalDiffEngine; |
205 | 232 | wfProfileIn( __METHOD__ ); |
— | — | @@ -268,6 +295,8 @@ |
269 | 296 | |
270 | 297 | /** |
271 | 298 | * Returns the whole line if it's small enough, or the MD5 hash otherwise |
| 299 | + * @param $line string |
| 300 | + * @return string |
272 | 301 | */ |
273 | 302 | function _line_hash( $line ) { |
274 | 303 | if ( strlen( $line ) > self::MAX_XREF_LENGTH ) { |
— | — | @@ -293,6 +322,12 @@ |
294 | 323 | * of the two files do not match, and likewise that the last lines do not |
295 | 324 | * match. The caller must trim matching lines from the beginning and end |
296 | 325 | * of the portions it is going to specify. |
| 326 | + * @param $xoff |
| 327 | + * @param $xlim |
| 328 | + * @param $yoff |
| 329 | + * @param $ylim |
| 330 | + * @param $nchunks |
| 331 | + * @return array |
297 | 332 | */ |
298 | 333 | function _diag( $xoff, $xlim, $yoff, $ylim, $nchunks ) { |
299 | 334 | $flip = false; |
— | — | @@ -373,6 +408,10 @@ |
374 | 409 | return array( $this->lcs, $seps ); |
375 | 410 | } |
376 | 411 | |
| 412 | + /** |
| 413 | + * @param $ypos |
| 414 | + * @return int |
| 415 | + */ |
377 | 416 | function _lcs_pos( $ypos ) { |
378 | 417 | $end = $this->lcs; |
379 | 418 | if ( $end == 0 || $ypos > $this->seq[$end] ) { |
— | — | @@ -410,6 +449,10 @@ |
411 | 450 | * |
412 | 451 | * Note that XLIM, YLIM are exclusive bounds. |
413 | 452 | * All line numbers are origin-0 and discarded lines are not counted. |
| 453 | + * @param $xoff |
| 454 | + * @param $xlim |
| 455 | + * @param $yoff |
| 456 | + * @param $ylim |
414 | 457 | */ |
415 | 458 | function _compareseq ( $xoff, $xlim, $yoff, $ylim ) { |
416 | 459 | // Slide down the bottom initial diagonal. |
— | — | @@ -703,6 +746,8 @@ |
704 | 747 | * Check a Diff for validity. |
705 | 748 | * |
706 | 749 | * This is here only for debugging purposes. |
| 750 | + * @param $from_lines |
| 751 | + * @param $to_lines |
707 | 752 | */ |
708 | 753 | function _check( $from_lines, $to_lines ) { |
709 | 754 | wfProfileIn( __METHOD__ ); |
— | — | @@ -886,6 +931,13 @@ |
887 | 932 | return $end; |
888 | 933 | } |
889 | 934 | |
| 935 | + /** |
| 936 | + * @param $xbeg |
| 937 | + * @param $xlen |
| 938 | + * @param $ybeg |
| 939 | + * @param $ylen |
| 940 | + * @param $edits |
| 941 | + */ |
890 | 942 | function _block( $xbeg, $xlen, $ybeg, $ylen, &$edits ) { |
891 | 943 | wfProfileIn( __METHOD__ ); |
892 | 944 | $this->_start_block( $this->_block_header( $xbeg, $xlen, $ybeg, $ylen ) ); |
— | — | @@ -910,12 +962,22 @@ |
911 | 963 | ob_start(); |
912 | 964 | } |
913 | 965 | |
| 966 | + /** |
| 967 | + * @return string |
| 968 | + */ |
914 | 969 | function _end_diff() { |
915 | 970 | $val = ob_get_contents(); |
916 | 971 | ob_end_clean(); |
917 | 972 | return $val; |
918 | 973 | } |
919 | 974 | |
| 975 | + /** |
| 976 | + * @param $xbeg |
| 977 | + * @param $xlen |
| 978 | + * @param $ybeg |
| 979 | + * @param $ylen |
| 980 | + * @return string |
| 981 | + */ |
920 | 982 | function _block_header( $xbeg, $xlen, $ybeg, $ylen ) { |
921 | 983 | if ( $xlen > 1 ) { |
922 | 984 | $xbeg .= ',' . ( $xbeg + $xlen - 1 ); |
— | — | @@ -934,23 +996,41 @@ |
935 | 997 | function _end_block() { |
936 | 998 | } |
937 | 999 | |
| 1000 | + /** |
| 1001 | + * @param $lines |
| 1002 | + * @param $prefix string |
| 1003 | + */ |
938 | 1004 | function _lines( $lines, $prefix = ' ' ) { |
939 | 1005 | foreach ( $lines as $line ) { |
940 | 1006 | echo "$prefix $line\n"; |
941 | 1007 | } |
942 | 1008 | } |
943 | 1009 | |
| 1010 | + /** |
| 1011 | + * @param $lines |
| 1012 | + */ |
944 | 1013 | function _context( $lines ) { |
945 | 1014 | $this->_lines( $lines ); |
946 | 1015 | } |
947 | 1016 | |
| 1017 | + /** |
| 1018 | + * @param $lines |
| 1019 | + */ |
948 | 1020 | function _added( $lines ) { |
949 | 1021 | $this->_lines( $lines, '>' ); |
950 | 1022 | } |
| 1023 | + |
| 1024 | + /** |
| 1025 | + * @param $lines |
| 1026 | + */ |
951 | 1027 | function _deleted( $lines ) { |
952 | 1028 | $this->_lines( $lines, '<' ); |
953 | 1029 | } |
954 | 1030 | |
| 1031 | + /** |
| 1032 | + * @param $orig |
| 1033 | + * @param $closing |
| 1034 | + */ |
955 | 1035 | function _changed( $orig, $closing ) { |
956 | 1036 | $this->_deleted( $orig ); |
957 | 1037 | echo "---\n"; |
— | — | @@ -966,16 +1046,36 @@ |
967 | 1047 | var $leading_context_lines = 2; |
968 | 1048 | var $trailing_context_lines = 2; |
969 | 1049 | |
| 1050 | + /** |
| 1051 | + * @param $lines |
| 1052 | + */ |
970 | 1053 | function _added( $lines ) { |
971 | 1054 | $this->_lines( $lines, '+' ); |
972 | 1055 | } |
| 1056 | + |
| 1057 | + /** |
| 1058 | + * @param $lines |
| 1059 | + */ |
973 | 1060 | function _deleted( $lines ) { |
974 | 1061 | $this->_lines( $lines, '-' ); |
975 | 1062 | } |
| 1063 | + |
| 1064 | + /** |
| 1065 | + * @param $orig |
| 1066 | + * @param $closing |
| 1067 | + */ |
976 | 1068 | function _changed( $orig, $closing ) { |
977 | 1069 | $this->_deleted( $orig ); |
978 | 1070 | $this->_added( $closing ); |
979 | 1071 | } |
| 1072 | + |
| 1073 | + /** |
| 1074 | + * @param $xbeg |
| 1075 | + * @param $xlen |
| 1076 | + * @param $ybeg |
| 1077 | + * @param $ylen |
| 1078 | + * @return string |
| 1079 | + */ |
980 | 1080 | function _block_header( $xbeg, $xlen, $ybeg, $ylen ) { |
981 | 1081 | return "@@ -$xbeg,$xlen +$ybeg,$ylen @@"; |
982 | 1082 | } |
— | — | @@ -986,6 +1086,11 @@ |
987 | 1087 | * @ingroup DifferenceEngine |
988 | 1088 | */ |
989 | 1089 | class ArrayDiffFormatter extends DiffFormatter { |
| 1090 | + |
| 1091 | + /** |
| 1092 | + * @param $diff |
| 1093 | + * @return array |
| 1094 | + */ |
990 | 1095 | function format( $diff ) { |
991 | 1096 | $oldline = 1; |
992 | 1097 | $newline = 1; |
— | — | @@ -1049,6 +1154,9 @@ |
1050 | 1155 | $this->_tag = ''; |
1051 | 1156 | } |
1052 | 1157 | |
| 1158 | + /** |
| 1159 | + * @param $new_tag |
| 1160 | + */ |
1053 | 1161 | function _flushGroup( $new_tag ) { |
1054 | 1162 | if ( $this->_group !== '' ) { |
1055 | 1163 | if ( $this->_tag == 'ins' ) { |
— | — | @@ -1065,6 +1173,9 @@ |
1066 | 1174 | $this->_tag = $new_tag; |
1067 | 1175 | } |
1068 | 1176 | |
| 1177 | + /** |
| 1178 | + * @param $new_tag |
| 1179 | + */ |
1069 | 1180 | function _flushLine( $new_tag ) { |
1070 | 1181 | $this->_flushGroup( $new_tag ); |
1071 | 1182 | if ( $this->_line != '' ) { |
— | — | @@ -1076,6 +1187,10 @@ |
1077 | 1188 | $this->_line = ''; |
1078 | 1189 | } |
1079 | 1190 | |
| 1191 | + /** |
| 1192 | + * @param $words |
| 1193 | + * @param $tag string |
| 1194 | + */ |
1080 | 1195 | function addWords ( $words, $tag = '' ) { |
1081 | 1196 | if ( $tag != $this->_tag ) { |
1082 | 1197 | $this->_flushGroup( $tag ); |
— | — | @@ -1095,6 +1210,9 @@ |
1096 | 1211 | } |
1097 | 1212 | } |
1098 | 1213 | |
| 1214 | + /** |
| 1215 | + * @return array |
| 1216 | + */ |
1099 | 1217 | function getLines() { |
1100 | 1218 | $this->_flushLine( '~done' ); |
1101 | 1219 | return $this->_lines; |
— | — | @@ -1109,6 +1227,10 @@ |
1110 | 1228 | class WordLevelDiff extends MappedDiff { |
1111 | 1229 | const MAX_LINE_LENGTH = 10000; |
1112 | 1230 | |
| 1231 | + /** |
| 1232 | + * @param $orig_lines |
| 1233 | + * @param $closing_lines |
| 1234 | + */ |
1113 | 1235 | function __construct ( $orig_lines, $closing_lines ) { |
1114 | 1236 | wfProfileIn( __METHOD__ ); |
1115 | 1237 | |
— | — | @@ -1120,6 +1242,10 @@ |
1121 | 1243 | wfProfileOut( __METHOD__ ); |
1122 | 1244 | } |
1123 | 1245 | |
| 1246 | + /** |
| 1247 | + * @param $lines |
| 1248 | + * @return array |
| 1249 | + */ |
1124 | 1250 | function _split( $lines ) { |
1125 | 1251 | wfProfileIn( __METHOD__ ); |
1126 | 1252 | |
— | — | @@ -1152,6 +1278,9 @@ |
1153 | 1279 | return array( $words, $stripped ); |
1154 | 1280 | } |
1155 | 1281 | |
| 1282 | + /** |
| 1283 | + * @return array |
| 1284 | + */ |
1156 | 1285 | function orig() { |
1157 | 1286 | wfProfileIn( __METHOD__ ); |
1158 | 1287 | $orig = new _HWLDF_WordAccumulator; |
— | — | @@ -1168,6 +1297,9 @@ |
1169 | 1298 | return $lines; |
1170 | 1299 | } |
1171 | 1300 | |
| 1301 | + /** |
| 1302 | + * @return array |
| 1303 | + */ |
1172 | 1304 | function closing() { |
1173 | 1305 | wfProfileIn( __METHOD__ ); |
1174 | 1306 | $closing = new _HWLDF_WordAccumulator; |
— | — | @@ -1197,6 +1329,11 @@ |
1198 | 1330 | $this->trailing_context_lines = 2; |
1199 | 1331 | } |
1200 | 1332 | |
| 1333 | + /** |
| 1334 | + * @static |
| 1335 | + * @param $msg |
| 1336 | + * @return mixed |
| 1337 | + */ |
1201 | 1338 | public static function escapeWhiteSpace( $msg ) { |
1202 | 1339 | $msg = preg_replace( '/^ /m', '  ', $msg ); |
1203 | 1340 | $msg = preg_replace( '/ $/m', '  ', $msg ); |
— | — | @@ -1204,12 +1341,22 @@ |
1205 | 1342 | return $msg; |
1206 | 1343 | } |
1207 | 1344 | |
| 1345 | + /** |
| 1346 | + * @param $xbeg |
| 1347 | + * @param $xlen |
| 1348 | + * @param $ybeg |
| 1349 | + * @param $ylen |
| 1350 | + * @return string |
| 1351 | + */ |
1208 | 1352 | function _block_header( $xbeg, $xlen, $ybeg, $ylen ) { |
1209 | 1353 | $r = '<tr><td colspan="2" class="diff-lineno"><!--LINE ' . $xbeg . "--></td>\n" . |
1210 | 1354 | '<td colspan="2" class="diff-lineno"><!--LINE ' . $ybeg . "--></td></tr>\n"; |
1211 | 1355 | return $r; |
1212 | 1356 | } |
1213 | 1357 | |
| 1358 | + /** |
| 1359 | + * @param $header |
| 1360 | + */ |
1214 | 1361 | function _start_block( $header ) { |
1215 | 1362 | echo $header; |
1216 | 1363 | } |
— | — | @@ -1220,21 +1367,39 @@ |
1221 | 1368 | function _lines( $lines, $prefix = ' ', $color = 'white' ) { |
1222 | 1369 | } |
1223 | 1370 | |
1224 | | - # HTML-escape parameter before calling this |
| 1371 | + /** |
| 1372 | + * HTML-escape parameter before calling this |
| 1373 | + * @param $line |
| 1374 | + * @return string |
| 1375 | + */ |
1225 | 1376 | function addedLine( $line ) { |
1226 | 1377 | return $this->wrapLine( '+', 'diff-addedline', $line ); |
1227 | 1378 | } |
1228 | 1379 | |
1229 | | - # HTML-escape parameter before calling this |
| 1380 | + /** |
| 1381 | + * HTML-escape parameter before calling this |
| 1382 | + * @param $line |
| 1383 | + * @return string |
| 1384 | + */ |
1230 | 1385 | function deletedLine( $line ) { |
1231 | 1386 | return $this->wrapLine( '−', 'diff-deletedline', $line ); |
1232 | 1387 | } |
1233 | 1388 | |
1234 | | - # HTML-escape parameter before calling this |
| 1389 | + /** |
| 1390 | + * HTML-escape parameter before calling this |
| 1391 | + * @param $line |
| 1392 | + * @return string |
| 1393 | + */ |
1235 | 1394 | function contextLine( $line ) { |
1236 | 1395 | return $this->wrapLine( ' ', 'diff-context', $line ); |
1237 | 1396 | } |
1238 | 1397 | |
| 1398 | + /** |
| 1399 | + * @param $marker |
| 1400 | + * @param $class |
| 1401 | + * @param $line |
| 1402 | + * @return string |
| 1403 | + */ |
1239 | 1404 | private function wrapLine( $marker, $class, $line ) { |
1240 | 1405 | if ( $line !== '' ) { |
1241 | 1406 | // The <div> wrapper is needed for 'overflow: auto' style to scroll properly |
— | — | @@ -1243,10 +1408,16 @@ |
1244 | 1409 | return "<td class='diff-marker'>$marker</td><td class='$class'>$line</td>"; |
1245 | 1410 | } |
1246 | 1411 | |
| 1412 | + /** |
| 1413 | + * @return string |
| 1414 | + */ |
1247 | 1415 | function emptyLine() { |
1248 | 1416 | return '<td colspan="2"> </td>'; |
1249 | 1417 | } |
1250 | 1418 | |
| 1419 | + /** |
| 1420 | + * @param $lines array |
| 1421 | + */ |
1251 | 1422 | function _added( $lines ) { |
1252 | 1423 | foreach ( $lines as $line ) { |
1253 | 1424 | echo '<tr>' . $this->emptyLine() . |
— | — | @@ -1255,6 +1426,9 @@ |
1256 | 1427 | } |
1257 | 1428 | } |
1258 | 1429 | |
| 1430 | + /** |
| 1431 | + * @param $lines |
| 1432 | + */ |
1259 | 1433 | function _deleted( $lines ) { |
1260 | 1434 | foreach ( $lines as $line ) { |
1261 | 1435 | echo '<tr>' . $this->deletedLine( '<del class="diffchange">' . |
— | — | @@ -1263,6 +1437,9 @@ |
1264 | 1438 | } |
1265 | 1439 | } |
1266 | 1440 | |
| 1441 | + /** |
| 1442 | + * @param $lines |
| 1443 | + */ |
1267 | 1444 | function _context( $lines ) { |
1268 | 1445 | foreach ( $lines as $line ) { |
1269 | 1446 | echo '<tr>' . |
— | — | @@ -1271,6 +1448,10 @@ |
1272 | 1449 | } |
1273 | 1450 | } |
1274 | 1451 | |
| 1452 | + /** |
| 1453 | + * @param $orig |
| 1454 | + * @param $closing |
| 1455 | + */ |
1275 | 1456 | function _changed( $orig, $closing ) { |
1276 | 1457 | wfProfileIn( __METHOD__ ); |
1277 | 1458 | |
Index: trunk/phase3/includes/json/FormatJson.php |
— | — | @@ -11,11 +11,14 @@ |
12 | 12 | |
13 | 13 | require_once dirname( __FILE__ ) . '/Services_JSON.php'; |
14 | 14 | |
| 15 | +/** |
| 16 | + * JSON formatter wrapper class |
| 17 | + */ |
15 | 18 | class FormatJson { |
16 | | - |
| 19 | + |
17 | 20 | /** |
18 | 21 | * Returns the JSON representation of a value. |
19 | | - * |
| 22 | + * |
20 | 23 | * @param $value Mixed: the value being encoded. Can be any type except a resource. |
21 | 24 | * @param $isHtml Boolean |
22 | 25 | * |
— | — | @@ -23,7 +26,7 @@ |
24 | 27 | * map to a parameter labeled "pretty-print output with indents and |
25 | 28 | * newlines" in Services_JSON::encode(), which has no string relation |
26 | 29 | * to HTML output. |
27 | | - * |
| 30 | + * |
28 | 31 | * @return string |
29 | 32 | */ |
30 | 33 | public static function encode( $value, $isHtml = false ) { |
— | — | @@ -40,10 +43,10 @@ |
41 | 44 | |
42 | 45 | /** |
43 | 46 | * Decodes a JSON string. |
44 | | - * |
| 47 | + * |
45 | 48 | * @param $value String: the json string being decoded. |
46 | 49 | * @param $assoc Boolean: when true, returned objects will be converted into associative arrays. |
47 | | - * |
| 50 | + * |
48 | 51 | * @return Mixed: the value encoded in json in appropriate PHP type. |
49 | 52 | * Values true, false and null (case-insensitive) are returned as true, false |
50 | 53 | * and &null; respectively. &null; is returned if the json cannot be |
— | — | @@ -61,5 +64,5 @@ |
62 | 65 | return json_decode( $value, $assoc ); |
63 | 66 | } |
64 | 67 | } |
65 | | - |
| 68 | + |
66 | 69 | } |
Index: trunk/phase3/includes/job/JobQueue.php |
— | — | @@ -213,6 +213,10 @@ |
214 | 214 | throw new MWException( "Invalid job command `{$command}`" ); |
215 | 215 | } |
216 | 216 | |
| 217 | + /** |
| 218 | + * @param $params |
| 219 | + * @return string |
| 220 | + */ |
217 | 221 | static function makeBlob( $params ) { |
218 | 222 | if ( $params !== false ) { |
219 | 223 | return serialize( $params ); |
— | — | @@ -221,6 +225,10 @@ |
222 | 226 | } |
223 | 227 | } |
224 | 228 | |
| 229 | + /** |
| 230 | + * @param $blob |
| 231 | + * @return bool|mixed |
| 232 | + */ |
225 | 233 | static function extractBlob( $blob ) { |
226 | 234 | if ( (string)$blob !== '' ) { |
227 | 235 | return unserialize( $blob ); |
— | — | @@ -323,13 +331,16 @@ |
324 | 332 | if ( $this->removeDuplicates ) { |
325 | 333 | $res = $dbw->select( 'job', array( '1' ), $fields, __METHOD__ ); |
326 | 334 | if ( $dbw->numRows( $res ) ) { |
327 | | - return; |
| 335 | + return true; |
328 | 336 | } |
329 | 337 | } |
330 | 338 | wfIncrStats( 'job-insert' ); |
331 | 339 | return $dbw->insert( 'job', $fields, __METHOD__ ); |
332 | 340 | } |
333 | 341 | |
| 342 | + /** |
| 343 | + * @return array |
| 344 | + */ |
334 | 345 | protected function insertFields() { |
335 | 346 | $dbw = wfGetDB( DB_MASTER ); |
336 | 347 | return array( |
— | — | @@ -362,6 +373,9 @@ |
363 | 374 | } |
364 | 375 | } |
365 | 376 | |
| 377 | + /** |
| 378 | + * @return string |
| 379 | + */ |
366 | 380 | function toString() { |
367 | 381 | $paramString = ''; |
368 | 382 | if ( $this->params ) { |
Index: trunk/phase3/includes/job/UploadFromUrlJob.php |
— | — | @@ -64,7 +64,7 @@ |
65 | 65 | |
66 | 66 | # Stash the upload |
67 | 67 | $key = $this->upload->stashFile(); |
68 | | - |
| 68 | + |
69 | 69 | if ( $this->params['leaveMessage'] ) { |
70 | 70 | $this->user->leaveUserMessage( |
71 | 71 | wfMsg( 'upload-warning-subj' ), |
— | — | @@ -73,7 +73,7 @@ |
74 | 74 | $this->params['url'] ) |
75 | 75 | ); |
76 | 76 | } else { |
77 | | - wfSetupSession( $this->params['sessionId'] ); |
| 77 | + wfSetupSession( $this->params['sessionId'] ); |
78 | 78 | $this->storeResultInSession( 'Warning', |
79 | 79 | 'warnings', $warnings ); |
80 | 80 | session_write_close(); |
— | — | @@ -151,6 +151,10 @@ |
152 | 152 | $$session['result'] = 'Queued'; |
153 | 153 | } |
154 | 154 | |
| 155 | + /** |
| 156 | + * @param $key |
| 157 | + * @return mixed |
| 158 | + */ |
155 | 159 | public static function &getSessionData( $key ) { |
156 | 160 | if ( !isset( $_SESSION[self::SESSION_KEYNAME][$key] ) ) { |
157 | 161 | $_SESSION[self::SESSION_KEYNAME][$key] = array(); |
Index: trunk/phase3/includes/job/DoubleRedirectJob.php |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | */ |
21 | 21 | static $user; |
22 | 22 | |
23 | | - /** |
| 23 | + /** |
24 | 24 | * Insert jobs into the job queue to fix redirects to the given title |
25 | 25 | * @param $reason String: the reason for the fix, see message double-redirect-fixed-<reason> |
26 | 26 | * @param $redirTitle Title: the title which has changed, redirects pointing to this title are fixed |
— | — | @@ -28,10 +28,10 @@ |
29 | 29 | public static function fixRedirects( $reason, $redirTitle, $destTitle = false ) { |
30 | 30 | # Need to use the master to get the redirect table updated in the same transaction |
31 | 31 | $dbw = wfGetDB( DB_MASTER ); |
32 | | - $res = $dbw->select( |
33 | | - array( 'redirect', 'page' ), |
34 | | - array( 'page_namespace', 'page_title' ), |
35 | | - array( |
| 32 | + $res = $dbw->select( |
| 33 | + array( 'redirect', 'page' ), |
| 34 | + array( 'page_namespace', 'page_title' ), |
| 35 | + array( |
36 | 36 | 'page_id = rd_from', |
37 | 37 | 'rd_namespace' => $redirTitle->getNamespace(), |
38 | 38 | 'rd_title' => $redirTitle->getDBkey() |
— | — | @@ -46,7 +46,7 @@ |
47 | 47 | continue; |
48 | 48 | } |
49 | 49 | |
50 | | - $jobs[] = new self( $title, array( |
| 50 | + $jobs[] = new self( $title, array( |
51 | 51 | 'reason' => $reason, |
52 | 52 | 'redirTitle' => $redirTitle->getPrefixedDBkey() ) ); |
53 | 53 | # Avoid excessive memory usage |
— | — | @@ -65,6 +65,9 @@ |
66 | 66 | $this->destTitleText = !empty( $params['destTitle'] ) ? $params['destTitle'] : ''; |
67 | 67 | } |
68 | 68 | |
| 69 | + /** |
| 70 | + * @return bool |
| 71 | + */ |
69 | 72 | function run() { |
70 | 73 | if ( !$this->redirTitle ) { |
71 | 74 | $this->setLastError( 'Invalid title' ); |
— | — | @@ -103,13 +106,13 @@ |
104 | 107 | } |
105 | 108 | |
106 | 109 | # Preserve fragment (bug 14904) |
107 | | - $newTitle = Title::makeTitle( $newTitle->getNamespace(), $newTitle->getDBkey(), |
| 110 | + $newTitle = Title::makeTitle( $newTitle->getNamespace(), $newTitle->getDBkey(), |
108 | 111 | $currentDest->getFragment() ); |
109 | 112 | |
110 | 113 | # Fix the text |
111 | 114 | # Remember that redirect pages can have categories, templates, etc., |
112 | 115 | # so the regex has to be fairly general |
113 | | - $newText = preg_replace( '/ \[ \[ [^\]]* \] \] /x', |
| 116 | + $newText = preg_replace( '/ \[ \[ [^\]]* \] \] /x', |
114 | 117 | '[[' . $newTitle->getFullText() . ']]', |
115 | 118 | $text, 1 ); |
116 | 119 | |
— | — | @@ -123,7 +126,7 @@ |
124 | 127 | $oldUser = $wgUser; |
125 | 128 | $wgUser = $this->getUser(); |
126 | 129 | $article = new Article( $this->title ); |
127 | | - $reason = wfMsgForContent( 'double-redirect-fixed-' . $this->reason, |
| 130 | + $reason = wfMsgForContent( 'double-redirect-fixed-' . $this->reason, |
128 | 131 | $this->redirTitle->getPrefixedText(), $newTitle->getPrefixedText() ); |
129 | 132 | $article->doEdit( $newText, $reason, EDIT_UPDATE | EDIT_SUPPRESS_RC ); |
130 | 133 | $wgUser = $oldUser; |
— | — | @@ -152,10 +155,10 @@ |
153 | 156 | } |
154 | 157 | $seenTitles[$titleText] = true; |
155 | 158 | |
156 | | - $row = $dbw->selectRow( |
| 159 | + $row = $dbw->selectRow( |
157 | 160 | array( 'redirect', 'page' ), |
158 | 161 | array( 'rd_namespace', 'rd_title' ), |
159 | | - array( |
| 162 | + array( |
160 | 163 | 'rd_from=page_id', |
161 | 164 | 'page_namespace' => $title->getNamespace(), |
162 | 165 | 'page_title' => $title->getDBkey() |
— | — | @@ -172,6 +175,7 @@ |
173 | 176 | |
174 | 177 | /** |
175 | 178 | * Get a user object for doing edits, from a request-lifetime cache |
| 179 | + * @return User |
176 | 180 | */ |
177 | 181 | function getUser() { |
178 | 182 | if ( !self::$user ) { |
Index: trunk/phase3/includes/libs/CSSJanus.php |
— | — | @@ -175,6 +175,8 @@ |
176 | 176 | * |
177 | 177 | * See http://code.google.com/p/cssjanus/issues/detail?id=15 and |
178 | 178 | * TODO: URL |
| 179 | + * @param $css string |
| 180 | + * @return string |
179 | 181 | */ |
180 | 182 | private static function fixDirection( $css ) { |
181 | 183 | $css = preg_replace( self::$patterns['direction_ltr'], |
— | — | @@ -187,6 +189,8 @@ |
188 | 190 | |
189 | 191 | /** |
190 | 192 | * Replace 'ltr' with 'rtl' and vice versa in background URLs |
| 193 | + * @param $css string |
| 194 | + * @return string |
191 | 195 | */ |
192 | 196 | private static function fixLtrRtlInURL( $css ) { |
193 | 197 | $css = preg_replace( self::$patterns['ltr_in_url'], self::$patterns['tmpToken'], $css ); |
— | — | @@ -198,6 +202,8 @@ |
199 | 203 | |
200 | 204 | /** |
201 | 205 | * Replace 'left' with 'right' and vice versa in background URLs |
| 206 | + * @param $css string |
| 207 | + * @return string |
202 | 208 | */ |
203 | 209 | private static function fixLeftRightInURL( $css ) { |
204 | 210 | $css = preg_replace( self::$patterns['left_in_url'], self::$patterns['tmpToken'], $css ); |
— | — | @@ -209,6 +215,8 @@ |
210 | 216 | |
211 | 217 | /** |
212 | 218 | * Flip rules like left: , padding-right: , etc. |
| 219 | + * @param $css string |
| 220 | + * @return string |
213 | 221 | */ |
214 | 222 | private static function fixLeftAndRight( $css ) { |
215 | 223 | $css = preg_replace( self::$patterns['left'], self::$patterns['tmpToken'], $css ); |
— | — | @@ -220,6 +228,8 @@ |
221 | 229 | |
222 | 230 | /** |
223 | 231 | * Flip East and West in rules like cursor: nw-resize; |
| 232 | + * @param $css string |
| 233 | + * @return string |
224 | 234 | */ |
225 | 235 | private static function fixCursorProperties( $css ) { |
226 | 236 | $css = preg_replace( self::$patterns['cursor_east'], |
— | — | @@ -239,6 +249,8 @@ |
240 | 250 | * and four-part color rules with multiple whitespace characters between |
241 | 251 | * colors are not recognized. |
242 | 252 | * See http://code.google.com/p/cssjanus/issues/detail?id=16 |
| 253 | + * @param $css string |
| 254 | + * @return string |
243 | 255 | */ |
244 | 256 | private static function fixFourPartNotation( $css ) { |
245 | 257 | $css = preg_replace( self::$patterns['four_notation_quantity'], '$1$2$7$4$5$6$3', $css ); |
— | — | @@ -249,6 +261,8 @@ |
250 | 262 | |
251 | 263 | /** |
252 | 264 | * Flip horizontal background percentages. |
| 265 | + * @param $css string |
| 266 | + * @return string |
253 | 267 | */ |
254 | 268 | private static function fixBackgroundPosition( $css ) { |
255 | 269 | $css = preg_replace_callback( self::$patterns['bg_horizontal_percentage'], |
— | — | @@ -261,6 +275,8 @@ |
262 | 276 | |
263 | 277 | /** |
264 | 278 | * Callback for calculateNewBackgroundPosition() |
| 279 | + * @param $matches array |
| 280 | + * @return string |
265 | 281 | */ |
266 | 282 | private static function calculateNewBackgroundPosition( $matches ) { |
267 | 283 | return $matches[1] . ( 100 - $matches[2] ) . $matches[3]; |
— | — | @@ -297,6 +313,10 @@ |
298 | 314 | return preg_replace_callback( $this->regex, array( $this, 'tokenizeCallback' ), $str ); |
299 | 315 | } |
300 | 316 | |
| 317 | + /** |
| 318 | + * @param $matches array |
| 319 | + * @return string |
| 320 | + */ |
301 | 321 | private function tokenizeCallback( $matches ) { |
302 | 322 | $this->originals[] = $matches[0]; |
303 | 323 | return $this->token; |
— | — | @@ -316,6 +336,10 @@ |
317 | 337 | array( $this, 'detokenizeCallback' ), $str ); |
318 | 338 | } |
319 | 339 | |
| 340 | + /** |
| 341 | + * @param $matches |
| 342 | + * @return mixed |
| 343 | + */ |
320 | 344 | private function detokenizeCallback( $matches ) { |
321 | 345 | $retval = current( $this->originals ); |
322 | 346 | next( $this->originals ); |
Index: trunk/phase3/includes/libs/CSSMin.php |
— | — | @@ -79,6 +79,10 @@ |
80 | 80 | return $files; |
81 | 81 | } |
82 | 82 | |
| 83 | + /** |
| 84 | + * @param $file string |
| 85 | + * @return bool|string |
| 86 | + */ |
83 | 87 | protected static function getMimeType( $file ) { |
84 | 88 | $realpath = realpath( $file ); |
85 | 89 | // Try a couple of different ways to get the mime-type of a file, in order of |
Index: trunk/phase3/includes/libs/IEUrlExtension.php |
— | — | @@ -1,31 +1,31 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * Internet Explorer derives a cache filename from a URL, and then in certain |
6 | | - * circumstances, uses the extension of the resulting file to determine the |
7 | | - * content type of the data, ignoring the Content-Type header. |
| 5 | + * Internet Explorer derives a cache filename from a URL, and then in certain |
| 6 | + * circumstances, uses the extension of the resulting file to determine the |
| 7 | + * content type of the data, ignoring the Content-Type header. |
8 | 8 | * |
9 | 9 | * This can be a problem, especially when non-HTML content is sent by MediaWiki, |
10 | 10 | * and Internet Explorer interprets it as HTML, exposing an XSS vulnerability. |
11 | 11 | * |
12 | | - * Usually the script filename (e.g. api.php) is present in the URL, and this |
| 12 | + * Usually the script filename (e.g. api.php) is present in the URL, and this |
13 | 13 | * makes Internet Explorer think the extension is a harmless script extension. |
14 | | - * But Internet Explorer 6 and earlier allows the script extension to be |
15 | | - * obscured by encoding the dot as "%2E". |
| 14 | + * But Internet Explorer 6 and earlier allows the script extension to be |
| 15 | + * obscured by encoding the dot as "%2E". |
16 | 16 | * |
17 | | - * This class contains functions which help in detecting and dealing with this |
| 17 | + * This class contains functions which help in detecting and dealing with this |
18 | 18 | * situation. |
19 | 19 | * |
20 | | - * Checking the URL for a bad extension is somewhat complicated due to the fact |
| 20 | + * Checking the URL for a bad extension is somewhat complicated due to the fact |
21 | 21 | * that CGI doesn't provide a standard method to determine the URL. Instead it |
22 | | - * is necessary to pass a subset of $_SERVER variables, which we then attempt |
| 22 | + * is necessary to pass a subset of $_SERVER variables, which we then attempt |
23 | 23 | * to use to guess parts of the URL. |
24 | 24 | */ |
25 | 25 | class IEUrlExtension { |
26 | 26 | /** |
27 | 27 | * Check a subset of $_SERVER (or the whole of $_SERVER if you like) |
28 | | - * to see if it indicates that the request was sent with a bad file |
29 | | - * extension. Returns true if the request should be denied or modified, |
| 28 | + * to see if it indicates that the request was sent with a bad file |
| 29 | + * extension. Returns true if the request should be denied or modified, |
30 | 30 | * false otherwise. The relevant $_SERVER elements are: |
31 | 31 | * |
32 | 32 | * - SERVER_SOFTWARE |
— | — | @@ -37,6 +37,7 @@ |
38 | 38 | * |
39 | 39 | * @param $vars A subset of $_SERVER. |
40 | 40 | * @param $extWhitelist Extensions which are allowed, assumed harmless. |
| 41 | + * @return bool |
41 | 42 | */ |
42 | 43 | public static function areServerVarsBad( $vars, $extWhitelist = array() ) { |
43 | 44 | // Check QUERY_STRING or REQUEST_URI |
— | — | @@ -55,7 +56,7 @@ |
56 | 57 | return true; |
57 | 58 | } |
58 | 59 | |
59 | | - // Some servers have PATH_INFO but not REQUEST_URI, so we check both |
| 60 | + // Some servers have PATH_INFO but not REQUEST_URI, so we check both |
60 | 61 | // to be on the safe side. |
61 | 62 | if ( isset( $vars['PATH_INFO'] ) |
62 | 63 | && self::isUrlExtensionBad( $vars['PATH_INFO'], $extWhitelist ) ) |
— | — | @@ -71,7 +72,7 @@ |
72 | 73 | * Given a right-hand portion of a URL, determine whether IE would detect |
73 | 74 | * a potentially harmful file extension. |
74 | 75 | * |
75 | | - * @param $urlPart The right-hand portion of a URL |
| 76 | + * @param $urlPart string The right-hand portion of a URL |
76 | 77 | * @param $extWhitelist An array of file extensions which may occur in this |
77 | 78 | * URL, and which should be allowed. |
78 | 79 | * @return bool |
— | — | @@ -97,10 +98,10 @@ |
98 | 99 | } |
99 | 100 | |
100 | 101 | if ( !preg_match( '/^[a-zA-Z0-9_-]+$/', $extension ) ) { |
101 | | - // Non-alphanumeric extension, unlikely to be registered. |
| 102 | + // Non-alphanumeric extension, unlikely to be registered. |
102 | 103 | // |
103 | 104 | // The regex above is known to match all registered file extensions |
104 | | - // in a default Windows XP installation. It's important to allow |
| 105 | + // in a default Windows XP installation. It's important to allow |
105 | 106 | // extensions with ampersands and percent signs, since that reduces |
106 | 107 | // the number of false positives substantially. |
107 | 108 | return false; |
— | — | @@ -111,8 +112,11 @@ |
112 | 113 | } |
113 | 114 | |
114 | 115 | /** |
115 | | - * Returns a variant of $url which will pass isUrlExtensionBad() but has the |
| 116 | + * Returns a variant of $url which will pass isUrlExtensionBad() but has the |
116 | 117 | * same GET parameters, or false if it can't figure one out. |
| 118 | + * @param $url |
| 119 | + * @param $extWhitelist array |
| 120 | + * @return bool|string |
117 | 121 | */ |
118 | 122 | public static function fixUrlForIE6( $url, $extWhitelist = array() ) { |
119 | 123 | $questionPos = strpos( $url, '?' ); |
— | — | @@ -127,7 +131,7 @@ |
128 | 132 | $query = substr( $url, $questionPos + 1 ); |
129 | 133 | } |
130 | 134 | |
131 | | - // Multiple question marks cause problems. Encode the second and |
| 135 | + // Multiple question marks cause problems. Encode the second and |
132 | 136 | // subsequent question mark. |
133 | 137 | $query = str_replace( '?', '%3E', $query ); |
134 | 138 | // Append an invalid path character so that IE6 won't see the end of the |
— | — | @@ -153,16 +157,16 @@ |
154 | 158 | * insecure. |
155 | 159 | * |
156 | 160 | * The criteria for finding an extension are as follows: |
157 | | - * - a possible extension is a dot followed by one or more characters not |
| 161 | + * - a possible extension is a dot followed by one or more characters not |
158 | 162 | * in <>\"/:|?.# |
159 | | - * - if we find a possible extension followed by the end of the string or |
| 163 | + * - if we find a possible extension followed by the end of the string or |
160 | 164 | * a #, that's our extension |
161 | 165 | * - if we find a possible extension followed by a ?, that's our extension |
162 | | - * - UNLESS it's exe, dll or cgi, in which case we ignore it and continue |
| 166 | + * - UNLESS it's exe, dll or cgi, in which case we ignore it and continue |
163 | 167 | * searching for another possible extension |
164 | | - * - if we find a possible extension followed by a dot or another illegal |
| 168 | + * - if we find a possible extension followed by a dot or another illegal |
165 | 169 | * character, we ignore it and continue searching |
166 | | - * |
| 170 | + * |
167 | 171 | * @param $url string URL |
168 | 172 | * @return mixed Detected extension (string), or false if none found |
169 | 173 | */ |
— | — | @@ -182,7 +186,7 @@ |
183 | 187 | // End of string, we're done |
184 | 188 | return false; |
185 | 189 | } |
186 | | - |
| 190 | + |
187 | 191 | // We found a dot. Skip past it |
188 | 192 | $pos++; |
189 | 193 | $remainingLength = $urlLength - $pos; |
— | — | @@ -220,12 +224,12 @@ |
221 | 225 | * with %2E not decoded to ".". On such a server, it is possible to detect |
222 | 226 | * whether the script filename has been obscured. |
223 | 227 | * |
224 | | - * The function returns false if the server is not known to have this |
| 228 | + * The function returns false if the server is not known to have this |
225 | 229 | * behaviour. Microsoft IIS in particular is known to decode escaped script |
226 | 230 | * filenames. |
227 | 231 | * |
228 | 232 | * SERVER_SOFTWARE typically contains either a plain string such as "Zeus", |
229 | | - * or a specification in the style of a User-Agent header, such as |
| 233 | + * or a specification in the style of a User-Agent header, such as |
230 | 234 | * "Apache/1.3.34 (Unix) mod_ssl/2.8.25 OpenSSL/0.9.8a PHP/4.4.2" |
231 | 235 | * |
232 | 236 | * @param $serverSoftware |
— | — | @@ -234,8 +238,8 @@ |
235 | 239 | */ |
236 | 240 | public static function haveUndecodedRequestUri( $serverSoftware ) { |
237 | 241 | static $whitelist = array( |
238 | | - 'Apache', |
239 | | - 'Zeus', |
| 242 | + 'Apache', |
| 243 | + 'Zeus', |
240 | 244 | 'LiteSpeed' ); |
241 | 245 | if ( preg_match( '/^(.*?)($|\/| )/', $serverSoftware, $m ) ) { |
242 | 246 | return in_array( $m[1], $whitelist ); |
Index: trunk/phase3/includes/libs/IEContentAnalyzer.php |
— | — | @@ -1,19 +1,19 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * This class simulates Microsoft Internet Explorer's terribly broken and |
| 5 | + * This class simulates Microsoft Internet Explorer's terribly broken and |
6 | 6 | * insecure MIME type detection algorithm. It can be used to check web uploads |
7 | | - * with an apparently safe type, to see if IE will reinterpret them to produce |
| 7 | + * with an apparently safe type, to see if IE will reinterpret them to produce |
8 | 8 | * something dangerous. |
9 | 9 | * |
10 | | - * It is full of bugs and strange design choices should not under any |
11 | | - * circumstances be used to determine a MIME type to present to a user or |
| 10 | + * It is full of bugs and strange design choices should not under any |
| 11 | + * circumstances be used to determine a MIME type to present to a user or |
12 | 12 | * client. (Apple Safari developers, this means you too.) |
13 | 13 | * |
14 | | - * This class is based on a disassembly of IE 5.0, 6.0 and 7.0. Although I have |
15 | | - * attempted to ensure that this code works in exactly the same way as Internet |
16 | | - * Explorer, it does not share any source code, or creative choices such as |
17 | | - * variable names, thus I (Tim Starling) claim copyright on it. |
| 14 | + * This class is based on a disassembly of IE 5.0, 6.0 and 7.0. Although I have |
| 15 | + * attempted to ensure that this code works in exactly the same way as Internet |
| 16 | + * Explorer, it does not share any source code, or creative choices such as |
| 17 | + * variable names, thus I (Tim Starling) claim copyright on it. |
18 | 18 | * |
19 | 19 | * It may be redistributed without restriction. To aid reuse, this class does |
20 | 20 | * not depend on any MediaWiki module. |
— | — | @@ -24,8 +24,8 @@ |
25 | 25 | */ |
26 | 26 | protected $baseTypeTable = array( |
27 | 27 | 'ambiguous' /*1*/ => array( |
28 | | - 'text/plain', |
29 | | - 'application/octet-stream', |
| 28 | + 'text/plain', |
| 29 | + 'application/octet-stream', |
30 | 30 | 'application/x-netcdf', // [sic] |
31 | 31 | ), |
32 | 32 | 'text' /*3*/ => array( |
— | — | @@ -34,8 +34,8 @@ |
35 | 35 | ), |
36 | 36 | 'binary' /*4*/ => array( |
37 | 37 | 'application/pdf', 'audio/x-aiff', 'audio/basic', 'audio/wav', 'image/gif', |
38 | | - 'image/pjpeg', 'image/jpeg', 'image/tiff', 'image/x-png', 'image/png', 'image/bmp', |
39 | | - 'image/x-jg', 'image/x-art', 'image/x-emf', 'image/x-wmf', 'video/avi', |
| 38 | + 'image/pjpeg', 'image/jpeg', 'image/tiff', 'image/x-png', 'image/png', 'image/bmp', |
| 39 | + 'image/x-jg', 'image/x-art', 'image/x-emf', 'image/x-wmf', 'video/avi', |
40 | 40 | 'video/x-msvideo', 'video/mpeg', 'application/x-compressed', |
41 | 41 | 'application/x-zip-compressed', 'application/x-gzip-compressed', 'application/java', |
42 | 42 | 'application/x-msdownload' |
— | — | @@ -293,21 +293,21 @@ |
294 | 294 | '.xsl' => 'text/xml', |
295 | 295 | ); |
296 | 296 | |
297 | | - /** |
298 | | - * IE versions which have been analysed to bring you this class, and for |
299 | | - * which some substantive difference exists. These will appear as keys |
| 297 | + /** |
| 298 | + * IE versions which have been analysed to bring you this class, and for |
| 299 | + * which some substantive difference exists. These will appear as keys |
300 | 300 | * in the return value of getRealMimesFromData(). The names are chosen to sort correctly. |
301 | 301 | */ |
302 | 302 | protected $versions = array( 'ie05', 'ie06', 'ie07', 'ie07.strict', 'ie07.nohtml' ); |
303 | 303 | |
304 | 304 | /** |
305 | | - * Type table with versions expanded |
| 305 | + * Type table with versions expanded |
306 | 306 | */ |
307 | 307 | protected $typeTable = array(); |
308 | 308 | |
309 | 309 | /** constructor */ |
310 | 310 | function __construct() { |
311 | | - // Construct versioned type arrays from the base type array plus additions |
| 311 | + // Construct versioned type arrays from the base type array plus additions |
312 | 312 | $types = $this->baseTypeTable; |
313 | 313 | foreach ( $this->versions as $version ) { |
314 | 314 | if ( isset( $this->addedTypes[$version] ) ) { |
— | — | @@ -320,7 +320,7 @@ |
321 | 321 | } |
322 | 322 | |
323 | 323 | /** |
324 | | - * Get the MIME types from getMimesFromData(), but convert the result from IE's |
| 324 | + * Get the MIME types from getMimesFromData(), but convert the result from IE's |
325 | 325 | * idiosyncratic private types into something other apps will understand. |
326 | 326 | * |
327 | 327 | * @param $fileName String: the file name (unused at present) |
— | — | @@ -338,6 +338,8 @@ |
339 | 339 | /** |
340 | 340 | * Translate a MIME type from IE's idiosyncratic private types into |
341 | 341 | * more commonly understood type strings |
| 342 | + * @param $type |
| 343 | + * @return string |
342 | 344 | */ |
343 | 345 | public function translateMimeType( $type ) { |
344 | 346 | static $table = array( |
— | — | @@ -375,6 +377,11 @@ |
376 | 378 | |
377 | 379 | /** |
378 | 380 | * Get the MIME type for a given named version |
| 381 | + * @param $version |
| 382 | + * @param $fileName |
| 383 | + * @param $chunk |
| 384 | + * @param $proposed |
| 385 | + * @return bool|string |
379 | 386 | */ |
380 | 387 | protected function getMimeTypeForVersion( $version, $fileName, $chunk, $proposed ) { |
381 | 388 | // Strip text after a semicolon |
— | — | @@ -397,8 +404,8 @@ |
398 | 405 | // Truncate chunk at 255 bytes |
399 | 406 | $chunk = substr( $chunk, 0, 255 ); |
400 | 407 | |
401 | | - // IE does the Check*Headers() calls last, and instead does the following image |
402 | | - // type checks by directly looking for the magic numbers. What I do here should |
| 408 | + // IE does the Check*Headers() calls last, and instead does the following image |
| 409 | + // type checks by directly looking for the magic numbers. What I do here should |
403 | 410 | // have the same effect since the magic number checks are identical in both cases. |
404 | 411 | $result = $this->sampleData( $version, $chunk ); |
405 | 412 | $sampleFound = $result['found']; |
— | — | @@ -413,7 +420,7 @@ |
414 | 421 | return 'image/gif'; |
415 | 422 | } |
416 | 423 | if ( ( $proposed == 'image/pjpeg' || $proposed == 'image/jpeg' ) |
417 | | - && $binaryType == 'image/pjpeg' ) |
| 424 | + && $binaryType == 'image/pjpeg' ) |
418 | 425 | { |
419 | 426 | return $proposed; |
420 | 427 | } |
— | — | @@ -430,7 +437,7 @@ |
431 | 438 | return 'application/x-cdf'; |
432 | 439 | } |
433 | 440 | |
434 | | - // RSS and Atom were added in IE 7 so they won't be in $sampleFound for |
| 441 | + // RSS and Atom were added in IE 7 so they won't be in $sampleFound for |
435 | 442 | // previous versions |
436 | 443 | if ( isset( $sampleFound['rss'] ) ) { |
437 | 444 | return 'application/rss+xml'; |
— | — | @@ -483,8 +490,8 @@ |
484 | 491 | |
485 | 492 | // Freaky heuristics to determine if the data is text or binary |
486 | 493 | // The heuristic is of course broken for non-ASCII text |
487 | | - if ( $counters['ctrl'] != 0 && ( $counters['ff'] + $counters['low'] ) |
488 | | - < ( $counters['ctrl'] + $counters['high'] ) * 16 ) |
| 494 | + if ( $counters['ctrl'] != 0 && ( $counters['ff'] + $counters['low'] ) |
| 495 | + < ( $counters['ctrl'] + $counters['high'] ) * 16 ) |
489 | 496 | { |
490 | 497 | $kindOfBinary = true; |
491 | 498 | $type = $binaryType ? $binaryType : $textType; |
— | — | @@ -529,8 +536,8 @@ |
530 | 537 | return $this->registry[$ext]; |
531 | 538 | } |
532 | 539 | |
533 | | - // TODO: If the extension has an application registered to it, IE will return |
534 | | - // application/octet-stream. We'll skip that, so we could erroneously |
| 540 | + // TODO: If the extension has an application registered to it, IE will return |
| 541 | + // application/octet-stream. We'll skip that, so we could erroneously |
535 | 542 | // return text/plain or application/x-netcdf where application/octet-stream |
536 | 543 | // would be correct. |
537 | 544 | |
— | — | @@ -540,6 +547,9 @@ |
541 | 548 | /** |
542 | 549 | * Check for text headers at the start of the chunk |
543 | 550 | * Confirmed same in 5 and 7. |
| 551 | + * @param $version |
| 552 | + * @param $chunk |
| 553 | + * @return bool|string |
544 | 554 | */ |
545 | 555 | private function checkTextHeaders( $version, $chunk ) { |
546 | 556 | $chunk2 = substr( $chunk, 0, 2 ); |
— | — | @@ -563,6 +573,9 @@ |
564 | 574 | /** |
565 | 575 | * Check for binary headers at the start of the chunk |
566 | 576 | * Confirmed same in 5 and 7. |
| 577 | + * @param $version |
| 578 | + * @param $chunk |
| 579 | + * @return bool|string |
567 | 580 | */ |
568 | 581 | private function checkBinaryHeaders( $version, $chunk ) { |
569 | 582 | $chunk2 = substr( $chunk, 0, 2 ); |
— | — | @@ -578,13 +591,13 @@ |
579 | 592 | return 'image/pjpeg'; // actually plain JPEG but this is what IE returns |
580 | 593 | } |
581 | 594 | |
582 | | - if ( $chunk2 == 'BM' |
| 595 | + if ( $chunk2 == 'BM' |
583 | 596 | && substr( $chunk, 6, 2 ) == "\000\000" |
584 | 597 | && substr( $chunk, 8, 2 ) == "\000\000" ) |
585 | 598 | { |
586 | 599 | return 'image/bmp'; // another non-standard MIME |
587 | 600 | } |
588 | | - if ( $chunk4 == 'RIFF' |
| 601 | + if ( $chunk4 == 'RIFF' |
589 | 602 | && substr( $chunk, 8, 4 ) == 'WAVE' ) |
590 | 603 | { |
591 | 604 | return 'audio/wav'; |
— | — | @@ -661,6 +674,9 @@ |
662 | 675 | /** |
663 | 676 | * Do heuristic checks on the bulk of the data sample. |
664 | 677 | * Search for HTML tags. |
| 678 | + * @param $version |
| 679 | + * @param $chunk |
| 680 | + * @return array |
665 | 681 | */ |
666 | 682 | protected function sampleData( $version, $chunk ) { |
667 | 683 | $found = array(); |
— | — | @@ -774,7 +790,7 @@ |
775 | 791 | } |
776 | 792 | |
777 | 793 | if ( !strncasecmp( $remainder, $rdfPurl, strlen( $rdfPurl ) ) ) { |
778 | | - if ( isset( $found['rdf-tag'] ) |
| 794 | + if ( isset( $found['rdf-tag'] ) |
779 | 795 | && isset( $found['rdf-url'] ) ) // [sic] |
780 | 796 | { |
781 | 797 | break; |
— | — | @@ -808,6 +824,11 @@ |
809 | 825 | return array( 'found' => $found, 'counters' => $counters ); |
810 | 826 | } |
811 | 827 | |
| 828 | + /** |
| 829 | + * @param $version |
| 830 | + * @param $type |
| 831 | + * @return int|string |
| 832 | + */ |
812 | 833 | protected function getDataFormat( $version, $type ) { |
813 | 834 | $types = $this->typeTable[$version]; |
814 | 835 | if ( $type == '(null)' || strval( $type ) === '' ) { |