Add newuser log to core
[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 $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 // Action text is suppressed...
221 } else if( self::typeAction($row,'move','move') && !empty($paramArray[0]) && $wgUser->isAllowed( 'move' ) ) {
222 $destTitle = Title::newFromText( $paramArray[0] );
223 if( $destTitle ) {
224 $revert = '(' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ),
225 $this->message['revertmove'],
226 'wpOldTitle=' . urlencode( $destTitle->getPrefixedDBkey() ) .
227 '&wpNewTitle=' . urlencode( $title->getPrefixedDBkey() ) .
228 '&wpReason=' . urlencode( wfMsgForContent( 'revertmove' ) ) .
229 '&wpMovetalk=0' ) . ')';
230 }
231 // Show undelete link
232 } else if( self::typeAction($row,array('delete','suppress'),'delete') && $wgUser->isAllowed( 'delete' ) ) {
233 $revert = '(' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Undelete' ),
234 $this->message['undeletelink'], 'target='. urlencode( $title->getPrefixedDBkey() ) ) . ')';
235 // Show unblock link
236 } else if( self::typeAction($row,array('block','suppress'),'block') && $wgUser->isAllowed( 'block' ) ) {
237 $revert = '(' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Ipblocklist' ),
238 $this->message['unblocklink'],
239 'action=unblock&ip=' . urlencode( $row->log_title ) ) . ')';
240 // Show change protection link
241 } else if( self::typeAction($row,'protect',array('modify','protect','unprotect')) ) {
242 $revert .= ' (' . $this->skin->makeKnownLinkObj( $title, $this->message['hist'],
243 'action=history&offset=' . urlencode($row->log_timestamp) ) . ')';
244 if( $wgUser->isAllowed('protect') && $row->log_action != 'unprotect' ) {
245 $revert .= ' (' . $this->skin->makeKnownLinkObj( $title, $this->message['protect_change'],
246 'action=unprotect' ) . ')';
247 }
248 // Show unmerge link
249 } else if ( self::typeAction($row,'merge','merge') ) {
250 $merge = SpecialPage::getTitleFor( 'Mergehistory' );
251 $revert = '(' . $this->skin->makeKnownLinkObj( $merge, $this->message['revertmerge'],
252 wfArrayToCGI( array('target' => $paramArray[0], 'dest' => $title->getPrefixedDBkey(),
253 'mergepoint' => $paramArray[1] ) ) ) . ')';
254 // If an edit was hidden from a page give a review link to the history
255 } else if( self::typeAction($row,array('delete','suppress'),'revision') && $wgUser->isAllowed( 'deleterevision' ) ) {
256 if( count($paramArray) == 2 ) {
257 $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
258 // Different revision types use different URL params...
259 $key = $paramArray[0];
260 // Link to each hidden object ID, $paramArray[1] is the url param
261 $Ids = explode( ',', $paramArray[1] );
262 $revParams = '';
263 foreach( $Ids as $n => $id ) {
264 $revParams .= '&' . urlencode($key) . '[]=' . urlencode($id);
265 }
266 $revert = '(' . $this->skin->makeKnownLinkObj( $revdel, $this->message['revdel-restore'],
267 'target=' . $title->getPrefixedUrl() . $revParams ) . ')';
268 }
269 // Hidden log items, give review link
270 } else if( self::typeAction($row,array('delete','suppress'),'event') && $wgUser->isAllowed( 'deleterevision' ) ) {
271 if( count($paramArray) == 1 ) {
272 $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
273 $Ids = explode( ',', $paramArray[0] );
274 // Link to each hidden object ID, $paramArray[1] is the url param
275 $logParams = '';
276 foreach( $Ids as $n => $id ) {
277 $logParams .= '&logid[]=' . intval($id);
278 }
279 $revert = '(' . $this->skin->makeKnownLinkObj( $revdel, $this->message['revdel-restore'],
280 'target=' . $title->getPrefixedUrl() . $logParams ) . ')';
281 }
282 // Self-created users
283 } else if( self::typeAction($row,'newusers','create2') ) {
284 if( isset( $paramArray[0] ) ) {
285 $revert = $this->skin->userToolLinks( $paramArray[0], $title->getDBkey(), true );
286 } else {
287 # Fall back to a blue contributions link
288 $revert = $this->skin->userToolLinks( 1, $title->getDBkey() );
289 }
290 if( $time < '20080129000000' ) {
291 # Suppress $comment from old entries (before 2008-01-29), not needed and can contain incorrect links
292 $comment = '';
293 }
294 // Do nothing. The implementation is handled by the hook modifiying the passed-by-ref parameters.
295 } else {
296 wfRunHooks( 'LogLine', array( $row->log_type, $row->log_action, $title, $paramArray,
297 &$comment, &$revert, $row->log_timestamp ) );
298 }
299 // Event description
300 if( self::isDeleted($row,LogPage::DELETED_ACTION) ) {
301 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
302 } else {
303 $action = LogPage::actionText( $row->log_type, $row->log_action, $title, $this->skin, $paramArray, true );
304 }
305
306 return "<li>$del$time $userLink $action $comment $revert</li>\n";
307 }
308
309 /**
310 * @param Row $row
311 * @return string
312 */
313 private function showhideLinks( $row ) {
314 $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
315 // If event was hidden from sysops
316 if( !self::userCan( $row, LogPage::DELETED_RESTRICTED ) ) {
317 $del = $this->message['rev-delundel'];
318 } else if( $row->log_type == 'suppress' ) {
319 // No one should be hiding from the oversight log
320 $del = $this->message['rev-delundel'];
321 } else {
322 $target = SpecialPage::getTitleFor( 'Log', $row->log_type );
323 $del = $this->skin->makeKnownLinkObj( $revdel, $this->message['rev-delundel'],
324 'target=' . $target->getPrefixedUrl() . '&logid='.$row->log_id );
325 // Bolden oversighted content
326 if( self::isDeleted( $row, LogPage::DELETED_RESTRICTED ) )
327 $del = "<strong>$del</strong>";
328 }
329 return "<tt>(<small>$del</small>)</tt>";
330 }
331
332 /**
333 * @param Row $row
334 * @param mixed $type (string/array)
335 * @param mixed $action (string/array)
336 * @return bool
337 */
338 public static function typeAction( $row, $type, $action ) {
339 $match = is_array($type) ? in_array($row->log_type,$type) : $row->log_type == $type;
340 if( $match ) {
341 $match = is_array($action) ? in_array($row->log_action,$action) : $row->log_action == $action;
342 }
343 return $match;
344 }
345
346 /**
347 * Determine if the current user is allowed to view a particular
348 * field of this log row, if it's marked as deleted.
349 * @param Row $row
350 * @param int $field
351 * @return bool
352 */
353 public static function userCan( $row, $field ) {
354 if( ( $row->log_deleted & $field ) == $field ) {
355 global $wgUser;
356 $permission = ( $row->log_deleted & LogPage::DELETED_RESTRICTED ) == LogPage::DELETED_RESTRICTED
357 ? 'suppressrevision'
358 : 'deleterevision';
359 wfDebug( "Checking for $permission due to $field match on $row->log_deleted\n" );
360 return $wgUser->isAllowed( $permission );
361 } else {
362 return true;
363 }
364 }
365
366 /**
367 * @param Row $row
368 * @param int $field one of DELETED_* bitfield constants
369 * @return bool
370 */
371 public static function isDeleted( $row, $field ) {
372 return ($row->log_deleted & $field) == $field;
373 }
374
375 /**
376 * Quick function to show a short log extract
377 * @param OutputPage $out
378 * @param string $type
379 * @param string $page
380 * @param string $user
381 */
382 public static function showLogExtract( $out, $type='', $page='', $user='', $limit = NULL ) {
383 global $wgUser;
384 # Insert list of top 50 or so items
385 $loglist = new LogEventsList( $wgUser->getSkin(), $out, 0 );
386 $pager = new LogPager( $loglist, $type, $user, $page, '' );
387 if( $limit ) $pager->mLimit = $limit;
388 $logBody = $pager->getBody();
389 if( $logBody ) {
390 $out->addHTML(
391 $loglist->beginLogEventsList() .
392 $logBody .
393 $loglist->endLogEventsList()
394 );
395 } else {
396 $out->addWikiMsg( 'logempty' );
397 }
398 }
399
400 /**
401 * SQL clause to skip forbidden log types for this user
402 * @param Database $db
403 * @returns mixed (string or false)
404 */
405 public static function getExcludeClause( $db ) {
406 global $wgLogRestrictions, $wgUser;
407 // Reset the array, clears extra "where" clauses when $par is used
408 $hiddenLogs = array();
409 // Don't show private logs to unprivileged users
410 foreach( $wgLogRestrictions as $logtype => $right ) {
411 if( !$wgUser->isAllowed($right) ) {
412 $safetype = $db->strencode( $logtype );
413 $hiddenLogs[] = $safetype;
414 }
415 }
416 if( count($hiddenLogs) == 1 ) {
417 return 'log_type != ' . $db->addQuotes( $hiddenLogs[0] );
418 } elseif( !empty( $hiddenLogs ) ) {
419 return 'log_type NOT IN (' . $db->makeList($hiddenLogs) . ')';
420 }
421 return false;
422 }
423 }
424
425 /**
426 * @ingroup Pager
427 */
428 class LogPager extends ReverseChronologicalPager {
429 private $type = '', $user = '', $title = '', $pattern = '';
430 public $mLogEventsList;
431 /**
432 * constructor
433 * @param LogEventsList $loglist,
434 * @param string $type,
435 * @param string $user,
436 * @param string $page,
437 * @param string $pattern
438 * @param array $conds
439 */
440 function __construct( $list, $type='', $user='', $title='', $pattern='', $conds=array(), $y=false, $m=false ) {
441 parent::__construct();
442 $this->mConds = $conds;
443
444 $this->mLogEventsList = $list;
445
446 $this->limitType( $type );
447 $this->limitUser( $user );
448 $this->limitTitle( $title, $pattern );
449 $this->getDateCond( $y, $m );
450 }
451
452 function getDefaultQuery() {
453 $query = parent::getDefaultQuery();
454 $query['type'] = $this->type;
455 $query['month'] = $this->mMonth;
456 $query['year'] = $this->mYear;
457 return $query;
458 }
459
460 /**
461 * Set the log reader to return only entries of the given type.
462 * Type restrictions enforced here
463 * @param string $type A log type ('upload', 'delete', etc)
464 * @private
465 */
466 private function limitType( $type ) {
467 global $wgLogRestrictions, $wgUser;
468 // Don't even show header for private logs; don't recognize it...
469 if( isset($wgLogRestrictions[$type]) && !$wgUser->isAllowed($wgLogRestrictions[$type]) ) {
470 $type = '';
471 }
472 // Don't show private logs to unpriviledged users
473 $hideLogs = LogEventsList::getExcludeClause( $this->mDb );
474 if( $hideLogs !== false ) {
475 $this->mConds[] = $hideLogs;
476 }
477 if( empty($type) ) {
478 return false;
479 }
480 $this->type = $type;
481 $this->mConds['log_type'] = $type;
482 }
483
484 /**
485 * Set the log reader to return only entries by the given user.
486 * @param string $name (In)valid user name
487 * @private
488 */
489 function limitUser( $name ) {
490 if( $name == '' ) {
491 return false;
492 }
493 $usertitle = Title::makeTitleSafe( NS_USER, $name );
494 if( is_null($usertitle) ) {
495 return false;
496 }
497 /* Fetch userid at first, if known, provides awesome query plan afterwards */
498 $userid = User::idFromName( $name );
499 if( !$userid ) {
500 /* It should be nicer to abort query at all,
501 but for now it won't pass anywhere behind the optimizer */
502 $this->mConds[] = "NULL";
503 } else {
504 $this->mConds['log_user'] = $userid;
505 $this->user = $usertitle->getText();
506 }
507 }
508
509 /**
510 * Set the log reader to return only entries affecting the given page.
511 * (For the block and rights logs, this is a user page.)
512 * @param string $page Title name as text
513 * @private
514 */
515 function limitTitle( $page, $pattern ) {
516 global $wgMiserMode;
517
518 $title = Title::newFromText( $page );
519 if( strlen($page) == 0 || !$title instanceof Title )
520 return false;
521
522 $this->title = $title->getPrefixedText();
523 $ns = $title->getNamespace();
524 # Using the (log_namespace, log_title, log_timestamp) index with a
525 # range scan (LIKE) on the first two parts, instead of simple equality,
526 # makes it unusable for sorting. Sorted retrieval using another index
527 # would be possible, but then we might have to scan arbitrarily many
528 # nodes of that index. Therefore, we need to avoid this if $wgMiserMode
529 # is on.
530 #
531 # This is not a problem with simple title matches, because then we can
532 # use the page_time index. That should have no more than a few hundred
533 # log entries for even the busiest pages, so it can be safely scanned
534 # in full to satisfy an impossible condition on user or similar.
535 if( $pattern && !$wgMiserMode ) {
536 # use escapeLike to avoid expensive search patterns like 't%st%'
537 $safetitle = $this->mDb->escapeLike( $title->getDBkey() );
538 $this->mConds['log_namespace'] = $ns;
539 $this->mConds[] = "log_title LIKE '$safetitle%'";
540 $this->pattern = $pattern;
541 } else {
542 $this->mConds['log_namespace'] = $ns;
543 $this->mConds['log_title'] = $title->getDBkey();
544 }
545 }
546
547 function getQueryInfo() {
548 $this->mConds[] = 'user_id = log_user';
549 # Don't use the wrong logging index
550 if( $this->title || $this->pattern || $this->user ) {
551 $index = array( 'USE INDEX' => array( 'logging' => array('page_time','user_time') ) );
552 } else if( $this->type ) {
553 $index = array( 'USE INDEX' => array( 'logging' => 'type_time' ) );
554 } else {
555 $index = array( 'USE INDEX' => array( 'logging' => 'times' ) );
556 }
557 return array(
558 'tables' => array( 'logging', 'user' ),
559 'fields' => array( 'log_type', 'log_action', 'log_user', 'log_namespace', 'log_title', 'log_params',
560 'log_comment', 'log_id', 'log_deleted', 'log_timestamp', 'user_name', 'user_editcount' ),
561 'conds' => $this->mConds,
562 'options' => $index
563 );
564 }
565
566 function getIndexField() {
567 return 'log_timestamp';
568 }
569
570 function getStartBody() {
571 wfProfileIn( __METHOD__ );
572 # Do a link batch query
573 if( $this->getNumRows() > 0 ) {
574 $lb = new LinkBatch;
575 while( $row = $this->mResult->fetchObject() ) {
576 $lb->add( $row->log_namespace, $row->log_title );
577 $lb->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
578 $lb->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_name ) );
579 }
580 $lb->execute();
581 $this->mResult->seek( 0 );
582 }
583 wfProfileOut( __METHOD__ );
584 return '';
585 }
586
587 function formatRow( $row ) {
588 return $this->mLogEventsList->logLine( $row );
589 }
590
591 public function getType() {
592 return $this->type;
593 }
594
595 public function getUser() {
596 return $this->user;
597 }
598
599 public function getPage() {
600 return $this->title;
601 }
602
603 public function getPattern() {
604 return $this->pattern;
605 }
606
607 public function getYear() {
608 return $this->mYear;
609 }
610
611 public function getMonth() {
612 return $this->mMonth;
613 }
614 }
615
616 /**
617 * @deprecated
618 * @ingroup SpecialPage
619 */
620 class LogReader {
621 var $pager;
622 /**
623 * @param WebRequest $request For internal use use a FauxRequest object to pass arbitrary parameters.
624 */
625 function __construct( $request ) {
626 global $wgUser, $wgOut;
627 # Get parameters
628 $type = $request->getVal( 'type' );
629 $user = $request->getText( 'user' );
630 $title = $request->getText( 'page' );
631 $pattern = $request->getBool( 'pattern' );
632 $y = $request->getIntOrNull( 'year' );
633 $m = $request->getIntOrNull( 'month' );
634 # Don't let the user get stuck with a certain date
635 $skip = $request->getText( 'offset' ) || $request->getText( 'dir' ) == 'prev';
636 if( $skip ) {
637 $y = '';
638 $m = '';
639 }
640 # Use new list class to output results
641 $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, 0 );
642 $this->pager = new LogPager( $loglist, $type, $user, $title, $pattern, $y, $m );
643 }
644
645 /**
646 * Is there at least one row?
647 * @return bool
648 */
649 public function hasRows() {
650 return isset($this->pager) ? ($this->pager->getNumRows() > 0) : false;
651 }
652 }
653
654 /**
655 * @deprecated
656 * @ingroup SpecialPage
657 */
658 class LogViewer {
659 const NO_ACTION_LINK = 1;
660 /**
661 * @var LogReader $reader
662 */
663 var $reader;
664 /**
665 * @param LogReader &$reader where to get our data from
666 * @param integer $flags Bitwise combination of flags:
667 * LogEventsList::NO_ACTION_LINK Don't show restore/unblock/block links
668 */
669 function __construct( &$reader, $flags = 0 ) {
670 global $wgUser;
671 $this->reader =& $reader;
672 $this->reader->pager->mLogEventsList->flags = $flags;
673 # Aliases for shorter code...
674 $this->pager =& $this->reader->pager;
675 $this->list =& $this->reader->pager->mLogEventsList;
676 }
677
678 /**
679 * Take over the whole output page in $wgOut with the log display.
680 */
681 public function show() {
682 # Set title and add header
683 $this->list->showHeader( $pager->getType() );
684 # Show form options
685 $this->list->showOptions( $this->pager->getType(), $this->pager->getUser(), $this->pager->getPage(),
686 $this->pager->getPattern(), $this->pager->getYear(), $this->pager->getMonth() );
687 # Insert list
688 $logBody = $this->pager->getBody();
689 if( $logBody ) {
690 $wgOut->addHTML(
691 $this->pager->getNavigationBar() .
692 $this->list->beginLogEventsList() .
693 $logBody .
694 $this->list->endLogEventsList() .
695 $this->pager->getNavigationBar()
696 );
697 } else {
698 $wgOut->addWikiMsg( 'logempty' );
699 }
700 }
701
702 /**
703 * Output just the list of entries given by the linked LogReader,
704 * with extraneous UI elements. Use for displaying log fragments in
705 * another page (eg at Special:Undelete)
706 * @param OutputPage $out where to send output
707 */
708 public function showList( &$out ) {
709 $logBody = $this->pager->getBody();
710 if( $logBody ) {
711 $out->addHTML(
712 $this->list->beginLogEventsList() .
713 $logBody .
714 $this->list->endLogEventsList()
715 );
716 } else {
717 $out->addWikiMsg( 'logempty' );
718 }
719 }
720 }