Merge "selenium: Replace regex matching with includes()"
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index a5f4def..b6a1470 100644 (file)
@@ -148,6 +148,7 @@ function wfArrayDiff2_cmp( $a, $b ) {
  * @return array
  */
 function wfArrayFilter( array $arr, callable $callback ) {
+       wfDeprecated( __FUNCTION__, '1.32' );
        return array_filter( $arr, $callback, ARRAY_FILTER_USE_BOTH );
 }
 
@@ -160,6 +161,7 @@ function wfArrayFilter( array $arr, callable $callback ) {
  * @return array
  */
 function wfArrayFilterByKey( array $arr, callable $callback ) {
+       wfDeprecated( __FUNCTION__, '1.32' );
        return array_filter( $arr, $callback, ARRAY_FILTER_USE_KEY );
 }
 
@@ -223,7 +225,7 @@ function wfMergeErrorArrays( ...$args ) {
  *
  * @param array $array The array.
  * @param array $insert The array to insert.
- * @param mixed $after The key to insert after
+ * @param mixed $after The key to insert after. Callers need to make sure the key is set.
  * @return array
  */
 function wfArrayInsertAfter( array $array, array $insert, $after ) {
@@ -332,6 +334,7 @@ function wfUrlencode( $s ) {
        static $needle;
 
        if ( is_null( $s ) ) {
+               // Reset $needle for testing.
                $needle = null;
                return '';
        }
@@ -1063,15 +1066,14 @@ function wfLogDBError( $text, array $context = [] ) {
 /**
  * Throws a warning that $function is deprecated
  *
- * @param string $function
+ * @param string $function Function that is deprecated.
  * @param string|bool $version Version of MediaWiki that the function
  *    was deprecated in (Added in 1.19).
- * @param string|bool $component Added in 1.19.
+ * @param string|bool $component Component to which the function belongs.
+ *    If false, it is assumed the function is in MediaWiki core (Added in 1.19).
  * @param int $callerOffset How far up the call stack is the original
  *    caller. 2 = function that called the function that called
- *    wfDeprecated (Added in 1.20)
- *
- * @return null
+ *    wfDeprecated (Added in 1.20).
  */
 function wfDeprecated( $function, $version = false, $component = false, $callerOffset = 2 ) {
        MWDebug::deprecated( $function, $version, $component, $callerOffset + 1 );
@@ -1748,13 +1750,11 @@ function wfResetOutputBuffers( $resetGzipEncoding = true ) {
                        // to avoid getting in some kind of infinite loop.
                        break;
                }
-               if ( $resetGzipEncoding ) {
-                       if ( $status['name'] == 'ob_gzhandler' ) {
-                               // Reset the 'Content-Encoding' field set by this handler
-                               // so we can start fresh.
-                               header_remove( 'Content-Encoding' );
-                               break;
-                       }
+               if ( $resetGzipEncoding && $status['name'] == 'ob_gzhandler' ) {
+                       // Reset the 'Content-Encoding' field set by this handler
+                       // so we can start fresh.
+                       header_remove( 'Content-Encoding' );
+                       break;
                }
        }
 }
@@ -2050,7 +2050,7 @@ function wfMkdirParents( $dir, $mode = null, $caller = null ) {
  */
 function wfRecursiveRemoveDir( $dir ) {
        wfDebug( __FUNCTION__ . "( $dir )\n" );
-       // taken from https://secure.php.net/manual/en/function.rmdir.php#98622
+       // taken from https://www.php.net/manual/en/function.rmdir.php#98622
        if ( is_dir( $dir ) ) {
                $objects = scandir( $dir );
                foreach ( $objects as $object ) {
@@ -2136,7 +2136,7 @@ function wfStringToBool( $val ) {
  * @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()
+ * @deprecated since 1.30 use MediaWiki\Shell\Shell::escape()
  */
 function wfEscapeShellArg( ...$args ) {
        return Shell::escape( ...$args );
@@ -2608,22 +2608,6 @@ function wfWikiID() {
        }
 }
 
-/**
- * Split a wiki ID into DB name and table prefix
- *
- * @param string $wiki
- *
- * @return array
- * @deprecated 1.32
- */
-function wfSplitWikiID( $wiki ) {
-       $bits = explode( '-', $wiki, 2 );
-       if ( count( $bits ) < 2 ) {
-               $bits[] = '';
-       }
-       return $bits;
-}
-
 /**
  * Get a Database object.
  *
@@ -2656,8 +2640,8 @@ function wfGetDB( $db, $groups = [], $wiki = false ) {
 /**
  * Get a load balancer object.
  *
- * @deprecated since 1.27, use MediaWikiServices::getDBLoadBalancer()
- *              or MediaWikiServices::getDBLoadBalancerFactory() instead.
+ * @deprecated since 1.27, use MediaWikiServices::getInstance()->getDBLoadBalancer()
+ *              or MediaWikiServices::getInstance()->getDBLoadBalancerFactory() instead.
  *
  * @param string|bool $wiki Wiki ID, or false for the current wiki
  * @return \Wikimedia\Rdbms\LoadBalancer
@@ -2674,7 +2658,7 @@ function wfGetLB( $wiki = false ) {
 /**
  * Get the load balancer factory object
  *
- * @deprecated since 1.27, use MediaWikiServices::getDBLoadBalancerFactory() instead.
+ * @deprecated since 1.27, use MediaWikiServices::getInstance()->getDBLoadBalancerFactory() instead.
  *
  * @return \Wikimedia\Rdbms\LBFactory
  */
@@ -3122,7 +3106,7 @@ function wfIsBadImage( $name, $contextTitle = false, $blacklist = null ) {
 function wfCanIPUseHTTPS( $ip ) {
        $canDo = true;
        Hooks::run( 'CanIPUseHTTPS', [ $ip, &$canDo ] );
-       return !!$canDo;
+       return (bool)$canDo;
 }
 
 /**