04df22698135ae5118dedbcfd06b1fce86352510
[lhc/web/wiklou.git] / includes / logging / LogEventsList.php
1 <?php
2 /**
3 * Contain classes to list log entries
4 *
5 * Copyright © 2004 Brion Vibber <brion@pobox.com>, 2008 Aaron Schulz
6 * http://www.mediawiki.org/
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
22 *
23 * @file
24 */
25
26 class LogEventsList {
27 const NO_ACTION_LINK = 1;
28 const NO_EXTRA_USER_LINKS = 2;
29 const USE_REVDEL_CHECKBOXES = 4;
30
31 /**
32 * @var Skin
33 */
34 private $skin;
35
36 /**
37 * @var OutputPage
38 */
39 private $out;
40 public $flags;
41
42 /**
43 * @var Array
44 */
45 protected $message;
46
47 /**
48 * @var Array
49 */
50 protected $mDefaultQuery;
51
52 public function __construct( $skin, $out, $flags = 0 ) {
53 $this->skin = $skin;
54 $this->out = $out;
55 $this->flags = $flags;
56 $this->preCacheMessages();
57 }
58
59 /**
60 * As we use the same small set of messages in various methods and that
61 * they are called often, we call them once and save them in $this->message
62 */
63 private function preCacheMessages() {
64 // Precache various messages
65 if( !isset( $this->message ) ) {
66 $messages = array( 'revertmerge', 'protect_change', 'unblocklink', 'change-blocklink',
67 'revertmove', 'undeletelink', 'undeleteviewlink', 'revdel-restore', 'hist', 'diff',
68 'pipe-separator', 'revdel-restore-deleted', 'revdel-restore-visible' );
69 foreach( $messages as $msg ) {
70 $this->message[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) );
71 }
72 }
73 }
74
75 /**
76 * Set page title and show header for this log type
77 * @param $type Array
78 * @deprecated in 1.19
79 */
80 public function showHeader( $type ) {
81 wfDeprecated( __METHOD__, '1.19' );
82 // If only one log type is used, then show a special message...
83 $headerType = (count($type) == 1) ? $type[0] : '';
84 if( LogPage::isLogType( $headerType ) ) {
85 $page = new LogPage( $headerType );
86 $this->out->setPageTitle( $page->getName()->text() );
87 $this->out->addHTML( $page->getDescription()->parseAsBlock() );
88 } else {
89 $this->out->addHTML( wfMsgExt('alllogstext',array('parseinline')) );
90 }
91 }
92
93 /**
94 * Show options for the log list
95 *
96 * @param $types string or Array
97 * @param $user String
98 * @param $page String
99 * @param $pattern String
100 * @param $year Integer: year
101 * @param $month Integer: month
102 * @param $filter: array
103 * @param $tagFilter: array?
104 */
105 public function showOptions( $types=array(), $user='', $page='', $pattern='', $year='',
106 $month = '', $filter = null, $tagFilter='' ) {
107 global $wgScript, $wgMiserMode;
108
109 $title = SpecialPage::getTitleFor( 'Log' );
110
111 // For B/C, we take strings, but make sure they are converted...
112 $types = ($types === '') ? array() : (array)$types;
113
114 $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter );
115
116 $html = Html::hidden( 'title', $title->getPrefixedDBkey() );
117
118 // Basic selectors
119 $html .= $this->getTypeMenu( $types ) . "\n";
120 $html .= $this->getUserInput( $user ) . "\n";
121 $html .= $this->getTitleInput( $page ) . "\n";
122 $html .= $this->getExtraInputs( $types ) . "\n";
123
124 // Title pattern, if allowed
125 if (!$wgMiserMode) {
126 $html .= $this->getTitlePattern( $pattern ) . "\n";
127 }
128
129 // date menu
130 $html .= Xml::tags( 'p', null, Xml::dateMenu( $year, $month ) );
131
132 // Tag filter
133 if ($tagSelector) {
134 $html .= Xml::tags( 'p', null, implode( '&#160;', $tagSelector ) );
135 }
136
137 // Filter links
138 if ($filter) {
139 $html .= Xml::tags( 'p', null, $this->getFilterLinks( $filter ) );
140 }
141
142 // Submit button
143 $html .= Xml::submitButton( wfMsg( 'allpagessubmit' ) );
144
145 // Fieldset
146 $html = Xml::fieldset( wfMsg( 'log' ), $html );
147
148 // Form wrapping
149 $html = Xml::tags( 'form', array( 'action' => $wgScript, 'method' => 'get' ), $html );
150
151 $this->out->addHTML( $html );
152 }
153
154 /**
155 * @param $filter Array
156 * @return String: Formatted HTML
157 */
158 private function getFilterLinks( $filter ) {
159 global $wgLang;
160 // show/hide links
161 $messages = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
162 // Option value -> message mapping
163 $links = array();
164 $hiddens = ''; // keep track for "go" button
165 foreach( $filter as $type => $val ) {
166 // Should the below assignment be outside the foreach?
167 // Then it would have to be copied. Not certain what is more expensive.
168 $query = $this->getDefaultQuery();
169 $queryKey = "hide_{$type}_log";
170
171 $hideVal = 1 - intval($val);
172 $query[$queryKey] = $hideVal;
173
174 $link = Linker::linkKnown(
175 $this->getDisplayTitle(),
176 $messages[$hideVal],
177 array(),
178 $query
179 );
180
181 $links[$type] = wfMsgHtml( "log-show-hide-{$type}", $link );
182 $hiddens .= Html::hidden( "hide_{$type}_log", $val ) . "\n";
183 }
184 // Build links
185 return '<small>'.$wgLang->pipeList( $links ) . '</small>' . $hiddens;
186 }
187
188 private function getDefaultQuery() {
189 global $wgRequest;
190
191 if ( !isset( $this->mDefaultQuery ) ) {
192 $this->mDefaultQuery = $wgRequest->getQueryValues();
193 unset( $this->mDefaultQuery['title'] );
194 unset( $this->mDefaultQuery['dir'] );
195 unset( $this->mDefaultQuery['offset'] );
196 unset( $this->mDefaultQuery['limit'] );
197 unset( $this->mDefaultQuery['order'] );
198 unset( $this->mDefaultQuery['month'] );
199 unset( $this->mDefaultQuery['year'] );
200 }
201 return $this->mDefaultQuery;
202 }
203
204 /**
205 * Get the Title object of the page the links should point to.
206 * This is NOT the Title of the page the entries should be restricted to.
207 *
208 * @return Title object
209 */
210 public function getDisplayTitle() {
211 return $this->out->getTitle();
212 }
213
214 public function getContext() {
215 return $this->out->getContext();
216 }
217
218 /**
219 * @param $queryTypes Array
220 * @return String: Formatted HTML
221 */
222 private function getTypeMenu( $queryTypes ) {
223 $queryType = count($queryTypes) == 1 ? $queryTypes[0] : '';
224 $selector = $this->getTypeSelector();
225 $selector->setDefault( $queryType );
226 return $selector->getHtml();
227 }
228
229 /**
230 * Returns log page selector.
231 * @return XmlSelect
232 * @since 1.19
233 */
234 public function getTypeSelector() {
235 global $wgUser;
236
237 $typesByName = array(); // Temporary array
238 // First pass to load the log names
239 foreach( LogPage::validTypes() as $type ) {
240 $page = new LogPage( $type );
241 $restriction = $page->getRestriction();
242 if ( $wgUser->isAllowed( $restriction ) ) {
243 $typesByName[$type] = $page->getName()->text();
244 }
245 }
246
247 // Second pass to sort by name
248 asort($typesByName);
249
250 // Always put "All public logs" on top
251 $public = $typesByName[''];
252 unset( $typesByName[''] );
253 $typesByName = array( '' => $public ) + $typesByName;
254
255 $select = new XmlSelect( 'type' );
256 foreach( $typesByName as $type => $name ) {
257 $select->addOption( $name, $type );
258 }
259
260 return $select;
261 }
262
263 /**
264 * @param $user String
265 * @return String: Formatted HTML
266 */
267 private function getUserInput( $user ) {
268 return '<span style="white-space: nowrap">' .
269 Xml::inputLabel( wfMsg( 'specialloguserlabel' ), 'user', 'mw-log-user', 15, $user ) .
270 '</span>';
271 }
272
273 /**
274 * @param $title String
275 * @return String: Formatted HTML
276 */
277 private function getTitleInput( $title ) {
278 return '<span style="white-space: nowrap">' .
279 Xml::inputLabel( wfMsg( 'speciallogtitlelabel' ), 'page', 'mw-log-page', 20, $title ) .
280 '</span>';
281 }
282
283 /**
284 * @param $pattern
285 * @return string Checkbox
286 */
287 private function getTitlePattern( $pattern ) {
288 return '<span style="white-space: nowrap">' .
289 Xml::checkLabel( wfMsg( 'log-title-wildcard' ), 'pattern', 'pattern', $pattern ) .
290 '</span>';
291 }
292
293 /**
294 * @param $types
295 * @return string
296 */
297 private function getExtraInputs( $types ) {
298 global $wgRequest;
299 $offender = $wgRequest->getVal('offender');
300 $user = User::newFromName( $offender, false );
301 if( !$user || ($user->getId() == 0 && !IP::isIPAddress($offender) ) ) {
302 $offender = ''; // Blank field if invalid
303 }
304 if( count($types) == 1 && $types[0] == 'suppress' ) {
305 return Xml::inputLabel( wfMsg('revdelete-offender'), 'offender',
306 'mw-log-offender', 20, $offender );
307 }
308 return '';
309 }
310
311 /**
312 * @return string
313 */
314 public function beginLogEventsList() {
315 return "<ul>\n";
316 }
317
318 /**
319 * @return string
320 */
321 public function endLogEventsList() {
322 return "</ul>\n";
323 }
324
325 /**
326 * @param $row Row: a single row from the result set
327 * @return String: Formatted HTML list item
328 */
329 public function logLine( $row ) {
330 $entry = DatabaseLogEntry::newFromRow( $row );
331 $formatter = LogFormatter::newFromEntry( $entry );
332 $formatter->setShowUserToolLinks( !( $this->flags & self::NO_EXTRA_USER_LINKS ) );
333
334 $action = $formatter->getActionText();
335 $comment = $formatter->getComment();
336
337 $classes = array( 'mw-logline-' . $entry->getType() );
338 $title = $entry->getTarget();
339 $time = $this->logTimestamp( $entry );
340
341 // Extract extra parameters
342 $paramArray = LogPage::extractParams( $row->log_params );
343 // Add review/revert links and such...
344 $revert = $this->logActionLinks( $row, $title, $paramArray, $comment );
345
346 // Some user can hide log items and have review links
347 $del = $this->getShowHideLinks( $row );
348 if( $del != '' ) $del .= ' ';
349
350 // Any tags...
351 list( $tagDisplay, $newClasses ) = ChangeTags::formatSummaryRow( $row->ts_tags, 'logevent' );
352 $classes = array_merge( $classes, $newClasses );
353
354 return Xml::tags( 'li', array( "class" => implode( ' ', $classes ) ),
355 $del . "$time $action $comment $revert $tagDisplay" ) . "\n";
356 }
357
358 private function logTimestamp( LogEntry $entry ) {
359 global $wgLang;
360 $time = $wgLang->timeanddate( wfTimestamp( TS_MW, $entry->getTimestamp() ), true );
361 return htmlspecialchars( $time );
362 }
363
364 /**
365 * @TODO: split up!
366 *
367 * @param $row
368 * @param Title $title
369 * @param Array $paramArray
370 * @param $comment
371 * @return String
372 */
373 private function logActionLinks( $row, $title, $paramArray, &$comment ) {
374 global $wgUser;
375 if( ( $this->flags & self::NO_ACTION_LINK ) // we don't want to see the action
376 || self::isDeleted( $row, LogPage::DELETED_ACTION ) ) // action is hidden
377 {
378 return '';
379 }
380 $revert = '';
381 if( self::typeAction( $row, 'move', 'move', 'move' ) && !empty( $paramArray[0] ) ) {
382 $destTitle = Title::newFromText( $paramArray[0] );
383 if( $destTitle ) {
384 $revert = Linker::linkKnown(
385 SpecialPage::getTitleFor( 'Movepage' ),
386 $this->message['revertmove'],
387 array(),
388 array(
389 'wpOldTitle' => $destTitle->getPrefixedDBkey(),
390 'wpNewTitle' => $title->getPrefixedDBkey(),
391 'wpReason' => wfMsgForContent( 'revertmove' ),
392 'wpMovetalk' => 0
393 )
394 );
395 $revert = wfMessage( 'parentheses' )->rawParams( $revert )->escaped();
396 }
397 // Show undelete link
398 } elseif( self::typeAction( $row, array( 'delete', 'suppress' ), 'delete', 'deletedhistory' ) ) {
399 if( !$wgUser->isAllowed( 'undelete' ) ) {
400 $viewdeleted = $this->message['undeleteviewlink'];
401 } else {
402 $viewdeleted = $this->message['undeletelink'];
403 }
404 $revert = Linker::linkKnown(
405 SpecialPage::getTitleFor( 'Undelete' ),
406 $viewdeleted,
407 array(),
408 array( 'target' => $title->getPrefixedDBkey() )
409 );
410 $revert = wfMessage( 'parentheses' )->rawParams( $revert )->escaped();
411 // Show unblock/change block link
412 } elseif( self::typeAction( $row, array( 'block', 'suppress' ), array( 'block', 'reblock' ), 'block' ) ) {
413 $revert = Linker::linkKnown(
414 SpecialPage::getTitleFor( 'Unblock', $row->log_title ),
415 $this->message['unblocklink']
416 ) .
417 $this->message['pipe-separator'] .
418 Linker::linkKnown(
419 SpecialPage::getTitleFor( 'Block', $row->log_title ),
420 $this->message['change-blocklink']
421 );
422 $revert = wfMessage( 'parentheses' )->rawParams( $revert )->escaped();
423 // Show change protection link
424 } elseif( self::typeAction( $row, 'protect', array( 'modify', 'protect', 'unprotect' ) ) ) {
425 $revert .= Linker::link( $title,
426 $this->message['hist'],
427 array(),
428 array(
429 'action' => 'history',
430 'offset' => $row->log_timestamp
431 )
432 );
433 if( $wgUser->isAllowed( 'protect' ) ) {
434 $revert .= $this->message['pipe-separator'] .
435 Linker::link( $title,
436 $this->message['protect_change'],
437 array(),
438 array( 'action' => 'protect' ),
439 'known' );
440 }
441 $revert = ' ' . wfMessage( 'parentheses' )->rawParams( $revert )->escaped();
442 // Show unmerge link
443 } elseif( self::typeAction( $row, 'merge', 'merge', 'mergehistory' ) ) {
444 $revert = Linker::linkKnown(
445 SpecialPage::getTitleFor( 'MergeHistory' ),
446 $this->message['revertmerge'],
447 array(),
448 array(
449 'target' => $paramArray[0],
450 'dest' => $title->getPrefixedDBkey(),
451 'mergepoint' => $paramArray[1]
452 )
453 );
454 $revert = wfMessage( 'parentheses' )->rawParams( $revert )->escaped();
455 // If an edit was hidden from a page give a review link to the history
456 } elseif( self::typeAction( $row, array( 'delete', 'suppress' ), 'revision', 'deletedhistory' ) ) {
457 $revert = RevisionDeleter::getLogLinks( $title, $paramArray,
458 $this->message );
459 // Hidden log items, give review link
460 } elseif( self::typeAction( $row, array( 'delete', 'suppress' ), 'event', 'deletedhistory' ) ) {
461 if( count($paramArray) >= 1 ) {
462 $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
463 // $paramArray[1] is a CSV of the IDs
464 $query = $paramArray[0];
465 // Link to each hidden object ID, $paramArray[1] is the url param
466 $revert = Linker::linkKnown(
467 $revdel,
468 $this->message['revdel-restore'],
469 array(),
470 array(
471 'target' => $title->getPrefixedText(),
472 'type' => 'logging',
473 'ids' => $query
474 )
475 );
476 $revert = wfMessage( 'parentheses' )->rawParams( $revert )->escaped();
477 }
478 // Do nothing. The implementation is handled by the hook modifiying the passed-by-ref parameters.
479 } else {
480 wfRunHooks( 'LogLine', array( $row->log_type, $row->log_action, $title, $paramArray,
481 &$comment, &$revert, $row->log_timestamp ) );
482 }
483 if( $revert != '' ) {
484 $revert = '<span class="mw-logevent-actionlink">' . $revert . '</span>';
485 }
486 return $revert;
487 }
488
489 /**
490 * @param $row Row
491 * @return string
492 */
493 private function getShowHideLinks( $row ) {
494 global $wgUser;
495 if( ( $this->flags == self::NO_ACTION_LINK ) // we don't want to see the links
496 || $row->log_type == 'suppress' ) { // no one can hide items from the suppress log
497 return '';
498 }
499 $del = '';
500 // Don't show useless checkbox to people who cannot hide revisions
501 if( $wgUser->isAllowed( 'deletedhistory' ) ) {
502 if( $row->log_deleted || $wgUser->isAllowed( 'deleterevision' ) ) {
503 $canHide = $wgUser->isAllowed( 'deleterevision' );
504 if ( $this->flags & self::USE_REVDEL_CHECKBOXES ) { // Show checkboxes instead of links.
505 if ( !self::userCan( $row, LogPage::DELETED_RESTRICTED ) ) { // If event was hidden from sysops
506 $del = Xml::check( 'deleterevisions', false, array( 'disabled' => 'disabled' ) );
507 } else {
508 $del = Xml::check( 'showhiderevisions', false, array( 'name' => 'ids[' . $row->log_id . ']' ) );
509 }
510 } else {
511 if ( !self::userCan( $row, LogPage::DELETED_RESTRICTED ) ) { // If event was hidden from sysops
512 $del = Linker::revDeleteLinkDisabled( $canHide );
513 } else {
514 $query = array(
515 'target' => SpecialPage::getTitleFor( 'Log', $row->log_type )->getPrefixedDBkey(),
516 'type' => 'logging',
517 'ids' => $row->log_id,
518 );
519 $del = Linker::revDeleteLink( $query, self::isDeleted( $row, LogPage::DELETED_RESTRICTED ), $canHide );
520 }
521 }
522 }
523 }
524 return $del;
525 }
526
527 /**
528 * @param $row Row
529 * @param $type Mixed: string/array
530 * @param $action Mixed: string/array
531 * @param $right string
532 * @return Boolean
533 */
534 public static function typeAction( $row, $type, $action, $right='' ) {
535 $match = is_array($type) ?
536 in_array( $row->log_type, $type ) : $row->log_type == $type;
537 if( $match ) {
538 $match = is_array( $action ) ?
539 in_array( $row->log_action, $action ) : $row->log_action == $action;
540 if( $match && $right ) {
541 global $wgUser;
542 $match = $wgUser->isAllowed( $right );
543 }
544 }
545 return $match;
546 }
547
548 /**
549 * Determine if the current user is allowed to view a particular
550 * field of this log row, if it's marked as deleted.
551 *
552 * @param $row Row
553 * @param $field Integer
554 * @param $user User object to check, or null to use $wgUser
555 * @return Boolean
556 */
557 public static function userCan( $row, $field, User $user = null ) {
558 return self::userCanBitfield( $row->log_deleted, $field, $user );
559 }
560
561 /**
562 * Determine if the current user is allowed to view a particular
563 * field of this log row, if it's marked as deleted.
564 *
565 * @param $bitfield Integer (current field)
566 * @param $field Integer
567 * @param $user User object to check, or null to use $wgUser
568 * @return Boolean
569 */
570 public static function userCanBitfield( $bitfield, $field, User $user = null ) {
571 if( $bitfield & $field ) {
572 if ( $bitfield & LogPage::DELETED_RESTRICTED ) {
573 $permission = 'suppressrevision';
574 } else {
575 $permission = 'deletedhistory';
576 }
577 wfDebug( "Checking for $permission due to $field match on $bitfield\n" );
578 if ( $user === null ) {
579 global $wgUser;
580 $user = $wgUser;
581 }
582 return $user->isAllowed( $permission );
583 } else {
584 return true;
585 }
586 }
587
588 /**
589 * @param $row Row
590 * @param $field Integer: one of DELETED_* bitfield constants
591 * @return Boolean
592 */
593 public static function isDeleted( $row, $field ) {
594 return ( $row->log_deleted & $field ) == $field;
595 }
596
597 /**
598 * Show log extract. Either with text and a box (set $msgKey) or without (don't set $msgKey)
599 *
600 * @param $out OutputPage|String-by-reference
601 * @param $types String|Array Log types to show
602 * @param $page String|Title The page title to show log entries for
603 * @param $user String The user who made the log entries
604 * @param $param array Associative Array with the following additional options:
605 * - lim Integer Limit of items to show, default is 50
606 * - conds Array Extra conditions for the query (e.g. "log_action != 'revision'")
607 * - showIfEmpty boolean Set to false if you don't want any output in case the loglist is empty
608 * if set to true (default), "No matching items in log" is displayed if loglist is empty
609 * - msgKey Array If you want a nice box with a message, set this to the key of the message.
610 * First element is the message key, additional optional elements are parameters for the key
611 * that are processed with wfMsgExt and option 'parse'
612 * - offset Set to overwrite offset parameter in $wgRequest
613 * set to '' to unset offset
614 * - wrap String Wrap the message in html (usually something like "<div ...>$1</div>").
615 * - flags Integer display flags (NO_ACTION_LINK,NO_EXTRA_USER_LINKS)
616 * @return Integer Number of total log items (not limited by $lim)
617 */
618 public static function showLogExtract(
619 &$out, $types=array(), $page='', $user='', $param = array()
620 ) {
621 $defaultParameters = array(
622 'lim' => 25,
623 'conds' => array(),
624 'showIfEmpty' => true,
625 'msgKey' => array(''),
626 'wrap' => "$1",
627 'flags' => 0
628 );
629 # The + operator appends elements of remaining keys from the right
630 # handed array to the left handed, whereas duplicated keys are NOT overwritten.
631 $param += $defaultParameters;
632 # Convert $param array to individual variables
633 $lim = $param['lim'];
634 $conds = $param['conds'];
635 $showIfEmpty = $param['showIfEmpty'];
636 $msgKey = $param['msgKey'];
637 $wrap = $param['wrap'];
638 $flags = $param['flags'];
639 if ( !is_array( $msgKey ) ) {
640 $msgKey = array( $msgKey );
641 }
642
643 if ( $out instanceof OutputPage ) {
644 $context = $out->getContext();
645 } else {
646 $context = RequestContext::getMain();
647 }
648
649 # Insert list of top 50 (or top $lim) items
650 $loglist = new LogEventsList( $context->getSkin(), $context->getOutput(), $flags );
651 $pager = new LogPager( $loglist, $types, $user, $page, '', $conds );
652 if ( isset( $param['offset'] ) ) { # Tell pager to ignore $wgRequest offset
653 $pager->setOffset( $param['offset'] );
654 }
655 if( $lim > 0 ) $pager->mLimit = $lim;
656 $logBody = $pager->getBody();
657 $s = '';
658 if( $logBody ) {
659 if ( $msgKey[0] ) {
660 $s = '<div class="mw-warning-with-logexcerpt">';
661
662 if ( count( $msgKey ) == 1 ) {
663 $s .= wfMsgExt( $msgKey[0], array( 'parse' ) );
664 } else { // Process additional arguments
665 $args = $msgKey;
666 array_shift( $args );
667 $s .= wfMsgExt( $msgKey[0], array( 'parse' ), $args );
668 }
669 }
670 $s .= $loglist->beginLogEventsList() .
671 $logBody .
672 $loglist->endLogEventsList();
673 } else {
674 if ( $showIfEmpty ) {
675 $s = Html::rawElement( 'div', array( 'class' => 'mw-warning-logempty' ),
676 wfMsgExt( 'logempty', array( 'parseinline' ) ) );
677 }
678 }
679 if( $pager->getNumRows() > $pager->mLimit ) { # Show "Full log" link
680 $urlParam = array();
681 if ( $page instanceof Title ) {
682 $urlParam['page'] = $page->getPrefixedDBkey();
683 } elseif ( $page != '' ) {
684 $urlParam['page'] = $page;
685 }
686 if ( $user != '')
687 $urlParam['user'] = $user;
688 if ( !is_array( $types ) ) # Make it an array, if it isn't
689 $types = array( $types );
690 # If there is exactly one log type, we can link to Special:Log?type=foo
691 if ( count( $types ) == 1 )
692 $urlParam['type'] = $types[0];
693 $s .= Linker::link(
694 SpecialPage::getTitleFor( 'Log' ),
695 wfMsgHtml( 'log-fulllog' ),
696 array(),
697 $urlParam
698 );
699 }
700 if ( $logBody && $msgKey[0] ) {
701 $s .= '</div>';
702 }
703
704 if ( $wrap != '' ) { // Wrap message in html
705 $s = str_replace( '$1', $s, $wrap );
706 }
707
708 /* hook can return false, if we don't want the message to be emitted (Wikia BugId:7093) */
709 if ( wfRunHooks( 'LogEventsListShowLogExtract', array( &$s, $types, $page, $user, $param ) ) ) {
710 // $out can be either an OutputPage object or a String-by-reference
711 if ( $out instanceof OutputPage ){
712 $out->addHTML( $s );
713 } else {
714 $out = $s;
715 }
716 }
717
718 return $pager->getNumRows();
719 }
720
721 /**
722 * SQL clause to skip forbidden log types for this user
723 *
724 * @param $db DatabaseBase
725 * @param $audience string, public/user
726 * @return Mixed: string or false
727 */
728 public static function getExcludeClause( $db, $audience = 'public' ) {
729 global $wgLogRestrictions, $wgUser;
730 // Reset the array, clears extra "where" clauses when $par is used
731 $hiddenLogs = array();
732 // Don't show private logs to unprivileged users
733 foreach( $wgLogRestrictions as $logType => $right ) {
734 if( $audience == 'public' || !$wgUser->isAllowed($right) ) {
735 $safeType = $db->strencode( $logType );
736 $hiddenLogs[] = $safeType;
737 }
738 }
739 if( count($hiddenLogs) == 1 ) {
740 return 'log_type != ' . $db->addQuotes( $hiddenLogs[0] );
741 } elseif( $hiddenLogs ) {
742 return 'log_type NOT IN (' . $db->makeList($hiddenLogs) . ')';
743 }
744 return false;
745 }
746 }