4e07cdb88618e10d0acd3ada56147dd73779ced5
[lhc/web/wiklou.git] / includes / LogEventsList.php
1 <?php
2 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>, 2008 Aaron Schulz
3 # http://www.mediawiki.org/
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # http://www.gnu.org/copyleft/gpl.html
19
20 class LogEventsList {
21 const NO_ACTION_LINK = 1;
22
23 private $skin;
24 private $out;
25 public $flags;
26
27 public function __construct( $skin, $out, $flags = 0 ) {
28 $this->skin = $skin;
29 $this->out = $out;
30 $this->flags = $flags;
31 $this->preCacheMessages();
32 }
33
34 /**
35 * As we use the same small set of messages in various methods and that
36 * they are called often, we call them once and save them in $this->message
37 */
38 private function preCacheMessages() {
39 // Precache various messages
40 if( !isset( $this->message ) ) {
41 $messages = array( 'revertmerge', 'protect_change', 'unblocklink', 'change-blocklink',
42 'revertmove', 'undeletelink', 'revdel-restore', 'rev-delundel', 'hist', 'pipe-separator' );
43 foreach( $messages as $msg ) {
44 $this->message[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
45 }
46 }
47 }
48
49 /**
50 * Set page title and show header for this log type
51 * @param $type String
52 */
53 public function showHeader( $type ) {
54 if( LogPage::isLogType( $type ) ) {
55 $this->out->setPageTitle( LogPage::logName( $type ) );
56 $this->out->addHTML( LogPage::logHeader( $type ) );
57 }
58 }
59
60 /**
61 * Show options for the log list
62 * @param $type String
63 * @param $user String
64 * @param $page String
65 * @param $pattern String
66 * @param $year Integer: year
67 * @param $month Integer: month
68 * @param $filter: array
69 * @param $tagFilter: array?
70 */
71 public function showOptions( $type = '', $user = '', $page = '', $pattern = '', $year = '',
72 $month = '', $filter = null, $tagFilter='' )
73 {
74 global $wgScript, $wgMiserMode;
75 $action = htmlspecialchars( $wgScript );
76 $title = SpecialPage::getTitleFor( 'Log' );
77 $special = htmlspecialchars( $title->getPrefixedDBkey() );
78
79 $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter );
80
81 $this->out->addHTML( "<form action=\"$action\" method=\"get\"><fieldset>" .
82 Xml::element( 'legend', array(), wfMsg( 'log' ) ) .
83 Xml::hidden( 'title', $special ) . "\n" .
84 $this->getTypeMenu( $type ) . "\n" .
85 $this->getUserInput( $user ) . "\n" .
86 $this->getTitleInput( $page ) . "\n" .
87 ( !$wgMiserMode ? ($this->getTitlePattern( $pattern )."\n") : "" ) .
88 "<p>" . Xml::dateMenu( $year, $month ) . "\n" .
89 ( $tagSelector ? Xml::tags( 'p', null, implode( '&nbsp;', $tagSelector ) ) :'' ). "\n" .
90 ( $filter ? "</p><p>".$this->getFilterLinks( $type, $filter )."\n" : "" ) . "\n" .
91 Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "</p>\n" .
92 "</fieldset></form>"
93 );
94 }
95
96 private function getFilterLinks( $logType, $filter ) {
97 global $wgTitle, $wgLang;
98 // show/hide links
99 $messages = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
100 // Option value -> message mapping
101 $links = array();
102 $hiddens = ''; // keep track for "go" button
103 foreach( $filter as $type => $val ) {
104 $hideVal = 1 - intval($val);
105 $link = $this->skin->makeKnownLinkObj( $wgTitle, $messages[$hideVal],
106 wfArrayToCGI( array( "hide_{$type}_log" => $hideVal ), $this->getDefaultQuery() )
107 );
108 $links[$type] = wfMsgHtml( "log-show-hide-{$type}", $link );
109 $hiddens .= Xml::hidden( "hide_{$type}_log", $val ) . "\n";
110 }
111 // Build links
112 return '<small>'.$wgLang->pipeList( $links ) . '</small>' . $hiddens;
113 }
114
115 private function getDefaultQuery() {
116 if ( !isset( $this->mDefaultQuery ) ) {
117 $this->mDefaultQuery = $_GET;
118 unset( $this->mDefaultQuery['title'] );
119 unset( $this->mDefaultQuery['dir'] );
120 unset( $this->mDefaultQuery['offset'] );
121 unset( $this->mDefaultQuery['limit'] );
122 unset( $this->mDefaultQuery['order'] );
123 unset( $this->mDefaultQuery['month'] );
124 unset( $this->mDefaultQuery['year'] );
125 }
126 return $this->mDefaultQuery;
127 }
128
129 /**
130 * @param $queryType String
131 * @return String: Formatted HTML
132 */
133 private function getTypeMenu( $queryType ) {
134 global $wgLogRestrictions, $wgUser;
135
136 $html = "<select name='type'>\n";
137
138 $validTypes = LogPage::validTypes();
139 $typesByName = array(); // Temporary array
140
141 // First pass to load the log names
142 foreach( $validTypes as $type ) {
143 $text = LogPage::logName( $type );
144 $typesByName[$text] = $type;
145 }
146
147 // Second pass to sort by name
148 ksort($typesByName);
149
150 // Third pass generates sorted XHTML content
151 foreach( $typesByName as $text => $type ) {
152 $selected = ($type == $queryType);
153 // Restricted types
154 if ( isset($wgLogRestrictions[$type]) ) {
155 if ( $wgUser->isAllowed( $wgLogRestrictions[$type] ) ) {
156 $html .= Xml::option( $text, $type, $selected ) . "\n";
157 }
158 } else {
159 $html .= Xml::option( $text, $type, $selected ) . "\n";
160 }
161 }
162
163 $html .= '</select>';
164 return $html;
165 }
166
167 /**
168 * @param $user String
169 * @return String: Formatted HTML
170 */
171 private function getUserInput( $user ) {
172 return Xml::inputLabel( wfMsg( 'specialloguserlabel' ), 'user', 'user', 15, $user );
173 }
174
175 /**
176 * @param $title String
177 * @return String: Formatted HTML
178 */
179 private function getTitleInput( $title ) {
180 return Xml::inputLabel( wfMsg( 'speciallogtitlelabel' ), 'page', 'page', 20, $title );
181 }
182
183 /**
184 * @return boolean Checkbox
185 */
186 private function getTitlePattern( $pattern ) {
187 return '<span style="white-space: nowrap">' .
188 Xml::checkLabel( wfMsg( 'log-title-wildcard' ), 'pattern', 'pattern', $pattern ) .
189 '</span>';
190 }
191
192 public function beginLogEventsList() {
193 return "<ul>\n";
194 }
195
196 public function endLogEventsList() {
197 return "</ul>\n";
198 }
199
200 /**
201 * @param $row Row: a single row from the result set
202 * @return String: Formatted HTML list item
203 */
204 public function logLine( $row ) {
205 global $wgLang, $wgUser, $wgContLang;
206
207 $title = Title::makeTitle( $row->log_namespace, $row->log_title );
208 $classes = array( "mw-logline-{$row->log_type}" );
209 $time = $wgLang->timeanddate( wfTimestamp(TS_MW, $row->log_timestamp), true );
210 // User links
211 if( self::isDeleted($row,LogPage::DELETED_USER) ) {
212 $userLink = '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
213 } else {
214 $userLink = $this->skin->userLink( $row->log_user, $row->user_name ) .
215 $this->skin->userToolLinks( $row->log_user, $row->user_name, true, 0, $row->user_editcount );
216 }
217 // Comment
218 if( self::isDeleted($row,LogPage::DELETED_COMMENT) ) {
219 $comment = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
220 } else {
221 $comment = $wgContLang->getDirMark() . $this->skin->commentBlock( $row->log_comment );
222 }
223 // Extract extra parameters
224 $paramArray = LogPage::extractParams( $row->log_params );
225 $revert = $del = '';
226 // Some user can hide log items and have review links
227 if( $wgUser->isAllowed( 'deleterevision' ) ) {
228 $del = $this->getShowHideLinks( $row ) . ' ';
229 }
230 // Add review links and such...
231 if( ($this->flags & self::NO_ACTION_LINK) || ($row->log_deleted & LogPage::DELETED_ACTION) ) {
232 // Action text is suppressed...
233 } else if( self::typeAction($row,'move','move','move') && !empty($paramArray[0]) ) {
234 $destTitle = Title::newFromText( $paramArray[0] );
235 if( $destTitle ) {
236 $revert = '(' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ),
237 $this->message['revertmove'],
238 'wpOldTitle=' . urlencode( $destTitle->getPrefixedDBkey() ) .
239 '&wpNewTitle=' . urlencode( $title->getPrefixedDBkey() ) .
240 '&wpReason=' . urlencode( wfMsgForContent( 'revertmove' ) ) .
241 '&wpMovetalk=0' ) . ')';
242 }
243 // Show undelete link
244 } else if( self::typeAction($row,array('delete','suppress'),'delete','delete') ) {
245 $revert = '(' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Undelete' ),
246 $this->message['undeletelink'], 'target='. urlencode( $title->getPrefixedDBkey() ) ) . ')';
247 // Show unblock/change block link
248 } else if( self::typeAction($row,array('block','suppress'),array('block','reblock'),'block') ) {
249 $revert = '(' .
250 $this->skin->link( SpecialPage::getTitleFor( 'Ipblocklist' ),
251 $this->message['unblocklink'],
252 array(),
253 array( 'action' => 'unblock', 'ip' => $row->log_title ),
254 'known' )
255 . $this->message['pipe-separator'] .
256 $this->skin->link( SpecialPage::getTitleFor( 'Blockip', $row->log_title ),
257 $this->message['change-blocklink'],
258 array(), array(), 'known' ) .
259 ')';
260 // Show change protection link
261 } else if( self::typeAction( $row, 'protect', array( 'modify', 'protect', 'unprotect' ) ) ) {
262 $revert .= ' (' .
263 $this->skin->link( $title,
264 $this->message['hist'],
265 array(),
266 array( 'action' => 'history', 'offset' => $row->log_timestamp ) );
267 if( $wgUser->isAllowed( 'protect' ) ) {
268 $revert .= $this->message['pipe-separator'] .
269 $this->skin->link( $title,
270 $this->message['protect_change'],
271 array(),
272 array( 'action' => 'protect' ),
273 'known' );
274 }
275 $revert .= ')';
276 // Show unmerge link
277 } else if( self::typeAction($row,'merge','merge','mergehistory') ) {
278 $merge = SpecialPage::getTitleFor( 'Mergehistory' );
279 $revert = '(' . $this->skin->makeKnownLinkObj( $merge, $this->message['revertmerge'],
280 wfArrayToCGI( array('target' => $paramArray[0], 'dest' => $title->getPrefixedDBkey(),
281 'mergepoint' => $paramArray[1] ) ) ) . ')';
282 // If an edit was hidden from a page give a review link to the history
283 } else if( self::typeAction($row,array('delete','suppress'),'revision','deleterevision') ) {
284 if( count($paramArray) == 2 ) {
285 $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
286 // Different revision types use different URL params...
287 $key = $paramArray[0];
288 // Link to each hidden object ID, $paramArray[1] is the url param
289 $Ids = explode( ',', $paramArray[1] );
290 $revParams = '';
291 foreach( $Ids as $n => $id ) {
292 $revParams .= '&' . urlencode($key) . '[]=' . urlencode($id);
293 }
294 $revert = '(' . $this->skin->makeKnownLinkObj( $revdel, $this->message['revdel-restore'],
295 'target=' . $title->getPrefixedUrl() . $revParams ) . ')';
296 }
297 // Hidden log items, give review link
298 } else if( self::typeAction($row,array('delete','suppress'),'event','deleterevision') ) {
299 if( count($paramArray) == 1 ) {
300 $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
301 $Ids = explode( ',', $paramArray[0] );
302 // Link to each hidden object ID, $paramArray[1] is the url param
303 $logParams = '';
304 foreach( $Ids as $n => $id ) {
305 $logParams .= '&logid[]=' . intval($id);
306 }
307 $revert = '(' . $this->skin->makeKnownLinkObj( $revdel, $this->message['revdel-restore'],
308 'target=' . $title->getPrefixedUrl() . $logParams ) . ')';
309 }
310 // Self-created users
311 } else if( self::typeAction($row,'newusers','create2') ) {
312 if( isset( $paramArray[0] ) ) {
313 $revert = $this->skin->userToolLinks( $paramArray[0], $title->getDBkey(), true );
314 } else {
315 # Fall back to a blue contributions link
316 $revert = $this->skin->userToolLinks( 1, $title->getDBkey() );
317 }
318 if( $time < '20080129000000' ) {
319 # Suppress $comment from old entries (before 2008-01-29),
320 # not needed and can contain incorrect links
321 $comment = '';
322 }
323 // Do nothing. The implementation is handled by the hook modifiying the passed-by-ref parameters.
324 } else {
325 wfRunHooks( 'LogLine', array( $row->log_type, $row->log_action, $title, $paramArray,
326 &$comment, &$revert, $row->log_timestamp ) );
327 }
328 // Event description
329 if( self::isDeleted($row,LogPage::DELETED_ACTION) ) {
330 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
331 } else {
332 $action = LogPage::actionText( $row->log_type, $row->log_action, $title,
333 $this->skin, $paramArray, true );
334 }
335
336 // Any tags...
337 list($tagDisplay, $newClasses) = ChangeTags::formatSummaryRow( $row->ts_tags, 'logevent' );
338 $classes = array_merge( $classes, $newClasses );
339
340 if( $revert != '' ) {
341 $revert = '<span class="mw-logevent-actionlink">' . $revert . '</span>';
342 }
343
344 return Xml::tags( 'li', array( "class" => implode( ' ', $classes ) ),
345 $del . $time . ' ' . $userLink . ' ' . $action . ' ' . $comment . ' ' . $revert . " $tagDisplay" ) . "\n";
346 }
347
348 /**
349 * @param $row Row
350 * @return string
351 */
352 private function getShowHideLinks( $row ) {
353 $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
354 // If event was hidden from sysops
355 if( !self::userCan( $row, LogPage::DELETED_RESTRICTED ) ) {
356 $del = Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ), '('.$this->message['rev-delundel'].')' );
357 } else if( $row->log_type == 'suppress' ) {
358 // No one should be hiding from the oversight log
359 $del = Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ), '('.$this->message['rev-delundel'].')' );
360 } else {
361 $target = SpecialPage::getTitleFor( 'Log', $row->log_type );
362 $query = array( 'target' => $target->getPrefixedDBkey(),
363 'logid[]' => $row->log_id
364 );
365 $del = $this->skin->revDeleteLink( $query, self::isDeleted( $row, LogPage::DELETED_RESTRICTED ) );
366 }
367 return $del;
368 }
369
370 /**
371 * @param $row Row
372 * @param $type Mixed: string/array
373 * @param $action Mixed: string/array
374 * @param $right string
375 * @return bool
376 */
377 public static function typeAction( $row, $type, $action, $right='' ) {
378 $match = is_array($type) ? in_array($row->log_type,$type) : $row->log_type == $type;
379 if( $match ) {
380 $match = is_array($action) ?
381 in_array($row->log_action,$action) : $row->log_action == $action;
382 if( $match && $right ) {
383 global $wgUser;
384 $match = $wgUser->isAllowed( $right );
385 }
386 }
387 return $match;
388 }
389
390 /**
391 * Determine if the current user is allowed to view a particular
392 * field of this log row, if it's marked as deleted.
393 * @param $row Row
394 * @param $field Integer
395 * @return Boolean
396 */
397 public static function userCan( $row, $field ) {
398 if( ( $row->log_deleted & $field ) == $field ) {
399 global $wgUser;
400 $permission = ( $row->log_deleted & LogPage::DELETED_RESTRICTED ) == LogPage::DELETED_RESTRICTED
401 ? 'suppressrevision'
402 : 'deleterevision';
403 wfDebug( "Checking for $permission due to $field match on $row->log_deleted\n" );
404 return $wgUser->isAllowed( $permission );
405 } else {
406 return true;
407 }
408 }
409
410 /**
411 * @param $row Row
412 * @param $field Integer: one of DELETED_* bitfield constants
413 * @return Boolean
414 */
415 public static function isDeleted( $row, $field ) {
416 return ($row->log_deleted & $field) == $field;
417 }
418
419 /**
420 * Quick function to show a short log extract
421 * @param $out OutputPage
422 * @param $type String
423 * @param $page String
424 * @param $user String
425 * @param $lim Integer
426 * @param $conds Array
427 */
428 public static function showLogExtract( $out, $type='', $page='', $user='', $lim=0, $conds=array() ) {
429 global $wgUser;
430 # Insert list of top 50 or so items
431 $loglist = new LogEventsList( $wgUser->getSkin(), $out, 0 );
432 $pager = new LogPager( $loglist, $type, $user, $page, '', $conds );
433 if( $lim > 0 ) $pager->mLimit = $lim;
434 $logBody = $pager->getBody();
435 if( $logBody ) {
436 $out->addHTML(
437 $loglist->beginLogEventsList() .
438 $logBody .
439 $loglist->endLogEventsList()
440 );
441 } else {
442 $out->addWikiMsg( 'logempty' );
443 }
444 return $pager->getNumRows();
445 }
446
447 /**
448 * SQL clause to skip forbidden log types for this user
449 * @param $db Database
450 * @param $audience string, public/user
451 * @return mixed (string or false)
452 */
453 public static function getExcludeClause( $db, $audience = 'public' ) {
454 global $wgLogRestrictions, $wgUser;
455 // Reset the array, clears extra "where" clauses when $par is used
456 $hiddenLogs = array();
457 // Don't show private logs to unprivileged users
458 foreach( $wgLogRestrictions as $logType => $right ) {
459 if( $audience == 'public' || !$wgUser->isAllowed($right) ) {
460 $safeType = $db->strencode( $logType );
461 $hiddenLogs[] = $safeType;
462 }
463 }
464 if( count($hiddenLogs) == 1 ) {
465 return 'log_type != ' . $db->addQuotes( $hiddenLogs[0] );
466 } elseif( $hiddenLogs ) {
467 return 'log_type NOT IN (' . $db->makeList($hiddenLogs) . ')';
468 }
469 return false;
470 }
471 }
472
473 /**
474 * @ingroup Pager
475 */
476 class LogPager extends ReverseChronologicalPager {
477 private $type = '', $user = '', $title = '', $pattern = '';
478 public $mLogEventsList;
479
480 /**
481 * constructor
482 * @param $list LogEventsList
483 * @param $type String
484 * @param $user String
485 * @param $title String
486 * @param $pattern String
487 * @param $conds Array
488 * @param $year Integer
489 * @param $month Integer
490 */
491 public function __construct( $list, $type = '', $user = '', $title = '', $pattern = '',
492 $conds = array(), $year = false, $month = false, $tagFilter = '' )
493 {
494 parent::__construct();
495 $this->mConds = $conds;
496
497 $this->mLogEventsList = $list;
498
499 $this->limitType( $type ); // also excludes hidden types
500 $this->limitUser( $user );
501 $this->limitTitle( $title, $pattern );
502 $this->getDateCond( $year, $month );
503 $this->mTagFilter = $tagFilter;
504 }
505
506 public function getDefaultQuery() {
507 $query = parent::getDefaultQuery();
508 $query['type'] = $this->type;
509 $query['user'] = $this->user;
510 $query['month'] = $this->mMonth;
511 $query['year'] = $this->mYear;
512 return $query;
513 }
514
515 public function getFilterParams() {
516 global $wgFilterLogTypes, $wgUser, $wgRequest;
517 $filters = array();
518 if( $this->type ) {
519 return $filters;
520 }
521 foreach( $wgFilterLogTypes as $type => $default ) {
522 // Avoid silly filtering
523 if( $type !== 'patrol' || $wgUser->useNPPatrol() ) {
524 $hide = $wgRequest->getInt( "hide_{$type}_log", $default );
525 $filters[$type] = $hide;
526 if( $hide )
527 $this->mConds[] = 'log_type != ' . $this->mDb->addQuotes( $type );
528 }
529 }
530 return $filters;
531 }
532
533 /**
534 * Set the log reader to return only entries of the given type.
535 * Type restrictions enforced here
536 * @param $type String: A log type ('upload', 'delete', etc)
537 */
538 private function limitType( $type ) {
539 global $wgLogRestrictions, $wgUser;
540 // Don't even show header for private logs; don't recognize it...
541 if( isset($wgLogRestrictions[$type]) && !$wgUser->isAllowed($wgLogRestrictions[$type]) ) {
542 $type = '';
543 }
544 // Don't show private logs to unpriviledged users.
545 // Also, only show them upon specific request to avoid suprises.
546 $audience = $type ? 'user' : 'public';
547 $hideLogs = LogEventsList::getExcludeClause( $this->mDb, $audience );
548 if( $hideLogs !== false ) {
549 $this->mConds[] = $hideLogs;
550 }
551 if( $type ) {
552 $this->type = $type;
553 $this->mConds['log_type'] = $type;
554 }
555 }
556
557 /**
558 * Set the log reader to return only entries by the given user.
559 * @param $name String: (In)valid user name
560 */
561 private function limitUser( $name ) {
562 if( $name == '' ) {
563 return false;
564 }
565 $usertitle = Title::makeTitleSafe( NS_USER, $name );
566 if( is_null($usertitle) ) {
567 return false;
568 }
569 /* Fetch userid at first, if known, provides awesome query plan afterwards */
570 $userid = User::idFromName( $name );
571 if( !$userid ) {
572 /* It should be nicer to abort query at all,
573 but for now it won't pass anywhere behind the optimizer */
574 $this->mConds[] = "NULL";
575 } else {
576 global $wgUser;
577 $this->mConds['log_user'] = $userid;
578 // Paranoia: avoid brute force searches (bug 17342)
579 if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
580 $this->mConds[] = 'log_deleted & ' . LogPage::DELETED_USER . ' = 0';
581 }
582 $this->user = $usertitle->getText();
583 }
584 }
585
586 /**
587 * Set the log reader to return only entries affecting the given page.
588 * (For the block and rights logs, this is a user page.)
589 * @param $page String: Title name as text
590 * @param $pattern String
591 */
592 private function limitTitle( $page, $pattern ) {
593 global $wgMiserMode, $wgUser;
594
595 $title = Title::newFromText( $page );
596 if( strlen($page) == 0 || !$title instanceof Title )
597 return false;
598
599 $this->title = $title->getPrefixedText();
600 $ns = $title->getNamespace();
601 # Using the (log_namespace, log_title, log_timestamp) index with a
602 # range scan (LIKE) on the first two parts, instead of simple equality,
603 # makes it unusable for sorting. Sorted retrieval using another index
604 # would be possible, but then we might have to scan arbitrarily many
605 # nodes of that index. Therefore, we need to avoid this if $wgMiserMode
606 # is on.
607 #
608 # This is not a problem with simple title matches, because then we can
609 # use the page_time index. That should have no more than a few hundred
610 # log entries for even the busiest pages, so it can be safely scanned
611 # in full to satisfy an impossible condition on user or similar.
612 if( $pattern && !$wgMiserMode ) {
613 # use escapeLike to avoid expensive search patterns like 't%st%'
614 $safetitle = $this->mDb->escapeLike( $title->getDBkey() );
615 $this->mConds['log_namespace'] = $ns;
616 $this->mConds[] = "log_title LIKE '$safetitle%'";
617 $this->pattern = $pattern;
618 } else {
619 $this->mConds['log_namespace'] = $ns;
620 $this->mConds['log_title'] = $title->getDBkey();
621 }
622 // Paranoia: avoid brute force searches (bug 17342)
623 if( !$wgUser->isAllowed( 'suppressrevision' ) ) {
624 $this->mConds[] = 'log_deleted & ' . LogPage::DELETED_ACTION . ' = 0';
625 }
626 }
627
628 public function getQueryInfo() {
629 $this->mConds[] = 'user_id = log_user';
630 # Don't use the wrong logging index
631 if( $this->title || $this->pattern || $this->user ) {
632 $index = array( 'USE INDEX' => array( 'logging' => array('page_time','user_time') ) );
633 } else if( $this->type ) {
634 $index = array( 'USE INDEX' => array( 'logging' => 'type_time' ) );
635 } else {
636 $index = array( 'USE INDEX' => array( 'logging' => 'times' ) );
637 }
638 $info = array(
639 'tables' => array( 'logging', 'user' ),
640 'fields' => array( 'log_type', 'log_action', 'log_user', 'log_namespace', 'log_title', 'log_params',
641 'log_comment', 'log_id', 'log_deleted', 'log_timestamp', 'user_name', 'user_editcount' ),
642 'conds' => $this->mConds,
643 'options' => $index,
644 'join_conds' => array( 'user' => array( 'INNER JOIN', 'user_id=log_user' ) ),
645 );
646
647 ChangeTags::modifyDisplayQuery( $info['tables'], $info['fields'], $info['conds'],
648 $info['join_conds'], $this->mTagFilter );
649
650 return $info;
651 }
652
653 function getIndexField() {
654 return 'log_timestamp';
655 }
656
657 public function getStartBody() {
658 wfProfileIn( __METHOD__ );
659 # Do a link batch query
660 if( $this->getNumRows() > 0 ) {
661 $lb = new LinkBatch;
662 while( $row = $this->mResult->fetchObject() ) {
663 $lb->add( $row->log_namespace, $row->log_title );
664 $lb->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
665 $lb->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_name ) );
666 }
667 $lb->execute();
668 $this->mResult->seek( 0 );
669 }
670 wfProfileOut( __METHOD__ );
671 return '';
672 }
673
674 public function formatRow( $row ) {
675 return $this->mLogEventsList->logLine( $row );
676 }
677
678 public function getType() {
679 return $this->type;
680 }
681
682 public function getUser() {
683 return $this->user;
684 }
685
686 public function getPage() {
687 return $this->title;
688 }
689
690 public function getPattern() {
691 return $this->pattern;
692 }
693
694 public function getYear() {
695 return $this->mYear;
696 }
697
698 public function getMonth() {
699 return $this->mMonth;
700 }
701
702 public function getTagFilter() {
703 return $this->mTagFilter;
704 }
705 }
706
707 /**
708 * @deprecated
709 * @ingroup SpecialPage
710 */
711 class LogReader {
712 var $pager;
713 /**
714 * @param $request WebRequest: for internal use use a FauxRequest object to pass arbitrary parameters.
715 */
716 function __construct( $request ) {
717 global $wgUser, $wgOut;
718 wfDeprecated(__METHOD__);
719 # Get parameters
720 $type = $request->getVal( 'type' );
721 $user = $request->getText( 'user' );
722 $title = $request->getText( 'page' );
723 $pattern = $request->getBool( 'pattern' );
724 $year = $request->getIntOrNull( 'year' );
725 $month = $request->getIntOrNull( 'month' );
726 $tagFilter = $request->getVal( 'tagfilter' );
727 # Don't let the user get stuck with a certain date
728 $skip = $request->getText( 'offset' ) || $request->getText( 'dir' ) == 'prev';
729 if( $skip ) {
730 $year = '';
731 $month = '';
732 }
733 # Use new list class to output results
734 $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, 0 );
735 $this->pager = new LogPager( $loglist, $type, $user, $title, $pattern, $year, $month, $tagFilter );
736 }
737
738 /**
739 * Is there at least one row?
740 * @return bool
741 */
742 public function hasRows() {
743 return isset($this->pager) ? ($this->pager->getNumRows() > 0) : false;
744 }
745 }
746
747 /**
748 * @deprecated
749 * @ingroup SpecialPage
750 */
751 class LogViewer {
752 const NO_ACTION_LINK = 1;
753
754 /**
755 * LogReader object
756 */
757 var $reader;
758
759 /**
760 * @param &$reader LogReader: where to get our data from
761 * @param $flags Integer: Bitwise combination of flags:
762 * LogEventsList::NO_ACTION_LINK Don't show restore/unblock/block links
763 */
764 function __construct( &$reader, $flags = 0 ) {
765 global $wgUser;
766 wfDeprecated(__METHOD__);
767 $this->reader =& $reader;
768 $this->reader->pager->mLogEventsList->flags = $flags;
769 # Aliases for shorter code...
770 $this->pager =& $this->reader->pager;
771 $this->list =& $this->reader->pager->mLogEventsList;
772 }
773
774 /**
775 * Take over the whole output page in $wgOut with the log display.
776 */
777 public function show() {
778 # Set title and add header
779 $this->list->showHeader( $pager->getType() );
780 # Show form options
781 $this->list->showOptions( $this->pager->getType(), $this->pager->getUser(), $this->pager->getPage(),
782 $this->pager->getPattern(), $this->pager->getYear(), $this->pager->getMonth() );
783 # Insert list
784 $logBody = $this->pager->getBody();
785 if( $logBody ) {
786 $wgOut->addHTML(
787 $this->pager->getNavigationBar() .
788 $this->list->beginLogEventsList() .
789 $logBody .
790 $this->list->endLogEventsList() .
791 $this->pager->getNavigationBar()
792 );
793 } else {
794 $wgOut->addWikiMsg( 'logempty' );
795 }
796 }
797
798 /**
799 * Output just the list of entries given by the linked LogReader,
800 * with extraneous UI elements. Use for displaying log fragments in
801 * another page (eg at Special:Undelete)
802 * @param $out OutputPage: where to send output
803 */
804 public function showList( &$out ) {
805 $logBody = $this->pager->getBody();
806 if( $logBody ) {
807 $out->addHTML(
808 $this->list->beginLogEventsList() .
809 $logBody .
810 $this->list->endLogEventsList()
811 );
812 } else {
813 $out->addWikiMsg( 'logempty' );
814 }
815 }
816 }