41 private $commentStore;
44 private $commentFormatter;
47 private $changeTagDefStore;
50 private $formattedComments;
66 parent::__construct( $query, $moduleName,
'le' );
67 $this->commentStore = $commentStore;
68 $this->commentFormatter = $commentFormatter;
69 $this->changeTagDefStore = $changeTagDefStore;
72 private $fld_ids =
false, $fld_title =
false, $fld_type =
false,
73 $fld_user =
false, $fld_userid =
false,
74 $fld_timestamp =
false, $fld_comment =
false, $fld_parsedcomment =
false,
75 $fld_details =
false, $fld_tags =
false;
82 $prop = array_fill_keys( $params[
'prop'],
true );
84 $this->fld_ids = isset( $prop[
'ids'] );
85 $this->fld_title = isset( $prop[
'title'] );
86 $this->fld_type = isset( $prop[
'type'] );
87 $this->fld_user = isset( $prop[
'user'] );
88 $this->fld_userid = isset( $prop[
'userid'] );
89 $this->fld_timestamp = isset( $prop[
'timestamp'] );
90 $this->fld_comment = isset( $prop[
'comment'] );
91 $this->fld_parsedcomment = isset( $prop[
'parsedcomment'] );
92 $this->fld_details = isset( $prop[
'details'] );
93 $this->fld_tags = isset( $prop[
'tags'] );
95 $hideLogs = LogEventsList::getExcludeClause( $db,
'user', $this->
getAuthority() );
96 if ( $hideLogs !==
false ) {
100 $this->
addTables( [
'logging',
'actor' ] );
102 'actor' => [
'JOIN',
'actor_id=log_actor' ],
113 if ( $this->fld_ids ) {
116 'page' => [
'LEFT JOIN',
117 [
'log_namespace=page_namespace',
118 'log_title=page_title' ] ]
123 $this->
addFields( [
'page_id',
'log_page' ] );
125 $this->
addFieldsIf( [
'actor_name',
'actor_user' ], $this->fld_user );
126 $this->
addFieldsIf(
'actor_user', $this->fld_userid );
128 [
'log_namespace',
'log_title' ],
129 $this->fld_title || $this->fld_parsedcomment
131 $this->
addFieldsIf(
'log_params', $this->fld_details );
133 if ( $this->fld_comment || $this->fld_parsedcomment ) {
134 $commentQuery = $this->commentStore->getJoin(
'log_comment' );
135 $this->
addTables( $commentQuery[
'tables'] );
136 $this->
addFields( $commentQuery[
'fields'] );
140 if ( $this->fld_tags ) {
144 if ( $params[
'tag'] !==
null ) {
147 [
'log_id=ct_log_id' ] ] ] );
149 $this->
addWhereFld(
'ct_tag_id', $this->changeTagDefStore->getId( $params[
'tag'] ) );
156 if ( $params[
'action'] !==
null ) {
159 $logAction = $params[
'action'];
160 if ( strpos( $logAction,
'/' ) ===
false ) {
164 $logActions = array_fill_keys( $this->getAllowedLogActions(),
true );
165 list(
$type, $action ) = explode(
'/', $logAction, 2 );
166 $valid = isset( $logActions[$logAction] ) || isset( $logActions[
$type .
'/*'] );
172 [
'apierror-unrecognizedvalue', $encParamName,
wfEscapeWikiText( $logAction ) ],
173 "unknown_$encParamName"
181 } elseif ( $params[
'type'] !==
null ) {
192 $this->
addWhereRange(
'log_id', $params[
'dir'],
null,
null );
194 if ( $params[
'continue'] !==
null ) {
195 $cont = explode(
'|', $params[
'continue'] );
197 $op = ( $params[
'dir'] ===
'newer' ?
'>' :
'<' );
198 $continueTimestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
199 $continueId = (int)$cont[1];
201 $this->
addWhere(
"log_timestamp $op $continueTimestamp OR " .
202 "(log_timestamp = $continueTimestamp AND " .
203 "log_id $op= $continueId)"
207 $limit = $params[
'limit'];
210 $user = $params[
'user'];
211 if ( $user !==
null ) {
215 $title = $params[
'title'];
217 $titleObj = Title::newFromText(
$title );
218 if ( $titleObj ===
null || $titleObj->isExternal() ) {
221 $this->
addWhereFld(
'log_namespace', $titleObj->getNamespace() );
222 $this->
addWhereFld(
'log_title', $titleObj->getDBkey() );
225 if ( $params[
'namespace'] !==
null ) {
226 $this->
addWhereFld(
'log_namespace', $params[
'namespace'] );
229 $prefix = $params[
'prefix'];
231 if ( $prefix !==
null ) {
232 if ( $this->
getConfig()->
get( MainConfigNames::MiserMode ) ) {
236 $title = Title::newFromText( $prefix );
241 $this->
addWhere(
'log_title ' . $db->buildLike(
$title->getDBkey(), $db->anyString() ) );
245 if ( $params[
'namespace'] !==
null ||
$title !==
null || $user !==
null ) {
246 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
249 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
256 if ( ( $params[
'namespace'] !==
null ||
$title !==
null ) && $titleBits ) {
257 $this->
addWhere( $db->bitAnd(
'log_deleted', $titleBits ) .
" != $titleBits" );
259 if ( $user !==
null && $userBits ) {
260 $this->
addWhere( $db->bitAnd(
'log_deleted', $userBits ) .
" != $userBits" );
269 if ( $params[
'tag'] ===
null && $user ===
null ) {
274 'MAX_EXECUTION_TIME',
275 $this->
getConfig()->
get( MainConfigNames::MaxExecutionTimeForExpensiveQueries )
281 if ( $this->fld_title ) {
284 if ( $this->fld_parsedcomment ) {
285 $this->formattedComments = $this->commentFormatter->formatItems(
286 $this->commentFormatter->rows(
$res )
287 ->commentKey(
'log_comment' )
288 ->indexField(
'log_id' )
289 ->namespaceField(
'log_namespace' )
290 ->titleField(
'log_title' )
295 foreach (
$res as $row ) {
296 if ( ++$count > $limit ) {
303 $vals = $this->extractRowInfo( $row );
304 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $vals );
310 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'item' );
313 private function extractRowInfo( $row ) {
314 $logEntry = DatabaseLogEntry::newFromRow( $row );
316 ApiResult::META_TYPE =>
'assoc',
320 if ( $this->fld_ids ) {
321 $vals[
'logid'] = (int)$row->log_id;
324 if ( $this->fld_title ) {
329 if ( $this->fld_title || $this->fld_ids || $this->fld_details && $row->log_params !==
'' ) {
331 $vals[
'actionhidden'] =
true;
335 if ( $this->fld_title ) {
340 if ( $this->fld_ids ) {
341 $vals[
'pageid'] = (int)$row->page_id;
342 $vals[
'logpage'] = (int)$row->log_page;
344 if ( $this->fld_details ) {
350 if ( $this->fld_type ) {
351 $vals[
'type'] = $row->log_type;
352 $vals[
'action'] = $row->log_action;
355 if ( $this->fld_user || $this->fld_userid ) {
357 $vals[
'userhidden'] =
true;
361 if ( $this->fld_user ) {
362 $vals[
'user'] = $row->actor_name;
364 if ( $this->fld_userid ) {
365 $vals[
'userid'] = (int)$row->actor_user;
368 if ( !$row->actor_user ) {
369 $vals[
'anon'] =
true;
373 if ( $this->fld_timestamp ) {
374 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->log_timestamp );
377 if ( $this->fld_comment || $this->fld_parsedcomment ) {
379 $vals[
'commenthidden'] =
true;
383 if ( $this->fld_comment ) {
384 $vals[
'comment'] = $this->commentStore->getComment(
'log_comment', $row )->text;
387 if ( $this->fld_parsedcomment ) {
389 $vals[
'parsedcomment'] = $this->formattedComments[$row->log_id];
394 if ( $this->fld_tags ) {
395 if ( $row->ts_tags ) {
396 $tags = explode(
',', $row->ts_tags );
398 $vals[
'tags'] = $tags;
405 $vals[
'suppressed'] =
true;
414 private function getAllowedLogActions() {
416 return array_keys( array_merge(
417 $config->get( MainConfigNames::LogActions ),
418 $config->get( MainConfigNames::LogActionsHandlers )
426 if ( $params[
'prop'] !==
null && in_array(
'parsedcomment', $params[
'prop'] ) ) {
428 return 'anon-public-user-private';
429 } elseif ( LogEventsList::getExcludeClause( $this->
getDB(),
'user', $this->
getAuthority() )
430 === LogEventsList::getExcludeClause( $this->
getDB(),
'public' )
434 return 'anon-public-user-private';
441 $logActions = $this->getAllowedLogActions();
448 ParamValidator::PARAM_ISMULTI =>
true,
449 ParamValidator::PARAM_DEFAULT =>
'ids|title|type|user|timestamp|comment|details',
450 ParamValidator::PARAM_TYPE => [
469 ParamValidator::PARAM_TYPE => $logActions
472 ParamValidator::PARAM_TYPE =>
'timestamp'
475 ParamValidator::PARAM_TYPE =>
'timestamp'
478 ParamValidator::PARAM_DEFAULT =>
'older',
479 ParamValidator::PARAM_TYPE => [
485 'newer' =>
'api-help-paramvalue-direction-newer',
486 'older' =>
'api-help-paramvalue-direction-older',
490 ParamValidator::PARAM_TYPE =>
'user',
491 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
495 ParamValidator::PARAM_TYPE =>
'namespace',
501 ParamValidator::PARAM_DEFAULT => 10,
502 ParamValidator::PARAM_TYPE =>
'limit',
503 IntegerDef::PARAM_MIN => 1,
512 if ( $config->get( MainConfigNames::MiserMode ) ) {
521 'action=query&list=logevents'
522 =>
'apihelp-query+logevents-example-simple',
527 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Logevents';
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
encodeParamName( $paramName)
This method mangles parameter name based on the prefix supplied to the constructor.
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
const LIMIT_BIG1
Fast query, standard limit.
requireMaxOneParameter( $params,... $required)
Die if more than one of a certain set of parameters is set and not false.
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
const GET_VALUES_FOR_HELP
getAllowedParams() flag: When set, the result could take longer to generate, but should be more thoro...
const LIMIT_BIG2
Fast query, apihighlimits limit.
getModuleName()
Get the name of the module being executed by this instance.
This is a base class for all Query modules.
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
addWhereRange( $field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, and an ORDER BY clause to sort in the right direction.
addFields( $value)
Add a set of fields to select to the internal array.
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
addTimestampWhereRange( $field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, similar to addWhereRange, but converts $start and $end t...
getDB()
Get the Query database connection (read-only)
executeGenderCacheFromResultWrapper(IResultWrapper $res, $fname=__METHOD__, $fieldPrefix='page')
Preprocess the result set to fill the GenderCache with the necessary information before using self::a...
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
addFieldsIf( $value, $condition)
Same as addFields(), but add the fields only if a condition is met.
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
addWhereFld( $field, $value)
Equivalent to addWhere( [ $field => $value ] )
addWhere( $value)
Add a set of WHERE clauses to the internal array.
userCanSeeRevDel()
Check whether the current user has permission to view revision-deleted fields.
Query action to List the log events, with optional filtering by various parameters.
getExamplesMessages()
Returns usage examples for this module.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
getAllowedParams( $flags=0)
__construct(ApiQuery $query, $moduleName, CommentStore $commentStore, RowCommentFormatter $commentFormatter, NameTableStore $changeTagDefStore)
getCacheMode( $params)
Get the cache mode for the data generated by this module.
getHelpUrls()
Return links to more detailed help pages about the module.
This is the main query class.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
static validTypes()
Get the list of valid log types.
A class containing constants representing the names of configuration variables.
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.