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:
parent
9686c83554
commit
9e5edca6c5
3 changed files with 32 additions and 2 deletions
|
|
@ -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[]
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 ],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue