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