jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/368325 )
Change subject: Allow blacklisting certain namespaces in Special:ShortPages ...................................................................... Allow blacklisting certain namespaces in Special:ShortPages This new config variable ($wgShortPagesNamespaceBlacklist) allows wikis to specify namespaces which should be excluded from Special:ShortPages. This will be used by Commons, for which NS_FILE is a content namespace (accessible via Special:Random and Special:Nearby) but is not useful to list on Special:ShortPages. If the blacklist cancels out all namespace in wgContentNamespaces then all namespaces will show up on the page. Bug: T170687 Change-Id: I10b4849a5d7f3f8af75ccc6cfba230d03725c898 --- M includes/DefaultSettings.php M includes/specials/SpecialShortpages.php A tests/phpunit/includes/specials/SpecialShortpagesTest.php 3 files changed, 53 insertions(+), 1 deletion(-) Approvals: Pmiazga: Looks good to me, approved jenkins-bot: Verified Jdlrobson: Looks good to me, but someone else must approve diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 74d5fa4..9fb29fd 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -4092,6 +4092,13 @@ $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 * Signature button on the edit toolbar, and may also be used by extensions. diff --git a/includes/specials/SpecialShortpages.php b/includes/specials/SpecialShortpages.php index f980e71..e9c15e7 100644 --- a/includes/specials/SpecialShortpages.php +++ b/includes/specials/SpecialShortpages.php @@ -41,9 +41,11 @@ } 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 index 0000000..14c692a --- /dev/null +++ b/tests/phpunit/includes/specials/SpecialShortpagesTest.php @@ -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 ] ] + ]; + } + +} -- To view, visit https://gerrit.wikimedia.org/r/368325 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I10b4849a5d7f3f8af75ccc6cfba230d03725c898 Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org> Gerrit-Reviewer: Anomie <bjor...@wikimedia.org> Gerrit-Reviewer: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com> Gerrit-Reviewer: Jdlrobson <jrob...@wikimedia.org> Gerrit-Reviewer: Pmiazga <pmia...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits