51 private $formattedComments;
69 parent::__construct( $query, $moduleName,
'le' );
70 $this->commentStore = $commentStore;
71 $this->commentFormatter = $commentFormatter;
72 $this->changeTagDefStore = $changeTagDefStore;
73 $this->userNameUtils = $userNameUtils;
76 private bool $fld_ids =
false;
77 private bool $fld_title =
false;
78 private bool $fld_type =
false;
79 private bool $fld_user =
false;
80 private bool $fld_userid =
false;
81 private bool $fld_timestamp =
false;
82 private bool $fld_comment =
false;
83 private bool $fld_parsedcomment =
false;
84 private bool $fld_details =
false;
85 private bool $fld_tags =
false;
92 $prop = array_fill_keys(
$params[
'prop'],
true );
94 $this->fld_ids = isset( $prop[
'ids'] );
95 $this->fld_title = isset( $prop[
'title'] );
96 $this->fld_type = isset( $prop[
'type'] );
97 $this->fld_user = isset( $prop[
'user'] );
98 $this->fld_userid = isset( $prop[
'userid'] );
99 $this->fld_timestamp = isset( $prop[
'timestamp'] );
100 $this->fld_comment = isset( $prop[
'comment'] );
101 $this->fld_parsedcomment = isset( $prop[
'parsedcomment'] );
102 $this->fld_details = isset( $prop[
'details'] );
103 $this->fld_tags = isset( $prop[
'tags'] );
105 $hideLogs = LogEventsList::getExcludeClause( $db,
'user', $this->
getAuthority() );
106 if ( $hideLogs !==
false ) {
121 if ( $this->fld_user || $this->fld_userid || $user !==
null ) {
124 'actor' => [
'JOIN',
'actor_id=log_actor' ],
126 $this->
addFieldsIf( [
'actor_name',
'actor_user' ], $this->fld_user );
127 $this->
addFieldsIf(
'actor_user', $this->fld_userid );
128 if ( $user !==
null ) {
133 if ( $this->fld_ids ) {
136 'page' => [
'LEFT JOIN',
137 [
'log_namespace=page_namespace',
138 'log_title=page_title' ] ]
143 $this->
addFields( [
'page_id',
'log_page' ] );
146 [
'log_namespace',
'log_title' ],
147 $this->fld_title || $this->fld_parsedcomment
149 $this->
addFieldsIf(
'log_params', $this->fld_details || $this->fld_ids );
151 if ( $this->fld_comment || $this->fld_parsedcomment ) {
152 $commentQuery = $this->commentStore->getJoin(
'log_comment' );
153 $this->
addTables( $commentQuery[
'tables'] );
154 $this->
addFields( $commentQuery[
'fields'] );
158 if ( $this->fld_tags ) {
162 if (
$params[
'tag'] !==
null ) {
165 [
'log_id=ct_log_id' ] ] ] );
174 if (
$params[
'action'] !==
null ) {
177 $logAction =
$params[
'action'];
178 if ( !str_contains( $logAction,
'/' ) ) {
182 $logActions = array_fill_keys( $this->getAllowedLogActions(),
true );
183 [ $type, $action ] = explode(
'/', $logAction, 2 );
184 $valid = isset( $logActions[$logAction] ) || isset( $logActions[$type .
'/*'] );
190 [
'apierror-unrecognizedvalue', $encParamName,
wfEscapeWikiText( $logAction ) ],
191 "unknown_$encParamName"
199 } elseif (
$params[
'type'] !==
null ) {
212 if (
$params[
'continue'] !==
null ) {
214 $op = (
$params[
'dir'] ===
'newer' ?
'>=' :
'<=' );
215 $this->
addWhere( $db->buildComparison( $op, [
216 'log_timestamp' => $db->timestamp( $cont[0] ),
217 'log_id' => $cont[1],
225 if ( $title !==
null ) {
226 $titleObj = Title::newFromText( $title );
227 if ( $titleObj ===
null || $titleObj->isExternal() ) {
230 $this->
addWhereFld(
'log_namespace', $titleObj->getNamespace() );
231 $this->
addWhereFld(
'log_title', $titleObj->getDBkey() );
234 if (
$params[
'namespace'] !==
null ) {
240 if ( $prefix !==
null ) {
241 if ( $this->
getConfig()->
get( MainConfigNames::MiserMode ) ) {
245 $title = Title::newFromText( $prefix );
246 if ( $title ===
null || $title->isExternal() ) {
249 $this->
addWhereFld(
'log_namespace', $title->getNamespace() );
251 $db->expr(
'log_title', IExpression::LIKE,
new LikeValue( $title->getDBkey(), $db->anyString() ) )
256 if (
$params[
'namespace'] !==
null || $title !==
null || $user !==
null ) {
257 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
258 $titleBits = LogPage::DELETED_ACTION;
259 $userBits = LogPage::DELETED_USER;
260 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
261 $titleBits = LogPage::DELETED_ACTION | LogPage::DELETED_RESTRICTED;
262 $userBits = LogPage::DELETED_USER | LogPage::DELETED_RESTRICTED;
267 if ( (
$params[
'namespace'] !==
null || $title !==
null ) && $titleBits ) {
268 $this->
addWhere( $db->bitAnd(
'log_deleted', $titleBits ) .
" != $titleBits" );
270 if ( $user !==
null && $userBits ) {
271 $this->
addWhere( $db->bitAnd(
'log_deleted', $userBits ) .
" != $userBits" );
280 if (
$params[
'tag'] ===
null && $user ===
null ) {
285 'MAX_EXECUTION_TIME',
286 $this->
getConfig()->
get( MainConfigNames::MaxExecutionTimeForExpensiveQueries )
290 $res = $this->
select( __METHOD__ );
292 if ( $this->fld_title ) {
295 if ( $this->fld_parsedcomment ) {
296 $this->formattedComments = $this->commentFormatter->formatItems(
297 $this->commentFormatter->rows( $res )
298 ->commentKey(
'log_comment' )
299 ->indexField(
'log_id' )
300 ->namespaceField(
'log_namespace' )
301 ->titleField(
'log_title' )
306 foreach ( $res as $row ) {
307 if ( ++$count > $limit ) {
314 $vals = $this->extractRowInfo( $row );
315 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $vals );
321 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'item' );
324 private function extractRowInfo( $row ) {
325 $logEntry = DatabaseLogEntry::newFromRow( $row );
327 ApiResult::META_TYPE =>
'assoc',
331 if ( $this->fld_ids ) {
332 $vals[
'logid'] = (int)$row->log_id;
335 if ( $this->fld_title ) {
336 $title = Title::makeTitle( $row->log_namespace, $row->log_title );
340 if ( $this->fld_title || $this->fld_ids || ( $this->fld_details && $row->log_params !==
'' ) ) {
341 if ( LogEventsList::isDeleted( $row, LogPage::DELETED_ACTION ) ) {
342 $vals[
'actionhidden'] =
true;
345 if ( LogEventsList::userCan( $row, LogPage::DELETED_ACTION, $authority ) ) {
346 if ( $this->fld_title ) {
351 if ( $this->fld_ids ) {
352 $vals[
'pageid'] = (int)$row->page_id;
353 $vals[
'logpage'] = (int)$row->log_page;
354 $revId = $logEntry->getAssociatedRevId();
356 $vals[
'revid'] = (int)$revId;
359 if ( $this->fld_details ) {
365 if ( $this->fld_type ) {
366 $vals[
'type'] = $row->log_type;
367 $vals[
'action'] = $row->log_action;
370 if ( $this->fld_user || $this->fld_userid ) {
371 if ( LogEventsList::isDeleted( $row, LogPage::DELETED_USER ) ) {
372 $vals[
'userhidden'] =
true;
375 if ( LogEventsList::userCan( $row, LogPage::DELETED_USER, $authority ) ) {
376 if ( $this->fld_user ) {
377 $vals[
'user'] = $row->actor_name;
379 if ( $this->fld_userid ) {
380 $vals[
'userid'] = (int)$row->actor_user;
383 if ( isset( $vals[
'user'] ) && $this->userNameUtils->isTemp( $vals[
'user'] ) ) {
384 $vals[
'temp'] =
true;
387 if ( !$row->actor_user ) {
388 $vals[
'anon'] =
true;
392 if ( $this->fld_timestamp ) {
393 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->log_timestamp );
396 if ( $this->fld_comment || $this->fld_parsedcomment ) {
397 if ( LogEventsList::isDeleted( $row, LogPage::DELETED_COMMENT ) ) {
398 $vals[
'commenthidden'] =
true;
401 if ( LogEventsList::userCan( $row, LogPage::DELETED_COMMENT, $authority ) ) {
402 if ( $this->fld_comment ) {
403 $vals[
'comment'] = $this->commentStore->getComment(
'log_comment', $row )->text;
406 if ( $this->fld_parsedcomment ) {
408 $vals[
'parsedcomment'] = $this->formattedComments[$row->log_id];
413 if ( $this->fld_tags ) {
414 if ( $row->ts_tags ) {
415 $tags = explode(
',', $row->ts_tags );
417 $vals[
'tags'] = $tags;
423 if ( $anyHidden && LogEventsList::isDeleted( $row, LogPage::DELETED_RESTRICTED ) ) {
424 $vals[
'suppressed'] =
true;
433 private function getAllowedLogActions() {
435 return array_keys( array_merge(
436 $config->get( MainConfigNames::LogActions ),
437 $config->get( MainConfigNames::LogActionsHandlers )
445 if (
$params[
'prop'] !==
null && in_array(
'parsedcomment',
$params[
'prop'] ) ) {
447 return 'anon-public-user-private';
448 } elseif ( LogEventsList::getExcludeClause( $this->
getDB(),
'user', $this->
getAuthority() )
449 === LogEventsList::getExcludeClause( $this->
getDB(),
'public' )
453 return 'anon-public-user-private';
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 =>
'user',
510 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
514 ParamValidator::PARAM_TYPE =>
'namespace',
520 ParamValidator::PARAM_DEFAULT => 10,
521 ParamValidator::PARAM_TYPE =>
'limit',
522 IntegerDef::PARAM_MIN => 1,
531 if ( $config->get( MainConfigNames::MiserMode ) ) {
540 'action=query&list=logevents'
541 =>
'apihelp-query+logevents-example-simple',
546 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Logevents';
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.
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.
parseContinueParamOrDie(string $continue, array $types)
Parse the 'continue' parameter in the usual format and validate the types of each part,...
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, or 'string' with PARAM_ISMULTI,...
const LIMIT_BIG1
Fast query, standard limit.
requireMaxOneParameter( $params,... $required)
Dies if more than one parameter from a certain set of parameters are 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 this is set, the result could take longer to generate,...
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.
__construct(ApiQuery $query, $moduleName, CommentStore $commentStore, RowCommentFormatter $commentFormatter, NameTableStore $changeTagDefStore, UserNameUtils $userNameUtils)
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
getAllowedParams( $flags=0)
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.
A class containing constants representing the names of configuration variables.