API change: Registration time of users registered before the DB field was created...
[lhc/web/wiklou.git] / includes / api / ApiQueryLogEvents.php
index df93e7c..7f4aef7 100644 (file)
@@ -31,7 +31,7 @@ if (!defined('MEDIAWIKI')) {
 /**
  * Query action to List the log events, with optional filtering by various parameters.
  *
- * @addtogroup API
+ * @ingroup API
  */
 class ApiQueryLogEvents extends ApiQueryBase {
 
@@ -58,10 +58,14 @@ class ApiQueryLogEvents extends ApiQueryBase {
                if($hideLogs !== false)
                        $this->addWhere($hideLogs);
 
-               $this->addOption('STRAIGHT_JOIN');
-               $this->addTables("$tbl_logging LEFT OUTER JOIN $tbl_page ON " .
-               "log_namespace=page_namespace AND log_title=page_title " .
-               "INNER JOIN $tbl_user ON user_id=log_user");
+               // Order is significant here
+               $this->addTables(array('user', 'page', 'logging'));
+               $this->addJoinConds(array(
+                       'page' => array('LEFT JOIN',
+                               array(  'log_namespace=page_namespace',
+                                       'log_title=page_title'))));
+               $this->addWhere('user_id=log_user');
+               $this->addOption('USE INDEX', array('logging' => 'times')); // default, may change
 
                $this->addFields(array (
                        'log_type',
@@ -69,8 +73,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
                        'log_timestamp',
                ));
 
-               // FIXME: Fake out log_id for now until the column is live on Wikimedia
-               // $this->addFieldsIf('log_id', $this->fld_ids);
+               $this->addFieldsIf('log_id', $this->fld_ids);
                $this->addFieldsIf('page_id', $this->fld_ids);
                $this->addFieldsIf('log_user', $this->fld_user);
                $this->addFieldsIf('user_name', $this->fld_user);
@@ -79,9 +82,13 @@ class ApiQueryLogEvents extends ApiQueryBase {
                $this->addFieldsIf('log_comment', $this->fld_comment);
                $this->addFieldsIf('log_params', $this->fld_details);
 
-
                $this->addWhereFld('log_deleted', 0);
-               $this->addWhereFld('log_type', $params['type']);
+               
+               if( !is_null($params['type']) ) {
+                       $this->addWhereFld('log_type', $params['type']);
+                       $this->addOption('USE INDEX', array('logging' => array('type_time')));
+               }
+               
                $this->addWhereRange('log_timestamp', $params['dir'], $params['start'], $params['end']);
 
                $limit = $params['limit'];
@@ -95,6 +102,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
                        if (!$userid)
                                $this->dieUsage("User name $user not found", 'param_user');
                        $this->addWhereFld('log_user', $userid);
+                       $this->addOption('USE INDEX', array('logging' => array('user_time','page_time')));
                }
 
                $title = $params['title'];
@@ -104,6 +112,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
                                $this->dieUsage("Bad title value '$title'", 'param_title');
                        $this->addWhereFld('log_namespace', $titleObj->getNamespace());
                        $this->addWhereFld('log_title', $titleObj->getDBkey());
+                       $this->addOption('USE INDEX', array('logging' => array('user_time','page_time')));
                }
 
                $data = array ();
@@ -130,9 +139,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
                $vals = array();
 
                if ($this->fld_ids) {
-                       // FIXME: Fake out log_id for now until the column is live on Wikimedia
-                       // $vals['logid'] = intval($row->log_id);
-                       $vals['logid'] = 0;
+                       $vals['logid'] = intval($row->log_id);
                        $vals['pageid'] = intval($row->page_id);
                }