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