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