38 private $performer =
'';
47 private $pattern =
false;
50 private $typeCGI =
'';
56 private $performerRestrictionsEnforced =
false;
59 private $actionRestrictionsEnforced =
false;
74 private $linkBatchFactory;
77 private $actorNormalization;
98 public function __construct( $list, $types = [], $performer =
'', $pages =
'',
99 $pattern =
false, $conds = [], $year =
false, $month =
false, $day =
false,
100 $tagFilter =
'', $action =
'', $logId = 0,
106 parent::__construct( $list->getContext() );
109 $this->mConds = $conds;
110 $this->mLogEventsList = $list;
113 $this->linkBatchFactory = $linkBatchFactory ?? $services->getLinkBatchFactory();
114 $this->actorNormalization = $actorNormalization ?? $services->getActorNormalization();
115 $this->logFormatterFactory = $logFormatterFactory ?? $services->getLogFormatterFactory();
118 $this->limitType( $types );
119 $this->limitFilterTypes();
120 $this->limitPerformer( $performer );
121 $this->limitTitles( $pages, $pattern );
122 $this->limitAction( $action );
124 $this->mTagFilter = (string)$tagFilter;
125 $this->mTagInvert = (bool)$tagInvert;
130 $query = parent::getDefaultQuery();
131 $query[
'type'] = $this->typeCGI;
132 $query[
'user'] = $this->performer;
140 private function limitFilterTypes() {
146 foreach ( $filterTypes as $type => $hide ) {
148 $excludeTypes[] = $type;
151 if ( $excludeTypes ) {
152 $this->mConds[] = $this->mDb->expr(
'log_type',
'!=', $excludeTypes );
158 if ( count( $this->types ) ) {
163 $wpfilters = $this->
getRequest()->getArray(
"wpfilters" );
166 foreach ( $filterLogTypes as $type => $default ) {
168 if ( $wpfilters ===
null ) {
169 $hide = $this->
getRequest()->getBool(
"hide_{$type}_log", $default );
171 $hide = !in_array( $type, $wpfilters );
174 $filters[$type] = $hide;
187 private function limitType( $types ) {
190 $types = ( $types ===
'' ) ? [] : (array)$types;
192 $needReindex =
false;
193 foreach ( $types as $type ) {
194 if ( isset( $restrictions[$type] )
195 && !$this->
getAuthority()->isAllowed( $restrictions[$type] )
198 $types = array_diff( $types, [ $type ] );
201 if ( $needReindex ) {
204 $types = array_values( $types );
206 $this->types = $types;
212 $audience = ( $types || $this->hasEqualsClause(
'log_id' ) ) ?
'user' :
'public';
214 if ( $hideLogs !==
false ) {
215 $this->mConds[] = $hideLogs;
217 if ( count( $types ) ) {
218 $this->mConds[
'log_type'] = $types;
220 if ( count( $types ) == 1 ) {
221 $this->typeCGI = $types[0];
232 private function limitPerformer( $name ) {
237 $actorId = $this->actorNormalization->findActorIdByName( $name, $this->mDb );
241 $this->mConds[] =
'1 = 0';
245 $this->mConds[
'log_actor' ] = $actorId;
247 $this->enforcePerformerRestrictions();
249 $this->performer = $name;
260 private function limitTitles( $pages, $pattern ) {
261 if ( !is_array( $pages ) ) {
266 foreach ( $pages as $page ) {
267 if ( (
string)$page ===
'' ) {
270 if ( !$page instanceof PageReference ) {
272 $page = Title::newFromText( $page );
278 $this->page = $titleFormatter->getPrefixedDBkey( $page );
279 $orConds[] = $this->mDb->makeList(
280 $this->getTitleConds( $page, $pattern ),
281 ISQLPlatform::LIST_AND
285 $this->mConds[] = $this->mDb->makeList( $orConds, ISQLPlatform::LIST_OR );
286 $this->pattern = $pattern;
287 $this->enforceActionRestrictions();
298 private function getTitleConds( $page, $pattern ) {
300 $ns = $page->getNamespace();
305 $doUserRightsLogLike =
false;
306 if ( $this->types == [
'rights' ] ) {
307 $parts = explode( $interwikiDelimiter, $page->getDBkey() );
308 if ( count( $parts ) == 2 ) {
309 [ $name, $database ] = array_map(
'trim', $parts );
310 if ( str_contains( $database,
'*' ) ) {
311 $doUserRightsLogLike =
true;
329 $conds[
'log_namespace'] = $ns;
330 if ( $doUserRightsLogLike ) {
332 $params = [ $name . $interwikiDelimiter ];
335 $databaseParts = explode(
'*', $database );
336 $databasePartCount = count( $databaseParts );
337 foreach ( $databaseParts as $i => $databasepart ) {
339 if ( $i < $databasePartCount - 1 ) {
343 $conds[] = $db->expr(
'log_title', IExpression::LIKE,
new LikeValue( ...$params ) );
344 } elseif ( $pattern ) {
345 $conds[] = $db->expr(
348 new LikeValue( $page->getDBkey(), $db->anyString() )
351 $conds[
'log_title'] = $page->getDBkey();
361 private function limitAction( $action ) {
363 $type = $this->typeCGI;
364 if ( $type ===
'' ) {
369 if ( isset( $actions[$type] ) ) {
371 if ( $action !==
'' && isset( $actions[$type][$action] ) ) {
373 $this->mConds[
'log_action'] = $actions[$type][$action];
374 $this->action = $action;
387 $this->mConds[
'log_id'] = $logId;
397 ->where( $this->mConds );
399 # Add log_search table if there are conditions on it.
400 # This filters the results to only include log rows that have
401 # log_search records with the specified ls_field and ls_value values.
402 if ( array_key_exists(
'ls_field', $this->mConds ) ) {
403 $queryBuilder->join(
'log_search',
null,
'ls_log_id=log_id' );
404 $queryBuilder->ignoreIndex( [
'log_search' =>
'ls_log_id' ] );
405 $queryBuilder->useIndex( [
'logging' =>
'PRIMARY' ] );
406 if ( !$this->hasEqualsClause(
'ls_field' )
407 || !$this->hasEqualsClause(
'ls_value' )
409 # Since (ls_field,ls_value,ls_logid) is unique, if the condition is
410 # to match a specific (ls_field,ls_value) tuple, then there will be
411 # no duplicate log rows. Otherwise, we need to remove the duplicates.
412 $queryBuilder->distinct();
414 } elseif ( array_key_exists(
'log_actor', $this->mConds ) ) {
416 $index =
'log_actor_time';
417 foreach ( $this->getFilterParams() as $hide ) {
419 $index =
'log_actor_type_time';
423 $queryBuilder->useIndex( [
'logging' => $index ] );
430 if ( $this->mTagFilter ===
'' && !array_key_exists(
'ls_field', $this->mConds ) ) {
431 $queryBuilder->straightJoinOption();
435 if ( $maxExecTime ) {
436 $queryBuilder->setMaxExecutionTime( $maxExecTime );
439 # Add ChangeTags filter query
447 return $queryBuilder->getQueryInfo();
457 array_key_exists( $field, $this->mConds ) &&
458 ( !is_array( $this->mConds[$field] ) || count( $this->mConds[$field] ) == 1 )
464 return [ [
'log_timestamp',
'log_id' ] ];
468 $lb = $this->linkBatchFactory->newLinkBatch()->setCaller( __METHOD__ );
469 foreach ( $this->mResult as $row ) {
470 $lb->add( $row->log_namespace, $row->log_title );
471 $lb->addUser(
new UserIdentityValue( (
int)$row->log_user, $row->log_user_text ) );
472 $formatter = $this->logFormatterFactory->newFromRow( $row );
473 foreach ( $formatter->getPreloadTitles() as $title ) {
474 $lb->addObj( $title );
482 return $this->mLogEventsList->logLine( $row );
500 return $this->performer;
518 return $this->pattern;
536 return $this->mMonth;
553 return $this->mTagFilter;
562 return $this->mTagInvert;
571 return $this->action;
577 private function enforceActionRestrictions() {
578 if ( $this->actionRestrictionsEnforced ) {
581 $this->actionRestrictionsEnforced =
true;
582 if ( !$this->getAuthority()->isAllowed(
'deletedhistory' ) ) {
584 } elseif ( !$this->getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
593 private function enforcePerformerRestrictions() {
595 if ( $this->performerRestrictionsEnforced ) {
598 $this->performerRestrictionsEnforced =
true;
599 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
601 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {