60 private $formattedComments;
72 parent::__construct( $query, $moduleName,
'le' );
73 $this->commentStore = $commentStore;
74 $this->commentFormatter = $commentFormatter;
75 $this->changeTagDefStore = $changeTagDefStore;
76 $this->changeTagsStore = $changeTagsStore;
77 $this->userNameUtils = $userNameUtils;
78 $this->logFormatterFactory = $logFormatterFactory;
81 private bool $fld_ids =
false;
82 private bool $fld_title =
false;
83 private bool $fld_type =
false;
84 private bool $fld_user =
false;
85 private bool $fld_userid =
false;
86 private bool $fld_timestamp =
false;
87 private bool $fld_comment =
false;
88 private bool $fld_parsedcomment =
false;
89 private bool $fld_details =
false;
90 private bool $fld_tags =
false;
97 $prop = array_fill_keys(
$params[
'prop'],
true );
99 $this->fld_ids = isset( $prop[
'ids'] );
100 $this->fld_title = isset( $prop[
'title'] );
101 $this->fld_type = isset( $prop[
'type'] );
102 $this->fld_user = isset( $prop[
'user'] );
103 $this->fld_userid = isset( $prop[
'userid'] );
104 $this->fld_timestamp = isset( $prop[
'timestamp'] );
105 $this->fld_comment = isset( $prop[
'comment'] );
106 $this->fld_parsedcomment = isset( $prop[
'parsedcomment'] );
107 $this->fld_details = isset( $prop[
'details'] );
108 $this->fld_tags = isset( $prop[
'tags'] );
110 $hideLogs = LogEventsList::getExcludeClause( $db,
'user', $this->
getAuthority() );
111 if ( $hideLogs !==
false ) {
126 if ( $this->fld_user || $this->fld_userid || $user !==
null ) {
129 'actor' => [
'JOIN',
'actor_id=log_actor' ],
131 $this->
addFieldsIf( [
'actor_name',
'actor_user' ], $this->fld_user );
132 $this->
addFieldsIf(
'actor_user', $this->fld_userid );
133 if ( $user !==
null ) {
138 if ( $this->fld_ids ) {
141 'page' => [
'LEFT JOIN',
142 [
'log_namespace=page_namespace',
143 'log_title=page_title' ] ]
148 $this->
addFields( [
'page_id',
'log_page' ] );
151 [
'log_namespace',
'log_title' ],
152 $this->fld_title || $this->fld_parsedcomment
154 $this->
addFieldsIf(
'log_params', $this->fld_details || $this->fld_ids );
156 if ( $this->fld_comment || $this->fld_parsedcomment ) {
157 $commentQuery = $this->commentStore->getJoin(
'log_comment' );
158 $this->
addTables( $commentQuery[
'tables'] );
159 $this->
addFields( $commentQuery[
'fields'] );
163 if ( $this->fld_tags ) {
165 'ts_tags' => $this->changeTagsStore->makeTagSummarySubquery(
'logging' )
169 if (
$params[
'tag'] !==
null ) {
172 [
'log_id=ct_log_id' ] ] ] );
181 if (
$params[
'action'] !==
null ) {
184 $logAction =
$params[
'action'];
185 if ( !str_contains( $logAction,
'/' ) ) {
189 $logActions = array_fill_keys( $this->getAllowedLogActions(),
true );
190 [ $type, $action ] = explode(
'/', $logAction, 2 );
191 $valid = isset( $logActions[$logAction] ) || isset( $logActions[$type .
'/*'] );
197 [
'apierror-unrecognizedvalue', $encParamName,
wfEscapeWikiText( $logAction ) ],
198 "unknown_$encParamName"
206 } elseif (
$params[
'type'] !==
null ) {
219 if (
$params[
'continue'] !==
null ) {
221 $op = (
$params[
'dir'] ===
'newer' ?
'>=' :
'<=' );
222 $this->
addWhere( $db->buildComparison( $op, [
223 'log_timestamp' => $db->timestamp( $cont[0] ),
224 'log_id' => $cont[1],
232 if ( $title !==
null ) {
233 $titleObj = Title::newFromText( $title );
234 if ( $titleObj ===
null || $titleObj->isExternal() ) {
237 $this->
addWhereFld(
'log_namespace', $titleObj->getNamespace() );
238 $this->
addWhereFld(
'log_title', $titleObj->getDBkey() );
241 if (
$params[
'namespace'] !==
null ) {
247 if ( $prefix !==
null ) {
252 $title = Title::newFromText( $prefix );
253 if ( $title ===
null || $title->isExternal() ) {
256 $this->
addWhereFld(
'log_namespace', $title->getNamespace() );
258 $db->expr(
'log_title', IExpression::LIKE,
new LikeValue( $title->getDBkey(), $db->anyString() ) )
263 if (
$params[
'namespace'] !==
null || $title !==
null || $user !==
null ) {
264 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
265 $titleBits = LogPage::DELETED_ACTION;
266 $userBits = LogPage::DELETED_USER;
267 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
268 $titleBits = LogPage::DELETED_ACTION | LogPage::DELETED_RESTRICTED;
269 $userBits = LogPage::DELETED_USER | LogPage::DELETED_RESTRICTED;
274 if ( (
$params[
'namespace'] !==
null || $title !==
null ) && $titleBits ) {
275 $this->
addWhere( $db->bitAnd(
'log_deleted', $titleBits ) .
" != $titleBits" );
277 if ( $user !==
null && $userBits ) {
278 $this->
addWhere( $db->bitAnd(
'log_deleted', $userBits ) .
" != $userBits" );
287 if (
$params[
'tag'] ===
null && $user ===
null ) {
292 'MAX_EXECUTION_TIME',
297 $res = $this->
select( __METHOD__ );
299 if ( $this->fld_title ) {
302 if ( $this->fld_parsedcomment ) {
303 $this->formattedComments = $this->commentFormatter->formatItems(
304 $this->commentFormatter->rows( $res )
305 ->commentKey(
'log_comment' )
306 ->indexField(
'log_id' )
307 ->namespaceField(
'log_namespace' )
308 ->titleField(
'log_title' )
313 foreach ( $res as $row ) {
314 if ( ++$count > $limit ) {
321 $vals = $this->extractRowInfo( $row );
322 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $vals );
328 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'item' );
331 private function extractRowInfo( $row ) {
338 if ( $this->fld_ids ) {
339 $vals[
'logid'] = (int)$row->log_id;
342 if ( $this->fld_title ) {
343 $title = Title::makeTitle( $row->log_namespace, $row->log_title );
347 if ( $this->fld_title || $this->fld_ids || ( $this->fld_details && $row->log_params !==
'' ) ) {
348 if ( LogEventsList::isDeleted( $row, LogPage::DELETED_ACTION ) ) {
349 $vals[
'actionhidden'] =
true;
352 if ( LogEventsList::userCan( $row, LogPage::DELETED_ACTION, $authority ) ) {
353 if ( $this->fld_title ) {
358 if ( $this->fld_ids ) {
359 $vals[
'pageid'] = (int)$row->page_id;
360 $vals[
'logpage'] = (int)$row->log_page;
361 $revId = $logEntry->getAssociatedRevId();
363 $vals[
'revid'] = (int)$revId;
366 if ( $this->fld_details ) {
367 $vals[
'params'] = $this->logFormatterFactory->newFromEntry( $logEntry )->formatParametersForApi();
372 if ( $this->fld_type ) {
373 $vals[
'type'] = $row->log_type;
374 $vals[
'action'] = $row->log_action;
377 if ( $this->fld_user || $this->fld_userid ) {
378 if ( LogEventsList::isDeleted( $row, LogPage::DELETED_USER ) ) {
379 $vals[
'userhidden'] =
true;
382 if ( LogEventsList::userCan( $row, LogPage::DELETED_USER, $authority ) ) {
383 if ( $this->fld_user ) {
384 $vals[
'user'] = $row->actor_name;
386 if ( $this->fld_userid ) {
387 $vals[
'userid'] = (int)$row->actor_user;
390 if ( isset( $vals[
'user'] ) && $this->userNameUtils->isTemp( $vals[
'user'] ) ) {
391 $vals[
'temp'] =
true;
394 if ( !$row->actor_user ) {
395 $vals[
'anon'] =
true;
399 if ( $this->fld_timestamp ) {
400 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->log_timestamp );
403 if ( $this->fld_comment || $this->fld_parsedcomment ) {
404 if ( LogEventsList::isDeleted( $row, LogPage::DELETED_COMMENT ) ) {
405 $vals[
'commenthidden'] =
true;
408 if ( LogEventsList::userCan( $row, LogPage::DELETED_COMMENT, $authority ) ) {
409 if ( $this->fld_comment ) {
410 $vals[
'comment'] = $this->commentStore->getComment(
'log_comment', $row )->text;
413 if ( $this->fld_parsedcomment ) {
415 $vals[
'parsedcomment'] = $this->formattedComments[$row->log_id];
420 if ( $this->fld_tags ) {
421 if ( $row->ts_tags ) {
422 $tags = explode(
',', $row->ts_tags );
424 $vals[
'tags'] = $tags;
430 if ( $anyHidden && LogEventsList::isDeleted( $row, LogPage::DELETED_RESTRICTED ) ) {
431 $vals[
'suppressed'] =
true;
440 private function getAllowedLogActions() {
442 return array_keys( array_merge(
452 if (
$params[
'prop'] !==
null && in_array(
'parsedcomment',
$params[
'prop'] ) ) {
454 return 'anon-public-user-private';
455 } elseif ( LogEventsList::getExcludeClause( $this->
getDB(),
'user', $this->
getAuthority() )
456 === LogEventsList::getExcludeClause( $this->
getDB(),
'public' )
460 return 'anon-public-user-private';
467 $logActions = $this->getAllowedLogActions();
474 ParamValidator::PARAM_ISMULTI =>
true,
475 ParamValidator::PARAM_DEFAULT =>
'ids|title|type|user|timestamp|comment|details',
476 ParamValidator::PARAM_TYPE => [
491 ParamValidator::PARAM_TYPE => LogPage::validTypes(),
495 ParamValidator::PARAM_TYPE => $logActions
498 ParamValidator::PARAM_TYPE =>
'timestamp'
501 ParamValidator::PARAM_TYPE =>
'timestamp'
504 ParamValidator::PARAM_DEFAULT =>
'older',
505 ParamValidator::PARAM_TYPE => [
511 'newer' =>
'api-help-paramvalue-direction-newer',
512 'older' =>
'api-help-paramvalue-direction-older',
516 ParamValidator::PARAM_TYPE =>
'user',
517 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
521 ParamValidator::PARAM_TYPE =>
'namespace',
527 ParamValidator::PARAM_DEFAULT => 10,
528 ParamValidator::PARAM_TYPE =>
'limit',
529 IntegerDef::PARAM_MIN => 1,
547 'action=query&list=logevents'
548 =>
'apihelp-query+logevents-example-simple',
553 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Logevents';
558class_alias( ApiQueryLogEvents::class,
'ApiQueryLogEvents' );
wfEscapeWikiText( $input)
Escapes the given text so that it may be output using addWikiText() without any linking,...
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
array $params
The job parameters.
A value class to process existing log entries.
static newFromRow( $row)
Constructs new LogEntry from database result row.
Class to simplify the use of log pages.
A class containing constants representing the names of configuration variables.
const MaxExecutionTimeForExpensiveQueries
Name constant for the MaxExecutionTimeForExpensiveQueries setting, for use with Config::get()
const LogActionsHandlers
Name constant for the LogActionsHandlers setting, for use with Config::get()
const LogActions
Name constant for the LogActions setting, for use with Config::get()
const MiserMode
Name constant for the MiserMode setting, for use with Config::get()