From 680de1a04acdbe56a7173aed6df684268f499ed3 Mon Sep 17 00:00:00 2001 From: mainframe98 Date: Mon, 6 Mar 2017 21:09:36 +0100 Subject: [PATCH] First version of AutoblockList special page This patch introduces a new special page named AutoblockList. Its design is reused from Special:BlockList. Bug: T146414 Change-Id: I811d23c98be749d8df36700b07a295355691af77 --- autoload.php | 1 + docs/hooks.txt | 4 + includes/specialpage/SpecialPageFactory.php | 3 +- includes/specials/SpecialAutoblockList.php | 152 ++++++++++++++++++++ languages/i18n/en.json | 6 + languages/i18n/qqq.json | 6 + languages/messages/MessagesEn.php | 1 + 7 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 includes/specials/SpecialAutoblockList.php diff --git a/autoload.php b/autoload.php index a16451d7a5..f274c7a79c 100644 --- a/autoload.php +++ b/autoload.php @@ -1307,6 +1307,7 @@ $wgAutoloadLocalClasses = [ 'SpecialAllPages' => __DIR__ . '/includes/specials/SpecialAllPages.php', 'SpecialApiHelp' => __DIR__ . '/includes/specials/SpecialApiHelp.php', 'SpecialApiSandbox' => __DIR__ . '/includes/specials/SpecialApiSandbox.php', + 'SpecialAutoblockList' => __DIR__ . '/includes/specials/SpecialAutoblockList.php', 'SpecialBlankpage' => __DIR__ . '/includes/specials/SpecialBlankpage.php', 'SpecialBlock' => __DIR__ . '/includes/specials/SpecialBlock.php', 'SpecialBlockList' => __DIR__ . '/includes/specials/SpecialBlockList.php', diff --git a/docs/hooks.txt b/docs/hooks.txt index 846a073b62..d56ca35961 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -2279,6 +2279,10 @@ $page: the Page that was rendered. $title: the Title of the rendered page. $parserOutput: ParserOutput resulting from rendering the page. +'OtherAutoblockLogLink': Get links to the autoblock log from extensions which +autoblocks users and/or IP addresses too. +&$otherBlockLink: An array with links to other autoblock logs + 'OtherBlockLogLink': Get links to the block log from extensions which blocks users and/or IP addresses too. &$otherBlockLink: An array with links to other block logs diff --git a/includes/specialpage/SpecialPageFactory.php b/includes/specialpage/SpecialPageFactory.php index 33e1cc30c8..0c9c718bc4 100644 --- a/includes/specialpage/SpecialPageFactory.php +++ b/includes/specialpage/SpecialPageFactory.php @@ -96,6 +96,7 @@ class SpecialPageFactory { 'Block' => 'SpecialBlock', 'Unblock' => 'SpecialUnblock', 'BlockList' => 'SpecialBlockList', + 'AutoblockList' => 'SpecialAutoblockList', 'ChangePassword' => 'SpecialChangePassword', 'BotPasswords' => 'SpecialBotPasswords', 'PasswordReset' => 'SpecialPasswordReset', @@ -504,7 +505,7 @@ class SpecialPageFactory { * @param bool $including Bool output is being captured for use in {{special:whatever}} * @param LinkRenderer|null $linkRenderer (since 1.28) * - * @return bool + * @return bool|Title */ public static function executePath( Title &$title, IContextSource &$context, $including = false, LinkRenderer $linkRenderer = null diff --git a/includes/specials/SpecialAutoblockList.php b/includes/specials/SpecialAutoblockList.php new file mode 100644 index 0000000000..dcb2444e18 --- /dev/null +++ b/includes/specials/SpecialAutoblockList.php @@ -0,0 +1,152 @@ +setHeaders(); + $this->outputHeader(); + $out = $this->getOutput(); + $lang = $this->getLanguage(); + $out->setPageTitle( $this->msg( 'autoblocklist' ) ); + $this->addHelpLink( 'Autoblock' ); + $out->addModuleStyles( [ 'mediawiki.special' ] ); + + # setup BlockListPager here to get the actual default Limit + $pager = $this->getBlockListPager(); + + # Just show the block list + $fields = [ + 'Limit' => [ + 'type' => 'limitselect', + 'label-message' => 'table_pager_limit_label', + 'options' => [ + $lang->formatNum( 20 ) => 20, + $lang->formatNum( 50 ) => 50, + $lang->formatNum( 100 ) => 100, + $lang->formatNum( 250 ) => 250, + $lang->formatNum( 500 ) => 500, + ], + 'name' => 'limit', + 'default' => $pager->getLimit(), + ] + ]; + + $context = new DerivativeContext( $this->getContext() ); + $context->setTitle( $this->getPageTitle() ); // Remove subpage + $form = HTMLForm::factory( 'ooui', $fields, $context ); + $form->setMethod( 'get' ) + ->setFormIdentifier( 'blocklist' ) + ->setWrapperLegendMsg( 'autoblocklist-legend' ) + ->setSubmitTextMsg( 'autoblocklist-submit' ) + ->setSubmitProgressive() + ->prepareForm() + ->displayForm( false ); + + $this->showList( $pager ); + } + + /** + * Setup a new BlockListPager instance. + * @return BlockListPager + */ + protected function getBlockListPager() { + $conds = [ + 'ipb_parent_block_id IS NOT NULL' + ]; + # Is the user allowed to see hidden blocks? + if ( !$this->getUser()->isAllowed( 'hideuser' ) ) { + $conds['ipb_deleted'] = 0; + } + + return new BlockListPager( $this, $conds ); + } + + /** + * Show the list of blocked accounts matching the actual filter. + * @param BlockListPager $pager The BlockListPager instance for this page + */ + protected function showList( BlockListPager $pager ) { + $out = $this->getOutput(); + + # Check for other blocks, i.e. global/tor blocks + $otherAutoblockLink = []; + Hooks::run( 'OtherAutoblockLogLink', [ &$otherAutoblockLink ] ); + + # Show additional header for the local block only when other blocks exists. + # Not necessary in a standard installation without such extensions enabled + if ( count( $otherAutoblockLink ) ) { + $out->addHTML( + Html::element( 'h2', [], $this->msg( 'autoblocklist-localblocks', + $pager->getNumRows() )->parse() ) + . "\n" + ); + } + + if ( $pager->getNumRows() ) { + $out->addParserOutputContent( $pager->getFullOutput() ); + } else { + $out->addWikiMsg( 'autoblocklist-empty' ); + } + + if ( count( $otherAutoblockLink ) ) { + $out->addHTML( + Html::rawElement( + 'h2', + [], + $this->msg( 'autoblocklist-otherblocks', count( $otherAutoblockLink ) )->parse() + ) . "\n" + ); + $list = ''; + foreach ( $otherAutoblockLink as $link ) { + $list .= Html::rawElement( 'li', [], $link ) . "\n"; + } + $out->addHTML( + Html::rawElement( + 'ul', + [ 'class' => 'mw-autoblocklist-otherblocks' ], + $list + ) . "\n" + ); + } + } + + protected function getGroupName() { + return 'users'; + } +} diff --git a/languages/i18n/en.json b/languages/i18n/en.json index b7078dd82e..32ec7bfa91 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -2463,6 +2463,12 @@ "unblocked-id": "Block $1 has been removed.", "unblocked-ip": "[[Special:Contributions/$1|$1]] has been unblocked.", "blocklist": "Blocked users", + "autoblocklist": "Autoblocks", + "autoblocklist-submit": "Search", + "autoblocklist-legend": "List autoblocks", + "autoblocklist-localblocks": "Local {{PLURAL:$1|autoblock|autoblocks}}", + "autoblocklist-empty": "The autoblock list is empty.", + "autoblocklist-otherblocks": "Other {{PLURAL:$1|autoblock|autoblocks}}", "ipblocklist": "Blocked users", "ipblocklist-legend": "Find a blocked user", "blocklist-userblocks": "Hide account blocks", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index a3e2a8cee1..2748f02e4c 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -2650,6 +2650,12 @@ "unblocked-id": "Used in [[Special:Unblock]]. Parameters:\n* $1 - autoblock ID\nSee also:\n* {{msg-mw|Unblocked}}\n* {{msg-mw|Unblocked-range}}", "unblocked-ip": "{{doc-important|Do not translate the title \"Special:Contributions\".}}\nParameters:\n* $1 - the IP address that was unblocked\nSee also:\n* {{msg-mw|Unblocked-range}}\n* {{msg-mw|Unblocked-id}}\n*{{msg-mw|Unblocked}}", "blocklist": "{{doc-special|BlockList}}", + "autoblocklist": "Title of [[Special:AutoblockList]].", + "autoblocklist-submit": "Used as Submit button text in the form on [[Special:BlockList]].\n\nSee also:\n* {{msg-mw|Ipblocklist-legend}}\n* {{msg-mw|Autoblocklist-submit}}\n{{Identical|Search}}", + "autoblocklist-legend":"Used as legend of the form in [[Special:AutoblockList]].\n\nSee also:\n* {{msg-mw|Autoblocklist-legend}}\n* {{msg-mw|Autoblocklist-submit}}", + "autoblocklist-localblocks": "[[File:Special AutoBlockList new.png|thumb|Example]]\nUsed on [[Special:AutoblockList]] as header when global autoblocks exists too.", + "autoblocklist-empty": "Used in [[Special:AutoblockList]].", + "autoblocklist-otherblocks": "[[File:Special AutoBlockList new.png|thumb|Example]]\nUsed on [[Special:AutoblockList]] as header for other blocks, i.e. from GlobalBlocking or TorBlocks.\n\nParameters:\n* $1 - number of blocks", "ipblocklist": "Title of [[Special:Ipblocklist]].", "ipblocklist-legend": "Used as legend of the form in [[Special:BlockList]].\n\nSee also:\n* {{msg-mw|Ipblocklist-legend}}\n* {{msg-mw|Ipblocklist-submit}}", "blocklist-userblocks": "Used as the label for the multi-select checkbox in the form on [[Special:BlockList]].\n{{Related|Blocklist-blocks}}", diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index b9280ea096..e6aa1090ad 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -400,6 +400,7 @@ $specialPageAliases = [ 'ApiHelp' => [ 'ApiHelp' ], 'ApiSandbox' => [ 'ApiSandbox' ], 'Ancientpages' => [ 'AncientPages' ], + 'AutoblockList' => [ 'AutoblockList', 'ListAutoblocks' ], 'Badtitle' => [ 'Badtitle' ], 'Blankpage' => [ 'BlankPage' ], 'Block' => [ 'Block', 'BlockIP', 'BlockUser' ], -- 2.20.1