From b433d1958b7aefcd20280564d5d7b6f5a6f92f74 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Szymon=20=C5=9Awierkosz?= Date: Thu, 26 Apr 2012 23:45:09 +0200 Subject: [PATCH] (bug 33602) list=allusers throws exceptions with invalid names 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 | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/includes/api/ApiQueryAllUsers.php b/includes/api/ApiQueryAllUsers.php index 3c19c18cb1..e96676ea4b 100644 --- a/includes/api/ApiQueryAllUsers.php +++ b/includes/api/ApiQueryAllUsers.php @@ -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'] ) ) { -- 2.20.1