Allow searching for IPs' logs
authorJackmcbarn <jackmcbarn@gmail.com>
Mon, 23 Dec 2013 21:09:21 +0000 (16:09 -0500)
committerJackmcbarn <jackmcbarn@gmail.com>
Mon, 23 Dec 2013 21:41:39 +0000 (16:41 -0500)
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
includes/logging/LogPager.php

index 14364cb..356fa3e 100644 (file)
@@ -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' );
index b399732..7efb23d 100644 (file)
@@ -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();
        }
 
        /**