From e96f254cf1748bb32d60e74fad3a7baac13b2d02 Mon Sep 17 00:00:00 2001 From: Niharika Kohli Date: Fri, 26 May 2017 22:43:19 +0530 Subject: [PATCH] Show total number of autoblocks on top of Special:AutoblockList Bug: T163172 Change-Id: I51b1b7675c2f4ed68ccb725230ffecf3583cf65f --- includes/specials/SpecialAutoblockList.php | 15 +++++++++++++++ includes/specials/pagers/BlockListPager.php | 20 ++++++++++++++++++++ languages/i18n/en.json | 1 + languages/i18n/qqq.json | 1 + 4 files changed, 37 insertions(+) diff --git a/includes/specials/SpecialAutoblockList.php b/includes/specials/SpecialAutoblockList.php index dcb2444e18..bf138656bd 100644 --- a/includes/specials/SpecialAutoblockList.php +++ b/includes/specials/SpecialAutoblockList.php @@ -78,6 +78,7 @@ class SpecialAutoblockList extends SpecialPage { ->prepareForm() ->displayForm( false ); + $this->showTotal( $pager ); $this->showList( $pager ); } @@ -97,6 +98,20 @@ class SpecialAutoblockList extends SpecialPage { return new BlockListPager( $this, $conds ); } + /** + * Show total number of autoblocks on top of the table + * + * @param BlockListPager $pager The BlockListPager instance for this page + */ + protected function showTotal( BlockListPager $pager ) { + $out = $this->getOutput(); + $out->addHTML( + Html::element( 'div', [ 'style' => 'font-weight: bold;' ], + $this->msg( 'autoblocklist-total-autoblocks', $pager->getTotalAutoblocks() )->parse() ) + . "\n" + ); + } + /** * Show the list of blocked accounts matching the actual filter. * @param BlockListPager $pager The BlockListPager instance for this page diff --git a/includes/specials/pagers/BlockListPager.php b/includes/specials/pagers/BlockListPager.php index 9a447ef8f3..51e446d593 100644 --- a/includes/specials/pagers/BlockListPager.php +++ b/includes/specials/pagers/BlockListPager.php @@ -246,6 +246,26 @@ class BlockListPager extends TablePager { return $info; } + /** + * Get total number of autoblocks at any given time + * + * @return int Total number of unexpired active autoblocks + */ + function getTotalAutoblocks() { + $dbr = $this->getDatabase(); + $res = $dbr->selectField( 'ipblocks', + [ 'COUNT(*) AS totalautoblocks' ], + [ + 'ipb_auto' => '1', + 'ipb_expiry >= ' . $dbr->addQuotes( $dbr->timestamp() ), + ] + ); + if ( $res ) { + return $res; + } + return 0; // We found nothing + } + protected function getTableClass() { return parent::getTableClass() . ' mw-blocklist'; } diff --git a/languages/i18n/en.json b/languages/i18n/en.json index cc60432627..a0efd0570c 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -2497,6 +2497,7 @@ "autoblocklist-submit": "Search", "autoblocklist-legend": "List autoblocks", "autoblocklist-localblocks": "Local {{PLURAL:$1|autoblock|autoblocks}}", + "autoblocklist-total-autoblocks": "Total number of autoblocks: $1", "autoblocklist-empty": "The autoblock list is empty.", "autoblocklist-otherblocks": "Other {{PLURAL:$1|autoblock|autoblocks}}", "ipblocklist": "Blocked users", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 694ef74506..7b7f27fe26 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -2686,6 +2686,7 @@ "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-total-autoblocks": "Shows the total number of active autoblocks on [[Special:AutoblockList]]. Parameters:\n* $1 - number of autoblocks", "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}}", -- 2.20.1