r100783 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100782‎ | r100783 | r100784 >
Date:04:15, 26 October 2011
Author:reedy
Status:ok
Tags:
Comment:
More documentation!
Modified paths:
  • /trunk/phase3/includes/diff/DairikiDiff.php (modified) (history)
  • /trunk/phase3/includes/job/DoubleRedirectJob.php (modified) (history)
  • /trunk/phase3/includes/job/JobQueue.php (modified) (history)
  • /trunk/phase3/includes/job/UploadFromUrlJob.php (modified) (history)
  • /trunk/phase3/includes/json/FormatJson.php (modified) (history)
  • /trunk/phase3/includes/libs/CSSJanus.php (modified) (history)
  • /trunk/phase3/includes/libs/CSSMin.php (modified) (history)
  • /trunk/phase3/includes/libs/IEContentAnalyzer.php (modified) (history)
  • /trunk/phase3/includes/libs/IEUrlExtension.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/HttpTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/HttpTest.php
@@ -48,7 +48,7 @@
4949
5050 /**
5151 * Test Http::isValidURI()
52 - * @bug 27854 : Http::isValidURI is to lax
 52+ * @bug 27854 : Http::isValidURI is too lax
5353 * @dataProvider provideURI
5454 */
5555 function testIsValidUri( $expect, $URI, $message = '' ) {
@@ -76,7 +76,7 @@
7777 array( false, '\\host\directory', 'CIFS share' ),
7878 array( false, 'gopher://host/dir', 'Reject gopher scheme' ),
7979 array( false, 'telnet://host', 'Reject telnet scheme' ),
80 -
 80+
8181 # :\/\/ - double slashes
8282 array( false, 'http//example.org', 'Reject missing colon in protocol' ),
8383 array( false, 'http:/example.org', 'Reject missing slash in protocol' ),
Index: trunk/phase3/includes/diff/DairikiDiff.php
@@ -24,10 +24,16 @@
2525 trigger_error( 'pure virtual', E_USER_ERROR );
2626 }
2727
 28+ /**
 29+ * @return int
 30+ */
2831 function norig() {
2932 return $this->orig ? sizeof( $this->orig ) : 0;
3033 }
3134
 35+ /**
 36+ * @return int
 37+ */
3238 function nclosing() {
3339 return $this->closing ? sizeof( $this->closing ) : 0;
3440 }
@@ -49,6 +55,9 @@
5056 $this->closing = $closing;
5157 }
5258
 59+ /**
 60+ * @return _DiffOp_Copy
 61+ */
5362 function reverse() {
5463 return new _DiffOp_Copy( $this->closing, $this->orig );
5564 }
@@ -67,6 +76,9 @@
6877 $this->closing = false;
6978 }
7079
 80+ /**
 81+ * @return _DiffOp_Add
 82+ */
7183 function reverse() {
7284 return new _DiffOp_Add( $this->orig );
7385 }
@@ -85,6 +97,9 @@
8698 $this->orig = false;
8799 }
88100
 101+ /**
 102+ * @return _DiffOp_Delete
 103+ */
89104 function reverse() {
90105 return new _DiffOp_Delete( $this->closing );
91106 }
@@ -103,6 +118,9 @@
104119 $this->closing = $closing;
105120 }
106121
 122+ /**
 123+ * @return _DiffOp_Change
 124+ */
107125 function reverse() {
108126 return new _DiffOp_Change( $this->closing, $this->orig );
109127 }
@@ -145,6 +163,11 @@
146164
147165 protected $lcs = 0;
148166
 167+ /**
 168+ * @param $from_lines
 169+ * @param $to_lines
 170+ * @return array
 171+ */
149172 function diff ( $from_lines, $to_lines ) {
150173 wfProfileIn( __METHOD__ );
151174
@@ -199,6 +222,10 @@
200223 return $edits;
201224 }
202225
 226+ /**
 227+ * @param $from_lines
 228+ * @param $to_lines
 229+ */
