Message::inLanguage() shouldn't unstub StubUserLang
authorBrad Jorsch <bjorsch@wikimedia.org>
Mon, 13 Apr 2015 15:40:30 +0000 (11:40 -0400)
committerBrad Jorsch <bjorsch@wikimedia.org>
Mon, 13 Apr 2015 15:40:30 +0000 (11:40 -0400)
When a string is passed to Message::inLanguage(), it first checks
whether the message's current language's code is equal to the string, to
avoid a call to Language::factory(). But if the message's current
language is an instance of StubUserLang, it's probably less expensive to
just call Language::factory() than it is to unstub.

This also avoids a possible recursion warning from T56193, particularly
if inLanguage() is being used intentionally in an attempt to avoid that
warning.

Change-Id: Ia09adec05cfbb09c09e07c6be1e2d613435664d9

includes/Message.php

index 134af0e..4935e33 100644 (file)
@@ -597,7 +597,7 @@ class Message implements MessageSpecifier {
                if ( $lang instanceof Language || $lang instanceof StubUserLang ) {
                        $this->language = $lang;
                } elseif ( is_string( $lang ) ) {
-                       if ( $this->language->getCode() != $lang ) {
+                       if ( !$this->language instanceof Language || $this->language->getCode() != $lang ) {
                                $this->language = Language::factory( $lang );
                        }
                } else {