* This queues an extension to be loaded through
* the ExtensionRegistry system.
*
- * @param string $name Name of the extension to load
+ * @param string $ext Name of the extension to load
* @param string|null $path Absolute path of where to find the extension.json file
*/
-function wfLoadExtension( $name, $path = null ) {
+function wfLoadExtension( $ext, $path = null ) {
if ( !$path ) {
- global $IP;
- $path = "$IP/extensions/$name/extension.json";
+ global $wgExtensionDirectory;
+ $path = "$wgExtensionDirectory/$ext/extension.json";
}
ExtensionRegistry::getInstance()->queue( $path );
}
* @param string[] $exts Array of extension names to load
*/
function wfLoadExtensions( array $exts ) {
- global $IP;
+ global $wgExtensionDirectory;
$registry = ExtensionRegistry::getInstance();
foreach ( $exts as $ext ) {
- $registry->queue( "$IP/extensions/$ext/extension.json" );
+ $registry->queue( "$wgExtensionDirectory/$ext/extension.json" );
}
}
* Load a skin
*
* @see wfLoadExtension
- * @param string $name Name of the extension to load
+ * @param string $skin Name of the extension to load
* @param string|null $path Absolute path of where to find the skin.json file
*/
-function wfLoadSkin( $name, $path = null ) {
+function wfLoadSkin( $skin, $path = null ) {
if ( !$path ) {
- global $IP;
- $path = "$IP/skins/$name/skin.json";
+ global $wgStyleDirectory;
+ $path = "$wgStyleDirectory/$skin/skin.json";
}
ExtensionRegistry::getInstance()->queue( $path );
}
* @param string[] $skins Array of extension names to load
*/
function wfLoadSkins( array $skins ) {
- global $IP;
+ global $wgStyleDirectory;
$registry = ExtensionRegistry::getInstance();
foreach ( $skins as $skin ) {
- $registry->queue( "$IP/skins/$skin/skin.json" );
+ $registry->queue( "$wgStyleDirectory/$skin/skin.json" );
}
}
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'] ) ) {
}
// Callers use this method to be aware that data presented to a user
// may be very stale and thus allowing submissions can be problematic.
- if ( $wgReadOnly === false && wfGetLB()->getLaggedSlaveMode() ) {
+ try {
+ if ( $wgReadOnly === false && wfGetLB()->getLaggedSlaveMode() ) {
+ $wgReadOnly = 'The database has been automatically locked ' .
+ 'while the slave database servers catch up to the master';
+ }
+ } catch ( DBConnectionError $e ) {
$wgReadOnly = 'The database has been automatically locked ' .
- 'while the slave database servers catch up to the master';
+ 'until the slave database servers become available';
}
}
}
if ( in_array( 'escape', $options, true ) ) {
- $string = htmlspecialchars ( $string );
+ $string = htmlspecialchars( $string );
} elseif ( in_array( 'escapenoentities', $options, true ) ) {
$string = Sanitizer::escapeHtmlAllowEntities( $string );
}
*/
function wfHttpError( $code, $label, $desc ) {
global $wgOut;
- header( "HTTP/1.0 $code $label" );
- header( "Status: $code $label" );
+ HttpStatus::header( $code );
if ( $wgOut ) {
$wgOut->disable();
$wgOut->sendCacheControl();
}
header( 'Content-type: text/html; charset=utf-8' );
- print "<!doctype html>" .
+ print '<!DOCTYPE html>' .
'<html><head><title>' .
htmlspecialchars( $label ) .
'</title></head><body><h1>' .
/**
* 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
function wfIsWindows() {
static $isWindows = null;
if ( $isWindows === null ) {
- $isWindows = substr( php_uname(), 0, 7 ) == 'Windows';
+ $isWindows = strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN';
}
return $isWindows;
}
}
// 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
$useLogPipe = false;
if ( is_executable( '/bin/bash' ) ) {
- $time = intval ( isset( $limits['time'] ) ? $limits['time'] : $wgMaxShellTime );
+ $time = intval( isset( $limits['time'] ) ? $limits['time'] : $wgMaxShellTime );
if ( isset( $limits['walltime'] ) ) {
$wallTime = intval( $limits['walltime'] );
} elseif ( isset( $limits['time'] ) ) {
} else {
$wallTime = intval( $wgMaxShellWallClockTime );
}
- $mem = intval ( isset( $limits['memory'] ) ? $limits['memory'] : $wgMaxShellMemory );
- $filesize = intval ( isset( $limits['filesize'] ) ? $limits['filesize'] : $wgMaxShellFileSize );
+ $mem = intval( isset( $limits['memory'] ) ? $limits['memory'] : $wgMaxShellMemory );
+ $filesize = intval( isset( $limits['filesize'] ) ? $limits['filesize'] : $wgMaxShellFileSize );
if ( $time > 0 || $mem > 0 || $filesize > 0 || $wallTime > 0 ) {
$cmd = '/bin/bash ' . escapeshellarg( "$IP/includes/limit.sh" ) . ' ' .
# 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" );
}
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.
// Removing leading zeros works around broken base detection code in
// some PHP versions (see <https://bugs.php.net/bug.php?id=50175> and
// <https://bugs.php.net/bug.php?id=55398>).
- $result = gmp_strval( gmp_init( ltrim( $input, '0' ), $sourceBase ), $destBase );
+ $result = gmp_strval( gmp_init( ltrim( $input, '0' ) ?: '0', $sourceBase ), $destBase );
} elseif ( extension_loaded( 'bcmath' ) && ( $engine == 'auto' || $engine == 'bcmath' ) ) {
$decimal = '0';
foreach ( str_split( strtolower( $input ) ) as $char ) {
} else {
wfFixSessionID();
}
- wfSuppressWarnings();
+ MediaWiki\suppressWarnings();
session_start();
- wfRestoreWarnings();
+ MediaWiki\restoreWarnings();
}
/**
}
// Figure out which clusters need to be checked
+ /** @var LoadBalancer[] $lbs */
$lbs = array();
if ( $cluster === '*' ) {
wfGetLBFactory()->forEachLB( function ( LoadBalancer $lb ) use ( &$lbs ) {
$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;
}
}
}
}
- wfSuppressWarnings();
+ MediaWiki\suppressWarnings();
$result = unpack( $format, $data );
- wfRestoreWarnings();
+ MediaWiki\restoreWarnings();
if ( $result === false ) {
// If it cannot extract the packed data.