MediaWiki REL1_27
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_SLAVE, '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 /* Fetch userid at first, if known, provides awesome query plan afterwards */
177 $userid = User::idFromName( $name );
178 if ( !$userid ) {
179 $this->mConds['log_user_text'] = IP::sanitizeIP( $name );
180 } else {
181 $this->mConds['log_user'] = $userid;
182 }
183 // Paranoia: avoid brute force searches (bug 17342)
184 $user = $this->getUser();
185 if ( !$user->isAllowed( 'deletedhistory' ) ) {
186 $this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::DELETED_USER ) . ' = 0';
187 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
188 $this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::SUPPRESSED_USER ) .
190 }
191
192 $this->performer = $usertitle->getText();
193 }
194
203 private function limitTitle( $page, $pattern ) {
205
206 if ( $page instanceof Title ) {
207 $title = $page;
208 } else {
210 if ( strlen( $page ) == 0 || !$title instanceof Title ) {
211 return;
212 }
213 }
214
215 $this->title = $title->getPrefixedText();
216 $ns = $title->getNamespace();
217 $db = $this->mDb;
218
219 $doUserRightsLogLike = false;
220 if ( $this->types == [ 'rights' ] ) {
221 $parts = explode( $wgUserrightsInterwikiDelimiter, $title->getDBkey() );
222 if ( count( $parts ) == 2 ) {
223 list( $name, $database ) = array_map( 'trim', $parts );
224 if ( strstr( $database, '*' ) ) { // Search for wildcard in database name
225 $doUserRightsLogLike = true;
226 }
227 }
228 }
229
243 $this->mConds['log_namespace'] = $ns;
244 if ( $doUserRightsLogLike ) {
246 foreach ( explode( '*', $database ) as $databasepart ) {
247 $params[] = $databasepart;
248 $params[] = $db->anyString();
249 }
250 array_pop( $params ); // Get rid of the last % we added.
251 $this->mConds[] = 'log_title' . $db->buildLike( $params );
252 } elseif ( $pattern && !$wgMiserMode ) {
253 $this->mConds[] = 'log_title' . $db->buildLike( $title->getDBkey(), $db->anyString() );
254 $this->pattern = $pattern;
255 } else {
256 $this->mConds['log_title'] = $title->getDBkey();
257 }
258 // Paranoia: avoid brute force searches (bug 17342)
259 $user = $this->getUser();
260 if ( !$user->isAllowed( 'deletedhistory' ) ) {
261 $this->mConds[] = $db->bitAnd( 'log_deleted', LogPage::DELETED_ACTION ) . ' = 0';
262 } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
263 $this->mConds[] = $db->bitAnd( 'log_deleted', LogPage::SUPPRESSED_ACTION ) .
265 }
266 }
267
273 private function limitAction( $action ) {
275 // Allow to filter the log by actions
277 if ( $type === '' ) {
278 // nothing to do
279 return;
280 }
281 $actions = $wgActionFilteredLogs;
282 if ( isset( $actions[$type] ) ) {
283 // log type can be filtered by actions
284 $this->mLogEventsList->setAllowedActions( array_keys( $actions[$type] ) );
285 if ( $action !== '' && isset( $actions[$type][$action] ) ) {
286 // add condition to query
287 $this->mConds['log_action'] = $actions[$type][$action];
288 $this->action = $action;
289 }
290 }
291 }
292
297 protected function limitLogId( $logId ) {
298 if ( !$logId ) {
299 return;
300 }
301 $this->mConds['log_id'] = $logId;
302 }
303
309 public function getQueryInfo() {
311
312 $tables = $basic['tables'];
313 $fields = $basic['fields'];
314 $conds = $basic['conds'];
315 $options = $basic['options'];
316 $joins = $basic['join_conds'];
317
318 $index = [];
319 # Add log_search table if there are conditions on it.
320 # This filters the results to only include log rows that have
321 # log_search records with the specified ls_field and ls_value values.
322 if ( array_key_exists( 'ls_field', $this->mConds ) ) {
323 $tables[] = 'log_search';
324 $index['log_search'] = 'ls_field_val';
325 $index['logging'] = 'PRIMARY';
326 if ( !$this->hasEqualsClause( 'ls_field' )
327 || !$this->hasEqualsClause( 'ls_value' )
328 ) {
329 # Since (ls_field,ls_value,ls_logid) is unique, if the condition is
330 # to match a specific (ls_field,ls_value) tuple, then there will be
331 # no duplicate log rows. Otherwise, we need to remove the duplicates.
332 $options[] = 'DISTINCT';
333 }
334 }
335 if ( count( $index ) ) {
336 $options['USE INDEX'] = $index;
337 }
338 # Don't show duplicate rows when using log_search
339 $joins['log_search'] = [ 'INNER JOIN', 'ls_log_id=log_id' ];
340
341 $info = [
342 'tables' => $tables,
343 'fields' => $fields,
344 'conds' => array_merge( $conds, $this->mConds ),
345 'options' => $options,
346 'join_conds' => $joins,
347 ];
348 # Add ChangeTags filter query
349 ChangeTags::modifyDisplayQuery( $info['tables'], $info['fields'], $info['conds'],
350 $info['join_conds'], $info['options'], $this->mTagFilter );
351
352 return $info;
353 }
354
360 protected function hasEqualsClause( $field ) {
361 return (
362 array_key_exists( $field, $this->mConds ) &&
363 ( !is_array( $this->mConds[$field] ) || count( $this->mConds[$field] ) == 1 )
364 );
365 }
366
367 function getIndexField() {
368 return 'log_timestamp';
369 }
370
371 public function getStartBody() {
372 # Do a link batch query
373 if ( $this->getNumRows() > 0 ) {
374 $lb = new LinkBatch;
375 foreach ( $this->mResult as $row ) {
376 $lb->add( $row->log_namespace, $row->log_title );
377 $lb->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
378 $lb->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_name ) );
379 $formatter = LogFormatter::newFromRow( $row );
380 foreach ( $formatter->getPreloadTitles() as $title ) {
381 $lb->addObj( $title );
382 }
383 }
384 $lb->execute();
385 $this->mResult->seek( 0 );
386 }
387
388 return '';
389 }
390
391 public function formatRow( $row ) {
392 return $this->mLogEventsList->logLine( $row );
393 }
394
395 public function getType() {
396 return $this->types;
397 }
398
404 public function getPerformer() {
405 return $this->performer;
406 }
407
411 public function getPage() {
412 return $this->title;
413 }
414
415 public function getPattern() {
416 return $this->pattern;
417 }
418
419 public function getYear() {
420 return $this->mYear;
421 }
422
423 public function getMonth() {
424 return $this->mMonth;
425 }
426
427 public function getTagFilter() {
428 return $this->mTagFilter;
429 }
430
431 public function getAction() {
432 return $this->action;
433 }
434
435 public function doQuery() {
436 // Workaround MySQL optimizer bug
437 $this->mDb->setBigSelects();
438 parent::doQuery();
439 $this->mDb->setBigSelects( 'default' );
440 }
441}
$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:170
static sanitizeIP( $ip)
Convert an IP into a verbose, uppercase, normalized form.
Definition IP.php:140
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:31
add( $ns, $dbkey)
Definition LinkBatch.php:74
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:39
const DELETED_USER
Definition LogPage.php:35
const DELETED_ACTION
Definition LogPage.php:33
const SUPPRESSED_ACTION
Definition LogPage.php:40
hasEqualsClause( $field)
Checks if $this->mConds has $field matched to a single value.
Definition LogPager.php:360
__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:391
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:371
limitLogId( $logId)
Limit to the (single) specified log ID.
Definition LogPager.php:297
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:203
string $action
Definition LogPager.php:46
getTagFilter()
Definition LogPager.php:427
LogEventsList $mLogEventsList
Definition LogPager.php:49
getQueryInfo()
Constructs the most part of the query.
Definition LogPager.php:309
doQuery()
Do the query, using information from the object context.
Definition LogPager.php:435
string $pattern
Definition LogPager.php:40
getPerformer()
Guaranteed to either return a valid title string or a Zero-Length String.
Definition LogPager.php:404
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:367
limitAction( $action)
Set the log_action field to a specified value (or values)
Definition LogPager.php:273
IndexPager with a formatted navigation bar.
Represents a title within MediaWiki.
Definition Title.php:34
getNamespace()
Get the namespace index, i.e.
Definition Title.php:934
getDBkey()
Get the main part with underscores.
Definition Title.php:911
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition Title.php:277
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition Title.php:548
getPrefixedText()
Get the prefixed title with spaces.
Definition Title.php:1449
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:72
const NS_USER_TALK
Definition Defines.php:73
const DB_SLAVE
Definition Defines.php:47
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:2379
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist & $tables
Definition hooks.txt:986
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist 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:1042
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 one of or reset 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:2413
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:314
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:1458
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
$params