Merge "Update formatting"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 7 Nov 2013 14:30:38 +0000 (14:30 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 7 Nov 2013 14:30:38 +0000 (14:30 +0000)
12 files changed:
includes/utils/ArrayUtils.php
includes/utils/Cdb.php
includes/utils/Cdb_PHP.php
includes/utils/ConfEditor.php
includes/utils/HashRing.php
includes/utils/IP.php
includes/utils/MWCryptRand.php
includes/utils/MWFunction.php
includes/utils/MappedIterator.php
includes/utils/StringUtils.php
includes/utils/UIDGenerator.php
includes/utils/ZipDirectoryReader.php

index 97a56e1..a222f81 100644 (file)
@@ -63,6 +63,7 @@ class ArrayUtils {
                                break;
                        }
                }
+
                return $i;
        }
 }
index 81c0afe..996b7af 100644 (file)
@@ -38,6 +38,7 @@ abstract class CdbReader {
                        return new CdbReader_DBA( $fileName );
                } else {
                        wfDebug( "Warning: no dba extension found, using emulation.\n" );
+
                        return new CdbReader_PHP( $fileName );
                }
        }
@@ -55,6 +56,7 @@ abstract class CdbReader {
                if ( !in_array( 'cdb', $handlers ) || !in_array( 'cdb_make', $handlers ) ) {
                        return false;
                }
+
                return true;
        }
 
@@ -94,6 +96,7 @@ abstract class CdbWriter {
                        return new CdbWriter_DBA( $fileName );
                } else {
                        wfDebug( "Warning: no dba extension found, using emulation.\n" );
+
                        return new CdbWriter_PHP( $fileName );
                }
        }
index a38b9a8..8c10b53 100644 (file)
@@ -40,6 +40,7 @@ class CdbFunctions {
        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 @@ class CdbFunctions {
                        $h ^= ord( $s[$i] );
                        $h &= 0xffffffff;
                }
+
                return $h;
        }
 }
@@ -164,6 +166,7 @@ class CdbReader_PHP extends CdbReader {
         */
        protected function match( $key, $pos ) {
                $buf = $this->read( strlen( $key ), $pos );
+
                return $buf === $key;
        }
 
@@ -193,6 +196,7 @@ class CdbReader_PHP extends CdbReader {
                        throw new MWException(
                                'Read from CDB file failed, file "' . $this->fileName . '" may be corrupted.' );
                }
+
                return $buf;
        }
 
@@ -208,6 +212,7 @@ class CdbReader_PHP extends CdbReader {
                        throw new MWException(
                                'Error in CDB file "' . $this->fileName . '", integer too big.' );
                }
+
                return $data[1];
        }
 
@@ -218,6 +223,7 @@ class CdbReader_PHP extends CdbReader {
         */
        protected function unpackSigned( $s ) {
                $data = unpack( 'va/vb', $s );
+
                return $data['a'] | ( $data['b'] << 16 );
        }
 
@@ -260,10 +266,12 @@ class CdbReader_PHP extends CdbReader {
                                        // Found
                                        $this->dlen = $this->unpack31( substr( $buf, 4 ) );
                                        $this->dpos = $pos + 8 + $keyLen;
+
                                        return true;
                                }
                        }
                }
+
                return false;
        }
 
@@ -273,6 +281,7 @@ class CdbReader_PHP extends CdbReader {
         */
        protected function find( $key ) {
                $this->findStart();
+
                return $this->findNext( $key );
        }
 }
@@ -411,7 +420,7 @@ class CdbWriter_PHP extends CdbWriter {
                // 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
index 67cb87d..163f73c 100644 (file)
@@ -115,6 +115,7 @@ class ConfEditor {
                } catch ( ConfEditorParseError $e ) {
                        return $e->getMessage() . "\n" . $e->highlight( $text );
                }
+
                return "OK";
        }
 
@@ -174,78 +175,78 @@ class ConfEditor {
                        $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];
-
-                               // 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( $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( $start, $start, $textToInsert );
-                               break;
-                       default:
-                               throw new MWException( "Unrecognised operation: \"$type\"" );
+                                       // 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\"" );
                        }
                }
 
@@ -268,6 +269,7 @@ class ConfEditor {
                                "Sorry, ConfEditor broke the file during editing and it won't parse anymore: " .
                                $e->getMessage() );
                }
+
                return $out;
        }
 
@@ -302,6 +304,7 @@ class ConfEditor {
                        $this->setVar( $vars, $parentPath, $name,
                                $this->parseScalar( $value ) );
                }
