29use Wikimedia\Timestamp\TimestampFormat as TS;
39 private $formattedComments;
51 parent::__construct( $query, $moduleName,
'le' );
54 private bool $fld_ids =
false;
55 private bool $fld_title =
false;
56 private bool $fld_type =
false;
57 private bool $fld_user =
false;
58 private bool $fld_userid =
false;
59 private bool $fld_timestamp =
false;
60 private bool $fld_comment =
false;
61 private bool $fld_parsedcomment =
false;
62 private bool $fld_details =
false;
63 private bool $fld_tags =
false;
70 $prop = array_fill_keys( $params[
'prop'],
true );
72 $this->fld_ids = isset( $prop[
'ids'] );
73 $this->fld_title = isset( $prop[
'title'] );
74 $this->fld_type = isset( $prop[
'type'] );
75 $this->fld_user = isset( $prop[
'user'] );
76 $this->fld_userid = isset( $prop[
'userid'] );
77 $this->fld_timestamp = isset( $prop[
'timestamp'] );
78 $this->fld_comment = isset( $prop[
'comment'] );
79 $this->fld_parsedcomment = isset( $prop[
'parsedcomment'] );
80 $this->fld_details = isset( $prop[
'details'] );
81 $this->fld_tags = isset( $prop[
'tags'] );
83 $hideLogs = LogEventsList::getExcludeClause( $db,
'user', $this->
getAuthority() );
84 if ( $hideLogs !==
false ) {
98 if ( $params[
'ids'] ) {
102 $user = $params[
'user'];
103 if ( $this->fld_user || $this->fld_userid || $user !==
null ) {
106 'actor' => [
'JOIN',
'actor_id=log_actor' ],
108 $this->
addFieldsIf( [
'actor_name',
'actor_user' ], $this->fld_user );
109 $this->
addFieldsIf(
'actor_user', $this->fld_userid );
110 if ( $user !==
null ) {
115 if ( $this->fld_ids ) {
118 'page' => [
'LEFT JOIN',
119 [
'log_namespace=page_namespace',
120 'log_title=page_title' ] ]
125 $this->
addFields( [
'page_id',
'log_page' ] );
128 [
'log_namespace',
'log_title' ],
129 $this->fld_title || $this->fld_parsedcomment
131 $this->
addFieldsIf(
'log_params', $this->fld_details || $this->fld_ids );
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 ) {
142 'ts_tags' => $this->changeTagsStore->makeTagSummarySubquery(
'logging' )
146 if ( $params[
'tag'] !==
null ) {
149 [
'log_id=ct_log_id' ] ] ] );
151 $this->
addWhereFld(
'ct_tag_id', $this->changeTagDefStore->getId( $params[
'tag'] ) );
158 if ( $params[
'action'] !==
null ) {
161 $logAction = $params[
'action'];
162 if ( !str_contains( $logAction,
'/' ) ) {
166 $logActions = array_fill_keys( $this->getAllowedLogActions(),
true );
167 [ $type, $action ] = explode(
'/', $logAction, 2 );
168 $valid = isset( $logActions[$logAction] ) || isset( $logActions[$type .
'/*'] );
174 [
'apierror-unrecognizedvalue', $encParamName,
wfEscapeWikiText( $logAction ) ],
175 "unknown_$encParamName"
183 } elseif ( $params[
'type'] !==
null ) {
194 $this->
addWhereRange(
'log_id', $params[
'dir'],
null,
null );
196 if ( $params[
'continue'] !==
null ) {
198 $op = ( $params[
'dir'] ===
'newer' ?
'>=' :
'<=' );
199 $this->
addWhere( $db->buildComparison( $op, [
200 'log_timestamp' => $db->timestamp( $cont[0] ),
201 'log_id' => $cont[1],
205 $limit = $params[
'limit'];
208 $title = $params[
'title'];
209 if ( $title !==
null ) {
210 $titleObj = Title::newFromText( $title );
211 if ( $titleObj ===
null || $titleObj->isExternal() ) {
214 $this->
addWhereFld(
'log_namespace', $titleObj->getNamespace() );
215 $this->
addWhereFld(
'log_title', $titleObj->getDBkey() );
218 if ( $params[
'namespace'] !==
null ) {
219 $this->
addWhereFld(
'log_namespace', $params[
'namespace'] );
222 $prefix = $params[
'prefix'];
224 if ( $prefix !==
null ) {
229 $title = Title::newFromText( $prefix );
230 if ( $title ===
null || $title->isExternal() ) {
233 $this->
addWhereFld(
'log_namespace', $title->getNamespace() );
235 $db->expr(
'log_title', IExpression::LIKE,
new LikeValue( $title->getDBkey(), $db->anyString() ) )
240 if ( $params[
'namespace'] !==
null || $title !==
null || $user !==
null ) {
241 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
242 $titleBits = LogPage::DELETED_ACTION;
243 $userBits = LogPage::DELETED_USER;
244 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
245 $titleBits = LogPage::DELETED_ACTION | LogPage::DELETED_RESTRICTED;
246 $userBits = LogPage::DELETED_USER | LogPage::DELETED_RESTRICTED;
251 if ( ( $params[
'namespace'] !==
null || $title !==
null ) && $titleBits ) {
252 $this->
addWhere( $db->bitAnd(
'log_deleted', $titleBits ) .
" != $titleBits" );
254 if ( $user !==
null && $userBits ) {
255 $this->
addWhere( $db->bitAnd(
'log_deleted', $userBits ) .
" != $userBits" );
264 if ( $params[
'tag'] ===
null && $user ===
null ) {
269 'MAX_EXECUTION_TIME',
274 $res = $this->
select( __METHOD__ );
276 if ( $this->fld_title ) {
279 if ( $this->fld_parsedcomment ) {
280 $this->formattedComments = $this->commentFormatter->formatItems(
281 $this->commentFormatter->rows( $res )
282 ->commentKey(
'log_comment' )
283 ->indexField(
'log_id' )
284 ->namespaceField(
'log_namespace' )
285 ->titleField(
'log_title' )
290 foreach ( $res as $row ) {
291 if ( ++$count > $limit ) {
298 $vals = $this->extractRowInfo( $row );
299 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $vals );
305 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'item' );
308 private function extractRowInfo( \stdClass $row ): array {
315 if ( $this->fld_ids ) {
316 $vals[
'logid'] = (int)$row->log_id;
319 if ( $this->fld_title ) {
324 if ( $this->fld_title || $this->fld_ids || ( $this->fld_details && $row->log_params !==
'' ) ) {
325 if ( LogEventsList::isDeleted( $row, LogPage::DELETED_ACTION ) ) {
326 $vals[
'actionhidden'] =
true;
329 if ( LogEventsList::userCan( $row, LogPage::DELETED_ACTION, $authority ) ) {
330 if ( $this->fld_title ) {
335 if ( $this->fld_ids ) {
336 $vals[
'pageid'] = (int)$row->page_id;
337 $vals[
'logpage'] = (int)$row->log_page;
338 $revId = $logEntry->getAssociatedRevId();
340 $vals[
'revid'] = (int)$revId;
343 if ( $this->fld_details ) {
344 $vals[
'params'] = $this->logFormatterFactory->newFromEntry( $logEntry )->formatParametersForApi();
349 if ( $this->fld_type ) {
350 $vals[
'type'] = $row->log_type;
351 $vals[
'action'] = $row->log_action;
354 if ( $this->fld_user || $this->fld_userid ) {
355 if ( LogEventsList::isDeleted( $row, LogPage::DELETED_USER ) ) {
356 $vals[
'userhidden'] =
true;
359 if ( LogEventsList::userCan( $row, LogPage::DELETED_USER, $authority ) ) {
360 if ( $this->fld_user ) {
361 $vals[
'user'] = $row->actor_name;
363 if ( $this->fld_userid ) {
364 $vals[
'userid'] = (int)$row->actor_user;
367 if ( isset( $vals[
'user'] ) && $this->userNameUtils->isTemp( $vals[
'user'] ) ) {
368 $vals[
'temp'] =
true;
371 if ( !$row->actor_user ) {
372 $vals[
'anon'] =
true;
376 if ( $this->fld_timestamp ) {
377 $vals[
'timestamp'] =
wfTimestamp( TS::ISO_8601, $row->log_timestamp );
380 if ( $this->fld_comment || $this->fld_parsedcomment ) {
381 if ( LogEventsList::isDeleted( $row, LogPage::DELETED_COMMENT ) ) {
382 $vals[
'commenthidden'] =
true;
385 if ( LogEventsList::userCan( $row, LogPage::DELETED_COMMENT, $authority ) ) {
386 if ( $this->fld_comment ) {
387 $vals[
'comment'] = $this->commentStore->getComment(
'log_comment', $row )->text;
390 if ( $this->fld_parsedcomment ) {
392 $vals[
'parsedcomment'] = $this->formattedComments[$row->log_id];
397 if ( $this->fld_tags ) {
398 if ( $row->ts_tags ) {
399 $tags = explode(
',', $row->ts_tags );
401 $vals[
'tags'] = $tags;
407 if ( $anyHidden && LogEventsList::isDeleted( $row, LogPage::DELETED_RESTRICTED ) ) {
408 $vals[
'suppressed'] =
true;
417 private function getAllowedLogActions() {
419 return array_keys( array_merge(
427 if ( $this->userCanSeeRevDel() ) {
430 if ( $params[
'prop'] !==
null && in_array(
'parsedcomment', $params[
'prop'] ) ) {
432 return 'anon-public-user-private';
433 } elseif ( LogEventsList::getExcludeClause( $this->
getDB(),
'user', $this->
getAuthority() )
434 === LogEventsList::getExcludeClause( $this->
getDB(),
'public' )
438 return 'anon-public-user-private';
444 $config = $this->getConfig();
446 $logActions = $this->getAllowedLogActions();
453 ParamValidator::PARAM_ISMULTI =>
true,
454 ParamValidator::PARAM_DEFAULT =>
'ids|title|type|user|timestamp|comment|details',
455 ParamValidator::PARAM_TYPE => [
470 ParamValidator::PARAM_TYPE => LogPage::validTypes(),
474 ParamValidator::PARAM_TYPE => $logActions
477 ParamValidator::PARAM_TYPE =>
'timestamp'
480 ParamValidator::PARAM_TYPE =>
'timestamp'
483 ParamValidator::PARAM_DEFAULT =>
'older',
484 ParamValidator::PARAM_TYPE => [
490 'newer' =>
'api-help-paramvalue-direction-newer',
491 'older' =>
'api-help-paramvalue-direction-older',
495 ParamValidator::PARAM_TYPE =>
'integer',
496 ParamValidator::PARAM_ISMULTI => true
499 ParamValidator::PARAM_TYPE =>
'user',
500 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
504 ParamValidator::PARAM_TYPE =>
'namespace',
510 ParamValidator::PARAM_DEFAULT => 10,
511 ParamValidator::PARAM_TYPE =>
'limit',
512 IntegerDef::PARAM_MIN => 1,
531 'action=query&list=logevents'
532 =>
'apihelp-query+logevents-example-simple',
538 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Logevents';
543class_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()