From f6e5079a6964b10deff40c3224957cab2474dde7 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Wed, 10 Jun 2015 11:29:05 -0700 Subject: [PATCH] Use mediawiki/at-ease library for suppressing warnings wfSuppressWarnings() and wfRestoreWarnings() were split out into a separate library. All usages in core were replaced with the new functions, and the wf* global functions are marked as deprecated. Additionally, some uses of @ were replaced due to composer's autoloader being loaded even earlier. Ie1234f8c12693408de9b94bf6f84480a90bd4f8e adds the library to mediawiki/vendor. Bug: T100923 Change-Id: I5c35079a0a656180852be0ae6b1262d40f6534c4 --- composer.json | 1 + includes/Collation.php | 8 +-- includes/GitInfo.php | 4 +- includes/GlobalFunctions.php | 61 ++++++------------- includes/HistoryBlob.php | 8 +-- includes/HttpFunctions.php | 8 +-- includes/Import.php | 4 +- includes/MediaWiki.php | 4 +- includes/MimeMagic.php | 8 +-- includes/OutputPage.php | 4 +- includes/Sanitizer.php | 24 ++++---- includes/Setup.php | 10 +-- includes/SquidPurgeClient.php | 24 ++++---- includes/StreamFile.php | 4 +- includes/WebRequest.php | 4 +- includes/api/ApiQueryImageInfo.php | 4 +- includes/cache/CacheDependency.php | 8 +-- includes/cache/FileCacheBase.php | 4 +- includes/cache/LocalisationCache.php | 8 +-- includes/cache/MessageCache.php | 12 ++-- includes/changes/RecentChange.php | 4 +- includes/content/ContentHandler.php | 4 +- includes/db/Database.php | 4 +- includes/db/DatabaseMssql.php | 4 +- includes/db/DatabaseMysqlBase.php | 24 ++++---- includes/db/DatabaseOracle.php | 24 ++++---- includes/db/DatabasePostgres.php | 16 ++--- includes/debug/logger/LegacyLogger.php | 4 +- includes/exception/MWExceptionHandler.php | 2 +- includes/filebackend/FSFile.php | 8 +-- includes/filebackend/FileBackendStore.php | 8 +-- includes/filebackend/FileOp.php | 4 +- includes/filebackend/MemoryFileBackend.php | 4 +- includes/filebackend/SwiftFileBackend.php | 4 +- includes/filebackend/TempFSFile.php | 12 ++-- .../filebackend/lockmanager/FSLockManager.php | 4 +- includes/filerepo/FileRepo.php | 8 +-- includes/installer/DatabaseInstaller.php | 4 +- includes/installer/Installer.php | 22 +++---- includes/installer/SqliteInstaller.php | 4 +- includes/logging/LogEntry.php | 4 +- includes/mail/UserMailer.php | 8 +-- includes/media/Bitmap.php | 4 +- includes/media/DjVu.php | 8 +-- includes/media/DjVuImage.php | 4 +- includes/media/Exif.php | 12 ++-- includes/media/ExifBitmap.php | 8 +-- includes/media/GIF.php | 8 +-- includes/media/GIFMetadataExtractor.php | 4 +- includes/media/IPTC.php | 4 +- includes/media/ImageHandler.php | 4 +- includes/media/JpegMetadataExtractor.php | 4 +- includes/media/MediaHandler.php | 4 +- includes/media/PNG.php | 8 +-- includes/media/PNGMetadataExtractor.php | 16 ++--- includes/media/SVG.php | 8 +-- includes/media/SVGMetadataExtractor.php | 6 +- includes/media/XCF.php | 4 +- includes/media/XMP.php | 8 +-- includes/objectcache/MemcachedClient.php | 4 +- includes/objectcache/SqlBagOStuff.php | 4 +- includes/parser/Preprocessor_DOM.php | 8 +-- .../resourceloader/ResourceLoaderModule.php | 4 +- includes/search/SearchMySQL.php | 4 +- includes/search/SearchSqlite.php | 4 +- includes/skins/MediaWikiI18N.php | 4 +- includes/specials/SpecialContributions.php | 4 +- .../specials/SpecialDeletedContributions.php | 4 +- includes/specials/SpecialExport.php | 4 +- includes/specials/SpecialLockdb.php | 4 +- includes/specials/SpecialUnlockdb.php | 4 +- includes/specials/SpecialVersion.php | 4 +- includes/upload/UploadBase.php | 4 +- includes/utils/MWCryptRand.php | 8 +-- includes/utils/UIDGenerator.php | 4 +- languages/Language.php | 12 ++-- maintenance/Maintenance.php | 7 +-- maintenance/backup.inc | 4 +- maintenance/backupTextPass.inc | 8 +-- maintenance/checkSyntax.php | 4 +- maintenance/importImages.php | 12 ++-- maintenance/install.php | 8 +-- maintenance/jsparse.php | 4 +- maintenance/language/StatOutputs.php | 8 +-- maintenance/rebuildFileCache.php | 4 +- maintenance/sqlite.php | 4 +- maintenance/storage/fixBug20757.php | 4 +- maintenance/storage/recompressTracked.php | 4 +- tests/phpunit/MediaWikiTestCase.php | 8 +-- .../includes/GlobalFunctions/GlobalTest.php | 4 +- tests/phpunit/includes/api/ApiUploadTest.php | 8 +-- tests/phpunit/includes/debug/MWDebugTest.php | 4 +- .../includes/libs/JavaScriptMinifierTest.php | 4 +- tests/phpunit/structure/AutoLoaderTest.php | 4 +- thumb.php | 4 +- 95 files changed, 338 insertions(+), 359 deletions(-) diff --git a/composer.json b/composer.json index 7df8ca0b73..fba1a82423 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,7 @@ "ext-iconv": "*", "leafo/lessphp": "0.5.0", "liuggio/statsd-php-client": "1.0.12", + "mediawiki/at-ease": "1.0.0", "oojs/oojs-ui": "0.11.4", "php": ">=5.3.3", "psr/log": "1.0.0", diff --git a/includes/Collation.php b/includes/Collation.php index 481d8e7034..c1f0b3881a 100644 --- a/includes/Collation.php +++ b/includes/Collation.php @@ -320,16 +320,16 @@ class IcuCollation extends Collation { // intl extension produces non null-terminated // strings. Appending '' fixes it so that it doesn't generate // a warning on each access in debug php. - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); $key = $this->mainCollator->getSortKey( $string ) . ''; - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); return $key; } function getPrimarySortKey( $string ) { - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); $key = $this->primaryCollator->getSortKey( $string ) . ''; - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); return $key; } diff --git a/includes/GitInfo.php b/includes/GitInfo.php index fb298cfeed..7f05bb0fd7 100644 --- a/includes/GitInfo.php +++ b/includes/GitInfo.php @@ -281,9 +281,9 @@ class GitInfo { $config = "{$this->basedir}/config"; $url = false; if ( is_readable( $config ) ) { - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); $configArray = parse_ini_file( $config, true ); - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); $remote = false; // Use the "origin" remote repo if available or any other repo if not. diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 25876fb99a..7a9b27bbf5 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -860,9 +860,9 @@ function wfParseUrl( $url ) { if ( $wasRelative ) { $url = "http:$url"; } - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); $bits = parse_url( $url ); - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); // parse_url() returns an array without scheme for some invalid URLs, e.g. // parse_url("%0Ahttp://example.com") == array( 'host' => '%0Ahttp', 'path' => 'example.com' ) if ( !$bits || !isset( $bits['scheme'] ) ) { @@ -2322,40 +2322,19 @@ function wfNegotiateType( $cprefs, $sprefs ) { /** * Reference-counted warning suppression * + * @deprecated since 1.26, use MediaWiki\suppressWarnings() directly * @param bool $end */ function wfSuppressWarnings( $end = false ) { - static $suppressCount = 0; - static $originalLevel = false; - - if ( $end ) { - if ( $suppressCount ) { - --$suppressCount; - if ( !$suppressCount ) { - error_reporting( $originalLevel ); - } - } - } else { - if ( !$suppressCount ) { - $originalLevel = error_reporting( E_ALL & ~( - E_WARNING | - E_NOTICE | - E_USER_WARNING | - E_USER_NOTICE | - E_DEPRECATED | - E_USER_DEPRECATED | - E_STRICT - ) ); - } - ++$suppressCount; - } + MediaWiki\suppressWarnings( $end ); } /** + * @deprecated since 1.26, use MediaWiki\restoreWarnings() directly * Restore error level to previous value */ function wfRestoreWarnings() { - wfSuppressWarnings( true ); + MediaWiki\suppressWarnings( true ); } # Autodetect, convert and provide timestamps of various types @@ -2536,9 +2515,9 @@ function wfMkdirParents( $dir, $mode = null, $caller = null ) { } // Turn off the normal warning, we're doing our own below - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); $ok = mkdir( $dir, $mode, true ); // PHP5 <3 - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); if ( !$ok ) { //directory may have been created on another request since we last checked @@ -3033,9 +3012,9 @@ function wfMerge( $old, $mine, $yours, &$result ) { # This check may also protect against code injection in # case of broken installations. - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); $haveDiff3 = $wgDiff3 && file_exists( $wgDiff3 ); - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); if ( !$haveDiff3 ) { wfDebug( "diff3 not found\n" ); @@ -3112,9 +3091,9 @@ function wfDiff( $before, $after, $params = '-u' ) { } global $wgDiff; - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); $haveDiff = $wgDiff && file_exists( $wgDiff ); - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); # This check may also protect against code injection in # case of broken installations. @@ -3491,9 +3470,9 @@ function wfSetupSession( $sessionId = false ) { } else { wfFixSessionID(); } - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); session_start(); - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); } /** @@ -3846,15 +3825,15 @@ function wfMemoryLimit() { $conflimit = wfShorthandToInteger( $wgMemoryLimit ); if ( $conflimit == -1 ) { wfDebug( "Removing PHP's memory limit\n" ); - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); ini_set( 'memory_limit', $conflimit ); - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); return $conflimit; } elseif ( $conflimit > $memlimit ) { wfDebug( "Raising PHP's memory limit to $conflimit bytes\n" ); - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); ini_set( 'memory_limit', $conflimit ); - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); return $conflimit; } } @@ -3999,9 +3978,9 @@ function wfUnpack( $format, $data, $length = false ) { } } - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); $result = unpack( $format, $data ); - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); if ( $result === false ) { // If it cannot extract the packed data. diff --git a/includes/HistoryBlob.php b/includes/HistoryBlob.php index 69f1120d43..494cbfaf8f 100644 --- a/includes/HistoryBlob.php +++ b/includes/HistoryBlob.php @@ -522,9 +522,9 @@ class DiffHistoryBlob implements HistoryBlob { function diff( $t1, $t2 ) { # Need to do a null concatenation with warnings off, due to bugs in the current version of xdiff # "String is not zero-terminated" - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); $diff = xdiff_string_rabdiff( $t1, $t2 ) . ''; - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); return $diff; } @@ -535,9 +535,9 @@ class DiffHistoryBlob implements HistoryBlob { */ function patch( $base, $diff ) { if ( function_exists( 'xdiff_string_bpatch' ) ) { - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); $text = xdiff_string_bpatch( $base, $diff ) . ''; - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); return $text; } diff --git a/includes/HttpFunctions.php b/includes/HttpFunctions.php index 8e05f597d9..825cd064e8 100644 --- a/includes/HttpFunctions.php +++ b/includes/HttpFunctions.php @@ -792,14 +792,14 @@ class CurlHttpRequest extends MWHttpRequest { } if ( $this->followRedirects && $this->canFollowRedirects() ) { - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); if ( !curl_setopt( $curlHandle, CURLOPT_FOLLOWLOCATION, true ) ) { wfDebug( __METHOD__ . ": Couldn't set CURLOPT_FOLLOWLOCATION. " . "Probably safe_mode or open_basedir is set.\n" ); // Continue the processing. If it were in curl_setopt_array, // processing would have halted on its entry } - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); } if ( $this->profiler ) { @@ -938,9 +938,9 @@ class PhpHttpRequest extends MWHttpRequest { } do { $reqCount++; - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); $fh = fopen( $url, "r", false, $context ); - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); if ( !$fh ) { break; diff --git a/includes/Import.php b/includes/Import.php index ee57a9e01e..214bc4e793 100644 --- a/includes/Import.php +++ b/includes/Import.php @@ -1857,9 +1857,9 @@ class ImportStreamSource implements ImportSource { * @return Status */ static function newFromFile( $filename ) { - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); $file = fopen( $filename, 'rt' ); - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); if ( !$file ) { return Status::newFatal( "importcantopen" ); } diff --git a/includes/MediaWiki.php b/includes/MediaWiki.php index df0870b899..7a0d7b7ce3 100644 --- a/includes/MediaWiki.php +++ b/includes/MediaWiki.php @@ -715,7 +715,7 @@ class MediaWiki { $errno = $errstr = null; $info = wfParseUrl( $this->config->get( 'Server' ) ); - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); $sock = fsockopen( $info['host'], isset( $info['port'] ) ? $info['port'] : 80, @@ -725,7 +725,7 @@ class MediaWiki { // is a problem elsewhere. 0.1 ); - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); if ( !$sock ) { $runJobsLogger->error( "Failed to start cron API (socket error $errno): $errstr" ); // Fall back to running the job here while the user waits diff --git a/includes/MimeMagic.php b/includes/MimeMagic.php index ebe98a3c1d..0d907b7e31 100644 --- a/includes/MimeMagic.php +++ b/includes/MimeMagic.php @@ -624,9 +624,9 @@ class MimeMagic { */ private function doGuessMimeType( $file, $ext ) { // TODO: remove $ext param // Read a chunk of the file - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); $f = fopen( $file, 'rb' ); - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); if ( !$f ) { return 'unknown/unknown'; @@ -780,9 +780,9 @@ class MimeMagic { return $this->detectZipType( $head, $tail, $ext ); } - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); $gis = getimagesize( $file ); - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); if ( $gis && isset( $gis['mime'] ) ) { $mime = $gis['mime']; diff --git a/includes/OutputPage.php b/includes/OutputPage.php index a8fc01dd75..fd553798c0 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -809,9 +809,9 @@ class OutputPage extends ContextSource { # this breaks strtotime(). $clientHeader = preg_replace( '/;.*$/', '', $clientHeader ); - wfSuppressWarnings(); // E_STRICT system time bitching + MediaWiki\suppressWarnings(); // E_STRICT system time bitching $clientHeaderTime = strtotime( $clientHeader ); - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); if ( !$clientHeaderTime ) { wfDebug( __METHOD__ . ": unable to parse the client's If-Modified-Since header: $clientHeader\n" ); diff --git a/includes/Sanitizer.php b/includes/Sanitizer.php index 8256db96bb..677d5a438e 100644 --- a/includes/Sanitizer.php +++ b/includes/Sanitizer.php @@ -488,9 +488,9 @@ class Sanitizer { $badtag = true; } elseif ( $slash ) { # Closing a tag... is it the one we just opened? - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); $ot = array_pop( $tagstack ); - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); if ( $ot != $t ) { if ( isset( $htmlsingleallowed[$ot] ) ) { @@ -498,32 +498,32 @@ class Sanitizer { # and see if we find a match below them $optstack = array(); array_push( $optstack, $ot ); - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); $ot = array_pop( $tagstack ); - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); while ( $ot != $t && isset( $htmlsingleallowed[$ot] ) ) { array_push( $optstack, $ot ); - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); $ot = array_pop( $tagstack ); - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); } if ( $t != $ot ) { # No match. Push the optional elements back again $badtag = true; - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); $ot = array_pop( $optstack ); - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); while ( $ot ) { array_push( $tagstack, $ot ); - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); $ot = array_pop( $optstack ); - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); } } } else { - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); array_push( $tagstack, $ot ); - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); #
  • can be nested in