From 9e5edca6c55bc386f899722cc50a62d669a1314b Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Tue, 28 Aug 2018 12:47:49 -0700 Subject: [PATCH] Title: Fix isRawHtmlMessage() for messages with underscores 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 | 2 ++ includes/Title.php | 4 ++-- tests/phpunit/includes/TitleTest.php | 28 ++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 24990779bd..2d1b331043 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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[] */ diff --git a/includes/Title.php b/includes/Title.php index 895cc0e635..ca62e0e0de 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -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 ); } diff --git a/tests/phpunit/includes/TitleTest.php b/tests/phpunit/includes/TitleTest.php index d585240d52..f36fbfd1d5 100644 --- a/tests/phpunit/includes/TitleTest.php +++ b/tests/phpunit/includes/TitleTest.php @@ -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 ], + ]; + } } -- 2.20.1