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