203230 function diff_local ( $from_lines, $to_lines ) {
204231 global $wgExternalDiffEngine;
205232 wfProfileIn( __METHOD__ );
@@ -268,6 +295,8 @@
269296
270297 /**
271298 * Returns the whole line if it's small enough, or the MD5 hash otherwise
 299+ * @param $line string
 300+ * @return string
272301 */
273302 function _line_hash( $line ) {
274303 if ( strlen( $line ) > self::MAX_XREF_LENGTH ) {
@@ -293,6 +322,12 @@
294323 * of the two files do not match, and likewise that the last lines do not
295324 * match. The caller must trim matching lines from the beginning and end
296325 * 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
297332 */
298333 function _diag( $xoff, $xlim, $yoff, $ylim, $nchunks ) {
299334 $flip = false;
@@ -373,6 +408,10 @@
374409 return array( $this->lcs, $seps );
375410 }
376411
 412+ /**
 413+ * @param $ypos
 414+ * @return int
 415+ */
377416 function _lcs_pos( $ypos ) {
378417 $end = $this->lcs;
379418 if ( $end == 0 || $ypos > $this->seq[$end] ) {
@@ -410,6 +449,10 @@
411450 *
412451 * Note that XLIM, YLIM are exclusive bounds.
413452 * All line numbers are origin-0 and discarded lines are not counted.
 453+ * @param $xoff
 454+ * @param $xlim
 455+ * @param $yoff
 456+ * @param $ylim
414457 */
415458 function _compareseq ( $xoff, $xlim, $yoff, $ylim ) {
416459 // Slide down the bottom initial diagonal.
@@ -703,6 +746,8 @@
704747 * Check a Diff for validity.
705748 *
706749 * This is here only for debugging purposes.
 750+ * @param $from_lines
 751+ * @param $to_lines
707752 */
708753 function _check( $from_lines, $to_lines ) {
709754 wfProfileIn( __METHOD__ );
@@ -886,6 +931,13 @@
887932 return $end;
888933 }
889934
 935+ /**
 936+ * @param $xbeg
 937+ * @param $xlen
 938+ * @param $ybeg
 939+ * @param $ylen
 940+ * @param $edits
 941+ */
890942 function _block( $xbeg, $xlen, $ybeg, $ylen, &$edits ) {
891943 wfProfileIn( __METHOD__ );
892944 $this->_start_block( $this->_block_header( $xbeg, $xlen, $ybeg, $ylen ) );
@@ -910,12 +962,22 @@
911963 ob_start();
912964 }
913965
 966+ /**
 967+ * @return string
 968+ */
914969 function _end_diff() {
915970 $val = ob_get_contents();
916971 ob_end_clean();
917972 return $val;
918973 }
919974
 975+ /**
 976+ * @param $xbeg
 977+ * @param $xlen
 978+ * @param $ybeg
 979+ * @param $ylen
 980+ * @return string
 981+ */
920982 function _block_header( $xbeg, $xlen, $ybeg, $ylen ) {
921983 if ( $xlen > 1 ) {
922984 $xbeg .= ',' . ( $xbeg + $xlen - 1 );
@@ -934,23 +996,41 @@
935997 function _end_block() {
936998 }
937999
 1000+ /**
 1001+ * @param $lines
 1002+ * @param $prefix string
 1003+ */
9381004 function _lines( $lines, $prefix = ' ' ) {
9391005 foreach ( $lines as $line ) {
9401006 echo "$prefix $line\n";
9411007 }
9421008 }
9431009
 1010+ /**
 1011+ * @param $lines
 1012+ */
9441013 function _context( $lines ) {
9451014 $this->_lines( $lines );
9461015 }
9471016
 1017+ /**
 1018+ * @param $lines
 1019+ */
9481020 function _added( $lines ) {
9491021 $this->_lines( $lines, '>' );
9501022 }
 1023+
 1024+ /**
 1025+ * @param $lines
 1026+ */
9511027 function _deleted( $lines ) {
9521028 $this->_lines( $lines, '<' );
9531029 }
9541030
 1031+ /**
 1032+ * @param $orig
 1033+ * @param $closing
 1034+ */
9551035 function _changed( $orig, $closing ) {
9561036 $this->_deleted( $orig );
9571037 echo "---\n";
@@ -966,16 +1046,36 @@
9671047 var $leading_context_lines = 2;
9681048 var $trailing_context_lines = 2;
9691049
 1050+ /**
 1051+ * @param $lines
 1052+ */
9701053 function _added( $lines ) {
9711054 $this->_lines( $lines, '+' );
9721055 }
 1056+
 1057+ /**
 1058+ * @param $lines
 1059+ */
9731060 function _deleted( $lines ) {
9741061 $this->_lines( $lines, '-' );
9751062 }
 1063+
 1064+ /**
 1065+ * @param $orig
 1066+ * @param $closing
 1067+ */
9761068 function _changed( $orig, $closing ) {
9771069 $this->_deleted( $orig );
9781070 $this->_added( $closing );
9791071 }
 1072+
 1073+ /**
 1074+ * @param $xbeg
 1075+ * @param $xlen
 1076+ * @param $ybeg
 1077+ * @param $ylen
 1078+ * @return string
 1079+ */
9801080 function _block_header( $xbeg, $xlen, $ybeg, $ylen ) {
9811081 return "@@ -$xbeg,$xlen +$ybeg,$ylen @@";
9821082 }
@@ -986,6 +1086,11 @@
9871087 * @ingroup DifferenceEngine
9881088 */
9891089 class ArrayDiffFormatter extends DiffFormatter {
 1090+
 1091+ /**
 1092+ * @param $diff
 1093+ * @return array
 1094+ */
9901095 function format( $diff ) {
9911096 $oldline = 1;
9921097 $newline = 1;
@@ -1049,6 +1154,9 @@
10501155 $this->_tag = '';
10511156 }
10521157
 1158+ /**
 1159+ * @param $new_tag
 1160+ */
10531161 function _flushGroup( $new_tag ) {
10541162 if ( $this->_group !== '' ) {
10551163 if ( $this->_tag == 'ins' ) {
@@ -1065,6 +1173,9 @@
10661174 $this->_tag = $new_tag;
10671175 }
10681176
 1177+ /**
 1178+ * @param $new_tag
 1179+ */
10691180 function _flushLine( $new_tag ) {
10701181 $this->_flushGroup( $new_tag );
10711182 if ( $this->_line != '' ) {
@@ -1076,6 +1187,10 @@
10771188 $this->_line = '';
10781189 }
10791190
 1191+ /**
 1192+ * @param $words
 1193+ * @param $tag string
 1194+ */
10801195 function addWords ( $words, $tag = '' ) {
10811196 if ( $tag != $this->_tag ) {
10821197 $this->_flushGroup( $tag );
@@ -1095,6 +1210,9 @@
10961211 }
10971212 }
10981213
 1214+ /**
 1215+ * @return array
 1216+ */
10991217 function getLines() {
11001218 $this->_flushLine( '~done' );
11011219 return $this->_lines;
@@ -1109,6 +1227,10 @@
11101228 class WordLevelDiff extends MappedDiff {
11111229 const MAX_LINE_LENGTH = 10000;
11121230
 1231+ /**
 1232+ * @param $orig_lines
 1233+ * @param $closing_lines
 1234+ */
11131235 function __construct ( $orig_lines, $closing_lines ) {
11141236 wfProfileIn( __METHOD__ );
11151237
@@ -1120,6 +1242,10 @@
11211243 wfProfileOut( __METHOD__ );
11221244 }
11231245
 1246+ /**
 1247+ * @param $lines
 1248+ * @return array
 1249+ */
11241250 function _split( $lines ) {
11251251 wfProfileIn( __METHOD__ );
11261252
@@ -1152,6 +1278,9 @@
11531279 return array( $words, $stripped );
11541280 }
11551281
 1282+ /**
 1283+ * @return array
 1284+ */
11561285 function orig() {
11571286 wfProfileIn( __METHOD__ );
11581287 $orig = new _HWLDF_WordAccumulator;
@@ -1168,6 +1297,9 @@
11691298 return $lines;
11701299 }
11711300
 1301+ /**
 1302+ * @return array
 1303+ */
11721304 function closing() {
11731305 wfProfileIn( __METHOD__ );
11741306 $closing = new _HWLDF_WordAccumulator;
@@ -1197,6 +1329,11 @@
11981330 $this->trailing_context_lines = 2;
11991331 }
12001332
 1333+ /**
 1334+ * @static
 1335+ * @param $msg
 1336+ * @return mixed
 1337+ */
12011338 public static function escapeWhiteSpace( $msg ) {
12021339 $msg = preg_replace( '/^ /m', '&#160; ', $msg );
12031340 $msg = preg_replace( '/ $/m', ' &#160;', $msg );
@@ -1204,12 +1341,22 @@
12051342 return $msg;
12061343 }
12071344
 1345+ /**
 1346+ * @param $xbeg
 1347+ * @param $xlen
 1348+ * @param $ybeg
 1349+ * @param $ylen
 1350+ * @return string
 1351+ */
12081352 function _block_header( $xbeg, $xlen, $ybeg, $ylen ) {
12091353 $r = '<tr><td colspan="2" class="diff-lineno"><!--LINE ' . $xbeg . "--></td>\n" .
12101354 '<td colspan="2" class="diff-lineno"><!--LINE ' . $ybeg . "--></td></tr>\n";
12111355 return $r;
12121356 }
12131357
 1358+ /**
 1359+ * @param $header
 1360+ */
12141361 function _start_block( $header ) {
12151362 echo $header;
12161363 }
@@ -1220,21 +1367,39 @@
12211368 function _lines( $lines, $prefix = ' ', $color = 'white' ) {
12221369 }
12231370
1224 - # HTML-escape parameter before calling this
 1371+ /**
 1372+ * HTML-escape parameter before calling this
 1373+ * @param $line
 1374+ * @return string
 1375+ */
12251376 function addedLine( $line ) {
12261377 return $this->wrapLine( '+', 'diff-addedline', $line );
12271378 }
12281379
1229 - # HTML-escape parameter before calling this
 1380+ /**
 1381+ * HTML-escape parameter before calling this
 1382+ * @param $line
 1383+ * @return string
 1384+ */
12301385 function deletedLine( $line ) {
12311386 return $this->wrapLine( '−', 'diff-deletedline', $line );
12321387 }
12331388
1234 - # HTML-escape parameter before calling this
 1389+ /**
 1390+ * HTML-escape parameter before calling this
 1391+ * @param $line
 1392+ * @return string
 1393+ */
12351394 function contextLine( $line ) {
12361395 return $this->wrapLine( '&#160;', 'diff-context', $line );
12371396 }
12381397
 1398+ /**
 1399+ * @param $marker
 1400+ * @param $class
 1401+ * @param $line
 1402+ * @return string
 1403+ */
12391404 private function wrapLine( $marker, $class, $line ) {
12401405 if ( $line !== '' ) {
12411406 // The <div> wrapper is needed for 'overflow: auto' style to scroll properly
@@ -1243,10 +1408,16 @@
12441409 return "<td class='diff-marker'>$marker</td><td class='$class'>$line</td>";
12451410 }
12461411
 1412+ /**
 1413+ * @return string
 1414+ */
12471415 function emptyLine() {
12481416 return '<td colspan="2">&#160;</td>';
12491417 }
12501418
 1419+ /**
 1420+ * @param $lines array
 1421+ */
12511422 function _added( $lines ) {
12521423 foreach ( $lines as $line ) {
12531424 echo '<tr>' . $this->emptyLine() .
@@ -1255,6 +1426,9 @@
12561427 }
12571428 }
12581429
 1430+ /**
 1431+ * @param $lines
 1432+ */
12591433 function _deleted( $lines ) {
12601434 foreach ( $lines as $line ) {
12611435 echo '<tr>' . $this->deletedLine( '<del class="diffchange">' .
@@ -1263,6 +1437,9 @@
12641438 }
12651439 }
12661440
 1441+ /**
 1442+ * @param $lines
 1443+ */
12671444 function _context( $lines ) {
12681445 foreach ( $lines as $line ) {
12691446 echo '<tr>' .
@@ -1271,6 +1448,10 @@
12721449 }
12731450 }
12741451
 1452+ /**
 1453+ * @param $orig
 1454+ * @param $closing
 1455+ */
12751456 function _changed( $orig, $closing ) {
12761457 wfProfileIn( __METHOD__ );
12771458
Index: trunk/phase3/includes/json/FormatJson.php
@@ -11,11 +11,14 @@
1212
1313 require_once dirname( __FILE__ ) . '/Services_JSON.php';
1414
 15+/**
 16+ * JSON formatter wrapper class
 17+ */
1518 class FormatJson {
16 -
 19+
1720 /**
1821 * Returns the JSON representation of a value.
19 - *
 22+ *
2023 * @param $value Mixed: the value being encoded. Can be any type except a resource.
2124 * @param $isHtml Boolean
2225 *
@@ -23,7 +26,7 @@
2427 * map to a parameter labeled "pretty-print output with indents and
2528 * newlines" in Services_JSON::encode(), which has no string relation
2629 * to HTML output.
27 - *
 30+ *
2831 * @return string
2932 */
3033 public static function encode( $value, $isHtml = false ) {
@@ -40,10 +43,10 @@
4144
4245 /**
4346 * Decodes a JSON string.
44 - *
 47+ *
4548 * @param $value String: the json string being decoded.
4649 * @param $assoc Boolean: when true, returned objects will be converted into associative arrays.
47 - *
 50+ *
4851 * @return Mixed: the value encoded in json in appropriate PHP type.
4952 * Values true, false and null (case-insensitive) are returned as true, false
5053 * and &null; respectively. &null; is returned if the json cannot be
@@ -61,5 +64,5 @@
6265 return json_decode( $value, $assoc );
6366 }
6467 }
65 -
 68+
6669 }
Index: trunk/phase3/includes/job/JobQueue.php
@@ -213,6 +213,10 @@
214214 throw new MWException( "Invalid job command `{$command}`" );
215215 }
216216
 217+ /**
 218+ * @param $params
 219+ * @return string
 220+ */
217221 static function makeBlob( $params ) {
218222 if ( $params !== false ) {
219223 return serialize( $params );
@@ -221,6 +225,10 @@
222226 }
223227 }
224228
 229+ /**
 230+ * @param $blob
 231+ * @return bool|mixed
 232+ */
225233 static function extractBlob( $blob ) {
226234 if ( (string)$blob !== '' ) {
227235 return unserialize( $blob );
@@ -323,13 +331,16 @@
324332 if ( $this->removeDuplicates ) {
325333 $res = $dbw->select( 'job', array( '1' ), $fields, __METHOD__ );
326334 if ( $dbw->numRows( $res ) ) {
327 - return;
 335+ return true;
328336 }
329337 }
330338 wfIncrStats( 'job-insert' );
331339 return $dbw->insert( 'job', $fields, __METHOD__ );
332340 }
333341
 342+ /**
 343+ * @return array
 344+ */
334345 protected function insertFields() {
335346 $dbw = wfGetDB( DB_MASTER );
336347 return array(
@@ -362,6 +373,9 @@
363374 }
364375 }
365376
 377+ /**
 378+ * @return string
 379+ */
366380 function toString() {
367381 $paramString = '';
368382 if ( $this->params ) {
Index: trunk/phase3/includes/job/UploadFromUrlJob.php
@@ -64,7 +64,7 @@
6565
6666 # Stash the upload
6767 $key = $this->upload->stashFile();
68 -
 68+
6969 if ( $this->params['leaveMessage'] ) {
7070 $this->user->leaveUserMessage(
7171 wfMsg( 'upload-warning-subj' ),
@@ -73,7 +73,7 @@
7474 $this->params['url'] )
7575 );
7676 } else {
77 - wfSetupSession( $this->params['sessionId'] );
 77+ wfSetupSession( $this->params['sessionId'] );
7878 $this->storeResultInSession( 'Warning',
7979 'warnings', $warnings );
8080 session_write_close();
@@ -151,6 +151,10 @@
152152 $$session['result'] = 'Queued';
153153 }
154154
 155+ /**
 156+ * @param $key
 157+ * @return mixed
 158+ */
155159 public static function &getSessionData( $key ) {
156160 if ( !isset( $_SESSION[self::SESSION_KEYNAME][$key] ) ) {
157161 $_SESSION[self::SESSION_KEYNAME][$key] = array();
Index: trunk/phase3/includes/job/DoubleRedirectJob.php
@@ -19,7 +19,7 @@
2020 */
2121 static $user;
2222
23 - /**
 23+ /**
2424 * Insert jobs into the job queue to fix redirects to the given title
2525 * @param $reason String: the reason for the fix, see message double-redirect-fixed-<reason>
2626 * @param $redirTitle Title: the title which has changed, redirects pointing to this title are fixed
@@ -28,10 +28,10 @@
2929 public static function fixRedirects( $reason, $redirTitle, $destTitle = false ) {
3030 # Need to use the master to get the redirect table updated in the same transaction
3131 $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(
3636 'page_id = rd_from',
3737 'rd_namespace' => $redirTitle->getNamespace(),
3838 'rd_title' => $redirTitle->getDBkey()
@@ -46,7 +46,7 @@
4747 continue;
4848 }
4949
50 - $jobs[] = new self( $title, array(
 50+ $jobs[] = new self( $title, array(
5151 'reason' => $reason,
5252 'redirTitle' => $redirTitle->getPrefixedDBkey() ) );
5353 # Avoid excessive memory usage
@@ -65,6 +65,9 @@
6666 $this->destTitleText = !empty( $params['destTitle'] ) ? $params['destTitle'] : '';
6767 }
6868
 69+ /**
 70+ * @return bool
 71+ */
6972 function run() {
7073 if ( !$this->redirTitle ) {
7174 $this->setLastError( 'Invalid title' );
@@ -103,13 +106,13 @@
104107 }
105108
106109 # Preserve fragment (bug 14904)
107 - $newTitle = Title::makeTitle( $newTitle->getNamespace(), $newTitle->getDBkey(),
 110+ $newTitle = Title::makeTitle( $newTitle->getNamespace(), $newTitle->getDBkey(),
108111 $currentDest->getFragment() );
109112
110113 # Fix the text
111114 # Remember that redirect pages can have categories, templates, etc.,
112115 # so the regex has to be fairly general
113 - $newText = preg_replace( '/ \[ \[ [^\]]* \] \] /x',
 116+ $newText = preg_replace( '/ \[ \[ [^\]]* \] \] /x',
114117 '[[' . $newTitle->getFullText() . ']]',
115118 $text, 1 );
116119
@@ -123,7 +126,7 @@
124127 $oldUser = $wgUser;
125128 $wgUser = $this->getUser();
126129 $article = new Article( $this->title );
127 - $reason = wfMsgForContent( 'double-redirect-fixed-' . $this->reason,
 130+ $reason = wfMsgForContent( 'double-redirect-fixed-' . $this->reason,
128131 $this->redirTitle->getPrefixedText(), $newTitle->getPrefixedText() );
129132 $article->doEdit( $newText, $reason, EDIT_UPDATE | EDIT_SUPPRESS_RC );
130133 $wgUser = $oldUser;
@@ -152,10 +155,10 @@
153156 }
154157 $seenTitles[$titleText] = true;
155158
156 - $row = $dbw->selectRow(
 159+ $row = $dbw->selectRow(
157160 array( 'redirect', 'page' ),
158161 array( 'rd_namespace', 'rd_title' ),
159 - array(
 162+ array(
160163 'rd_from=page_id',
161164 'page_namespace' => $title->getNamespace(),
162165 'page_title' => $title->getDBkey()
@@ -172,6 +175,7 @@
173176
174177 /**
175178 * Get a user object for doing edits, from a request-lifetime cache
 179+ * @return User
176180 */
177181 function getUser() {
178182 if ( !self::$user ) {
Index: trunk/phase3/includes/libs/CSSJanus.php
@@ -175,6 +175,8 @@
176176 *
177177 * See http://code.google.com/p/cssjanus/issues/detail?id=15 and
178178 * TODO: URL
 179+ * @param $css string
 180+ * @return string
179181 */
180182 private static function fixDirection( $css ) {
181183 $css = preg_replace( self::$patterns['direction_ltr'],
@@ -187,6 +189,8 @@
188190
189191 /**
190192 * Replace 'ltr' with 'rtl' and vice versa in background URLs
 193+ * @param $css string
 194+ * @return string
191195 */
192196 private static function fixLtrRtlInURL( $css ) {
193197 $css = preg_replace( self::$patterns['ltr_in_url'], self::$patterns['tmpToken'], $css );
@@ -198,6 +202,8 @@
199203
200204 /**
201205 * Replace 'left' with 'right' and vice versa in background URLs
 206+ * @param $css string
 207+ * @return string
202208 */
203209 private static function fixLeftRightInURL( $css ) {
204210 $css = preg_replace( self::$patterns['left_in_url'], self::$patterns['tmpToken'], $css );
@@ -209,6 +215,8 @@
210216
211217 /**
212218 * Flip rules like left: , padding-right: , etc.
 219+ * @param $css string
 220+ * @return string
213221 */
214222 private static function fixLeftAndRight( $css ) {
215223 $css = preg_replace( self::$patterns['left'], self::$patterns['tmpToken'], $css );
@@ -220,6 +228,8 @@
221229
222230 /**
223231 * Flip East and West in rules like cursor: nw-resize;
 232+ * @param $css string
 233+ * @return string
224234 */
225235 private static function fixCursorProperties( $css ) {
226236 $css = preg_replace( self::$patterns['cursor_east'],
@@ -239,6 +249,8 @@
240250 * and four-part color rules with multiple whitespace characters between
241251 * colors are not recognized.
242252 * See http://code.google.com/p/cssjanus/issues/detail?id=16
 253+ * @param $css string
 254+ * @return string
243255 */
244256 private static function fixFourPartNotation( $css ) {
245257 $css = preg_replace( self::$patterns['four_notation_quantity'], '$1$2$7$4$5$6$3', $css );
@@ -249,6 +261,8 @@
250262
251263 /**
252264 * Flip horizontal background percentages.
 265+ * @param $css string
 266+ * @return string
253267 */
254268 private static function fixBackgroundPosition( $css ) {
255269 $css = preg_replace_callback( self::$patterns['bg_horizontal_percentage'],
@@ -261,6 +275,8 @@
262276
263277 /**
264278 * Callback for calculateNewBackgroundPosition()
 279+ * @param $matches array
 280+ * @return string
265281 */
266282 private static function calculateNewBackgroundPosition( $matches ) {
267283 return $matches[1] . ( 100 - $matches[2] ) . $matches[3];
@@ -297,6 +313,10 @@
298314 return preg_replace_callback( $this->regex, array( $this, 'tokenizeCallback' ), $str );
299315 }
300316
 317+ /**
 318+ * @param $matches array
 319+ * @return string
 320+ */
301321 private function tokenizeCallback( $matches ) {
302322 $this->originals[] = $matches[0];
303323 return $this->token;
@@ -316,6 +336,10 @@
317337 array( $this, 'detokenizeCallback' ), $str );
318338 }
319339
 340+ /**
 341+ * @param $matches
 342+ * @return mixed
 343+ */
320344 private function detokenizeCallback( $matches ) {
321345 $retval = current( $this->originals );
322346 next( $this->originals );
Index: trunk/phase3/includes/libs/CSSMin.php
@@ -79,6 +79,10 @@
8080 return $files;
8181 }
8282
 83+ /**
 84+ * @param $file string
 85+ * @return bool|string
 86+ */
8387 protected static function getMimeType( $file ) {
8488 $realpath = realpath( $file );
8589 // 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 @@
22 <?php
33
44 /**
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.
88 *
99 * This can be a problem, especially when non-HTML content is sent by MediaWiki,
1010 * and Internet Explorer interprets it as HTML, exposing an XSS vulnerability.
1111 *
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
1313 * 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".
1616 *
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
1818 * situation.
1919 *
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
2121 * 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
2323 * to use to guess parts of the URL.
2424 */
2525 class IEUrlExtension {
2626 /**
2727 * 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,
3030 * false otherwise. The relevant $_SERVER elements are:
3131 *
3232 * - SERVER_SOFTWARE
@@ -37,6 +37,7 @@
3838 *
3939 * @param $vars A subset of $_SERVER.
4040 * @param $extWhitelist Extensions which are allowed, assumed harmless.
 41+ * @return bool
4142 */
4243 public static function areServerVarsBad( $vars, $extWhitelist = array() ) {
4344 // Check QUERY_STRING or REQUEST_URI
@@ -55,7 +56,7 @@
5657 return true;
5758 }
5859
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
6061 // to be on the safe side.
6162 if ( isset( $vars['PATH_INFO'] )
6263 && self::isUrlExtensionBad( $vars['PATH_INFO'], $extWhitelist ) )
@@ -71,7 +72,7 @@
7273 * Given a right-hand portion of a URL, determine whether IE would detect
7374 * a potentially harmful file extension.
7475 *
75 - * @param $urlPart The right-hand portion of a URL
 76+ * @param $urlPart string The right-hand portion of a URL
7677 * @param $extWhitelist An array of file extensions which may occur in this
7778 * URL, and which should be allowed.
7879 * @return bool
@@ -97,10 +98,10 @@
9899 }
99100
100101 if ( !preg_match( '/^[a-zA-Z0-9_-]+$/', $extension ) ) {
101 - // Non-alphanumeric extension, unlikely to be registered.
 102+ // Non-alphanumeric extension, unlikely to be registered.
102103 //
103104 // 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
105106 // extensions with ampersands and percent signs, since that reduces
106107 // the number of false positives substantially.
107108 return false;
@@ -111,8 +112,11 @@
112113 }
113114
114115 /**
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
116117 * same GET parameters, or false if it can't figure one out.
 118+ * @param $url
 119+ * @param $extWhitelist array
 120+ * @return bool|string
117121 */
118122 public static function fixUrlForIE6( $url, $extWhitelist = array() ) {
119123 $questionPos = strpos( $url, '?' );
@@ -127,7 +131,7 @@
128132 $query = substr( $url, $questionPos + 1 );
129133 }
130134
131 - // Multiple question marks cause problems. Encode the second and
 135+ // Multiple question marks cause problems. Encode the second and
132136 // subsequent question mark.
133137 $query = str_replace( '?', '%3E', $query );
134138 // Append an invalid path character so that IE6 won't see the end of the
@@ -153,16 +157,16 @@
154158 * insecure.
155159 *
156160 * 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
158162 * 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
160164 * a #, that's our extension
161165 * - 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
163167 * 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
165169 * character, we ignore it and continue searching
166 - *
 170+ *
167171 * @param $url string URL
168172 * @return mixed Detected extension (string), or false if none found
169173 */
@@ -182,7 +186,7 @@
183187 // End of string, we're done
184188 return false;
185189 }
186 -
 190+
187191 // We found a dot. Skip past it
188192 $pos++;
189193 $remainingLength = $urlLength - $pos;
@@ -220,12 +224,12 @@
221225 * with %2E not decoded to ".". On such a server, it is possible to detect
222226 * whether the script filename has been obscured.
223227 *
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
225229 * behaviour. Microsoft IIS in particular is known to decode escaped script
226230 * filenames.
227231 *
228232 * 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
230234 * "Apache/1.3.34 (Unix) mod_ssl/2.8.25 OpenSSL/0.9.8a PHP/4.4.2"
231235 *
232236 * @param $serverSoftware
@@ -234,8 +238,8 @@
235239 */
236240 public static function haveUndecodedRequestUri( $serverSoftware ) {
237241 static $whitelist = array(
238 - 'Apache',
239 - 'Zeus',
 242+ 'Apache',
 243+ 'Zeus',
240244 'LiteSpeed' );
241245 if ( preg_match( '/^(.*?)($|\/| )/', $serverSoftware, $m ) ) {
242246 return in_array( $m[1], $whitelist );
Index: trunk/phase3/includes/libs/IEContentAnalyzer.php
@@ -1,19 +1,19 @@
22 <?php
33
44 /**
5 - * This class simulates Microsoft Internet Explorer's terribly broken and
 5+ * This class simulates Microsoft Internet Explorer's terribly broken and
66 * 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
88 * something dangerous.
99 *
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
1212 * client. (Apple Safari developers, this means you too.)
1313 *
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.
1818 *
1919 * It may be redistributed without restriction. To aid reuse, this class does
2020 * not depend on any MediaWiki module.
@@ -24,8 +24,8 @@
2525 */
2626 protected $baseTypeTable = array(
2727 'ambiguous' /*1*/ => array(
28 - 'text/plain',
29 - 'application/octet-stream',
 28+ 'text/plain',
 29+ 'application/octet-stream',
3030 'application/x-netcdf', // [sic]
3131 ),
3232 'text' /*3*/ => array(
@@ -34,8 +34,8 @@
3535 ),
3636 'binary' /*4*/ => array(
3737 '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',
4040 'video/x-msvideo', 'video/mpeg', 'application/x-compressed',
4141 'application/x-zip-compressed', 'application/x-gzip-compressed', 'application/java',
4242 'application/x-msdownload'
@@ -293,21 +293,21 @@
294294 '.xsl' => 'text/xml',
295295 );
296296
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
300300 * in the return value of getRealMimesFromData(). The names are chosen to sort correctly.
301301 */
302302 protected $versions = array( 'ie05', 'ie06', 'ie07', 'ie07.strict', 'ie07.nohtml' );
303303
304304 /**
305 - * Type table with versions expanded
 305+ * Type table with versions expanded
306306 */
307307 protected $typeTable = array();
308308
309309 /** constructor */
310310 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
312312 $types = $this->baseTypeTable;
313313 foreach ( $this->versions as $version ) {
314314 if ( isset( $this->addedTypes[$version] ) ) {
@@ -320,7 +320,7 @@
321321 }
322322
323323 /**
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
325325 * idiosyncratic private types into something other apps will understand.
326326 *
327327 * @param $fileName String: the file name (unused at present)
@@ -338,6 +338,8 @@
339339 /**
340340 * Translate a MIME type from IE's idiosyncratic private types into
341341 * more commonly understood type strings
 342+ * @param $type
 343+ * @return string
342344 */
343345 public function translateMimeType( $type ) {
344346 static $table = array(
@@ -375,6 +377,11 @@
376378
377379 /**
378380 * 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
379386 */
380387 protected function getMimeTypeForVersion( $version, $fileName, $chunk, $proposed ) {
381388 // Strip text after a semicolon
@@ -397,8 +404,8 @@
398405 // Truncate chunk at 255 bytes
399406 $chunk = substr( $chunk, 0, 255 );
400407
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
403410 // have the same effect since the magic number checks are identical in both cases.
404411 $result = $this->sampleData( $version, $chunk );
405412 $sampleFound = $result['found'];
@@ -413,7 +420,7 @@
414421 return 'image/gif';
415422 }
416423 if ( ( $proposed == 'image/pjpeg' || $proposed == 'image/jpeg' )
417 - && $binaryType == 'image/pjpeg' )
 424+ && $binaryType == 'image/pjpeg' )
418425 {
419426 return $proposed;
420427 }
@@ -430,7 +437,7 @@
431438 return 'application/x-cdf';
432439 }
433440
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
435442 // previous versions
436443 if ( isset( $sampleFound['rss'] ) ) {
437444 return 'application/rss+xml';
@@ -483,8 +490,8 @@
484491
485492 // Freaky heuristics to determine if the data is text or binary
486493 // 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 )
489496 {
490497 $kindOfBinary = true;
491498 $type = $binaryType ? $binaryType : $textType;
@@ -529,8 +536,8 @@
530537 return $this->registry[$ext];
531538 }
532539
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
535542 // return text/plain or application/x-netcdf where application/octet-stream
536543 // would be correct.
537544
@@ -540,6 +547,9 @@
541548 /**
542549 * Check for text headers at the start of the chunk
543550 * Confirmed same in 5 and 7.
 551+ * @param $version
 552+ * @param $chunk
 553+ * @return bool|string
544554 */
545555 private function checkTextHeaders( $version, $chunk ) {
546556 $chunk2 = substr( $chunk, 0, 2 );
@@ -563,6 +573,9 @@
564574 /**
565575 * Check for binary headers at the start of the chunk
566576 * Confirmed same in 5 and 7.
 577+ * @param $version
 578+ * @param $chunk
 579+ * @return bool|string
567580 */
568581 private function checkBinaryHeaders( $version, $chunk ) {
569582 $chunk2 = substr( $chunk, 0, 2 );
@@ -578,13 +591,13 @@
579592 return 'image/pjpeg'; // actually plain JPEG but this is what IE returns
580593 }
581594
582 - if ( $chunk2 == 'BM'
 595+ if ( $chunk2 == 'BM'
583596 && substr( $chunk, 6, 2 ) == "\000\000"
584597 && substr( $chunk, 8, 2 ) == "\000\000" )
585598 {
586599 return 'image/bmp'; // another non-standard MIME
587600 }
588 - if ( $chunk4 == 'RIFF'
 601+ if ( $chunk4 == 'RIFF'
589602 && substr( $chunk, 8, 4 ) == 'WAVE' )
590603 {
591604 return 'audio/wav';
@@ -661,6 +674,9 @@
662675 /**
663676 * Do heuristic checks on the bulk of the data sample.
664677 * Search for HTML tags.
 678+ * @param $version
 679+ * @param $chunk
 680+ * @return array
665681 */
666682 protected function sampleData( $version, $chunk ) {
667683 $found = array();
@@ -774,7 +790,7 @@
775791 }
776792
777793 if ( !strncasecmp( $remainder, $rdfPurl, strlen( $rdfPurl ) ) ) {
778 - if ( isset( $found['rdf-tag'] )
 794+ if ( isset( $found['rdf-tag'] )
779795 && isset( $found['rdf-url'] ) ) // [sic]
780796 {
781797 break;
@@ -808,6 +824,11 @@
809825 return array( 'found' => $found, 'counters' => $counters );
810826 }
811827
 828+ /**
 829+ * @param $version
 830+ * @param $type
 831+ * @return int|string
 832+ */
812833 protected function getDataFormat( $version, $type ) {
813834 $types = $this->typeTable[$version];
814835 if ( $type == '(null)' || strval( $type ) === '' ) {

Status & tagging log