From d0664545ecffbded7862081eb877ae20c001075f Mon Sep 17 00:00:00 2001 From: Jackmcbarn Date: Mon, 23 Dec 2013 16:09:21 -0500 Subject: [PATCH] Allow searching for IPs' logs Update limitPerformer to search for IPs based on log_user_text, rather than preventing any results from being returned. Also, make a corresponding adjustment to list=logevents in the API, and remove indexes to match the LogPager code. Bug: 58691 Bug: 54404 Change-Id: Iae3f4ee5c7fba5b0b0f4f8fb3e67ac054c7b8dd7 --- includes/api/ApiQueryLogEvents.php | 15 ++++----------- includes/logging/LogPager.php | 22 ++++++++++------------ 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/includes/api/ApiQueryLogEvents.php b/includes/api/ApiQueryLogEvents.php index 14364cbaa8..356fa3eff7 100644 --- a/includes/api/ApiQueryLogEvents.php +++ b/includes/api/ApiQueryLogEvents.php @@ -72,7 +72,6 @@ class ApiQueryLogEvents extends ApiQueryBase { 'page' => array( 'LEFT JOIN', array( 'log_namespace=page_namespace', 'log_title=page_title' ) ) ) ); - $index = array( 'logging' => 'times' ); // default, may change $this->addFields( array( 'log_type', @@ -110,7 +109,6 @@ class ApiQueryLogEvents extends ApiQueryBase { $this->addWhereFld( 'log_action', $action ); } elseif ( !is_null( $params['type'] ) ) { $this->addWhereFld( 'log_type', $params['type'] ); - $index['logging'] = 'type_time'; } $this->addTimestampWhereRange( @@ -126,11 +124,11 @@ class ApiQueryLogEvents extends ApiQueryBase { $user = $params['user']; if ( !is_null( $user ) ) { $userid = User::idFromName( $user ); - if ( !$userid ) { - $this->dieUsage( "User name $user not found", 'param_user' ); + if ( $userid ) { + $this->addWhereFld( 'log_user', $userid ); + } else { + $this->addWhereFld( 'log_user_text', IP::sanitizeIP( $user ) ); } - $this->addWhereFld( 'log_user', $userid ); - $index['logging'] = 'user_time'; } $title = $params['title']; @@ -141,9 +139,6 @@ class ApiQueryLogEvents extends ApiQueryBase { } $this->addWhereFld( 'log_namespace', $titleObj->getNamespace() ); $this->addWhereFld( 'log_title', $titleObj->getDBkey() ); - - // Use the title index in preference to the user index if there is a conflict - $index['logging'] = is_null( $user ) ? 'page_time' : array( 'page_time', 'user_time' ); } $prefix = $params['prefix']; @@ -162,8 +157,6 @@ class ApiQueryLogEvents extends ApiQueryBase { $this->addWhere( 'log_title ' . $db->buildLike( $title->getDBkey(), $db->anyString() ) ); } - $this->addOption( 'USE INDEX', $index ); - // Paranoia: avoid brute force searches (bug 17342) if ( !is_null( $title ) ) { $this->addWhere( $db->bitAnd( 'log_deleted', LogPage::DELETED_ACTION ) . ' = 0' ); diff --git a/includes/logging/LogPager.php b/includes/logging/LogPager.php index b399732cdd..7efb23d7dd 100644 --- a/includes/logging/LogPager.php +++ b/includes/logging/LogPager.php @@ -167,21 +167,19 @@ class LogPager extends ReverseChronologicalPager { /* Fetch userid at first, if known, provides awesome query plan afterwards */ $userid = User::idFromName( $name ); if ( !$userid ) { - /* It should be nicer to abort query at all, - but for now it won't pass anywhere behind the optimizer */ - $this->mConds[] = "NULL"; + $this->mConds['log_user_text'] = IP::sanitizeIP( $name ); } else { $this->mConds['log_user'] = $userid; - // Paranoia: avoid brute force searches (bug 17342) - $user = $this->getUser(); - if ( !$user->isAllowed( 'deletedhistory' ) ) { - $this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::DELETED_USER ) . ' = 0'; - } elseif ( !$user->isAllowed( 'suppressrevision' ) ) { - $this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::SUPPRESSED_USER ) . - ' != ' . LogPage::SUPPRESSED_USER; - } - $this->performer = $usertitle->getText(); } + // Paranoia: avoid brute force searches (bug 17342) + $user = $this->getUser(); + if ( !$user->isAllowed( 'deletedhistory' ) ) { + $this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::DELETED_USER ) . ' = 0'; + } elseif ( !$user->isAllowed( 'suppressrevision' ) ) { + $this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::SUPPRESSED_USER ) . + ' != ' . LogPage::SUPPRESSED_USER; + } + $this->performer = $usertitle->getText(); } /** -- 2.20.1