MediaWiki REL1_31
LogPager.php
Go to the documentation of this file.
1<?php
31 private $types = [];
32
34 private $performer = '';
35
37 private $title = '';
38
40 private $pattern = '';
41
43 private $typeCGI = '';
44
46 private $action = '';
47
50
53
56
70 public function __construct( $list, $types = [], $performer = '', $title = '',
71 $pattern = '', $conds = [], $year = false, $month = false, $tagFilter = '',
72 $action = '', $logId = false
73 ) {
74 parent::__construct( $list->getContext() );
75 $this->mConds = $conds;
76
77 $this->mLogEventsList = $list;
78
79 $this->limitType( $types ); // also excludes hidden types
80 $this->limitPerformer( $performer );
81 $this->limitTitle( $title, $pattern );
82 $this->limitAction( $action );
83 $this->getDateCond( $year, $month );
84 $this->mTagFilter = $tagFilter;
85 $this->limitLogId( $logId );
86
87 $this->mDb = wfGetDB( DB_REPLICA, 'logpager' );
88 }
89
90 public function getDefaultQuery() {
91 $query = parent::getDefaultQuery();
92 $query['type'] = $this->typeCGI; // arrays won't work here
93 $query['user'] = $this->performer;
94 $query['month'] = $this->mMonth;
95 $query['year'] = $this->mYear;
96
97 return $query;
98 }
99
100 // Call ONLY after calling $this->limitType() already!
101 public function getFilterParams() {
103 $filters = [];
104 if ( count( $this->types ) ) {
105 return $filters;
106 }
107 foreach ( $wgFilterLogTypes as $type => $default ) {
108 $hide = $this->getRequest()->getInt( "hide_{$type}_log", $default );
109
110 $filters[$type] = $hide;
111 if ( $hide ) {
112 $this->mConds[] = 'log_type != ' . $this->mDb->addQuotes( $type );
113 }
114 }
115
116 return $filters;
117 }
118
126 private function limitType( $types ) {
128
129 $user = $this->getUser();
130 // If $types is not an array, make it an array
131 $types = ( $types === '' ) ? [] : (array)$types;
132 // Don't even show header for private logs; don't recognize it...
133 $needReindex = false;
134 foreach ( $types as $type ) {
135 if ( isset( $wgLogRestrictions[$type] )
136 && !$user->isAllowed( $wgLogRestrictions[$type] )
137 ) {
138 $needReindex = true;
139 $types = array_diff( $types, [ $type ] );
140 }
141 }
142 if ( $needReindex ) {
143 // Lots of this code makes assumptions that
144 // the first entry in the array is $types[0].
145 $types = array_values( $types );
146 }
147 $this->types = $types;
148 // Don't show private logs to unprivileged users.
149 // Also, only show them upon specific request to avoid suprises.
150 $audience = $types ? 'user' : 'public';
151 $hideLogs = LogEventsList::getExcludeClause( $this->mDb, $audience, $user );
152 if ( $hideLogs !== false ) {
153 $this->mConds[] = $hideLogs;
154 }
155 if ( count( $types ) ) {
156 $this->mConds['log_type'] = $types;
157 // Set typeCGI; used in url param for paging
158 if ( count( $types ) == 1 ) {
159 $this->typeCGI = $types[0];
160 }
161 }
162 }
163
170 private function limitPerformer( $name ) {
171 if ( $name == '' ) {
172 return;
173 }
174 $usertitle = Title::makeTitleSafe( NS_USER, $name );
175 if ( is_null( $usertitle ) ) {
176 return;
177 }
178 // Normalize username first so that non-existent users used
179 // in maintenance scripts work
180 $name = $usertitle->getText();
181
182 // Assume no joins required for log_user
183 $this->mConds[] = ActorMigration::newMigration()->getWhere(
184 wfGetDB( DB_REPLICA ), 'log_user', User::newFromName( $name, false )
185 )['conds'];
186
188
189 $this->performer = $name;
190 }
191
200 private function limitTitle( $page, $pattern ) {
202
203 if ( $page instanceof Title ) {
204 $title = $page;
205 } else {
206 $title = Title::newFromText( $page );
207 if ( strlen( $page ) == 0 || !$title instanceof Title ) {
208 return;
209 }
210 }
211
212 $this->title = $title->getPrefixedText();
213 $ns = $title->getNamespace();
214 $db = $this->mDb;
215
216 $doUserRightsLogLike = false;
217 if ( $this->types == [ 'rights' ] ) {
218 $parts = explode( $wgUserrightsInterwikiDelimiter, $title->getDBkey() );
219 if ( count( $parts ) == 2 ) {
220 list( $name, $database ) = array_map( 'trim', $parts );
221 if ( strstr( $database, '*' ) ) { // Search for wildcard in database name
222 $doUserRightsLogLike = true;
223 }
224 }
225 }
226
240 $this->mConds['log_namespace'] = $ns;
241 if ( $doUserRightsLogLike ) {
243 foreach ( explode( '*', $database ) as $databasepart ) {
244 $params[] = $databasepart;
245 $params[] = $db->anyString();
246 }
247 array_pop( $params ); // Get rid of the last % we added.
248 $this->mConds[] = 'log_title' . $db->buildLike( $params );
249 } elseif ( $pattern && !$wgMiserMode ) {
250 $this->mConds[] = 'log_title' . $db->buildLike( $title->getDBkey(), $db->anyString() );
251 $this->pattern = $pattern;
252 } else {
253 $this->mConds['log_title'] = $title->getDBkey();
254 }
256 }
257
263 private function limitAction( $action ) {
265 // Allow to filter the log by actions
267 if ( $type === '' ) {
268 // nothing to do
269 return;
270 }
271 $actions = $wgActionFilteredLogs;
272 if ( isset( $actions[$type] ) ) {
273 // log type can be filtered by actions
274 $this->mLogEventsList->setAllowedActions( array_keys( $actions[$type] ) );
275 if ( $action !== '' && isset( $actions[$type][$action] ) ) {
276 // add condition to query
277 $this->mConds['log_action'] = $actions[$type][$action];
278 $this->action = $action;
279 }
280 }
281 }
282
287 protected function limitLogId( $logId ) {
288 if ( !$logId ) {
289 return;
290 }
291 $this->mConds['log_id'] = $logId;
292 }
293
299 public function getQueryInfo() {
301
302 $tables = $basic['tables'];
303 $fields = $basic['fields'];
304 $conds = $basic['conds'];
305 $options = $basic['options'];
306 $joins = $basic['join_conds'];
307
308 # Add log_search table if there are conditions on it.
309 # This filters the results to only include log rows that have
310 # log_search records with the specified ls_field and ls_value values.
311 if ( array_key_exists( 'ls_field', $this->mConds ) ) {
312 $tables[] = 'log_search';
313 $options['IGNORE INDEX'] = [ 'log_search' => 'ls_log_id' ];
314 $options['USE INDEX'] = [ 'logging' => 'PRIMARY' ];
315 if ( !$this->hasEqualsClause( 'ls_field' )
316 || !$this->hasEqualsClause( 'ls_value' )
317 ) {
318 # Since (ls_field,ls_value,ls_logid) is unique, if the condition is
319 # to match a specific (ls_field,ls_value) tuple, then there will be
320 # no duplicate log rows. Otherwise, we need to remove the duplicates.
321 $options[] = 'DISTINCT';
322 }
323 }
324 # Don't show duplicate rows when using log_search
325 $joins['log_search'] = [ 'INNER JOIN', 'ls_log_id=log_id' ];
326
327 $info = [
328 'tables' => $tables,
329 'fields' => $fields,
330 'conds' => array_merge( $conds, $this->mConds ),
331 'options' => $options,
332 'join_conds' => $joins,
333 ];
334 # Add ChangeTags filter query
335 ChangeTags::modifyDisplayQuery( $info['tables'], $info['fields'], $info['conds'],
336 $info['join_conds'], $info['options'], $this->mTagFilter );
337
338 return $info;
339 }
340
346 protected function hasEqualsClause( $field ) {
347 return (
348 array_key_exists( $field, $this->mConds ) &&
349 ( !is_array( $this->mConds[$field] ) || count( $this->mConds[$field] ) == 1 )
350 );
351 }
352
353 function getIndexField() {
354 return 'log_timestamp';
355 }
356
357 public function getStartBody() {
358 # Do a link batch query
359 if ( $this->getNumRows() > 0 ) {
360 $lb = new LinkBatch;
361 foreach ( $this->mResult as $row ) {
362 $lb->add( $row->log_namespace, $row->log_title );
363 $lb->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
364 $lb->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_name ) );
365 $formatter = LogFormatter::newFromRow( $row );
366 foreach ( $formatter->getPreloadTitles() as $title ) {
367 $lb->addObj( $title );
368 }
369 }
370 $lb->execute();
371 $this->mResult->seek( 0 );
372 }
373
374 return '';
375 }
376
377 public function formatRow( $row ) {
378 return $this->mLogEventsList->logLine( $row );
379 }
380
381 public function getType() {
382 return $this->types;
383 }
384
390 public function getPerformer() {
391 return $this->performer;
392 }
393
397 public function getPage() {
398 return $this->title;
399 }
400
401 public function getPattern() {
402 return $this->pattern;
403 }
404
405 public function getYear() {
406 return $this->mYear;
407 }
408
409 public function getMonth() {
410 return $this->mMonth;
411 }
412
413 public function getTagFilter() {
414 return $this->mTagFilter;
415 }
416
417 public function getAction() {
418 return $this->action;
419 }
420
421 public function doQuery() {
422 // Workaround MySQL optimizer bug
423 $this->mDb->setBigSelects();
424 parent::doQuery();
425 $this->mDb->setBigSelects( 'default' );
426 }
427
431 private function enforceActionRestrictions() {
432 if ( $this->actionRestrictionsEnforced ) {
433 return;
434 }
435 $this->actionRestrictionsEnforced = true;
436 $user = $this->getUser();
437 if ( !$user->isAllowed( 'deletedhistory' ) ) {
438 $this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::DELETED_ACTION ) . ' = 0';
439 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
440 $this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::SUPPRESSED_ACTION ) .
442 }
443 }
444
448 private function enforcePerformerRestrictions() {
449 // Same as enforceActionRestrictions(), except for _USER instead of _ACTION bits.
450 if ( $this->performerRestrictionsEnforced ) {
451 return;
452 }
453 $this->performerRestrictionsEnforced = true;
454 $user = $this->getUser();
455 if ( !$user->isAllowed( 'deletedhistory' ) ) {
456 $this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::DELETED_USER ) . ' = 0';
457 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
458 $this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::SUPPRESSED_USER ) .
460 }
461 }
462}
$wgUserrightsInterwikiDelimiter
Character used as a delimiter when testing for interwiki userrights (In Special:UserRights,...
$wgLogRestrictions
This restricts log access to those who have a certain right Users without this will not see it in the...
$wgActionFilteredLogs
List of log types that can be filtered by action types.
$wgFilterLogTypes
Show/hide links on Special:Log will be shown for these log types.
$wgMiserMode
Disable database-intensive features.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
static modifyDisplayQuery(&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag='')
Applies all tags-related changes to a query.
static getSelectQueryData()
Returns array of information that is needed for querying log entries.
Definition LogEntry.php:172
getNumRows()
Get the number of rows in the result set.
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition LinkBatch.php:34
add( $ns, $dbkey)
Definition LinkBatch.php:80
static getExcludeClause( $db, $audience='public', User $user=null)
SQL clause to skip forbidden log types for this user.
static newFromRow( $row)
Handy shortcut for constructing a formatter directly from database row.
const SUPPRESSED_USER
Definition LogPage.php:38
const DELETED_USER
Definition LogPage.php:34
const DELETED_ACTION
Definition LogPage.php:32
const SUPPRESSED_ACTION
Definition LogPage.php:39
hasEqualsClause( $field)
Checks if $this->mConds has $field matched to a single value.
Definition LogPager.php:346
bool $actionRestrictionsEnforced
Definition LogPager.php:52
__construct( $list, $types=[], $performer='', $title='', $pattern='', $conds=[], $year=false, $month=false, $tagFilter='', $action='', $logId=false)
Definition LogPager.php:70
bool $performerRestrictionsEnforced
Definition LogPager.php:49
string Title $title
Events limited to those about Title when set.
Definition LogPager.php:37
formatRow( $row)
Abstract formatting function.
Definition LogPager.php:377
limitType( $types)
Set the log reader to return only entries of the given type.
Definition LogPager.php:126
getStartBody()
Hook into getBody(), allows text to be inserted at the start.
Definition LogPager.php:357
limitLogId( $logId)
Limit to the (single) specified log ID.
Definition LogPager.php:287
string $performer
Events limited to those by performer when set.
Definition LogPager.php:34
getFilterParams()
Definition LogPager.php:101
enforcePerformerRestrictions()
Paranoia: avoid brute force searches (T19342)
Definition LogPager.php:448
enforceActionRestrictions()
Paranoia: avoid brute force searches (T19342)
Definition LogPager.php:431
getDefaultQuery()
Get an array of query parameters that should be put into self-links.
Definition LogPager.php:90
limitTitle( $page, $pattern)
Set the log reader to return only entries affecting the given page.
Definition LogPager.php:200
string $action
Definition LogPager.php:46
getTagFilter()
Definition LogPager.php:413
LogEventsList $mLogEventsList
Definition LogPager.php:55
getQueryInfo()
Constructs the most part of the query.
Definition LogPager.php:299
doQuery()
Do the query, using information from the object context.
Definition LogPager.php:421
string $pattern
Definition LogPager.php:40
getPerformer()
Guaranteed to either return a valid title string or a Zero-Length String.
Definition LogPager.php:390
string $typeCGI
Definition LogPager.php:43
limitPerformer( $name)
Set the log reader to return only entries by the given user.
Definition LogPager.php:170
array $types
Log types.
Definition LogPager.php:31
getIndexField()
This function should be overridden to return the name of the index fi- eld.
Definition LogPager.php:353
limitAction( $action)
Set the log_action field to a specified value (or values)
Definition LogPager.php:263
Efficient paging for SQL queries.
getDateCond( $year, $month, $day=-1)
Set and return the mOffset timestamp such that we can get all revisions with a timestamp up to the sp...
Represents a title within MediaWiki.
Definition Title.php:39
getNamespace()
Get the namespace index, i.e.
Definition Title.php:970
getDBkey()
Get the main part with underscores.
Definition Title.php:947
getPrefixedText()
Get the prefixed title with spaces.
Definition Title.php:1625
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition User.php:591
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition deferred.txt:11
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
const NS_USER
Definition Defines.php:76
const NS_USER_TALK
Definition Defines.php:77
the array() calling protocol came about after MediaWiki 1.4rc1.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist & $tables
Definition hooks.txt:1015
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition hooks.txt:2001
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:302
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition hooks.txt:1620
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition hooks.txt:247
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
title
const DB_REPLICA
Definition defines.php:25
$params