More documentation!
authorSam Reed <reedy@users.mediawiki.org>
Wed, 26 Oct 2011 04:15:09 +0000 (04:15 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Wed, 26 Oct 2011 04:15:09 +0000 (04:15 +0000)
includes/diff/DairikiDiff.php
includes/job/DoubleRedirectJob.php
includes/job/JobQueue.php
includes/job/UploadFromUrlJob.php
includes/json/FormatJson.php
includes/libs/CSSJanus.php
includes/libs/CSSMin.php
includes/libs/IEContentAnalyzer.php
includes/libs/IEUrlExtension.php
tests/phpunit/includes/HttpTest.php

index 8f19712..c935eee 100644 (file)
@@ -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', '&#160; ', $msg );
                $msg = preg_replace( '/ $/m', ' &#160;', $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 = '<tr><td colspan="2" class="diff-lineno"><!--LINE ' . $xbeg . "--></td>\n" .
                  '<td colspan="2" class="diff-lineno"><!--LINE ' . $ybeg . "--></td></tr>\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( '&#160;', 'diff-context', $line );
        }
 
+       /**
+        * @param $marker
+        * @param $class
+        * @param $line
+        * @return string
+        */
        private function wrapLine( $marker, $class, $line ) {
                if ( $line !== '' ) {
                        // The <div> wrapper is needed for 'overflow: auto' style to scroll properly
@@ -1243,10 +1408,16 @@ class TableDiffFormatter extends DiffFormatter {
                return "<td class='diff-marker'>$marker</td><td class='$class'>$line</td>";
        }
 
+       /**
+        * @return string
+        */
        function emptyLine() {
                return '<td colspan="2">&#160;</td>';
        }
 
+       /**
+        * @param $lines array
+        */
        function _added( $lines ) {
                foreach ( $lines as $line ) {
                        echo '<tr>' . $this->emptyLine() .
@@ -1255,6 +1426,9 @@ class TableDiffFormatter extends DiffFormatter {
                }
        }
 
+       /**
+        * @param $lines
+        */
        function _deleted( $lines ) {
                foreach ( $lines as $line ) {
                        echo '<tr>' . $this->deletedLine( '<del class="diffchange">' .
@@ -1263,6 +1437,9 @@ class TableDiffFormatter extends DiffFormatter {
                }
        }
 
+       /**
+        * @param $lines
+        */
        function _context( $lines ) {
                foreach ( $lines as $line ) {
                        echo '<tr>' .
@@ -1271,6 +1448,10 @@ class TableDiffFormatter extends DiffFormatter {
                }
        }
 
+       /**
+        * @param $orig
+        * @param $closing
+        */
        function _changed( $orig, $closing ) {
                wfProfileIn( __METHOD__ );
 
index d7991f5..ce3d8bb 100644 (file)
@@ -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-<reason>
         * @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 ) {
index 0d917ba..bfaec33 100644 (file)
@@ -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 ) {
index d664e71..26f6e4b 100644 (file)
@@ -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();
index 006f772..0f5f7d5 100644 (file)
@@ -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 );
                }
        }
-       
+
 }
index 31f570d..e6940ea 100644 (file)
@@ -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 );
index 225a8ab..45f256f 100644 (file)
@@ -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
index a2ef1a0..01e72e6 100644 (file)
@@ -1,19 +1,19 @@
 <?php
 
 /**
- * This class simulates Microsoft Internet Explorer's terribly broken and 
+ * This class simulates Microsoft Internet Explorer's terribly broken and
  * insecure MIME type detection algorithm. It can be used to check web uploads
- * with an apparently safe type, to see if IE will reinterpret them to produce 
+ * with an apparently safe type, to see if IE will reinterpret them to produce
  * something dangerous.
  *
- * It is full of bugs and strange design choices should not under any 
- * circumstances be used to determine a MIME type to present to a user or 
+ * It is full of bugs and strange design choices should not under any
+ * circumstances be used to determine a MIME type to present to a user or
  * client. (Apple Safari developers, this means you too.)
  *
- * This class is based on a disassembly of IE 5.0, 6.0 and 7.0. Although I have 
- * attempted to ensure that this code works in exactly the same way as Internet 
- * Explorer, it does not share any source code, or creative choices such as 
- * variable names, thus I (Tim Starling) claim copyright on it. 
+ * This class is based on a disassembly of IE 5.0, 6.0 and 7.0. Although I have
+ * attempted to ensure that this code works in exactly the same way as Internet
+ * Explorer, it does not share any source code, or creative choices such as
+ * variable names, thus I (Tim Starling) claim copyright on it.
  *
  * It may be redistributed without restriction. To aid reuse, this class does
  * not depend on any MediaWiki module.
@@ -24,8 +24,8 @@ class IEContentAnalyzer {
         */
        protected $baseTypeTable = array(
                'ambiguous' /*1*/ => 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 ) === '' ) {
index 100454d..e00e666 100644 (file)
@@ -1,31 +1,31 @@
 <?php
 
 /**
- * Internet Explorer derives a cache filename from a URL, and then in certain 
- * circumstances, uses the extension of the resulting file to determine the 
- * content type of the data, ignoring the Content-Type header. 
+ * Internet Explorer derives a cache filename from a URL, and then in certain
+ * circumstances, uses the extension of the resulting file to determine the
+ * content type of the data, ignoring the Content-Type header.
  *
  * This can be a problem, especially when non-HTML content is sent by MediaWiki,
  * and Internet Explorer interprets it as HTML, exposing an XSS vulnerability.
  *
- * Usually the script filename (e.g. api.php) is present in the URL, and this 
+ * Usually the script filename (e.g. api.php) is present in the URL, and this
  * makes Internet Explorer think the extension is a harmless script extension.
- * But Internet Explorer 6 and earlier allows the script extension to be 
- * obscured by encoding the dot as "%2E". 
+ * But Internet Explorer 6 and earlier allows the script extension to be
+ * obscured by encoding the dot as "%2E".
  *
- * This class contains functions which help in detecting and dealing with this 
+ * This class contains functions which help in detecting and dealing with this
  * situation.
  *
- * Checking the URL for a bad extension is somewhat complicated due to the fact 
+ * Checking the URL for a bad extension is somewhat complicated due to the fact
  * that CGI doesn't provide a standard method to determine the URL. Instead it
- * is necessary to pass a subset of $_SERVER variables, which we then attempt 
+ * is necessary to pass a subset of $_SERVER variables, which we then attempt
  * to use to guess parts of the URL.
  */
 class IEUrlExtension {
        /**
         * Check a subset of $_SERVER (or the whole of $_SERVER if you like)
-        * to see if it indicates that the request was sent with a bad file 
-        * extension. Returns true if the request should be denied or modified, 
+        * to see if it indicates that the request was sent with a bad file
+        * extension. Returns true if the request should be denied or modified,
         * false otherwise. The relevant $_SERVER elements are:
         *
         *   - SERVER_SOFTWARE
@@ -37,6 +37,7 @@ class IEUrlExtension {
         *
         * @param $vars A subset of $_SERVER.
         * @param $extWhitelist Extensions which are allowed, assumed harmless.
+        * @return bool
         */
        public static function areServerVarsBad( $vars, $extWhitelist = array() ) {
                // Check QUERY_STRING or REQUEST_URI
@@ -55,7 +56,7 @@ class IEUrlExtension {
                        return true;
                }
 
-               // Some servers have PATH_INFO but not REQUEST_URI, so we check both 
+               // Some servers have PATH_INFO but not REQUEST_URI, so we check both
                // to be on the safe side.
                if ( isset( $vars['PATH_INFO'] )
                        && self::isUrlExtensionBad( $vars['PATH_INFO'], $extWhitelist ) )
@@ -71,7 +72,7 @@ class IEUrlExtension {
         * Given a right-hand portion of a URL, determine whether IE would detect
         * a potentially harmful file extension.
         *
-        * @param $urlPart The right-hand portion of a URL
+        * @param $urlPart string The right-hand portion of a URL
         * @param $extWhitelist An array of file extensions which may occur in this
         *    URL, and which should be allowed.
         * @return bool
@@ -97,10 +98,10 @@ class IEUrlExtension {
                }
 
                if ( !preg_match( '/^[a-zA-Z0-9_-]+$/', $extension ) ) {
-                       // Non-alphanumeric extension, unlikely to be registered. 
+                       // Non-alphanumeric extension, unlikely to be registered.
                        //
                        // The regex above is known to match all registered file extensions
-                       // in a default Windows XP installation. It's important to allow 
+                       // in a default Windows XP installation. It's important to allow
                        // extensions with ampersands and percent signs, since that reduces
                        // the number of false positives substantially.
                        return false;
@@ -111,8 +112,11 @@ class IEUrlExtension {
        }
 
        /**
-        * Returns a variant of $url which will pass isUrlExtensionBad() but has the 
+        * Returns a variant of $url which will pass isUrlExtensionBad() but has the
         * same GET parameters, or false if it can't figure one out.
+        * @param $url
+        * @param $extWhitelist array
+        * @return bool|string
         */
        public static function fixUrlForIE6( $url, $extWhitelist = array() ) {
                $questionPos = strpos( $url, '?' );
@@ -127,7 +131,7 @@ class IEUrlExtension {
                        $query = substr( $url, $questionPos + 1 );
                }
 
-               // Multiple question marks cause problems. Encode the second and 
+               // Multiple question marks cause problems. Encode the second and
                // subsequent question mark.
                $query = str_replace( '?', '%3E', $query );
                // Append an invalid path character so that IE6 won't see the end of the
@@ -153,16 +157,16 @@ class IEUrlExtension {
         * insecure.
         *
         * The criteria for finding an extension are as follows:
-        * - a possible extension is a dot followed by one or more characters not 
+        * - a possible extension is a dot followed by one or more characters not
         *   in <>\"/:|?.#
-        * - 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 );
index dd3207d..7ddedb9 100644 (file)
@@ -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' ),