From 2a7e5c81935b5c45392fcb4fd48b620239e617db Mon Sep 17 00:00:00 2001 From: Marius Hoch Date: Tue, 26 Mar 2013 00:28:26 +0100 Subject: [PATCH] Make use of the user_timestamp index in ApiQueryAbuseLog Furthermore sanitize IPs as ::01 == ::1 Change-Id: I91489d17c012004f607bbe571b9a2702afbf3d81 --- api/ApiQueryAbuseLog.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/api/ApiQueryAbuseLog.php b/api/ApiQueryAbuseLog.php index 7bb12ee7c..db77fac39 100644 --- a/api/ApiQueryAbuseLog.php +++ b/api/ApiQueryAbuseLog.php @@ -105,7 +105,29 @@ class ApiQueryAbuseLog extends ApiQueryBase { $db = $this->getDB(); $notDeletedCond = SpecialAbuseLog::getNotDeletedCond($db); - $this->addWhereIf( array( 'afl_user_text' => $params['user'] ), isset( $params['user'] ) ); + if ( isset( $params['user'] ) ) { + $u = User::newFromName( $params['user'] ); + if ( $u ) { + // Username normalisation + $params['user'] = $u->getName(); + $userId = $u->getId(); + } elseif( IP::isIPAddress( $params['user'] ) ) { + // It's an IP, sanitize it + $params['user'] = IP::sanitizeIP( $params['user'] ); + $userId = 0; + } + + if ( isset( $userId ) ) { + // Only add the WHERE for user in case it's either a valid user (but not necessary an existing one) or an IP + $this->addWhere( + array( + 'afl_user' => $userId, + 'afl_user_text' => $params['user'] + ) + ); + } + } + $this->addWhereIf( array( 'afl_filter' => $params['filter'] ), isset( $params['filter'] ) ); $this->addWhereIf( $notDeletedCond, !SpecialAbuseLog::canSeeHidden( $user ) );