Merge "includes/Linker.php: Added hook for "Media:" links"
[lhc/web/wiklou.git] / includes / api / ApiQueryLogEvents.php
index 1578775..ee7fbc0 100644 (file)
@@ -65,7 +65,6 @@ class ApiQueryLogEvents extends ApiQueryBase {
 
                // Order is significant here
                $this->addTables( array( 'logging', 'user', 'page' ) );
-               $this->addOption( 'STRAIGHT_JOIN' );
                $this->addJoinConds( array(
                        'user' => array( 'LEFT JOIN',
                                'user_id=log_user' ),
@@ -74,13 +73,14 @@ class ApiQueryLogEvents extends ApiQueryBase {
                                        'log_title=page_title' ) ) ) );
 
                $this->addFields( array(
+                       'log_id',
                        'log_type',
                        'log_action',
                        'log_timestamp',
                        'log_deleted',
                ) );
 
-               $this->addFieldsIf( array( 'log_id', 'page_id' ), $this->fld_ids );
+               $this->addFieldsIf( 'page_id', $this->fld_ids );
                $this->addFieldsIf( array( 'log_user', 'log_user_text', 'user_name' ), $this->fld_user );
                $this->addFieldsIf( 'log_user', $this->fld_userid );
                $this->addFieldsIf(
@@ -104,7 +104,26 @@ class ApiQueryLogEvents extends ApiQueryBase {
                }
 
                if ( !is_null( $params['action'] ) ) {
-                       list( $type, $action ) = explode( '/', $params['action'] );
+                       // Do validation of action param, list of allowed actions can contains wildcards
+                       // Allow the param, when the actions is in the list or a wildcard version is listed.
+                       $logAction = $params['action'];
+                       if ( strpos( $logAction, '/' ) === false ) {
+                               // all items in the list have a slash
+                               $valid = false;
+                       } else {
+                               $logActions = array_flip( $this->getAllowedLogActions() );
+                               list( $type, $action ) = explode( '/', $logAction, 2 );
+                               $valid = isset( $logActions[$logAction] ) || isset( $logActions[$type . '/*'] );
+                       }
+
+                       if ( !$valid ) {
+                               $valueName = $this->encodeParamName( 'action' );
+                               $this->dieUsage(
+                                       "Unrecognized value for parameter '$valueName': {$logAction}",
+                                       "unknown_$valueName"
+                               );
+                       }
+
                        $this->addWhereFld( 'log_type', $type );
                        $this->addWhereFld( 'log_action', $action );
                } elseif ( !is_null( $params['type'] ) ) {
@@ -117,6 +136,21 @@ class ApiQueryLogEvents extends ApiQueryBase {
                        $params['start'],
                        $params['end']
                );
+               // Include in ORDER BY for uniqueness
+               $this->addWhereRange( 'log_id', $params['dir'], null, null );
+
+               if ( !is_null( $params['continue'] ) ) {
+                       $cont = explode( '|', $params['continue'] );
+                       $this->dieContinueUsageIf( count( $cont ) != 2 );
+                       $op = ( $params['dir'] === 'newer' ? '>' : '<' );
+                       $continueTimestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
+                       $continueId = (int)$cont[1];
+                       $this->dieContinueUsageIf( $continueId != $cont[1] );
+                       $this->addWhere( "log_timestamp $op $continueTimestamp OR " .
+                               "(log_timestamp = $continueTimestamp AND " .
+                               "log_id $op= $continueId)"
+                       );
+               }
 
                $limit = $params['limit'];
                $this->addOption( 'LIMIT', $limit + 1 );
@@ -184,7 +218,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
                        if ( ++$count > $limit ) {
                                // We've reached the one extra which shows that there are
                                // additional pages to be had. Stop here...
-                               $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->log_timestamp ) );
+                               $this->setContinueEnumParameter( 'continue', "$row->log_timestamp|$row->log_id" );
                                break;
                        }
 
@@ -194,7 +228,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
                        }
                        $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
                        if ( !$fit ) {
-                               $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->log_timestamp ) );
+                               $this->setContinueEnumParameter( 'continue', "$row->log_timestamp|$row->log_id" );
                                break;
                        }
                }
@@ -405,6 +439,12 @@ class ApiQueryLogEvents extends ApiQueryBase {
                return $vals;
        }
 
+       private function getAllowedLogActions() {
+               global $wgLogActions, $wgLogActionsHandlers;
+
+               return array_keys( array_merge( $wgLogActions, $wgLogActionsHandlers ) );
+       }
+
        public function getCacheMode( $params ) {
                if ( $this->userCanSeeRevDel() ) {
                        return 'private';
@@ -421,8 +461,8 @@ class ApiQueryLogEvents extends ApiQueryBase {
                }
        }
 
-       public function getAllowedParams() {
-               global $wgLogTypes, $wgLogActions, $wgLogActionsHandlers;
+       public function getAllowedParams( $flags = 0 ) {
+               global $wgLogTypes;
 
                return array(
                        'prop' => array(
@@ -445,7 +485,10 @@ class ApiQueryLogEvents extends ApiQueryBase {
                                ApiBase::PARAM_TYPE => $wgLogTypes
                        ),
                        'action' => array(
-                               ApiBase::PARAM_TYPE => array_keys( array_merge( $wgLogActions, $wgLogActionsHandlers ) )
+                               // validation on request is done in execute()
+                               ApiBase::PARAM_TYPE => ( $flags & ApiBase::GET_VALUES_FOR_HELP )
+                                       ? $this->getAllowedLogActions()
+                                       : null
                        ),
                        'start' => array(
                                ApiBase::PARAM_TYPE => 'timestamp'
@@ -470,7 +513,8 @@ class ApiQueryLogEvents extends ApiQueryBase {
                                ApiBase::PARAM_MIN => 1,
                                ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
                                ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
-                       )
+                       ),
+                       'continue' => null,
                );
        }
 
@@ -492,7 +536,10 @@ class ApiQueryLogEvents extends ApiQueryBase {
                                ' tags           - Lists tags for the event',
                        ),
                        'type' => 'Filter log entries to only this type',
-                       'action' => "Filter log actions to only this type. Overrides {$p}type",
+                       'action' => array(
+                               "Filter log actions to only this action. Overrides {$p}type",
+                               "Wildcard actions like 'action/*' allows to specify any string for the asterisk"
+                       ),
                        'start' => 'The timestamp to start enumerating from',
                        'end' => 'The timestamp to end enumerating',
                        'dir' => $this->getDirectionDescription( $p ),
@@ -501,6 +548,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
                        'prefix' => 'Filter entries that start with this prefix. Disabled in Miser Mode',
                        'limit' => 'How many total event entries to return',
                        'tag' => 'Only list event entries tagged with this tag',
+                       'continue' => 'When more results are available, use this to continue',
                );
        }
 
@@ -562,7 +610,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
        }
 
        public function getDescription() {
-               return 'Get events from logs';
+               return 'Get events from logs.';
        }
 
        public function getPossibleErrors() {