Title: Fix isRawHtmlMessage() for messages with underscores
authorKunal Mehta <legoktm@member.fsf.org>
Tue, 28 Aug 2018 19:47:49 +0000 (12:47 -0700)
committerJames D. Forrester <jforrester@wikimedia.org>
Fri, 31 Aug 2018 16:45:01 +0000 (09:45 -0700)
Title::getRootText() uses the text form (spaces) of the title, while
$wgRawHtmlMessages was specifying them in dbkey form (underscores).

And add tests while we're at it. Which spotted that the existing
code didn't work. Whoops. Fixed.

Change-Id: I05eea553c588e0f99f862e07ad15386507ed0728

includes/DefaultSettings.php
includes/Title.php
tests/phpunit/includes/TitleTest.php

index 2499077..2d1b331 100644 (file)
@@ -8850,6 +8850,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 ],
+               ];
+       }
 }