From 742ec5b8c09bbb8731a8586aab4d90b10084062b Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Sat, 13 Aug 2011 15:39:57 +0000 Subject: [PATCH] * (bug 26885) Allow show/hide of account blocks, temporary blocks and single IP blocks for list=blocks Patch by John DuHart Minor extras: * Minor style tweak * Add new error to getPossibleErrors * Reused $p for module prefix --- RELEASE-NOTES-1.19 | 2 ++ includes/api/ApiQueryBlocks.php | 45 +++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES-1.19 b/RELEASE-NOTES-1.19 index 04cce33c9a..17239765a0 100644 --- a/RELEASE-NOTES-1.19 +++ b/RELEASE-NOTES-1.19 @@ -54,6 +54,8 @@ production. a best effort language name translation. Use CLDR extension for best result. * (bug 30230) action=expandtemplates should not silently override invalid title inputs * (bug 18634) Create API to fetch MediaWiki's language fallback tree structure +* (bug 26885) Allow show/hide of account blocks, temporary blocks and single IP blocks + for list=blocks === Languages updated in 1.19 === diff --git a/includes/api/ApiQueryBlocks.php b/includes/api/ApiQueryBlocks.php index 0ad0717d50..4553a35030 100644 --- a/includes/api/ApiQueryBlocks.php +++ b/includes/api/ApiQueryBlocks.php @@ -114,6 +114,28 @@ class ApiQueryBlocks extends ApiQueryBase { ) ); } + if ( !is_null( $params['show'] ) ) { + $show = array_flip( $params['show'] ); + + /* Check for conflicting parameters. */ + if ( ( isset ( $show['account'] ) && isset ( $show['!account'] ) ) + || ( isset ( $show['ip'] ) && isset ( $show['!ip'] ) ) + || ( isset ( $show['range'] ) && isset ( $show['!range'] ) ) + || ( isset ( $show['temp'] ) && isset ( $show['!temp'] ) ) + ) { + $this->dieUsageMsg( 'show' ); + } + + $this->addWhereIf( 'ipb_user = 0', isset( $show['!account'] ) ); + $this->addWhereIf( 'ipb_user != 0', isset( $show['account'] ) ); + $this->addWhereIf( 'ipb_user != 0 OR ipb_range_end > ipb_range_start', isset( $show['!ip'] ) ); + $this->addWhereIf( 'ipb_user = 0 AND ipb_range_end = ipb_range_start', isset( $show['ip'] ) ); + $this->addWhereIf( "ipb_expiry = 'infinity'", isset( $show['!temp'] ) ); + $this->addWhereIf( "ipb_expiry != 'infinity'", isset( $show['temp'] ) ); + $this->addWhereIf( "ipb_range_end = ipb_range_start", isset( $show['!range'] ) ); + $this->addWhereIf( "ipb_range_end > ipb_range_start", isset( $show['range'] ) ); + } + if ( !$wgUser->isAllowed( 'hideuser' ) ) { $this->addWhereFld( 'ipb_deleted', 0 ); } @@ -252,15 +274,29 @@ class ApiQueryBlocks extends ApiQueryBase { 'flags' ), ApiBase::PARAM_ISMULTI => true - ) + ), + 'show' => array( + ApiBase::PARAM_TYPE => array( + 'account', + '!account', + 'temp', + '!temp', + 'ip', + '!ip', + 'range', + '!range', + ), + ApiBase::PARAM_ISMULTI => true + ), ); } public function getParamDescription() { + $p = $this->getModulePrefix(); return array( 'start' => 'The timestamp to start enumerating from', 'end' => 'The timestamp to stop enumerating at', - 'dir' => $this->getDirectionDescription( $this->getModulePrefix() ), + 'dir' => $this->getDirectionDescription( $p ), 'ids' => 'Pipe-separated list of block IDs to list (optional)', 'users' => 'Pipe-separated list of users to search for (optional)', 'ip' => array( 'Get all blocks applying to this IP or CIDR range, including range blocks.', @@ -279,6 +315,10 @@ class ApiQueryBlocks extends ApiQueryBase { ' range - Adds the range of IPs affected by the block', ' flags - Tags the ban with (autoblock, anononly, etc)', ), + 'show' => array( + 'Show only items that meet this criteria.', + "For example, to see only indefinite blocks on IPs, set {$p}show=ip|!temp" + ), ); } @@ -292,6 +332,7 @@ class ApiQueryBlocks extends ApiQueryBase { array( 'code' => 'cidrtoobroad', 'info' => 'CIDR ranges broader than /16 are not accepted' ), array( 'code' => 'param_user', 'info' => 'User parameter may not be empty' ), array( 'code' => 'param_user', 'info' => 'User name user is not valid' ), + array( 'show' ), ) ); } -- 2.20.1