Show total number of autoblocks on top of Special:AutoblockList
authorNiharika Kohli <niharikakohli29@gmail.com>
Fri, 26 May 2017 17:13:19 +0000 (22:43 +0530)
committerKaldari <rkaldari@wikimedia.org>
Tue, 30 May 2017 20:45:36 +0000 (13:45 -0700)
Bug: T163172
Change-Id: I51b1b7675c2f4ed68ccb725230ffecf3583cf65f

includes/specials/SpecialAutoblockList.php
includes/specials/pagers/BlockListPager.php
languages/i18n/en.json
languages/i18n/qqq.json

index dcb2444..bf13865 100644 (file)
@@ -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
index 9a447ef..51e446d 100644 (file)
@@ -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';
        }
index cc60432..a0efd05 100644 (file)
        "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",
index 694ef74..7b7f27f 100644 (file)
        "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}}",