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