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