MediaWiki  1.30.0
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 
63  public function __construct( $list, $types = [], $performer = '', $title = '',
64  $pattern = '', $conds = [], $year = false, $month = false, $tagFilter = '',
65  $action = ''
66  ) {
67  parent::__construct( $list->getContext() );
68  $this->mConds = $conds;
69 
70  $this->mLogEventsList = $list;
71 
72  $this->limitType( $types ); // also excludes hidden types
73  $this->limitPerformer( $performer );
74  $this->limitTitle( $title, $pattern );
75  $this->limitAction( $action );
76  $this->getDateCond( $year, $month );
77  $this->mTagFilter = $tagFilter;
78 
79  $this->mDb = wfGetDB( DB_REPLICA, 'logpager' );
80  }
81 
82  public function getDefaultQuery() {
83  $query = parent::getDefaultQuery();
84  $query['type'] = $this->typeCGI; // arrays won't work here
85  $query['user'] = $this->performer;
86  $query['month'] = $this->mMonth;
87  $query['year'] = $this->mYear;
88 
89  return $query;
90  }
91 
92  // Call ONLY after calling $this->limitType() already!
93  public function getFilterParams() {
95  $filters = [];
96  if ( count( $this->types ) ) {
97  return $filters;
98  }
99  foreach ( $wgFilterLogTypes as $type => $default ) {
100  // Avoid silly filtering
101  if ( $type !== 'patrol' || $this->getUser()->useNPPatrol() ) {
102  $hide = $this->getRequest()->getInt( "hide_{$type}_log", $default );
103  $filters[$type] = $hide;
104  if ( $hide ) {
105  $this->mConds[] = 'log_type != ' . $this->mDb->addQuotes( $type );
106  }
107  }
108  }
109 
110  return $filters;
111  }
112 
120  private function limitType( $types ) {
122 
123  $user = $this->getUser();
124  // If $types is not an array, make it an array
125  $types = ( $types === '' ) ? [] : (array)$types;
126  // Don't even show header for private logs; don't recognize it...
127  $needReindex = false;
128  foreach ( $types as $type ) {
129  if ( isset( $wgLogRestrictions[$type] )
130  && !$user->isAllowed( $wgLogRestrictions[$type] )
131  ) {
132  $needReindex = true;
133  $types = array_diff( $types, [ $type ] );
134  }
135  }
136  if ( $needReindex ) {
137  // Lots of this code makes assumptions that
138  // the first entry in the array is $types[0].
139  $types = array_values( $types );
140  }
141  $this->types = $types;
142  // Don't show private logs to unprivileged users.
143  // Also, only show them upon specific request to avoid suprises.
144  $audience = $types ? 'user' : 'public';
145  $hideLogs = LogEventsList::getExcludeClause( $this->mDb, $audience, $user );
146  if ( $hideLogs !== false ) {
147  $this->mConds[] = $hideLogs;
148  }
149  if ( count( $types ) ) {
150  $this->mConds['log_type'] = $types;
151  // Set typeCGI; used in url param for paging
152  if ( count( $types ) == 1 ) {
153  $this->typeCGI = $types[0];
154  }
155  }
156  }
157 
164  private function limitPerformer( $name ) {
165  if ( $name == '' ) {
166  return;
167  }
168  $usertitle = Title::makeTitleSafe( NS_USER, $name );
169  if ( is_null( $usertitle ) ) {
170  return;
171  }
172  // Normalize username first so that non-existent users used
173  // in maintenance scripts work
174  $name = $usertitle->getText();
175  /* Fetch userid at first, if known, provides awesome query plan afterwards */
176  $userid = User::idFromName( $name );
177  if ( !$userid ) {
178  $this->mConds['log_user_text'] = IP::sanitizeIP( $name );
179  } else {
180  $this->mConds['log_user'] = $userid;
181  }
182  // Paranoia: avoid brute force searches (T19342)
183  $user = $this->getUser();
184  if ( !$user->isAllowed( 'deletedhistory' ) ) {
185  $this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::DELETED_USER ) . ' = 0';
186  } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
187  $this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::SUPPRESSED_USER ) .
188  ' != ' . LogPage::SUPPRESSED_USER;
189  }
190 
191  $this->performer = $name;
192  }
193 
202  private function limitTitle( $page, $pattern ) {
204 
205  if ( $page instanceof Title ) {
206  $title = $page;
207  } else {
208  $title = Title::newFromText( $page );
209  if ( strlen( $page ) == 0 || !$title instanceof Title ) {
210  return;
211  }
212  }
213 
214  $this->title = $title->getPrefixedText();
215  $ns = $title->getNamespace();
216  $db = $this->mDb;
217 
218  $doUserRightsLogLike = false;
219  if ( $this->types == [ 'rights' ] ) {
220  $parts = explode( $wgUserrightsInterwikiDelimiter, $title->getDBkey() );
221  if ( count( $parts ) == 2 ) {
222  list( $name, $database ) = array_map( 'trim', $parts );
223  if ( strstr( $database, '*' ) ) { // Search for wildcard in database name
224  $doUserRightsLogLike = true;
225  }
226  }
227  }
228 
242  $this->mConds['log_namespace'] = $ns;
243  if ( $doUserRightsLogLike ) {
245  foreach ( explode( '*', $database ) as $databasepart ) {
246  $params[] = $databasepart;
247  $params[] = $db->anyString();
248  }
249  array_pop( $params ); // Get rid of the last % we added.
250  $this->mConds[] = 'log_title' . $db->buildLike( $params );
251  } elseif ( $pattern && !$wgMiserMode ) {
252  $this->mConds[] = 'log_title' . $db->buildLike( $title->getDBkey(), $db->anyString() );
253  $this->pattern = $pattern;
254  } else {
255  $this->mConds['log_title'] = $title->getDBkey();
256  }
257  // Paranoia: avoid brute force searches (T19342)
258  $user = $this->getUser();
259  if ( !$user->isAllowed( 'deletedhistory' ) ) {
260  $this->mConds[] = $db->bitAnd( 'log_deleted', LogPage::DELETED_ACTION ) . ' = 0';
261  } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
262  $this->mConds[] = $db->bitAnd( 'log_deleted', LogPage::SUPPRESSED_ACTION ) .
264  }
265  }
266 
272  private function limitAction( $action ) {
274  // Allow to filter the log by actions
276  if ( $type === '' ) {
277  // nothing to do
278  return;
279  }
280  $actions = $wgActionFilteredLogs;
281  if ( isset( $actions[$type] ) ) {
282  // log type can be filtered by actions
283  $this->mLogEventsList->setAllowedActions( array_keys( $actions[$type] ) );
284  if ( $action !== '' && isset( $actions[$type][$action] ) ) {
285  // add condition to query
286  $this->mConds['log_action'] = $actions[$type][$action];
287  $this->action = $action;
288  }
289  }
290  }
291 
297  public function getQueryInfo() {
299 
300  $tables = $basic['tables'];
301  $fields = $basic['fields'];
302  $conds = $basic['conds'];
303  $options = $basic['options'];
304  $joins = $basic['join_conds'];
305 
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  $options['IGNORE INDEX'] = [ 'log_search' => 'ls_log_id' ];
312  $options['USE 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  # Don't show duplicate rows when using log_search
323  $joins['log_search'] = [ 'INNER JOIN', 'ls_log_id=log_id' ];
324 
325  $info = [
326  'tables' => $tables,
327  'fields' => $fields,
328  'conds' => array_merge( $conds, $this->mConds ),
329  'options' => $options,
330  'join_conds' => $joins,
331  ];
332  # Add ChangeTags filter query
333  ChangeTags::modifyDisplayQuery( $info['tables'], $info['fields'], $info['conds'],
334  $info['join_conds'], $info['options'], $this->mTagFilter );
335 
336  return $info;
337  }
338 
344  protected function hasEqualsClause( $field ) {
345  return (
346  array_key_exists( $field, $this->mConds ) &&
347  ( !is_array( $this->mConds[$field] ) || count( $this->mConds[$field] ) == 1 )
348  );
349  }
350 
351  function getIndexField() {
352  return 'log_timestamp';
353  }
354 
355  public function getStartBody() {
356  # Do a link batch query
357  if ( $this->getNumRows() > 0 ) {
358  $lb = new LinkBatch;
359  foreach ( $this->mResult as $row ) {
360  $lb->add( $row->log_namespace, $row->log_title );
361  $lb->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
362  $lb->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_name ) );
363  $formatter = LogFormatter::newFromRow( $row );
364  foreach ( $formatter->getPreloadTitles() as $title ) {
365  $lb->addObj( $title );
366  }
367  }
368  $lb->execute();
369  $this->mResult->seek( 0 );
370  }
371 
372  return '';
373  }
374 
375  public function formatRow( $row ) {
376  return $this->mLogEventsList->logLine( $row );
377  }
378 
379  public function getType() {
380  return $this->types;
381  }
382 
388  public function getPerformer() {
389  return $this->performer;
390  }
391 
395  public function getPage() {
396  return $this->title;
397  }
398 
399  public function getPattern() {
400  return $this->pattern;
401  }
402 
403  public function getYear() {
404  return $this->mYear;
405  }
406 
407  public function getMonth() {
408  return $this->mMonth;
409  }
410 
411  public function getTagFilter() {
412  return $this->mTagFilter;
413  }
414 
415  public function getAction() {
416  return $this->action;
417  }
418 
419  public function doQuery() {
420  // Workaround MySQL optimizer bug
421  $this->mDb->setBigSelects();
422  parent::doQuery();
423  $this->mDb->setBigSelects( 'default' );
424  }
425 }
$wgActionFilteredLogs
$wgActionFilteredLogs
List of log types that can be filtered by action types.
Definition: DefaultSettings.php:7727
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
$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:244
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:268
LogPage\SUPPRESSED_USER
const SUPPRESSED_USER
Definition: LogPage.php:38
LogPager\getPattern
getPattern()
Definition: LogPager.php:399
$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:988
LogPager\getType
getType()
Definition: LogPager.php:379
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:80
LogPager\getPerformer
getPerformer()
Guaranteed to either return a valid title string or a Zero-Length String.
Definition: LogPager.php:388
LogPager\limitTitle
limitTitle( $page, $pattern)
Set the log reader to return only entries affecting the given page.
Definition: LogPager.php:202
LogPager\getMonth
getMonth()
Definition: LogPager.php:407
LogPager\getFilterParams
getFilterParams()
Definition: LogPager.php:93
captcha-old.count
count
Definition: captcha-old.py:249
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:297
Title\getPrefixedText
getPrefixedText()
Get the prefixed title with spaces.
Definition: Title.php:1550
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:302
ContextSource\getRequest
getRequest()
Get the WebRequest object.
Definition: ContextSource.php:78
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
title
to move a page</td >< td > &*You are moving the page across *A non empty talk page already exists under the new or *You uncheck the box below In those you will have to move or merge the page manually if desired</td >< td > be sure to &You are responsible for making sure that links continue to point where they are supposed to go Note that the page will &a page at the new title
Definition: All_system_messages.txt:2696
LogPager\getPage
getPage()
Definition: LogPager.php:395
ChangeTags\modifyDisplayQuery
static modifyDisplayQuery(&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag='')
Applies all tags-related changes to a query.
Definition: ChangeTags.php:661
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:1581
Title\getDBkey
getDBkey()
Get the main part with underscores.
Definition: Title.php:955
LogPager\$action
string $action
Definition: LogPager.php:46
LogPager\formatRow
formatRow( $row)
Abstract formatting function.
Definition: LogPager.php:375
LogFormatter\newFromRow
static newFromRow( $row)
Handy shortcut for constructing a formatter directly from database row.
Definition: LogFormatter.php:76
LogPager\getIndexField
getIndexField()
This function should be overridden to return the name of the index fi- eld.
Definition: LogPager.php:351
Title\getNamespace
getNamespace()
Get the namespace index, i.e.
Definition: Title.php:978
$wgFilterLogTypes
$wgFilterLogTypes
Show/hide links on Special:Log will be shown for these log types.
Definition: DefaultSettings.php:7615
LogPage\DELETED_USER
const DELETED_USER
Definition: LogPage.php:34
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2856
$wgUserrightsInterwikiDelimiter
$wgUserrightsInterwikiDelimiter
Character used as a delimiter when testing for interwiki userrights (In Special:UserRights,...
Definition: DefaultSettings.php:4947
LogPager\__construct
__construct( $list, $types=[], $performer='', $title='', $pattern='', $conds=[], $year=false, $month=false, $tagFilter='', $action='')
Definition: LogPager.php:63
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:30
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:212
LogPager\getStartBody
getStartBody()
Hook into getBody(), allows text to be inserted at the start.
Definition: LogPager.php:355
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:557
NS_USER_TALK
const NS_USER_TALK
Definition: Defines.php:68
$wgLogRestrictions
$wgLogRestrictions
This restricts log access to those who have a certain right Users without this will not see it in the...
Definition: DefaultSettings.php:7592
LogEventsList\getExcludeClause
static getExcludeClause( $db, $audience='public', User $user=null)
SQL clause to skip forbidden log types for this user.
Definition: LogEventsList.php:750
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:419
LogPager\getAction
getAction()
Definition: LogPager.php:415
ReverseChronologicalPager\$mYear
$mYear
Definition: ReverseChronologicalPager.php:30
LogPager\getTagFilter
getTagFilter()
Definition: LogPager.php:411
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:120
IP\sanitizeIP
static sanitizeIP( $ip)
Convert an IP into a verbose, uppercase, normalized form.
Definition: IP.php:152
LogPager\limitPerformer
limitPerformer( $name)
Set the log reader to return only entries by the given user.
Definition: LogPager.php:164
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:344
$wgMiserMode
$wgMiserMode
Disable database-intensive features.
Definition: DefaultSettings.php:2166
LogPager\$pattern
string $pattern
Definition: LogPager.php:40
$options
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:1965
LogPager\getDefaultQuery
getDefaultQuery()
Get an array of query parameters that should be put into self-links.
Definition: LogPager.php:82
User\idFromName
static idFromName( $name, $flags=self::READ_NORMAL)
Get database id given a user name.
Definition: User.php:765
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:31
NS_USER
const NS_USER
Definition: Defines.php:67
ReverseChronologicalPager
Efficient paging for SQL queries.
Definition: ReverseChronologicalPager.php:28
LogPager\limitAction
limitAction( $action)
Set the log_action field to a specified value (or values)
Definition: LogPager.php:272
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:403
$type
$type
Definition: testCompression.php:48