+
                return $vars;
        }
 
@@ -359,6 +362,7 @@ class ConfEditor {
                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 @@ class ConfEditor {
                                break;
                        }
                }
+
                return array( $regionStart, $regionEnd );
        }
 
@@ -475,6 +480,7 @@ class ConfEditor {
                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 @@ class ConfEditor {
                                break;
                        }
                }
+
                return $extraPath;
        }
 
@@ -538,6 +545,7 @@ class ConfEditor {
                                return $candidatePath;
                        }
                }
+
                return false;
        }
 
@@ -560,6 +568,7 @@ class ConfEditor {
                                $arrowIndent = str_repeat( ' ', $arrowIndentLength );
                        }
                }
+
                return array( $indent, $arrowIndent );
        }
 
@@ -580,32 +589,137 @@ class ConfEditor {
                        }
 
                        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 @@ class ConfEditor {
                                        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 @@ class ConfEditor {
                } else {
                        $this->currentToken = $this->newTokenObj( $this->tokens[$this->pos] );
                }
+
                return $this->currentToken;
        }
 
@@ -787,6 +797,7 @@ class ConfEditor {
                $this->lineNum = 1;
                $this->colNum = 1;
                $this->byteNum = 0;
+
                return $this->currentToken;
        }
 
@@ -814,6 +825,7 @@ class ConfEditor {
                }
                $this->prevToken = $this->currentToken;
                $this->setPos( $this->pos + 1 );
+
                return $this->currentToken;
        }
 
@@ -838,6 +850,7 @@ class ConfEditor {
                while ( $this->currentToken && $this->currentToken->isSkip() ) {
                        $this->nextToken();
                }
+
                return $this->currentToken;
        }
 
@@ -1028,6 +1041,7 @@ class ConfEditor {
                                return false;
                        }
                }
+
                return false;
        }
 
@@ -1058,6 +1072,7 @@ class ConfEditor {
  */
 class ConfEditorParseError extends MWException {
        var $lineNum, $colNum;
+
        function __construct( $editor, $msg ) {
                $this->lineNum = $editor->lineNum;
                $this->colNum = $editor->colNum;
@@ -1072,9 +1087,9 @@ class ConfEditorParseError extends MWException {
                                return "$line\n" . str_repeat( ' ', $this->colNum - 1 ) . "^\n";
                        }
                }
+
                return '';
        }
-
 }
 
 /**
index 930f8c0..c152d41 100644 (file)
@@ -38,7 +38,9 @@ class HashRing {
         * @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 @@ class HashRing {
         */
        public function getLocation( $item ) {
                $locations = $this->getLocations( $item, 1 );
+
                return $locations[0];
        }
 
@@ -113,6 +116,7 @@ class HashRing {
                        }
                        $locations[] = $location;
                }
+
                return $locations;
        }
 
@@ -137,6 +141,7 @@ class HashRing {
                if ( count( $map ) ) {
                        return new self( $map );
                }
+
                return false;
        }
 }
index 73834a5..002dcd9 100644 (file)
@@ -175,6 +175,7 @@ class IP {
                }
                // Remove leading zeros from each bloc as needed
                $ip = preg_replace( '/(^|:)0+(' . RE_IPV6_WORD . ')/', '$1$2', $ip );
+
                return $ip;
        }
 
@@ -218,6 +219,7 @@ class IP {
                        // Convert to lower case to make it more readable
                        $ip = strtolower( $ip );
                }
+
                return $ip;
        }
 
@@ -270,6 +272,7 @@ class IP {
                                return false;
                        }
                }
+
                // Plain hostname
                return array( $both, false );
        }
@@ -336,6 +339,7 @@ class IP {
                }
                // NO leading zeroes
                $ip_oct = preg_replace( '/(^|:)0+(' . RE_IPV6_WORD . ')/', '$1$2', $ip_oct );
+
                return $ip_oct;
        }
 
@@ -356,6 +360,7 @@ class IP {
                        }
                        $s .= base_convert( substr( $ip_hex, $i * 2, 2 ), 16, 10 );
                }
+
                return $s;
        }
 
@@ -400,6 +405,7 @@ class IP {
                                return false;
                        }
                }
+
                return true;
        }
 
@@ -426,6 +432,7 @@ class IP {
                                return false;
                        }
                }
+
                return true;
        }
 
@@ -449,6 +456,7 @@ class IP {
                                $n = wfBaseConvert( $n, 10, 16, 8, false );
                        }
                }
+
                return $n;
        }
 
@@ -467,6 +475,7 @@ class IP {
                foreach ( explode( ':', $ip ) as $v ) {
                        $r_ip .= str_pad( $v, 4, 0, STR_PAD_LEFT );
                }
+
                return $r_ip;
        }
 
@@ -492,6 +501,7 @@ class IP {
                                }
                        }
                }
+
                return $n;
        }
 
@@ -534,6 +544,7 @@ class IP {
                        $network = false;
                        $bits = false;
                }
+
                return array( $network, $bits );
        }
 
@@ -546,9 +557,9 @@ class IP {
         *     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 @@ class IP {
                        $network = false;
                        $bits = false;
                }
+
                return array( $network, (int)$bits );
        }
 
@@ -634,9 +646,9 @@ class IP {
         * 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 @@ class IP {
                                $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 @@ class IP {
        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 @@ class IP {
                        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 @@ class IP {
                if ( $bits === false ) {
                        return $start; // wasn't actually a range
                }
+
                return "$start/$bits";
        }
 }
index bac018e..d71193f 100644 (file)
@@ -189,6 +189,7 @@ class MWCryptRand {
                        "(time-taken=" . ( $timeTaken * 1000 ) . "ms, " .
                        "iterations=$iterations, " .
                        "time-per-iteration=" . ( $timeTaken / $iterations * 1e6 ) . "us)\n" );
+
                return $data;
        }
 
@@ -207,6 +208,7 @@ class MWCryptRand {
                // 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 @@ class MWCryptRand {
                        if ( in_array( $algorithm, $algos ) ) {
                                $this->algo = $algorithm;
                                wfDebug( __METHOD__ . ": Using the {$this->algo} hash algorithm.\n" );
+
                                return $this->algo;
                        }
                }
@@ -249,6 +252,7 @@ class MWCryptRand {
                if ( is_null( $this->hashLength ) ) {
                        $this->hashLength = strlen( $this->hash( '' ) );
                }
+
                return $this->hashLength;
        }
 
@@ -282,6 +286,7 @@ class MWCryptRand {
                if ( is_null( $this->strong ) ) {
                        throw new MWException( __METHOD__ . ' called before generation of random data' );
                }
+
                return $this->strong;
        }
 
@@ -415,6 +420,7 @@ class MWCryptRand {
                wfDebug( __METHOD__ . ": " . strlen( $buffer ) . " bytes of randomness leftover in the buffer.\n" );
 
                wfProfileOut( __METHOD__ );
+
                return $generated;
        }
 
@@ -428,6 +434,7 @@ class MWCryptRand {
                $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 @@ class MWCryptRand {
                if ( is_null( self::$singleton ) ) {
                        self::$singleton = new self;
                }
+
                return self::$singleton;
        }
 
@@ -493,5 +501,4 @@ class MWCryptRand {
        public static function generateHex( $chars, $forceStrong = false ) {
                return self::singleton()->realGenerateHex( $chars, $forceStrong );
        }
-
 }
index 6d11d17..7105f6c 100644 (file)
@@ -30,6 +30,7 @@ class MWFunction {
        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 @@ class MWFunction {
         */
        public static function callArray( $callback, $argsarams ) {
                wfDeprecated( __METHOD__, '1.22' );
+
                return call_user_func_array( $callback, $argsarams );
        }
 
@@ -55,7 +57,7 @@ class MWFunction {
                }
 
                $ref = new ReflectionClass( $class );
+
                return $ref->newInstanceArgs( $args );
        }
-
 }
index 70d2032..f2e6df6 100644 (file)
@@ -81,16 +81,19 @@ class MappedIterator extends FilterIterator {
                if ( $ok ) {
                        $this->cache['current'] = $value;
                }
+
                return $ok;
        }
 
        public function key() {
                $this->init();
+
                return parent::key();
        }
 
        public function valid() {
                $this->init();
+
                return parent::valid();
        }
 
index c1545e6..0ebba2a 100644 (file)
@@ -107,6 +107,7 @@ class StringUtils {
                                return false;
                        }
                }
+
                return true;
        }
 
@@ -139,6 +140,7 @@ class StringUtils {
                                $output .= $replace . substr( $s, $endDelimPos + strlen( $endDelim ) );
                        }
                }
+
                return $output;
        }
 
@@ -176,13 +178,13 @@ class StringUtils {
                $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 @@ class StringUtils {
                                        $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 @@ class StringUtils {
                if ( $outputPos < strlen( $subject ) ) {
                        $output .= substr( $subject, $outputPos );
                }
+
                return $output;
        }
 
@@ -251,6 +254,7 @@ class StringUtils {
         */
        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 @@ class StringUtils {
        static function escapeRegexReplacement( $string ) {
                $string = str_replace( '\\', '\\\\', $string );
                $string = str_replace( '$', '\\$', $string );
+
                return $string;
        }
 
@@ -346,9 +351,9 @@ class RegexlikeReplacer extends Replacer {
                foreach ( $matches as $i => $match ) {
                        $pairs["\$$i"] = $match;
                }
+
                return strtr( $this->r, $pairs );
        }
-
 }
 
 /**
@@ -505,6 +510,7 @@ class ReplacementArray {
                        $result = strtr( $subject, $this->data );
                        wfProfileOut( __METHOD__ . '-strtr' );
                }
+
                return $result;
        }
 }
@@ -594,6 +600,7 @@ class ExplodeIterator implements Iterator {
                        }
                }
                $this->refreshCurrent();
+
                return $this->current;
        }
 
index 963e51a..10ff957 100644 (file)
@@ -82,6 +82,7 @@ class UIDGenerator {
                if ( self::$instance === null ) {
                        self::$instance = new self();
                }
+
                return self::$instance;
        }
 
@@ -106,6 +107,7 @@ class UIDGenerator {
                }
                $gen = self::singleton();
                $time = $gen->getTimestampAndDelay( 'lockFile88', 1, 1024 );
+
                return wfBaseConvert( $gen->getTimestampedID88( $time ), 2, $base );
        }
 
@@ -125,6 +127,7 @@ class UIDGenerator {
                if ( strlen( $id_bin ) !== 88 ) {
                        throw new MWException( "Detected overflow for millisecond timestamp." );
                }
+
                return $id_bin;
        }
 
@@ -148,6 +151,7 @@ class UIDGenerator {
                }
                $gen = self::singleton();
                $time = $gen->getTimestampAndDelay( 'lockFile128', 16384, 1048576 );
+
                return wfBaseConvert( $gen->getTimestampedID128( $time ), 2, $base );
        }
 
@@ -169,6 +173,7 @@ class UIDGenerator {
                if ( strlen( $id_bin ) !== 128 ) {
                        throw new MWException( "Detected overflow for millisecond timestamp." );
                }
+
                return $id_bin;
        }
 
@@ -320,6 +325,7 @@ class UIDGenerator {
                        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 @@ class UIDGenerator {
         */
        protected static function millitime() {
                list( $msec, $sec ) = explode( ' ', microtime() );
+
                return array( (int)$sec, (int)( $msec * 1000 ) );
        }
 
index 307efce..7bf538a 100644 (file)
@@ -88,6 +88,7 @@ class ZipDirectoryReader {
         */
        public static function read( $fileName, $callback, $options = array() ) {
                $zdr = new self( $fileName, $callback, $options );
+
                return $zdr->execute();
        }
 
@@ -159,8 +160,8 @@ class ZipDirectoryReader {
                        } 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 @@ class ZipDirectoryReader {
                }
 
                fclose( $this->file );
+
                return $status;
        }
 
@@ -221,8 +223,8 @@ class ZipDirectoryReader {
                        $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 @@ class ZipDirectoryReader {
         */
        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 @@ class ZipDirectoryReader {
                        $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 @@ class ZipDirectoryReader {
                        $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 @@ class ZipDirectoryReader {
                $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 @@ class ZipDirectoryReader {
                        $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 @@ class ZipDirectoryReader {
                        $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 @@ class ZipDirectoryReader {
 
                        // 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 @@ class ZipDirectoryReader {
                        $stat = fstat( $this->file );
                        $this->fileLength = $stat['size'];
                }
+
                return $this->fileLength;
        }
 
@@ -548,6 +553,7 @@ class ZipDirectoryReader {
                        $bytePos = $segIndex * self::SEGSIZE;
                        if ( $bytePos >= $this->getFileLength() ) {
                                $this->buffer[$segIndex] = '';
+
                                return '';
                        }
                        if ( fseek( $this->file, $bytePos ) ) {
@@ -559,6 +565,7 @@ class ZipDirectoryReader {
                        }
                        $this->buffer[$segIndex] = $seg;
                }
+
                return $this->buffer[$segIndex];
        }
 
@@ -576,6 +583,7 @@ class ZipDirectoryReader {
                                $size += $type;
                        }
                }
+
                return $size;
        }
 
@@ -613,12 +621,12 @@ class ZipDirectoryReader {
                        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