From: Ori Livneh Date: Mon, 4 Feb 2013 03:01:17 +0000 (-0800) Subject: (Bug 37957) Replace php_sapi_name() with PHP_SAPI X-Git-Tag: 1.31.0-rc.0~20808 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22articles%22%2C%22id_article=%24id_article%22%29%20.%20%22?a=commitdiff_plain;h=6c163ad26532346ae30984ad1423ee4bf5aed561;p=lhc%2Fweb%2Fwiklou.git (Bug 37957) Replace php_sapi_name() with PHP_SAPI The PHP_SAPI constant has been available since PHP 4.2.0. It's more concise to use the constant and has less overhead than a function call. Furthermore, PHP_SAPI rhymes with "happy", whereas "php_sapi_name" rhymes with "lame". QED, etc. Change-Id: Ie8c121cb8fcef50536af8d3f66723b458f0bf9af --- diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index ca6505cb73..68c4542ce8 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -123,9 +123,9 @@ $wgScriptPath = '/wiki'; * redirect loops when "pretty URLs" are used. */ $wgUsePathInfo = - ( strpos( php_sapi_name(), 'cgi' ) === false ) && - ( strpos( php_sapi_name(), 'apache2filter' ) === false ) && - ( strpos( php_sapi_name(), 'isapi' ) === false ); + ( strpos( PHP_SAPI, 'cgi' ) === false ) && + ( strpos( PHP_SAPI, 'apache2filter' ) === false ) && + ( strpos( PHP_SAPI, 'isapi' ) === false ); /** * The extension to append to script names by default. This can either be .php diff --git a/includes/ForkController.php b/includes/ForkController.php index 2a05411ef2..89ad955385 100644 --- a/includes/ForkController.php +++ b/includes/ForkController.php @@ -53,7 +53,7 @@ class ForkController { const RESTART_ON_ERROR = 1; public function __construct( $numProcs, $flags = 0 ) { - if ( php_sapi_name() != 'cli' ) { + if ( PHP_SAPI != 'cli' ) { throw new MWException( "ForkController cannot be used from the web." ); } $this->procsToStart = $numProcs; diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 1ff9ac7b40..c57018ef98 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -2681,8 +2681,7 @@ function wfDl( $extension, $fileName = null ) { } $canDl = false; - $sapi = php_sapi_name(); - if( $sapi == 'cli' || $sapi == 'cgi' || $sapi == 'embed' ) { + if( PHP_SAPI == 'cli' || PHP_SAPI == 'cgi' || PHP_SAPI == 'embed' ) { $canDl = ( function_exists( 'dl' ) && is_callable( 'dl' ) && wfIniGetBool( 'enable_dl' ) && !wfIniGetBool( 'safe_mode' ) ); } diff --git a/includes/api/ApiQuerySiteinfo.php b/includes/api/ApiQuerySiteinfo.php index 04897e8e55..3b4220cbef 100644 --- a/includes/api/ApiQuerySiteinfo.php +++ b/includes/api/ApiQuerySiteinfo.php @@ -120,7 +120,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { $data['sitename'] = $GLOBALS['wgSitename']; $data['generator'] = "MediaWiki {$GLOBALS['wgVersion']}"; $data['phpversion'] = phpversion(); - $data['phpsapi'] = php_sapi_name(); + $data['phpsapi'] = PHP_SAPI; $data['dbtype'] = $GLOBALS['wgDBtype']; $data['dbversion'] = $this->getDB()->getServerVersion(); diff --git a/includes/filebackend/SwiftFileBackend.php b/includes/filebackend/SwiftFileBackend.php index 3c097a1f9b..d825d049f2 100644 --- a/includes/filebackend/SwiftFileBackend.php +++ b/includes/filebackend/SwiftFileBackend.php @@ -148,7 +148,7 @@ class SwiftFileBackend extends FileBackendStore { $this->connContainerCache = new ProcessCacheLRU( 300 ); // Cache auth token information to avoid RTTs if ( !empty( $config['cacheAuthInfo'] ) ) { - if ( php_sapi_name() === 'cli' ) { + if ( PHP_SAPI === 'cli' ) { $this->srvCache = wfGetMainCache(); // preferrably memcached } else { try { // look for APC, XCache, WinCache, ect... diff --git a/includes/normal/RandomTest.php b/includes/normal/RandomTest.php index 23471e94e1..9dc1c86150 100644 --- a/includes/normal/RandomTest.php +++ b/includes/normal/RandomTest.php @@ -26,7 +26,7 @@ * @ingroup UtfNormal */ -if( php_sapi_name() != 'cli' ) { +if( PHP_SAPI != 'cli' ) { die( "Run me from the command line please.\n" ); } diff --git a/includes/normal/Utf8CaseGenerate.php b/includes/normal/Utf8CaseGenerate.php index d9deb3c36f..eaa2304e12 100644 --- a/includes/normal/Utf8CaseGenerate.php +++ b/includes/normal/Utf8CaseGenerate.php @@ -25,7 +25,7 @@ * @ingroup UtfNormal */ -if( php_sapi_name() != 'cli' ) { +if( PHP_SAPI != 'cli' ) { die( "Run me from the command line please.\n" ); } diff --git a/includes/normal/Utf8Test.php b/includes/normal/Utf8Test.php index 6eae6e7275..904a27ff61 100644 --- a/includes/normal/Utf8Test.php +++ b/includes/normal/Utf8Test.php @@ -34,7 +34,7 @@ mb_internal_encoding( "utf-8" ); $verbose = false; #$verbose = true; -if( php_sapi_name() != 'cli' ) { +if( PHP_SAPI != 'cli' ) { die( "Run me from the command line please.\n" ); } diff --git a/includes/normal/UtfNormalBench.php b/includes/normal/UtfNormalBench.php index 9a05b81678..392ba2bfdf 100644 --- a/includes/normal/UtfNormalBench.php +++ b/includes/normal/UtfNormalBench.php @@ -34,7 +34,7 @@ require_once 'UtfNormal.php'; define( 'BENCH_CYCLES', 5 ); -if( php_sapi_name() != 'cli' ) { +if( PHP_SAPI != 'cli' ) { die( "Run me from the command line please.\n" ); } diff --git a/includes/normal/UtfNormalGenerate.php b/includes/normal/UtfNormalGenerate.php index 11d06d4ccd..f392df52aa 100644 --- a/includes/normal/UtfNormalGenerate.php +++ b/includes/normal/UtfNormalGenerate.php @@ -25,7 +25,7 @@ * @ingroup UtfNormal */ -if( php_sapi_name() != 'cli' ) { +if( PHP_SAPI != 'cli' ) { die( "Run me from the command line please.\n" ); } diff --git a/includes/normal/UtfNormalMemStress.php b/includes/normal/UtfNormalMemStress.php index 7162a8b1b9..257e105bab 100644 --- a/includes/normal/UtfNormalMemStress.php +++ b/includes/normal/UtfNormalMemStress.php @@ -38,7 +38,7 @@ define( 'BENCH_CYCLES', 1 ); define( 'BIGSIZE', 1024 * 1024 * 10); // 10m ini_set('memory_limit', BIGSIZE + 120 * 1024 * 1024); -if( php_sapi_name() != 'cli' ) { +if( PHP_SAPI != 'cli' ) { die( "Run me from the command line please.\n" ); } diff --git a/includes/normal/UtfNormalTest.php b/includes/normal/UtfNormalTest.php index 5872ec34ca..22e6471673 100644 --- a/includes/normal/UtfNormalTest.php +++ b/includes/normal/UtfNormalTest.php @@ -54,7 +54,7 @@ require_once 'UtfNormalDefines.php'; require_once 'UtfNormalUtil.php'; require_once 'UtfNormal.php'; -if( php_sapi_name() != 'cli' ) { +if( PHP_SAPI != 'cli' ) { die( "Run me from the command line please.\n" ); } diff --git a/includes/normal/UtfNormalTest2.php b/includes/normal/UtfNormalTest2.php index 691bfaa74d..f4a8379223 100644 --- a/includes/normal/UtfNormalTest2.php +++ b/includes/normal/UtfNormalTest2.php @@ -22,7 +22,7 @@ * @ingroup UtfNormal */ -if( php_sapi_name() != 'cli' ) { +if( PHP_SAPI != 'cli' ) { die( "Run me from the command line please.\n" ); } diff --git a/includes/profiler/ProfilerSimpleText.php b/includes/profiler/ProfilerSimpleText.php index 847e34ff40..37350bf35c 100644 --- a/includes/profiler/ProfilerSimpleText.php +++ b/includes/profiler/ProfilerSimpleText.php @@ -50,7 +50,7 @@ class ProfilerSimpleText extends ProfilerSimple { : 0; // profiling mismatch error? uasort( $this->mCollated, array( 'self', 'sort' ) ); array_walk( $this->mCollated, array( 'self', 'format' ), $totalReal ); - if ( php_sapi_name() === 'cli' ) { + if ( PHP_SAPI === 'cli' ) { print "\n"; } elseif ( $this->getContentType() === 'text/html' ) { if ( $this->visible ) { diff --git a/includes/profiler/ProfilerSimpleTrace.php b/includes/profiler/ProfilerSimpleTrace.php index f766a39be1..d44dfe1bcb 100644 --- a/includes/profiler/ProfilerSimpleTrace.php +++ b/includes/profiler/ProfilerSimpleTrace.php @@ -69,7 +69,7 @@ class ProfilerSimpleTrace extends ProfilerSimple { } function logData() { - if ( php_sapi_name() === 'cli' ) { + if ( PHP_SAPI === 'cli' ) { print ""; } elseif ( $this->getContentType() === 'text/html' ) { print ""; diff --git a/includes/specials/SpecialVersion.php b/includes/specials/SpecialVersion.php index c87a6ff2d2..b04f1ef2d1 100644 --- a/includes/specials/SpecialVersion.php +++ b/includes/specials/SpecialVersion.php @@ -148,7 +148,7 @@ class SpecialVersion extends SpecialPage { // wikimarkup can be used. $software = array(); $software['[https://www.mediawiki.org/ MediaWiki]'] = self::getVersionLinked(); - $software['[http://www.php.net/ PHP]'] = phpversion() . " (" . php_sapi_name() . ")"; + $software['[http://www.php.net/ PHP]'] = phpversion() . " (" . PHP_SAPI . ")"; $software[$dbr->getSoftwareLink()] = $dbr->getServerInfo(); // Allow a hook to add/remove items. diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index c32069510a..2a8b8e5099 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -342,7 +342,7 @@ abstract class Maintenance { */ protected function error( $err, $die = 0 ) { $this->outputChanneled( false ); - if ( php_sapi_name() == 'cli' ) { + if ( PHP_SAPI == 'cli' ) { fwrite( STDERR, $err . "\n" ); } else { print $err; diff --git a/maintenance/dev/includes/router.php b/maintenance/dev/includes/router.php index ac96f459d1..1d5070b1b5 100644 --- a/maintenance/dev/includes/router.php +++ b/maintenance/dev/includes/router.php @@ -21,7 +21,7 @@ * @file */ -if ( php_sapi_name() != 'cli-server' ) { +if ( PHP_SAPI != 'cli-server' ) { die( "This script can only be run by php's cli-server sapi." ); } diff --git a/maintenance/locking/LockServerDaemon.php b/maintenance/locking/LockServerDaemon.php index 0ba9bfec78..01fbac72d6 100644 --- a/maintenance/locking/LockServerDaemon.php +++ b/maintenance/locking/LockServerDaemon.php @@ -23,7 +23,7 @@ * @ingroup LockManager Maintenance */ -if ( php_sapi_name() !== 'cli' ) { +if ( PHP_SAPI !== 'cli' ) { die( "This is not a valid entry point.\n" ); } error_reporting( E_ALL ); diff --git a/maintenance/mwdocgen.php b/maintenance/mwdocgen.php index 6e01291eb7..429e3b3ef8 100644 --- a/maintenance/mwdocgen.php +++ b/maintenance/mwdocgen.php @@ -43,7 +43,7 @@ # Variables / Configuration # -if ( php_sapi_name() != 'cli' ) { +if ( PHP_SAPI != 'cli' ) { echo 'Run "' . __FILE__ . '" from the command line.'; die( -1 ); } diff --git a/maintenance/proxy_check.php b/maintenance/proxy_check.php index 10892c42a4..2ccf703eb1 100644 --- a/maintenance/proxy_check.php +++ b/maintenance/proxy_check.php @@ -21,7 +21,7 @@ * @ingroup Maintenance */ -if( php_sapi_name() != 'cli' ) { +if( PHP_SAPI != 'cli' ) { die( 1 ); }