Merge "Remove workaround for PHP bug 66021 (PHP < 5.5.12)"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 31 May 2018 02:28:30 +0000 (02:28 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 31 May 2018 02:28:30 +0000 (02:28 +0000)
21 files changed:
.editorconfig [new file with mode: 0644]
RELEASE-NOTES-1.32
includes/Storage/RevisionRecord.php
includes/api/ApiResult.php
includes/dao/IDBAccessObject.php
includes/diff/DiffEngine.php
includes/http/PhpHttpRequest.php
includes/libs/IP.php
includes/libs/filebackend/FileBackendStore.php
includes/logging/LogPage.php
includes/media/FormatMetadata.php
includes/media/GIFMetadataExtractor.php
includes/parser/Preprocessor.php
includes/session/PHPSessionHandler.php
includes/utils/UIDGenerator.php
includes/utils/ZipDirectoryReader.php
maintenance/generateSitemap.php
maintenance/storage/storageTypeStats.php
tests/phpunit/includes/api/RandomImageGenerator.php
tests/phpunit/languages/LanguageTest.php
tests/phpunit/suites/ParserTestTopLevelSuite.php

diff --git a/.editorconfig b/.editorconfig
new file mode 100644 (file)
index 0000000..9231818
--- /dev/null
@@ -0,0 +1,11 @@
+root = true
+
+[*]
+indent_style = tab
+end_of_line = lf
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[*.md]
+trim_trailing_whitespace = false
index 3d193d4..13d15c2 100644 (file)
@@ -126,6 +126,9 @@ because of Phabricator reports.
 * (T140807) The wgResourceLoaderLESSImportPaths configuration option was removed
   from ResourceLoader. Instead, use `@import` statements in LESS to import
   files directly from nearby directories within the same project.
+* The protected methods PHPSessionHandler::returnSuccess() and returnFailure(),
+  only needed for PHP5 compatibility, have been removed. It now uses the boolean
+  values `true` and `false` respectively.
 
 === Deprecations in 1.32 ===
 * Use of a StartProfiler.php file is deprecated in favour of placing
index 6d83e1c..ff0a70d 100644 (file)
@@ -48,8 +48,9 @@ abstract class RevisionRecord {
        const DELETED_COMMENT = 2;
        const DELETED_USER = 4;
        const DELETED_RESTRICTED = 8;
-       const SUPPRESSED_USER = 12; // convenience
-       const SUPPRESSED_ALL = 15; // convenience
+       const SUPPRESSED_USER = self::DELETED_USER | self::DELETED_RESTRICTED; // convenience
+       const SUPPRESSED_ALL = self::DELETED_TEXT | self::DELETED_COMMENT | self::DELETED_USER |
+               self::DELETED_RESTRICTED; // convenience
 
        // Audience options for accessors
        const FOR_PUBLIC = 1;
index 468d878..1afacaf 100644 (file)
@@ -61,7 +61,7 @@ class ApiResult implements ApiSerializable {
         * probably wrong.
         * @since 1.25
         */
-       const NO_VALIDATE = 12;
+       const NO_VALIDATE = self::NO_SIZE_CHECK | 8;
 
        /**
         * Key for the 'indexed tag name' metadata item. Value is string.
index e18a090..a555c55 100644 (file)
@@ -59,9 +59,9 @@ interface IDBAccessObject {
        /** @var int Read from the master/quorum */
        const READ_LATEST = 1;
        /* @var int Read from the master/quorum and lock out other writers */
-       const READ_LOCKING = 3; // READ_LATEST (1) and "LOCK IN SHARE MODE" (2)
+       const READ_LOCKING = self::READ_LATEST | 2; // READ_LATEST (1) and "LOCK IN SHARE MODE" (2)
        /** @var int Read from the master/quorum and lock out other writers and locking readers */
-       const READ_EXCLUSIVE = 7; // READ_LOCKING (3) and "FOR UPDATE" (4)
+       const READ_EXCLUSIVE = self::READ_LOCKING | 4; // READ_LOCKING (3) and "FOR UPDATE" (4)
 
        /** @var int Read from a replica DB or without a quorum, using the master/quorum on miss */
        const READ_LATEST_IMMUTABLE = 8;
index 273d1d6..142c51d 100644 (file)
@@ -351,7 +351,7 @@ class DiffEngine {
                        $this->maxDifferences = ceil( ( $this->m + $this->n ) / 2.0 );
                        if ( $this->m * $this->n > $this->tooLong ) {
                                // limit complexity to D^POW_LIMIT for long sequences
-                               $this->maxDifferences = floor( pow( $this->maxDifferences, $this->powLimit - 1.0 ) );
+                               $this->maxDifferences = floor( $this->maxDifferences ** ( $this->powLimit - 1.0 ) );
                                wfDebug( "Limiting max number of differences to $this->maxDifferences\n" );
                        }
 
index 0f499c2..30ab181 100644 (file)
@@ -137,13 +137,7 @@ class PhpHttpRequest extends MWHttpRequest {
                }
 
                if ( $this->sslVerifyHost ) {
-                       // PHP 5.6.0 deprecates CN_match, in favour of peer_name which
-                       // actually checks SubjectAltName properly.
-                       if ( version_compare( PHP_VERSION, '5.6.0', '>=' ) ) {
-                               $options['ssl']['peer_name'] = $this->parsedUrl['host'];
-                       } else {
-                               $options['ssl']['CN_match'] = $this->parsedUrl['host'];
-                       }
+                       $options['ssl']['peer_name'] = $this->parsedUrl['host'];
                }
 
                $options['ssl'] += $this->getCertOptions();
@@ -169,19 +163,6 @@ class PhpHttpRequest extends MWHttpRequest {
                        restore_error_handler();
 
                        if ( !$fh ) {
-                               // HACK for instant commons.
-                               // If we are contacting (commons|upload).wikimedia.org
-                               // try again with CN_match for en.wikipedia.org
-                               // as php does not handle SubjectAltName properly
-                               // prior to "peer_name" option in php 5.6
-                               if ( isset( $options['ssl']['CN_match'] )
-                                       && ( $options['ssl']['CN_match'] === 'commons.wikimedia.org'
-                                               || $options['ssl']['CN_match'] === 'upload.wikimedia.org' )
-                               ) {
-                                       $options['ssl']['CN_match'] = 'en.wikipedia.org';
-                                       $context = stream_context_create( $options );
-                                       continue;
-                               }
                                break;
                        }
 
index 06589d2..8efcd15 100644 (file)
@@ -425,7 +425,7 @@ class IP {
                        $ip = self::sanitizeIP( $ip );
                        $n = ip2long( $ip );
                        if ( $n < 0 ) {
-                               $n += pow( 2, 32 );
+                               $n += 2 ** 32;
                                # On 32-bit platforms (and on Windows), 2^32 does not fit into an int,
                                # so $n becomes a float. We convert it to string instead.
                                if ( is_float( $n ) ) {
@@ -487,7 +487,7 @@ class IP {
                        }
                        # Convert to unsigned
                        if ( $network < 0 ) {
-                               $network += pow( 2, 32 );
+                               $network += 2 ** 32;
                        }
                } else {
                        $network = false;
@@ -523,7 +523,7 @@ class IP {
                                $start = $end = false;
                        } else {
                                $start = sprintf( '%08X', $network );
-                               $end = sprintf( '%08X', $network + pow( 2, ( 32 - $bits ) ) - 1 );
+                               $end = sprintf( '%08X', $network + 2 ** ( 32 - $bits ) - 1 );
                        }
                // Explicit range
                } elseif ( strpos( $range, '-' ) !== false ) {
index 06b263a..16ea3ea 100644 (file)
@@ -1560,7 +1560,7 @@ abstract class FileBackendStore extends FileBackend {
                $shards = [];
                list( $digits, $base ) = $this->getContainerHashLevels( $container );
                if ( $digits > 0 ) {
-                       $numShards = pow( $base, $digits );
+                       $numShards = $base ** $digits;
                        for ( $index = 0; $index < $numShards; $index++ ) {
                                $shards[] = '.' . Wikimedia\base_convert( $index, 10, $base, $digits );
                        }
index 9f34264..265a41c 100644 (file)
@@ -37,8 +37,8 @@ class LogPage {
        const DELETED_RESTRICTED = 8;
 
        // Convenience fields
-       const SUPPRESSED_USER = 12;
-       const SUPPRESSED_ACTION = 9;
+       const SUPPRESSED_USER = self::DELETED_USER | self::DELETED_RESTRICTED;
+       const SUPPRESSED_ACTION = self::DELETED_ACTION | self::DELETED_RESTRICTED;
 
        /** @var bool */
        public $updateRecentChanges;
index 2a8b375..52d7373 100644 (file)
@@ -787,7 +787,7 @@ class FormatMetadata extends ContextSource {
                                                        }
                                                }
                                                if ( is_numeric( $val ) ) {
-                                                       $fNumber = pow( 2, $val / 2 );
+                                                       $fNumber = 2 ** ( $val / 2 );
                                                        if ( $fNumber !== false ) {
                                                                $val = $this->msg( 'exif-maxaperturevalue-value',
                                                                        $this->formatNum( $val ),
index a26539a..591ccf1 100644 (file)
@@ -264,7 +264,7 @@ class GIFMetadataExtractor {
         */
        static function readGCT( $fh, $bpp ) {
                if ( $bpp > 0 ) {
-                       $max = pow( 2, $bpp );
+                       $max = 2 ** $bpp;
                        for ( $i = 1; $i <= $max; ++$i ) {
                                fread( $fh, 3 );
                        }
index 49e961a..b6084d8 100644 (file)
@@ -171,7 +171,8 @@ interface PPFrame {
        const RECOVER_COMMENTS = 16;
        const NO_TAGS = 32;
 
-       const RECOVER_ORIG = 59; // = 1|2|8|16|32 no constant expression support in PHP yet
+       const RECOVER_ORIG = self::NO_ARGS | self::NO_TEMPLATES | self::NO_IGNORE |
+               self::RECOVER_COMMENTS | self::NO_TAGS;
 
        /** This constant exists when $indexOffset is supported in newChild() */
        const SUPPORTS_INDEX_OFFSET = 1;
index b76f0ff..4e1a69b 100644 (file)
@@ -162,39 +162,12 @@ class PHPSessionHandler implements \SessionHandlerInterface {
                }
        }
 
-       /**
-        * Workaround for PHP5 bug
-        *
-        * PHP5 has a bug in handling boolean return values for
-        * SessionHandlerInterface methods, it expects 0 or -1 instead of true or
-        * false. See <https://wiki.php.net/rfc/session.user.return-value>.
-        *
-        * PHP7 and HHVM are not affected.
-        *
-        * @todo When we drop support for Zend PHP 5, this can be removed.
-        * @return bool|int
-        * @codeCoverageIgnore
-        */
-       protected static function returnSuccess() {
-               return defined( 'HHVM_VERSION' ) || version_compare( PHP_VERSION, '7.0.0', '>=' ) ? true : 0;
-       }
-
-       /**
-        * Workaround for PHP5 bug
-        * @see self::returnSuccess()
-        * @return bool|int
-        * @codeCoverageIgnore
-        */
-       protected static function returnFailure() {
-               return defined( 'HHVM_VERSION' ) || version_compare( PHP_VERSION, '7.0.0', '>=' ) ? false : -1;
-       }
-
        /**
         * Initialize the session (handler)
         * @private For internal use only
         * @param string $save_path Path used to store session files (ignored)
         * @param string $session_name Session name (ignored)
-        * @return bool|int Success (see self::returnSuccess())
+        * @return true
         */
        public function open( $save_path, $session_name ) {
                if ( self::$instance !== $this ) {
@@ -203,20 +176,20 @@ class PHPSessionHandler implements \SessionHandlerInterface {
                if ( !$this->enable ) {
                        throw new \BadMethodCallException( 'Attempt to use PHP session management' );
                }
-               return self::returnSuccess();
+               return true;
        }
 
        /**
         * Close the session (handler)
         * @private For internal use only
-        * @return bool|int Success (see self::returnSuccess())
+        * @return true
         */
        public function close() {
                if ( self::$instance !== $this ) {
                        throw new \UnexpectedValueException( __METHOD__ . ': Wrong instance called!' );
                }
                $this->sessionFieldCache = [];
-               return self::returnSuccess();
+               return true;
        }
 
        /**
@@ -251,7 +224,7 @@ class PHPSessionHandler implements \SessionHandlerInterface {
         * @param string $dataStr Session data. Not that you should ever call this
         *   directly, but note that this has the same issues with code injection
         *   via user-controlled data as does PHP's unserialize function.
-        * @return bool|int Success (see self::returnSuccess())
+        * @return bool
         */
        public function write( $id, $dataStr ) {
                if ( self::$instance !== $this ) {
@@ -270,14 +243,14 @@ class PHPSessionHandler implements \SessionHandlerInterface {
                                [
                                        'session' => $id,
                        ] );
-                       return self::returnSuccess();
+                       return true;
                }
 
                // First, decode the string PHP handed us
                $data = \Wikimedia\PhpSessionSerializer::decode( $dataStr );
                if ( $data === null ) {
                        // @codeCoverageIgnoreStart
-                       return self::returnFailure();
+                       return false;
                        // @codeCoverageIgnoreEnd
                }
 
@@ -350,14 +323,14 @@ class PHPSessionHandler implements \SessionHandlerInterface {
 
                $session->persist();
 
-               return self::returnSuccess();
+               return true;
        }
 
        /**
         * Destroy a session
         * @private For internal use only
         * @param string $id Session id
-        * @return bool|int Success (see self::returnSuccess())
+        * @return true
         */
        public function destroy( $id ) {
                if ( self::$instance !== $this ) {
@@ -370,14 +343,14 @@ class PHPSessionHandler implements \SessionHandlerInterface {
                if ( $session ) {
                        $session->clear();
                }
-               return self::returnSuccess();
+               return true;
        }
 
        /**
         * Execute garbage collection.
         * @private For internal use only
         * @param int $maxlifetime Maximum session life time (ignored)
-        * @return bool|int Success (see self::returnSuccess())
+        * @return true
         * @codeCoverageIgnore See T135576
         */
        public function gc( $maxlifetime ) {
@@ -386,6 +359,6 @@ class PHPSessionHandler implements \SessionHandlerInterface {
                }
                $before = date( 'YmdHis', time() );
                $this->store->deleteObjectsExpiringBefore( $before );
-               return self::returnSuccess();
+               return true;
        }
 }
index 4d5c3af..c23d999 100644 (file)
@@ -400,14 +400,14 @@ class UIDGenerator {
                        // Write back the new counter value
                        ftruncate( $handle, 0 );
                        rewind( $handle );
-                       fwrite( $handle, fmod( $counter, pow( 2, 48 ) ) ); // warp-around as needed
+                       fwrite( $handle, fmod( $counter, 2 ** 48 ) ); // warp-around as needed
                        fflush( $handle );
                        // Release the UID lock file
                        flock( $handle, LOCK_UN );
                }
 
                $ids = [];
-               $divisor = pow( 2, $bits );
+               $divisor = 2 ** $bits;
                $currentId = floor( $counter - $count ); // pre-increment counter value
                for ( $i = 0; $i < $count; ++$i ) {
                        $ids[] = fmod( ++$currentId, $divisor );
@@ -532,7 +532,7 @@ class UIDGenerator {
        protected function millisecondsSinceEpochBinary( array $time ) {
                list( $sec, $msec ) = $time;
                $ts = 1000 * $sec + $msec;
-               if ( $ts > pow( 2, 52 ) ) {
+               if ( $ts > 2 ** 52 ) {
                        throw new RuntimeException( __METHOD__ .
                                ': sorry, this function doesn\'t work after the year 144680' );
                }
@@ -551,7 +551,7 @@ class UIDGenerator {
                $offset = '122192928000000000';
                if ( PHP_INT_SIZE >= 8 ) { // 64 bit integers
                        $ts = ( 1000 * $sec + $msec ) * 10000 + (int)$offset + $delta;
-                       $id_bin = str_pad( decbin( $ts % pow( 2, 60 ) ), 60, '0', STR_PAD_LEFT );
+                       $id_bin = str_pad( decbin( $ts % ( 2 ** 60 ) ), 60, '0', STR_PAD_LEFT );
                } elseif ( extension_loaded( 'gmp' ) ) {
                        $ts = gmp_add( gmp_mul( (string)$sec, '1000' ), (string)$msec ); // ms
                        $ts = gmp_add( gmp_mul( $ts, '10000' ), $offset ); // 100ns intervals
index f0ace2c..20bad13 100644 (file)
@@ -656,7 +656,7 @@ class ZipDirectoryReader {
                                }
 
                                // Throw an exception if there was loss of precision
-                               if ( $value > pow( 2, 52 ) ) {
+                               if ( $value > 2 ** 52 ) {
                                        $this->error( 'zip-unsupported', 'number too large to be stored in a double. ' .
                                                'This could happen if we tried to unpack a 64-bit structure ' .
                                                'at an invalid location.' );
index 5a2c6c7..e2dc9b8 100644 (file)
@@ -177,7 +177,7 @@ class GenerateSitemap extends Maintenance {
        public function execute() {
                $this->setNamespacePriorities();
                $this->url_limit = 50000;
-               $this->size_limit = pow( 2, 20 ) * 10;
+               $this->size_limit = ( 2 ** 20 ) * 10;
 
                # Create directory if needed
                $fspath = $this->getOption( 'fspath', getcwd() );
index 9ba3d1b..af9dd08 100644 (file)
@@ -31,7 +31,7 @@ class StorageTypeStats extends Maintenance {
                        exit( 1 );
                }
 
-               $binSize = intval( pow( 10, floor( log10( $endId ) ) - 3 ) );
+               $binSize = intval( 10 ** ( floor( log10( $endId ) ) - 3 ) );
                if ( $binSize < 100 ) {
                        $binSize = 100;
                }
index 50a59f9..7fd5f1d 100644 (file)
@@ -187,7 +187,7 @@ class RandomImageGenerator {
                $spec['height'] = mt_rand( $this->minHeight, $this->maxHeight );
                $spec['fill'] = $this->getRandomColor();
 
-               $diagonalLength = sqrt( pow( $spec['width'], 2 ) + pow( $spec['height'], 2 ) );
+               $diagonalLength = sqrt( $spec['width'] ** 2 + $spec['height'] ** 2 );
 
                $draws = [];
                for ( $i = 0; $i <= $this->shapesToDraw; $i++ ) {
index 050ed83..8653bcd 100644 (file)
@@ -1110,27 +1110,27 @@ class LanguageTest extends LanguageClassesTestCase {
                                "1 gigabyte"
                        ],
                        [
-                               pow( 1024, 4 ),
+                               1024 ** 4,
                                "1 TB",
                                "1 terabyte"
                        ],
                        [
-                               pow( 1024, 5 ),
+                               1024 ** 5,
                                "1 PB",
                                "1 petabyte"
                        ],
                        [
-                               pow( 1024, 6 ),
+                               1024 ** 6,
                                "1 EB",
                                "1,024 exabyte"
                        ],
                        [
-                               pow( 1024, 7 ),
+                               1024 ** 7,
                                "1 ZB",
                                "1 zetabyte"
                        ],
                        [
-                               pow( 1024, 8 ),
+                               1024 ** 8,
                                "1 YB",
                                "1 yottabyte"
                        ],
@@ -1173,37 +1173,37 @@ class LanguageTest extends LanguageClassesTestCase {
                                "1 megabit per second"
                        ],
                        [
-                               pow( 10, 9 ),
+                               10 ** 9,
                                "1 Gbps",
                                "1 gigabit per second"
                        ],
                        [
-                               pow( 10, 12 ),
+                               10 ** 12,
                                "1 Tbps",
                                "1 terabit per second"
                        ],
                        [
-                               pow( 10, 15 ),
+                               10 ** 15,
                                "1 Pbps",
                                "1 petabit per second"
                        ],
                        [
-                               pow( 10, 18 ),
+                               10 ** 18,
                                "1 Ebps",
                                "1 exabit per second"
                        ],
                        [
-                               pow( 10, 21 ),
+                               10 ** 21,
                                "1 Zbps",
                                "1 zetabit per second"
                        ],
                        [
-                               pow( 10, 24 ),
+                               10 ** 24,
                                "1 Ybps",
                                "1 yottabit per second"
                        ],
                        [
-                               pow( 10, 27 ),
+                               10 ** 27,
                                "1,000 Ybps",
                                "1,000 yottabits per second"
                        ],
index 07b18f5..fe38a98 100644 (file)
@@ -29,7 +29,7 @@ class ParserTestTopLevelSuite extends PHPUnit_Framework_TestSuite {
        /** Include non core files as set in $wgParserTestFiles */
        const NO_CORE = 2;
        /** Include anything set via $wgParserTestFiles */
-       const WITH_ALL = 3; # CORE_ONLY | NO_CORE
+       const WITH_ALL = self::CORE_ONLY | self::NO_CORE;
 
        /** @} */