Siebrand has uploaded a new change for review.
https://gerrit.wikimedia.org/r/93440
Change subject: Update formatting
......................................................................
Update formatting
Change-Id: I5ec6257295261caab6cb2d9eb9d32ce76cae08a2
---
M includes/utils/ArrayUtils.php
M includes/utils/Cdb.php
M includes/utils/Cdb_PHP.php
M includes/utils/ConfEditor.php
M includes/utils/HashRing.php
M includes/utils/IP.php
M includes/utils/MWCryptRand.php
M includes/utils/MWFunction.php
M includes/utils/MappedIterator.php
M includes/utils/StringUtils.php
M includes/utils/UIDGenerator.php
M includes/utils/ZipDirectoryReader.php
12 files changed, 322 insertions(+), 241 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/40/93440/1
diff --git a/includes/utils/ArrayUtils.php b/includes/utils/ArrayUtils.php
index 97a56e1..a222f81 100644
--- a/includes/utils/ArrayUtils.php
+++ b/includes/utils/ArrayUtils.php
@@ -63,6 +63,7 @@
break;
}
}
+
return $i;
}
}
diff --git a/includes/utils/Cdb.php b/includes/utils/Cdb.php
index 81c0afe..996b7af 100644
--- a/includes/utils/Cdb.php
+++ b/includes/utils/Cdb.php
@@ -38,6 +38,7 @@
return new CdbReader_DBA( $fileName );
} else {
wfDebug( "Warning: no dba extension found, using
emulation.\n" );
+
return new CdbReader_PHP( $fileName );
}
}
@@ -55,6 +56,7 @@
if ( !in_array( 'cdb', $handlers ) || !in_array( 'cdb_make',
$handlers ) ) {
return false;
}
+
return true;
}
@@ -94,6 +96,7 @@
return new CdbWriter_DBA( $fileName );
} else {
wfDebug( "Warning: no dba extension found, using
emulation.\n" );
+
return new CdbWriter_PHP( $fileName );
}
}
diff --git a/includes/utils/Cdb_PHP.php b/includes/utils/Cdb_PHP.php
index a38b9a8..8c10b53 100644
--- a/includes/utils/Cdb_PHP.php
+++ b/includes/utils/Cdb_PHP.php
@@ -40,6 +40,7 @@
public static function unsignedMod( $a, $b ) {
if ( $a & 0x80000000 ) {
$m = ( $a & 0x7fffffff ) % $b + 2 * ( 0x40000000 % $b );
+
return $m % $b;
} else {
return $a % $b;
@@ -89,6 +90,7 @@
$h ^= ord( $s[$i] );
$h &= 0xffffffff;
}
+
return $h;
}
}
@@ -164,6 +166,7 @@
*/
protected function match( $key, $pos ) {
$buf = $this->read( strlen( $key ), $pos );
+
return $buf === $key;
}
@@ -193,6 +196,7 @@
throw new MWException(
'Read from CDB file failed, file "' .
$this->fileName . '" may be corrupted.' );
}
+
return $buf;
}
@@ -208,6 +212,7 @@
throw new MWException(
'Error in CDB file "' . $this->fileName . '",
integer too big.' );
}
+
return $data[1];
}
@@ -218,6 +223,7 @@
*/
protected function unpackSigned( $s ) {
$data = unpack( 'va/vb', $s );
+
return $data['a'] | ( $data['b'] << 16 );
}
@@ -260,10 +266,12 @@
// Found
$this->dlen = $this->unpack31( substr(
$buf, 4 ) );
$this->dpos = $pos + 8 + $keyLen;
+
return true;
}
}
}
+
return false;
}
@@ -273,6 +281,7 @@
*/
protected function find( $key ) {
$this->findStart();
+
return $this->findNext( $key );
}
}
@@ -411,7 +420,7 @@
// Calculate the number of items that will be in each hashtable
$counts = array_fill( 0, 256, 0 );
foreach ( $this->hplist as $item ) {
- ++ $counts[255 & $item['h']];
+ ++$counts[255 & $item['h']];
}
// Fill in $starts with the *end* indexes
diff --git a/includes/utils/ConfEditor.php b/includes/utils/ConfEditor.php
index 67cb87d..163f73c 100644
--- a/includes/utils/ConfEditor.php
+++ b/includes/utils/ConfEditor.php
@@ -115,6 +115,7 @@
} catch ( ConfEditorParseError $e ) {
return $e->getMessage() . "\n" . $e->highlight( $text );
}
+
return "OK";
}
@@ -174,78 +175,78 @@
$key = isset( $op['key'] ) ? $op['key'] : null;
switch ( $type ) {
- case 'delete':
- list( $start, $end ) =
$this->findDeletionRegion( $path );
- $this->replaceSourceRegion( $start, $end, false
);
- break;
- case 'set':
- if ( isset( $this->pathInfo[$path] ) ) {
- list( $start, $end ) =
$this->findValueRegion( $path );
- $encValue = $value; // var_export(
$value, true );
- $this->replaceSourceRegion( $start,
$end, $encValue );
+ case 'delete':
+ list( $start, $end ) =
$this->findDeletionRegion( $path );
+ $this->replaceSourceRegion( $start,
$end, false );
break;
- }
- // No existing path, fall through to append
- $slashPos = strrpos( $path, '/' );
- $key = var_export( substr( $path, $slashPos + 1
), true );
- $path = substr( $path, 0, $slashPos );
- // Fall through
- case 'append':
- // Find the last array element
- $lastEltPath = $this->findLastArrayElement(
$path );
- if ( $lastEltPath === false ) {
- throw new MWException( "Can't find any
element of array \"$path\"" );
- }
- $lastEltInfo = $this->pathInfo[$lastEltPath];
+ case 'set':
+ if ( isset( $this->pathInfo[$path] ) ) {
+ list( $start, $end ) =
$this->findValueRegion( $path );
+ $encValue = $value; //
var_export( $value, true );
+ $this->replaceSourceRegion(
$start, $end, $encValue );
+ break;
+ }
+ // No existing path, fall through to
append
+ $slashPos = strrpos( $path, '/' );
+ $key = var_export( substr( $path,
$slashPos + 1 ), true );
+ $path = substr( $path, 0, $slashPos );
+ // Fall through
+ case 'append':
+ // Find the last array element
+ $lastEltPath =
$this->findLastArrayElement( $path );
+ if ( $lastEltPath === false ) {
+ throw new MWException( "Can't
find any element of array \"$path\"" );
+ }
+ $lastEltInfo =
$this->pathInfo[$lastEltPath];
- // Has it got a comma already?
- if ( strpos( $lastEltPath, '@extra' ) === false
&& !$lastEltInfo['hasComma'] ) {
- // No comma, insert one after the value
region
- list( , $end ) =
$this->findValueRegion( $lastEltPath );
- $this->replaceSourceRegion( $end - 1,
$end - 1, ',' );
- }
+ // Has it got a comma already?
+ if ( strpos( $lastEltPath, '@extra' )
=== false && !$lastEltInfo['hasComma'] ) {
+ // No comma, insert one after
the value region
+ list( , $end ) =
$this->findValueRegion( $lastEltPath );
+ $this->replaceSourceRegion(
$end - 1, $end - 1, ',' );
+ }
- // Make the text to insert
- list( $start, $end ) =
$this->findDeletionRegion( $lastEltPath );
+ // Make the text to insert
+ list( $start, $end ) =
$this->findDeletionRegion( $lastEltPath );
- if ( $key === null ) {
- list( $indent, ) = $this->getIndent(
$start );
- $textToInsert = "$indent$value,";
- } else {
- list( $indent, $arrowIndent ) =
- $this->getIndent( $start, $key,
$lastEltInfo['arrowByte'] );
- $textToInsert =
"$indent$key$arrowIndent=> $value,";
- }
- $textToInsert .= ( $indent === false ? ' ' :
"\n" );
+ if ( $key === null ) {
+ list( $indent, ) =
$this->getIndent( $start );
+ $textToInsert =
"$indent$value,";
+ } else {
+ list( $indent, $arrowIndent ) =
+ $this->getIndent(
$start, $key, $lastEltInfo['arrowByte'] );
+ $textToInsert =
"$indent$key$arrowIndent=> $value,";
+ }
+ $textToInsert .= ( $indent === false ?
' ' : "\n" );
- // Insert the item
- $this->replaceSourceRegion( $end, $end,
$textToInsert );
- break;
- case 'insert':
- // Find first array element
- $firstEltPath = $this->findFirstArrayElement(
$path );
- if ( $firstEltPath === false ) {
- throw new MWException( "Can't find
array element of \"$path\"" );
- }
- list( $start, ) = $this->findDeletionRegion(
$firstEltPath );
- $info = $this->pathInfo[$firstEltPath];
+ // Insert the item
+ $this->replaceSourceRegion( $end, $end,
$textToInsert );
+ break;
+ case 'insert':
+ // Find first array element
+ $firstEltPath =
$this->findFirstArrayElement( $path );
+ if ( $firstEltPath === false ) {
+ throw new MWException( "Can't
find array element of \"$path\"" );
+ }
+ list( $start, ) =
$this->findDeletionRegion( $firstEltPath );
+ $info = $this->pathInfo[$firstEltPath];
- // Make the text to insert
- if ( $key === null ) {
- list( $indent, ) = $this->getIndent(
$start );
- $textToInsert = "$indent$value,";
- } else {
- list( $indent, $arrowIndent ) =
- $this->getIndent( $start, $key,
$info['arrowByte'] );
- $textToInsert =
"$indent$key$arrowIndent=> $value,";
- }
- $textToInsert .= ( $indent === false ? ' ' :
"\n" );
+ // Make the text to insert
+ if ( $key === null ) {
+ list( $indent, ) =
$this->getIndent( $start );
+ $textToInsert =
"$indent$value,";
+ } else {
+ list( $indent, $arrowIndent ) =
+ $this->getIndent(
$start, $key, $info['arrowByte'] );
+ $textToInsert =
"$indent$key$arrowIndent=> $value,";
+ }
+ $textToInsert .= ( $indent === false ?
' ' : "\n" );
- // Insert the item
- $this->replaceSourceRegion( $start, $start,
$textToInsert );
- break;
- default:
- throw new MWException( "Unrecognised operation:
\"$type\"" );
+ // Insert the item
+ $this->replaceSourceRegion( $start,
$start, $textToInsert );
+ break;
+ default:
+ throw new MWException( "Unrecognised
operation: \"$type\"" );
}
}
@@ -268,6 +269,7 @@
"Sorry, ConfEditor broke the file during
editing and it won't parse anymore: " .
$e->getMessage() );
}
+
return $out;
}
@@ -302,6 +304,7 @@
$this->setVar( $vars, $parentPath, $name,
$this->parseScalar( $value ) );
}
+
return $vars;
}
@@ -359,6 +362,7 @@
if ( substr( $str, 0, 4 ) == 'null' ) {
return null;
}
+
// Must be some kind of numeric value, so let PHP's weak typing
// be useful for a change
return $str;
@@ -454,6 +458,7 @@
break;
}
}
+
return array( $regionStart, $regionEnd );
}
@@ -475,6 +480,7 @@
if ( $path['valueStartByte'] === false || $path['valueEndByte']
=== false ) {
throw new MWException( "Can't find value region for
path \"$pathName\"" );
}
+
return array( $path['valueStartByte'], $path['valueEndByte'] );
}
@@ -512,6 +518,7 @@
break;
}
}
+
return $extraPath;
}
@@ -538,6 +545,7 @@
return $candidatePath;
}
}
+
return false;
}
@@ -560,6 +568,7 @@
$arrowIndent = str_repeat( ' ',
$arrowIndentLength );
}
}
+
return array( $indent, $arrowIndent );
}
@@ -580,32 +589,137 @@
}
switch ( $state ) {
- case 'file':
- $this->expect( T_OPEN_TAG );
- $token = $this->skipSpace();
- if ( $token->isEnd() ) {
- break 2;
- }
- $this->pushState( 'statement', 'file 2' );
- break;
- case 'file 2':
- $token = $this->skipSpace();
- if ( $token->isEnd() ) {
- break 2;
- }
- $this->pushState( 'statement', 'file 2' );
- break;
- case 'statement':
- $token = $this->skipSpace();
- if ( !$this->validatePath( $token->text ) ) {
- $this->error( "Invalid variable name
\"{$token->text}\"" );
- }
- $this->nextPath( $token->text );
- $this->expect( T_VARIABLE );
- $this->skipSpace();
- $arrayAssign = false;
- if ( $this->currentToken()->type == '[' ) {
- $this->nextToken();
+ case 'file':
+ $this->expect( T_OPEN_TAG );
+ $token = $this->skipSpace();
+ if ( $token->isEnd() ) {
+ break 2;
+ }
+ $this->pushState( 'statement', 'file 2'
);
+ break;
+ case 'file 2':
+ $token = $this->skipSpace();
+ if ( $token->isEnd() ) {
+ break 2;
+ }
+ $this->pushState( 'statement', 'file 2'
);
+ break;
+ case 'statement':
+ $token = $this->skipSpace();
+ if ( !$this->validatePath( $token->text
) ) {
+ $this->error( "Invalid variable
name \"{$token->text}\"" );
+ }
+ $this->nextPath( $token->text );
+ $this->expect( T_VARIABLE );
+ $this->skipSpace();
+ $arrayAssign = false;
+ if ( $this->currentToken()->type == '['
) {
+ $this->nextToken();
+ $token = $this->skipSpace();
+ if ( !$token->isScalar() ) {
+ $this->error( "expected
a string or number for the array key" );
+ }
+ if ( $token->type ==
T_CONSTANT_ENCAPSED_STRING ) {
+ $text =
$this->parseScalar( $token->text );
+ } else {
+ $text = $token->text;
+ }
+ if ( !$this->validatePath(
$text ) ) {
+ $this->error( "Invalid
associative array name \"$text\"" );
+ }
+ $this->pushPath( $text );
+ $this->nextToken();
+ $this->skipSpace();
+ $this->expect( ']' );
+ $this->skipSpace();
+ $arrayAssign = true;
+ }
+ $this->expect( '=' );
+ $this->skipSpace();
+ $this->startPathValue();
+ if ( $arrayAssign ) {
+ $this->pushState( 'expression',
'array assign end' );
+ } else {
+ $this->pushState( 'expression',
'statement end' );
+ }
+ break;
+ case 'array assign end':
+ case 'statement end':
+ $this->endPathValue();
+ if ( $state == 'array assign end' ) {
+ $this->popPath();
+ }
+ $this->skipSpace();
+ $this->expect( ';' );
+ $this->nextPath( '@extra-' . (
$this->serial++ ) );
+ break;
+ case 'expression':
+ $token = $this->skipSpace();
+ if ( $token->type == T_ARRAY ) {
+ $this->pushState( 'array' );
+ } elseif ( $token->isScalar() ) {
+ $this->nextToken();
+ } elseif ( $token->type == T_VARIABLE )
{
+ $this->nextToken();
+ } else {
+ $this->error( "expected simple
expression" );
+ }
+ break;
+ case 'array':
+ $this->skipSpace();
+ $this->expect( T_ARRAY );
+ $this->skipSpace();
+ $this->expect( '(' );
+ $this->skipSpace();
+ $this->pushPath( '@extra-' . (
$this->serial++ ) );
+ if ( $this->isAhead( ')' ) ) {
+ // Empty array
+ $this->pushState( 'array end' );
+ } else {
+ $this->pushState( 'element',
'array end' );
+ }
+ break;
+ case 'array end':
+ $this->skipSpace();
+ $this->popPath();
+ $this->expect( ')' );
+ break;
+ case 'element':
+ $token = $this->skipSpace();
+ // Look ahead to find the double arrow
+ if ( $token->isScalar() &&
$this->isAhead( T_DOUBLE_ARROW, 1 ) ) {
+ // Found associative element
+ $this->pushState(
'assoc-element', 'element end' );
+ } else {
+ // Not associative
+ $this->nextPath( '@next' );
+ $this->startPathValue();
+ $this->pushState( 'expression',
'element end' );
+ }
+ break;
+ case 'element end':
+ $token = $this->skipSpace();
+ if ( $token->type == ',' ) {
+ $this->endPathValue();
+ $this->markComma();
+ $this->nextToken();
+ $this->nextPath( '@extra-' . (
$this->serial++ ) );
+ // Look ahead to find ending
bracket
+ if ( $this->isAhead( ")" ) ) {
+ // Found ending
bracket, no continuation
+ $this->skipSpace();
+ } else {
+ // No ending bracket,
continue to next element
+ $this->pushState(
'element' );
+ }
+ } elseif ( $token->type == ')' ) {
+ // End array
+ $this->endPathValue();
+ } else {
+ $this->error( "expected the
next array element or the end of the array" );
+ }
+ break;
+ case 'assoc-element':
$token = $this->skipSpace();
if ( !$token->isScalar() ) {
$this->error( "expected a
string or number for the array key" );
@@ -618,120 +732,15 @@
if ( !$this->validatePath( $text ) ) {
$this->error( "Invalid
associative array name \"$text\"" );
}
- $this->pushPath( $text );
+ $this->nextPath( $text );
$this->nextToken();
$this->skipSpace();
- $this->expect( ']' );
+ $this->markArrow();
+ $this->expect( T_DOUBLE_ARROW );
$this->skipSpace();
- $arrayAssign = true;
- }
- $this->expect( '=' );
- $this->skipSpace();
- $this->startPathValue();
- if ( $arrayAssign ) {
- $this->pushState( 'expression', 'array
assign end' );
- } else {
- $this->pushState( 'expression',
'statement end' );
- }
- break;
- case 'array assign end':
- case 'statement end':
- $this->endPathValue();
- if ( $state == 'array assign end' ) {
- $this->popPath();
- }
- $this->skipSpace();
- $this->expect( ';' );
- $this->nextPath( '@extra-' . ( $this->serial++
) );
- break;
- case 'expression':
- $token = $this->skipSpace();
- if ( $token->type == T_ARRAY ) {
- $this->pushState( 'array' );
- } elseif ( $token->isScalar() ) {
- $this->nextToken();
- } elseif ( $token->type == T_VARIABLE ) {
- $this->nextToken();
- } else {
- $this->error( "expected simple
expression" );
- }
- break;
- case 'array':
- $this->skipSpace();
- $this->expect( T_ARRAY );
- $this->skipSpace();
- $this->expect( '(' );
- $this->skipSpace();
- $this->pushPath( '@extra-' . ( $this->serial++
) );
- if ( $this->isAhead( ')' ) ) {
- // Empty array
- $this->pushState( 'array end' );
- } else {
- $this->pushState( 'element', 'array
end' );
- }
- break;
- case 'array end':
- $this->skipSpace();
- $this->popPath();
- $this->expect( ')' );
- break;
- case 'element':
- $token = $this->skipSpace();
- // Look ahead to find the double arrow
- if ( $token->isScalar() && $this->isAhead(
T_DOUBLE_ARROW, 1 ) ) {
- // Found associative element
- $this->pushState( 'assoc-element',
'element end' );
- } else {
- // Not associative
- $this->nextPath( '@next' );
$this->startPathValue();
- $this->pushState( 'expression',
'element end' );
- }
- break;
- case 'element end':
- $token = $this->skipSpace();
- if ( $token->type == ',' ) {
- $this->endPathValue();
- $this->markComma();
- $this->nextToken();
- $this->nextPath( '@extra-' . (
$this->serial++ ) );
- // Look ahead to find ending bracket
- if ( $this->isAhead( ")" ) ) {
- // Found ending bracket, no
continuation
- $this->skipSpace();
- } else {
- // No ending bracket, continue
to next element
- $this->pushState( 'element' );
- }
- } elseif ( $token->type == ')' ) {
- // End array
- $this->endPathValue();
- } else {
- $this->error( "expected the next array
element or the end of the array" );
- }
- break;
- case 'assoc-element':
- $token = $this->skipSpace();
- if ( !$token->isScalar() ) {
- $this->error( "expected a string or
number for the array key" );
- }
- if ( $token->type == T_CONSTANT_ENCAPSED_STRING
) {
- $text = $this->parseScalar(
$token->text );
- } else {
- $text = $token->text;
- }
- if ( !$this->validatePath( $text ) ) {
- $this->error( "Invalid associative
array name \"$text\"" );
- }
- $this->nextPath( $text );
- $this->nextToken();
- $this->skipSpace();
- $this->markArrow();
- $this->expect( T_DOUBLE_ARROW );
- $this->skipSpace();
- $this->startPathValue();
- $this->pushState( 'expression' );
- break;
+ $this->pushState( 'expression' );
+ break;
}
}
if ( count( $this->stateStack ) ) {
@@ -763,6 +772,7 @@
} else {
$this->currentToken = $this->newTokenObj(
$this->tokens[$this->pos] );
}
+
return $this->currentToken;
}
@@ -787,6 +797,7 @@
$this->lineNum = 1;
$this->colNum = 1;
$this->byteNum = 0;
+
return $this->currentToken;
}
@@ -814,6 +825,7 @@
}
$this->prevToken = $this->currentToken;
$this->setPos( $this->pos + 1 );
+
return $this->currentToken;
}
@@ -838,6 +850,7 @@
while ( $this->currentToken && $this->currentToken->isSkip() ) {
$this->nextToken();
}
+
return $this->currentToken;
}
@@ -1028,6 +1041,7 @@
return false;
}
}
+
return false;
}
@@ -1058,6 +1072,7 @@
*/
class ConfEditorParseError extends MWException {
var $lineNum, $colNum;
+
function __construct( $editor, $msg ) {
$this->lineNum = $editor->lineNum;
$this->colNum = $editor->colNum;
@@ -1072,9 +1087,9 @@
return "$line\n" . str_repeat( ' ',
$this->colNum - 1 ) . "^\n";
}
}
+
return '';
}
-
}
/**
diff --git a/includes/utils/HashRing.php b/includes/utils/HashRing.php
index 930f8c0..c152d41 100644
--- a/includes/utils/HashRing.php
+++ b/includes/utils/HashRing.php
@@ -38,7 +38,9 @@
* @param array $map (location => weight)
*/
public function __construct( array $map ) {
- $map = array_filter( $map, function( $w ) { return $w > 0; } );
+ $map = array_filter( $map, function ( $w ) {
+ return $w > 0;
+ } );
if ( !count( $map ) ) {
throw new MWException( "Ring is empty or all weights
are zero." );
}
@@ -77,6 +79,7 @@
*/
public function getLocation( $item ) {
$locations = $this->getLocations( $item, 1 );
+
return $locations[0];
}
@@ -113,6 +116,7 @@
}
$locations[] = $location;
}
+
return $locations;
}
@@ -137,6 +141,7 @@
if ( count( $map ) ) {
return new self( $map );
}
+
return false;
}
}
diff --git a/includes/utils/IP.php b/includes/utils/IP.php
index 73834a5..002dcd9 100644
--- a/includes/utils/IP.php
+++ b/includes/utils/IP.php
@@ -175,6 +175,7 @@
}
// Remove leading zeros from each bloc as needed
$ip = preg_replace( '/(^|:)0+(' . RE_IPV6_WORD . ')/', '$1$2',
$ip );
+
return $ip;
}
@@ -218,6 +219,7 @@
// Convert to lower case to make it more readable
$ip = strtolower( $ip );
}
+
return $ip;
}
@@ -270,6 +272,7 @@
return false;
}
}
+
// Plain hostname
return array( $both, false );
}
@@ -336,6 +339,7 @@
}
// NO leading zeroes
$ip_oct = preg_replace( '/(^|:)0+(' . RE_IPV6_WORD . ')/',
'$1$2', $ip_oct );
+
return $ip_oct;
}
@@ -356,6 +360,7 @@
}
$s .= base_convert( substr( $ip_hex, $i * 2, 2 ), 16,
10 );
}
+
return $s;
}
@@ -400,6 +405,7 @@
return false;
}
}
+
return true;
}
@@ -426,6 +432,7 @@
return false;
}
}
+
return true;
}
@@ -449,6 +456,7 @@
$n = wfBaseConvert( $n, 10, 16, 8, false );
}
}
+
return $n;
}
@@ -467,6 +475,7 @@
foreach ( explode( ':', $ip ) as $v ) {
$r_ip .= str_pad( $v, 4, 0, STR_PAD_LEFT );
}
+
return $r_ip;
}
@@ -492,6 +501,7 @@
}
}
}
+
return $n;
}
@@ -534,6 +544,7 @@
$network = false;
$bits = false;
}
+
return array( $network, $bits );
}
@@ -546,9 +557,9 @@
* 1.2.3.4 - 1.2.3.5 Explicit range
* 1.2.3.4 Single IP
*
- * 2001:0db8:85a3::7344/96 CIDR
+ * 2001:0db8:85a3::7344/96 CIDR
* 2001:0db8:85a3::7344 - 2001:0db8:85a3::7344 Explicit range
- * 2001:0db8:85a3::7344 Single
IP
+ * 2001:0db8:85a3::7344 Single IP
* @param string $range IP range
* @return array(string, string)
*/
@@ -626,6 +637,7 @@
$network = false;
$bits = false;
}
+
return array( $network, (int)$bits );
}
@@ -634,9 +646,9 @@
* start and end of the range in hexadecimal. For IPv6.
*
* Formats are:
- * 2001:0db8:85a3::7344/96 CIDR
+ * 2001:0db8:85a3::7344/96 CIDR
* 2001:0db8:85a3::7344 - 2001:0db8:85a3::7344 Explicit range
- * 2001:0db8:85a3::7344/96 Single
IP
+ * 2001:0db8:85a3::7344/96 Single IP
*
* @param $range
*
@@ -662,7 +674,7 @@
$start = "v6-$start";
$end = "v6-$end";
}
- // Explicit range notation...
+ // Explicit range notation...
} elseif ( strpos( $range, '-' ) !== false ) {
list( $start, $end ) = array_map( 'trim', explode( '-',
$range, 2 ) );
$start = self::toUnsigned6( $start );
@@ -697,6 +709,7 @@
public static function isInRange( $addr, $range ) {
$hexIP = self::toHex( $addr );
list( $start, $end ) = self::parseRange( $range );
+
return ( strcmp( $hexIP, $start ) >= 0 &&
strcmp( $hexIP, $end ) <= 0 );
}
@@ -735,8 +748,8 @@
return $m[1];
}
if ( preg_match( '/^' . RE_IPV6_V4_PREFIX . RE_IPV6_WORD .
- ':' . RE_IPV6_WORD . '$/i', $addr, $m ) )
- {
+ ':' . RE_IPV6_WORD . '$/i', $addr, $m )
+ ) {
return long2ip( ( hexdec( $m[1] ) << 16 ) + hexdec(
$m[2] ) );
}
@@ -756,6 +769,7 @@
if ( $bits === false ) {
return $start; // wasn't actually a range
}
+
return "$start/$bits";
}
}
diff --git a/includes/utils/MWCryptRand.php b/includes/utils/MWCryptRand.php
index bac018e..d71193f 100644
--- a/includes/utils/MWCryptRand.php
+++ b/includes/utils/MWCryptRand.php
@@ -189,6 +189,7 @@
"(time-taken=" . ( $timeTaken * 1000 ) . "ms, " .
"iterations=$iterations, " .
"time-per-iteration=" . ( $timeTaken / $iterations *
1e6 ) . "us)\n" );
+
return $data;
}
@@ -207,6 +208,7 @@
// Generate a new random state based on the initial random
state or previous
// random state by combining it with clock drift
$state = $this->driftHash( $state );
+
return $state;
}
@@ -227,6 +229,7 @@
if ( in_array( $algorithm, $algos ) ) {
$this->algo = $algorithm;
wfDebug( __METHOD__ . ": Using the
{$this->algo} hash algorithm.\n" );
+
return $this->algo;
}
}
@@ -249,6 +252,7 @@
if ( is_null( $this->hashLength ) ) {
$this->hashLength = strlen( $this->hash( '' ) );
}
+
return $this->hashLength;
}
@@ -282,6 +286,7 @@
if ( is_null( $this->strong ) ) {
throw new MWException( __METHOD__ . ' called before
generation of random data' );
}
+
return $this->strong;
}
@@ -415,6 +420,7 @@
wfDebug( __METHOD__ . ": " . strlen( $buffer ) . " bytes of
randomness leftover in the buffer.\n" );
wfProfileOut( __METHOD__ );
+
return $generated;
}
@@ -428,6 +434,7 @@
$bytes = ceil( $chars / 2 );
// Generate the data and then convert it to a hex string
$hex = bin2hex( $this->generate( $bytes, $forceStrong ) );
+
// A bit of paranoia here, the caller asked for a specific
length of string
// here, and it's possible (eg when given an odd number) that
we may actually
// have at least 1 char more than they asked for. Just in case
they made this
@@ -448,6 +455,7 @@
if ( is_null( self::$singleton ) ) {
self::$singleton = new self;
}
+
return self::$singleton;
}
@@ -493,5 +501,4 @@
public static function generateHex( $chars, $forceStrong = false ) {
return self::singleton()->realGenerateHex( $chars, $forceStrong
);
}
-
}
diff --git a/includes/utils/MWFunction.php b/includes/utils/MWFunction.php
index 6d11d17..7105f6c 100644
--- a/includes/utils/MWFunction.php
+++ b/includes/utils/MWFunction.php
@@ -30,6 +30,7 @@
public static function call( $callback ) {
wfDeprecated( __METHOD__, '1.22' );
$args = func_get_args();
+
return call_user_func_array( 'call_user_func', $args );
}
@@ -41,6 +42,7 @@
*/
public static function callArray( $callback, $argsarams ) {
wfDeprecated( __METHOD__, '1.22' );
+
return call_user_func_array( $callback, $argsarams );
}
@@ -55,7 +57,7 @@
}
$ref = new ReflectionClass( $class );
+
return $ref->newInstanceArgs( $args );
}
-
}
diff --git a/includes/utils/MappedIterator.php
b/includes/utils/MappedIterator.php
index 70d2032..f2e6df6 100644
--- a/includes/utils/MappedIterator.php
+++ b/includes/utils/MappedIterator.php
@@ -81,16 +81,19 @@
if ( $ok ) {
$this->cache['current'] = $value;
}
+
return $ok;
}
public function key() {
$this->init();
+
return parent::key();
}
public function valid() {
$this->init();
+
return parent::valid();
}
diff --git a/includes/utils/StringUtils.php b/includes/utils/StringUtils.php
index c1545e6..0ebba2a 100644
--- a/includes/utils/StringUtils.php
+++ b/includes/utils/StringUtils.php
@@ -107,6 +107,7 @@
return false;
}
}
+
return true;
}
@@ -139,6 +140,7 @@
$output .= $replace . substr( $s, $endDelimPos
+ strlen( $endDelim ) );
}
}
+
return $output;
}
@@ -176,13 +178,13 @@
$m = array();
while ( $inputPos < strlen( $subject ) &&
- preg_match( "!($encStart)|($encEnd)!S$flags", $subject,
$m, PREG_OFFSET_CAPTURE, $inputPos ) )
- {
+ preg_match( "!($encStart)|($encEnd)!S$flags", $subject,
$m, PREG_OFFSET_CAPTURE, $inputPos )
+ ) {
$tokenOffset = $m[0][1];
if ( $m[1][0] != '' ) {
if ( $foundStart &&
- $strcmp( $endDelim, substr( $subject,
$tokenOffset, $endLength ) ) == 0 )
- {
+ $strcmp( $endDelim, substr( $subject,
$tokenOffset, $endLength ) ) == 0
+ ) {
# An end match is present at the same
location
$tokenType = 'end';
$tokenLength = $endLength;
@@ -219,7 +221,7 @@
$output .= call_user_func( $callback,
array(
substr( $subject, $outputPos,
$tokenOffset + $tokenLength - $outputPos ),
substr( $subject, $contentPos,
$tokenOffset - $contentPos )
- ));
+ ) );
$foundStart = false;
} else {
# Non-matching end, write it out
@@ -233,6 +235,7 @@
if ( $outputPos < strlen( $subject ) ) {
$output .= substr( $subject, $outputPos );
}
+
return $output;
}
@@ -251,6 +254,7 @@
*/
static function delimiterReplace( $startDelim, $endDelim, $replace,
$subject, $flags = '' ) {
$replacer = new RegexlikeReplacer( $replace );
+
return self::delimiterReplaceCallback( $startDelim, $endDelim,
$replacer->cb(), $subject, $flags );
}
@@ -291,6 +295,7 @@
static function escapeRegexReplacement( $string ) {
$string = str_replace( '\\', '\\\\', $string );
$string = str_replace( '$', '\\$', $string );
+
return $string;
}
@@ -346,9 +351,9 @@
foreach ( $matches as $i => $match ) {
$pairs["\$$i"] = $match;
}
+
return strtr( $this->r, $pairs );
}
-
}
/**
@@ -505,6 +510,7 @@
$result = strtr( $subject, $this->data );
wfProfileOut( __METHOD__ . '-strtr' );
}
+
return $result;
}
}
@@ -594,6 +600,7 @@
}
}
$this->refreshCurrent();
+
return $this->current;
}
diff --git a/includes/utils/UIDGenerator.php b/includes/utils/UIDGenerator.php
index 963e51a..10ff957 100644
--- a/includes/utils/UIDGenerator.php
+++ b/includes/utils/UIDGenerator.php
@@ -82,6 +82,7 @@
if ( self::$instance === null ) {
self::$instance = new self();
}
+
return self::$instance;
}
@@ -106,6 +107,7 @@
}
$gen = self::singleton();
$time = $gen->getTimestampAndDelay( 'lockFile88', 1, 1024 );
+
return wfBaseConvert( $gen->getTimestampedID88( $time ), 2,
$base );
}
@@ -125,6 +127,7 @@
if ( strlen( $id_bin ) !== 88 ) {
throw new MWException( "Detected overflow for
millisecond timestamp." );
}
+
return $id_bin;
}
@@ -148,6 +151,7 @@
}
$gen = self::singleton();
$time = $gen->getTimestampAndDelay( 'lockFile128', 16384,
1048576 );
+
return wfBaseConvert( $gen->getTimestampedID128( $time ), 2,
$base );
}
@@ -169,6 +173,7 @@
if ( strlen( $id_bin ) !== 128 ) {
throw new MWException( "Detected overflow for
millisecond timestamp." );
}
+
return $id_bin;
}
@@ -320,6 +325,7 @@
throw new MWException( __METHOD__ .
': sorry, this function doesn\'t work after the
year 144680' );
}
+
return substr( wfBaseConvert( $ts, 10, 2, 46 ), -46 );
}
@@ -328,6 +334,7 @@
*/
protected static function millitime() {
list( $msec, $sec ) = explode( ' ', microtime() );
+
return array( (int)$sec, (int)( $msec * 1000 ) );
}
diff --git a/includes/utils/ZipDirectoryReader.php
b/includes/utils/ZipDirectoryReader.php
index 307efce..7bf538a 100644
--- a/includes/utils/ZipDirectoryReader.php
+++ b/includes/utils/ZipDirectoryReader.php
@@ -88,6 +88,7 @@
*/
public static function read( $fileName, $callback, $options = array() )
{
$zdr = new self( $fileName, $callback, $options );
+
return $zdr->execute();
}
@@ -159,8 +160,8 @@
} else {
if ( $this->eocdr['CD size'] == 0xffffffff
|| $this->eocdr['CD offset'] ==
0xffffffff
- || $this->eocdr['CD entries total'] ==
0xffff )
- {
+ || $this->eocdr['CD entries total'] ==
0xffff
+ ) {
$this->error( 'zip-unsupported',
'Central directory header indicates ZIP64, ' .
'but we are in legacy mode.
Rejecting this upload is necessary to avoid ' .
'opening vulnerabilities on
clients using OpenJDK 7 or later.' );
@@ -174,6 +175,7 @@
}
fclose( $this->file );
+
return $status;
}
@@ -221,8 +223,8 @@
$this->error( 'zip-bad', 'trailing bytes after the end
of the file comment' );
}
if ( $this->eocdr['disk'] !== 0
- || $this->eocdr['CD start disk'] !== 0 )
- {
+ || $this->eocdr['CD start disk'] !== 0
+ ) {
$this->error( 'zip-unsupported', 'more than one disk
(in EOCDR)' );
}
$this->eocdr += $this->unpack(
@@ -263,8 +265,8 @@
*/
function readZip64EndOfCentralDirectoryRecord() {
if ( $this->eocdr64Locator['eocdr64 start disk'] != 0
- || $this->eocdr64Locator['number of disks'] != 0 )
- {
+ || $this->eocdr64Locator['number of disks'] != 0
+ ) {
$this->error( 'zip-unsupported', 'more than one disk
(in EOCDR64 locator)' );
}
@@ -287,8 +289,8 @@
$this->error( 'zip-bad', 'wrong signature on Zip64 end
of central directory record' );
}
if ( $data['disk'] !== 0
- || $data['CD start disk'] !== 0 )
- {
+ || $data['CD start disk'] !== 0
+ ) {
$this->error( 'zip-unsupported', 'more than one disk
(in EOCDR64)' );
}
}
@@ -310,6 +312,7 @@
$this->error( 'zip-bad', 'the central directory does
not immediately precede the end ' .
'of central directory record' );
}
+
return array( $offset, $size );
}
@@ -329,8 +332,8 @@
$endPos = $this->eocdr['position'];
if ( $size == 0xffffffff
|| $offset == 0xffffffff
- || $numEntries == 0xffff )
- {
+ || $numEntries == 0xffff
+ ) {
$this->readZip64EndOfCentralDirectoryLocator();
if ( isset( $this->eocdr64Locator['eocdr64 offset'] ) )
{
@@ -348,6 +351,7 @@
$this->error( 'zip-bad', 'the central directory does
not immediately precede the end ' .
'of central directory record' );
}
+
return array( $offset, $size );
}
@@ -396,10 +400,10 @@
$pos += $this->getStructSize( $variableInfo );
if ( $this->zip64 && (
- $data['compressed size'] == 0xffffffff
- || $data['uncompressed size'] == 0xffffffff
- || $data['local header offset'] == 0xffffffff )
)
- {
+ $data['compressed size'] == 0xffffffff
+ || $data['uncompressed size'] ==
0xffffffff
+ || $data['local header offset'] ==
0xffffffff )
+ ) {
$zip64Data = $this->unpackZip64Extra(
$data['extra field'] );
if ( $zip64Data ) {
$data = $zip64Data + $data;
@@ -427,8 +431,8 @@
// Convert the character set in the file name
if ( !function_exists( 'iconv' )
- || $this->testBit( $data['general bits'],
self::GENERAL_UTF8 ) )
- {
+ || $this->testBit( $data['general bits'],
self::GENERAL_UTF8 )
+ ) {
$name = $data['name'];
} else {
$name = iconv( 'CP437', 'UTF-8', $data['name']
);
@@ -487,6 +491,7 @@
$stat = fstat( $this->file );
$this->fileLength = $stat['size'];
}
+
return $this->fileLength;
}
@@ -548,6 +553,7 @@
$bytePos = $segIndex * self::SEGSIZE;
if ( $bytePos >= $this->getFileLength() ) {
$this->buffer[$segIndex] = '';
+
return '';
}
if ( fseek( $this->file, $bytePos ) ) {
@@ -559,6 +565,7 @@
}
$this->buffer[$segIndex] = $seg;
}
+
return $this->buffer[$segIndex];
}
@@ -576,6 +583,7 @@
$size += $type;
}
}
+
return $size;
}
@@ -613,12 +621,12 @@
if ( is_array( $type ) ) {
list( $typeName, $fieldSize ) = $type;
switch ( $typeName ) {
- case 'string':
- $data[$key] = substr( $string, $pos,
$fieldSize );
- $pos += $fieldSize;
- break;
- default:
- throw new MWException( __METHOD__ . ":
invalid type \"$typeName\"" );
+ case 'string':
+ $data[$key] = substr( $string,
$pos, $fieldSize );
+ $pos += $fieldSize;
+ break;
+ default:
+ throw new MWException(
__METHOD__ . ": invalid type \"$typeName\"" );
}
} else {
// Unsigned little-endian integer
--
To view, visit https://gerrit.wikimedia.org/r/93440
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5ec6257295261caab6cb2d9eb9d32ce76cae08a2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Siebrand <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits