48 private $performer =
'';
54 private $pattern =
false;
57 private $typeCGI =
'';
63 private $performerRestrictionsEnforced =
false;
66 private $actionRestrictionsEnforced =
false;
81 private $linkBatchFactory;
84 private $actorNormalization;
103 public function __construct( $list, $types = [], $performer =
'', $page =
'',
104 $pattern =
false, $conds = [], $year =
false, $month =
false, $day =
false,
105 $tagFilter =
'', $action =
'', $logId = 0,
110 parent::__construct( $list->getContext() );
113 $this->mConds = $conds;
114 $this->mLogEventsList = $list;
117 $this->linkBatchFactory = $linkBatchFactory ?? $services->getLinkBatchFactory();
118 $this->actorNormalization = $actorNormalization ?? $services->getActorNormalization();
121 $this->limitType( $types );
122 $this->limitFilterTypes();
123 $this->limitPerformer( $performer );
124 $this->limitTitle( $page, $pattern );
125 $this->limitAction( $action );
127 $this->mTagFilter = (string)$tagFilter;
128 $this->mTagInvert = (bool)$tagInvert;
132 $query = parent::getDefaultQuery();
133 $query[
'type'] = $this->typeCGI;
134 $query[
'user'] = $this->performer;
142 private function limitFilterTypes() {
147 foreach ( $filterTypes as $type => $hide ) {
149 $this->mConds[] =
'log_type != ' . $this->mDb->addQuotes( $type );
156 if ( count( $this->types ) ) {
161 $wpfilters = $this->
getRequest()->getArray(
"wpfilters" );
164 foreach ( $filterLogTypes as $type => $default ) {
166 if ( $wpfilters ===
null ) {
167 $hide = $this->
getRequest()->getBool(
"hide_{$type}_log", $default );
169 $hide = !in_array( $type, $wpfilters );
172 $filters[$type] = $hide;
185 private function limitType( $types ) {
188 $types = ( $types ===
'' ) ? [] : (array)$types;
190 $needReindex =
false;
191 foreach ( $types as $type ) {
192 if ( isset( $restrictions[$type] )
193 && !$this->
getAuthority()->isAllowed( $restrictions[$type] )
196 $types = array_diff( $types, [ $type ] );
199 if ( $needReindex ) {
202 $types = array_values( $types );
204 $this->types = $types;
210 $audience = ( $types || $this->
hasEqualsClause(
'log_id' ) ) ?
'user' :
'public';
212 if ( $hideLogs !==
false ) {
213 $this->mConds[] = $hideLogs;
215 if ( count( $types ) ) {
216 $this->mConds[
'log_type'] = $types;
218 if ( count( $types ) == 1 ) {
219 $this->typeCGI = $types[0];
230 private function limitPerformer( $name ) {
235 $actorId = $this->actorNormalization->findActorIdByName( $name, $this->mDb );
239 $this->mConds[] =
'1 = 0';
243 $this->mConds[
'log_actor' ] = $actorId;
245 $this->enforcePerformerRestrictions();
247 $this->performer = $name;
258 private function limitTitle( $page, $pattern ) {
259 if ( !$page instanceof PageReference ) {
268 $this->page = $titleFormatter->getPrefixedDBkey( $page );
269 $ns = $page->getNamespace();
274 $doUserRightsLogLike =
false;
275 if ( $this->types == [
'rights' ] ) {
276 $parts = explode( $interwikiDelimiter, $page->getDBkey() );
277 if ( count( $parts ) == 2 ) {
278 [ $name, $database ] = array_map(
'trim', $parts );
279 if ( strstr( $database,
'*' ) ) {
280 $doUserRightsLogLike =
true;
298 $this->mConds[
'log_namespace'] = $ns;
299 if ( $doUserRightsLogLike ) {
301 $params = [ $name . $interwikiDelimiter ];
304 $databaseParts = explode(
'*', $database );
305 $databasePartCount = count( $databaseParts );
306 foreach ( $databaseParts as $i => $databasepart ) {
307 $params[] = $databasepart;
308 if ( $i < $databasePartCount - 1 ) {
309 $params[] = $db->anyString();
312 $this->mConds[] =
'log_title' . $db->buildLike( ...$params );
314 $this->mConds[] =
'log_title' . $db->buildLike( $page->getDBkey(), $db->anyString() );
315 $this->pattern = $pattern;
317 $this->mConds[
'log_title'] = $page->getDBkey();
319 $this->enforceActionRestrictions();
327 private function limitAction( $action ) {
329 $type = $this->typeCGI;
330 if ( $type ===
'' ) {
335 if ( isset( $actions[$type] ) ) {
337 if ( $action !==
'' && isset( $actions[$type][$action] ) ) {
339 $this->mConds[
'log_action'] = $actions[$type][$action];
340 $this->action = $action;
353 $this->mConds[
'log_id'] = $logId;
364 $tables = $basic[
'tables'];
365 $fields = $basic[
'fields'];
366 $conds = $basic[
'conds'];
367 $options = $basic[
'options'];
368 $joins = $basic[
'join_conds'];
370 # Add log_search table if there are conditions on it.
371 # This filters the results to only include log rows that have
372 # log_search records with the specified ls_field and ls_value values.
373 if ( array_key_exists(
'ls_field', $this->mConds ) ) {
374 $tables[] =
'log_search';
375 $options[
'IGNORE INDEX'] = [
'log_search' =>
'ls_log_id' ];
376 $options[
'USE INDEX'] = [
'logging' =>
'PRIMARY' ];
380 # Since (ls_field,ls_value,ls_logid) is unique, if the condition is
381 # to match a specific (ls_field,ls_value) tuple, then there will be
382 # no duplicate log rows. Otherwise, we need to remove the duplicates.
383 $options[] =
'DISTINCT';
385 } elseif ( array_key_exists(
'log_actor', $this->mConds ) ) {
387 $index =
'log_actor_time';
390 $index =
'log_actor_type_time';
394 $options[
'USE INDEX'] = [
'logging' => $index ];
396 # Don't show duplicate rows when using log_search
397 $joins[
'log_search'] = [
'JOIN',
'ls_log_id=log_id' ];
403 if ( $this->mTagFilter ===
'' && !array_key_exists(
'ls_field', $this->mConds ) ) {
404 $options[] =
'STRAIGHT_JOIN';
407 $options[
'MAX_EXECUTION_TIME'] = $this->
getConfig()
413 'conds' => array_merge( $conds, $this->mConds ),
414 'options' => $options,
415 'join_conds' => $joins,
417 # Add ChangeTags filter query
419 $info[
'join_conds'], $info[
'options'], $this->mTagFilter, $this->mTagInvert );
431 array_key_exists( $field, $this->mConds ) &&
432 ( !is_array( $this->mConds[$field] ) || count( $this->mConds[$field] ) == 1 )
437 return [ [
'log_timestamp',
'log_id' ] ];
441 $lb = $this->linkBatchFactory->newLinkBatch();
442 foreach ( $this->mResult as $row ) {
443 $lb->add( $row->log_namespace, $row->log_title );
444 $lb->add(
NS_USER, $row->log_user_text );
447 foreach ( $formatter->getPreloadTitles() as $title ) {
448 $lb->addObj( $title );
455 return $this->mLogEventsList->logLine( $row );
468 return $this->performer;
482 return $this->pattern;
498 return $this->mTagFilter;
502 return $this->mTagInvert;
506 return $this->action;
512 private function enforceActionRestrictions() {
513 if ( $this->actionRestrictionsEnforced ) {
516 $this->actionRestrictionsEnforced =
true;
517 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
519 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
528 private function enforcePerformerRestrictions() {
530 if ( $this->performerRestrictionsEnforced ) {
533 $this->performerRestrictionsEnforced =
true;
534 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
536 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
547 class_alias( LogPager::class,
'LogPager' );
A value class to process existing log entries.
static getSelectQueryData()
Returns array of information that is needed for querying log entries.
static getExcludeClause( $db, $audience='public', Authority $performer=null)
SQL clause to skip forbidden log types for this user.
Class to simplify the use of log pages.
A class containing constants representing the names of configuration variables.
const LogRestrictions
Name constant for the LogRestrictions setting, for use with Config::get()
const ActionFilteredLogs
Name constant for the ActionFilteredLogs setting, for use with Config::get()
const MaxExecutionTimeForExpensiveQueries
Name constant for the MaxExecutionTimeForExpensiveQueries setting, for use with Config::get()
const FilterLogTypes
Name constant for the FilterLogTypes setting, for use with Config::get()
const UserrightsInterwikiDelimiter
Name constant for the UserrightsInterwikiDelimiter setting, for use with Config::get()
const MiserMode
Name constant for the MiserMode setting, for use with Config::get()