if ( is_string( $a ) && is_string( $b ) ) {
return strcmp( $a, $b );
} elseif ( count( $a ) !== count( $b ) ) {
- return count( $a ) < count( $b ) ? -1 : 1;
+ return count( $a ) <=> count( $b );
} else {
reset( $a );
reset( $b );
* This function replaces all old wfMsg* functions.
*
* @param string|string[]|MessageSpecifier $key Message key, or array of keys, or a MessageSpecifier
- * @param mixed $params,... Normal message parameters
+ * @param string[]|string[][] ...$params Normal message parameters
* @return Message
*
* @since 1.17
*
* @see Message::__construct
*/
-function wfMessage( $key /*...*/ ) {
+function wfMessage( $key, ...$params ) {
$message = new Message( $key );
// We call Message::params() to reduce code duplication
- $params = func_get_args();
- array_shift( $params );
if ( $params ) {
- call_user_func_array( [ $message, 'params' ], $params );
+ $message->params( ...$params );
}
return $message;
* for the first message which is non-empty. If all messages are empty then an
* instance of the first message key is returned.
*
- * @param string|string[] $keys,... Message keys
+ * @param string[] ...$keys Message keys
* @return Message
*
* @since 1.18
*
* @see Message::newFallbackSequence
*/
-function wfMessageFallback( /*...*/ ) {
- $args = func_get_args();
- return call_user_func_array( 'Message::newFallbackSequence', $args );
+function wfMessageFallback( ...$keys ) {
+ return Message::newFallbackSequence( ...$keys );
}
/**
* hostname of the server handling the request.
*
* @param string $nonce Value from OutputPage::getCSPNonce
- * @return string
+ * @return string|WrappedString HTML
*/
function wfReportTime( $nonce = null ) {
global $wgShowHostnames;
$frames = array_map( function ( $frame ) use ( $frameFormat ) {
$file = !empty( $frame['file'] ) ? basename( $frame['file'] ) : '-';
- $line = isset( $frame['line'] ) ? $frame['line'] : '-';
+ $line = $frame['line'] ?? '-';
$call = $frame['function'];
if ( !empty( $frame['class'] ) ) {
$call = $frame['class'] . $frame['type'] . $call;
* @deprecated since 1.30 use MediaWiki\Shell::escape()
*/
function wfEscapeShellArg( /*...*/ ) {
- $args = func_get_args();
-
- return call_user_func_array( Shell::class . '::escape', $args );
+ return Shell::escape( ...func_get_args() );
}
/**
}
$includeStderr = isset( $options['duplicateStderr'] ) && $options['duplicateStderr'];
- $profileMethod = isset( $options['profileMethod'] ) ? $options['profileMethod'] : wfGetCaller();
+ $profileMethod = $options['profileMethod'] ?? wfGetCaller();
try {
$result = Shell::command( [] )
return false;
}
+/**
+ * @since 1.32
+ * @param string[] $data Array with string keys/values to export
+ * @param string $header
+ * @return string PHP code
+ */
+function wfMakeStaticArrayFile( array $data, $header = 'Automatically generated' ) {
+ $format = "\t%s => %s,\n";
+ $code = "<?php\n"
+ . "// " . implode( "\n// ", explode( "\n", $header ) ) . "\n"
+ . "return [\n";
+ foreach ( $data as $key => $value ) {
+ $code .= sprintf(
+ $format,
+ var_export( $key, true ),
+ var_export( $value, true )
+ );
+ }
+ $code .= "];\n";
+ return $code;
+}
+
/**
* Make a cache key for the local wiki.
*
* @return string
*/
function wfMemcKey( /*...*/ ) {
- return call_user_func_array(
- [ ObjectCache::getLocalClusterInstance(), 'makeKey' ],
- func_get_args()
- );
+ return ObjectCache::getLocalClusterInstance()->makeKey( ...func_get_args() );
}
/**
function wfForeignMemcKey( $db, $prefix /*...*/ ) {
$args = array_slice( func_get_args(), 2 );
$keyspace = $prefix ? "$db-$prefix" : $db;
- return call_user_func_array(
- [ ObjectCache::getLocalClusterInstance(), 'makeKeyInternal' ],
- [ $keyspace, $args ]
- );
+ return ObjectCache::getLocalClusterInstance()->makeKeyInternal( $keyspace, $args );
}
/**
* @return string
*/
function wfGlobalCacheKey( /*...*/ ) {
- return call_user_func_array(
- [ ObjectCache::getLocalClusterInstance(), 'makeGlobalKey' ],
- func_get_args()
- );
+ return ObjectCache::getLocalClusterInstance()->makeGlobalKey( ...func_get_args() );
}
/**
return ObjectCache::getInstance( $wgMessageCacheType );
}
-/**
- * Get the cache object used by the parser cache
- *
- * @deprecated since 1.30, use MediaWikiServices::getParserCache()->getCacheStorage()
- * @return BagOStuff
- */
-function wfGetParserCacheStorage() {
- global $wgParserCacheType;
- return ObjectCache::getInstance( $wgParserCacheType );
-}
-
/**
* Call hook functions defined in $wgHooks
*