Require $key in msg() functions
authorAmir Sarabadani <ladsgroup@gmail.com>
Mon, 12 Jun 2017 09:53:51 +0000 (14:23 +0430)
committerAmir Sarabadani <ladsgroup@gmail.com>
Wed, 14 Jun 2017 08:56:27 +0000 (13:26 +0430)
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
includes/context/ContextSource.php
includes/context/DerivativeContext.php
includes/context/IContextSource.php
includes/context/RequestContext.php
includes/resourceloader/ResourceLoaderContext.php
includes/specialpage/SpecialPage.php

index f06f828..844a0d6 100644 (file)
@@ -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 );
        }
index 2264670..36d6df2 100644 (file)
@@ -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 );
index 2939510..9c3c42a 100644 (file)
@@ -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 );
index 8e9fc6f..d13e1a5 100644 (file)
@@ -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.
index 0e1de50..2cabfe1 100644 (file)
@@ -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 );
index 8955b8c..f99114e 100644 (file)
@@ -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
index ba58e92..b883d33 100644 (file)
@@ -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 <h1> 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()