Stylize on Api
[lhc/web/wiklou.git] / includes / api / ApiQueryBlocks.php
index cc0e5fd..0609163 100644 (file)
@@ -64,10 +64,12 @@ class ApiQueryBlocks extends ApiQueryBase {
                $data = array();
 
                $this->addTables( 'ipblocks' );
+               $this->addFields( 'ipb_auto' );
+
                if ( $fld_id )
                        $this->addFields( 'ipb_id' );
                if ( $fld_user )
-                       $this->addFields( array( 'ipb_address', 'ipb_user', 'ipb_auto' ) );
+                       $this->addFields( array( 'ipb_address', 'ipb_user' ) );
                if ( $fld_by )
                {
                        $this->addTables( 'user' );
@@ -83,7 +85,7 @@ class ApiQueryBlocks extends ApiQueryBase {
                if ( $fld_range )
                        $this->addFields( array( 'ipb_range_start', 'ipb_range_end' ) );
                if ( $fld_flags )
-                       $this->addFields( array( 'ipb_auto', 'ipb_anon_only', 'ipb_create_account', 'ipb_enable_autoblock', 'ipb_block_email', 'ipb_deleted', 'ipb_allow_usertalk' ) );
+                       $this->addFields( array( 'ipb_anon_only', 'ipb_create_account', 'ipb_enable_autoblock', 'ipb_block_email', 'ipb_deleted', 'ipb_allow_usertalk' ) );
 
                $this->addOption( 'LIMIT', $params['limit'] + 1 );
                $this->addWhereRange( 'ipb_timestamp', $params['dir'], $params['start'], $params['end'] );
@@ -94,13 +96,14 @@ class ApiQueryBlocks extends ApiQueryBase {
                        foreach ( (array)$params['users'] as $u )
                                $this->prepareUsername( $u );
                        $this->addWhereFld( 'ipb_address', $this->usernames );
+                       $this->addWhereFld( 'ipb_auto', 0 );
                }
                if ( isset( $params['ip'] ) )
                {
                        list( $ip, $range ) = IP::parseCIDR( $params['ip'] );
                        if ( $ip && $range )
                        {
-                               # We got a CIDR range
+                               // We got a CIDR range
                                if ( $range < 16 )
                                        $this->dieUsage( 'CIDR ranges broader than /16 are not accepted', 'cidrtoobroad' );
                                $lower = wfBaseConvert( $ip, 10, 16, 8, false );
@@ -114,7 +117,8 @@ class ApiQueryBlocks extends ApiQueryBase {
                        $this->addWhere( array(
                                'ipb_range_start' . $db->buildLike( $prefix, $db->anyString() ),
                                "ipb_range_start <= '$lower'",
-                               "ipb_range_end >= '$upper'"
+                               "ipb_range_end >= '$upper'",
+                               'ipb_auto' => 0
                        ) );
                }
                if ( !$wgUser->isAllowed( 'hideuser' ) )
@@ -148,7 +152,7 @@ class ApiQueryBlocks extends ApiQueryBase {
                                $block['expiry'] = Block::decodeExpiry( $row->ipb_expiry, TS_ISO_8601 );
                        if ( $fld_reason )
                                $block['reason'] = $row->ipb_reason;
-                       if ( $fld_range )
+                       if ( $fld_range && !$row->ipb_auto )
                        {
                                $block['rangestart'] = IP::hexToQuad( $row->ipb_range_start );
                                $block['rangeend'] = IP::hexToQuad( $row->ipb_range_end );
@@ -257,6 +261,15 @@ class ApiQueryBlocks extends ApiQueryBase {
        public function getDescription() {
                return 'List all blocked users and IP addresses.';
        }
+       
+       public function getPossibleErrors() {
+               return array_merge( parent::getPossibleErrors(), array(
+                       array( 'code' => 'usersandip', 'info' => 'bkusers and bkip cannot be used together' ),
+                       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' ),
+               ) );
+       }
 
        protected function getExamples() {
                return array (  'api.php?action=query&list=blocks',