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