API: Make `usernames` a local variable
authorPatrick Westerhoff <PatrickWesterhoff@gmail.com>
Sat, 25 Oct 2014 01:51:28 +0000 (03:51 +0200)
committerUmherirrender <umherirrender_de.wp@web.de>
Mon, 10 Nov 2014 18:44:00 +0000 (18:44 +0000)
Instead of having a single-purpose instance variable, keep the array
local. This also allows reusing `prepareUsername` for other parameters.

Change-Id: Iea7c3c1f24a371a665ebdbeeb3e827262246f1b3

includes/api/ApiQueryBlocks.php

index 5c44173..b7779a7 100644 (file)
  */
 class ApiQueryBlocks extends ApiQueryBase {
 
-       /**
-        * @var array
-        */
-       protected $usernames;
-
        public function __construct( ApiQuery $query, $moduleName ) {
                parent::__construct( $query, $moduleName, 'bk' );
        }
@@ -102,10 +97,11 @@ class ApiQueryBlocks extends ApiQueryBase {
                        $this->addWhereFld( 'ipb_id', $params['ids'] );
                }
                if ( isset( $params['users'] ) ) {
+                       $usernames = array();
                        foreach ( (array)$params['users'] as $u ) {
-                               $this->prepareUsername( $u );
+                               $usernames[] = $this->prepareUsername( $u );
                        }
-                       $this->addWhereFld( 'ipb_address', $this->usernames );
+                       $this->addWhereFld( 'ipb_address', $usernames );
                        $this->addWhereFld( 'ipb_auto', 0 );
                }
                if ( isset( $params['ip'] ) ) {
@@ -264,7 +260,7 @@ class ApiQueryBlocks extends ApiQueryBase {
                if ( $name === false ) {
                        $this->dieUsage( "User name {$user} is not valid", 'param_user' );
                }
-               $this->usernames[] = $name;
+               return $name;
        }
 
        public function getAllowedParams() {