Merge "Omit 'external' changes from ChangesFeed"
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index 23a8bbb..7a9b27b 100644 (file)
@@ -170,13 +170,13 @@ if ( !function_exists( 'hash_equals' ) ) {
  * 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 );
 }
@@ -194,10 +194,10 @@ function wfLoadExtension( $name, $path = null ) {
  * @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" );
        }
 }
 
@@ -205,13 +205,13 @@ function wfLoadExtensions( array $exts ) {
  * 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 );
 }
@@ -223,10 +223,10 @@ function wfLoadSkin( $name, $path = null ) {
  * @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" );
        }
 }
 
@@ -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'] ) ) {
@@ -2129,15 +2129,14 @@ function wfVarDump( $var ) {
  */
 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>' .
@@ -2323,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
@@ -2537,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
@@ -3034,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" );
@@ -3113,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.
@@ -3353,7 +3331,7 @@ function wfBaseConvert( $input, $sourceBase, $destBase, $pad = 1,
                // 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 ) {
@@ -3492,9 +3470,9 @@ function wfSetupSession( $sessionId = false ) {
        } else {
                wfFixSessionID();
        }
-       wfSuppressWarnings();
+       MediaWiki\suppressWarnings();
        session_start();
-       wfRestoreWarnings();
+       MediaWiki\restoreWarnings();
 }
 
 /**
@@ -3847,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;
                }
        }
@@ -4000,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.