Merge "Add link to protect log to action=info"
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index d215e9f..868fda3 100644 (file)
@@ -30,7 +30,6 @@ use MediaWiki\Session\SessionManager;
 use MediaWiki\MediaWikiServices;
 use MediaWiki\Shell\Shell;
 use Wikimedia\ScopedCallback;
-use Wikimedia\Rdbms\DBReplicationWaitError;
 use Wikimedia\WrappedString;
 
 /**
@@ -198,11 +197,10 @@ function wfAppendToArrayIfNotDefault( $key, $value, $default, &$changed ) {
  *       [ 'y' ]
  *     ]
  *
- * @param array $array1,...
+ * @param array ...$args
  * @return array
  */
-function wfMergeErrorArrays( /*...*/ ) {
-       $args = func_get_args();
+function wfMergeErrorArrays( ...$args ) {
        $out = [];
        foreach ( $args as $errors ) {
                foreach ( $errors as $params ) {
@@ -1148,26 +1146,6 @@ function wfLogWarning( $msg, $callerOffset = 1, $level = E_USER_WARNING ) {
        MWDebug::warning( $msg, $callerOffset + 1, $level, 'production' );
 }
 
-/**
- * Log to a file without getting "file size exceeded" signals.
- *
- * Can also log to TCP or UDP with the syntax udp://host:port/prefix. This will
- * send lines to the specified port, prefixed by the specified prefix and a space.
- * @since 1.25 support for additional context data
- *
- * @param string $text
- * @param string $file Filename
- * @param array $context Additional logging context data
- * @throws MWException
- * @deprecated since 1.25 Use \MediaWiki\Logger\LegacyLogger::emit or UDPTransport
- */
-function wfErrorLog( $text, $file, array $context = [] ) {
-       wfDeprecated( __METHOD__, '1.25' );
-       $logger = LoggerFactory::getInstance( 'wfErrorLog' );
-       $context['destination'] = $file;
-       $logger->info( trim( $text ), $context );
-}
-
 /**
  * @todo document
  * @todo Move logic to MediaWiki.php
@@ -2197,13 +2175,13 @@ function wfStringToBool( $val ) {
  * (https://bugs.php.net/bug.php?id=26285) and the locale problems on Linux in
  * PHP 5.2.6+ (bug backported to earlier distro releases of PHP).
  *
- * @param string $args,... strings to escape and glue together,
+ * @param string|string[] ...$args strings to escape and glue together,
  *  or a single array of strings parameter
  * @return string
  * @deprecated since 1.30 use MediaWiki\Shell::escape()
  */
-function wfEscapeShellArg( /*...*/ ) {
-       return Shell::escape( ...func_get_args() );
+function wfEscapeShellArg( ...$args ) {
+       return Shell::escape( ...$args );
 }
 
 /**
@@ -2504,38 +2482,6 @@ function wfUsePHP( $req_ver ) {
        }
 }
 
-/**
- * This function works like "use VERSION" in Perl except it checks the version
- * of MediaWiki, the program will die with a backtrace if the current version
- * of MediaWiki is less than the version provided.
- *
- * This is useful for extensions which due to their nature are not kept in sync
- * with releases
- *
- * Note: Due to the behavior of PHP's version_compare() which is used in this
- * function, if you want to allow the 'wmf' development versions add a 'c' (or
- * any single letter other than 'a', 'b' or 'p') as a post-fix to your
- * targeted version number. For example if you wanted to allow any variation
- * of 1.22 use `wfUseMW( '1.22c' )`. Using an 'a' or 'b' instead of 'c' will
- * not result in the same comparison due to the internal logic of
- * version_compare().
- *
- * @see perldoc -f use
- *
- * @deprecated since 1.26, use the "requires" property of extension.json
- * @param string|int|float $req_ver The version to check, can be a string, an integer, or a float
- * @throws MWException
- */
-function wfUseMW( $req_ver ) {
-       global $wgVersion;
-
-       wfDeprecated( __FUNCTION__, '1.26' );
-
-       if ( version_compare( $wgVersion, (string)$req_ver, '<' ) ) {
-               throw new MWException( "MediaWiki $req_ver required--this is only $wgVersion" );
-       }
-}
-
 /**
  * Return the final portion of a pathname.
  * Reimplemented because PHP5's "basename()" is buggy with multibyte text.
@@ -2678,11 +2624,11 @@ function wfGetPrecompiledData( $name ) {
  * Make a cache key for the local wiki.
  *
  * @deprecated since 1.30 Call makeKey on a BagOStuff instance
- * @param string $args,...
+ * @param string ...$args
  * @return string
  */
-function wfMemcKey( /*...*/ ) {
-       return ObjectCache::getLocalClusterInstance()->makeKey( ...func_get_args() );
+function wfMemcKey( ...$args ) {
+       return ObjectCache::getLocalClusterInstance()->makeKey( ...$args );
 }
 
 /**
@@ -2692,11 +2638,10 @@ function wfMemcKey( /*...*/ ) {
  *
  * @param string $db
  * @param string $prefix
- * @param string $args,...
+ * @param string ...$args
  * @return string
  */
-function wfForeignMemcKey( $db, $prefix /*...*/ ) {
-       $args = array_slice( func_get_args(), 2 );
+function wfForeignMemcKey( $db, $prefix, ...$args ) {
        $keyspace = $prefix ? "$db-$prefix" : $db;
        return ObjectCache::getLocalClusterInstance()->makeKeyInternal( $keyspace, $args );
 }
@@ -2710,11 +2655,11 @@ function wfForeignMemcKey( $db, $prefix /*...*/ ) {
  *
  * @deprecated since 1.30 Call makeGlobalKey on a BagOStuff instance
  * @since 1.26
- * @param string $args,...
+ * @param string ...$args
  * @return string
  */
-function wfGlobalCacheKey( /*...*/ ) {
-       return ObjectCache::getLocalClusterInstance()->makeGlobalKey( ...func_get_args() );
+function wfGlobalCacheKey( ...$args ) {
+       return ObjectCache::getLocalClusterInstance()->makeGlobalKey( ...$args );
 }
 
 /**
@@ -2922,17 +2867,13 @@ function wfGetNull() {
  * @param float|null $ifWritesSince Only wait if writes were done since this UNIX timestamp
  * @param string|bool $wiki Wiki identifier accepted by wfGetLB
  * @param string|bool $cluster Cluster name accepted by LBFactory. Default: false.
- * @param int|null $timeout Max wait time. Default: 1 day (cli), ~10 seconds (web)
+ * @param int|null $timeout Max wait time. Default: 60 seconds (cli), 1 second (web)
  * @return bool Success (able to connect and no timeouts reached)
  * @deprecated since 1.27 Use LBFactory::waitForReplication
  */
 function wfWaitForSlaves(
        $ifWritesSince = null, $wiki = false, $cluster = false, $timeout = null
 ) {
-       if ( $timeout === null ) {
-               $timeout = wfIsCLI() ? 60 : 10;
-       }
-
        if ( $cluster === '*' ) {
                $cluster = false;
                $wiki = false;
@@ -2940,20 +2881,18 @@ function wfWaitForSlaves(
                $wiki = wfWikiID();
        }
 
-       try {
-               $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
-               $lbFactory->waitForReplication( [
-                       'wiki' => $wiki,
-                       'cluster' => $cluster,
-                       'timeout' => $timeout,
-                       // B/C: first argument used to be "max seconds of lag"; ignore such values
-                       'ifWritesSince' => ( $ifWritesSince > 1e9 ) ? $ifWritesSince : null
-               ] );
-       } catch ( DBReplicationWaitError $e ) {
-               return false;
+       $opts = [
+               'wiki' => $wiki,
+               'cluster' => $cluster,
+               // B/C: first argument used to be "max seconds of lag"; ignore such values
+               'ifWritesSince' => ( $ifWritesSince > 1e9 ) ? $ifWritesSince : null
+       ];
+       if ( $timeout !== null ) {
+               $opts['timeout'] = $timeout;
        }
 
-       return true;
+       $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
+       return $lbFactory->waitForReplication( $opts );
 }
 
 /**