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