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