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