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