Make "show" work ;)
[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 $hide = $wgRequest->getInt( "hide{$type}log", $default );
504 $filters[$type] = $hide;
505 if( $hide )
506 $this->mConds[] = 'log_type != '.$this->mDb->addQuotes( $this->mDb->strencode($type) );
507 }
508 }
509 return $filters;
510 }
511
512 /**
513 * Set the log reader to return only entries of the given type.
514 * Type restrictions enforced here
515 * @param string $type A log type ('upload', 'delete', etc)
516 * @private
517 */
518 private function limitType( $type ) {
519 global $wgLogRestrictions, $wgUser;
520 // Don't even show header for private logs; don't recognize it...
521 if( isset($wgLogRestrictions[$type]) && !$wgUser->isAllowed($wgLogRestrictions[$type]) ) {
522 $type = '';
523 }
524 // Don't show private logs to unpriviledged users
525 $hideLogs = LogEventsList::getExcludeClause( $this->mDb );
526 if( $hideLogs !== false ) {
527 $this->mConds[] = $hideLogs;
528 }
529 if( empty($type) ) {
530 return false;
531 }
532 $this->type = $type;
533 $this->mConds['log_type'] = $type;
534 }
535
536 /**
537 * Set the log reader to return only entries by the given user.
538 * @param string $name (In)valid user name
539 * @private
540 */
541 function limitUser( $name ) {
542 if( $name == '' ) {
543 return false;
544 }
545 $usertitle = Title::makeTitleSafe( NS_USER, $name );
546 if( is_null($usertitle) ) {
547 return false;
548 }
549 /* Fetch userid at first, if known, provides awesome query plan afterwards */
550 $userid = User::idFromName( $name );
551 if( !$userid ) {
552 /* It should be nicer to abort query at all,
553 but for now it won't pass anywhere behind the optimizer */
554 $this->mConds[] = "NULL";
555 } else {
556 $this->mConds['log_user'] = $userid;
557 $this->user = $usertitle->getText();
558 }
559 }
560
561 /**
562 * Set the log reader to return only entries affecting the given page.
563 * (For the block and rights logs, this is a user page.)
564 * @param string $page Title name as text
565 * @private
566 */
567 function limitTitle( $page, $pattern ) {
568 global $wgMiserMode;
569
570 $title = Title::newFromText( $page );
571 if( strlen($page) == 0 || !$title instanceof Title )
572 return false;
573
574 $this->title = $title->getPrefixedText();
575 $ns = $title->getNamespace();
576 # Using the (log_namespace, log_title, log_timestamp) index with a
577 # range scan (LIKE) on the first two parts, instead of simple equality,
578 # makes it unusable for sorting. Sorted retrieval using another index
579 # would be possible, but then we might have to scan arbitrarily many
580 # nodes of that index. Therefore, we need to avoid this if $wgMiserMode
581 # is on.
582 #
583 # This is not a problem with simple title matches, because then we can
584 # use the page_time index. That should have no more than a few hundred
585 # log entries for even the busiest pages, so it can be safely scanned
586 # in full to satisfy an impossible condition on user or similar.
587 if( $pattern && !$wgMiserMode ) {
588 # use escapeLike to avoid expensive search patterns like 't%st%'
589 $safetitle = $this->mDb->escapeLike( $title->getDBkey() );
590 $this->mConds['log_namespace'] = $ns;
591 $this->mConds[] = "log_title LIKE '$safetitle%'";
592 $this->pattern = $pattern;
593 } else {
594 $this->mConds['log_namespace'] = $ns;
595 $this->mConds['log_title'] = $title->getDBkey();
596 }
597 }
598
599 function getQueryInfo() {
600 $this->mConds[] = 'user_id = log_user';
601 # Don't use the wrong logging index
602 if( $this->title || $this->pattern || $this->user ) {
603 $index = array( 'USE INDEX' => array( 'logging' => array('page_time','user_time') ) );
604 } else if( $this->type ) {
605 $index = array( 'USE INDEX' => array( 'logging' => 'type_time' ) );
606 } else {
607 $index = array( 'USE INDEX' => array( 'logging' => 'times' ) );
608 }
609 return array(
610 'tables' => array( 'logging', 'user' ),
611 'fields' => array( 'log_type', 'log_action', 'log_user', 'log_namespace', 'log_title', 'log_params',
612 'log_comment', 'log_id', 'log_deleted', 'log_timestamp', 'user_name', 'user_editcount' ),
613 'conds' => $this->mConds,
614 'options' => $index
615 );
616 }
617
618 function getIndexField() {
619 return 'log_timestamp';
620 }
621
622 function getStartBody() {
623 wfProfileIn( __METHOD__ );
624 # Do a link batch query
625 if( $this->getNumRows() > 0 ) {
626 $lb = new LinkBatch;
627 while( $row = $this->mResult->fetchObject() ) {
628 $lb->add( $row->log_namespace, $row->log_title );
629 $lb->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
630 $lb->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_name ) );
631 }
632 $lb->execute();
633 $this->mResult->seek( 0 );
634 }
635 wfProfileOut( __METHOD__ );
636 return '';
637 }
638
639 function formatRow( $row ) {
640 return $this->mLogEventsList->logLine( $row );
641 }
642
643 public function getType() {
644 return $this->type;
645 }
646
647 public function getUser() {
648 return $this->user;
649 }
650
651 public function getPage() {
652 return $this->title;
653 }
654
655 public function getPattern() {
656 return $this->pattern;
657 }
658
659 public function getYear() {
660 return $this->mYear;
661 }
662
663 public function getMonth() {
664 return $this->mMonth;
665 }
666 }
667
668 /**
669 * @deprecated
670 * @ingroup SpecialPage
671 */
672 class LogReader {
673 var $pager;
674 /**
675 * @param WebRequest $request For internal use use a FauxRequest object to pass arbitrary parameters.
676 */
677 function __construct( $request ) {
678 global $wgUser, $wgOut;
679 # Get parameters
680 $type = $request->getVal( 'type' );
681 $user = $request->getText( 'user' );
682 $title = $request->getText( 'page' );
683 $pattern = $request->getBool( 'pattern' );
684 $y = $request->getIntOrNull( 'year' );
685 $m = $request->getIntOrNull( 'month' );
686 # Don't let the user get stuck with a certain date
687 $skip = $request->getText( 'offset' ) || $request->getText( 'dir' ) == 'prev';
688 if( $skip ) {
689 $y = '';
690 $m = '';
691 }
692 # Use new list class to output results
693 $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, 0 );
694 $this->pager = new LogPager( $loglist, $type, $user, $title, $pattern, $y, $m );
695 }
696
697 /**
698 * Is there at least one row?
699 * @return bool
700 */
701 public function hasRows() {
702 return isset($this->pager) ? ($this->pager->getNumRows() > 0) : false;
703 }
704 }
705
706 /**
707 * @deprecated
708 * @ingroup SpecialPage
709 */
710 class LogViewer {
711 const NO_ACTION_LINK = 1;
712 /**
713 * @var LogReader $reader
714 */
715 var $reader;
716 /**
717 * @param LogReader &$reader where to get our data from
718 * @param integer $flags Bitwise combination of flags:
719 * LogEventsList::NO_ACTION_LINK Don't show restore/unblock/block links
720 */
721 function __construct( &$reader, $flags = 0 ) {
722 global $wgUser;
723 $this->reader =& $reader;
724 $this->reader->pager->mLogEventsList->flags = $flags;
725 # Aliases for shorter code...
726 $this->pager =& $this->reader->pager;
727 $this->list =& $this->reader->pager->mLogEventsList;
728 }
729
730 /**
731 * Take over the whole output page in $wgOut with the log display.
732 */
733 public function show() {
734 # Set title and add header
735 $this->list->showHeader( $pager->getType() );
736 # Show form options
737 $this->list->showOptions( $this->pager->getType(), $this->pager->getUser(), $this->pager->getPage(),
738 $this->pager->getPattern(), $this->pager->getYear(), $this->pager->getMonth() );
739 # Insert list
740 $logBody = $this->pager->getBody();
741 if( $logBody ) {
742 $wgOut->addHTML(
743 $this->pager->getNavigationBar() .
744 $this->list->beginLogEventsList() .
745 $logBody .
746 $this->list->endLogEventsList() .
747 $this->pager->getNavigationBar()
748 );
749 } else {
750 $wgOut->addWikiMsg( 'logempty' );
751 }
752 }
753
754 /**
755 * Output just the list of entries given by the linked LogReader,
756 * with extraneous UI elements. Use for displaying log fragments in
757 * another page (eg at Special:Undelete)
758 * @param OutputPage $out where to send output
759 */
760 public function showList( &$out ) {
761 $logBody = $this->pager->getBody();
762 if( $logBody ) {
763 $out->addHTML(
764 $this->list->beginLogEventsList() .
765 $logBody .
766 $this->list->endLogEventsList()
767 );
768 } else {
769 $out->addWikiMsg( 'logempty' );
770 }
771 }
772 }