Krinkle has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/276898

Change subject: Minor clean up of MFResourceLoaderParsedMessageModule
......................................................................

Minor clean up of MFResourceLoaderParsedMessageModule

* Remove redundant getMessages() method inherited from parent.
* Use $context->msg() instead of manually passing around language
  for consistency with core.
* Export one mw.messages.set() call with an object instead of one
  call for each message.
* Remove spurious line break from output.
* Fix typo (getScripts > getScript).

Change-Id: I1842d278ecdb69e8696d596fc89f6e2df86f1d28
---
M includes/modules/MFResourceLoaderParsedMessageModule.php
M tests/phpunit/modules/MFResourceLoaderParsedMessageModuleTest.php
2 files changed, 20 insertions(+), 27 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/98/276898/1

diff --git a/includes/modules/MFResourceLoaderParsedMessageModule.php 
b/includes/modules/MFResourceLoaderParsedMessageModule.php
index c92de3a..f500245 100644
--- a/includes/modules/MFResourceLoaderParsedMessageModule.php
+++ b/includes/modules/MFResourceLoaderParsedMessageModule.php
@@ -10,7 +10,7 @@
        protected $messages = array();
        /** @var array Saves the target for the module (e.g. desktop and 
mobile). */
        protected $targets = array( 'mobile', 'desktop' );
-       /** @var boolean Whether the module abuses getScripts. */
+       /** @var boolean Whether the module abuses getScript. */
        protected $hasHackedScriptMode = false;
 
        /**
@@ -33,25 +33,27 @@
        }
 
        /**
-        * Processes messages which have been marked as needing parsing
+        * Process messages which have been marked as needing parsing
         *
         * @param string $lang Language code to use
         * @return string JavaScript code
         */
-       public function addParsedMessages( $lang ) {
-               $js = "\n";
-               foreach ( $this->parsedMessages as $key ) {
-                       $value = wfMessage( $key )->inLanguage( $lang 
)->parse();
-                       $js .= Xml::encodeJsCall( 'mw.messages.set', array( 
$key, $value ) );
+       public function addParsedMessages( ResourceLoaderContext $context ) {
+               if ( !$this->parsedMessages ) {
+                       return '';
                }
-               return $js;
+               $messages = [];
+               foreach ( $this->parsedMessages as $key ) {
+                       $messages[ $key ] = $context->msg( $key )->parse();
+               }
+               return Xml::encodeJsCall( 'mw.messages.set', array( $messages ) 
);
        }
 
        /**
-        * Separates messages which have been marked as needing parsing from 
standard messages
+        * Separate messages which have been marked as needing parsing from 
standard messages
         * @param array $messages Array of messages to process
         */
-       public function processMessages( $messages ) {
+       private function processMessages( $messages ) {
                foreach ( $messages as $key => $value ) {
                        if ( is_array( $value ) ) {
                                foreach ( $value as $directive ) {
@@ -66,15 +68,6 @@
        }
 
        /**
-        * Gets list of message keys used by this module.
-        *
-        * @return array List of message keys
-        */
-       public function getMessages() {
-               return $this->messages;
-       }
-
-       /**
         * Gets all scripts for a given context concatenated together including 
processed messages
         *
         * @param ResourceLoaderContext $context Context in which to generate 
script
@@ -82,7 +75,7 @@
         */
        public function getScript( ResourceLoaderContext $context ) {
                $script = parent::getScript( $context );
-               return $this->addParsedMessages( $context->getLanguage() ) . 
$script;
+               return $this->addParsedMessages( $context ) . $script;
        }
 
        /**
diff --git a/tests/phpunit/modules/MFResourceLoaderParsedMessageModuleTest.php 
b/tests/phpunit/modules/MFResourceLoaderParsedMessageModuleTest.php
index 8500df6..260b334 100644
--- a/tests/phpunit/modules/MFResourceLoaderParsedMessageModuleTest.php
+++ b/tests/phpunit/modules/MFResourceLoaderParsedMessageModuleTest.php
@@ -3,7 +3,7 @@
 /**
  * @group MobileFrontend
  */
-class MFResourceLoaderParsedMessageModuleTest extends MediaWikiTestCase {
+class MFResourceLoaderParsedMessageModuleTest extends ResourceLoaderTestCase {
        private $modules = array(
                array(
                        'messages' => array( 'foo', 'bar' ),
@@ -41,16 +41,16 @@
        }
 
        public function providerAddParsedMessages() {
-               $msg = wfMessage( 'mobile-frontend-photo-license' )->parse();
-               $expected = "\n" . Xml::encodeJsCall( 'mw.messages.set',
-                               array( 'mobile-frontend-photo-license', $msg ) 
);
+               $html = wfMessage( 'mobile-frontend-photo-license' )->parse();
+               $expected = Xml::encodeJsCall( 'mw.messages.set',
+                               array( array( 'mobile-frontend-photo-license' 
=> $html ) ) );
 
                return array(
                        // test case 1
                        array(
                                $this->modules[0],
                                // expected value
-                               "\n"
+                               ''
                        ),
                        // test case 2
                        array(
@@ -62,7 +62,7 @@
                        array(
                                $this->modules[2],
                                // expected value 2
-                               "\n"
+                               ''
                        ),
                );
        }
@@ -74,7 +74,7 @@
         */
        public function testAddParsedMessages( $module, $expectedJavascript ) {
                $rl = new MFResourceLoaderParsedMessageModule( $module );
-               $js = $rl->addParsedMessages( 'en' );
+               $js = $rl->addParsedMessages( $this->getResourceLoaderContext( 
'en' ) );
 
                $this->assertEquals( $js, $expectedJavascript );
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/276898
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1842d278ecdb69e8696d596fc89f6e2df86f1d28
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Krinkle <krinklem...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to