30use Wikimedia\Timestamp\TimestampFormat as TS;
47 private $formattedComments;
59 parent::__construct( $query, $moduleName,
'le' );
60 $this->commentStore = $commentStore;
61 $this->commentFormatter = $commentFormatter;
62 $this->changeTagDefStore = $changeTagDefStore;
63 $this->changeTagsStore = $changeTagsStore;
64 $this->userNameUtils = $userNameUtils;
65 $this->logFormatterFactory = $logFormatterFactory;
68 private bool $fld_ids =
false;
69 private bool $fld_title =
false;
70 private bool $fld_type =
false;
71 private bool $fld_user =
false;
72 private bool $fld_userid =
false;
73 private bool $fld_timestamp =
false;
74 private bool $fld_comment =
false;
75 private bool $fld_parsedcomment =
false;
76 private bool $fld_details =
false;
77 private bool $fld_tags =
false;
84 $prop = array_fill_keys( $params[
'prop'],
true );
86 $this->fld_ids = isset( $prop[
'ids'] );
87 $this->fld_title = isset( $prop[
'title'] );
88 $this->fld_type = isset( $prop[
'type'] );
89 $this->fld_user = isset( $prop[
'user'] );
90 $this->fld_userid = isset( $prop[
'userid'] );
91 $this->fld_timestamp = isset( $prop[
'timestamp'] );
92 $this->fld_comment = isset( $prop[
'comment'] );
93 $this->fld_parsedcomment = isset( $prop[
'parsedcomment'] );
94 $this->fld_details = isset( $prop[
'details'] );
95 $this->fld_tags = isset( $prop[
'tags'] );
97 $hideLogs = LogEventsList::getExcludeClause( $db,
'user', $this->
getAuthority() );
98 if ( $hideLogs !==
false ) {
112 if ( $params[
'ids'] ) {
116 $user = $params[
'user'];
117 if ( $this->fld_user || $this->fld_userid || $user !==
null ) {
120 'actor' => [
'JOIN',
'actor_id=log_actor' ],
122 $this->
addFieldsIf( [
'actor_name',
'actor_user' ], $this->fld_user );
123 $this->
addFieldsIf(
'actor_user', $this->fld_userid );
124 if ( $user !==
null ) {
129 if ( $this->fld_ids ) {
132 'page' => [
'LEFT JOIN',
133 [
'log_namespace=page_namespace',
134 'log_title=page_title' ] ]
139 $this->
addFields( [
'page_id',
'log_page' ] );
142 [
'log_namespace',
'log_title' ],
143 $this->fld_title || $this->fld_parsedcomment
145 $this->
addFieldsIf(
'log_params', $this->fld_details || $this->fld_ids );
147 if ( $this->fld_comment || $this->fld_parsedcomment ) {
148 $commentQuery = $this->commentStore->getJoin(
'log_comment' );
149 $this->
addTables( $commentQuery[
'tables'] );
150 $this->
addFields( $commentQuery[
'fields'] );
154 if ( $this->fld_tags ) {
156 'ts_tags' => $this->changeTagsStore->makeTagSummarySubquery(
'logging' )
160 if ( $params[
'tag'] !==
null ) {
163 [
'log_id=ct_log_id' ] ] ] );
165 $this->
addWhereFld(
'ct_tag_id', $this->changeTagDefStore->getId( $params[
'tag'] ) );
172 if ( $params[
'action'] !==
null ) {
175 $logAction = $params[
'action'];
176 if ( !str_contains( $logAction,
'/' ) ) {
180 $logActions = array_fill_keys( $this->getAllowedLogActions(),
true );
181 [ $type, $action ] = explode(
'/', $logAction, 2 );
182 $valid = isset( $logActions[$logAction] ) || isset( $logActions[$type .
'/*'] );
188 [
'apierror-unrecognizedvalue', $encParamName,
wfEscapeWikiText( $logAction ) ],
189 "unknown_$encParamName"
197 } elseif ( $params[
'type'] !==
null ) {
208 $this->
addWhereRange(
'log_id', $params[
'dir'],
null,
null );
210 if ( $params[
'continue'] !==
null ) {
212 $op = ( $params[
'dir'] ===
'newer' ?
'>=' :
'<=' );
213 $this->
addWhere( $db->buildComparison( $op, [
214 'log_timestamp' => $db->timestamp( $cont[0] ),
215 'log_id' => $cont[1],
219 $limit = $params[
'limit'];
222 $title = $params[
'title'];
223 if ( $title !==
null ) {
224 $titleObj = Title::newFromText( $title );
225 if ( $titleObj ===
null || $titleObj->isExternal() ) {
228 $this->
addWhereFld(
'log_namespace', $titleObj->getNamespace() );
229 $this->
addWhereFld(
'log_title', $titleObj->getDBkey() );
232 if ( $params[
'namespace'] !==
null ) {
233 $this->
addWhereFld(
'log_namespace', $params[
'namespace'] );
236 $prefix = $params[
'prefix'];
238 if ( $prefix !==
null ) {
243 $title = Title::newFromText( $prefix );
244 if ( $title ===
null || $title->isExternal() ) {
247 $this->
addWhereFld(
'log_namespace', $title->getNamespace() );
249 $db->expr(
'log_title', IExpression::LIKE,
new LikeValue( $title->getDBkey(), $db->anyString() ) )
254 if ( $params[
'namespace'] !==
null || $title !==
null || $user !==
null ) {
255 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
256 $titleBits = LogPage::DELETED_ACTION;
257 $userBits = LogPage::DELETED_USER;
258 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
259 $titleBits = LogPage::DELETED_ACTION | LogPage::DELETED_RESTRICTED;
260 $userBits = LogPage::DELETED_USER | LogPage::DELETED_RESTRICTED;
265 if ( ( $params[
'namespace'] !==
null || $title !==
null ) && $titleBits ) {
266 $this->
addWhere( $db->bitAnd(
'log_deleted', $titleBits ) .
" != $titleBits" );
268 if ( $user !==
null && $userBits ) {
269 $this->
addWhere( $db->bitAnd(
'log_deleted', $userBits ) .
" != $userBits" );
278 if ( $params[
'tag'] ===
null && $user ===
null ) {
283 'MAX_EXECUTION_TIME',
288 $res = $this->
select( __METHOD__ );
290 if ( $this->fld_title ) {
293 if ( $this->fld_parsedcomment ) {
294 $this->formattedComments = $this->commentFormatter->formatItems(
295 $this->commentFormatter->rows( $res )
296 ->commentKey(
'log_comment' )
297 ->indexField(
'log_id' )
298 ->namespaceField(
'log_namespace' )
299 ->titleField(
'log_title' )
304 foreach ( $res as $row ) {
305 if ( ++$count > $limit ) {
312 $vals = $this->extractRowInfo( $row );
313 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $vals );
319 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'item' );
322 private function extractRowInfo( \stdClass $row ): array {
329 if ( $this->fld_ids ) {
330 $vals[
'logid'] = (int)$row->log_id;
333 if ( $this->fld_title ) {
338 if ( $this->fld_title || $this->fld_ids || ( $this->fld_details && $row->log_params !==
'' ) ) {
339 if ( LogEventsList::isDeleted( $row, LogPage::DELETED_ACTION ) ) {
340 $vals[
'actionhidden'] =
true;
343 if ( LogEventsList::userCan( $row, LogPage::DELETED_ACTION, $authority ) ) {
344 if ( $this->fld_title ) {
349 if ( $this->fld_ids ) {
350 $vals[
'pageid'] = (int)$row->page_id;
351 $vals[
'logpage'] = (int)$row->log_page;
352 $revId = $logEntry->getAssociatedRevId();
354 $vals[
'revid'] = (int)$revId;
357 if ( $this->fld_details ) {
358 $vals[
'params'] = $this->logFormatterFactory->newFromEntry( $logEntry )->formatParametersForApi();
363 if ( $this->fld_type ) {
364 $vals[
'type'] = $row->log_type;
365 $vals[
'action'] = $row->log_action;
368 if ( $this->fld_user || $this->fld_userid ) {
369 if ( LogEventsList::isDeleted( $row, LogPage::DELETED_USER ) ) {
370 $vals[
'userhidden'] =
true;
373 if ( LogEventsList::userCan( $row, LogPage::DELETED_USER, $authority ) ) {
374 if ( $this->fld_user ) {
375 $vals[
'user'] = $row->actor_name;
377 if ( $this->fld_userid ) {
378 $vals[
'userid'] = (int)$row->actor_user;
381 if ( isset( $vals[
'user'] ) && $this->userNameUtils->isTemp( $vals[
'user'] ) ) {
382 $vals[
'temp'] =
true;
385 if ( !$row->actor_user ) {
386 $vals[
'anon'] =
true;
390 if ( $this->fld_timestamp ) {
391 $vals[
'timestamp'] =
wfTimestamp( TS::ISO_8601, $row->log_timestamp );
394 if ( $this->fld_comment || $this->fld_parsedcomment ) {
395 if ( LogEventsList::isDeleted( $row, LogPage::DELETED_COMMENT ) ) {
396 $vals[
'commenthidden'] =
true;
399 if ( LogEventsList::userCan( $row, LogPage::DELETED_COMMENT, $authority ) ) {
400 if ( $this->fld_comment ) {
401 $vals[
'comment'] = $this->commentStore->getComment(
'log_comment', $row )->text;
404 if ( $this->fld_parsedcomment ) {
406 $vals[
'parsedcomment'] = $this->formattedComments[$row->log_id];
411 if ( $this->fld_tags ) {
412 if ( $row->ts_tags ) {
413 $tags = explode(
',', $row->ts_tags );
415 $vals[
'tags'] = $tags;
421 if ( $anyHidden && LogEventsList::isDeleted( $row, LogPage::DELETED_RESTRICTED ) ) {
422 $vals[
'suppressed'] =
true;
431 private function getAllowedLogActions() {
432 $config = $this->getConfig();
433 return array_keys( array_merge(
441 if ( $this->userCanSeeRevDel() ) {
444 if ( $params[
'prop'] !==
null && in_array(
'parsedcomment', $params[
'prop'] ) ) {
446 return 'anon-public-user-private';
447 } elseif ( LogEventsList::getExcludeClause( $this->
getDB(),
'user', $this->
getAuthority() )
448 === LogEventsList::getExcludeClause( $this->
getDB(),
'public' )
452 return 'anon-public-user-private';
458 $config = $this->getConfig();
460 $logActions = $this->getAllowedLogActions();
467 ParamValidator::PARAM_ISMULTI =>
true,
468 ParamValidator::PARAM_DEFAULT =>
'ids|title|type|user|timestamp|comment|details',
469 ParamValidator::PARAM_TYPE => [
484 ParamValidator::PARAM_TYPE => LogPage::validTypes(),
488 ParamValidator::PARAM_TYPE => $logActions
491 ParamValidator::PARAM_TYPE =>
'timestamp'
494 ParamValidator::PARAM_TYPE =>
'timestamp'
497 ParamValidator::PARAM_DEFAULT =>
'older',
498 ParamValidator::PARAM_TYPE => [
504 'newer' =>
'api-help-paramvalue-direction-newer',
505 'older' =>
'api-help-paramvalue-direction-older',
509 ParamValidator::PARAM_TYPE =>
'integer',
510 ParamValidator::PARAM_ISMULTI => true
513 ParamValidator::PARAM_TYPE =>
'user',
514 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
518 ParamValidator::PARAM_TYPE =>
'namespace',
524 ParamValidator::PARAM_DEFAULT => 10,
525 ParamValidator::PARAM_TYPE =>
'limit',
526 IntegerDef::PARAM_MIN => 1,
545 'action=query&list=logevents'
546 =>
'apihelp-query+logevents-example-simple',
552 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Logevents';
557class_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.
A value class to process existing log entries.
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()