From d9022f63880ce039446fba8364f68e656b7bf4cb Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 3 May 2012 13:01:35 +0200 Subject: Update to MediaWiki 1.19.0 --- includes/api/ApiQueryBlocks.php | 58 +++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 11 deletions(-) (limited to 'includes/api/ApiQueryBlocks.php') diff --git a/includes/api/ApiQueryBlocks.php b/includes/api/ApiQueryBlocks.php index cfcaf0b3..bebb5a7d 100644 --- a/includes/api/ApiQueryBlocks.php +++ b/includes/api/ApiQueryBlocks.php @@ -24,11 +24,6 @@ * @file */ -if ( !defined( 'MEDIAWIKI' ) ) { - // Eclipse helper - will be ignored in production - require_once( 'ApiQueryBase.php' ); -} - /** * Query module to enumerate all user blocks * @@ -46,7 +41,7 @@ class ApiQueryBlocks extends ApiQueryBase { } public function execute() { - global $wgUser, $wgContLang; + global $wgContLang; $params = $this->extractRequestParams(); $this->requireMaxOneParameter( $params, 'users', 'ip' ); @@ -92,6 +87,7 @@ class ApiQueryBlocks extends ApiQueryBase { $this->addWhereFld( 'ipb_address', $this->usernames ); $this->addWhereFld( 'ipb_auto', 0 ); } + $db = $this->getDB(); if ( isset( $params['ip'] ) ) { list( $ip, $range ) = IP::parseCIDR( $params['ip'] ); if ( $ip && $range ) { @@ -105,7 +101,6 @@ class ApiQueryBlocks extends ApiQueryBase { } $prefix = substr( $lower, 0, 4 ); - $db = $this->getDB(); $this->addWhere( array( 'ipb_range_start' . $db->buildLike( $prefix, $db->anyString() ), "ipb_range_start <= '$lower'", @@ -114,7 +109,29 @@ class ApiQueryBlocks extends ApiQueryBase { ) ); } - if ( !$wgUser->isAllowed( 'hideuser' ) ) { + 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 = '.$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'] ) ); + } + + if ( !$this->getUser()->isAllowed( 'hideuser' ) ) { $this->addWhereFld( 'ipb_deleted', 0 ); } @@ -252,15 +269,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 +310,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,10 +327,11 @@ 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' ), ) ); } - protected function getExamples() { + public function getExamples() { return array( 'api.php?action=query&list=blocks', 'api.php?action=query&list=blocks&bkusers=Alice|Bob' -- cgit v1.2.3-54-g00ecf