(bug 33602) list=allusers throws exceptions with invalid names
authorSzymon Świerkosz <beau@adres.pl>
Thu, 26 Apr 2012 21:45:09 +0000 (23:45 +0200)
committerSzymon Świerkosz <beau@adres.pl>
Thu, 26 Apr 2012 21:45:09 +0000 (23:45 +0200)
Follow up to: I7d115e734cb8c93dcf6dc3b98bdbc81975951273.
I have replaced $this->keyToTitle calls with simple str_replace.
As a result invalid user names will be accepted in parameters, so
the chain of requests based on query-continue will not be broken
by invalid entry in the database.

Change-Id: I8a80fe6395ae6e9304e4d9ec7b604195ec3c9d00

includes/api/ApiQueryAllUsers.php

index 3c19c18..e96676e 100644 (file)
@@ -34,6 +34,16 @@ class ApiQueryAllUsers extends ApiQueryBase {
                parent::__construct( $query, $moduleName, 'au' );
        }
 
+       /**
+        * This function converts the user name to a canonical form
+        * which is stored in the database.
+        * @param String $name
+        * @return String
+        */
+       private function getCanonicalUserName( $name ) {
+               return str_replace( '_', ' ', $name );
+       }
+
        public function execute() {
                $db = $this->getDB();
                $params = $this->extractRequestParams();
@@ -57,8 +67,8 @@ class ApiQueryAllUsers extends ApiQueryBase {
                $useIndex = true;
 
                $dir = ( $params['dir'] == 'descending' ? 'older' : 'newer' );
-               $from = is_null( $params['from'] ) ? null : $this->keyToTitle( $params['from'] );
-               $to = is_null( $params['to'] ) ? null : $this->keyToTitle( $params['to'] );
+               $from = is_null( $params['from'] ) ? null : $this->getCanonicalUserName( $params['from'] );
+               $to = is_null( $params['to'] ) ? null : $this->getCanonicalUserName( $params['to'] );
 
                # MySQL doesn't seem to use 'equality propagation' here, so like the
                # ActiveUsers special page, we have to use rc_user_text for some cases.
@@ -68,7 +78,7 @@ class ApiQueryAllUsers extends ApiQueryBase {
 
                if ( !is_null( $params['prefix'] ) ) {
                        $this->addWhere( $userFieldToSort .
-                               $db->buildLike( $this->keyToTitle( $params['prefix'] ), $db->anyString() ) );
+                               $db->buildLike( $this->getCanonicalUserName( $params['prefix'] ), $db->anyString() ) );
                }
 
                if ( !is_null( $params['rights'] ) ) {