mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-24 07:34:11 +00:00
Merge "Use canonical name for NS_SPECIAL titles when checking the blacklist"
This commit is contained in:
commit
8850c1d0a3
|
@ -72,8 +72,8 @@
|
|||
"PopupsEventLogging": false,
|
||||
"@PopupsStatsvSamplingRate": "Sampling rate for logging performance data to statsv.",
|
||||
"PopupsStatsvSamplingRate": 0,
|
||||
"@PopupsPageBlacklist": "Blacklisted pages are subject to the HTML cache policy of the wiki. A purge on a blacklisted page maybe needed to see the effect of this configuration variable.",
|
||||
"PopupsPageBlacklist": [ "Special:UserLogin", "Special:CreateAccount" ]
|
||||
"@PopupsPageBlacklist": "Blacklisted pages are subject to the HTML cache policy of the wiki. A purge on a blacklisted page maybe needed to see the effect of this configuration variable. Every blacklisted page should be defined by a canonical name, eg: Special:Userlogin",
|
||||
"PopupsPageBlacklist": [ "Special:Userlogin", "Special:CreateAccount" ]
|
||||
},
|
||||
"ResourceModules": {
|
||||
"ext.popups.images": {
|
||||
|
|
|
@ -177,9 +177,21 @@ class PopupsContext {
|
|||
*/
|
||||
public function isTitleBlacklisted( $title ) {
|
||||
$blacklistedPages = $this->config->get( 'PopupsPageBlacklist' );
|
||||
$canonicalTitle = $title->getRootTitle();
|
||||
|
||||
if ( $title->isSpecialPage() ) {
|
||||
// it's special page, translate it to canonical name
|
||||
list( $name, $subpage ) = \SpecialPageFactory::resolveAlias( $canonicalTitle->getText() );
|
||||
|
||||
if ( $name !== null ) {
|
||||
$canonicalTitle = Title::newFromText( $name, NS_SPECIAL );
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $blacklistedPages as $page ) {
|
||||
$blacklistedTitle = Title::newFromText( $page );
|
||||
if ( $title->getRootTitle() == $blacklistedTitle->getRootTitle() ) {
|
||||
|
||||
if ( $canonicalTitle->equals( $blacklistedTitle ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -279,21 +279,39 @@ class PopupsContextTest extends MediaWikiTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return array/
|
||||
* @return array
|
||||
*/
|
||||
public function provideTestIsTitleBlacklisted() {
|
||||
$blacklist = [ 'Special:UserLogin', 'Special:CreateAccount', 'User:A' ];
|
||||
$blacklist = [ 'Special:Userlogin', 'Special:CreateAccount', 'User:A' ];
|
||||
return [
|
||||
[ $blacklist, Title::newFromText( 'Main_Page' ), false ],
|
||||
[ $blacklist, Title::newFromText( 'Special:UserLogin' ), true ],
|
||||
[ $blacklist, Title::newFromText( 'Special:CreateAccount' ), true ],
|
||||
[ $blacklist, Title::newFromText( 'User:A' ), true ],
|
||||
[ $blacklist, Title::newFromText( 'User:A/B' ), true ],
|
||||
[ $blacklist, Title::newFromText( 'User:B' ), false ],
|
||||
[ $blacklist, Title::newFromText( 'User:B/A' ), false ],
|
||||
// test canonical name handling
|
||||
[ $blacklist, Title::newFromText( 'Special:UserLogin' ), true ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if special page in different language is blacklisted
|
||||
*
|
||||
* @covers ::isTitleBlacklisted
|
||||
*/
|
||||
public function testIsTranslatedTitleBlacklisted() {
|
||||
$page = 'Specjalna:Preferencje';
|
||||
$blacklist = [ $page ];
|
||||
|
||||
$this->setMwGlobals( [
|
||||
"wgPopupsPageBlacklist" => $blacklist,
|
||||
"wgLanguageCode" => "pl"
|
||||
] );
|
||||
$context = $this->getContext();
|
||||
$this->assertEquals( true, $context->isTitleBlacklisted( Title::newFromText( $page ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getDefaultIsEnabledState
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue