* subsequent arguments to $msg2 will be passed as parameters only for replacing in $msg2
* @param string $msg1
* @param string $msg2
+ * @param mixed ...$args To pass as params to wfMessage() with $msg2. Either variadic, or a single
+ * array argument.
*/
-function wfForbidden( $msg1, $msg2 ) {
+function wfForbidden( $msg1, $msg2, ...$args ) {
global $wgImgAuthDetails;
- $args = func_get_args();
- array_shift( $args );
- array_shift( $args );
$args = ( isset( $args[0] ) && is_array( $args[0] ) ) ? $args[0] : $args;
$msgHdr = wfMessage( $msg1 )->escaped();
* which is not fun
*
* @param array $array1
+ * @param array ...$arrays
*
* @return array
*/
- static function arrayMerge( $array1/* ... */ ) {
+ static function arrayMerge( array $array1, ...$arrays ) {
$out = $array1;
- $argsCount = func_num_args();
- for ( $i = 1; $i < $argsCount; $i++ ) {
- foreach ( func_get_arg( $i ) as $key => $value ) {
+ foreach ( $arrays as $array ) {
+ foreach ( $array as $key => $value ) {
if ( isset( $out[$key] ) && is_array( $out[$key] ) && is_array( $value ) ) {
$out[$key] = self::arrayMerge( $out[$key], $value );
} elseif ( !isset( $out[$key] ) || !$out[$key] && !is_numeric( $key ) ) {
/**
* Fetch the standard parameters this helper recognizes
* @param string $action AuthManager action
- * @param string $param,... Parameters to use
+ * @param string ...$wantedParams Parameters to use
* @return array
*/
- public static function getStandardParams( $action, $param /* ... */ ) {
+ public static function getStandardParams( $action, ...$wantedParams ) {
$params = [
'requests' => [
ApiBase::PARAM_TYPE => 'string',
];
$ret = [];
- $wantedParams = func_get_args();
- array_shift( $wantedParams );
foreach ( $wantedParams as $name ) {
if ( isset( $params[$name] ) ) {
$ret[$name] = $params[$name];
* @param string $key Message name
* @param string $fallback Default message if the message cache can't be
* called by the exception
- * The function also has other parameters that are arguments for the message
+ * @param mixed ...$params To pass to wfMessage()
* @return string Message with arguments replaced
*/
- public function msg( $key, $fallback /*[, params...] */ ) {
+ public function msg( $key, $fallback, ...$params ) {
global $wgSitename;
- $args = array_slice( func_get_args(), 2 );
// FIXME: Keep logic in sync with MWExceptionRenderer::msg.
$res = false;
if ( $this->useMessageCache() ) {
try {
- $res = wfMessage( $key, $args )->text();
+ $res = wfMessage( $key, $params )->text();
} catch ( Exception $e ) {
}
}
if ( $res === false ) {
- $res = wfMsgReplaceArgs( $fallback, $args );
+ $res = wfMsgReplaceArgs( $fallback, $params );
// If an exception happens inside message rendering,
// {{SITENAME}} sometimes won't be replaced.
$res = strtr( $res, [
* @param string $key Message name
* @param string $fallback Default message if the message cache can't be
* called by the exception
- * The function also has other parameters that are arguments for the message
+ * @param mixed ...$params To pass to wfMessage()
* @return string Message with arguments replaced
*/
- private static function msg( $key, $fallback /*[, params...] */ ) {
+ private static function msg( $key, $fallback, ...$params ) {
global $wgSitename;
- $args = array_slice( func_get_args(), 2 );
// FIXME: Keep logic in sync with MWException::msg.
try {
- $res = wfMessage( $key, $args )->text();
+ $res = wfMessage( $key, $params )->text();
} catch ( Exception $e ) {
- $res = wfMsgReplaceArgs( $fallback, $args );
+ $res = wfMsgReplaceArgs( $fallback, $params );
// If an exception happens inside message rendering,
// {{SITENAME}} sometimes won't be replaced.
$res = strtr( $res, [
*
* @return Message
*/
- public function msg() {
- $args = func_get_args();
-
+ public function msg( ...$args ) {
if ( $this->mParent ) {
return $this->mParent->msg( ...$args );
}
wfDebug( "IMPORT: $data\n" );
}
- public function notice( $msg /*, $param, ...*/ ) {
- $params = func_get_args();
- array_shift( $params );
-
+ public function notice( $msg, ...$params ) {
if ( is_callable( $this->mNoticeCallback ) ) {
call_user_func( $this->mNoticeCallback, $msg, $params );
} else { # No ImportReporter -> CLI
}
}
- $args = func_get_args();
- return Hooks::run( 'AfterImportPage', $args );
+ return Hooks::run( 'AfterImportPage', func_get_args() );
}
/**
private function pageOutCallback( $title, $foreignTitle, $revCount,
$sucCount, $pageInfo ) {
if ( isset( $this->mPageOutCallback ) ) {
- $args = func_get_args();
- call_user_func_array( $this->mPageOutCallback, $args );
+ call_user_func_array( $this->mPageOutCallback, func_get_args() );
}
}
$this->showMessage( 'config-install-step-done' );
}
- public function showMessage( $msg /*, ... */ ) {
- echo $this->getMessageText( func_get_args() ) . "\n";
+ public function showMessage( $msg, ...$params ) {
+ echo $this->getMessageText( $msg, $params ) . "\n";
flush();
}
- public function showError( $msg /*, ... */ ) {
- echo "***{$this->getMessageText( func_get_args() )}***\n";
+ public function showError( $msg, ...$params ) {
+ echo "***{$this->getMessageText( $msg, $params )}***\n";
flush();
}
/**
+ * @param string $msg
* @param array $params
*
* @return string
*/
- protected function getMessageText( $params ) {
- $msg = array_shift( $params );
-
+ protected function getMessageText( $msg, $params ) {
$text = wfMessage( $msg, $params )->parse();
$text = preg_replace( '/<a href="(.*?)".*?>(.*?)<\/a>/', '$2 <$1>', $text );
* The messages will be in wikitext format, which will be converted to an
* output format such as HTML or text before being sent to the user.
* @param string $msg
+ * @param mixed ...$params
*/
- abstract public function showMessage( $msg /*, ... */ );
+ abstract public function showMessage( $msg, ...$params );
/**
* Same as showMessage(), but for displaying errors
* @param string $msg
+ * @param mixed ...$params
*/
- abstract public function showError( $msg /*, ... */ );
+ abstract public function showError( $msg, ...$params );
/**
* Show a message to the installing user by using a Status object
* Show an error message in a box. Parameters are like wfMessage(), or
* alternatively, pass a Message object in.
* @param string|Message $msg
+ * @param mixed ...$params
*/
- public function showError( $msg /*...*/ ) {
+ public function showError( $msg, ...$params ) {
if ( !( $msg instanceof Message ) ) {
- $args = func_get_args();
- array_shift( $args );
- $args = array_map( 'htmlspecialchars', $args );
- $msg = wfMessage( $msg, $args );
+ $msg = wfMessage(
+ $msg,
+ array_map( 'htmlspecialchars', $params )
+ );
}
$text = $msg->useDatabase( false )->plain();
$this->output->addHTML( $this->getErrorBox( $text ) );
* @param string $msg
* @return string
*/
- public function getHelpBox( $msg /*, ... */ ) {
- $args = func_get_args();
- array_shift( $args );
+ public function getHelpBox( $msg, ...$args ) {
$args = array_map( 'htmlspecialchars', $args );
$text = wfMessage( $msg, $args )->useDatabase( false )->plain();
$html = $this->parse( $text, true );
/**
* Output a help box.
* @param string $msg Key for wfMessage()
+ * @param mixed ...$params
*/
- public function showHelpBox( $msg /*, ... */ ) {
- $args = func_get_args();
- $html = $this->getHelpBox( ...$args );
+ public function showHelpBox( $msg, ...$params ) {
+ $html = $this->getHelpBox( $msg, ...$params );
$this->output->addHTML( $html );
}
* Output looks like a list.
*
* @param string $msg
+ * @param mixed ...$params
*/
- public function showMessage( $msg /*, ... */ ) {
- $args = func_get_args();
- array_shift( $args );
+ public function showMessage( $msg, ...$params ) {
$html = '<div class="config-message">' .
- $this->parse( wfMessage( $msg, $args )->useDatabase( false )->plain() ) .
+ $this->parse( wfMessage( $msg, $params )->useDatabase( false )->plain() ) .
"</div>\n";
$this->output->addHTML( $html );
}
* @since 1.23
*
* @param array $array1 The array to compare from
- * @param array $array2,... More arrays to compare against
+ * @param array ...$arrays More arrays to compare against
* @return array An array containing all the values from array1
* that are not present in any of the other arrays.
*/
- public static function arrayDiffAssocRecursive( $array1 ) {
- $arrays = func_get_args();
- array_shift( $arrays );
+ public static function arrayDiffAssocRecursive( $array1, ...$arrays ) {
$ret = [];
foreach ( $array1 as $key => $value ) {
/**
* @param callable $callback Callback that gets called by __toString
- * @param mixed $param,... Parameters to the callback
+ * @param mixed ...$params Parameters to the callback
*/
- public function __construct( $callback /*...*/ ) {
- $this->params = func_get_args();
- array_shift( $this->params );
+ public function __construct( $callback, ...$params ) {
$this->callback = $callback;
+ $this->params = $params;
}
/**
*
* Like MemoizedCallable::invokeArgs(), but variadic.
*
- * @param mixed $params,... Parameters for memoized function or method.
+ * @param mixed ...$params Parameters for memoized function or method.
* @return mixed The memoized callable's return value.
*/
- public function invoke() {
- return $this->invokeArgs( func_get_args() );
+ public function invoke( ...$params ) {
+ return $this->invokeArgs( $params );
}
/**
* - StatusValue::newGood() if this method is called without parameters
* - StatusValue::newFatal() with all parameters to this method if passed in
*
- * @param string $args,...
+ * @param string ...$args
* @return StatusValue
*/
- final protected function newStatus() {
- $args = func_get_args();
+ final protected function newStatus( ...$args ) {
if ( count( $args ) ) {
$sv = StatusValue::newFatal( ...$args );
} else {
public $funDecls = array();
public $varDecls = array();
- public function __construct($t, $type=0)
+ public function __construct($t, $type=0, ...$nodes)
{
if ($token = $t->currentToken())
{
$this->lineno = $t->lineno;
}
- if (($numargs = func_num_args()) > 2)
+ foreach($nodes as $node)
{
- $args = func_get_args();
- for ($i = 2; $i < $numargs; $i++)
- $this->addNode($args[$i]);
+ $this->addNode($node);
}
}
/** @var Message */
private $msg;
- function __construct( $msg, $width, $height /*, ... */ ) {
- $args = array_slice( func_get_args(), 3 );
+ function __construct( $msg, $width, $height, ...$args ) {
$this->msg = wfMessage( $msg )->params( $args );
$this->width = intval( $width );
$this->height = intval( $height );
function toHtml( $options = [] ) {
global $wgPriorityHints, $wgElementTiming;
- if ( count( func_get_args() ) == 2 ) {
+ if ( func_num_args() == 2 ) {
throw new MWException( __METHOD__ . ' called in the old style' );
}
/**
* @param Parser $parser
- * @param string $part1
+ * @param string $part1 Message key
+ * @param mixed ...$params To pass to wfMessage()
* @return array
*/
- public static function intFunction( $parser, $part1 = '' /*, ... */ ) {
+ public static function intFunction( $parser, $part1 = '', ...$params ) {
if ( strval( $part1 ) !== '' ) {
- $args = array_slice( func_get_args(), 2 );
- $message = wfMessage( $part1, $args )
+ $message = wfMessage( $part1, $params )
->inLanguage( $parser->getOptions()->getUserLangObj() );
return [ $message->plain(), 'noparse' => false ];
} else {
/**
* @param Parser $parser
* @param string $username
+ * @param string ...$forms What to output for each gender
* @return string
*/
- public static function gender( $parser, $username ) {
- $forms = array_slice( func_get_args(), 2 );
-
+ public static function gender( $parser, $username, ...$forms ) {
// Some shortcuts to avoid loading user data unnecessarily
if ( count( $forms ) === 0 ) {
return '';
/**
* @param Parser $parser
* @param string $text
+ * @param string ...$forms What to output for each number (singular, dual, plural, etc.)
* @return string
*/
- public static function plural( $parser, $text = '' ) {
- $forms = array_slice( func_get_args(), 2 );
+ public static function plural( $parser, $text = '', ...$forms ) {
$text = $parser->getFunctionLang()->parseFormattedNumber( $text );
settype( $text, ctype_digit( $text ) ? 'int' : 'float' );
return $parser->getFunctionLang()->convertPlural( $text, $forms );
/**
* @param string $sep
* @param int $flags
- * @param string|PPNode_DOM|DOMDocument $args,...
+ * @param string|PPNode_DOM|DOMDocument ...$args
* @return string
*/
- public function implodeWithFlags( $sep, $flags /*, ... */ ) {
- $args = array_slice( func_get_args(), 2 );
-
+ public function implodeWithFlags( $sep, $flags, ...$args ) {
$first = true;
$s = '';
foreach ( $args as $root ) {
* This previously called implodeWithFlags but has now been inlined to reduce stack depth
*
* @param string $sep
- * @param string|PPNode_DOM|DOMDocument $args,...
+ * @param string|PPNode_DOM|DOMDocument ...$args
* @return string
*/
- public function implode( $sep /*, ... */ ) {
- $args = array_slice( func_get_args(), 1 );
-
+ public function implode( $sep, ...$args ) {
$first = true;
$s = '';
foreach ( $args as $root ) {
* with implode()
*
* @param string $sep
- * @param string|PPNode_DOM|DOMDocument $args,...
+ * @param string|PPNode_DOM|DOMDocument ...$args
* @return array
*/
- public function virtualImplode( $sep /*, ... */ ) {
- $args = array_slice( func_get_args(), 1 );
+ public function virtualImplode( $sep, ...$args ) {
$out = [];
$first = true;
* @param string $start
* @param string $sep
* @param string $end
- * @param string|PPNode_DOM|DOMDocument $args,...
+ * @param string|PPNode_DOM|DOMDocument ...$args
* @return array
*/
- public function virtualBracketedImplode( $start, $sep, $end /*, ... */ ) {
- $args = array_slice( func_get_args(), 3 );
+ public function virtualBracketedImplode( $start, $sep, $end, ...$args ) {
$out = [ $start ];
$first = true;
/**
* @param string $sep
* @param int $flags
- * @param string|PPNode $args,...
+ * @param string|PPNode ...$args
* @return string
*/
- public function implodeWithFlags( $sep, $flags /*, ... */ ) {
- $args = array_slice( func_get_args(), 2 );
-
+ public function implodeWithFlags( $sep, $flags, ...$args ) {
$first = true;
$s = '';
foreach ( $args as $root ) {
* Implode with no flags specified
* This previously called implodeWithFlags but has now been inlined to reduce stack depth
* @param string $sep
- * @param string|PPNode $args,...
+ * @param string|PPNode ...$args
* @return string
*/
- public function implode( $sep /*, ... */ ) {
- $args = array_slice( func_get_args(), 1 );
-
+ public function implode( $sep, ...$args ) {
$first = true;
$s = '';
foreach ( $args as $root ) {
* with implode()
*
* @param string $sep
- * @param string|PPNode $args,...
+ * @param string|PPNode ...$args
* @return PPNode_Hash_Array
*/
- public function virtualImplode( $sep /*, ... */ ) {
- $args = array_slice( func_get_args(), 1 );
+ public function virtualImplode( $sep, ...$args ) {
$out = [];
$first = true;
* @param string $start
* @param string $sep
* @param string $end
- * @param string|PPNode $args,...
+ * @param string|PPNode ...$args
* @return PPNode_Hash_Array
*/
- public function virtualBracketedImplode( $start, $sep, $end /*, ... */ ) {
- $args = array_slice( func_get_args(), 3 );
+ public function virtualBracketedImplode( $start, $sep, $end, ...$args ) {
$out = [ $start ];
$first = true;
* Adds parameters to the command. All parameters are sanitized via Shell::escape().
* Null values are ignored.
*
- * @param string|string[] $args,...
+ * @param string|string[] ...$args
* @return $this
*/
- public function params( /* ... */ ) {
- $args = func_get_args();
+ public function params( ...$args ) {
if ( count( $args ) === 1 && is_array( reset( $args ) ) ) {
// If only one argument has been passed, and that argument is an array,
// treat it as a list of arguments
* Adds unsafe parameters to the command. These parameters are NOT sanitized in any way.
* Null values are ignored.
*
- * @param string|string[] $args,...
+ * @param string|string[] ...$args
* @return $this
*/
- public function unsafeParams( /* ... */ ) {
- $args = func_get_args();
+ public function unsafeParams( ...$args ) {
if ( count( $args ) === 1 && is_array( reset( $args ) ) ) {
// If only one argument has been passed, and that argument is an array,
// treat it as a list of arguments
);
}
- function reportLogItem( /* ... */ ) {
+ function reportLogItem( ...$args ) {
$this->mLogItemCount++;
if ( is_callable( $this->mOriginalLogCallback ) ) {
- call_user_func_array( $this->mOriginalLogCallback, func_get_args() );
+ call_user_func_array( $this->mOriginalLogCallback, $args );
}
}
*/
public function reportPage( $title, $foreignTitle, $revisionCount,
$successCount, $pageInfo ) {
- $args = func_get_args();
- call_user_func_array( $this->mOriginalPageOutCallback, $args );
+ call_user_func_array( $this->mOriginalPageOutCallback, func_get_args() );
if ( $title === null ) {
# Invalid or non-importable title; a notice is already displayed
* Dispatch a command to the next available replica DB.
* This may block until a replica DB finishes its work and becomes available.
*/
- function dispatch( /*...*/ ) {
- $args = func_get_args();
+ function dispatch( ...$args ) {
$pipes = $this->replicaPipes;
$x = [];
$y = [];
->getMock();
$mock->expects( $this->exactly( $insertCalls ) )
->method( 'insert' )
- ->willReturnCallback( function () {
- return call_user_func_array( [ $this->db, 'insert' ], func_get_args() );
+ ->willReturnCallback( function ( ...$args ) {
+ return call_user_func_array( [ $this->db, 'insert' ], $args );
} );
$mock->expects( $this->exactly( $selectCalls ) )
->method( 'select' )
- ->willReturnCallback( function () {
- return call_user_func_array( [ $this->db, 'select' ], func_get_args() );
+ ->willReturnCallback( function ( ...$args ) {
+ return call_user_func_array( [ $this->db, 'select' ], $args );
} );
$mock->expects( $this->exactly( $insertCalls ) )
->method( 'affectedRows' )
- ->willReturnCallback( function () {
- return call_user_func_array( [ $this->db, 'affectedRows' ], func_get_args() );
+ ->willReturnCallback( function ( ...$args ) {
+ return call_user_func_array( [ $this->db, 'affectedRows' ], $args );
} );
$mock->expects( $this->any() )
->method( 'insertId' )
- ->willReturnCallback( function () {
- return call_user_func_array( [ $this->db, 'insertId' ], func_get_args() );
+ ->willReturnCallback( function ( ...$args ) {
+ return call_user_func_array( [ $this->db, 'insertId' ], $args );
} );
return $mock;
}
/**
* Merges all requests parameter + expected values into one
- * @param array $v,... List of arrays, each of which contains exactly two
+ * @param array ...$arrays List of arrays, each of which contains exactly two
* @return array
*/
- protected function merge( /*...*/ ) {
+ protected function merge( ...$arrays ) {
$request = [];
$expected = [];
- foreach ( func_get_args() as $v ) {
- list( $req, $exp ) = $this->validateRequestExpectedPair( $v );
+ foreach ( $arrays as $array ) {
+ list( $req, $exp ) = $this->validateRequestExpectedPair( $array );
$request = array_merge_recursive( $request, $req );
$this->mergeExpected( $expected, $exp );
}
* @dataProvider provideLoadFromSubmission
*/
public function testLoadFromSubmission(
- array $args, array $data, $expectState /* $hiddenPref, $enableEmail */
+ array $args, array $data, $expectState, $hiddenPref = null, $enableEmail = null
) {
- list( $args, $data, $expectState, $hiddenPref, $enableEmail ) = func_get_args();
$this->setMwGlobals( 'wgHiddenPrefs', $hiddenPref );
$this->setMwGlobals( 'wgEnableEmail', $enableEmail );
parent::testLoadFromSubmission( $args, $data, $expectState );
*/
private static $pageName = 'CategoryMembershipChangeTestPage';
- public static function newForCategorizationCallback() {
- self::$lastNotifyArgs = func_get_args();
+ public static function newForCategorizationCallback( ...$args ) {
+ self::$lastNotifyArgs = $args;
self::$notifyCallCounter += 1;
return self::$mockRecentChange;
}
* @covers ArrayUtils::arrayDiffAssocRecursive
* @dataProvider provideArrayDiffAssocRecursive
*/
- function testArrayDiffAssocRecursive( $expected ) {
- $args = func_get_args();
- array_shift( $args );
+ function testArrayDiffAssocRecursive( $expected, ...$args ) {
$this->assertEquals( call_user_func_array(
'ArrayUtils::arrayDiffAssocRecursive', $args
), $expected );
// That call will die if the contructor is not public, unless we use disableOriginalConstructor(),
// in which case we could not test the constructor.
abstract class PoolCounterAbstractMock extends PoolCounter {
- public function __construct() {
- call_user_func_array( 'parent::__construct', func_get_args() );
+ public function __construct( ...$args ) {
+ call_user_func_array( 'parent::__construct', $args );
}
}
} ) );
$mock->expects( $this->any() )
->method( 'isAllowedAny' )
- ->will( $this->returnCallback( function () use ( $notAllowedAction ) {
- $actions = func_get_args();
+ ->will( $this->returnCallback( function ( ...$actions ) use ( $notAllowedAction ) {
return !in_array( $notAllowedAction, $actions );
} ) );
->getMock();
$mock->expects( $this->any() )
->method( 'makeKey' )
- ->will( $this->returnCallback( function () {
- return implode( ':', func_get_args() );
+ ->will( $this->returnCallback( function ( ...$args ) {
+ return implode( ':', $args );
} ) );
return $mock;
}