* (bug 26885) Allow show/hide of account blocks, temporary blocks and single IP block...
authorSam Reed <reedy@users.mediawiki.org>
Sat, 13 Aug 2011 15:39:57 +0000 (15:39 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Sat, 13 Aug 2011 15:39:57 +0000 (15:39 +0000)
Patch by John DuHart

Minor extras:
* Minor style tweak
* Add new error to getPossibleErrors
* Reused $p for module prefix

RELEASE-NOTES-1.19
includes/api/ApiQueryBlocks.php

index 04cce33..1723976 100644 (file)
@@ -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 ===
 
index 0ad0717..4553a35 100644 (file)
@@ -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' ),
                ) );
        }