Merge "Allow blacklisting certain namespaces in Special:ShortPages"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 1 Aug 2017 14:20:30 +0000 (14:20 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 1 Aug 2017 14:20:30 +0000 (14:20 +0000)
includes/DefaultSettings.php
includes/specials/SpecialShortpages.php
tests/phpunit/includes/specials/SpecialShortpagesTest.php [new file with mode: 0644]

index aa4320d..b6d75ce 100644 (file)
@@ -4089,6 +4089,13 @@ $wgTrackingCategories = [];
  */
 $wgContentNamespaces = [ NS_MAIN ];
 
+/**
+ * Optional array of namespaces which should be blacklisted from Special:ShortPages
+ * Only pages inside $wgContentNamespaces but not $wgShortPagesNamespaceBlacklist will
+ * be shown on that page.
+ */
+$wgShortPagesNamespaceBlacklist = [];
+
 /**
  * Array of namespaces, in addition to the talk namespaces, where signatures
  * (~~~~) are likely to be used. This determines whether to display the
index f980e71..e9c15e7 100644 (file)
@@ -41,9 +41,11 @@ class ShortPagesPage extends QueryPage {
        }
 
        public function getQueryInfo() {
+               $config = $this->getConfig();
+               $blacklist = $config->get( 'ShortPagesNamespaceBlacklist' );
                $tables = [ 'page' ];
                $conds = [
-                       'page_namespace' => MWNamespace::getContentNamespaces(),
+                       'page_namespace' => array_diff( MWNamespace::getContentNamespaces(), $blacklist ),
                        'page_is_redirect' => 0
                ];
                $joinConds = [];
diff --git a/tests/phpunit/includes/specials/SpecialShortpagesTest.php b/tests/phpunit/includes/specials/SpecialShortpagesTest.php
new file mode 100644 (file)
index 0000000..14c692a
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+
+/**
+ * Test class for SpecialShortpages class
+ *
+ * @since 1.30
+ *
+ * @licence GNU GPL v2+
+ */
+class SpecialShortpagesTest extends MediaWikiTestCase {
+
+       /**
+        * @dataProvider provideGetQueryInfoRespectsContentNs
+        * @covers ShortPagesPage::getQueryInfo()
+        */
+       public function testGetQueryInfoRespectsContentNS( $contentNS, $blacklistNS, $expectedNS ) {
+               $this->setMwGlobals( [
+                       'wgShortPagesNamespaceBlacklist' => $blacklistNS,
+                       'wgContentNamespaces' => $contentNS
+               ] );
+               $this->setTemporaryHook( 'ShortPagesQuery', function() {
+                       // empty hook handler
+               } );
+
+               $page = new ShortPagesPage();
+               $queryInfo = $page->getQueryInfo();
+
+               $this->assertArrayHasKey( 'conds', $queryInfo );
+               $this->assertArrayHasKey( 'page_namespace', $queryInfo[ 'conds' ] );
+               $this->assertEquals( $expectedNS, $queryInfo[ 'conds' ][ 'page_namespace' ] );
+       }
+
+       public function provideGetQueryInfoRespectsContentNs() {
+               return [
+                       [ [ NS_MAIN, NS_FILE ], [], [ NS_MAIN, NS_FILE ] ],
+                       [ [ NS_MAIN, NS_TALK ], [ NS_FILE ], [ NS_MAIN, NS_TALK ] ],
+                       [ [ NS_MAIN, NS_FILE ], [ NS_FILE ], [ NS_MAIN ] ],
+                       // NS_MAIN namespace is always forced
+                       [ [], [ NS_FILE ], [ NS_MAIN ] ]
+               ];
+       }
+
+}