Switch some HTMLForms in special pages to OOUI
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index 8b3b959..c618426 100644 (file)
@@ -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'] ) ) {
@@ -1756,7 +1756,7 @@ function wfMsgExt( $key, $options ) {
        }
 
        if ( in_array( 'escape', $options, true ) ) {
-               $string = htmlspecialchars ( $string );
+               $string = htmlspecialchars( $string );
        } elseif ( in_array( 'escapenoentities', $options, true ) ) {
                $string = Sanitizer::escapeHtmlAllowEntities( $string );
        }
@@ -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
@@ -2780,7 +2758,7 @@ function wfShellExec( $cmd, &$retval = null, $environ = array(),
 
        $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'] ) ) {
@@ -2788,8 +2766,8 @@ function wfShellExec( $cmd, &$retval = null, $environ = array(),
                } 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" ) . ' ' .
@@ -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.
@@ -3492,9 +3470,9 @@ function wfSetupSession( $sessionId = false ) {
        } else {
                wfFixSessionID();
        }
-       wfSuppressWarnings();
+       MediaWiki\suppressWarnings();
        session_start();
-       wfRestoreWarnings();
+       MediaWiki\restoreWarnings();
 }
 
 /**
@@ -3517,7 +3495,7 @@ function wfGetPrecompiledData( $name ) {
 }
 
 /**
- * Get a cache key
+ * Make a cache key for the local wiki.
  *
  * @param string $args,...
  * @return string
@@ -3532,7 +3510,9 @@ function wfMemcKey( /*...*/ ) {
 }
 
 /**
- * Get a cache key for a foreign DB
+ * Make a cache key for a foreign DB.
+ *
+ * Must match what wfMemcKey() would produce in context of the foreign wiki.
  *
  * @param string $db
  * @param string $prefix
@@ -3542,6 +3522,7 @@ function wfMemcKey( /*...*/ ) {
 function wfForeignMemcKey( $db, $prefix /*...*/ ) {
        $args = array_slice( func_get_args(), 2 );
        if ( $prefix ) {
+               // Match wfWikiID() logic
                $key = "$db-$prefix:" . implode( ':', $args );
        } else {
                $key = $db . ':' . implode( ':', $args );
@@ -3549,6 +3530,24 @@ function wfForeignMemcKey( $db, $prefix /*...*/ ) {
        return str_replace( ' ', '_', $key );
 }
 
+/**
+ * Make a cache key with database-agnostic prefix.
+ *
+ * Doesn't have a wiki-specific namespace. Uses a generic 'global' prefix
+ * instead. Must have a prefix as otherwise keys that use a database name
+ * in the first segment will clash with wfMemcKey/wfForeignMemcKey.
+ *
+ * @since 1.26
+ * @param string $args,...
+ * @return string
+ */
+function wfGlobalCacheKey( /*...*/ ) {
+       $args = func_get_args();
+       $key = 'global:' . implode( ':', $args );
+       $key = str_replace( ' ', '_', $key );
+       return $key;
+}
+
 /**
  * Get an ASCII string identifying this wiki
  * This is used as a prefix in memcached keys
@@ -3847,15 +3846,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 +3999,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.