API: Fixed handling of usernames containing spaces in list=block
authorRoan Kattouw <catrope@users.mediawiki.org>
Sat, 26 Apr 2008 14:09:16 +0000 (14:09 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Sat, 26 Apr 2008 14:09:16 +0000 (14:09 +0000)
RELEASE-NOTES
includes/api/ApiQueryBlocks.php

index 824288a..6a644e1 100644 (file)
@@ -266,6 +266,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * action=login now returns the correct waiting time in the details property
 * (bug 13792) Broken titles are now silently skipped in search results.
 * (bug 13819) exturlusage paging skipped an item
+* Fixed handling of usernames containing spaces in list=block
 
 === Languages updated in 1.13 ===
 
index 7d85dd3..795c350 100644 (file)
@@ -34,6 +34,8 @@ if (!defined('MEDIAWIKI')) {
  * @addtogroup API
  */
 class ApiQueryBlocks extends ApiQueryBase {
+       
+       var $users;
 
        public function __construct($query, $moduleName) {
                parent :: __construct($query, $moduleName, 'bk');
@@ -89,7 +91,11 @@ class ApiQueryBlocks extends ApiQueryBase {
                if(isset($params['ids']))
                        $this->addWhere(array('ipb_id' => $params['ids']));
                if(isset($params['users']))
-                       $this->addWhere(array('ipb_address' => $params['users']));
+               {
+                       foreach((array)$params['users'] as $u)
+                               $this->prepareUsername($u);
+                       $this->addWhere(array('ipb_address' => $this->usernames));
+               }
                if(!$wgUser->isAllowed('suppress'))
                        $this->addWhere(array('ipb_deleted' => 0));
 
@@ -152,6 +158,21 @@ class ApiQueryBlocks extends ApiQueryBase {
                $result->setIndexedTagName($data, 'block');
                $result->addValue('query', $this->getModuleName(), $data);
        }
+       
+       protected function prepareUsername($user) {
+               if( $user ) {
+                       $name = User::isIP( $user )
+                               ? $user
+                               : User::getCanonicalName( $user, 'valid' );
+                       if( $name === false ) {
+                               $this->dieUsage( "User name {$user} is not valid", 'param_user' );
+                       } else {
+                               $this->usernames[] = $name;
+                       }
+               } else {
+                       $this->dieUsage( 'User parameter may not be empty', 'param_user' );
+               }
+       }
 
        protected function convertHexIP($ip)
        {