MediaWiki REL1_30
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
64 public function __construct( $list, $types = [], $performer = '', $title = '',
65 $pattern = '', $conds = [], $year = false, $month = false, $tagFilter = '',
66 $action = '', $logId = false
67 ) {
68 parent::__construct( $list->getContext() );
69 $this->mConds = $conds;
70
71 $this->mLogEventsList = $list;
72
73 $this->limitType( $types ); // also excludes hidden types
74 $this->limitPerformer( $performer );
75 $this->limitTitle( $title, $pattern );
76 $this->limitAction( $action );
77 $this->getDateCond( $year, $month );
78 $this->mTagFilter = $tagFilter;
79 $this->limitLogId( $logId );
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 ) .
191 }
192
193 $this->performer = $name;
194 }
195
204 private function limitTitle( $page, $pattern ) {
206
207 if ( $page instanceof Title ) {
208 $title = $page;
209 } else {
210 $title = Title::newFromText( $page );
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 ) {
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 ) {
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
298 protected function limitLogId( $logId ) {
299 if ( !$logId ) {
300 return;
301 }
302 $this->mConds['log_id'] = $logId;
303 }
304
310 public function getQueryInfo() {
312
313 $tables = $basic['tables'];
314 $fields = $basic['fields'];
315 $conds = $basic['conds'];
316 $options = $basic['options'];
317 $joins = $basic['join_conds'];
318
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 $options['IGNORE INDEX'] = [ 'log_search' => 'ls_log_id' ];
325 $options['USE 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 # Don't show duplicate rows when using log_search
336 $joins['log_search'] = [ 'INNER JOIN', 'ls_log_id=log_id' ];
337
338 $info = [
339 'tables' => $tables,
340 'fields' => $fields,
341 'conds' => array_merge( $conds, $this->mConds ),
342 'options' => $options,
343 'join_conds' => $joins,
344 ];
345 # Add ChangeTags filter query
346 ChangeTags::modifyDisplayQuery( $info['tables'], $info['fields'], $info['conds'],
347 $info['join_conds'], $info['options'], $this->mTagFilter );
348
349 return $info;
350 }
351
357 protected function hasEqualsClause( $field ) {
358 return (
359 array_key_exists( $field, $this->mConds ) &&
360 ( !is_array( $this->mConds[$field] ) || count( $this->mConds[$field] ) == 1 )
361 );
362 }
363
364 function getIndexField() {
365 return 'log_timestamp';
366 }
367
368 public function getStartBody() {
369 # Do a link batch query
370 if ( $this->getNumRows() > 0 ) {
371 $lb = new LinkBatch;
372 foreach ( $this->mResult as $row ) {
373 $lb->add( $row->log_namespace, $row->log_title );
374 $lb->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
375 $lb->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_name ) );
376 $formatter = LogFormatter::newFromRow( $row );
377 foreach ( $formatter->getPreloadTitles() as $title ) {
378 $lb->addObj( $title );
379 }
380 }
381 $lb->execute();
382 $this->mResult->seek( 0 );
383 }
384
385 return '';
386 }
387
388 public function formatRow( $row ) {
389 return $this->mLogEventsList->logLine( $row );
390 }
391
392 public function getType() {
393 return $this->types;
394 }
395
401 public function getPerformer() {
402 return $this->performer;
403 }
404
408 public function getPage() {
409 return $this->title;
410 }
411
412 public function getPattern() {
413 return $this->pattern;
414 }
415
416 public function getYear() {
417 return $this->mYear;
418 }
419
420 public function getMonth() {
421 return $this->mMonth;
422 }
423
424 public function getTagFilter() {
425 return $this->mTagFilter;
426 }
427
428 public function getAction() {
429 return $this->action;
430 }
431
432 public function doQuery() {
433 // Workaround MySQL optimizer bug
434 $this->mDb->setBigSelects();
435 parent::doQuery();
436 $this->mDb->setBigSelects( 'default' );
437 }
438}
$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='')
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:172
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:34
add( $ns, $dbkey)
Definition LinkBatch.php:80
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:38
const DELETED_USER
Definition LogPage.php:34
const DELETED_ACTION
Definition LogPage.php:32
const SUPPRESSED_ACTION
Definition LogPage.php:39
hasEqualsClause( $field)
Checks if $this->mConds has $field matched to a single value.
Definition LogPager.php:357
__construct( $list, $types=[], $performer='', $title='', $pattern='', $conds=[], $year=false, $month=false, $tagFilter='', $action='', $logId=false)
Definition LogPager.php:64
string Title $title
Events limited to those about Title when set.
Definition LogPager.php:37
formatRow( $row)
Abstract formatting function.
Definition LogPager.php:388
limitType( $types)
Set the log reader to return only entries of the given type.
Definition LogPager.php:122
getStartBody()
Hook into getBody(), allows text to be inserted at the start.
Definition LogPager.php:368
limitLogId( $logId)
Limit to the (single) specified log ID.
Definition LogPager.php:298
string $performer
Events limited to those by performer when set.
Definition LogPager.php:34
getFilterParams()
Definition LogPager.php:95
getDefaultQuery()
Get an array of query parameters that should be put into self-links.
Definition LogPager.php:84
limitTitle( $page, $pattern)
Set the log reader to return only entries affecting the given page.
Definition LogPager.php:204
string $action
Definition LogPager.php:46
getTagFilter()
Definition LogPager.php:424
LogEventsList $mLogEventsList
Definition LogPager.php:49
getQueryInfo()
Constructs the most part of the query.
Definition LogPager.php:310
doQuery()
Do the query, using information from the object context.
Definition LogPager.php:432
string $pattern
Definition LogPager.php:40
getPerformer()
Guaranteed to either return a valid title string or a Zero-Length String.
Definition LogPager.php:401
string $typeCGI
Definition LogPager.php:43
limitPerformer( $name)
Set the log reader to return only entries by the given user.
Definition LogPager.php:166
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:364
limitAction( $action)
Set the log_action field to a specified value (or values)
Definition LogPager.php:274
Efficient paging for SQL queries.
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...
Represents a title within MediaWiki.
Definition Title.php:39
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
the array() calling protocol came about after MediaWiki 1.4rc1.
info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED! Use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language & $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED! Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language & $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) action
Definition hooks.txt:1855
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:1013
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:1971
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:302
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:1610
const NS_USER_TALK
Definition Defines.php:68
const DB_REPLICA
Definition defines.php:25
$params