MediaWiki  1.29.1
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_REPLICA, '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  // Normalize username first so that non-existent users used
175  // in maintenance scripts work
176  $name = $usertitle->getText();
177  /* Fetch userid at first, if known, provides awesome query plan afterwards */
178  $userid = User::idFromName( $name );
179  if ( !$userid ) {
180  $this->mConds['log_user_text'] = IP::sanitizeIP( $name );
181  } else {
182  $this->mConds['log_user'] = $userid;
183  }
184  // Paranoia: avoid brute force searches (T19342)
185  $user = $this->getUser();
186  if ( !$user->isAllowed( 'deletedhistory' ) ) {
187  $this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::DELETED_USER ) . ' = 0';
188  } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
189  $this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::SUPPRESSED_USER ) .
190  ' != ' . LogPage::SUPPRESSED_USER;
191  }
192 
193  $this->performer = $name;
194  }
195 
204  private function limitTitle( $page, $pattern ) {
205  global $wgMiserMode, $wgUserrightsInterwikiDelimiter;
206 
207  if ( $page instanceof Title ) {
208  $title = $page;
209  } else {
211  if ( strlen( $page ) == 0 || !$title instanceof Title ) {
212  return;
213  }
214  }
215 
216  $this->title = $title->getPrefixedText();
217  $ns = $title->getNamespace();
218  $db = $this->mDb;
219 
220  $doUserRightsLogLike = false;
221  if ( $this->types == [ 'rights' ] ) {
222  $parts = explode( $wgUserrightsInterwikiDelimiter, $title->getDBkey() );
223  if ( count( $parts ) == 2 ) {
224  list( $name, $database ) = array_map( 'trim', $parts );
225  if ( strstr( $database, '*' ) ) { // Search for wildcard in database name
226  $doUserRightsLogLike = true;
227  }
228  }
229  }
230 
244  $this->mConds['log_namespace'] = $ns;
245  if ( $doUserRightsLogLike ) {
246  $params = [ $name . $wgUserrightsInterwikiDelimiter ];
247  foreach ( explode( '*', $database ) as $databasepart ) {
248  $params[] = $databasepart;
249  $params[] = $db->anyString();
250  }
251  array_pop( $params ); // Get rid of the last % we added.
252  $this->mConds[] = 'log_title' . $db->buildLike( $params );
253  } elseif ( $pattern && !$wgMiserMode ) {
254  $this->mConds[] = 'log_title' . $db->buildLike( $title->getDBkey(), $db->anyString() );
255  $this->pattern = $pattern;
256  } else {
257  $this->mConds['log_title'] = $title->getDBkey();
258  }
259  // Paranoia: avoid brute force searches (T19342)
260  $user = $this->getUser();
261  if ( !$user->isAllowed( 'deletedhistory' ) ) {
262  $this->mConds[] = $db->bitAnd( 'log_deleted', LogPage::DELETED_ACTION ) . ' = 0';
263  } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
264  $this->mConds[] = $db->bitAnd( 'log_deleted', LogPage::SUPPRESSED_ACTION ) .
266  }
267  }
268 
274  private function limitAction( $action ) {
275  global $wgActionFilteredLogs;
276  // Allow to filter the log by actions
278  if ( $type === '' ) {
279  // nothing to do
280  return;
281  }
282  $actions = $wgActionFilteredLogs;
283  if ( isset( $actions[$type] ) ) {
284  // log type can be filtered by actions
285  $this->mLogEventsList->setAllowedActions( array_keys( $actions[$type] ) );
286  if ( $action !== '' && isset( $actions[$type][$action] ) ) {
287  // add condition to query
288  $this->mConds['log_action'] = $actions[$type][$action];
289  $this->action = $action;
290  }
291  }
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  $index = [];
309  # Add log_search table if there are conditions on it.
310  # This filters the results to only include log rows that have
311  # log_search records with the specified ls_field and ls_value values.
312  if ( array_key_exists( 'ls_field', $this->mConds ) ) {
313  $tables[] = 'log_search';
314  $index['log_search'] = 'ls_field_val';
315  $index['logging'] = 'PRIMARY';
316  if ( !$this->hasEqualsClause( 'ls_field' )
317  || !$this->hasEqualsClause( 'ls_value' )
318  ) {
319  # Since (ls_field,ls_value,ls_logid) is unique, if the condition is
320  # to match a specific (ls_field,ls_value) tuple, then there will be
321  # no duplicate log rows. Otherwise, we need to remove the duplicates.
322  $options[] = 'DISTINCT';
323  }
324  }
325  if ( count( $index ) ) {
326  $options['USE INDEX'] = $index;
327  }
328  # Don't show duplicate rows when using log_search
329  $joins['log_search'] = [ 'INNER JOIN', 'ls_log_id=log_id' ];
330 
331  $info = [
332  'tables' => $tables,
333  'fields' => $fields,
334  'conds' => array_merge( $conds, $this->mConds ),
335  'options' => $options,
336  'join_conds' => $joins,
337  ];
338  # Add ChangeTags filter query
339  ChangeTags::modifyDisplayQuery( $info['tables'], $info['fields'], $info['conds'],
340  $info['join_conds'], $info['options'], $this->mTagFilter );
341 
342  return $info;
343  }
344 
350  protected function hasEqualsClause( $field ) {
351  return (
352  array_key_exists( $field, $this->mConds ) &&
353  ( !is_array( $this->mConds[$field] ) || count( $this->mConds[$field] ) == 1 )
354  );
355  }
356 
357  function getIndexField() {
358  return 'log_timestamp';
359  }
360 
361  public function getStartBody() {
362  # Do a link batch query
363  if ( $this->getNumRows() > 0 ) {
364  $lb = new LinkBatch;
365  foreach ( $this->mResult as $row ) {
366  $lb->add( $row->log_namespace, $row->log_title );
367  $lb->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
368  $lb->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_name ) );
369  $formatter = LogFormatter::newFromRow( $row );
370  foreach ( $formatter->getPreloadTitles() as $title ) {
371  $lb->addObj( $title );
372  }
373  }
374  $lb->execute();
375  $this->mResult->seek( 0 );
376  }
377 
378  return '';
379  }
380 
381  public function formatRow( $row ) {
382  return $this->mLogEventsList->logLine( $row );
383  }
384 
385  public function getType() {
386  return $this->types;
387  }
388 
394  public function getPerformer() {
395  return $this->performer;
396  }
397 
401  public function getPage() {
402  return $this->title;
403  }
404 
405  public function getPattern() {
406  return $this->pattern;
407  }
408 
409  public function getYear() {
410  return $this->mYear;
411  }
412 
413  public function getMonth() {
414  return $this->mMonth;
415  }
416 
417  public function getTagFilter() {
418  return $this->mTagFilter;
419  }
420 
421  public function getAction() {
422  return $this->action;
423  }
424 
425  public function doQuery() {
426  // Workaround MySQL optimizer bug
427  $this->mDb->setBigSelects();
428  parent::doQuery();
429  $this->mDb->setBigSelects( 'default' );
430  }
431 }
ReverseChronologicalPager\getDateCond
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...
Definition: ReverseChronologicalPager.php:73
LogPage\SUPPRESSED_ACTION
const SUPPRESSED_ACTION
Definition: LogPage.php:39
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:265
LogPage\SUPPRESSED_USER
const SUPPRESSED_USER
Definition: LogPage.php:38
LogPager\getPattern
getPattern()
Definition: LogPager.php:405
$tables
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:990
LogPager\getType
getType()
Definition: LogPager.php:385
LinkBatch
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition: LinkBatch.php:34
LinkBatch\add
add( $ns, $dbkey)
Definition: LinkBatch.php:81
LogPager\getPerformer
getPerformer()
Guaranteed to either return a valid title string or a Zero-Length String.
Definition: LogPager.php:394
LogPager\limitTitle
limitTitle( $page, $pattern)
Set the log reader to return only entries affecting the given page.
Definition: LogPager.php:204
LogPager\getMonth
getMonth()
Definition: LogPager.php:413
LogPager\getFilterParams
getFilterParams()
Definition: LogPager.php:95
captcha-old.count
count
Definition: captcha-old.py:225
LogPager\$types
array $types
Log types.
Definition: LogPager.php:31
DatabaseLogEntry\getSelectQueryData
static getSelectQueryData()
Returns array of information that is needed for querying log entries.
Definition: LogEntry.php:172
LogPager\getQueryInfo
getQueryInfo()
Constructs the most part of the query.
Definition: LogPager.php:299
Title\getPrefixedText
getPrefixedText()
Get the prefixed title with spaces.
Definition: Title.php:1451
$user
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 account $user
Definition: hooks.txt:246
LogPager
Definition: LogPager.php:29
$params
$params
Definition: styleTest.css.php:40
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:304
ContextSource\getRequest
getRequest()
Get the WebRequest object.
Definition: ContextSource.php:78
$type
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:2536
ContextSource\getUser
getUser()
Get the User object.
Definition: ContextSource.php:133
php
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
IndexPager\$mDb
$mDb
Definition: IndexPager.php:83
LogPager\getPage
getPage()
Definition: LogPager.php:401
LogPager\$title
string Title $title
Events limited to those about Title when set.
Definition: LogPager.php:37
$query
null for the 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:1572
Title\getDBkey
getDBkey()
Get the main part with underscores.
Definition: Title.php:901
LogPager\$action
string $action
Definition: LogPager.php:46
ChangeTags\modifyDisplayQuery
static modifyDisplayQuery(&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag=false)
Applies all tags-related changes to a query.
Definition: ChangeTags.php:632
LogPager\formatRow
formatRow( $row)
Abstract formatting function.
Definition: LogPager.php:381
LogFormatter\newFromRow
static newFromRow( $row)
Handy shortcut for constructing a formatter directly from database row.
Definition: LogFormatter.php:74
LogPager\getIndexField
getIndexField()
This function should be overridden to return the name of the index fi- eld.
Definition: LogPager.php:357
Title\getNamespace
getNamespace()
Get the namespace index, i.e.
Definition: Title.php:924
LogPage\DELETED_USER
const DELETED_USER
Definition: LogPage.php:34
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3060
$page
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:2536
LogPager\__construct
__construct( $list, $types=[], $performer='', $title='', $pattern='', $conds=[], $year=false, $month=false, $tagFilter='', $action='')
Constructor.
Definition: LogPager.php:65
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
LogEventsList
Definition: LogEventsList.php:29
list
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
LogPage\DELETED_ACTION
const DELETED_ACTION
Definition: LogPage.php:32
captcha-old.action
action
Definition: captcha-old.py:189
LogPager\getStartBody
getStartBody()
Hook into getBody(), allows text to be inserted at the start.
Definition: LogPager.php:361
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:538
NS_USER_TALK
const NS_USER_TALK
Definition: Defines.php:65
title
title
Definition: parserTests.txt:211
LogEventsList\getExcludeClause
static getExcludeClause( $db, $audience='public', User $user=null)
SQL clause to skip forbidden log types for this user.
Definition: LogEventsList.php:717
LogPager\$mLogEventsList
LogEventsList $mLogEventsList
Definition: LogPager.php:49
LogPager\$typeCGI
string $typeCGI
Definition: LogPager.php:43
LogPager\doQuery
doQuery()
Do the query, using information from the object context.
Definition: LogPager.php:425
LogPager\getAction
getAction()
Definition: LogPager.php:421
ReverseChronologicalPager\$mYear
$mYear
Definition: ReverseChronologicalPager.php:31
LogPager\getTagFilter
getTagFilter()
Definition: LogPager.php:417
LogPager\$performer
string $performer
Events limited to those by performer when set.
Definition: LogPager.php:34
LogPager\limitType
limitType( $types)
Set the log reader to return only entries of the given type.
Definition: LogPager.php:122
IP\sanitizeIP
static sanitizeIP( $ip)
Convert an IP into a verbose, uppercase, normalized form.
Definition: IP.php:140
LogPager\limitPerformer
limitPerformer( $name)
Set the log reader to return only entries by the given user.
Definition: LogPager.php:166
Title
Represents a title within MediaWiki.
Definition: Title.php:39
LogPager\hasEqualsClause
hasEqualsClause( $field)
Checks if $this->mConds has $field matched to a single value.
Definition: LogPager.php:350
$wgMiserMode
$wgMiserMode
Disable database-intensive features.
Definition: DefaultSettings.php:2144
LogPager\$pattern
string $pattern
Definition: LogPager.php:40
LogPager\getDefaultQuery
getDefaultQuery()
Get an array of query parameters that should be put into self-links.
Definition: LogPager.php:84
User\idFromName
static idFromName( $name, $flags=self::READ_NORMAL)
Get database id given a user name.
Definition: User.php:759
as
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
ReverseChronologicalPager\$mMonth
$mMonth
Definition: ReverseChronologicalPager.php:32
NS_USER
const NS_USER
Definition: Defines.php:64
ReverseChronologicalPager
IndexPager with a formatted navigation bar.
Definition: ReverseChronologicalPager.php:29
LogPager\limitAction
limitAction( $action)
Set the log_action field to a specified value (or values)
Definition: LogPager.php:274
$options
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:1049
IndexPager\getNumRows
getNumRows()
Get the number of rows in the result set.
Definition: IndexPager.php:555
array
the array() calling protocol came about after MediaWiki 1.4rc1.
LogPager\getYear
getYear()
Definition: LogPager.php:409