From: Umherirrender Date: Fri, 8 Jun 2018 20:35:15 +0000 (+0200) Subject: Use varargs for MessageLocalizer::msg and similar X-Git-Tag: 1.34.0-rc.1~29 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=81aa6d7a758a000dcd110a2d4d21e50aca6d3444 Use varargs for MessageLocalizer::msg and similar Bug: T191666 Change-Id: I59f2ae1a96af392026fc106e57d23553003c16b8 (cherry picked from commit 8752df6592436d3394a743331bf8ac8299fe0f7d) --- diff --git a/includes/actions/Action.php b/includes/actions/Action.php index 4be2f7d945..6497cab263 100644 --- a/includes/actions/Action.php +++ b/includes/actions/Action.php @@ -252,11 +252,12 @@ abstract class Action implements MessageLocalizer { * Get a Message object with context set * Parameters are the same as wfMessage() * + * @param string|string[]|MessageSpecifier $key + * @param mixed ...$params * @return Message */ - final public function msg( $key ) { - $params = func_get_args(); - return $this->getContext()->msg( ...$params ); + final public function msg( $key, ...$params ) { + return $this->getContext()->msg( $key, ...$params ); } /** diff --git a/includes/context/ContextSource.php b/includes/context/ContextSource.php index a21f404b85..79d4e5bf14 100644 --- a/includes/context/ContextSource.php +++ b/includes/context/ContextSource.php @@ -162,14 +162,11 @@ abstract class ContextSource implements IContextSource { * @since 1.18 * @param string|string[]|MessageSpecifier $key Message key, or array of keys, * or a MessageSpecifier. - * @param mixed $args,... - * @suppress PhanCommentParamWithoutRealParam HHVM bug T228695#5450847 + * @param mixed ...$params * @return Message */ - public function msg( $key /* $args */ ) { - $args = func_get_args(); - - return $this->getContext()->msg( ...$args ); + public function msg( $key, ...$params ) { + return $this->getContext()->msg( $key, ...$params ); } /** diff --git a/includes/context/DerivativeContext.php b/includes/context/DerivativeContext.php index e4340ce2db..27dd500c15 100644 --- a/includes/context/DerivativeContext.php +++ b/includes/context/DerivativeContext.php @@ -256,14 +256,11 @@ class DerivativeContext extends ContextSource implements MutableContext { * * @param string|string[]|MessageSpecifier $key Message key, or array of keys, * or a MessageSpecifier. - * @param mixed $args,... Arguments to wfMessage - * @suppress PhanCommentParamWithoutRealParam HHVM bug T228695#5450847 + * @param mixed ...$params * @return Message */ - public function msg( $key ) { - $args = func_get_args(); - + public function msg( $key, ...$params ) { // phpcs:ignore MediaWiki.Usage.ExtendClassUsage.FunctionVarUsage - return wfMessage( ...$args )->setContext( $this ); + return wfMessage( $key, ...$params )->setContext( $this ); } } diff --git a/includes/context/RequestContext.php b/includes/context/RequestContext.php index cbcaba1c9f..73b8c5c15c 100644 --- a/includes/context/RequestContext.php +++ b/includes/context/RequestContext.php @@ -416,14 +416,11 @@ class RequestContext implements IContextSource, MutableContext { * * @param string|string[]|MessageSpecifier $key Message key, or array of keys, * or a MessageSpecifier. - * @param mixed $args,... - * @suppress PhanCommentParamWithoutRealParam HHVM bug T228695#5450847 + * @param mixed ...$params * @return Message */ - public function msg( $key ) { - $args = func_get_args(); - - return wfMessage( ...$args )->setContext( $this ); + public function msg( $key, ...$params ) { + return wfMessage( $key, ...$params )->setContext( $this ); } /** diff --git a/includes/htmlform/HTMLFormField.php b/includes/htmlform/HTMLFormField.php index b55b65287d..e4c6b30fc1 100644 --- a/includes/htmlform/HTMLFormField.php +++ b/includes/htmlform/HTMLFormField.php @@ -76,15 +76,15 @@ abstract class HTMLFormField { * * Parameters are the same as wfMessage(). * + * @param string|string[]|MessageSpecifier $key + * @param mixed ...$params * @return Message */ - public function msg() { - $args = func_get_args(); - + public function msg( $key, ...$params ) { if ( $this->mParent ) { - return $this->mParent->msg( ...$args ); + return $this->mParent->msg( $key, ...$params ); } - return wfMessage( ...$args ); + return wfMessage( $key, ...$params ); } /** diff --git a/includes/language/MessageLocalizer.php b/includes/language/MessageLocalizer.php index fc514390dd..fd0b08d66b 100644 --- a/includes/language/MessageLocalizer.php +++ b/includes/language/MessageLocalizer.php @@ -35,10 +35,9 @@ interface MessageLocalizer { * * @param string|string[]|MessageSpecifier $key Message key, or array of keys, * or a MessageSpecifier. - * @param mixed $params,... Normal message parameters - * @suppress PhanCommentParamWithoutRealParam HHVM bug T228695#5450847 + * @param mixed ...$params Normal message parameters * @return Message */ - public function msg( $key /*...*/ ); + public function msg( $key, ...$params ); } diff --git a/includes/logging/LogFormatter.php b/includes/logging/LogFormatter.php index b4a682583c..4aa890fb9b 100644 --- a/includes/logging/LogFormatter.php +++ b/includes/logging/LogFormatter.php @@ -755,10 +755,11 @@ class LogFormatter { /** * Shortcut for wfMessage which honors local context. * @param string $key + * @param mixed ...$params * @return Message */ - protected function msg( $key ) { - return $this->context->msg( $key ); + protected function msg( $key, ...$params ) { + return $this->context->msg( $key, ...$params ); } /** diff --git a/includes/resourceloader/ResourceLoaderContext.php b/includes/resourceloader/ResourceLoaderContext.php index 1274052142..ed9d70b51b 100644 --- a/includes/resourceloader/ResourceLoaderContext.php +++ b/includes/resourceloader/ResourceLoaderContext.php @@ -215,12 +215,11 @@ class ResourceLoaderContext implements MessageLocalizer { * @since 1.27 * @param string|string[]|MessageSpecifier $key Message key, or array of keys, * or a MessageSpecifier. - * @param mixed $args,... - * @suppress PhanCommentParamWithoutRealParam HHVM bug T228695#5450847 + * @param mixed ...$params * @return Message */ - public function msg( $key ) { - return wfMessage( ...func_get_args() ) + public function msg( $key, ...$params ) { + return wfMessage( $key, ...$params ) ->inLanguage( $this->getLanguage() ) // Use a dummy title because there is no real title // for this endpoint, and the cache won't vary on it diff --git a/includes/specialpage/SpecialPage.php b/includes/specialpage/SpecialPage.php index ba8e318bcd..1400d35db2 100644 --- a/includes/specialpage/SpecialPage.php +++ b/includes/specialpage/SpecialPage.php @@ -784,11 +784,13 @@ class SpecialPage implements MessageLocalizer { * Wrapper around wfMessage that sets the current context. * * @since 1.16 + * @param string|string[]|MessageSpecifier $key + * @param mixed ...$params * @return Message * @see wfMessage */ - public function msg( $key /* $args */ ) { - $message = $this->getContext()->msg( ...func_get_args() ); + public function msg( $key, ...$params ) { + $message = $this->getContext()->msg( $key, ...$params ); // RequestContext passes context to wfMessage, and the language is set from // the context, but setting the language for Message class removes the // interface message status, which breaks for example usernameless gender diff --git a/tests/phpunit/mocks/MockMessageLocalizer.php b/tests/phpunit/mocks/MockMessageLocalizer.php index 4d35930730..388dcf0933 100644 --- a/tests/phpunit/mocks/MockMessageLocalizer.php +++ b/tests/phpunit/mocks/MockMessageLocalizer.php @@ -30,14 +30,11 @@ class MockMessageLocalizer implements MessageLocalizer { * * @param string|string[]|MessageSpecifier $key Message key, or array of keys, * or a MessageSpecifier. - * @param mixed $args,... + * @param mixed ...$params * @return Message */ - public function msg( $key ) { - $args = func_get_args(); - - /** @var Message $message */ - $message = wfMessage( ...$args ); + public function msg( $key, ...$params ) { + $message = wfMessage( $key, ...$params ); if ( $this->languageCode !== null ) { $message->inLanguage( $this->languageCode );