41 private $performer =
'';
47 private $pattern =
false;
50 private $typeCGI =
'';
56 private $performerRestrictionsEnforced =
false;
59 private $actionRestrictionsEnforced =
false;
71 private $linkBatchFactory;
74 private $actorNormalization;
93 public function __construct( $list, $types = [], $performer =
'', $page =
'',
94 $pattern =
false, $conds = [], $year =
false, $month =
false, $day =
false,
95 $tagFilter =
'', $action =
'', $logId = 0,
100 $services = MediaWikiServices::getInstance();
102 $this->mDb = ( $loadBalancer ?? $services->getDBLoadBalancer() )
103 ->getConnectionRef( ILoadBalancer::DB_REPLICA,
'logpager' );
104 parent::__construct( $list->getContext() );
105 $this->mConds = $conds;
107 $this->mLogEventsList = $list;
110 $this->linkBatchFactory = $linkBatchFactory ?? $services->getLinkBatchFactory();
111 $this->actorNormalization = $actorNormalization ?? $services->getActorNormalization();
114 $this->limitType( $types );
115 $this->limitFilterTypes();
116 $this->limitPerformer( $performer );
117 $this->limitTitle( $page, $pattern );
118 $this->limitAction( $action );
120 $this->mTagFilter = (string)$tagFilter;
124 $query = parent::getDefaultQuery();
125 $query[
'type'] = $this->typeCGI;
126 $query[
'user'] = $this->performer;
134 private function limitFilterTypes() {
139 foreach ( $filterTypes as
$type => $hide ) {
141 $this->mConds[] =
'log_type != ' . $this->mDb->addQuotes(
$type );
148 if ( count( $this->types ) ) {
152 $wpfilters = $this->
getRequest()->getArray(
"wpfilters" );
153 $filterLogTypes = $this->
getConfig()->get( MainConfigNames::FilterLogTypes );
155 foreach ( $filterLogTypes as
$type => $default ) {
157 if ( $wpfilters ===
null ) {
158 $hide = $this->
getRequest()->getBool(
"hide_{$type}_log", $default );
160 $hide = !in_array(
$type, $wpfilters );
163 $filters[
$type] = $hide;
176 private function limitType( $types ) {
177 $restrictions = $this->
getConfig()->get( MainConfigNames::LogRestrictions );
179 $types = ( $types ===
'' ) ? [] : (array)$types;
181 $needReindex =
false;
182 foreach ( $types as
$type ) {
183 if ( isset( $restrictions[
$type] )
187 $types = array_diff( $types, [
$type ] );
190 if ( $needReindex ) {
193 $types = array_values( $types );
195 $this->types = $types;
201 $audience = ( $types || $this->
hasEqualsClause(
'log_id' ) ) ?
'user' :
'public';
203 if ( $hideLogs !==
false ) {
204 $this->mConds[] = $hideLogs;
206 if ( count( $types ) ) {
207 $this->mConds[
'log_type'] = $types;
209 if ( count( $types ) == 1 ) {
210 $this->typeCGI = $types[0];
221 private function limitPerformer( $name ) {
226 $actorId = $this->actorNormalization->findActorIdByName( $name, $this->mDb );
230 $this->mConds[] =
'1 = 0';
234 $this->mConds[
'log_actor' ] = $actorId;
236 $this->enforcePerformerRestrictions();
238 $this->performer = $name;
249 private function limitTitle( $page, $pattern ) {
258 $titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter();
259 $this->page = $titleFormatter->getPrefixedDBkey( $page );
260 $ns = $page->getNamespace();
263 $interwikiDelimiter = $this->
getConfig()->get( MainConfigNames::UserrightsInterwikiDelimiter );
265 $doUserRightsLogLike =
false;
266 if ( $this->types == [
'rights' ] ) {
267 $parts = explode( $interwikiDelimiter, $page->getDBkey() );
268 if ( count( $parts ) == 2 ) {
269 list( $name, $database ) = array_map(
'trim', $parts );
270 if ( strstr( $database,
'*' ) ) {
271 $doUserRightsLogLike =
true;
289 $this->mConds[
'log_namespace'] = $ns;
290 if ( $doUserRightsLogLike ) {
292 $params = [ $name . $interwikiDelimiter ];
295 $databaseParts = explode(
'*', $database );
296 $databasePartCount = count( $databaseParts );
297 foreach ( $databaseParts as $i => $databasepart ) {
298 $params[] = $databasepart;
299 if ( $i < $databasePartCount - 1 ) {
300 $params[] = $db->anyString();
303 $this->mConds[] =
'log_title' . $db->buildLike( ...$params );
304 } elseif ( $pattern && !$this->
getConfig()->
get( MainConfigNames::MiserMode ) ) {
305 $this->mConds[] =
'log_title' . $db->buildLike( $page->getDBkey(), $db->anyString() );
306 $this->pattern = $pattern;
308 $this->mConds[
'log_title'] = $page->getDBkey();
310 $this->enforceActionRestrictions();
318 private function limitAction( $action ) {
320 $type = $this->typeCGI;
321 if (
$type ===
'' ) {
325 $actions = $this->
getConfig()->get( MainConfigNames::ActionFilteredLogs );
326 if ( isset( $actions[
$type] ) ) {
328 $this->mLogEventsList->setAllowedActions( array_keys( $actions[
$type] ) );
329 if ( $action !==
'' && isset( $actions[
$type][$action] ) ) {
331 $this->mConds[
'log_action'] = $actions[
$type][$action];
332 $this->action = $action;
345 $this->mConds[
'log_id'] = $logId;
354 $basic = DatabaseLogEntry::getSelectQueryData();
356 $tables = $basic[
'tables'];
357 $fields = $basic[
'fields'];
358 $conds = $basic[
'conds'];
359 $options = $basic[
'options'];
360 $joins = $basic[
'join_conds'];
362 # Add log_search table if there are conditions on it.
363 # This filters the results to only include log rows that have
364 # log_search records with the specified ls_field and ls_value values.
365 if ( array_key_exists(
'ls_field', $this->mConds ) ) {
366 $tables[] =
'log_search';
367 $options[
'IGNORE INDEX'] = [
'log_search' =>
'ls_log_id' ];
368 $options[
'USE INDEX'] = [
'logging' =>
'PRIMARY' ];
372 # Since (ls_field,ls_value,ls_logid) is unique, if the condition is
373 # to match a specific (ls_field,ls_value) tuple, then there will be
374 # no duplicate log rows. Otherwise, we need to remove the duplicates.
375 $options[] =
'DISTINCT';
377 } elseif ( array_key_exists(
'log_actor', $this->mConds ) ) {
379 $index =
'log_actor_time';
382 $index =
'log_actor_type_time';
386 $options[
'USE INDEX'] = [
'logging' => $index ];
388 # Don't show duplicate rows when using log_search
389 $joins[
'log_search'] = [
'JOIN',
'ls_log_id=log_id' ];
395 if ( $this->mTagFilter ===
'' && !array_key_exists(
'ls_field', $this->mConds ) ) {
396 $options[] =
'STRAIGHT_JOIN';
399 $options[
'MAX_EXECUTION_TIME'] = $this->
getConfig()
400 ->get( MainConfigNames::MaxExecutionTimeForExpensiveQueries );
405 'conds' => array_merge( $conds, $this->mConds ),
406 'options' => $options,
407 'join_conds' => $joins,
409 # Add ChangeTags filter query
411 $info[
'join_conds'], $info[
'options'], $this->mTagFilter );
423 array_key_exists( $field, $this->mConds ) &&
424 ( !is_array( $this->mConds[$field] ) || count( $this->mConds[$field] ) == 1 )
429 return 'log_timestamp';
433 # Do a link batch query
435 $lb = $this->linkBatchFactory->newLinkBatch();
436 foreach ( $this->mResult as $row ) {
437 $lb->add( $row->log_namespace, $row->log_title );
438 $lb->add(
NS_USER, $row->log_user_text );
440 $formatter = LogFormatter::newFromRow( $row );
441 foreach ( $formatter->getPreloadTitles() as
$title ) {
446 $this->mResult->seek( 0 );
453 return $this->mLogEventsList->logLine( $row );
466 return $this->performer;
480 return $this->pattern;
496 return $this->mTagFilter;
500 return $this->action;
505 $this->mDb->setBigSelects();
507 $this->mDb->setBigSelects(
'default' );
513 private function enforceActionRestrictions() {
514 if ( $this->actionRestrictionsEnforced ) {
517 $this->actionRestrictionsEnforced =
true;
518 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
520 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
529 private function enforcePerformerRestrictions() {
531 if ( $this->performerRestrictionsEnforced ) {
534 $this->performerRestrictionsEnforced =
true;
535 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
537 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {