user table: replace some '*' with explicit fields in selects
authorumherirrender <umherirrender_de.wp@web.de>
Fri, 25 May 2012 15:53:29 +0000 (17:53 +0200)
committerumherirrender <umherirrender_de.wp@web.de>
Fri, 25 May 2012 15:53:29 +0000 (17:53 +0200)
It is good practice to select only fields, which are used later

Change-Id: Iaaa252d594112894334a8ee9916007352d5bc4e7

includes/User.php
includes/api/ApiQueryUsers.php
includes/specials/SpecialPasswordReset.php

index 5de4b2c..84f02af 100644 (file)
@@ -1028,7 +1028,7 @@ class User {
                }
 
                $dbr = wfGetDB( DB_MASTER );
-               $s = $dbr->selectRow( 'user', '*', array( 'user_id' => $this->mId ), __METHOD__ );
+               $s = $dbr->selectRow( 'user', self::selectFields(), array( 'user_id' => $this->mId ), __METHOD__ );
 
                wfRunHooks( 'UserLoadFromDatabase', array( $this, &$s ) );
 
@@ -4018,7 +4018,7 @@ class User {
 
                        $res = $dbr->select(
                                'user_properties',
-                               '*',
+                               array( 'up_property', 'up_value' ),
                                array( 'up_user' => $this->getId() ),
                                __METHOD__
                        );
@@ -4141,4 +4141,28 @@ class User {
 
                return $ret;
        }
+
+       /**
+        * Return the list of user fields that should be selected to create
+        * a new user object.
+        * @return array
+        */
+       public static function selectFields() {
+               return array(
+                       'user_id',
+                       'user_name',
+                       'user_real_name',
+                       'user_password',
+                       'user_newpassword',
+                       'user_newpass_time',
+                       'user_email',
+                       'user_touched',
+                       'user_token',
+                       'user_email_authenticated',
+                       'user_email_token',
+                       'user_email_token_expires',
+                       'user_registration',
+                       'user_editcount',
+               );
+       }
 }
index a07ee7f..83872a5 100644 (file)
@@ -107,7 +107,7 @@ class ApiQueryUsers extends ApiQueryBase {
 
                if ( count( $goodNames ) ) {
                        $this->addTables( 'user' );
-                       $this->addFields( '*' );
+                       $this->addFields( User::selectFields() );
                        $this->addWhereFld( 'user_name', $goodNames );
 
                        if ( isset( $this->prop['groups'] ) || isset( $this->prop['rights'] ) ) {
index f140546..51520c8 100644 (file)
@@ -154,7 +154,7 @@ class SpecialPasswordReset extends FormSpecialPage {
                        $method = 'email';
                        $res = wfGetDB( DB_SLAVE )->select(
                                'user',
-                               '*',
+                               User::selectFields(),
                                array( 'user_email' => $data['Email'] ),
                                __METHOD__
                        );