Merge "Move User::getAllRights to PermissionManager."
[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>
6 * https://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 use MediaWiki\Linker\LinkRenderer;
27 use MediaWiki\MediaWikiServices;
28 use Wikimedia\Rdbms\IDatabase;
29
30 class LogEventsList extends ContextSource {
31 const NO_ACTION_LINK = 1;
32 const NO_EXTRA_USER_LINKS = 2;
33 const USE_CHECKBOXES = 4;
34
35 public $flags;
36
37 /**
38 * @var array
39 */
40 protected $mDefaultQuery;
41
42 /**
43 * @var bool
44 */
45 protected $showTagEditUI;
46
47 /**
48 * @var array
49 */
50 protected $allowedActions = null;
51
52 /**
53 * @var LinkRenderer|null
54 */
55 private $linkRenderer;
56
57 /**
58 * The first two parameters used to be $skin and $out, but now only a context
59 * is needed, that's why there's a second unused parameter.
60 *
61 * @param IContextSource|Skin $context Context to use; formerly it was
62 * a Skin object. Use of Skin is deprecated.
63 * @param LinkRenderer|null $linkRenderer previously unused
64 * @param int $flags Can be a combination of self::NO_ACTION_LINK,
65 * self::NO_EXTRA_USER_LINKS or self::USE_CHECKBOXES.
66 */
67 public function __construct( $context, $linkRenderer = null, $flags = 0 ) {
68 if ( $context instanceof IContextSource ) {
69 $this->setContext( $context );
70 } else {
71 // Old parameters, $context should be a Skin object
72 $this->setContext( $context->getContext() );
73 }
74
75 $this->flags = $flags;
76 $this->showTagEditUI = ChangeTags::showTagEditingUI( $this->getUser() );
77 if ( $linkRenderer instanceof LinkRenderer ) {
78 $this->linkRenderer = $linkRenderer;
79 }
80 }
81
82 /**
83 * @since 1.30
84 * @return LinkRenderer
85 */
86 protected function getLinkRenderer() {
87 if ( $this->linkRenderer !== null ) {
88 return $this->linkRenderer;
89 } else {
90 return MediaWikiServices::getInstance()->getLinkRenderer();
91 }
92 }
93
94 /**
95 * Show options for the log list
96 *
97 * @param array|string $types
98 * @param string $user
99 * @param string $page
100 * @param bool $pattern
101 * @param int|string $year Use 0 to start with no year preselected.
102 * @param int|string $month A month in the 1..12 range. Use 0 to start with no month
103 * preselected.
104 * @param int|string $day A day in the 1..31 range. Use 0 to start with no month
105 * preselected.
106 * @param array|null $filter
107 * @param string $tagFilter Tag to select by default
108 * @param string|null $action
109 */
110 public function showOptions( $types = [], $user = '', $page = '', $pattern = false, $year = 0,
111 $month = 0, $day = 0, $filter = null, $tagFilter = '', $action = null
112 ) {
113 // For B/C, we take strings, but make sure they are converted...
114 $types = ( $types === '' ) ? [] : (array)$types;
115
116 $formDescriptor = [];
117
118 // Basic selectors
119 $formDescriptor['type'] = $this->getTypeMenuDesc( $types );
120 $formDescriptor['user'] = $this->getUserInputDesc( $user );
121 $formDescriptor['page'] = $this->getTitleInputDesc( $page );
122
123 // Add extra inputs if any
124 // This could either be a form descriptor array or a string with raw HTML.
125 // We need it to work in both cases and show a deprecation warning if it
126 // is a string. See T199495.
127 $extraInputsDescriptor = $this->getExtraInputsDesc( $types );
128 if (
129 is_array( $extraInputsDescriptor ) &&
130 !empty( $extraInputsDescriptor )
131 ) {
132 $formDescriptor[ 'extra' ] = $extraInputsDescriptor;
133 } elseif (
134 is_string( $extraInputsDescriptor ) &&
135 $extraInputsDescriptor !== ''
136 ) {
137 // We'll add this to the footer of the form later
138 $extraInputsString = $extraInputsDescriptor;
139 wfDeprecated( '$input in LogEventsListGetExtraInputs hook', '1.32' );
140 }
141
142 // Title pattern, if allowed
143 if ( !$this->getConfig()->get( 'MiserMode' ) ) {
144 $formDescriptor['pattern'] = $this->getTitlePatternDesc( $pattern );
145 }
146
147 // Date menu
148 $formDescriptor['date'] = [
149 'type' => 'date',
150 'label-message' => 'date',
151 'default' => $year && $month && $day ? sprintf( "%04d-%02d-%02d", $year, $month, $day ) : '',
152 ];
153
154 // Tag filter
155 $formDescriptor['tagfilter'] = [
156 'type' => 'tagfilter',
157 'name' => 'tagfilter',
158 'label-raw' => $this->msg( 'tag-filter' )->parse(),
159 ];
160
161 // Filter links
162 if ( $filter ) {
163 $formDescriptor['filters'] = $this->getFiltersDesc( $filter );
164 }
165
166 // Action filter
167 if (
168 $action !== null &&
169 $this->allowedActions !== null &&
170 count( $this->allowedActions ) > 0
171 ) {
172 $formDescriptor['subtype'] = $this->getActionSelectorDesc( $types, $action );
173 }
174
175 $context = new DerivativeContext( $this->getContext() );
176 $context->setTitle( SpecialPage::getTitleFor( 'Log' ) ); // Remove subpage
177 $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $context );
178 $htmlForm
179 ->setSubmitText( $this->msg( 'logeventslist-submit' )->text() )
180 ->setMethod( 'get' )
181 ->setWrapperLegendMsg( 'log' );
182
183 // TODO This will should be removed at some point. See T199495.
184 if ( isset( $extraInputsString ) ) {
185 $htmlForm->addFooterText( Html::rawElement(
186 'div',
187 null,
188 $extraInputsString
189 ) );
190 }
191
192 $htmlForm->prepareForm()->displayForm( false );
193 }
194
195 /**
196 * @param array $filter
197 * @return array Form descriptor
198 */
199 private function getFiltersDesc( $filter ) {
200 $options = [];
201 $default = [];
202 foreach ( $filter as $type => $val ) {
203 $message = $this->msg( "logeventslist-{$type}-log" );
204 // FIXME: Remove this check once T199657 is fully resolved.
205 if ( !$message->exists() ) {
206 $message = $this->msg( "log-show-hide-{$type}" )->params( $this->msg( 'show' )->text() );
207 }
208 $options[ $message->text() ] = $type;
209
210 if ( $val === false ) {
211 $default[] = $type;
212 }
213 }
214 return [
215 'class' => 'HTMLMultiSelectField',
216 'label-message' => 'logeventslist-more-filters',
217 'flatlist' => true,
218 'options' => $options,
219 'default' => $default,
220 ];
221 }
222
223 /**
224 * @param array $queryTypes
225 * @return array Form descriptor
226 */
227 private function getTypeMenuDesc( $queryTypes ) {
228 $queryType = count( $queryTypes ) == 1 ? $queryTypes[0] : '';
229
230 $typesByName = []; // Temporary array
231 // First pass to load the log names
232 foreach ( LogPage::validTypes() as $type ) {
233 $page = new LogPage( $type );
234 $restriction = $page->getRestriction();
235 if ( $this->getUser()->isAllowed( $restriction ) ) {
236 $typesByName[$type] = $page->getName()->text();
237 }
238 }
239
240 // Second pass to sort by name
241 asort( $typesByName );
242
243 // Always put "All public logs" on top
244 $public = $typesByName[''];
245 unset( $typesByName[''] );
246 $typesByName = [ '' => $public ] + $typesByName;
247
248 return [
249 'class' => 'HTMLSelectField',
250 'name' => 'type',
251 'options' => array_flip( $typesByName ),
252 'default' => $queryType,
253 ];
254 }
255
256 /**
257 * @param string $user
258 * @return array Form descriptor
259 */
260 private function getUserInputDesc( $user ) {
261 return [
262 'class' => 'HTMLUserTextField',
263 'label-message' => 'specialloguserlabel',
264 'name' => 'user',
265 'default' => $user,
266 ];
267 }
268
269 /**
270 * @param string $title
271 * @return array Form descriptor
272 */
273 private function getTitleInputDesc( $title ) {
274 return [
275 'class' => 'HTMLTitleTextField',
276 'label-message' => 'speciallogtitlelabel',
277 'name' => 'page',
278 'required' => false
279 ];
280 }
281
282 /**
283 * @param bool $pattern
284 * @return array Form descriptor
285 */
286 private function getTitlePatternDesc( $pattern ) {
287 return [
288 'type' => 'check',
289 'label-message' => 'log-title-wildcard',
290 'name' => 'pattern',
291 ];
292 }
293
294 /**
295 * @param array $types
296 * @return array|string Form descriptor or string with HTML
297 */
298 private function getExtraInputsDesc( $types ) {
299 if ( count( $types ) == 1 ) {
300 if ( $types[0] == 'suppress' ) {
301 return [
302 'type' => 'text',
303 'label-message' => 'revdelete-offender',
304 'name' => 'offender',
305 ];
306 } else {
307 // Allow extensions to add their own extra inputs
308 // This could be an array or string. See T199495.
309 $input = ''; // Deprecated
310 $formDescriptor = [];
311 Hooks::run( 'LogEventsListGetExtraInputs', [ $types[0], $this, &$input, &$formDescriptor ] );
312
313 return empty( $formDescriptor ) ? $input : $formDescriptor;
314 }
315 }
316
317 return [];
318 }
319
320 /**
321 * Drop down menu for selection of actions that can be used to filter the log
322 * @param array $types
323 * @param string $action
324 * @return array Form descriptor
325 */
326 private function getActionSelectorDesc( $types, $action ) {
327 $actionOptions = [];
328 $actionOptions[ 'log-action-filter-all' ] = '';
329
330 foreach ( $this->allowedActions as $value ) {
331 $msgKey = 'log-action-filter-' . $types[0] . '-' . $value;
332 $actionOptions[ $msgKey ] = $value;
333 }
334
335 return [
336 'class' => 'HTMLSelectField',
337 'name' => 'subtype',
338 'options-messages' => $actionOptions,
339 'default' => $action,
340 'label' => $this->msg( 'log-action-filter-' . $types[0] )->text(),
341 ];
342 }
343
344 /**
345 * Sets the action types allowed for log filtering
346 * To one action type may correspond several log_actions
347 * @param array $actions
348 * @since 1.27
349 */
350 public function setAllowedActions( $actions ) {
351 $this->allowedActions = $actions;
352 }
353
354 /**
355 * @return string
356 */
357 public function beginLogEventsList() {
358 return "<ul>\n";
359 }
360
361 /**
362 * @return string
363 */
364 public function endLogEventsList() {
365 return "</ul>\n";
366 }
367
368 /**
369 * @param stdClass $row A single row from the result set
370 * @return string Formatted HTML list item
371 */
372 public function logLine( $row ) {
373 $entry = DatabaseLogEntry::newFromRow( $row );
374 $formatter = LogFormatter::newFromEntry( $entry );
375 $formatter->setContext( $this->getContext() );
376 $formatter->setLinkRenderer( $this->getLinkRenderer() );
377 $formatter->setShowUserToolLinks( !( $this->flags & self::NO_EXTRA_USER_LINKS ) );
378
379 $time = htmlspecialchars( $this->getLanguage()->userTimeAndDate(
380 $entry->getTimestamp(), $this->getUser() ) );
381
382 $action = $formatter->getActionText();
383
384 if ( $this->flags & self::NO_ACTION_LINK ) {
385 $revert = '';
386 } else {
387 $revert = $formatter->getActionLinks();
388 if ( $revert != '' ) {
389 $revert = '<span class="mw-logevent-actionlink">' . $revert . '</span>';
390 }
391 }
392
393 $comment = $formatter->getComment();
394
395 // Some user can hide log items and have review links
396 $del = $this->getShowHideLinks( $row );
397
398 // Any tags...
399 list( $tagDisplay, $newClasses ) = ChangeTags::formatSummaryRow(
400 $row->ts_tags,
401 'logevent',
402 $this->getContext()
403 );
404 $classes = array_merge(
405 [ 'mw-logline-' . $entry->getType() ],
406 $newClasses
407 );
408 $attribs = [
409 'data-mw-logid' => $entry->getId(),
410 'data-mw-logaction' => $entry->getFullType(),
411 ];
412 $ret = "$del $time $action $comment $revert $tagDisplay";
413
414 // Let extensions add data
415 Hooks::run( 'LogEventsListLineEnding', [ $this, &$ret, $entry, &$classes, &$attribs ] );
416 $attribs = array_filter( $attribs,
417 [ Sanitizer::class, 'isReservedDataAttribute' ],
418 ARRAY_FILTER_USE_KEY
419 );
420 $attribs['class'] = implode( ' ', $classes );
421
422 return Html::rawElement( 'li', $attribs, $ret ) . "\n";
423 }
424
425 /**
426 * @param stdClass $row
427 * @return string
428 */
429 private function getShowHideLinks( $row ) {
430 // We don't want to see the links and
431 if ( $this->flags == self::NO_ACTION_LINK ) {
432 return '';
433 }
434
435 $user = $this->getUser();
436
437 // If change tag editing is available to this user, return the checkbox
438 if ( $this->flags & self::USE_CHECKBOXES && $this->showTagEditUI ) {
439 return Xml::check(
440 'showhiderevisions',
441 false,
442 [ 'name' => 'ids[' . $row->log_id . ']' ]
443 );
444 }
445
446 // no one can hide items from the suppress log.
447 if ( $row->log_type == 'suppress' ) {
448 return '';
449 }
450
451 $del = '';
452 // Don't show useless checkbox to people who cannot hide log entries
453 if ( $user->isAllowed( 'deletedhistory' ) ) {
454 $canHide = $user->isAllowed( 'deletelogentry' );
455 $canViewSuppressedOnly = $user->isAllowed( 'viewsuppressed' ) &&
456 !$user->isAllowed( 'suppressrevision' );
457 $entryIsSuppressed = self::isDeleted( $row, LogPage::DELETED_RESTRICTED );
458 $canViewThisSuppressedEntry = $canViewSuppressedOnly && $entryIsSuppressed;
459 if ( $row->log_deleted || $canHide ) {
460 // Show checkboxes instead of links.
461 if ( $canHide && $this->flags & self::USE_CHECKBOXES && !$canViewThisSuppressedEntry ) {
462 // If event was hidden from sysops
463 if ( !self::userCan( $row, LogPage::DELETED_RESTRICTED, $user ) ) {
464 $del = Xml::check( 'deleterevisions', false, [ 'disabled' => 'disabled' ] );
465 } else {
466 $del = Xml::check(
467 'showhiderevisions',
468 false,
469 [ 'name' => 'ids[' . $row->log_id . ']' ]
470 );
471 }
472 } else {
473 // If event was hidden from sysops
474 if ( !self::userCan( $row, LogPage::DELETED_RESTRICTED, $user ) ) {
475 $del = Linker::revDeleteLinkDisabled( $canHide );
476 } else {
477 $query = [
478 'target' => SpecialPage::getTitleFor( 'Log', $row->log_type )->getPrefixedDBkey(),
479 'type' => 'logging',
480 'ids' => $row->log_id,
481 ];
482 $del = Linker::revDeleteLink(
483 $query,
484 $entryIsSuppressed,
485 $canHide && !$canViewThisSuppressedEntry
486 );
487 }
488 }
489 }
490 }
491
492 return $del;
493 }
494
495 /**
496 * @param stdClass $row
497 * @param string|array $type
498 * @param string|array $action
499 * @param string $right
500 * @return bool
501 */
502 public static function typeAction( $row, $type, $action, $right = '' ) {
503 $match = is_array( $type ) ?
504 in_array( $row->log_type, $type ) : $row->log_type == $type;
505 if ( $match ) {
506 $match = is_array( $action ) ?
507 in_array( $row->log_action, $action ) : $row->log_action == $action;
508 if ( $match && $right ) {
509 global $wgUser;
510 $match = $wgUser->isAllowed( $right );
511 }
512 }
513
514 return $match;
515 }
516
517 /**
518 * Determine if the current user is allowed to view a particular
519 * field of this log row, if it's marked as deleted and/or restricted log type.
520 *
521 * @param stdClass $row
522 * @param int $field
523 * @param User|null $user User to check, or null to use $wgUser
524 * @return bool
525 */
526 public static function userCan( $row, $field, User $user = null ) {
527 return self::userCanBitfield( $row->log_deleted, $field, $user ) &&
528 self::userCanViewLogType( $row->log_type, $user );
529 }
530
531 /**
532 * Determine if the current user is allowed to view a particular
533 * field of this log row, if it's marked as deleted.
534 *
535 * @param int $bitfield Current field
536 * @param int $field
537 * @param User|null $user User to check, or null to use $wgUser
538 * @return bool
539 */
540 public static function userCanBitfield( $bitfield, $field, User $user = null ) {
541 if ( $bitfield & $field ) {
542 if ( $user === null ) {
543 global $wgUser;
544 $user = $wgUser;
545 }
546 if ( $bitfield & LogPage::DELETED_RESTRICTED ) {
547 $permissions = [ 'suppressrevision', 'viewsuppressed' ];
548 } else {
549 $permissions = [ 'deletedhistory' ];
550 }
551 $permissionlist = implode( ', ', $permissions );
552 wfDebug( "Checking for $permissionlist due to $field match on $bitfield\n" );
553 return MediaWikiServices::getInstance()
554 ->getPermissionManager()
555 ->userHasAnyRight( $user, ...$permissions );
556 }
557 return true;
558 }
559
560 /**
561 * Determine if the current user is allowed to view a particular
562 * field of this log row, if it's marked as restricted log type.
563 *
564 * @param stdClass $type
565 * @param User|null $user User to check, or null to use $wgUser
566 * @return bool
567 */
568 public static function userCanViewLogType( $type, User $user = null ) {
569 if ( $user === null ) {
570 global $wgUser;
571 $user = $wgUser;
572 }
573 $logRestrictions = MediaWikiServices::getInstance()->getMainConfig()->get( 'LogRestrictions' );
574 if ( isset( $logRestrictions[$type] ) && !$user->isAllowed( $logRestrictions[$type] ) ) {
575 return false;
576 }
577 return true;
578 }
579
580 /**
581 * @param stdClass $row
582 * @param int $field One of DELETED_* bitfield constants
583 * @return bool
584 */
585 public static function isDeleted( $row, $field ) {
586 return ( $row->log_deleted & $field ) == $field;
587 }
588
589 /**
590 * Show log extract. Either with text and a box (set $msgKey) or without (don't set $msgKey)
591 *
592 * @param OutputPage|string &$out
593 * @param string|array $types Log types to show
594 * @param string|Title $page The page title to show log entries for
595 * @param string $user The user who made the log entries
596 * @param array $param Associative Array with the following additional options:
597 * - lim Integer Limit of items to show, default is 50
598 * - conds Array Extra conditions for the query
599 * (e.g. 'log_action != ' . $dbr->addQuotes( 'revision' ))
600 * - showIfEmpty boolean Set to false if you don't want any output in case the loglist is empty
601 * if set to true (default), "No matching items in log" is displayed if loglist is empty
602 * - msgKey Array If you want a nice box with a message, set this to the key of the message.
603 * First element is the message key, additional optional elements are parameters for the key
604 * that are processed with wfMessage
605 * - offset Set to overwrite offset parameter in WebRequest
606 * set to '' to unset offset
607 * - wrap String Wrap the message in html (usually something like "<div ...>$1</div>").
608 * - flags Integer display flags (NO_ACTION_LINK,NO_EXTRA_USER_LINKS)
609 * - useRequestParams boolean Set true to use Pager-related parameters in the WebRequest
610 * - useMaster boolean Use master DB
611 * - extraUrlParams array|bool Additional url parameters for "full log" link (if it is shown)
612 * @return int Number of total log items (not limited by $lim)
613 */
614 public static function showLogExtract(
615 &$out, $types = [], $page = '', $user = '', $param = []
616 ) {
617 $defaultParameters = [
618 'lim' => 25,
619 'conds' => [],
620 'showIfEmpty' => true,
621 'msgKey' => [ '' ],
622 'wrap' => "$1",
623 'flags' => 0,
624 'useRequestParams' => false,
625 'useMaster' => false,
626 'extraUrlParams' => false,
627 ];
628 # The + operator appends elements of remaining keys from the right
629 # handed array to the left handed, whereas duplicated keys are NOT overwritten.
630 $param += $defaultParameters;
631 # Convert $param array to individual variables
632 $lim = $param['lim'];
633 $conds = $param['conds'];
634 $showIfEmpty = $param['showIfEmpty'];
635 $msgKey = $param['msgKey'];
636 $wrap = $param['wrap'];
637 $flags = $param['flags'];
638 $extraUrlParams = $param['extraUrlParams'];
639
640 $useRequestParams = $param['useRequestParams'];
641 if ( !is_array( $msgKey ) ) {
642 $msgKey = [ $msgKey ];
643 }
644
645 if ( $out instanceof OutputPage ) {
646 $context = $out->getContext();
647 } else {
648 $context = RequestContext::getMain();
649 }
650
651 // FIXME: Figure out how to inject this
652 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
653
654 # Insert list of top 50 (or top $lim) items
655 $loglist = new LogEventsList( $context, $linkRenderer, $flags );
656 $pager = new LogPager( $loglist, $types, $user, $page, '', $conds );
657 if ( !$useRequestParams ) {
658 # Reset vars that may have been taken from the request
659 $pager->mLimit = 50;
660 $pager->mDefaultLimit = 50;
661 $pager->mOffset = "";
662 $pager->mIsBackwards = false;
663 }
664
665 if ( $param['useMaster'] ) {
666 $pager->mDb = wfGetDB( DB_MASTER );
667 }
668 if ( isset( $param['offset'] ) ) { # Tell pager to ignore WebRequest offset
669 $pager->setOffset( $param['offset'] );
670 }
671
672 if ( $lim > 0 ) {
673 $pager->mLimit = $lim;
674 }
675 // Fetch the log rows and build the HTML if needed
676 $logBody = $pager->getBody();
677 $numRows = $pager->getNumRows();
678
679 $s = '';
680
681 if ( $logBody ) {
682 if ( $msgKey[0] ) {
683 $dir = $context->getLanguage()->getDir();
684 $lang = $context->getLanguage()->getHtmlCode();
685
686 $s = Xml::openElement( 'div', [
687 'class' => "mw-warning-with-logexcerpt mw-content-$dir",
688 'dir' => $dir,
689 'lang' => $lang,
690 ] );
691
692 if ( count( $msgKey ) == 1 ) {
693 $s .= $context->msg( $msgKey[0] )->parseAsBlock();
694 } else { // Process additional arguments
695 $args = $msgKey;
696 array_shift( $args );
697 $s .= $context->msg( $msgKey[0], $args )->parseAsBlock();
698 }
699 }
700 $s .= $loglist->beginLogEventsList() .
701 $logBody .
702 $loglist->endLogEventsList();
703 // add styles for change tags
704 $context->getOutput()->addModuleStyles( 'mediawiki.interface.helpers.styles' );
705 } elseif ( $showIfEmpty ) {
706 $s = Html::rawElement( 'div', [ 'class' => 'mw-warning-logempty' ],
707 $context->msg( 'logempty' )->parse() );
708 }
709
710 if ( $numRows > $pager->mLimit ) { # Show "Full log" link
711 $urlParam = [];
712 if ( $page instanceof Title ) {
713 $urlParam['page'] = $page->getPrefixedDBkey();
714 } elseif ( $page != '' ) {
715 $urlParam['page'] = $page;
716 }
717
718 if ( $user != '' ) {
719 $urlParam['user'] = $user;
720 }
721
722 if ( !is_array( $types ) ) { # Make it an array, if it isn't
723 $types = [ $types ];
724 }
725
726 # If there is exactly one log type, we can link to Special:Log?type=foo
727 if ( count( $types ) == 1 ) {
728 $urlParam['type'] = $types[0];
729 }
730
731 if ( $extraUrlParams !== false ) {
732 $urlParam = array_merge( $urlParam, $extraUrlParams );
733 }
734
735 $s .= $linkRenderer->makeKnownLink(
736 SpecialPage::getTitleFor( 'Log' ),
737 $context->msg( 'log-fulllog' )->text(),
738 [],
739 $urlParam
740 );
741 }
742
743 if ( $logBody && $msgKey[0] ) {
744 $s .= '</div>';
745 }
746
747 if ( $wrap != '' ) { // Wrap message in html
748 $s = str_replace( '$1', $s, $wrap );
749 }
750
751 /* hook can return false, if we don't want the message to be emitted (Wikia BugId:7093) */
752 if ( Hooks::run( 'LogEventsListShowLogExtract', [ &$s, $types, $page, $user, $param ] ) ) {
753 // $out can be either an OutputPage object or a String-by-reference
754 if ( $out instanceof OutputPage ) {
755 $out->addHTML( $s );
756 } else {
757 $out = $s;
758 }
759 }
760
761 return $numRows;
762 }
763
764 /**
765 * SQL clause to skip forbidden log types for this user
766 *
767 * @param IDatabase $db
768 * @param string $audience Public/user
769 * @param User|null $user User to check, or null to use $wgUser
770 * @return string|bool String on success, false on failure.
771 */
772 public static function getExcludeClause( $db, $audience = 'public', User $user = null ) {
773 global $wgLogRestrictions;
774
775 if ( $audience != 'public' && $user === null ) {
776 global $wgUser;
777 $user = $wgUser;
778 }
779
780 // Reset the array, clears extra "where" clauses when $par is used
781 $hiddenLogs = [];
782
783 // Don't show private logs to unprivileged users
784 foreach ( $wgLogRestrictions as $logType => $right ) {
785 if ( $audience == 'public' || !$user->isAllowed( $right ) ) {
786 $hiddenLogs[] = $logType;
787 }
788 }
789 if ( count( $hiddenLogs ) == 1 ) {
790 return 'log_type != ' . $db->addQuotes( $hiddenLogs[0] );
791 } elseif ( $hiddenLogs ) {
792 return 'log_type NOT IN (' . $db->makeList( $hiddenLogs ) . ')';
793 }
794
795 return false;
796 }
797 }