From: Sam Reed Date: Wed, 26 Oct 2011 04:15:09 +0000 (+0000) Subject: More documentation! X-Git-Tag: 1.31.0-rc.0~26908 X-Git-Url: https://git.cyclocoop.org//%22?a=commitdiff_plain;h=4622da783cb5c02aa9ec7420946982a7d6ea78e4;p=lhc%2Fweb%2Fwiklou.git More documentation! --- diff --git a/includes/diff/DairikiDiff.php b/includes/diff/DairikiDiff.php index 8f19712b5c..c935eee284 100644 --- a/includes/diff/DairikiDiff.php +++ b/includes/diff/DairikiDiff.php @@ -24,10 +24,16 @@ class _DiffOp { trigger_error( 'pure virtual', E_USER_ERROR ); } + /** + * @return int + */ function norig() { return $this->orig ? sizeof( $this->orig ) : 0; } + /** + * @return int + */ function nclosing() { return $this->closing ? sizeof( $this->closing ) : 0; } @@ -49,6 +55,9 @@ class _DiffOp_Copy extends _DiffOp { $this->closing = $closing; } + /** + * @return _DiffOp_Copy + */ function reverse() { return new _DiffOp_Copy( $this->closing, $this->orig ); } @@ -67,6 +76,9 @@ class _DiffOp_Delete extends _DiffOp { $this->closing = false; } + /** + * @return _DiffOp_Add + */ function reverse() { return new _DiffOp_Add( $this->orig ); } @@ -85,6 +97,9 @@ class _DiffOp_Add extends _DiffOp { $this->orig = false; } + /** + * @return _DiffOp_Delete + */ function reverse() { return new _DiffOp_Delete( $this->closing ); } @@ -103,6 +118,9 @@ class _DiffOp_Change extends _DiffOp { $this->closing = $closing; } + /** + * @return _DiffOp_Change + */ function reverse() { return new _DiffOp_Change( $this->closing, $this->orig ); } @@ -145,6 +163,11 @@ class _DiffEngine { protected $lcs = 0; + /** + * @param $from_lines + * @param $to_lines + * @return array + */ function diff ( $from_lines, $to_lines ) { wfProfileIn( __METHOD__ ); @@ -199,6 +222,10 @@ class _DiffEngine { return $edits; } + /** + * @param $from_lines + * @param $to_lines + */ function diff_local ( $from_lines, $to_lines ) { global $wgExternalDiffEngine; wfProfileIn( __METHOD__ ); @@ -268,6 +295,8 @@ class _DiffEngine { /** * Returns the whole line if it's small enough, or the MD5 hash otherwise + * @param $line string + * @return string */ function _line_hash( $line ) { if ( strlen( $line ) > self::MAX_XREF_LENGTH ) { @@ -293,6 +322,12 @@ class _DiffEngine { * of the two files do not match, and likewise that the last lines do not * match. The caller must trim matching lines from the beginning and end * of the portions it is going to specify. + * @param $xoff + * @param $xlim + * @param $yoff + * @param $ylim + * @param $nchunks + * @return array */ function _diag( $xoff, $xlim, $yoff, $ylim, $nchunks ) { $flip = false; @@ -373,6 +408,10 @@ class _DiffEngine { return array( $this->lcs, $seps ); } + /** + * @param $ypos + * @return int + */ function _lcs_pos( $ypos ) { $end = $this->lcs; if ( $end == 0 || $ypos > $this->seq[$end] ) { @@ -410,6 +449,10 @@ class _DiffEngine { * * Note that XLIM, YLIM are exclusive bounds. * All line numbers are origin-0 and discarded lines are not counted. + * @param $xoff + * @param $xlim + * @param $yoff + * @param $ylim */ function _compareseq ( $xoff, $xlim, $yoff, $ylim ) { // Slide down the bottom initial diagonal. @@ -703,6 +746,8 @@ class Diff { * Check a Diff for validity. * * This is here only for debugging purposes. + * @param $from_lines + * @param $to_lines */ function _check( $from_lines, $to_lines ) { wfProfileIn( __METHOD__ ); @@ -886,6 +931,13 @@ class DiffFormatter { return $end; } + /** + * @param $xbeg + * @param $xlen + * @param $ybeg + * @param $ylen + * @param $edits + */ function _block( $xbeg, $xlen, $ybeg, $ylen, &$edits ) { wfProfileIn( __METHOD__ ); $this->_start_block( $this->_block_header( $xbeg, $xlen, $ybeg, $ylen ) ); @@ -910,12 +962,22 @@ class DiffFormatter { ob_start(); } + /** + * @return string + */ function _end_diff() { $val = ob_get_contents(); ob_end_clean(); return $val; } + /** + * @param $xbeg + * @param $xlen + * @param $ybeg + * @param $ylen + * @return string + */ function _block_header( $xbeg, $xlen, $ybeg, $ylen ) { if ( $xlen > 1 ) { $xbeg .= ',' . ( $xbeg + $xlen - 1 ); @@ -934,23 +996,41 @@ class DiffFormatter { function _end_block() { } + /** + * @param $lines + * @param $prefix string + */ function _lines( $lines, $prefix = ' ' ) { foreach ( $lines as $line ) { echo "$prefix $line\n"; } } + /** + * @param $lines + */ function _context( $lines ) { $this->_lines( $lines ); } + /** + * @param $lines + */ function _added( $lines ) { $this->_lines( $lines, '>' ); } + + /** + * @param $lines + */ function _deleted( $lines ) { $this->_lines( $lines, '<' ); } + /** + * @param $orig + * @param $closing + */ function _changed( $orig, $closing ) { $this->_deleted( $orig ); echo "---\n"; @@ -966,16 +1046,36 @@ class UnifiedDiffFormatter extends DiffFormatter { var $leading_context_lines = 2; var $trailing_context_lines = 2; + /** + * @param $lines + */ function _added( $lines ) { $this->_lines( $lines, '+' ); } + + /** + * @param $lines + */ function _deleted( $lines ) { $this->_lines( $lines, '-' ); } + + /** + * @param $orig + * @param $closing + */ function _changed( $orig, $closing ) { $this->_deleted( $orig ); $this->_added( $closing ); } + + /** + * @param $xbeg + * @param $xlen + * @param $ybeg + * @param $ylen + * @return string + */ function _block_header( $xbeg, $xlen, $ybeg, $ylen ) { return "@@ -$xbeg,$xlen +$ybeg,$ylen @@"; } @@ -986,6 +1086,11 @@ class UnifiedDiffFormatter extends DiffFormatter { * @ingroup DifferenceEngine */ class ArrayDiffFormatter extends DiffFormatter { + + /** + * @param $diff + * @return array + */ function format( $diff ) { $oldline = 1; $newline = 1; @@ -1049,6 +1154,9 @@ class _HWLDF_WordAccumulator { $this->_tag = ''; } + /** + * @param $new_tag + */ function _flushGroup( $new_tag ) { if ( $this->_group !== '' ) { if ( $this->_tag == 'ins' ) { @@ -1065,6 +1173,9 @@ class _HWLDF_WordAccumulator { $this->_tag = $new_tag; } + /** + * @param $new_tag + */ function _flushLine( $new_tag ) { $this->_flushGroup( $new_tag ); if ( $this->_line != '' ) { @@ -1076,6 +1187,10 @@ class _HWLDF_WordAccumulator { $this->_line = ''; } + /** + * @param $words + * @param $tag string + */ function addWords ( $words, $tag = '' ) { if ( $tag != $this->_tag ) { $this->_flushGroup( $tag ); @@ -1095,6 +1210,9 @@ class _HWLDF_WordAccumulator { } } + /** + * @return array + */ function getLines() { $this->_flushLine( '~done' ); return $this->_lines; @@ -1109,6 +1227,10 @@ class _HWLDF_WordAccumulator { class WordLevelDiff extends MappedDiff { const MAX_LINE_LENGTH = 10000; + /** + * @param $orig_lines + * @param $closing_lines + */ function __construct ( $orig_lines, $closing_lines ) { wfProfileIn( __METHOD__ ); @@ -1120,6 +1242,10 @@ class WordLevelDiff extends MappedDiff { wfProfileOut( __METHOD__ ); } + /** + * @param $lines + * @return array + */ function _split( $lines ) { wfProfileIn( __METHOD__ ); @@ -1152,6 +1278,9 @@ class WordLevelDiff extends MappedDiff { return array( $words, $stripped ); } + /** + * @return array + */ function orig() { wfProfileIn( __METHOD__ ); $orig = new _HWLDF_WordAccumulator; @@ -1168,6 +1297,9 @@ class WordLevelDiff extends MappedDiff { return $lines; } + /** + * @return array + */ function closing() { wfProfileIn( __METHOD__ ); $closing = new _HWLDF_WordAccumulator; @@ -1197,6 +1329,11 @@ class TableDiffFormatter extends DiffFormatter { $this->trailing_context_lines = 2; } + /** + * @static + * @param $msg + * @return mixed + */ public static function escapeWhiteSpace( $msg ) { $msg = preg_replace( '/^ /m', '  ', $msg ); $msg = preg_replace( '/ $/m', '  ', $msg ); @@ -1204,12 +1341,22 @@ class TableDiffFormatter extends DiffFormatter { return $msg; } + /** + * @param $xbeg + * @param $xlen + * @param $ybeg + * @param $ylen + * @return string + */ function _block_header( $xbeg, $xlen, $ybeg, $ylen ) { $r = '\n" . '\n"; return $r; } + /** + * @param $header + */ function _start_block( $header ) { echo $header; } @@ -1220,21 +1367,39 @@ class TableDiffFormatter extends DiffFormatter { function _lines( $lines, $prefix = ' ', $color = 'white' ) { } - # HTML-escape parameter before calling this + /** + * HTML-escape parameter before calling this + * @param $line + * @return string + */ function addedLine( $line ) { return $this->wrapLine( '+', 'diff-addedline', $line ); } - # HTML-escape parameter before calling this + /** + * HTML-escape parameter before calling this + * @param $line + * @return string + */ function deletedLine( $line ) { return $this->wrapLine( '−', 'diff-deletedline', $line ); } - # HTML-escape parameter before calling this + /** + * HTML-escape parameter before calling this + * @param $line + * @return string + */ function contextLine( $line ) { return $this->wrapLine( ' ', 'diff-context', $line ); } + /** + * @param $marker + * @param $class + * @param $line + * @return string + */ private function wrapLine( $marker, $class, $line ) { if ( $line !== '' ) { // The
wrapper is needed for 'overflow: auto' style to scroll properly @@ -1243,10 +1408,16 @@ class TableDiffFormatter extends DiffFormatter { return "$marker$line"; } + /** + * @return string + */ function emptyLine() { return ' '; } + /** + * @param $lines array + */ function _added( $lines ) { foreach ( $lines as $line ) { echo '' . $this->emptyLine() . @@ -1255,6 +1426,9 @@ class TableDiffFormatter extends DiffFormatter { } } + /** + * @param $lines + */ function _deleted( $lines ) { foreach ( $lines as $line ) { echo '' . $this->deletedLine( '' . @@ -1263,6 +1437,9 @@ class TableDiffFormatter extends DiffFormatter { } } + /** + * @param $lines + */ function _context( $lines ) { foreach ( $lines as $line ) { echo '' . @@ -1271,6 +1448,10 @@ class TableDiffFormatter extends DiffFormatter { } } + /** + * @param $orig + * @param $closing + */ function _changed( $orig, $closing ) { wfProfileIn( __METHOD__ ); diff --git a/includes/job/DoubleRedirectJob.php b/includes/job/DoubleRedirectJob.php index d7991f5e39..ce3d8bb428 100644 --- a/includes/job/DoubleRedirectJob.php +++ b/includes/job/DoubleRedirectJob.php @@ -19,7 +19,7 @@ class DoubleRedirectJob extends Job { */ static $user; - /** + /** * Insert jobs into the job queue to fix redirects to the given title * @param $reason String: the reason for the fix, see message double-redirect-fixed- * @param $redirTitle Title: the title which has changed, redirects pointing to this title are fixed @@ -28,10 +28,10 @@ class DoubleRedirectJob extends Job { public static function fixRedirects( $reason, $redirTitle, $destTitle = false ) { # Need to use the master to get the redirect table updated in the same transaction $dbw = wfGetDB( DB_MASTER ); - $res = $dbw->select( - array( 'redirect', 'page' ), - array( 'page_namespace', 'page_title' ), - array( + $res = $dbw->select( + array( 'redirect', 'page' ), + array( 'page_namespace', 'page_title' ), + array( 'page_id = rd_from', 'rd_namespace' => $redirTitle->getNamespace(), 'rd_title' => $redirTitle->getDBkey() @@ -46,7 +46,7 @@ class DoubleRedirectJob extends Job { continue; } - $jobs[] = new self( $title, array( + $jobs[] = new self( $title, array( 'reason' => $reason, 'redirTitle' => $redirTitle->getPrefixedDBkey() ) ); # Avoid excessive memory usage @@ -65,6 +65,9 @@ class DoubleRedirectJob extends Job { $this->destTitleText = !empty( $params['destTitle'] ) ? $params['destTitle'] : ''; } + /** + * @return bool + */ function run() { if ( !$this->redirTitle ) { $this->setLastError( 'Invalid title' ); @@ -103,13 +106,13 @@ class DoubleRedirectJob extends Job { } # Preserve fragment (bug 14904) - $newTitle = Title::makeTitle( $newTitle->getNamespace(), $newTitle->getDBkey(), + $newTitle = Title::makeTitle( $newTitle->getNamespace(), $newTitle->getDBkey(), $currentDest->getFragment() ); # Fix the text # Remember that redirect pages can have categories, templates, etc., # so the regex has to be fairly general - $newText = preg_replace( '/ \[ \[ [^\]]* \] \] /x', + $newText = preg_replace( '/ \[ \[ [^\]]* \] \] /x', '[[' . $newTitle->getFullText() . ']]', $text, 1 ); @@ -123,7 +126,7 @@ class DoubleRedirectJob extends Job { $oldUser = $wgUser; $wgUser = $this->getUser(); $article = new Article( $this->title ); - $reason = wfMsgForContent( 'double-redirect-fixed-' . $this->reason, + $reason = wfMsgForContent( 'double-redirect-fixed-' . $this->reason, $this->redirTitle->getPrefixedText(), $newTitle->getPrefixedText() ); $article->doEdit( $newText, $reason, EDIT_UPDATE | EDIT_SUPPRESS_RC ); $wgUser = $oldUser; @@ -152,10 +155,10 @@ class DoubleRedirectJob extends Job { } $seenTitles[$titleText] = true; - $row = $dbw->selectRow( + $row = $dbw->selectRow( array( 'redirect', 'page' ), array( 'rd_namespace', 'rd_title' ), - array( + array( 'rd_from=page_id', 'page_namespace' => $title->getNamespace(), 'page_title' => $title->getDBkey() @@ -172,6 +175,7 @@ class DoubleRedirectJob extends Job { /** * Get a user object for doing edits, from a request-lifetime cache + * @return User */ function getUser() { if ( !self::$user ) { diff --git a/includes/job/JobQueue.php b/includes/job/JobQueue.php index 0d917ba3e6..bfaec33cf5 100644 --- a/includes/job/JobQueue.php +++ b/includes/job/JobQueue.php @@ -213,6 +213,10 @@ abstract class Job { throw new MWException( "Invalid job command `{$command}`" ); } + /** + * @param $params + * @return string + */ static function makeBlob( $params ) { if ( $params !== false ) { return serialize( $params ); @@ -221,6 +225,10 @@ abstract class Job { } } + /** + * @param $blob + * @return bool|mixed + */ static function extractBlob( $blob ) { if ( (string)$blob !== '' ) { return unserialize( $blob ); @@ -323,13 +331,16 @@ abstract class Job { if ( $this->removeDuplicates ) { $res = $dbw->select( 'job', array( '1' ), $fields, __METHOD__ ); if ( $dbw->numRows( $res ) ) { - return; + return true; } } wfIncrStats( 'job-insert' ); return $dbw->insert( 'job', $fields, __METHOD__ ); } + /** + * @return array + */ protected function insertFields() { $dbw = wfGetDB( DB_MASTER ); return array( @@ -362,6 +373,9 @@ abstract class Job { } } + /** + * @return string + */ function toString() { $paramString = ''; if ( $this->params ) { diff --git a/includes/job/UploadFromUrlJob.php b/includes/job/UploadFromUrlJob.php index d664e71819..26f6e4ba37 100644 --- a/includes/job/UploadFromUrlJob.php +++ b/includes/job/UploadFromUrlJob.php @@ -64,7 +64,7 @@ class UploadFromUrlJob extends Job { # Stash the upload $key = $this->upload->stashFile(); - + if ( $this->params['leaveMessage'] ) { $this->user->leaveUserMessage( wfMsg( 'upload-warning-subj' ), @@ -73,7 +73,7 @@ class UploadFromUrlJob extends Job { $this->params['url'] ) ); } else { - wfSetupSession( $this->params['sessionId'] ); + wfSetupSession( $this->params['sessionId'] ); $this->storeResultInSession( 'Warning', 'warnings', $warnings ); session_write_close(); @@ -151,6 +151,10 @@ class UploadFromUrlJob extends Job { $$session['result'] = 'Queued'; } + /** + * @param $key + * @return mixed + */ public static function &getSessionData( $key ) { if ( !isset( $_SESSION[self::SESSION_KEYNAME][$key] ) ) { $_SESSION[self::SESSION_KEYNAME][$key] = array(); diff --git a/includes/json/FormatJson.php b/includes/json/FormatJson.php index 006f7720d2..0f5f7d53c6 100644 --- a/includes/json/FormatJson.php +++ b/includes/json/FormatJson.php @@ -11,11 +11,14 @@ if ( !defined( 'MEDIAWIKI' ) ) { require_once dirname( __FILE__ ) . '/Services_JSON.php'; +/** + * JSON formatter wrapper class + */ class FormatJson { - + /** * Returns the JSON representation of a value. - * + * * @param $value Mixed: the value being encoded. Can be any type except a resource. * @param $isHtml Boolean * @@ -23,7 +26,7 @@ class FormatJson { * map to a parameter labeled "pretty-print output with indents and * newlines" in Services_JSON::encode(), which has no string relation * to HTML output. - * + * * @return string */ public static function encode( $value, $isHtml = false ) { @@ -40,10 +43,10 @@ class FormatJson { /** * Decodes a JSON string. - * + * * @param $value String: the json string being decoded. * @param $assoc Boolean: when true, returned objects will be converted into associative arrays. - * + * * @return Mixed: the value encoded in json in appropriate PHP type. * Values true, false and null (case-insensitive) are returned as true, false * and &null; respectively. &null; is returned if the json cannot be @@ -61,5 +64,5 @@ class FormatJson { return json_decode( $value, $assoc ); } } - + } diff --git a/includes/libs/CSSJanus.php b/includes/libs/CSSJanus.php index 31f570d53f..e6940ea8ce 100644 --- a/includes/libs/CSSJanus.php +++ b/includes/libs/CSSJanus.php @@ -175,6 +175,8 @@ class CSSJanus { * * See http://code.google.com/p/cssjanus/issues/detail?id=15 and * TODO: URL + * @param $css string + * @return string */ private static function fixDirection( $css ) { $css = preg_replace( self::$patterns['direction_ltr'], @@ -187,6 +189,8 @@ class CSSJanus { /** * Replace 'ltr' with 'rtl' and vice versa in background URLs + * @param $css string + * @return string */ private static function fixLtrRtlInURL( $css ) { $css = preg_replace( self::$patterns['ltr_in_url'], self::$patterns['tmpToken'], $css ); @@ -198,6 +202,8 @@ class CSSJanus { /** * Replace 'left' with 'right' and vice versa in background URLs + * @param $css string + * @return string */ private static function fixLeftRightInURL( $css ) { $css = preg_replace( self::$patterns['left_in_url'], self::$patterns['tmpToken'], $css ); @@ -209,6 +215,8 @@ class CSSJanus { /** * Flip rules like left: , padding-right: , etc. + * @param $css string + * @return string */ private static function fixLeftAndRight( $css ) { $css = preg_replace( self::$patterns['left'], self::$patterns['tmpToken'], $css ); @@ -220,6 +228,8 @@ class CSSJanus { /** * Flip East and West in rules like cursor: nw-resize; + * @param $css string + * @return string */ private static function fixCursorProperties( $css ) { $css = preg_replace( self::$patterns['cursor_east'], @@ -239,6 +249,8 @@ class CSSJanus { * and four-part color rules with multiple whitespace characters between * colors are not recognized. * See http://code.google.com/p/cssjanus/issues/detail?id=16 + * @param $css string + * @return string */ private static function fixFourPartNotation( $css ) { $css = preg_replace( self::$patterns['four_notation_quantity'], '$1$2$7$4$5$6$3', $css ); @@ -249,6 +261,8 @@ class CSSJanus { /** * Flip horizontal background percentages. + * @param $css string + * @return string */ private static function fixBackgroundPosition( $css ) { $css = preg_replace_callback( self::$patterns['bg_horizontal_percentage'], @@ -261,6 +275,8 @@ class CSSJanus { /** * Callback for calculateNewBackgroundPosition() + * @param $matches array + * @return string */ private static function calculateNewBackgroundPosition( $matches ) { return $matches[1] . ( 100 - $matches[2] ) . $matches[3]; @@ -297,6 +313,10 @@ class CSSJanus_Tokenizer { return preg_replace_callback( $this->regex, array( $this, 'tokenizeCallback' ), $str ); } + /** + * @param $matches array + * @return string + */ private function tokenizeCallback( $matches ) { $this->originals[] = $matches[0]; return $this->token; @@ -316,6 +336,10 @@ class CSSJanus_Tokenizer { array( $this, 'detokenizeCallback' ), $str ); } + /** + * @param $matches + * @return mixed + */ private function detokenizeCallback( $matches ) { $retval = current( $this->originals ); next( $this->originals ); diff --git a/includes/libs/CSSMin.php b/includes/libs/CSSMin.php index 225a8ab928..45f256fefb 100644 --- a/includes/libs/CSSMin.php +++ b/includes/libs/CSSMin.php @@ -79,6 +79,10 @@ class CSSMin { return $files; } + /** + * @param $file string + * @return bool|string + */ protected static function getMimeType( $file ) { $realpath = realpath( $file ); // Try a couple of different ways to get the mime-type of a file, in order of diff --git a/includes/libs/IEContentAnalyzer.php b/includes/libs/IEContentAnalyzer.php index a2ef1a0974..01e72e6875 100644 --- a/includes/libs/IEContentAnalyzer.php +++ b/includes/libs/IEContentAnalyzer.php @@ -1,19 +1,19 @@ array( - 'text/plain', - 'application/octet-stream', + 'text/plain', + 'application/octet-stream', 'application/x-netcdf', // [sic] ), 'text' /*3*/ => array( @@ -34,8 +34,8 @@ class IEContentAnalyzer { ), 'binary' /*4*/ => array( 'application/pdf', 'audio/x-aiff', 'audio/basic', 'audio/wav', 'image/gif', - 'image/pjpeg', 'image/jpeg', 'image/tiff', 'image/x-png', 'image/png', 'image/bmp', - 'image/x-jg', 'image/x-art', 'image/x-emf', 'image/x-wmf', 'video/avi', + 'image/pjpeg', 'image/jpeg', 'image/tiff', 'image/x-png', 'image/png', 'image/bmp', + 'image/x-jg', 'image/x-art', 'image/x-emf', 'image/x-wmf', 'video/avi', 'video/x-msvideo', 'video/mpeg', 'application/x-compressed', 'application/x-zip-compressed', 'application/x-gzip-compressed', 'application/java', 'application/x-msdownload' @@ -293,21 +293,21 @@ class IEContentAnalyzer { '.xsl' => 'text/xml', ); - /** - * IE versions which have been analysed to bring you this class, and for - * which some substantive difference exists. These will appear as keys + /** + * IE versions which have been analysed to bring you this class, and for + * which some substantive difference exists. These will appear as keys * in the return value of getRealMimesFromData(). The names are chosen to sort correctly. */ protected $versions = array( 'ie05', 'ie06', 'ie07', 'ie07.strict', 'ie07.nohtml' ); /** - * Type table with versions expanded + * Type table with versions expanded */ protected $typeTable = array(); /** constructor */ function __construct() { - // Construct versioned type arrays from the base type array plus additions + // Construct versioned type arrays from the base type array plus additions $types = $this->baseTypeTable; foreach ( $this->versions as $version ) { if ( isset( $this->addedTypes[$version] ) ) { @@ -320,7 +320,7 @@ class IEContentAnalyzer { } /** - * Get the MIME types from getMimesFromData(), but convert the result from IE's + * Get the MIME types from getMimesFromData(), but convert the result from IE's * idiosyncratic private types into something other apps will understand. * * @param $fileName String: the file name (unused at present) @@ -338,6 +338,8 @@ class IEContentAnalyzer { /** * Translate a MIME type from IE's idiosyncratic private types into * more commonly understood type strings + * @param $type + * @return string */ public function translateMimeType( $type ) { static $table = array( @@ -375,6 +377,11 @@ class IEContentAnalyzer { /** * Get the MIME type for a given named version + * @param $version + * @param $fileName + * @param $chunk + * @param $proposed + * @return bool|string */ protected function getMimeTypeForVersion( $version, $fileName, $chunk, $proposed ) { // Strip text after a semicolon @@ -397,8 +404,8 @@ class IEContentAnalyzer { // Truncate chunk at 255 bytes $chunk = substr( $chunk, 0, 255 ); - // IE does the Check*Headers() calls last, and instead does the following image - // type checks by directly looking for the magic numbers. What I do here should + // IE does the Check*Headers() calls last, and instead does the following image + // type checks by directly looking for the magic numbers. What I do here should // have the same effect since the magic number checks are identical in both cases. $result = $this->sampleData( $version, $chunk ); $sampleFound = $result['found']; @@ -413,7 +420,7 @@ class IEContentAnalyzer { return 'image/gif'; } if ( ( $proposed == 'image/pjpeg' || $proposed == 'image/jpeg' ) - && $binaryType == 'image/pjpeg' ) + && $binaryType == 'image/pjpeg' ) { return $proposed; } @@ -430,7 +437,7 @@ class IEContentAnalyzer { return 'application/x-cdf'; } - // RSS and Atom were added in IE 7 so they won't be in $sampleFound for + // RSS and Atom were added in IE 7 so they won't be in $sampleFound for // previous versions if ( isset( $sampleFound['rss'] ) ) { return 'application/rss+xml'; @@ -483,8 +490,8 @@ class IEContentAnalyzer { // Freaky heuristics to determine if the data is text or binary // The heuristic is of course broken for non-ASCII text - if ( $counters['ctrl'] != 0 && ( $counters['ff'] + $counters['low'] ) - < ( $counters['ctrl'] + $counters['high'] ) * 16 ) + if ( $counters['ctrl'] != 0 && ( $counters['ff'] + $counters['low'] ) + < ( $counters['ctrl'] + $counters['high'] ) * 16 ) { $kindOfBinary = true; $type = $binaryType ? $binaryType : $textType; @@ -529,8 +536,8 @@ class IEContentAnalyzer { return $this->registry[$ext]; } - // TODO: If the extension has an application registered to it, IE will return - // application/octet-stream. We'll skip that, so we could erroneously + // TODO: If the extension has an application registered to it, IE will return + // application/octet-stream. We'll skip that, so we could erroneously // return text/plain or application/x-netcdf where application/octet-stream // would be correct. @@ -540,6 +547,9 @@ class IEContentAnalyzer { /** * Check for text headers at the start of the chunk * Confirmed same in 5 and 7. + * @param $version + * @param $chunk + * @return bool|string */ private function checkTextHeaders( $version, $chunk ) { $chunk2 = substr( $chunk, 0, 2 ); @@ -563,6 +573,9 @@ class IEContentAnalyzer { /** * Check for binary headers at the start of the chunk * Confirmed same in 5 and 7. + * @param $version + * @param $chunk + * @return bool|string */ private function checkBinaryHeaders( $version, $chunk ) { $chunk2 = substr( $chunk, 0, 2 ); @@ -578,13 +591,13 @@ class IEContentAnalyzer { return 'image/pjpeg'; // actually plain JPEG but this is what IE returns } - if ( $chunk2 == 'BM' + if ( $chunk2 == 'BM' && substr( $chunk, 6, 2 ) == "\000\000" && substr( $chunk, 8, 2 ) == "\000\000" ) { return 'image/bmp'; // another non-standard MIME } - if ( $chunk4 == 'RIFF' + if ( $chunk4 == 'RIFF' && substr( $chunk, 8, 4 ) == 'WAVE' ) { return 'audio/wav'; @@ -661,6 +674,9 @@ class IEContentAnalyzer { /** * Do heuristic checks on the bulk of the data sample. * Search for HTML tags. + * @param $version + * @param $chunk + * @return array */ protected function sampleData( $version, $chunk ) { $found = array(); @@ -774,7 +790,7 @@ class IEContentAnalyzer { } if ( !strncasecmp( $remainder, $rdfPurl, strlen( $rdfPurl ) ) ) { - if ( isset( $found['rdf-tag'] ) + if ( isset( $found['rdf-tag'] ) && isset( $found['rdf-url'] ) ) // [sic] { break; @@ -808,6 +824,11 @@ class IEContentAnalyzer { return array( 'found' => $found, 'counters' => $counters ); } + /** + * @param $version + * @param $type + * @return int|string + */ protected function getDataFormat( $version, $type ) { $types = $this->typeTable[$version]; if ( $type == '(null)' || strval( $type ) === '' ) { diff --git a/includes/libs/IEUrlExtension.php b/includes/libs/IEUrlExtension.php index 100454d450..e00e666385 100644 --- a/includes/libs/IEUrlExtension.php +++ b/includes/libs/IEUrlExtension.php @@ -1,31 +1,31 @@ \"/:|?.# - * - if we find a possible extension followed by the end of the string or + * - if we find a possible extension followed by the end of the string or * a #, that's our extension * - if we find a possible extension followed by a ?, that's our extension - * - UNLESS it's exe, dll or cgi, in which case we ignore it and continue + * - UNLESS it's exe, dll or cgi, in which case we ignore it and continue * searching for another possible extension - * - if we find a possible extension followed by a dot or another illegal + * - if we find a possible extension followed by a dot or another illegal * character, we ignore it and continue searching - * + * * @param $url string URL * @return mixed Detected extension (string), or false if none found */ @@ -182,7 +186,7 @@ class IEUrlExtension { // End of string, we're done return false; } - + // We found a dot. Skip past it $pos++; $remainingLength = $urlLength - $pos; @@ -220,12 +224,12 @@ class IEUrlExtension { * with %2E not decoded to ".". On such a server, it is possible to detect * whether the script filename has been obscured. * - * The function returns false if the server is not known to have this + * The function returns false if the server is not known to have this * behaviour. Microsoft IIS in particular is known to decode escaped script * filenames. * * SERVER_SOFTWARE typically contains either a plain string such as "Zeus", - * or a specification in the style of a User-Agent header, such as + * or a specification in the style of a User-Agent header, such as * "Apache/1.3.34 (Unix) mod_ssl/2.8.25 OpenSSL/0.9.8a PHP/4.4.2" * * @param $serverSoftware @@ -234,8 +238,8 @@ class IEUrlExtension { */ public static function haveUndecodedRequestUri( $serverSoftware ) { static $whitelist = array( - 'Apache', - 'Zeus', + 'Apache', + 'Zeus', 'LiteSpeed' ); if ( preg_match( '/^(.*?)($|\/| )/', $serverSoftware, $m ) ) { return in_array( $m[1], $whitelist ); diff --git a/tests/phpunit/includes/HttpTest.php b/tests/phpunit/includes/HttpTest.php index dd3207dbf1..7ddedb9b24 100644 --- a/tests/phpunit/includes/HttpTest.php +++ b/tests/phpunit/includes/HttpTest.php @@ -48,7 +48,7 @@ class HttpTest extends MediaWikiTestCase { /** * Test Http::isValidURI() - * @bug 27854 : Http::isValidURI is to lax + * @bug 27854 : Http::isValidURI is too lax * @dataProvider provideURI */ function testIsValidUri( $expect, $URI, $message = '' ) { @@ -76,7 +76,7 @@ class HttpTest extends MediaWikiTestCase { array( false, '\\host\directory', 'CIFS share' ), array( false, 'gopher://host/dir', 'Reject gopher scheme' ), array( false, 'telnet://host', 'Reject telnet scheme' ), - + # :\/\/ - double slashes array( false, 'http//example.org', 'Reject missing colon in protocol' ), array( false, 'http:/example.org', 'Reject missing slash in protocol' ),