Make use of the user_timestamp index in ApiQueryAbuseLog

Furthermore sanitize IPs as ::01 == ::1

Change-Id: I91489d17c012004f607bbe571b9a2702afbf3d81
This commit is contained in:
Marius Hoch 2013-03-26 00:28:26 +01:00
parent d5f282a2dd
commit 2a7e5c8193

View file

@ -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 ) );