Merge "Api method documentation tweaks"
[lhc/web/wiklou.git] / includes / api / ApiQueryBlocks.php
index d5e2e64..49cd590 100644 (file)
  * @file
  */
 
-if ( !defined( 'MEDIAWIKI' ) ) {
-       // Eclipse helper - will be ignored in production
-       require_once( 'ApiQueryBase.php' );
-}
-
 /**
  * Query module to enumerate all user blocks
  *
@@ -82,6 +77,9 @@ class ApiQueryBlocks extends ApiQueryBase {
 
                $this->addOption( 'LIMIT', $params['limit'] + 1 );
                $this->addTimestampWhereRange( 'ipb_timestamp', $params['dir'], $params['start'], $params['end'] );
+
+               $db = $this->getDB();
+
                if ( isset( $params['ids'] ) ) {
                        $this->addWhereFld( 'ipb_id', $params['ids'] );
                }
@@ -105,11 +103,15 @@ class ApiQueryBlocks extends ApiQueryBase {
                        }
                        $prefix = substr( $lower, 0, 4 );
 
-                       $db = $this->getDB();
+                       # Fairly hard to make a malicious SQL statement out of hex characters,
+                       # but it is good practice to add quotes
+                       $lower = $db->addQuotes( $lower );
+                       $upper = $db->addQuotes( $upper );
+
                        $this->addWhere( array(
                                'ipb_range_start' . $db->buildLike( $prefix, $db->anyString() ),
-                               "ipb_range_start <= '$lower'",
-                               "ipb_range_end >= '$upper'",
+                               'ipb_range_start <= ' . $lower,
+                               'ipb_range_end >= ' . $upper,
                                'ipb_auto' => 0
                        ) );
                }
@@ -130,8 +132,8 @@ class ApiQueryBlocks extends ApiQueryBase {
                        $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 =  '.$db->addQuotes($db->getInfinity(), isset( $show['!temp'] ) );
-                       $this->addWhereIf( 'ipb_expiry != '.$db->addQuotes($db->getInfinity(), isset( $show['temp'] ) );
+                       $this->addWhereIf( 'ipb_expiry =  '.$db->addQuotes($db->getInfinity()), isset( $show['!temp'] ) );
+                       $this->addWhereIf( 'ipb_expiry != '.$db->addQuotes($db->getInfinity()), 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'] ) );
                }
@@ -322,6 +324,60 @@ class ApiQueryBlocks extends ApiQueryBase {
                );
        }
 
+       public function getResultProperties() {
+               return array(
+                       'id' => array(
+                               'id' => 'integer'
+                       ),
+                       'user' => array(
+                               'user' => array(
+                                       ApiBase::PROP_TYPE => 'string',
+                                       ApiBase::PROP_NULLABLE => true
+                               )
+                       ),
+                       'userid' => array(
+                               'userid' => array(
+                                       ApiBase::PROP_TYPE => 'integer',
+                                       ApiBase::PROP_NULLABLE => true
+                               )
+                       ),
+                       'by' => array(
+                               'by' => 'string'
+                       ),
+                       'byid' => array(
+                               'byid' => 'integer'
+                       ),
+                       'timestamp' => array(
+                               'timestamp' => 'timestamp'
+                       ),
+                       'expiry' => array(
+                               'expiry' => 'timestamp'
+                       ),
+                       'reason' => array(
+                               'reason' => 'string'
+                       ),
+                       'range' => array(
+                               'rangestart' => array(
+                                       ApiBase::PROP_TYPE => 'string',
+                                       ApiBase::PROP_NULLABLE => true
+                               ),
+                               'rangeend' => array(
+                                       ApiBase::PROP_TYPE => 'string',
+                                       ApiBase::PROP_NULLABLE => true
+                               )
+                       ),
+                       'flags' => array(
+                               'automatic' => 'boolean',
+                               'anononly' => 'boolean',
+                               'nocreate' => 'boolean',
+                               'autoblock' => 'boolean',
+                               'noemail' => 'boolean',
+                               'hidden' => 'boolean',
+                               'allowusertalk' => 'boolean'
+                       )
+               );
+       }
+
        public function getDescription() {
                return 'List all blocked users and IP addresses';
        }
@@ -344,7 +400,7 @@ class ApiQueryBlocks extends ApiQueryBase {
        }
 
        public function getHelpUrls() {
-               return 'http://www.mediawiki.org/wiki/API:Blocks';
+               return 'https://www.mediawiki.org/wiki/API:Blocks';
        }
 
        public function getVersion() {