diff options
author | Umherirrender <umherirrender_de.wp@web.de> | 2022-02-26 17:28:48 +0100 |
---|---|---|
committer | Umherirrender <umherirrender_de.wp@web.de> | 2022-03-01 18:19:33 +0100 |
commit | 9efd9ca45ec67ca17fdbb00fd0242966d6692caf (patch) | |
tree | 817815ded23dfb5b1b71d9e3b9ed7d7023214bbc | |
parent | b042d6577643985624d0f4ee867806e30b14c16b (diff) | |
download | mediawikicore-9efd9ca45ec67ca17fdbb00fd0242966d6692caf.tar.gz mediawikicore-9efd9ca45ec67ca17fdbb00fd0242966d6692caf.zip |
Add explicit casts between scalar types
* Some functions accept only string, cast ints and floats to string
* After preg_matches or explode() casts numbers to int to do maths
* Cast unix timestamps to int to do maths
* Cast return values from timestamp format function to int
* Cast bitwise operator to bool when needed as bool
* php internal functions like floor/round/ceil documented to return
float, most cases the result is used as int, added casts
Found by phan strict checks
Change-Id: Icb2de32107f43817acc45fe296fb77acf65c1786
49 files changed, 76 insertions, 76 deletions
diff --git a/includes/CommentFormatter/CommentParser.php b/includes/CommentFormatter/CommentParser.php index 87a667787f8e..ccd21cd06f46 100644 --- a/includes/CommentFormatter/CommentParser.php +++ b/includes/CommentFormatter/CommentParser.php @@ -440,7 +440,7 @@ class CommentParser { */ private function addLinkMarker( $callback ) { $nextId = count( $this->links ); - if ( strlen( $nextId ) > self::MAX_ID_SIZE ) { + if ( strlen( (string)$nextId ) > self::MAX_ID_SIZE ) { throw new \RuntimeException( 'Too many links in comment batch' ); } $this->links[] = $callback; diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 9c6b1929d0fe..025dfec77e47 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -2356,7 +2356,7 @@ function wfMemoryLimit( $newLimit ) { $oldLimit = wfShorthandToInteger( ini_get( 'memory_limit' ) ); // If the INI config is already unlimited, there is nothing larger if ( $oldLimit != -1 ) { - $newLimit = wfShorthandToInteger( $newLimit ); + $newLimit = wfShorthandToInteger( (string)$newLimit ); if ( $newLimit == -1 ) { wfDebug( "Removing PHP's memory limit" ); AtEase::suppressWarnings(); diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 293398f99e26..84868d7b193a 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -2637,7 +2637,7 @@ class OutputPage extends ContextSource { if ( $this->getHookRunner()->onBeforePageRedirect( $this, $redirect, $code ) ) { if ( $code == '301' || $code == '303' ) { if ( !$config->get( 'DebugRedirects' ) ) { - $response->statusHeader( $code ); + $response->statusHeader( (int)$code ); } $this->mLastModified = wfTimestamp( TS_RFC2822 ); } diff --git a/includes/Rest/ConditionalHeaderUtil.php b/includes/Rest/ConditionalHeaderUtil.php index 0a39f06678cf..866ac51dd03a 100644 --- a/includes/Rest/ConditionalHeaderUtil.php +++ b/includes/Rest/ConditionalHeaderUtil.php @@ -32,7 +32,7 @@ class ConditionalHeaderUtil { if ( $lastModified === null ) { $this->lastModified = null; } else { - $this->lastModified = ConvertibleTimestamp::convert( TS_UNIX, $lastModified ); + $this->lastModified = (int)ConvertibleTimestamp::convert( TS_UNIX, $lastModified ); } if ( $hasRepresentation === null ) { $hasRepresentation = $eTag !== null; diff --git a/includes/Storage/PageUpdater.php b/includes/Storage/PageUpdater.php index 071f102a5707..ece328b3b890 100644 --- a/includes/Storage/PageUpdater.php +++ b/includes/Storage/PageUpdater.php @@ -881,7 +881,7 @@ class PageUpdater { // Deprecated since 1.35. $allowedByHook = $this->hookRunner->onPageContentSave( $this->getWikiPage(), $legacyUser, $mainContent, $summary, - $this->flags & EDIT_MINOR, null, null, $this->flags, $hookStatus + (bool)( $this->flags & EDIT_MINOR ), null, null, $this->flags, $hookStatus ); } diff --git a/includes/actions/HistoryAction.php b/includes/actions/HistoryAction.php index 3e85516c6acb..b0a6f1cbcb53 100644 --- a/includes/actions/HistoryAction.php +++ b/includes/actions/HistoryAction.php @@ -117,8 +117,8 @@ class HistoryAction extends FormlessAction { $day = cal_days_in_month( CAL_GREGORIAN, $month, $year ); // Left pad the months and days - $month = str_pad( $month, 2, "0", STR_PAD_LEFT ); - $day = str_pad( $day, 2, "0", STR_PAD_LEFT ); + $month = str_pad( (string)$month, 2, "0", STR_PAD_LEFT ); + $day = str_pad( (string)$day, 2, "0", STR_PAD_LEFT ); } $before = $request->getVal( 'date-range-to' ); diff --git a/includes/collation/NumericUppercaseCollation.php b/includes/collation/NumericUppercaseCollation.php index 55e42338fb72..318a920f0e70 100644 --- a/includes/collation/NumericUppercaseCollation.php +++ b/includes/collation/NumericUppercaseCollation.php @@ -71,7 +71,7 @@ class NumericUppercaseCollation extends UppercaseCollation { $len = strlen( $number ); // This allows sequences of up to 65536 numeric characters to be handled correctly. One byte // would allow only for 256, which doesn't feel future-proof. - $prefix = chr( floor( $len / 256 ) ) . chr( $len % 256 ); + $prefix = chr( (int)floor( $len / 256 ) ) . chr( $len % 256 ); return '0' . $prefix . $number; }, $sortkey ); diff --git a/includes/export/Dump7ZipOutput.php b/includes/export/Dump7ZipOutput.php index afaf52a1c9bc..4e7d8684a23f 100644 --- a/includes/export/Dump7ZipOutput.php +++ b/includes/export/Dump7ZipOutput.php @@ -51,7 +51,7 @@ class Dump7ZipOutput extends DumpPipeOutput { */ private function setup7zCommand( $file ) { $command = "7za a -bd -si -mx="; - $command .= Shell::escape( $this->compressionLevel ) . ' '; + $command .= Shell::escape( (string)$this->compressionLevel ) . ' '; $command .= Shell::escape( $file ); // Suppress annoying useless crap from p7zip // Unfortunately this could suppress real error messages too diff --git a/includes/externalstore/ExternalStoreMwstore.php b/includes/externalstore/ExternalStoreMwstore.php index 6e7786f8331c..f0a15bf87d6a 100644 --- a/includes/externalstore/ExternalStoreMwstore.php +++ b/includes/externalstore/ExternalStoreMwstore.php @@ -91,7 +91,7 @@ class ExternalStoreMwstore extends ExternalStoreMedium { public function store( $backend, $data ) { $be = $this->fbGroup->get( $backend ); // Get three random base 36 characters to act as shard directories - $rand = Wikimedia\base_convert( mt_rand( 0, 46655 ), 10, 36, 3 ); + $rand = Wikimedia\base_convert( (string)mt_rand( 0, 46655 ), 10, 36, 3 ); // Make sure ID is roughly lexicographically increasing for performance $id = str_pad( UIDGenerator::newTimestampedUID128( 32 ), 26, '0', STR_PAD_LEFT ); // Segregate items by DB domain ID for the sake of bookkeeping diff --git a/includes/jobqueue/JobRunner.php b/includes/jobqueue/JobRunner.php index 96177db4941e..6cfba0ab3c7c 100644 --- a/includes/jobqueue/JobRunner.php +++ b/includes/jobqueue/JobRunner.php @@ -591,7 +591,7 @@ class JobRunner implements LoggerAwareInterface { if ( preg_match( '!^(\d+)(k|m|g|)$!i', ini_get( 'memory_limit' ), $m ) ) { list( , $num, $unit ) = $m; $conv = [ 'g' => 1073741824, 'm' => 1048576, 'k' => 1024, '' => 1 ]; - $maxBytes = $num * $conv[strtolower( $unit )]; + $maxBytes = (int)$num * $conv[strtolower( $unit )]; } else { $maxBytes = 0; } diff --git a/includes/libs/filebackend/FileBackendMultiWrite.php b/includes/libs/filebackend/FileBackendMultiWrite.php index 3f4ebe01b9d0..62df3a78fd7f 100644 --- a/includes/libs/filebackend/FileBackendMultiWrite.php +++ b/includes/libs/filebackend/FileBackendMultiWrite.php @@ -288,8 +288,8 @@ class FileBackendMultiWrite extends FileBackend { } elseif ( ( $this->syncChecks & self::CHECK_TIME ) && abs( - ConvertibleTimestamp::convert( TS_UNIX, $masterStat['mtime'] ) - - ConvertibleTimestamp::convert( TS_UNIX, $cloneStat['mtime'] ) + (int)ConvertibleTimestamp::convert( TS_UNIX, $masterStat['mtime'] ) - + (int)ConvertibleTimestamp::convert( TS_UNIX, $cloneStat['mtime'] ) ) > 30 ) { // File in the clone backend is significantly newer or older diff --git a/includes/libs/filebackend/FileBackendStore.php b/includes/libs/filebackend/FileBackendStore.php index f6bcd03b821c..82788ca84ebe 100644 --- a/includes/libs/filebackend/FileBackendStore.php +++ b/includes/libs/filebackend/FileBackendStore.php @@ -1738,7 +1738,7 @@ abstract class FileBackendStore extends FileBackend { if ( $digits > 0 ) { $numShards = $base ** $digits; for ( $index = 0; $index < $numShards; $index++ ) { - $shards[] = '.' . Wikimedia\base_convert( $index, 10, $base, $digits ); + $shards[] = '.' . Wikimedia\base_convert( (string)$index, 10, $base, $digits ); } } diff --git a/includes/libs/filebackend/HTTPFileStreamer.php b/includes/libs/filebackend/HTTPFileStreamer.php index ee1e3dfb01fc..ad100c7fa872 100644 --- a/includes/libs/filebackend/HTTPFileStreamer.php +++ b/includes/libs/filebackend/HTTPFileStreamer.php @@ -231,11 +231,11 @@ class HTTPFileStreamer { if ( $start === '' && $end === '' ) { $absRange = [ 0, $size - 1 ]; } elseif ( $start === '' ) { - $absRange = [ $size - $end, $size - 1 ]; + $absRange = [ $size - (int)$end, $size - 1 ]; } elseif ( $end === '' ) { - $absRange = [ $start, $size - 1 ]; + $absRange = [ (int)$start, $size - 1 ]; } else { - $absRange = [ $start, $end ]; + $absRange = [ (int)$start, (int)$end ]; } if ( $absRange[0] >= 0 && $absRange[1] >= $absRange[0] ) { if ( $absRange[0] < $size ) { diff --git a/includes/libs/filebackend/SwiftFileBackend.php b/includes/libs/filebackend/SwiftFileBackend.php index b5abade8d9c3..d25ad9e88900 100644 --- a/includes/libs/filebackend/SwiftFileBackend.php +++ b/includes/libs/filebackend/SwiftFileBackend.php @@ -1768,7 +1768,7 @@ class SwiftFileBackend extends FileBackendStore { if ( isset( $creds['auth_token'] ) && isset( $creds['storage_url'] ) ) { $this->authCreds = $creds; // Skew the timestamp for worst case to avoid using stale credentials - $this->authSessionTimestamp = time() - ceil( $this->authTTL / 2 ); + $this->authSessionTimestamp = time() - (int)ceil( $this->authTTL / 2 ); } else { // cache miss list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $this->http->run( [ 'method' => 'GET', diff --git a/includes/libs/objectcache/RedisBagOStuff.php b/includes/libs/objectcache/RedisBagOStuff.php index 5e9974d8d58e..63007e5fba6e 100644 --- a/includes/libs/objectcache/RedisBagOStuff.php +++ b/includes/libs/objectcache/RedisBagOStuff.php @@ -488,7 +488,7 @@ class RedisBagOStuff extends MediumSpecificBagOStuff { $conn->multi( Redis::PIPELINE ); $conn->set( $key, - $init - $step, + (string)( $init - $step ), $ttl ? [ 'nx', 'ex' => $ttl ] : [ 'nx' ] ); $conn->incrBy( $key, $step ); diff --git a/includes/libs/objectcache/wancache/WANObjectCache.php b/includes/libs/objectcache/wancache/WANObjectCache.php index e69ef5e7f2b1..bc25cdf211c0 100644 --- a/includes/libs/objectcache/wancache/WANObjectCache.php +++ b/includes/libs/objectcache/wancache/WANObjectCache.php @@ -1523,7 +1523,7 @@ class WANObjectCache implements // so that purges to the main key propagate to the variant value. $this->logger->debug( "getWithSetCallback($key): using variant key" ); list( $value ) = $this->fetchOrRegenerate( - $this->makeGlobalKey( 'WANCache-key-variant', md5( $key ), $version ), + $this->makeGlobalKey( 'WANCache-key-variant', md5( $key ), (string)$version ), $ttl, $callback, [ 'version' => null, 'minAsOf' => $curAsOf ] + $opts, @@ -1755,7 +1755,7 @@ class WANObjectCache implements private function yieldStampedeLock( $key, $hasLock ) { if ( $hasLock ) { $checkSisterKey = $this->makeSisterKey( $key, self::TYPE_MUTEX ); - $this->cache->changeTTL( $checkSisterKey, $this->getCurrentTime() - 60 ); + $this->cache->changeTTL( $checkSisterKey, (int)$this->getCurrentTime() - 60 ); } } diff --git a/includes/libs/uuid/GlobalIdGenerator.php b/includes/libs/uuid/GlobalIdGenerator.php index 3c504521633d..154490915b2b 100644 --- a/includes/libs/uuid/GlobalIdGenerator.php +++ b/includes/libs/uuid/GlobalIdGenerator.php @@ -396,7 +396,7 @@ class GlobalIdGenerator { ftruncate( $handle, 0 ); rewind( $handle ); // Use fmod() to avoid "division by zero" on 32 bit machines - fwrite( $handle, fmod( $counter, 2 ** 48 ) ); // warp-around as needed + fwrite( $handle, (string)fmod( $counter, 2 ** 48 ) ); // warp-around as needed fflush( $handle ); // Release the UID lock file flock( $handle, LOCK_UN ); @@ -589,7 +589,7 @@ class GlobalIdGenerator { ': sorry, this function doesn\'t work after the year 144680' ); } - return substr( \Wikimedia\base_convert( $ts, 10, 2, 46 ), -46 ); + return substr( \Wikimedia\base_convert( (string)$ts, 10, 2, 46 ), -46 ); } /** @@ -613,7 +613,7 @@ class GlobalIdGenerator { } elseif ( extension_loaded( 'bcmath' ) ) { $ts = bcadd( bcmul( $sec, 1000 ), $msec ); // ms $ts = bcadd( bcmul( $ts, 10000 ), $offset ); // 100ns intervals - $ts = bcadd( $ts, $delta ); + $ts = bcadd( $ts, (string)$delta ); $ts = bcmod( $ts, bcpow( 2, 60 ) ); // wrap around $id_bin = \Wikimedia\base_convert( $ts, 10, 2, 60 ); } else { diff --git a/includes/logging/LogFormatter.php b/includes/logging/LogFormatter.php index 144cdd24915e..949ac09f242f 100644 --- a/includes/logging/LogFormatter.php +++ b/includes/logging/LogFormatter.php @@ -541,7 +541,7 @@ class LogFormatter { } list( $index, $type, ) = explode( ':', $key, 3 ); if ( ctype_digit( $index ) ) { - $params[$index - 1] = $this->formatParameterValue( $type, $value ); + $params[(int)$index - 1] = $this->formatParameterValue( $type, $value ); } } diff --git a/includes/media/BitmapHandler.php b/includes/media/BitmapHandler.php index 6b8aced241db..0cd74fb7983e 100644 --- a/includes/media/BitmapHandler.php +++ b/includes/media/BitmapHandler.php @@ -306,7 +306,7 @@ class BitmapHandler extends TransformationalImageHandler { ) { // Hack, since $wgSharpenParameter is written specifically for the command line convert list( $radius, $sigma ) = explode( 'x', $sharpenParameter ); - $im->sharpenImage( $radius, $sigma ); + $im->sharpenImage( (float)$radius, (float)$sigma ); } $qualityVal = isset( $params['quality'] ) ? (string)$params['quality'] : null; $im->setCompressionQuality( $qualityVal ?: $jpegQuality ); diff --git a/includes/media/Exif.php b/includes/media/Exif.php index 29c8d595401a..593e623b8023 100644 --- a/includes/media/Exif.php +++ b/includes/media/Exif.php @@ -370,7 +370,7 @@ class Exif { // functions ran earlier. But multiplying such a string by -1 // doesn't work well, so convert. list( $num, $denom ) = explode( '/', $this->mFilteredExifData['GPSAltitude'] ); - $this->mFilteredExifData['GPSAltitude'] = $num / $denom; + $this->mFilteredExifData['GPSAltitude'] = (int)$num / (int)$denom; if ( isset( $this->mFilteredExifData['GPSAltitudeRef'] ) ) { switch ( $this->mFilteredExifData['GPSAltitudeRef'] ) { @@ -531,11 +531,11 @@ class Exif { && ( $dir === 'N' || $dir === 'S' || $dir === 'E' || $dir === 'W' ) ) { list( $num, $denom ) = explode( '/', $loc[0] ); - $res = $num / $denom; + $res = (int)$num / (int)$denom; list( $num, $denom ) = explode( '/', $loc[1] ); - $res += ( $num / $denom ) * ( 1 / 60 ); + $res += ( (int)$num / (int)$denom ) * ( 1 / 60 ); list( $num, $denom ) = explode( '/', $loc[2] ); - $res += ( $num / $denom ) * ( 1 / 3600 ); + $res += ( (int)$num / (int)$denom ) * ( 1 / 3600 ); if ( $dir === 'S' || $dir === 'W' ) { $res *= -1; // make negative diff --git a/includes/media/FormatMetadata.php b/includes/media/FormatMetadata.php index 917783652cba..4ea350573010 100644 --- a/includes/media/FormatMetadata.php +++ b/includes/media/FormatMetadata.php @@ -160,9 +160,9 @@ class FormatMetadata extends ContextSource { ) { continue; } - $vals = str_pad( intval( $h[0] / $h[1] ), 2, '0', STR_PAD_LEFT ) - . ':' . str_pad( intval( $m[0] / $m[1] ), 2, '0', STR_PAD_LEFT ) - . ':' . str_pad( intval( $s[0] / $s[1] ), 2, '0', STR_PAD_LEFT ); + $vals = str_pad( (string)( (int)$h[0] / (int)$h[1] ), 2, '0', STR_PAD_LEFT ) + . ':' . str_pad( (string)( (int)$m[0] / (int)$m[1] ), 2, '0', STR_PAD_LEFT ) + . ':' . str_pad( (string)( (int)$s[0] / (int)$s[1] ), 2, '0', STR_PAD_LEFT ); try { $time = wfTimestamp( TS_MW, '1971:01:01 ' . $vals ); @@ -861,7 +861,7 @@ class FormatMetadata extends ContextSource { // need to expand this earlier to calculate fNumber list( $n, $d ) = explode( '/', $val ); if ( is_numeric( $n ) && is_numeric( $d ) ) { - $val = $n / $d; + $val = (int)$n / (int)$d; } } if ( is_numeric( $val ) ) { @@ -1372,7 +1372,7 @@ class FormatMetadata extends ContextSource { } if ( preg_match( '/^(-?\d+)\/(\d+)$/', $num, $m ) ) { if ( $m[2] != 0 ) { - $newNum = $m[1] / $m[2]; + $newNum = (int)$m[1] / (int)$m[2]; if ( $round !== false ) { $newNum = round( $newNum, $round ); } diff --git a/includes/media/IPTC.php b/includes/media/IPTC.php index fd0db3769fad..3a5351984163 100644 --- a/includes/media/IPTC.php +++ b/includes/media/IPTC.php @@ -389,9 +389,9 @@ class IPTC { $tz = -$tz; } - $finalTimestamp = wfTimestamp( TS_EXIF, $unixTS + $tz ); + $finalTimestamp = wfTimestamp( TS_EXIF, (int)$unixTS + $tz ); if ( $finalTimestamp === false ) { - wfDebugLog( 'iptc', "IPTC: can't make final timestamp. Date: " . ( $unixTS + $tz ) ); + wfDebugLog( 'iptc', "IPTC: can't make final timestamp. Date: " . ( (int)$unixTS + $tz ) ); return null; } diff --git a/includes/media/JpegHandler.php b/includes/media/JpegHandler.php index 480e6735c173..b41beeda7abc 100644 --- a/includes/media/JpegHandler.php +++ b/includes/media/JpegHandler.php @@ -149,7 +149,7 @@ class JpegHandler extends ExifBitmapHandler { if ( $jpegTran && is_executable( $jpegTran ) ) { $command = Shell::command( $jpegTran, '-rotate', - $rotation, + (string)$rotation, '-outfile', $params['dstPath'], $params['srcPath'] diff --git a/includes/media/MediaHandler.php b/includes/media/MediaHandler.php index 6610f92ee36f..ded4a69bfc5e 100644 --- a/includes/media/MediaHandler.php +++ b/includes/media/MediaHandler.php @@ -863,7 +863,7 @@ abstract class MediaHandler { $idealWidth = $boxWidth * $maxHeight / $boxHeight; $roundedUp = ceil( $idealWidth ); if ( round( $roundedUp * $boxHeight / $boxWidth ) > $maxHeight ) { - return floor( $idealWidth ); + return (int)floor( $idealWidth ); } else { return $roundedUp; } diff --git a/includes/media/ThumbnailImage.php b/includes/media/ThumbnailImage.php index 7184c5ac8ea6..4276d4eef6ed 100644 --- a/includes/media/ThumbnailImage.php +++ b/includes/media/ThumbnailImage.php @@ -73,8 +73,8 @@ class ThumbnailImage extends MediaTransformOutput { # These should be integers when they get here. # If not, there's a bug somewhere. But let's at # least produce valid HTML code regardless. - $this->width = round( $actualParams['width'] ); - $this->height = round( $actualParams['height'] ); + $this->width = (int)round( $actualParams['width'] ); + $this->height = (int)round( $actualParams['height'] ); $this->page = $actualParams['page']; $this->lang = $actualParams['lang']; diff --git a/includes/objectcache/SqlBagOStuff.php b/includes/objectcache/SqlBagOStuff.php index da555931957d..c5ae117f6b27 100644 --- a/includes/objectcache/SqlBagOStuff.php +++ b/includes/objectcache/SqlBagOStuff.php @@ -499,7 +499,7 @@ class SqlBagOStuff extends MediumSpecificBagOStuff { */ private function getTableNameByShard( $index ) { if ( $index !== null && $this->numTableShards > 1 ) { - $decimals = strlen( $this->numTableShards - 1 ); + $decimals = strlen( (string)( $this->numTableShards - 1 ) ); return $this->tableName . sprintf( "%0{$decimals}d", $index ); } @@ -1103,7 +1103,7 @@ class SqlBagOStuff extends MediumSpecificBagOStuff { // 67 bit integral portion of UNIX timestamp, qualified \Wikimedia\base_convert( // 35 bit integral seconds portion of UNIX timestamp - str_pad( base_convert( $seconds, 10, 2 ), 35, '0', STR_PAD_LEFT ) . + str_pad( base_convert( (string)$seconds, 10, 2 ), 35, '0', STR_PAD_LEFT ) . // 32 bit ID of the primary database server handling the write str_pad( base_convert( $id, 10, 2 ), 32, '0', STR_PAD_LEFT ), 2, @@ -1484,7 +1484,7 @@ class SqlBagOStuff extends MediumSpecificBagOStuff { if ( $res->numRows() ) { $row = $res->current(); if ( $minExpUnix === null ) { - $minExpUnix = ConvertibleTimestamp::convert( TS_UNIX, $row->exptime ); + $minExpUnix = (int)ConvertibleTimestamp::convert( TS_UNIX, $row->exptime ); $totalSeconds = max( $cutoffUnix - $minExpUnix, 1 ); } @@ -1507,7 +1507,7 @@ class SqlBagOStuff extends MediumSpecificBagOStuff { if ( $progress && is_callable( $progress['fn'] ) ) { if ( $totalSeconds ) { - $maxExpUnix = ConvertibleTimestamp::convert( TS_UNIX, $maxExp ); + $maxExpUnix = (int)ConvertibleTimestamp::convert( TS_UNIX, $maxExp ); $remainingSeconds = $cutoffUnix - $maxExpUnix; $processedSeconds = max( $totalSeconds - $remainingSeconds, 0 ); // For example, if we've done 1.5 table shard, and are thus half-way on the diff --git a/includes/page/ImagePage.php b/includes/page/ImagePage.php index 20c0089da102..8a8b46c42083 100644 --- a/includes/page/ImagePage.php +++ b/includes/page/ImagePage.php @@ -533,7 +533,7 @@ class ImagePage extends Article { ]; $options = []; for ( $i = 1; $i <= $count; $i++ ) { - $options[] = Xml::option( $lang->formatNum( $i ), $i, $i == $page ); + $options[] = Xml::option( $lang->formatNum( $i ), (string)$i, $i == $page ); } $select = Xml::tags( 'select', [ 'id' => 'pageselector', 'name' => 'page' ], diff --git a/includes/parser/CoreMagicVariables.php b/includes/parser/CoreMagicVariables.php index 4879ae7158b1..3a2571071f97 100644 --- a/includes/parser/CoreMagicVariables.php +++ b/includes/parser/CoreMagicVariables.php @@ -226,7 +226,7 @@ class CoreMagicVariables { case 'namespacee': return wfUrlencode( $parser->getContentLanguage()->getNsText( $title->getNamespace() ) ); case 'namespacenumber': - return $title->getNamespace(); + return (string)$title->getNamespace(); case 'talkspace': return $title->canHaveTalkPage() ? str_replace( '_', ' ', $title->getTalkNsText() ) diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index 9117f0af6ff2..6415743b277c 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -565,7 +565,7 @@ class CoreParserFunctions { if ( $raw !== null && self::matchAgainstMagicword( $magicWordFactory, 'rawsuffix', $raw ) ) { - return $num; + return (string)$num; } else { return $language->formatNum( $num ); } diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 18ddf9272f3e..0e09a886319c 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -4195,7 +4195,7 @@ class Parser { $numbering = ''; $markerMatches = []; if ( preg_match( "/^$markerRegex/", $headline, $markerMatches ) ) { - $serial = $markerMatches[1]; + $serial = (int)$markerMatches[1]; list( $titleText, $sectionIndex ) = $this->mHeadings[$serial]; $isTemplate = ( $titleText != $baseTitleText ); $headline = preg_replace( "/^$markerRegex\\s*/", "", $headline ); diff --git a/includes/poolcounter/PoolCounterRedis.php b/includes/poolcounter/PoolCounterRedis.php index ab52329646c0..b89e917c59ca 100644 --- a/includes/poolcounter/PoolCounterRedis.php +++ b/includes/poolcounter/PoolCounterRedis.php @@ -95,7 +95,7 @@ class PoolCounterRedis extends PoolCounter { $this->keySha1 = sha1( $this->key ); $met = ini_get( 'max_execution_time' ); // usually 0 in CLI mode - $this->lockTTL = $met ? 2 * $met : 3600; + $this->lockTTL = $met ? 2 * (int)$met : 3600; if ( self::$active === null ) { self::$active = []; @@ -282,7 +282,7 @@ LUA; if ( $slot !== 'w' ) { $this->slot = $slot; - $this->slotTime = $slotTime; + $this->slotTime = (int)$slotTime; $this->onRelease = $doWakeup; self::$active[$this->session] = $this; } diff --git a/includes/preferences/DefaultPreferencesFactory.php b/includes/preferences/DefaultPreferencesFactory.php index cf276efc743c..8cf5109b369f 100644 --- a/includes/preferences/DefaultPreferencesFactory.php +++ b/includes/preferences/DefaultPreferencesFactory.php @@ -1019,7 +1019,7 @@ class DefaultPreferencesFactory implements PreferencesFactory { } } if ( count( $tz ) > 1 && $tz[0] == 'Offset' ) { - $minDiff = $tz[1]; + $minDiff = (int)$tz[1]; $tzSetting = sprintf( '%+03d:%02d', floor( $minDiff / 60 ), abs( $minDiff ) % 60 ); } @@ -1808,7 +1808,7 @@ class DefaultPreferencesFactory implements PreferencesFactory { $timestamp = MWTimestamp::getLocalInstance(); // Check that the LocalTZoffset is the same as the local time zone offset - if ( $localTZoffset === $timestamp->format( 'Z' ) / 60 ) { + if ( $localTZoffset === (int)$timestamp->format( 'Z' ) / 60 ) { $timezoneName = $timestamp->getTimezone()->getName(); // Localize timezone if ( isset( $timeZoneList[$timezoneName] ) ) { diff --git a/includes/session/CookieSessionProvider.php b/includes/session/CookieSessionProvider.php index 21ee26f76369..d3497bb137c9 100644 --- a/includes/session/CookieSessionProvider.php +++ b/includes/session/CookieSessionProvider.php @@ -303,7 +303,7 @@ class CookieSessionProvider extends SessionProvider { if ( $loggedOut + 86400 > time() && $loggedOut !== (int)$this->getCookie( $request, 'LoggedOut', $this->cookieOptions['prefix'] ) ) { - $request->response()->setCookie( 'LoggedOut', $loggedOut, $loggedOut + 86400, + $request->response()->setCookie( 'LoggedOut', (string)$loggedOut, $loggedOut + 86400, $this->cookieOptions ); } } diff --git a/includes/session/SessionManager.php b/includes/session/SessionManager.php index a2506e6a97b2..bc0d218aeb29 100644 --- a/includes/session/SessionManager.php +++ b/includes/session/SessionManager.php @@ -1060,7 +1060,7 @@ class SessionManager implements SessionManagerInterface { return; } $mwuser = $session->getRequest()->getCookie( 'mwuser-sessionId' ); - $now = \MWTimestamp::now( TS_UNIX ); + $now = (int)\MWTimestamp::now( TS_UNIX ); // Record (and possibly log) that the IP is using the current session. // Don't touch the stored data unless we are changing the IP or re-adding an expired one. diff --git a/includes/specials/SpecialBlock.php b/includes/specials/SpecialBlock.php index 9f6f5a40dee2..bc814c2f38a6 100644 --- a/includes/specials/SpecialBlock.php +++ b/includes/specials/SpecialBlock.php @@ -855,7 +855,7 @@ class SpecialBlock extends FormSpecialPage { } if ( isset( $data['NamespaceRestrictions'] ) && $data['NamespaceRestrictions'] !== '' ) { $namespaceRestrictions = array_map( static function ( $id ) { - return new NamespaceRestriction( 0, $id ); + return new NamespaceRestriction( 0, (int)$id ); }, explode( "\n", $data['NamespaceRestrictions'] ) ); } if ( diff --git a/includes/specials/SpecialBookSources.php b/includes/specials/SpecialBookSources.php index b0d9713037c4..99895ea0603e 100644 --- a/includes/specials/SpecialBookSources.php +++ b/includes/specials/SpecialBookSources.php @@ -87,9 +87,9 @@ class SpecialBookSources extends SpecialPage { if ( $isbn[$i] === 'X' ) { return false; } elseif ( $i % 2 == 0 ) { - $sum += $isbn[$i]; + $sum += (int)$isbn[$i]; } else { - $sum += 3 * $isbn[$i]; + $sum += 3 * (int)$isbn[$i]; } } @@ -102,7 +102,7 @@ class SpecialBookSources extends SpecialPage { if ( $isbn[$i] === 'X' ) { return false; } - $sum += $isbn[$i] * ( $i + 1 ); + $sum += (int)$isbn[$i] * ( $i + 1 ); } $check = $sum % 11; diff --git a/includes/specials/SpecialComparePages.php b/includes/specials/SpecialComparePages.php index aeec5b7a2d7c..c50057932c7c 100644 --- a/includes/specials/SpecialComparePages.php +++ b/includes/specials/SpecialComparePages.php @@ -176,7 +176,7 @@ class SpecialComparePages extends SpecialPage { if ( $value === '' || $value === null ) { return true; } - $revisionRecord = $this->revisionLookup->getRevisionById( $value ); + $revisionRecord = $this->revisionLookup->getRevisionById( (int)$value ); if ( $revisionRecord === null ) { return $this->msg( 'compare-revision-not-exists' )->parseAsBlock(); } diff --git a/includes/specials/SpecialEditWatchlist.php b/includes/specials/SpecialEditWatchlist.php index 212f60a607d2..cdac1ad5cecd 100644 --- a/includes/specials/SpecialEditWatchlist.php +++ b/includes/specials/SpecialEditWatchlist.php @@ -677,7 +677,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { foreach ( $fields as $data ) { # strip out the 'ns' prefix from the section name: - $ns = substr( $data['section'], 2 ); + $ns = (int)substr( $data['section'], 2 ); $nsText = ( $ns == NS_MAIN ) ? $this->msg( 'blanknamespace' )->escaped() diff --git a/includes/specials/SpecialExport.php b/includes/specials/SpecialExport.php index ebf75c2d7954..3b548103d70b 100644 --- a/includes/specials/SpecialExport.php +++ b/includes/specials/SpecialExport.php @@ -105,7 +105,7 @@ class SpecialExport extends SpecialPage { /** * Same implementation as above, so same @todo */ - $nspages = $this->getPagesFromNamespace( $nsindex ); + $nspages = $this->getPagesFromNamespace( (int)$nsindex ); if ( $nspages ) { $page .= "\n" . implode( "\n", $nspages ); } diff --git a/includes/specials/SpecialRevisionDelete.php b/includes/specials/SpecialRevisionDelete.php index 8816bab8c893..589bfc58cf1a 100644 --- a/includes/specials/SpecialRevisionDelete.php +++ b/includes/specials/SpecialRevisionDelete.php @@ -577,7 +577,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage { $this->msg( $message )->text(), $name, $name, - $bitfield & $field + (bool)( $bitfield & $field ) ); if ( $field == RevisionRecord::DELETED_RESTRICTED ) { diff --git a/includes/specials/SpecialVersion.php b/includes/specials/SpecialVersion.php index 966ea699d002..8cc626a4b35a 100644 --- a/includes/specials/SpecialVersion.php +++ b/includes/specials/SpecialVersion.php @@ -396,7 +396,7 @@ class SpecialVersion extends SpecialPage { $gitHeadCommitDate = $gitInfo->getHeadCommitDate(); if ( $gitHeadCommitDate ) { - $shortSHA1 .= Html::element( 'br' ) . $wgLang->timeanddate( $gitHeadCommitDate, true ); + $shortSHA1 .= Html::element( 'br' ) . $wgLang->timeanddate( (string)$gitHeadCommitDate, true ); } return self::getMWVersionLinked() . " $shortSHA1"; diff --git a/includes/specials/SpecialWatchlist.php b/includes/specials/SpecialWatchlist.php index 74df5d560a62..a07b93dd068f 100644 --- a/includes/specials/SpecialWatchlist.php +++ b/includes/specials/SpecialWatchlist.php @@ -905,7 +905,7 @@ class SpecialWatchlist extends ChangesListSpecialPage { 'span', $attribs, // not using Html::checkLabel because that would escape the contents - Html::check( $name, (int)$value, [ 'id' => $name ] ) . "\n" . Html::rawElement( + Html::check( $name, (bool)$value, [ 'id' => $name ] ) . "\n" . Html::rawElement( 'label', $attribs + [ 'for' => $name ], // <nowiki/> at beginning to avoid messages with "$1 ..." being parsed as pre tags @@ -923,7 +923,7 @@ class SpecialWatchlist extends ChangesListSpecialPage { */ protected function countItems() { $count = $this->watchedItemStore->countWatchedItems( $this->getUser() ); - return floor( $count / 2 ); + return (int)floor( $count / 2 ); } /** diff --git a/includes/specials/forms/EditWatchlistNormalHTMLForm.php b/includes/specials/forms/EditWatchlistNormalHTMLForm.php index 53207ba57ead..00e79b970642 100644 --- a/includes/specials/forms/EditWatchlistNormalHTMLForm.php +++ b/includes/specials/forms/EditWatchlistNormalHTMLForm.php @@ -23,7 +23,7 @@ */ class EditWatchlistNormalHTMLForm extends OOUIHTMLForm { public function getLegend( $namespace ) { - $namespace = substr( $namespace, 2 ); + $namespace = (int)substr( $namespace, 2 ); return $namespace == NS_MAIN ? $this->msg( 'blanknamespace' )->text() diff --git a/includes/specials/pagers/BlockListPager.php b/includes/specials/pagers/BlockListPager.php index e9e539aa1a61..13ee501889b8 100644 --- a/includes/specials/pagers/BlockListPager.php +++ b/includes/specials/pagers/BlockListPager.php @@ -252,8 +252,8 @@ class BlockListPager extends TablePager { break; case 'ipb_by': - $formatted = Linker::userLink( $value, $row->ipb_by_text ); - $formatted .= Linker::userToolLinks( $value, $row->ipb_by_text ); + $formatted = Linker::userLink( (int)$value, $row->ipb_by_text ); + $formatted .= Linker::userToolLinks( (int)$value, $row->ipb_by_text ); break; case 'ipb_reason': diff --git a/includes/specials/pagers/ContribsPager.php b/includes/specials/pagers/ContribsPager.php index e3a2415ffd46..5a51c89a985d 100644 --- a/includes/specials/pagers/ContribsPager.php +++ b/includes/specials/pagers/ContribsPager.php @@ -315,7 +315,7 @@ class ContribsPager extends RangeChronologicalPager { // If the query results are in descending order, the indexes must also be in descending order $index = $order === self::QUERY_ASCENDING ? $i : $limit - 1 - $i; // Left-pad with zeroes, because these values will be sorted as strings - $index = str_pad( $index, strlen( $limit ), '0', STR_PAD_LEFT ); + $index = str_pad( (string)$index, strlen( (string)$limit ), '0', STR_PAD_LEFT ); // use index column as key, allowing us to easily sort in PHP $result[$row->{$this->getIndexField()} . "-$index"] = $row; } diff --git a/includes/specials/pagers/ImageListPager.php b/includes/specials/pagers/ImageListPager.php index ccd632d7c62e..f6d1fc42aa5f 100644 --- a/includes/specials/pagers/ImageListPager.php +++ b/includes/specials/pagers/ImageListPager.php @@ -502,7 +502,7 @@ class ImageListPager extends TablePager { return $link; case 'img_size': - return htmlspecialchars( $this->getLanguage()->formatSize( $value ) ); + return htmlspecialchars( $this->getLanguage()->formatSize( (int)$value ) ); case 'img_description': $field = $this->mCurrentRow->description_field; $value = $this->commentStore->getComment( $field, $this->mCurrentRow )->text; diff --git a/includes/specials/pagers/ProtectedPagesPager.php b/includes/specials/pagers/ProtectedPagesPager.php index 4fa22a746c9b..eece60f1041e 100644 --- a/includes/specials/pagers/ProtectedPagesPager.php +++ b/includes/specials/pagers/ProtectedPagesPager.php @@ -233,8 +233,8 @@ class ProtectedPagesPager extends TablePager { LogPage::DELETED_USER, $this->getUser() ) ) { - $formatted = Linker::userLink( $value, $username ) - . Linker::userToolLinks( $value, $username ); + $formatted = Linker::userLink( (int)$value, $username ) + . Linker::userToolLinks( (int)$value, $username ); } else { $formatted = $this->msg( 'rev-deleted-user' )->escaped(); } diff --git a/includes/upload/UploadStash.php b/includes/upload/UploadStash.php index eab47962a300..fed1e069bc62 100644 --- a/includes/upload/UploadStash.php +++ b/includes/upload/UploadStash.php @@ -229,7 +229,7 @@ class UploadStash { list( $usec, $sec ) = explode( ' ', microtime() ); $usec = substr( $usec, 2 ); $key = Wikimedia\base_convert( $sec . $usec, 10, 36 ) . '.' . - Wikimedia\base_convert( mt_rand(), 10, 36 ) . '.' . + Wikimedia\base_convert( (string)mt_rand(), 10, 36 ) . '.' . $this->user->getId() . '.' . $extension; diff --git a/includes/utils/ZipDirectoryReader.php b/includes/utils/ZipDirectoryReader.php index 87a2edecaa26..3ec0bf6b0b41 100644 --- a/includes/utils/ZipDirectoryReader.php +++ b/includes/utils/ZipDirectoryReader.php @@ -532,8 +532,8 @@ class ZipDirectoryReader { $this->error( 'zip-bad', "getBlock() requested end position $end, " . "file length is $fileLength" ); } - $startSeg = floor( $start / self::SEGSIZE ); - $endSeg = ceil( $end / self::SEGSIZE ); + $startSeg = (int)floor( $start / self::SEGSIZE ); + $endSeg = (int)ceil( $end / self::SEGSIZE ); $block = ''; for ( $segIndex = $startSeg; $segIndex <= $endSeg; $segIndex++ ) { |