59 private $formattedComments;
70 parent::__construct( $query, $moduleName,
'le' );
71 $this->commentStore = $commentStore;
72 $this->commentFormatter = $commentFormatter;
73 $this->changeTagDefStore = $changeTagDefStore;
74 $this->userNameUtils = $userNameUtils;
75 $this->logFormatterFactory = $logFormatterFactory;
78 private bool $fld_ids =
false;
79 private bool $fld_title =
false;
80 private bool $fld_type =
false;
81 private bool $fld_user =
false;
82 private bool $fld_userid =
false;
83 private bool $fld_timestamp =
false;
84 private bool $fld_comment =
false;
85 private bool $fld_parsedcomment =
false;
86 private bool $fld_details =
false;
87 private bool $fld_tags =
false;
94 $prop = array_fill_keys(
$params[
'prop'],
true );
96 $this->fld_ids = isset( $prop[
'ids'] );
97 $this->fld_title = isset( $prop[
'title'] );
98 $this->fld_type = isset( $prop[
'type'] );
99 $this->fld_user = isset( $prop[
'user'] );
100 $this->fld_userid = isset( $prop[
'userid'] );
101 $this->fld_timestamp = isset( $prop[
'timestamp'] );
102 $this->fld_comment = isset( $prop[
'comment'] );
103 $this->fld_parsedcomment = isset( $prop[
'parsedcomment'] );
104 $this->fld_details = isset( $prop[
'details'] );
105 $this->fld_tags = isset( $prop[
'tags'] );
107 $hideLogs = LogEventsList::getExcludeClause( $db,
'user', $this->
getAuthority() );
108 if ( $hideLogs !==
false ) {
123 if ( $this->fld_user || $this->fld_userid || $user !==
null ) {
126 'actor' => [
'JOIN',
'actor_id=log_actor' ],
128 $this->
addFieldsIf( [
'actor_name',
'actor_user' ], $this->fld_user );
129 $this->
addFieldsIf(
'actor_user', $this->fld_userid );
130 if ( $user !==
null ) {
135 if ( $this->fld_ids ) {
138 'page' => [
'LEFT JOIN',
139 [
'log_namespace=page_namespace',
140 'log_title=page_title' ] ]
145 $this->
addFields( [
'page_id',
'log_page' ] );
148 [
'log_namespace',
'log_title' ],
149 $this->fld_title || $this->fld_parsedcomment
151 $this->
addFieldsIf(
'log_params', $this->fld_details || $this->fld_ids );
153 if ( $this->fld_comment || $this->fld_parsedcomment ) {
154 $commentQuery = $this->commentStore->getJoin(
'log_comment' );
155 $this->
addTables( $commentQuery[
'tables'] );
156 $this->
addFields( $commentQuery[
'fields'] );
160 if ( $this->fld_tags ) {
163 ->makeTagSummarySubquery(
'logging' )
167 if (
$params[
'tag'] !==
null ) {
170 [
'log_id=ct_log_id' ] ] ] );
179 if (
$params[
'action'] !==
null ) {
182 $logAction =
$params[
'action'];
183 if ( !str_contains( $logAction,
'/' ) ) {
187 $logActions = array_fill_keys( $this->getAllowedLogActions(),
true );
188 [ $type, $action ] = explode(
'/', $logAction, 2 );
189 $valid = isset( $logActions[$logAction] ) || isset( $logActions[$type .
'/*'] );
195 [
'apierror-unrecognizedvalue', $encParamName,
wfEscapeWikiText( $logAction ) ],
196 "unknown_$encParamName"
204 } elseif (
$params[
'type'] !==
null ) {
217 if (
$params[
'continue'] !==
null ) {
219 $op = (
$params[
'dir'] ===
'newer' ?
'>=' :
'<=' );
220 $this->
addWhere( $db->buildComparison( $op, [
221 'log_timestamp' => $db->timestamp( $cont[0] ),
222 'log_id' => $cont[1],
230 if ( $title !==
null ) {
231 $titleObj = Title::newFromText( $title );
232 if ( $titleObj ===
null || $titleObj->isExternal() ) {
235 $this->
addWhereFld(
'log_namespace', $titleObj->getNamespace() );
236 $this->
addWhereFld(
'log_title', $titleObj->getDBkey() );
239 if (
$params[
'namespace'] !==
null ) {
245 if ( $prefix !==
null ) {
250 $title = Title::newFromText( $prefix );
251 if ( $title ===
null || $title->isExternal() ) {
254 $this->
addWhereFld(
'log_namespace', $title->getNamespace() );
256 $db->expr(
'log_title', IExpression::LIKE,
new LikeValue( $title->getDBkey(), $db->anyString() ) )
261 if (
$params[
'namespace'] !==
null || $title !==
null || $user !==
null ) {
262 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
263 $titleBits = LogPage::DELETED_ACTION;
264 $userBits = LogPage::DELETED_USER;
265 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
266 $titleBits = LogPage::DELETED_ACTION | LogPage::DELETED_RESTRICTED;
267 $userBits = LogPage::DELETED_USER | LogPage::DELETED_RESTRICTED;
272 if ( (
$params[
'namespace'] !==
null || $title !==
null ) && $titleBits ) {
273 $this->
addWhere( $db->bitAnd(
'log_deleted', $titleBits ) .
" != $titleBits" );
275 if ( $user !==
null && $userBits ) {
276 $this->
addWhere( $db->bitAnd(
'log_deleted', $userBits ) .
" != $userBits" );
285 if (
$params[
'tag'] ===
null && $user ===
null ) {
290 'MAX_EXECUTION_TIME',
295 $res = $this->
select( __METHOD__ );
297 if ( $this->fld_title ) {
300 if ( $this->fld_parsedcomment ) {
301 $this->formattedComments = $this->commentFormatter->formatItems(
302 $this->commentFormatter->rows( $res )
303 ->commentKey(
'log_comment' )
304 ->indexField(
'log_id' )
305 ->namespaceField(
'log_namespace' )
306 ->titleField(
'log_title' )
311 foreach ( $res as $row ) {
312 if ( ++$count > $limit ) {
319 $vals = $this->extractRowInfo( $row );
320 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $vals );
326 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'item' );
329 private function extractRowInfo( $row ) {
336 if ( $this->fld_ids ) {
337 $vals[
'logid'] = (int)$row->log_id;
340 if ( $this->fld_title ) {
341 $title = Title::makeTitle( $row->log_namespace, $row->log_title );
345 if ( $this->fld_title || $this->fld_ids || ( $this->fld_details && $row->log_params !==
'' ) ) {
346 if ( LogEventsList::isDeleted( $row, LogPage::DELETED_ACTION ) ) {
347 $vals[
'actionhidden'] =
true;
350 if ( LogEventsList::userCan( $row, LogPage::DELETED_ACTION, $authority ) ) {
351 if ( $this->fld_title ) {
356 if ( $this->fld_ids ) {
357 $vals[
'pageid'] = (int)$row->page_id;
358 $vals[
'logpage'] = (int)$row->log_page;
359 $revId = $logEntry->getAssociatedRevId();
361 $vals[
'revid'] = (int)$revId;
364 if ( $this->fld_details ) {
365 $vals[
'params'] = $this->logFormatterFactory->newFromEntry( $logEntry )->formatParametersForApi();
370 if ( $this->fld_type ) {
371 $vals[
'type'] = $row->log_type;
372 $vals[
'action'] = $row->log_action;
375 if ( $this->fld_user || $this->fld_userid ) {
376 if ( LogEventsList::isDeleted( $row, LogPage::DELETED_USER ) ) {
377 $vals[
'userhidden'] =
true;
380 if ( LogEventsList::userCan( $row, LogPage::DELETED_USER, $authority ) ) {
381 if ( $this->fld_user ) {
382 $vals[
'user'] = $row->actor_name;
384 if ( $this->fld_userid ) {
385 $vals[
'userid'] = (int)$row->actor_user;
388 if ( isset( $vals[
'user'] ) && $this->userNameUtils->isTemp( $vals[
'user'] ) ) {
389 $vals[
'temp'] =
true;
392 if ( !$row->actor_user ) {
393 $vals[
'anon'] =
true;
397 if ( $this->fld_timestamp ) {
398 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->log_timestamp );
401 if ( $this->fld_comment || $this->fld_parsedcomment ) {
402 if ( LogEventsList::isDeleted( $row, LogPage::DELETED_COMMENT ) ) {
403 $vals[
'commenthidden'] =
true;
406 if ( LogEventsList::userCan( $row, LogPage::DELETED_COMMENT, $authority ) ) {
407 if ( $this->fld_comment ) {
408 $vals[
'comment'] = $this->commentStore->getComment(
'log_comment', $row )->text;
411 if ( $this->fld_parsedcomment ) {
413 $vals[
'parsedcomment'] = $this->formattedComments[$row->log_id];
418 if ( $this->fld_tags ) {
419 if ( $row->ts_tags ) {
420 $tags = explode(
',', $row->ts_tags );
422 $vals[
'tags'] = $tags;
428 if ( $anyHidden && LogEventsList::isDeleted( $row, LogPage::DELETED_RESTRICTED ) ) {
429 $vals[
'suppressed'] =
true;
438 private function getAllowedLogActions() {
440 return array_keys( array_merge(
450 if (
$params[
'prop'] !==
null && in_array(
'parsedcomment',
$params[
'prop'] ) ) {
452 return 'anon-public-user-private';
453 } elseif ( LogEventsList::getExcludeClause( $this->
getDB(),
'user', $this->
getAuthority() )
454 === LogEventsList::getExcludeClause( $this->
getDB(),
'public' )
458 return 'anon-public-user-private';
465 $logActions = $this->getAllowedLogActions();
472 ParamValidator::PARAM_ISMULTI =>
true,
473 ParamValidator::PARAM_DEFAULT =>
'ids|title|type|user|timestamp|comment|details',
474 ParamValidator::PARAM_TYPE => [
489 ParamValidator::PARAM_TYPE => LogPage::validTypes(),
493 ParamValidator::PARAM_TYPE => $logActions
496 ParamValidator::PARAM_TYPE =>
'timestamp'
499 ParamValidator::PARAM_TYPE =>
'timestamp'
502 ParamValidator::PARAM_DEFAULT =>
'older',
503 ParamValidator::PARAM_TYPE => [
509 'newer' =>
'api-help-paramvalue-direction-newer',
510 'older' =>
'api-help-paramvalue-direction-older',
514 ParamValidator::PARAM_TYPE =>
'user',
515 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
519 ParamValidator::PARAM_TYPE =>
'namespace',
525 ParamValidator::PARAM_DEFAULT => 10,
526 ParamValidator::PARAM_TYPE =>
'limit',
527 IntegerDef::PARAM_MIN => 1,
545 'action=query&list=logevents'
546 =>
'apihelp-query+logevents-example-simple',
551 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Logevents';
556class_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()