MediaWiki REL1_29
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
66 public function __construct( $list, $types = [], $performer = '', $title = '',
67 $pattern = '', $conds = [], $year = false, $month = false, $tagFilter = '',
68 $action = '', $logId = false
69 ) {
70 parent::__construct( $list->getContext() );
71 $this->mConds = $conds;
72
73 $this->mLogEventsList = $list;
74
75 $this->limitType( $types ); // also excludes hidden types
76 $this->limitPerformer( $performer );
77 $this->limitTitle( $title, $pattern );
78 $this->limitAction( $action );
79 $this->getDateCond( $year, $month );
80 $this->mTagFilter = $tagFilter;
81 $this->limitLogId( $logId );
82
83 $this->mDb = wfGetDB( DB_REPLICA, 'logpager' );
84 }
85
86 public function getDefaultQuery() {
87 $query = parent::getDefaultQuery();
88 $query['type'] = $this->typeCGI; // arrays won't work here
89 $query['user'] = $this->performer;
90 $query['month'] = $this->mMonth;
91 $query['year'] = $this->mYear;
92
93 return $query;
94 }
95
96 // Call ONLY after calling $this->limitType() already!
97 public function getFilterParams() {
99 $filters = [];
100 if ( count( $this->types ) ) {
101 return $filters;
102 }
103 foreach ( $wgFilterLogTypes as $type => $default ) {
104 // Avoid silly filtering
105 if ( $type !== 'patrol' || $this->getUser()->useNPPatrol() ) {
106 $hide = $this->getRequest()->getInt( "hide_{$type}_log", $default );
107 $filters[$type] = $hide;
108 if ( $hide ) {
109 $this->mConds[] = 'log_type != ' . $this->mDb->addQuotes( $type );
110 }
111 }
112 }
113
114 return $filters;
115 }
116
124 private function limitType( $types ) {
126
127 $user = $this->getUser();
128 // If $types is not an array, make it an array
129 $types = ( $types === '' ) ? [] : (array)$types;
130 // Don't even show header for private logs; don't recognize it...
131 $needReindex = false;
132 foreach ( $types as $type ) {
133 if ( isset( $wgLogRestrictions[$type] )
134 && !$user->isAllowed( $wgLogRestrictions[$type] )
135 ) {
136 $needReindex = true;
137 $types = array_diff( $types, [ $type ] );
138 }
139 }
140 if ( $needReindex ) {
141 // Lots of this code makes assumptions that
142 // the first entry in the array is $types[0].
143 $types = array_values( $types );
144 }
145 $this->types = $types;
146 // Don't show private logs to unprivileged users.
147 // Also, only show them upon specific request to avoid suprises.
148 $audience = $types ? 'user' : 'public';
149 $hideLogs = LogEventsList::getExcludeClause( $this->mDb, $audience, $user );
150 if ( $hideLogs !== false ) {
151 $this->mConds[] = $hideLogs;
152 }
153 if ( count( $types ) ) {
154 $this->mConds['log_type'] = $types;
155 // Set typeCGI; used in url param for paging
156 if ( count( $types ) == 1 ) {
157 $this->typeCGI = $types[0];
158 }
159 }
160 }
161
168 private function limitPerformer( $name ) {
169 if ( $name == '' ) {
170 return;
171 }
172 $usertitle = Title::makeTitleSafe( NS_USER, $name );
173 if ( is_null( $usertitle ) ) {
174 return;
175 }
176 // Normalize username first so that non-existent users used
177 // in maintenance scripts work
178 $name = $usertitle->getText();
179 /* Fetch userid at first, if known, provides awesome query plan afterwards */
180 $userid = User::idFromName( $name );
181 if ( !$userid ) {
182 $this->mConds['log_user_text'] = IP::sanitizeIP( $name );
183 } else {
184 $this->mConds['log_user'] = $userid;
185 }
186 // Paranoia: avoid brute force searches (T19342)
187 $user = $this->getUser();
188 if ( !$user->isAllowed( 'deletedhistory' ) ) {
189 $this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::DELETED_USER ) . ' = 0';
190 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
191 $this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::SUPPRESSED_USER ) .
193 }
194
195 $this->performer = $name;
196 }
197
206 private function limitTitle( $page, $pattern ) {
208
209 if ( $page instanceof Title ) {
210 $title = $page;
211 } else {
212 $title = Title::newFromText( $page );
213 if ( strlen( $page ) == 0 || !$title instanceof Title ) {
214 return;
215 }
216 }
217
218 $this->title = $title->getPrefixedText();
219 $ns = $title->getNamespace();
220 $db = $this->mDb;
221
222 $doUserRightsLogLike = false;
223 if ( $this->types == [ 'rights' ] ) {
224 $parts = explode( $wgUserrightsInterwikiDelimiter, $title->getDBkey() );
225 if ( count( $parts ) == 2 ) {
226 list( $name, $database ) = array_map( 'trim', $parts );
227 if ( strstr( $database, '*' ) ) { // Search for wildcard in database name
228 $doUserRightsLogLike = true;
229 }
230 }
231 }
232
246 $this->mConds['log_namespace'] = $ns;
247 if ( $doUserRightsLogLike ) {
249 foreach ( explode( '*', $database ) as $databasepart ) {
250 $params[] = $databasepart;
251 $params[] = $db->anyString();
252 }
253 array_pop( $params ); // Get rid of the last % we added.
254 $this->mConds[] = 'log_title' . $db->buildLike( $params );
255 } elseif ( $pattern && !$wgMiserMode ) {
256 $this->mConds[] = 'log_title' . $db->buildLike( $title->getDBkey(), $db->anyString() );
257 $this->pattern = $pattern;
258 } else {
259 $this->mConds['log_title'] = $title->getDBkey();
260 }
261 // Paranoia: avoid brute force searches (T19342)
262 $user = $this->getUser();
263 if ( !$user->isAllowed( 'deletedhistory' ) ) {
264 $this->mConds[] = $db->bitAnd( 'log_deleted', LogPage::DELETED_ACTION ) . ' = 0';
265 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
266 $this->mConds[] = $db->bitAnd( 'log_deleted', LogPage::SUPPRESSED_ACTION ) .
268 }
269 }
270
276 private function limitAction( $action ) {
278 // Allow to filter the log by actions
280 if ( $type === '' ) {
281 // nothing to do
282 return;
283 }
284 $actions = $wgActionFilteredLogs;
285 if ( isset( $actions[$type] ) ) {
286 // log type can be filtered by actions
287 $this->mLogEventsList->setAllowedActions( array_keys( $actions[$type] ) );
288 if ( $action !== '' && isset( $actions[$type][$action] ) ) {
289 // add condition to query
290 $this->mConds['log_action'] = $actions[$type][$action];
291 $this->action = $action;
292 }
293 }
294 }
295
300 protected function limitLogId( $logId ) {
301 if ( !$logId ) {
302 return;
303 }
304 $this->mConds['log_id'] = $logId;
305 }
306
312 public function getQueryInfo() {
314
315 $tables = $basic['tables'];
316 $fields = $basic['fields'];
317 $conds = $basic['conds'];
318 $options = $basic['options'];
319 $joins = $basic['join_conds'];
320
321 $index = [];
322 # Add log_search table if there are conditions on it.
323 # This filters the results to only include log rows that have
324 # log_search records with the specified ls_field and ls_value values.
325 if ( array_key_exists( 'ls_field', $this->mConds ) ) {
326 $tables[] = 'log_search';
327 $index['log_search'] = 'ls_field_val';
328 $index['logging'] = 'PRIMARY';
329 if ( !$this->hasEqualsClause( 'ls_field' )
330 || !$this->hasEqualsClause( 'ls_value' )
331 ) {
332 # Since (ls_field,ls_value,ls_logid) is unique, if the condition is
333 # to match a specific (ls_field,ls_value) tuple, then there will be
334 # no duplicate log rows. Otherwise, we need to remove the duplicates.
335 $options[] = 'DISTINCT';
336 }
337 }
338 if ( count( $index ) ) {
339 $options['USE INDEX'] = $index;
340 }
341 # Don't show duplicate rows when using log_search
342 $joins['log_search'] = [ 'INNER JOIN', 'ls_log_id=log_id' ];
343
344 $info = [
345 'tables' => $tables,
346 'fields' => $fields,
347 'conds' => array_merge( $conds, $this->mConds ),
348 'options' => $options,
349 'join_conds' => $joins,
350 ];
351 # Add ChangeTags filter query
352 ChangeTags::modifyDisplayQuery( $info['tables'], $info['fields'], $info['conds'],
353 $info['join_conds'], $info['options'], $this->mTagFilter );
354
355 return $info;
356 }
357
363 protected function hasEqualsClause( $field ) {
364 return (
365 array_key_exists( $field, $this->mConds ) &&
366 ( !is_array( $this->mConds[$field] ) || count( $this->mConds[$field] ) == 1 )
367 );
368 }
369
370 function getIndexField() {
371 return 'log_timestamp';
372 }
373
374 public function getStartBody() {
375 # Do a link batch query
376 if ( $this->getNumRows() > 0 ) {
377 $lb = new LinkBatch;
378 foreach ( $this->mResult as $row ) {
379 $lb->add( $row->log_namespace, $row->log_title );
380 $lb->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
381 $lb->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_name ) );
382 $formatter = LogFormatter::newFromRow( $row );
383 foreach ( $formatter->getPreloadTitles() as $title ) {
384 $lb->addObj( $title );
385 }
386 }
387 $lb->execute();
388 $this->mResult->seek( 0 );
389 }
390
391 return '';
392 }
393
394 public function formatRow( $row ) {
395 return $this->mLogEventsList->logLine( $row );
396 }
397
398 public function getType() {
399 return $this->types;
400 }
401
407 public function getPerformer() {
408 return $this->performer;
409 }
410
414 public function getPage() {
415 return $this->title;
416 }
417
418 public function getPattern() {
419 return $this->pattern;
420 }
421
422 public function getYear() {
423 return $this->mYear;
424 }
425
426 public function getMonth() {
427 return $this->mMonth;
428 }
429
430 public function getTagFilter() {
431 return $this->mTagFilter;
432 }
433
434 public function getAction() {
435 return $this->action;
436 }
437
438 public function doQuery() {
439 // Workaround MySQL optimizer bug
440 $this->mDb->setBigSelects();
441 parent::doQuery();
442 $this->mDb->setBigSelects( 'default' );
443 }
444}
$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=false)
Applies all tags-related changes to a query.
getUser()
Get the User object.
getRequest()
Get the WebRequest object.
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:81
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:363
__construct( $list, $types=[], $performer='', $title='', $pattern='', $conds=[], $year=false, $month=false, $tagFilter='', $action='', $logId=false)
Constructor.
Definition LogPager.php:66
string Title $title
Events limited to those about Title when set.
Definition LogPager.php:37
formatRow( $row)
Abstract formatting function.
Definition LogPager.php:394
limitType( $types)
Set the log reader to return only entries of the given type.
Definition LogPager.php:124
getStartBody()
Hook into getBody(), allows text to be inserted at the start.
Definition LogPager.php:374
limitLogId( $logId)
Limit to the (single) specified log ID.
Definition LogPager.php:300
string $performer
Events limited to those by performer when set.
Definition LogPager.php:34
getFilterParams()
Definition LogPager.php:97
getDefaultQuery()
Get an array of query parameters that should be put into self-links.
Definition LogPager.php:86
limitTitle( $page, $pattern)
Set the log reader to return only entries affecting the given page.
Definition LogPager.php:206
string $action
Definition LogPager.php:46
getTagFilter()
Definition LogPager.php:430
LogEventsList $mLogEventsList
Definition LogPager.php:49
getQueryInfo()
Constructs the most part of the query.
Definition LogPager.php:312
doQuery()
Do the query, using information from the object context.
Definition LogPager.php:438
string $pattern
Definition LogPager.php:40
getPerformer()
Guaranteed to either return a valid title string or a Zero-Length String.
Definition LogPager.php:407
string $typeCGI
Definition LogPager.php:43
limitPerformer( $name)
Set the log reader to return only entries by the given user.
Definition LogPager.php:168
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:370
limitAction( $action)
Set the log_action field to a specified value (or values)
Definition LogPager.php:276
IndexPager with a formatted navigation bar.
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:924
getDBkey()
Get the main part with underscores.
Definition Title.php:901
getPrefixedText()
Get the prefixed title with spaces.
Definition Title.php:1451
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:64
const NS_USER_TALK
Definition Defines.php:65
the array() calling protocol came about after MediaWiki 1.4rc1.
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:249
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached $page
Definition hooks.txt:2578
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:1018
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 and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
Definition hooks.txt:1102
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
Definition hooks.txt:2604
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:304
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:1601
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