From: DannyS712 Date: Sun, 25 Aug 2019 00:18:30 +0000 (+0000) Subject: Add filter to `Special:BlockList` to exclude indefinite blocks X-Git-Tag: 1.34.0-rc.0~279^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/%22%24ccApp/ecrire?a=commitdiff_plain;h=e50f14a47fdc98c024bbcaca341453a5091f11bb;p=lhc%2Fweb%2Fwiklou.git Add filter to `Special:BlockList` to exclude indefinite blocks Bug: T112380 Change-Id: If4bcccc46605c03793213da4d47bacf2200afc36 --- diff --git a/includes/specials/SpecialBlockList.php b/includes/specials/SpecialBlockList.php index b3d2358193..638535940d 100644 --- a/includes/specials/SpecialBlockList.php +++ b/includes/specials/SpecialBlockList.php @@ -82,8 +82,9 @@ class SpecialBlockList extends SpecialPage { 'Options' => [ 'type' => 'multiselect', 'options-messages' => [ - 'blocklist-userblocks' => 'userblocks', 'blocklist-tempblocks' => 'tempblocks', + 'blocklist-indefblocks' => 'indefblocks', + 'blocklist-userblocks' => 'userblocks', 'blocklist-addressblocks' => 'addressblocks', 'blocklist-rangeblocks' => 'rangeblocks', ], @@ -136,6 +137,7 @@ class SpecialBlockList extends SpecialPage { */ protected function getBlockListPager() { $conds = []; + $db = $this->getDB(); # Is the user allowed to see hidden blocks? if ( !$this->getUser()->isAllowed( 'hideuser' ) ) { $conds['ipb_deleted'] = 0; @@ -153,7 +155,7 @@ class SpecialBlockList extends SpecialPage { case DatabaseBlock::TYPE_IP: case DatabaseBlock::TYPE_RANGE: list( $start, $end ) = IP::parseRange( $target ); - $conds[] = wfGetDB( DB_REPLICA )->makeList( + $conds[] = $db->makeList( [ 'ipb_address' => $target, DatabaseBlock::getRangeCond( $start, $end ) @@ -174,9 +176,6 @@ class SpecialBlockList extends SpecialPage { if ( in_array( 'userblocks', $this->options ) ) { $conds['ipb_user'] = 0; } - if ( in_array( 'tempblocks', $this->options ) ) { - $conds['ipb_expiry'] = 'infinity'; - } if ( in_array( 'addressblocks', $this->options ) ) { $conds[] = "ipb_user != 0 OR ipb_range_end > ipb_range_start"; } @@ -184,10 +183,21 @@ class SpecialBlockList extends SpecialPage { $conds[] = "ipb_range_end = ipb_range_start"; } + $hideTemp = in_array( 'tempblocks', $this->options ); + $hideIndef = in_array( 'indefblocks', $this->options ); + if ( $hideTemp && $hideIndef ) { + // If both types are hidden, ensure query doesn't produce any results + $conds[] = '1=0'; + } elseif ( $hideTemp ) { + $conds['ipb_expiry'] = $db->getInfinity(); + } elseif ( $hideIndef ) { + $conds[] = "ipb_expiry != " . $db->addQuotes( $db->getInfinity() ); + } + if ( $this->blockType === 'sitewide' ) { - $conds[] = 'ipb_sitewide = 1'; + $conds['ipb_sitewide'] = 1; } elseif ( $this->blockType === 'partial' ) { - $conds[] = 'ipb_sitewide = 0'; + $conds['ipb_sitewide'] = 0; } return new BlockListPager( $this, $conds ); @@ -243,4 +253,13 @@ class SpecialBlockList extends SpecialPage { protected function getGroupName() { return 'users'; } + + /** + * Return a IDatabase object for reading + * + * @return IDatabase + */ + protected function getDB() { + return wfGetDB( DB_REPLICA ); + } } diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 8988419bcb..a330101cf7 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -2691,6 +2691,7 @@ "ipblocklist-legend": "Find a blocked user", "blocklist-userblocks": "Hide account blocks", "blocklist-tempblocks": "Hide temporary blocks", + "blocklist-indefblocks": "Hide indefinite blocks", "blocklist-addressblocks": "Hide single IP blocks", "blocklist-type": "Type:", "blocklist-type-opt-all": "All", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 86933e3a39..cbcc70a70e 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -2900,6 +2900,7 @@ "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}}", "blocklist-tempblocks": "Used as the label for the multi-select checkbox in the form on [[Special:BlockList]].\n{{Related|Blocklist-blocks}}", + "blocklist-indefblocks": "Used as the label for the multi-select checkbox in the form on [[Special:BlockList]].\n{{Related|Blocklist-blocks}}", "blocklist-addressblocks": "Used as the label for the multi-select checkbox in the form on [[Special:BlockList]].\n{{Related|Blocklist-blocks}}", "blocklist-type": "Used as label for dropdown box in [[Special:BlockList]].", "blocklist-type-opt-all": "Used as option for dropdown box in [[Special:BlockList]]. This is the default option and indicates that \"all\" blocks will be listed\n{{Identical|All}}",