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;
}
$this->closing = $closing;
}
+ /**
+ * @return _DiffOp_Copy
+ */
function reverse() {
return new _DiffOp_Copy( $this->closing, $this->orig );
}
$this->closing = false;
}
+ /**
+ * @return _DiffOp_Add
+ */
function reverse() {
return new _DiffOp_Add( $this->orig );
}
$this->orig = false;
}
+ /**
+ * @return _DiffOp_Delete
+ */
function reverse() {
return new _DiffOp_Delete( $this->closing );
}
$this->closing = $closing;
}
+ /**
+ * @return _DiffOp_Change
+ */
function reverse() {
return new _DiffOp_Change( $this->closing, $this->orig );
}
protected $lcs = 0;
+ /**
+ * @param $from_lines
+ * @param $to_lines
+ * @return array
+ */
function diff ( $from_lines, $to_lines ) {
wfProfileIn( __METHOD__ );
return $edits;
}
+ /**
+ * @param $from_lines
+ * @param $to_lines
+ */
function diff_local ( $from_lines, $to_lines ) {
global $wgExternalDiffEngine;
wfProfileIn( __METHOD__ );
/**
* 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 ) {
* 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;
return array( $this->lcs, $seps );
}
+ /**
+ * @param $ypos
+ * @return int
+ */
function _lcs_pos( $ypos ) {
$end = $this->lcs;
if ( $end == 0 || $ypos > $this->seq[$end] ) {
*
* 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.
* 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__ );
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 ) );
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 );
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";
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 @@";
}
* @ingroup DifferenceEngine
*/
class ArrayDiffFormatter extends DiffFormatter {
+
+ /**
+ * @param $diff
+ * @return array
+ */
function format( $diff ) {
$oldline = 1;
$newline = 1;
$this->_tag = '';
}
+ /**
+ * @param $new_tag
+ */
function _flushGroup( $new_tag ) {
if ( $this->_group !== '' ) {
if ( $this->_tag == 'ins' ) {
$this->_tag = $new_tag;
}
+ /**
+ * @param $new_tag
+ */
function _flushLine( $new_tag ) {
$this->_flushGroup( $new_tag );
if ( $this->_line != '' ) {
$this->_line = '';
}
+ /**
+ * @param $words
+ * @param $tag string
+ */
function addWords ( $words, $tag = '' ) {
if ( $tag != $this->_tag ) {
$this->_flushGroup( $tag );
}
}
+ /**
+ * @return array
+ */
function getLines() {
$this->_flushLine( '~done' );
return $this->_lines;
class WordLevelDiff extends MappedDiff {
const MAX_LINE_LENGTH = 10000;
+ /**
+ * @param $orig_lines
+ * @param $closing_lines
+ */
function __construct ( $orig_lines, $closing_lines ) {
wfProfileIn( __METHOD__ );
wfProfileOut( __METHOD__ );
}
+ /**
+ * @param $lines
+ * @return array
+ */
function _split( $lines ) {
wfProfileIn( __METHOD__ );
return array( $words, $stripped );
}
+ /**
+ * @return array
+ */
function orig() {
wfProfileIn( __METHOD__ );
$orig = new _HWLDF_WordAccumulator;
return $lines;
}
+ /**
+ * @return array
+ */
function closing() {
wfProfileIn( __METHOD__ );
$closing = new _HWLDF_WordAccumulator;
$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 );
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;
}
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 <div> wrapper is needed for 'overflow: auto' style to scroll properly
return "<td class='diff-marker'>$marker</td><td class='$class'>$line</td>";
}
+ /**
+ * @return string
+ */
function emptyLine() {
return '<td colspan="2"> </td>';
}
+ /**
+ * @param $lines array
+ */
function _added( $lines ) {
foreach ( $lines as $line ) {
echo '<tr>' . $this->emptyLine() .
}
}
+ /**
+ * @param $lines
+ */
function _deleted( $lines ) {
foreach ( $lines as $line ) {
echo '<tr>' . $this->deletedLine( '<del class="diffchange">' .
}
}
+ /**
+ * @param $lines
+ */
function _context( $lines ) {
foreach ( $lines as $line ) {
echo '<tr>' .
}
}
+ /**
+ * @param $orig
+ * @param $closing
+ */
function _changed( $orig, $closing ) {
wfProfileIn( __METHOD__ );
*/
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
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()
continue;
}
- $jobs[] = new self( $title, array(
+ $jobs[] = new self( $title, array(
'reason' => $reason,
'redirTitle' => $redirTitle->getPrefixedDBkey() ) );
# Avoid excessive memory usage
$this->destTitleText = !empty( $params['destTitle'] ) ? $params['destTitle'] : '';
}
+ /**
+ * @return bool
+ */
function run() {
if ( !$this->redirTitle ) {
$this->setLastError( 'Invalid title' );
}
# 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 );
$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;
}
$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()
/**
* Get a user object for doing edits, from a request-lifetime cache
+ * @return User
*/
function getUser() {
if ( !self::$user ) {
throw new MWException( "Invalid job command `{$command}`" );
}
+ /**
+ * @param $params
+ * @return string
+ */
static function makeBlob( $params ) {
if ( $params !== false ) {
return serialize( $params );
}
}
+ /**
+ * @param $blob
+ * @return bool|mixed
+ */
static function extractBlob( $blob ) {
if ( (string)$blob !== '' ) {
return unserialize( $blob );
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(
}
}
+ /**
+ * @return string
+ */
function toString() {
$paramString = '';
if ( $this->params ) {
# Stash the upload
$key = $this->upload->stashFile();
-
+
if ( $this->params['leaveMessage'] ) {
$this->user->leaveUserMessage(
wfMsg( 'upload-warning-subj' ),
$this->params['url'] )
);
} else {
- wfSetupSession( $this->params['sessionId'] );
+ wfSetupSession( $this->params['sessionId'] );
$this->storeResultInSession( 'Warning',
'warnings', $warnings );
session_write_close();
$$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();
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
*
* 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 ) {
/**
* 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
return json_decode( $value, $assoc );
}
}
-
+
}
*
* 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'],
/**
* 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 );
/**
* 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 );
/**
* 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 );
/**
* 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'],
* 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 );
/**
* Flip horizontal background percentages.
+ * @param $css string
+ * @return string
*/
private static function fixBackgroundPosition( $css ) {
$css = preg_replace_callback( self::$patterns['bg_horizontal_percentage'],
/**
* Callback for calculateNewBackgroundPosition()
+ * @param $matches array
+ * @return string
*/
private static function calculateNewBackgroundPosition( $matches ) {
return $matches[1] . ( 100 - $matches[2] ) . $matches[3];
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;
array( $this, 'detokenizeCallback' ), $str );
}
+ /**
+ * @param $matches
+ * @return mixed
+ */
private function detokenizeCallback( $matches ) {
$retval = current( $this->originals );
next( $this->originals );
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
<?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.
*/
protected $baseTypeTable = array(
'ambiguous' /*1*/ => array(
- 'text/plain',
- 'application/octet-stream',
+ 'text/plain',
+ 'application/octet-stream',
'application/x-netcdf', // [sic]
),
'text' /*3*/ => array(
),
'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'
'.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] ) ) {
}
/**
- * 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)
/**
* 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(
/**
* 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
// 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'];
return 'image/gif';
}
if ( ( $proposed == 'image/pjpeg' || $proposed == 'image/jpeg' )
- && $binaryType == 'image/pjpeg' )
+ && $binaryType == 'image/pjpeg' )
{
return $proposed;
}
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';
// 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;
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.
/**
* 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 );
/**
* 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 );
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';
/**
* 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();
}
if ( !strncasecmp( $remainder, $rdfPurl, strlen( $rdfPurl ) ) ) {
- if ( isset( $found['rdf-tag'] )
+ if ( isset( $found['rdf-tag'] )
&& isset( $found['rdf-url'] ) ) // [sic]
{
break;
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 ) === '' ) {
<?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
*
* @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
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 ) )
* 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
}
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;
}
/**
- * 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, '?' );
$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
* 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
*/
// End of string, we're done
return false;
}
-
+
// We found a dot. Skip past it
$pos++;
$remainingLength = $urlLength - $pos;
* 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
*/
public static function haveUndecodedRequestUri( $serverSoftware ) {
static $whitelist = array(
- 'Apache',
- 'Zeus',
+ 'Apache',
+ 'Zeus',
'LiteSpeed' );
if ( preg_match( '/^(.*?)($|\/| )/', $serverSoftware, $m ) ) {
return in_array( $m[1], $whitelist );
/**
* Test Http::isValidURI()
- * @bug 27854 : Http::isValidURI is to lax
+ * @bug 27854 : Http::isValidURI is too lax
* @dataProvider provideURI
*/
function testIsValidUri( $expect, $URI, $message = '' ) {
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' ),