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
This commit is contained in:
Kunal Mehta 2018-08-28 12:47:49 -07:00 committed by James D. Forrester
parent 9686c83554
commit 9e5edca6c5
3 changed files with 32 additions and 2 deletions

View 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[]
*/

View 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 );
}

View 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 ],
];
}
}