From d062560f241ccd4f04aa2dbfe1d20b83d4cdd3ad Mon Sep 17 00:00:00 2001 From: Amir Sarabadani Date: Mon, 12 Jun 2017 14:23:51 +0430 Subject: [PATCH] Require $key in msg() functions Note: calling msg() with no parameter was never supported, doing this on a RequestContext for example would result in: PHP Warning: Missing argument 1 for wfMessage() ...followed by a bunch of fallout. So this patch only formally declares what was already a requirement in reality. Change-Id: I1864afb8bcc641698689828914949a06506d8f3a --- includes/actions/Action.php | 4 ++-- includes/context/ContextSource.php | 4 +++- includes/context/DerivativeContext.php | 4 +++- includes/context/IContextSource.php | 10 +--------- includes/context/RequestContext.php | 4 +++- includes/resourceloader/ResourceLoaderContext.php | 6 ++++-- includes/specialpage/SpecialPage.php | 4 ++-- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/includes/actions/Action.php b/includes/actions/Action.php index f06f828204..844a0d6048 100644 --- a/includes/actions/Action.php +++ b/includes/actions/Action.php @@ -34,7 +34,7 @@ * format (protect, delete, move, etc), and the just-do-something format (watch, rollback, * patrol, etc). The FormAction and FormlessAction classes represent these two groups. */ -abstract class Action { +abstract class Action implements MessageLocalizer { /** * Page on which we're performing the action @@ -253,7 +253,7 @@ abstract class Action { * * @return Message */ - final public function msg() { + final public function msg( $key ) { $params = func_get_args(); return call_user_func_array( [ $this->getContext(), 'msg' ], $params ); } diff --git a/includes/context/ContextSource.php b/includes/context/ContextSource.php index 2264670cfa..36d6df2c57 100644 --- a/includes/context/ContextSource.php +++ b/includes/context/ContextSource.php @@ -181,10 +181,12 @@ abstract class ContextSource implements IContextSource { * Parameters are the same as wfMessage() * * @since 1.18 + * @param string|string[]|MessageSpecifier $key Message key, or array of keys, + * or a MessageSpecifier. * @param mixed ... * @return Message */ - public function msg( /* $args */ ) { + public function msg( $key /* $args */ ) { $args = func_get_args(); return call_user_func_array( [ $this->getContext(), 'msg' ], $args ); diff --git a/includes/context/DerivativeContext.php b/includes/context/DerivativeContext.php index 29395101d0..9c3c42a92d 100644 --- a/includes/context/DerivativeContext.php +++ b/includes/context/DerivativeContext.php @@ -324,10 +324,12 @@ class DerivativeContext extends ContextSource implements MutableContext { * it would set only the original context, and not take * into account any changes. * + * @param string|string[]|MessageSpecifier $key Message key, or array of keys, + * or a MessageSpecifier. * @param mixed $args,... Arguments to wfMessage * @return Message */ - public function msg() { + public function msg( $key ) { $args = func_get_args(); return call_user_func_array( 'wfMessage', $args )->setContext( $this ); diff --git a/includes/context/IContextSource.php b/includes/context/IContextSource.php index 8e9fc6f6a9..d13e1a5705 100644 --- a/includes/context/IContextSource.php +++ b/includes/context/IContextSource.php @@ -52,7 +52,7 @@ use Liuggio\StatsdClient\Factory\StatsdDataFactory; * belong here either. Session state changes should only be propagated on * shutdown by separate persistence handler objects, for example. */ -interface IContextSource { +interface IContextSource extends MessageLocalizer { /** * Get the WebRequest object * @@ -143,14 +143,6 @@ interface IContextSource { */ public function getTiming(); - /** - * Get a Message object with context set. See wfMessage for parameters. - * - * @param mixed ... - * @return Message - */ - public function msg(); - /** * Export the resolved user IP, HTTP headers, user ID, and session ID. * The result will be reasonably sized to allow for serialization. diff --git a/includes/context/RequestContext.php b/includes/context/RequestContext.php index 0e1de504e5..2cabfe1013 100644 --- a/includes/context/RequestContext.php +++ b/includes/context/RequestContext.php @@ -449,10 +449,12 @@ class RequestContext implements IContextSource, MutableContext { * Get a Message object with context set * Parameters are the same as wfMessage() * + * @param string|string[]|MessageSpecifier $key Message key, or array of keys, + * or a MessageSpecifier. * @param mixed ... * @return Message */ - public function msg() { + public function msg( $key ) { $args = func_get_args(); return call_user_func_array( 'wfMessage', $args )->setContext( $this ); diff --git a/includes/resourceloader/ResourceLoaderContext.php b/includes/resourceloader/ResourceLoaderContext.php index 8955b8c2a0..f99114e2b9 100644 --- a/includes/resourceloader/ResourceLoaderContext.php +++ b/includes/resourceloader/ResourceLoaderContext.php @@ -29,7 +29,7 @@ use MediaWiki\MediaWikiServices; * Object passed around to modules which contains information about the state * of a specific loader request. */ -class ResourceLoaderContext { +class ResourceLoaderContext implements MessageLocalizer { protected $resourceLoader; protected $request; protected $logger; @@ -222,10 +222,12 @@ class ResourceLoaderContext { * Get a Message object with context set. See wfMessage for parameters. * * @since 1.27 + * @param string|string[]|MessageSpecifier $key Message key, or array of keys, + * or a MessageSpecifier. * @param mixed ... * @return Message */ - public function msg() { + public function msg( $key ) { return call_user_func_array( 'wfMessage', func_get_args() ) ->inLanguage( $this->getLanguage() ) // Use a dummy title because there is no real title diff --git a/includes/specialpage/SpecialPage.php b/includes/specialpage/SpecialPage.php index ba58e924ac..b883d335dd 100644 --- a/includes/specialpage/SpecialPage.php +++ b/includes/specialpage/SpecialPage.php @@ -33,7 +33,7 @@ use MediaWiki\MediaWikiServices; * * @ingroup SpecialPage */ -class SpecialPage { +class SpecialPage implements MessageLocalizer { // The canonical name of this special page // Also used for the default

heading, @see getDescription() protected $mName; @@ -743,7 +743,7 @@ class SpecialPage { * @return Message * @see wfMessage */ - public function msg( /* $args */ ) { + public function msg( $key /* $args */ ) { $message = call_user_func_array( [ $this->getContext(), 'msg' ], func_get_args() -- 2.20.1