Merge "Title: Fix isRawHtmlMessage() for messages with underscores"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 31 Aug 2018 17:39:51 +0000 (17:39 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 31 Aug 2018 17:39:51 +0000 (17:39 +0000)
includes/DefaultSettings.php
includes/Title.php
tests/phpunit/includes/TitleTest.php

index 4ddc23e..928d875 100644 (file)
@@ -8848,6 +8848,8 @@ $wgCSPReportOnlyHeader = false;
  * Extensions should add their messages here. The list is used for access control:
  * changing messages listed here will require editsitecss and editsitejs rights.
  *
+ * Message names must be given with underscores rather than spaces and with lowercase first letter.
+ *
  * @since 1.32
  * @var string[]
  */
index 895cc0e..ca62e0e 100644 (file)
@@ -1489,10 +1489,10 @@ class Title implements LinkTarget {
        public function isRawHtmlMessage() {
                global $wgRawHtmlMessages;
 
-               if ( $this->inNamespace( NS_MEDIAWIKI ) ) {
+               if ( !$this->inNamespace( NS_MEDIAWIKI ) ) {
                        return false;
                }
-               $message = lcfirst( $this->getRootText() );
+               $message = lcfirst( $this->getRootTitle()->getDBkey() );
                return in_array( $message, $wgRawHtmlMessages, true );
        }
 
index d585240..f36fbfd 100644 (file)
@@ -967,4 +967,32 @@ class TitleTest extends MediaWikiTestCase {
                        [ 'zz:Foo#ั‚ะตัั‚', '#.D1.82.D0.B5.D1.81.D1.82' ],
                ];
        }
+
+       /**
+        * @covers Title::isRawHtmlMessage
+        * @dataProvider provideIsRawHtmlMessage
+        */
+       public function testIsRawHtmlMessage( $textForm, $expected ) {
+               $this->setMwGlobals( 'wgRawHtmlMessages', [
+                       'foobar',
+                       'foo_bar',
+                       'foo-bar',
+               ] );
+
+               $title = Title::newFromText( $textForm );
+               $this->assertSame( $expected, $title->isRawHtmlMessage() );
+       }
+
+       public function provideIsRawHtmlMessage() {
+               return [
+                       [ 'MediaWiki:Foobar', true ],
+                       [ 'MediaWiki:Foo bar', true ],
+                       [ 'MediaWiki:Foo-bar', true ],
+                       [ 'MediaWiki:foo bar', true ],
+                       [ 'MediaWiki:foo-bar', true ],
+                       [ 'MediaWiki:foobar', true ],
+                       [ 'MediaWiki:some-other-message', false ],
+                       [ 'Main Page', false ],
+               ];
+       }
 }