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