jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/373688 )

Change subject: Use canonical name for NS_SPECIAL titles when checking the 
blacklist
......................................................................


Use canonical name for NS_SPECIAL titles when checking the blacklist

Changes
 - when verifying title use canonical names for pages in
 special namespace
 - improve unit tests to verify canonical names and translated titles

Bug: T170169
Change-Id: I49592133eb8286eacf04fd3034df091f7ef2aa50
---
M extension.json
M includes/PopupsContext.php
M tests/phpunit/PopupsContextTest.php
3 files changed, 36 insertions(+), 6 deletions(-)

Approvals:
  jenkins-bot: Verified
  Jdlrobson: Looks good to me, approved



diff --git a/extension.json b/extension.json
index 0bbf610..501aef3 100644
--- a/extension.json
+++ b/extension.json
@@ -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": {
diff --git a/includes/PopupsContext.php b/includes/PopupsContext.php
index 8b3bdfa..2a3e090 100644
--- a/includes/PopupsContext.php
+++ b/includes/PopupsContext.php
@@ -177,9 +177,21 @@
         */
        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;
                        }
                }
diff --git a/tests/phpunit/PopupsContextTest.php 
b/tests/phpunit/PopupsContextTest.php
index 2976b7c..67bbd9e 100644
--- a/tests/phpunit/PopupsContextTest.php
+++ b/tests/phpunit/PopupsContextTest.php
@@ -279,22 +279,40 @@
        }
 
        /**
-        * @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
         */
        public function testGetDefaultIsEnabledState() {

-- 
To view, visit https://gerrit.wikimedia.org/r/373688
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I49592133eb8286eacf04fd3034df091f7ef2aa50
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Popups
Gerrit-Branch: master
Gerrit-Owner: Pmiazga <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to