MediaWiki  1.23.14
LogPager.php
Go to the documentation of this file.
1 <?php
31  private $types = array();
32 
34  private $performer = '';
35 
37  private $title = '';
38 
40  private $pattern = '';
41 
43  private $typeCGI = '';
44 
46  public $mLogEventsList;
47 
61  public function __construct( $list, $types = array(), $performer = '', $title = '', $pattern = '',
62  $conds = array(), $year = false, $month = false, $tagFilter = '' ) {
63  parent::__construct( $list->getContext() );
64  $this->mConds = $conds;
65 
66  $this->mLogEventsList = $list;
67 
68  $this->limitType( $types ); // also excludes hidden types
69  $this->limitPerformer( $performer );
70  $this->limitTitle( $title, $pattern );
71  $this->getDateCond( $year, $month );
72  $this->mTagFilter = $tagFilter;
73 
74  $this->mDb = wfGetDB( DB_SLAVE, 'logpager' );
75  }
76 
77  public function getDefaultQuery() {
78  $query = parent::getDefaultQuery();
79  $query['type'] = $this->typeCGI; // arrays won't work here
80  $query['user'] = $this->performer;
81  $query['month'] = $this->mMonth;
82  $query['year'] = $this->mYear;
83 
84  return $query;
85  }
86 
87  // Call ONLY after calling $this->limitType() already!
88  public function getFilterParams() {
89  global $wgFilterLogTypes;
90  $filters = array();
91  if ( count( $this->types ) ) {
92  return $filters;
93  }
94  foreach ( $wgFilterLogTypes as $type => $default ) {
95  // Avoid silly filtering
96  if ( $type !== 'patrol' || $this->getUser()->useNPPatrol() ) {
97  $hide = $this->getRequest()->getInt( "hide_{$type}_log", $default );
98  $filters[$type] = $hide;
99  if ( $hide ) {
100  $this->mConds[] = 'log_type != ' . $this->mDb->addQuotes( $type );
101  }
102  }
103  }
104 
105  return $filters;
106  }
107 
115  private function limitType( $types ) {
116  global $wgLogRestrictions;
117 
118  $user = $this->getUser();
119  // If $types is not an array, make it an array
120  $types = ( $types === '' ) ? array() : (array)$types;
121  // Don't even show header for private logs; don't recognize it...
122  $needReindex = false;
123  foreach ( $types as $type ) {
124  if ( isset( $wgLogRestrictions[$type] )
125  && !$user->isAllowed( $wgLogRestrictions[$type] )
126  ) {
127  $needReindex = true;
128  $types = array_diff( $types, array( $type ) );
129  }
130  }
131  if ( $needReindex ) {
132  // Lots of this code makes assumptions that
133  // the first entry in the array is $types[0].
134  $types = array_values( $types );
135  }
136  $this->types = $types;
137  // Don't show private logs to unprivileged users.
138  // Also, only show them upon specific request to avoid suprises.
139  $audience = $types ? 'user' : 'public';
140  $hideLogs = LogEventsList::getExcludeClause( $this->mDb, $audience, $user );
141  if ( $hideLogs !== false ) {
142  $this->mConds[] = $hideLogs;
143  }
144  if ( count( $types ) ) {
145  $this->mConds['log_type'] = $types;
146  // Set typeCGI; used in url param for paging
147  if ( count( $types ) == 1 ) {
148  $this->typeCGI = $types[0];
149  }
150  }
151  }
152 
159  private function limitPerformer( $name ) {
160  if ( $name == '' ) {
161  return;
162  }
163  $usertitle = Title::makeTitleSafe( NS_USER, $name );
164  if ( is_null( $usertitle ) ) {
165  return;
166  }
167  /* Fetch userid at first, if known, provides awesome query plan afterwards */
168  $userid = User::idFromName( $name );
169  if ( !$userid ) {
170  $this->mConds['log_user_text'] = IP::sanitizeIP( $name );
171  } else {
172  $this->mConds['log_user'] = $userid;
173  }
174  // Paranoia: avoid brute force searches (bug 17342)
175  $user = $this->getUser();
176  if ( !$user->isAllowed( 'deletedhistory' ) ) {
177  $this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::DELETED_USER ) . ' = 0';
178  } elseif ( !$user->isAllowed( 'suppressrevision' ) ) {
179  $this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::SUPPRESSED_USER ) .
180  ' != ' . LogPage::SUPPRESSED_USER;
181  }
182 
183  $this->performer = $usertitle->getText();
184  }
185 
194  private function limitTitle( $page, $pattern ) {
195  global $wgMiserMode;
196 
197  if ( $page instanceof Title ) {
198  $title = $page;
199  } else {
200  $title = Title::newFromText( $page );
201  if ( strlen( $page ) == 0 || !$title instanceof Title ) {
202  return;
203  }
204  }
205 
206  $this->title = $title->getPrefixedText();
207  $ns = $title->getNamespace();
208  $db = $this->mDb;
209 
210  # Using the (log_namespace, log_title, log_timestamp) index with a
211  # range scan (LIKE) on the first two parts, instead of simple equality,
212  # makes it unusable for sorting. Sorted retrieval using another index
213  # would be possible, but then we might have to scan arbitrarily many
214  # nodes of that index. Therefore, we need to avoid this if $wgMiserMode
215  # is on.
216  #
217  # This is not a problem with simple title matches, because then we can
218  # use the page_time index. That should have no more than a few hundred
219  # log entries for even the busiest pages, so it can be safely scanned
220  # in full to satisfy an impossible condition on user or similar.
221  if ( $pattern && !$wgMiserMode ) {
222  $this->mConds['log_namespace'] = $ns;
223  $this->mConds[] = 'log_title ' . $db->buildLike( $title->getDBkey(), $db->anyString() );
224  $this->pattern = $pattern;
225  } else {
226  $this->mConds['log_namespace'] = $ns;
227  $this->mConds['log_title'] = $title->getDBkey();
228  }
229  // Paranoia: avoid brute force searches (bug 17342)
230  $user = $this->getUser();
231  if ( !$user->isAllowed( 'deletedhistory' ) ) {
232  $this->mConds[] = $db->bitAnd( 'log_deleted', LogPage::DELETED_ACTION ) . ' = 0';
233  } elseif ( !$user->isAllowed( 'suppressrevision' ) ) {
234  $this->mConds[] = $db->bitAnd( 'log_deleted', LogPage::SUPPRESSED_ACTION ) .
236  }
237  }
238 
244  public function getQueryInfo() {
246 
247  $tables = $basic['tables'];
248  $fields = $basic['fields'];
249  $conds = $basic['conds'];
250  $options = $basic['options'];
251  $joins = $basic['join_conds'];
252 
253  $index = array();
254  # Add log_search table if there are conditions on it.
255  # This filters the results to only include log rows that have
256  # log_search records with the specified ls_field and ls_value values.
257  if ( array_key_exists( 'ls_field', $this->mConds ) ) {
258  $tables[] = 'log_search';
259  $index['log_search'] = 'ls_field_val';
260  $index['logging'] = 'PRIMARY';
261  if ( !$this->hasEqualsClause( 'ls_field' )
262  || !$this->hasEqualsClause( 'ls_value' )
263  ) {
264  # Since (ls_field,ls_value,ls_logid) is unique, if the condition is
265  # to match a specific (ls_field,ls_value) tuple, then there will be
266  # no duplicate log rows. Otherwise, we need to remove the duplicates.
267  $options[] = 'DISTINCT';
268  }
269  }
270  if ( count( $index ) ) {
271  $options['USE INDEX'] = $index;
272  }
273  # Don't show duplicate rows when using log_search
274  $joins['log_search'] = array( 'INNER JOIN', 'ls_log_id=log_id' );
275 
276  $info = array(
277  'tables' => $tables,
278  'fields' => $fields,
279  'conds' => array_merge( $conds, $this->mConds ),
280  'options' => $options,
281  'join_conds' => $joins,
282  );
283  # Add ChangeTags filter query
284  ChangeTags::modifyDisplayQuery( $info['tables'], $info['fields'], $info['conds'],
285  $info['join_conds'], $info['options'], $this->mTagFilter );
286 
287  return $info;
288  }
289 
295  protected function hasEqualsClause( $field ) {
296  return (
297  array_key_exists( $field, $this->mConds ) &&
298  ( !is_array( $this->mConds[$field] ) || count( $this->mConds[$field] ) == 1 )
299  );
300  }
301 
302  function getIndexField() {
303  return 'log_timestamp';
304  }
305 
306  public function getStartBody() {
307  wfProfileIn( __METHOD__ );
308  # Do a link batch query
309  if ( $this->getNumRows() > 0 ) {
310  $lb = new LinkBatch;
311  foreach ( $this->mResult as $row ) {
312  $lb->add( $row->log_namespace, $row->log_title );
313  $lb->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
314  $lb->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_name ) );
315  $formatter = LogFormatter::newFromRow( $row );
316  foreach ( $formatter->getPreloadTitles() as $title ) {
317  $lb->addObj( $title );
318  }
319  }
320  $lb->execute();
321  $this->mResult->seek( 0 );
322  }
323  wfProfileOut( __METHOD__ );
324 
325  return '';
326  }
327 
328  public function formatRow( $row ) {
329  return $this->mLogEventsList->logLine( $row );
330  }
331 
332  public function getType() {
333  return $this->types;
334  }
335 
339  public function getPerformer() {
341  }
342 
346  public function getPage() {
347  return $this->title;
348  }
349 
350  public function getPattern() {
351  return $this->pattern;
352  }
353 
354  public function getYear() {
355  return $this->mYear;
356  }
357 
358  public function getMonth() {
359  return $this->mMonth;
360  }
361 
362  public function getTagFilter() {
363  return $this->mTagFilter;
364  }
365 
366  public function doQuery() {
367  // Workaround MySQL optimizer bug
368  $this->mDb->setBigSelects();
369  parent::doQuery();
370  $this->mDb->setBigSelects( 'default' );
371  }
372 }
LogPage\SUPPRESSED_ACTION
const SUPPRESSED_ACTION
Definition: LogPage.php:40
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:189
LogPage\SUPPRESSED_USER
const SUPPRESSED_USER
Definition: LogPage.php:39
LogPager\getPattern
getPattern()
Definition: LogPager.php:344
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
LogPager\getType
getType()
Definition: LogPager.php:326
LinkBatch
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition: LinkBatch.php:30
$tables
namespace and then decline to actually register it RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist & $tables
Definition: hooks.txt:815
LogPager\getPerformer
getPerformer()
Definition: LogPager.php:333
LogPager\limitTitle
limitTitle( $page, $pattern)
Set the log reader to return only entries affecting the given page.
Definition: LogPager.php:188
LogPager\getMonth
getMonth()
Definition: LogPager.php:352
LogPager\getFilterParams
getFilterParams()
Definition: LogPager.php:82
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3714
LogPager\$types
array $types
Log types *.
Definition: LogPager.php:30
DatabaseLogEntry\getSelectQueryData
static getSelectQueryData()
Returns array of information that is needed for querying log entries.
Definition: LogEntry.php:133
LogPager\getQueryInfo
getQueryInfo()
Constructs the most part of the query.
Definition: LogPager.php:238
wfProfileIn
wfProfileIn( $functionname)
Begin profiling of a function.
Definition: Profiler.php:33
Title\getPrefixedText
getPrefixedText()
Get the prefixed title with spaces.
Definition: Title.php:1369
LogPager
Definition: LogPager.php:29
ContextSource\getRequest
getRequest()
Get the WebRequest object.
Definition: ContextSource.php:77
ContextSource\getUser
getUser()
Get the User object.
Definition: ContextSource.php:132
IndexPager\$mDb
$mDb
Definition: Pager.php:85
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:2703
LogPager\getPage
getPage()
Definition: LogPager.php:340
LogPager\$title
string Title $title
Events limited to those about Title when set *.
Definition: LogPager.php:34
$lb
if( $wgAPIRequestLog) $lb
Definition: api.php:126
Title\getDBkey
getDBkey()
Get the main part with underscores.
Definition: Title.php:857
ChangeTags\modifyDisplayQuery
static modifyDisplayQuery(&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag=false)
Applies all tags-related changes to a query.
Definition: ChangeTags.php:202
LogPager\formatRow
formatRow( $row)
Abstract formatting function.
Definition: LogPager.php:322
LogFormatter\newFromRow
static newFromRow( $row)
Handy shortcut for constructing a formatter directly from database row.
Definition: LogFormatter.php:71
LogPager\getIndexField
getIndexField()
This function should be overridden to return the name of the index fi- eld.
Definition: LogPager.php:296
Title\getNamespace
getNamespace()
Get the namespace index, i.e.
Definition: Title.php:880
LogPage\DELETED_USER
const DELETED_USER
Definition: LogPage.php:35
LogPager\__construct
__construct( $list, $types=array(), $performer='', $title='', $pattern='', $conds=array(), $year=false, $month=false, $tagFilter='')
Constructor.
Definition: LogPager.php:55
wfProfileOut
wfProfileOut( $functionname='missing')
Stop profiling of a function.
Definition: Profiler.php:46
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
LogEventsList
Definition: LogEventsList.php:26
LogPage\DELETED_ACTION
const DELETED_ACTION
Definition: LogPage.php:33
$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:1530
LogPager\getStartBody
getStartBody()
Hook into getBody(), allows text to be inserted at the start.
Definition: LogPager.php:300
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:422
NS_USER_TALK
const NS_USER_TALK
Definition: Defines.php:82
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
LogEventsList\getExcludeClause
static getExcludeClause( $db, $audience='public', User $user=null)
SQL clause to skip forbidden log types for this user.
Definition: LogEventsList.php:651
LogPager\$mLogEventsList
LogEventsList $mLogEventsList
Definition: LogPager.php:40
LogPager\$typeCGI
string $typeCGI
Definition: LogPager.php:38
LogPager\doQuery
doQuery()
Do the query, using information from the object context.
Definition: LogPager.php:360
ReverseChronologicalPager\$mYear
$mYear
Definition: Pager.php:831
LogPager\getTagFilter
getTagFilter()
Definition: LogPager.php:356
$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:237
LogPager\$performer
string $performer
Events limited to those by performer when set *.
Definition: LogPager.php:32
LogPager\limitType
limitType( $types)
Set the log reader to return only entries of the given type.
Definition: LogPager.php:109
IP\sanitizeIP
static sanitizeIP( $ip)
Convert an IP into a verbose, uppercase, normalized form.
Definition: IP.php:135
DB_SLAVE
const DB_SLAVE
Definition: Defines.php:55
LogPager\limitPerformer
limitPerformer( $name)
Set the log reader to return only entries by the given user.
Definition: LogPager.php:153
Title
Represents a title within MediaWiki.
Definition: Title.php:35
LogPager\hasEqualsClause
hasEqualsClause( $field)
Checks if $this->mConds has $field matched to a single value.
Definition: LogPager.php:289
User\idFromName
static idFromName( $name)
Get database id given a user name.
Definition: User.php:503
LogPager\$pattern
string $pattern
Definition: LogPager.php:36
LogPager\getDefaultQuery
getDefaultQuery()
Get an array of query parameters that should be put into self-links.
Definition: LogPager.php:71
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: Pager.php:832
NS_USER
const NS_USER
Definition: Defines.php:81
ReverseChronologicalPager
IndexPager with a formatted navigation bar.
Definition: Pager.php:829
$query
return true to allow those checks to and false if checking is done use this to change the tables headers temp or archived zone change it to an object instance and return false override the list derivative used the name of the old file when set the default code will be skipped add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1105
ReverseChronologicalPager\getDateCond
getDateCond( $year, $month)
Definition: Pager.php:864
IndexPager\getNumRows
getNumRows()
Get the number of rows in the result set.
Definition: Pager.php:550
LogPager\getYear
getYear()
Definition: LogPager.php:348
$type
$type
Definition: testCompression.php:46