MediaWiki  1.27.2
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 
65  public function __construct( $list, $types = [], $performer = '', $title = '',
66  $pattern = '', $conds = [], $year = false, $month = false, $tagFilter = '',
67  $action = ''
68  ) {
69  parent::__construct( $list->getContext() );
70  $this->mConds = $conds;
71 
72  $this->mLogEventsList = $list;
73 
74  $this->limitType( $types ); // also excludes hidden types
75  $this->limitPerformer( $performer );
76  $this->limitTitle( $title, $pattern );
77  $this->limitAction( $action );
78  $this->getDateCond( $year, $month );
79  $this->mTagFilter = $tagFilter;
80 
81  $this->mDb = wfGetDB( DB_SLAVE, 'logpager' );
82  }
83 
84  public function getDefaultQuery() {
85  $query = parent::getDefaultQuery();
86  $query['type'] = $this->typeCGI; // arrays won't work here
87  $query['user'] = $this->performer;
88  $query['month'] = $this->mMonth;
89  $query['year'] = $this->mYear;
90 
91  return $query;
92  }
93 
94  // Call ONLY after calling $this->limitType() already!
95  public function getFilterParams() {
96  global $wgFilterLogTypes;
97  $filters = [];
98  if ( count( $this->types ) ) {
99  return $filters;
100  }
101  foreach ( $wgFilterLogTypes as $type => $default ) {
102  // Avoid silly filtering
103  if ( $type !== 'patrol' || $this->getUser()->useNPPatrol() ) {
104  $hide = $this->getRequest()->getInt( "hide_{$type}_log", $default );
105  $filters[$type] = $hide;
106  if ( $hide ) {
107  $this->mConds[] = 'log_type != ' . $this->mDb->addQuotes( $type );
108  }
109  }
110  }
111 
112  return $filters;
113  }
114 
122  private function limitType( $types ) {
123  global $wgLogRestrictions;
124 
125  $user = $this->getUser();
126  // If $types is not an array, make it an array
127  $types = ( $types === '' ) ? [] : (array)$types;
128  // Don't even show header for private logs; don't recognize it...
129  $needReindex = false;
130  foreach ( $types as $type ) {
131  if ( isset( $wgLogRestrictions[$type] )
132  && !$user->isAllowed( $wgLogRestrictions[$type] )
133  ) {
134  $needReindex = true;
135  $types = array_diff( $types, [ $type ] );
136  }
137  }
138  if ( $needReindex ) {
139  // Lots of this code makes assumptions that
140  // the first entry in the array is $types[0].
141  $types = array_values( $types );
142  }
143  $this->types = $types;
144  // Don't show private logs to unprivileged users.
145  // Also, only show them upon specific request to avoid suprises.
146  $audience = $types ? 'user' : 'public';
147  $hideLogs = LogEventsList::getExcludeClause( $this->mDb, $audience, $user );
148  if ( $hideLogs !== false ) {
149  $this->mConds[] = $hideLogs;
150  }
151  if ( count( $types ) ) {
152  $this->mConds['log_type'] = $types;
153  // Set typeCGI; used in url param for paging
154  if ( count( $types ) == 1 ) {
155  $this->typeCGI = $types[0];
156  }
157  }
158  }
159 
166  private function limitPerformer( $name ) {
167  if ( $name == '' ) {
168  return;
169  }
170  $usertitle = Title::makeTitleSafe( NS_USER, $name );
171  if ( is_null( $usertitle ) ) {
172  return;
173  }
174  /* Fetch userid at first, if known, provides awesome query plan afterwards */
175  $userid = User::idFromName( $name );
176  if ( !$userid ) {
177  $this->mConds['log_user_text'] = IP::sanitizeIP( $name );
178  } else {
179  $this->mConds['log_user'] = $userid;
180  }
181  // Paranoia: avoid brute force searches (bug 17342)
182  $user = $this->getUser();
183  if ( !$user->isAllowed( 'deletedhistory' ) ) {
184  $this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::DELETED_USER ) . ' = 0';
185  } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
186  $this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::SUPPRESSED_USER ) .
187  ' != ' . LogPage::SUPPRESSED_USER;
188  }
189 
190  $this->performer = $usertitle->getText();
191  }
192 
201  private function limitTitle( $page, $pattern ) {
202  global $wgMiserMode, $wgUserrightsInterwikiDelimiter;
203 
204  if ( $page instanceof Title ) {
205  $title = $page;
206  } else {
208  if ( strlen( $page ) == 0 || !$title instanceof Title ) {
209  return;
210  }
211  }
212 
213  $this->title = $title->getPrefixedText();
214  $ns = $title->getNamespace();
215  $db = $this->mDb;
216 
217  $doUserRightsLogLike = false;
218  if ( $this->types == [ 'rights' ] ) {
219  $parts = explode( $wgUserrightsInterwikiDelimiter, $title->getDBkey() );
220  if ( count( $parts ) == 2 ) {
221  list( $name, $database ) = array_map( 'trim', $parts );
222  if ( strstr( $database, '*' ) ) { // Search for wildcard in database name
223  $doUserRightsLogLike = true;
224  }
225  }
226  }
227 
241  $this->mConds['log_namespace'] = $ns;
242  if ( $doUserRightsLogLike ) {
243  $params = [ $name . $wgUserrightsInterwikiDelimiter ];
244  foreach ( explode( '*', $database ) as $databasepart ) {
245  $params[] = $databasepart;
246  $params[] = $db->anyString();
247  }
248  array_pop( $params ); // Get rid of the last % we added.
249  $this->mConds[] = 'log_title' . $db->buildLike( $params );
250  } elseif ( $pattern && !$wgMiserMode ) {
251  $this->mConds[] = 'log_title' . $db->buildLike( $title->getDBkey(), $db->anyString() );
252  $this->pattern = $pattern;
253  } else {
254  $this->mConds['log_title'] = $title->getDBkey();
255  }
256  // Paranoia: avoid brute force searches (bug 17342)
257  $user = $this->getUser();
258  if ( !$user->isAllowed( 'deletedhistory' ) ) {
259  $this->mConds[] = $db->bitAnd( 'log_deleted', LogPage::DELETED_ACTION ) . ' = 0';
260  } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
261  $this->mConds[] = $db->bitAnd( 'log_deleted', LogPage::SUPPRESSED_ACTION ) .
263  }
264  }
265 
271  private function limitAction( $action ) {
272  global $wgActionFilteredLogs;
273  // Allow to filter the log by actions
275  if ( $type === '' ) {
276  // nothing to do
277  return;
278  }
279  $actions = $wgActionFilteredLogs;
280  if ( isset( $actions[$type] ) ) {
281  // log type can be filtered by actions
282  $this->mLogEventsList->setAllowedActions( array_keys( $actions[$type] ) );
283  if ( $action !== '' && isset( $actions[$type][$action] ) ) {
284  // add condition to query
285  $this->mConds['log_action'] = $actions[$type][$action];
286  $this->action = $action;
287  }
288  }
289  }
290 
296  public function getQueryInfo() {
298 
299  $tables = $basic['tables'];
300  $fields = $basic['fields'];
301  $conds = $basic['conds'];
302  $options = $basic['options'];
303  $joins = $basic['join_conds'];
304 
305  $index = [];
306  # Add log_search table if there are conditions on it.
307  # This filters the results to only include log rows that have
308  # log_search records with the specified ls_field and ls_value values.
309  if ( array_key_exists( 'ls_field', $this->mConds ) ) {
310  $tables[] = 'log_search';
311  $index['log_search'] = 'ls_field_val';
312  $index['logging'] = 'PRIMARY';
313  if ( !$this->hasEqualsClause( 'ls_field' )
314  || !$this->hasEqualsClause( 'ls_value' )
315  ) {
316  # Since (ls_field,ls_value,ls_logid) is unique, if the condition is
317  # to match a specific (ls_field,ls_value) tuple, then there will be
318  # no duplicate log rows. Otherwise, we need to remove the duplicates.
319  $options[] = 'DISTINCT';
320  }
321  }
322  if ( count( $index ) ) {
323  $options['USE INDEX'] = $index;
324  }
325  # Don't show duplicate rows when using log_search
326  $joins['log_search'] = [ 'INNER JOIN', 'ls_log_id=log_id' ];
327 
328  $info = [
329  'tables' => $tables,
330  'fields' => $fields,
331  'conds' => array_merge( $conds, $this->mConds ),
332  'options' => $options,
333  'join_conds' => $joins,
334  ];
335  # Add ChangeTags filter query
336  ChangeTags::modifyDisplayQuery( $info['tables'], $info['fields'], $info['conds'],
337  $info['join_conds'], $info['options'], $this->mTagFilter );
338 
339  return $info;
340  }
341 
347  protected function hasEqualsClause( $field ) {
348  return (
349  array_key_exists( $field, $this->mConds ) &&
350  ( !is_array( $this->mConds[$field] ) || count( $this->mConds[$field] ) == 1 )
351  );
352  }
353 
354  function getIndexField() {
355  return 'log_timestamp';
356  }
357 
358  public function getStartBody() {
359  # Do a link batch query
360  if ( $this->getNumRows() > 0 ) {
361  $lb = new LinkBatch;
362  foreach ( $this->mResult as $row ) {
363  $lb->add( $row->log_namespace, $row->log_title );
364  $lb->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
365  $lb->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_name ) );
366  $formatter = LogFormatter::newFromRow( $row );
367  foreach ( $formatter->getPreloadTitles() as $title ) {
368  $lb->addObj( $title );
369  }
370  }
371  $lb->execute();
372  $this->mResult->seek( 0 );
373  }
374 
375  return '';
376  }
377 
378  public function formatRow( $row ) {
379  return $this->mLogEventsList->logLine( $row );
380  }
381 
382  public function getType() {
383  return $this->types;
384  }
385 
391  public function getPerformer() {
392  return $this->performer;
393  }
394 
398  public function getPage() {
399  return $this->title;
400  }
401 
402  public function getPattern() {
403  return $this->pattern;
404  }
405 
406  public function getYear() {
407  return $this->mYear;
408  }
409 
410  public function getMonth() {
411  return $this->mMonth;
412  }
413 
414  public function getTagFilter() {
415  return $this->mTagFilter;
416  }
417 
418  public function getAction() {
419  return $this->action;
420  }
421 
422  public function doQuery() {
423  // Workaround MySQL optimizer bug
424  $this->mDb->setBigSelects();
425  parent::doQuery();
426  $this->mDb->setBigSelects( 'default' );
427  }
428 }
limitPerformer($name)
Set the log reader to return only entries by the given user.
Definition: LogPager.php:166
getPerformer()
Guaranteed to either return a valid title string or a Zero-Length String.
Definition: LogPager.php:391
getFilterParams()
Definition: LogPager.php:95
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
wfGetDB($db, $groups=[], $wiki=false)
Get a Database object.
the array() calling protocol came about after MediaWiki 1.4rc1.
static newFromRow($row)
Handy shortcut for constructing a formatter directly from database row.
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:1418
static sanitizeIP($ip)
Convert an IP into a verbose, uppercase, normalized form.
Definition: IP.php:140
getPattern()
Definition: LogPager.php:402
getQueryInfo()
Constructs the most part of the query.
Definition: LogPager.php:296
formatRow($row)
Definition: LogPager.php:378
IndexPager with a formatted navigation bar.
string $action
Definition: LogPager.php:46
getDefaultQuery()
Definition: LogPager.php:84
getPrefixedText()
Get the prefixed title with spaces.
Definition: Title.php:1449
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
const SUPPRESSED_ACTION
Definition: LogPage.php:40
Represents a title within MediaWiki.
Definition: Title.php:34
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist & $tables
Definition: hooks.txt:965
LogEventsList $mLogEventsList
Definition: LogPager.php:49
getAction()
Definition: LogPager.php:418
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition: LinkBatch.php:31
getRequest()
Get the WebRequest object.
__construct($list, $types=[], $performer= '', $title= '', $pattern= '', $conds=[], $year=false, $month=false, $tagFilter= '', $action= '')
Constructor.
Definition: LogPager.php:65
string Title $title
Events limited to those about Title when set.
Definition: LogPager.php:37
getDBkey()
Get the main part with underscores.
Definition: Title.php:911
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:1004
getIndexField()
Definition: LogPager.php:354
$wgMiserMode
Disable database-intensive features.
$params
hasEqualsClause($field)
Checks if $this->mConds has $field matched to a single value.
Definition: LogPager.php:347
getStartBody()
Definition: LogPager.php:358
static makeTitleSafe($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:548
title
const DB_SLAVE
Definition: Defines.php:46
getNamespace()
Get the namespace index, i.e.
Definition: Title.php:934
limitTitle($page, $pattern)
Set the log reader to return only entries affecting the given page.
Definition: LogPager.php:201
getTagFilter()
Definition: LogPager.php:414
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
Definition: distributors.txt:9
static getSelectQueryData()
Returns array of information that is needed for querying log entries.
Definition: LogEntry.php:170
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:242
const DELETED_USER
Definition: LogPage.php:35
static modifyDisplayQuery(&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag=false)
Applies all tags-related changes to a query.
Definition: ChangeTags.php:615
const SUPPRESSED_USER
Definition: LogPage.php:39
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:35
limitAction($action)
Set the log_action field to a specified value (or values)
Definition: LogPager.php:271
action
static idFromName($name, $flags=self::READ_NORMAL)
Get database id given a user name.
Definition: User.php:770
string $performer
Events limited to those by performer when set.
Definition: LogPager.php:34
add($ns, $dbkey)
Definition: LinkBatch.php:74
string $pattern
Definition: LogPager.php:40
string $typeCGI
Definition: LogPager.php:43
const DELETED_ACTION
Definition: LogPage.php:33
const NS_USER_TALK
Definition: Defines.php:72
getMonth()
Definition: LogPager.php:410
getUser()
Get the User object.
limitType($types)
Set the log reader to return only entries of the given type.
Definition: LogPager.php:122
static getExcludeClause($db, $audience= 'public', User $user=null)
SQL clause to skip forbidden log types for this user.
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:2338
array $types
Log types.
Definition: LogPager.php:31
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:2338
getNumRows()
Get the number of rows in the result set.
Definition: IndexPager.php:552
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:310