jenkins-bot has submitted this change and it was merged.

Change subject: Better handling of Message objects as Message parameters
......................................................................


Better handling of Message objects as Message parameters

If a Message object is a parameter of another Message object, it should
use the same language, use-database flag, and so on as the outer Message
when it's being stringified.

Change-Id: I92762a1a63c90a16e8581edc96bd1da699880157
---
M includes/Message.php
M tests/phpunit/includes/MessageTest.php
2 files changed, 47 insertions(+), 1 deletion(-)

Approvals:
  Nikerabbit: Looks good to me, approved
  Gergő Tisza: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/includes/Message.php b/includes/Message.php
index 7d86d07..85c78d6 100644
--- a/includes/Message.php
+++ b/includes/Message.php
@@ -766,6 +766,7 @@
         */
        public function useDatabase( $useDatabase ) {
                $this->useDatabase = (bool)$useDatabase;
+               $this->message = null;
                return $this;
        }
 
@@ -1132,10 +1133,27 @@
                                return [ 'before', '[INVALID]' ];
                        }
                } elseif ( $param instanceof Message ) {
+                       // Match language, flags, etc. to the current message.
+                       $msg = clone $param;
+                       if ( $msg->language !== $this->language || 
$msg->useDatabase !== $this->useDatabase ) {
+                               // Cache depends on these parameters
+                               $msg->message = null;
+                       }
+                       $msg->interface = $this->interface;
+                       $msg->language = $this->language;
+                       $msg->useDatabase = $this->useDatabase;
+                       $msg->title = $this->title;
+
+                       // DWIM
+                       if ( $format === 'block-parse' ) {
+                               $format = 'parse';
+                       }
+                       $msg->format = $format;
+
                        // Message objects should not be before parameters 
because
                        // then they'll get double escaped. If the message 
needs to be
                        // escaped, it'll happen right here when we call 
toString().
-                       return [ 'after', $param->toString( $format ) ];
+                       return [ 'after', $msg->toString( $format ) ];
                } else {
                        return [ 'before', $param ];
                }
diff --git a/tests/phpunit/includes/MessageTest.php 
b/tests/phpunit/includes/MessageTest.php
index 8390e1f..e8afb4c 100644
--- a/tests/phpunit/includes/MessageTest.php
+++ b/tests/phpunit/includes/MessageTest.php
@@ -512,6 +512,34 @@
                );
        }
 
+       /**
+        * @covers Message::extractParam
+        */
+       public function testMessageAsParam() {
+               $this->setMwGlobals( [
+                       'wgScript' => '/wiki/index.php',
+                       'wgArticlePath' => '/wiki/$1',
+               ] );
+
+               $msg = new Message( 'returnto', [
+                       new Message( 'apihelp-link', [
+                               'foo', new Message( 'mainpage', [], 
Language::factory( 'en' ) )
+                       ], Language::factory( 'de' ) )
+               ], Language::factory( 'es' ) );
+
+               $this->assertEquals(
+                       'Volver a [[Special:ApiHelp/foo|Página principal]].',
+                       $msg->text(),
+                       'Process with ->text()'
+               );
+               $this->assertEquals(
+                       '<p>Volver a <a href="/wiki/Special:ApiHelp/foo" 
title="Special:ApiHelp/foo">Página '
+                               . "principal</a>.\n</p>",
+                       $msg->parseAsBlock(),
+                       'Process with ->parseAsBlock()'
+               );
+       }
+
        public static function provideParser() {
                return [
                        [

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I92762a1a63c90a16e8581edc96bd1da699880157
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Gergő Tisza <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to