Move IDatabase/IMaintainableDatabase to Rdbms namespace
[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>, 2008 Aaron Schulz
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\MediaWikiServices;
27 use Wikimedia\Rdbms\IDatabase;
28
29 class LogEventsList extends ContextSource {
30 const NO_ACTION_LINK = 1;
31 const NO_EXTRA_USER_LINKS = 2;
32 const USE_CHECKBOXES = 4;
33
34 public $flags;
35
36 /**
37 * @var array
38 */
39 protected $mDefaultQuery;
40
41 /**
42 * @var bool
43 */
44 protected $showTagEditUI;
45
46 /**
47 * @var array
48 */
49 protected $allowedActions = null;
50
51 /**
52 * Constructor.
53 * The first two parameters used to be $skin and $out, but now only a context
54 * is needed, that's why there's a second unused parameter.
55 *
56 * @param IContextSource|Skin $context Context to use; formerly it was
57 * a Skin object. Use of Skin is deprecated.
58 * @param null $unused Unused; used to be an OutputPage object.
59 * @param int $flags Can be a combination of self::NO_ACTION_LINK,
60 * self::NO_EXTRA_USER_LINKS or self::USE_CHECKBOXES.
61 */
62 public function __construct( $context, $unused = null, $flags = 0 ) {
63 if ( $context instanceof IContextSource ) {
64 $this->setContext( $context );
65 } else {
66 // Old parameters, $context should be a Skin object
67 $this->setContext( $context->getContext() );
68 }
69
70 $this->flags = $flags;
71 $this->showTagEditUI = ChangeTags::showTagEditingUI( $this->getUser() );
72 }
73
74 /**
75 * Show options for the log list
76 *
77 * @param array|string $types
78 * @param string $user
79 * @param string $page
80 * @param string $pattern
81 * @param int $year Year
82 * @param int $month Month
83 * @param array $filter
84 * @param string $tagFilter Tag to select by default
85 * @param string $action
86 */
87 public function showOptions( $types = [], $user = '', $page = '', $pattern = '', $year = 0,
88 $month = 0, $filter = null, $tagFilter = '', $action = null
89 ) {
90 global $wgScript, $wgMiserMode;
91
92 $title = SpecialPage::getTitleFor( 'Log' );
93
94 // For B/C, we take strings, but make sure they are converted...
95 $types = ( $types === '' ) ? [] : (array)$types;
96
97 $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter, false, $this->getContext() );
98
99 $html = Html::hidden( 'title', $title->getPrefixedDBkey() );
100
101 // Basic selectors
102 $html .= $this->getTypeMenu( $types ) . "\n";
103 $html .= $this->getUserInput( $user ) . "\n";
104 $html .= $this->getTitleInput( $page ) . "\n";
105 $html .= $this->getExtraInputs( $types ) . "\n";
106
107 // Title pattern, if allowed
108 if ( !$wgMiserMode ) {
109 $html .= $this->getTitlePattern( $pattern ) . "\n";
110 }
111
112 // date menu
113 $html .= Xml::tags( 'p', null, Xml::dateMenu( (int)$year, (int)$month ) );
114
115 // Tag filter
116 if ( $tagSelector ) {
117 $html .= Xml::tags( 'p', null, implode( '&#160;', $tagSelector ) );
118 }
119
120 // Filter links
121 if ( $filter ) {
122 $html .= Xml::tags( 'p', null, $this->getFilterLinks( $filter ) );
123 }
124
125 // Action filter
126 if ( $action !== null ) {
127 $html .= Xml::tags( 'p', null, $this->getActionSelector( $types, $action ) );
128 }
129
130 // Submit button
131 $html .= Xml::submitButton( $this->msg( 'logeventslist-submit' )->text() );
132
133 // Fieldset
134 $html = Xml::fieldset( $this->msg( 'log' )->text(), $html );
135
136 // Form wrapping
137 $html = Xml::tags( 'form', [ 'action' => $wgScript, 'method' => 'get' ], $html );
138
139 $this->getOutput()->addHTML( $html );
140 }
141
142 /**
143 * @param array $filter
144 * @return string Formatted HTML
145 */
146 private function getFilterLinks( $filter ) {
147 // show/hide links
148 $messages = [ $this->msg( 'show' )->text(), $this->msg( 'hide' )->text() ];
149 // Option value -> message mapping
150 $links = [];
151 $hiddens = ''; // keep track for "go" button
152 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
153 foreach ( $filter as $type => $val ) {
154 // Should the below assignment be outside the foreach?
155 // Then it would have to be copied. Not certain what is more expensive.
156 $query = $this->getDefaultQuery();
157 $queryKey = "hide_{$type}_log";
158
159 $hideVal = 1 - intval( $val );
160 $query[$queryKey] = $hideVal;
161
162 $link = $linkRenderer->makeKnownLink(
163 $this->getTitle(),
164 $messages[$hideVal],
165 [],
166 $query
167 );
168
169 // Message: log-show-hide-patrol
170 $links[$type] = $this->msg( "log-show-hide-{$type}" )->rawParams( $link )->escaped();
171 $hiddens .= Html::hidden( "hide_{$type}_log", $val ) . "\n";
172 }
173
174 // Build links
175 return '<small>' . $this->getLanguage()->pipeList( $links ) . '</small>' . $hiddens;
176 }
177
178 private function getDefaultQuery() {
179 if ( !isset( $this->mDefaultQuery ) ) {
180 $this->mDefaultQuery = $this->getRequest()->getQueryValues();
181 unset( $this->mDefaultQuery['title'] );
182 unset( $this->mDefaultQuery['dir'] );
183 unset( $this->mDefaultQuery['offset'] );
184 unset( $this->mDefaultQuery['limit'] );
185 unset( $this->mDefaultQuery['order'] );
186 unset( $this->mDefaultQuery['month'] );
187 unset( $this->mDefaultQuery['year'] );
188 }
189
190 return $this->mDefaultQuery;
191 }
192
193 /**
194 * @param array $queryTypes
195 * @return string Formatted HTML
196 */
197 private function getTypeMenu( $queryTypes ) {
198 $queryType = count( $queryTypes ) == 1 ? $queryTypes[0] : '';
199 $selector = $this->getTypeSelector();
200 $selector->setDefault( $queryType );
201
202 return $selector->getHTML();
203 }
204
205 /**
206 * Returns log page selector.
207 * @return XmlSelect
208 * @since 1.19
209 */
210 public function getTypeSelector() {
211 $typesByName = []; // Temporary array
212 // First pass to load the log names
213 foreach ( LogPage::validTypes() as $type ) {
214 $page = new LogPage( $type );
215 $restriction = $page->getRestriction();
216 if ( $this->getUser()->isAllowed( $restriction ) ) {
217 $typesByName[$type] = $page->getName()->text();
218 }
219 }
220
221 // Second pass to sort by name
222 asort( $typesByName );
223
224 // Always put "All public logs" on top
225 $public = $typesByName[''];
226 unset( $typesByName[''] );
227 $typesByName = [ '' => $public ] + $typesByName;
228
229 $select = new XmlSelect( 'type' );
230 foreach ( $typesByName as $type => $name ) {
231 $select->addOption( $name, $type );
232 }
233
234 return $select;
235 }
236
237 /**
238 * @param string $user
239 * @return string Formatted HTML
240 */
241 private function getUserInput( $user ) {
242 $label = Xml::inputLabel(
243 $this->msg( 'specialloguserlabel' )->text(),
244 'user',
245 'mw-log-user',
246 15,
247 $user,
248 [ 'class' => 'mw-autocomplete-user' ]
249 );
250
251 return '<span class="mw-input-with-label">' . $label . '</span>';
252 }
253
254 /**
255 * @param string $title
256 * @return string Formatted HTML
257 */
258 private function getTitleInput( $title ) {
259 $label = Xml::inputLabel(
260 $this->msg( 'speciallogtitlelabel' )->text(),
261 'page',
262 'mw-log-page',
263 20,
264 $title
265 );
266
267 return '<span class="mw-input-with-label">' . $label . '</span>';
268 }
269
270 /**
271 * @param string $pattern
272 * @return string Checkbox
273 */
274 private function getTitlePattern( $pattern ) {
275 return '<span class="mw-input-with-label">' .
276 Xml::checkLabel( $this->msg( 'log-title-wildcard' )->text(), 'pattern', 'pattern', $pattern ) .
277 '</span>';
278 }
279
280 /**
281 * @param array $types
282 * @return string
283 */
284 private function getExtraInputs( $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 Xml::inputLabel( $this->msg( 'revdelete-offender' )->text(), 'offender',
293 'mw-log-offender', 20, $offender );
294 } else {
295 // Allow extensions to add their own extra inputs
296 $input = '';
297 Hooks::run( 'LogEventsListGetExtraInputs', [ $types[0], $this, &$input ] );
298 return $input;
299 }
300 }
301
302 return '';
303 }
304
305 /**
306 * Drop down menu for selection of actions that can be used to filter the log
307 * @param array $types
308 * @param string $action
309 * @return string
310 * @since 1.27
311 */
312 private function getActionSelector( $types, $action ) {
313 if ( $this->allowedActions === null || !count( $this->allowedActions ) ) {
314 return '';
315 }
316 $html = '';
317 $html .= Xml::label( wfMessage( 'log-action-filter-' . $types[0] )->text(),
318 'action-filter-' .$types[0] ) . "\n";
319 $select = new XmlSelect( 'subtype' );
320 $select->addOption( wfMessage( 'log-action-filter-all' )->text(), '' );
321 foreach ( $this->allowedActions as $value ) {
322 $msgKey = 'log-action-filter-' . $types[0] . '-' . $value;
323 $select->addOption( wfMessage( $msgKey )->text(), $value );
324 }
325 $select->setDefault( $action );
326 $html .= $select->getHTML();
327 return $html;
328 }
329
330 /**
331 * Sets the action types allowed for log filtering
332 * To one action type may correspond several log_actions
333 * @param array $actions
334 * @since 1.27
335 */
336 public function setAllowedActions( $actions ) {
337 $this->allowedActions = $actions;
338 }
339
340 /**
341 * @return string
342 */
343 public function beginLogEventsList() {
344 return "<ul>\n";
345 }
346
347 /**
348 * @return string
349 */
350 public function endLogEventsList() {
351 return "</ul>\n";
352 }
353
354 /**
355 * @param stdClass $row A single row from the result set
356 * @return string Formatted HTML list item
357 */
358 public function logLine( $row ) {
359 $entry = DatabaseLogEntry::newFromRow( $row );
360 $formatter = LogFormatter::newFromEntry( $entry );
361 $formatter->setContext( $this->getContext() );
362 $formatter->setShowUserToolLinks( !( $this->flags & self::NO_EXTRA_USER_LINKS ) );
363
364 $time = htmlspecialchars( $this->getLanguage()->userTimeAndDate(
365 $entry->getTimestamp(), $this->getUser() ) );
366
367 $action = $formatter->getActionText();
368
369 if ( $this->flags & self::NO_ACTION_LINK ) {
370 $revert = '';
371 } else {
372 $revert = $formatter->getActionLinks();
373 if ( $revert != '' ) {
374 $revert = '<span class="mw-logevent-actionlink">' . $revert . '</span>';
375 }
376 }
377
378 $comment = $formatter->getComment();
379
380 // Some user can hide log items and have review links
381 $del = $this->getShowHideLinks( $row );
382
383 // Any tags...
384 list( $tagDisplay, $newClasses ) = ChangeTags::formatSummaryRow(
385 $row->ts_tags,
386 'logevent',
387 $this->getContext()
388 );
389 $classes = array_merge(
390 [ 'mw-logline-' . $entry->getType() ],
391 $newClasses
392 );
393
394 return Html::rawElement( 'li', [ 'class' => $classes ],
395 "$del $time $action $comment $revert $tagDisplay" ) . "\n";
396 }
397
398 /**
399 * @param stdClass $row Row
400 * @return string
401 */
402 private function getShowHideLinks( $row ) {
403 // We don't want to see the links and
404 if ( $this->flags == self::NO_ACTION_LINK ) {
405 return '';
406 }
407
408 $user = $this->getUser();
409
410 // If change tag editing is available to this user, return the checkbox
411 if ( $this->flags & self::USE_CHECKBOXES && $this->showTagEditUI ) {
412 return Xml::check(
413 'showhiderevisions',
414 false,
415 [ 'name' => 'ids[' . $row->log_id . ']' ]
416 );
417 }
418
419 // no one can hide items from the suppress log.
420 if ( $row->log_type == 'suppress' ) {
421 return '';
422 }
423
424 $del = '';
425 // Don't show useless checkbox to people who cannot hide log entries
426 if ( $user->isAllowed( 'deletedhistory' ) ) {
427 $canHide = $user->isAllowed( 'deletelogentry' );
428 $canViewSuppressedOnly = $user->isAllowed( 'viewsuppressed' ) &&
429 !$user->isAllowed( 'suppressrevision' );
430 $entryIsSuppressed = self::isDeleted( $row, LogPage::DELETED_RESTRICTED );
431 $canViewThisSuppressedEntry = $canViewSuppressedOnly && $entryIsSuppressed;
432 if ( $row->log_deleted || $canHide ) {
433 // Show checkboxes instead of links.
434 if ( $canHide && $this->flags & self::USE_CHECKBOXES && !$canViewThisSuppressedEntry ) {
435 // If event was hidden from sysops
436 if ( !self::userCan( $row, LogPage::DELETED_RESTRICTED, $user ) ) {
437 $del = Xml::check( 'deleterevisions', false, [ 'disabled' => 'disabled' ] );
438 } else {
439 $del = Xml::check(
440 'showhiderevisions',
441 false,
442 [ 'name' => 'ids[' . $row->log_id . ']' ]
443 );
444 }
445 } else {
446 // If event was hidden from sysops
447 if ( !self::userCan( $row, LogPage::DELETED_RESTRICTED, $user ) ) {
448 $del = Linker::revDeleteLinkDisabled( $canHide );
449 } else {
450 $query = [
451 'target' => SpecialPage::getTitleFor( 'Log', $row->log_type )->getPrefixedDBkey(),
452 'type' => 'logging',
453 'ids' => $row->log_id,
454 ];
455 $del = Linker::revDeleteLink(
456 $query,
457 $entryIsSuppressed,
458 $canHide && !$canViewThisSuppressedEntry
459 );
460 }
461 }
462 }
463 }
464
465 return $del;
466 }
467
468 /**
469 * @param stdClass $row Row
470 * @param string|array $type
471 * @param string|array $action
472 * @param string $right
473 * @return bool
474 */
475 public static function typeAction( $row, $type, $action, $right = '' ) {
476 $match = is_array( $type ) ?
477 in_array( $row->log_type, $type ) : $row->log_type == $type;
478 if ( $match ) {
479 $match = is_array( $action ) ?
480 in_array( $row->log_action, $action ) : $row->log_action == $action;
481 if ( $match && $right ) {
482 global $wgUser;
483 $match = $wgUser->isAllowed( $right );
484 }
485 }
486
487 return $match;
488 }
489
490 /**
491 * Determine if the current user is allowed to view a particular
492 * field of this log row, if it's marked as deleted.
493 *
494 * @param stdClass $row Row
495 * @param int $field
496 * @param User $user User to check, or null to use $wgUser
497 * @return bool
498 */
499 public static function userCan( $row, $field, User $user = null ) {
500 return self::userCanBitfield( $row->log_deleted, $field, $user );
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 int $bitfield Current field
508 * @param int $field
509 * @param User $user User to check, or null to use $wgUser
510 * @return bool
511 */
512 public static function userCanBitfield( $bitfield, $field, User $user = null ) {
513 if ( $bitfield & $field ) {
514 if ( $user === null ) {
515 global $wgUser;
516 $user = $wgUser;
517 }
518 if ( $bitfield & LogPage::DELETED_RESTRICTED ) {
519 $permissions = [ 'suppressrevision', 'viewsuppressed' ];
520 } else {
521 $permissions = [ 'deletedhistory' ];
522 }
523 $permissionlist = implode( ', ', $permissions );
524 wfDebug( "Checking for $permissionlist due to $field match on $bitfield\n" );
525 return call_user_func_array( [ $user, 'isAllowedAny' ], $permissions );
526 }
527 return true;
528 }
529
530 /**
531 * @param stdClass $row Row
532 * @param int $field One of DELETED_* bitfield constants
533 * @return bool
534 */
535 public static function isDeleted( $row, $field ) {
536 return ( $row->log_deleted & $field ) == $field;
537 }
538
539 /**
540 * Show log extract. Either with text and a box (set $msgKey) or without (don't set $msgKey)
541 *
542 * @param OutputPage|string $out By-reference
543 * @param string|array $types Log types to show
544 * @param string|Title $page The page title to show log entries for
545 * @param string $user The user who made the log entries
546 * @param array $param Associative Array with the following additional options:
547 * - lim Integer Limit of items to show, default is 50
548 * - conds Array Extra conditions for the query
549 * (e.g. 'log_action != ' . $dbr->addQuotes( 'revision' ))
550 * - showIfEmpty boolean Set to false if you don't want any output in case the loglist is empty
551 * if set to true (default), "No matching items in log" is displayed if loglist is empty
552 * - msgKey Array If you want a nice box with a message, set this to the key of the message.
553 * First element is the message key, additional optional elements are parameters for the key
554 * that are processed with wfMessage
555 * - offset Set to overwrite offset parameter in WebRequest
556 * set to '' to unset offset
557 * - wrap String Wrap the message in html (usually something like "<div ...>$1</div>").
558 * - flags Integer display flags (NO_ACTION_LINK,NO_EXTRA_USER_LINKS)
559 * - useRequestParams boolean Set true to use Pager-related parameters in the WebRequest
560 * - useMaster boolean Use master DB
561 * - extraUrlParams array|bool Additional url parameters for "full log" link (if it is shown)
562 * @return int Number of total log items (not limited by $lim)
563 */
564 public static function showLogExtract(
565 &$out, $types = [], $page = '', $user = '', $param = []
566 ) {
567 $defaultParameters = [
568 'lim' => 25,
569 'conds' => [],
570 'showIfEmpty' => true,
571 'msgKey' => [ '' ],
572 'wrap' => "$1",
573 'flags' => 0,
574 'useRequestParams' => false,
575 'useMaster' => false,
576 'extraUrlParams' => false,
577 ];
578 # The + operator appends elements of remaining keys from the right
579 # handed array to the left handed, whereas duplicated keys are NOT overwritten.
580 $param += $defaultParameters;
581 # Convert $param array to individual variables
582 $lim = $param['lim'];
583 $conds = $param['conds'];
584 $showIfEmpty = $param['showIfEmpty'];
585 $msgKey = $param['msgKey'];
586 $wrap = $param['wrap'];
587 $flags = $param['flags'];
588 $extraUrlParams = $param['extraUrlParams'];
589
590 $useRequestParams = $param['useRequestParams'];
591 if ( !is_array( $msgKey ) ) {
592 $msgKey = [ $msgKey ];
593 }
594
595 if ( $out instanceof OutputPage ) {
596 $context = $out->getContext();
597 } else {
598 $context = RequestContext::getMain();
599 }
600
601 # Insert list of top 50 (or top $lim) items
602 $loglist = new LogEventsList( $context, null, $flags );
603 $pager = new LogPager( $loglist, $types, $user, $page, '', $conds );
604 if ( !$useRequestParams ) {
605 # Reset vars that may have been taken from the request
606 $pager->mLimit = 50;
607 $pager->mDefaultLimit = 50;
608 $pager->mOffset = "";
609 $pager->mIsBackwards = false;
610 }
611
612 if ( $param['useMaster'] ) {
613 $pager->mDb = wfGetDB( DB_MASTER );
614 }
615 if ( isset( $param['offset'] ) ) { # Tell pager to ignore WebRequest offset
616 $pager->setOffset( $param['offset'] );
617 }
618
619 if ( $lim > 0 ) {
620 $pager->mLimit = $lim;
621 }
622 // Fetch the log rows and build the HTML if needed
623 $logBody = $pager->getBody();
624 $numRows = $pager->getNumRows();
625
626 $s = '';
627
628 if ( $logBody ) {
629 if ( $msgKey[0] ) {
630 $dir = $context->getLanguage()->getDir();
631 $lang = $context->getLanguage()->getHtmlCode();
632
633 $s = Xml::openElement( 'div', [
634 'class' => "mw-warning-with-logexcerpt mw-content-$dir",
635 'dir' => $dir,
636 'lang' => $lang,
637 ] );
638
639 if ( count( $msgKey ) == 1 ) {
640 $s .= $context->msg( $msgKey[0] )->parseAsBlock();
641 } else { // Process additional arguments
642 $args = $msgKey;
643 array_shift( $args );
644 $s .= $context->msg( $msgKey[0], $args )->parseAsBlock();
645 }
646 }
647 $s .= $loglist->beginLogEventsList() .
648 $logBody .
649 $loglist->endLogEventsList();
650 } elseif ( $showIfEmpty ) {
651 $s = Html::rawElement( 'div', [ 'class' => 'mw-warning-logempty' ],
652 $context->msg( 'logempty' )->parse() );
653 }
654
655 if ( $numRows > $pager->mLimit ) { # Show "Full log" link
656 $urlParam = [];
657 if ( $page instanceof Title ) {
658 $urlParam['page'] = $page->getPrefixedDBkey();
659 } elseif ( $page != '' ) {
660 $urlParam['page'] = $page;
661 }
662
663 if ( $user != '' ) {
664 $urlParam['user'] = $user;
665 }
666
667 if ( !is_array( $types ) ) { # Make it an array, if it isn't
668 $types = [ $types ];
669 }
670
671 # If there is exactly one log type, we can link to Special:Log?type=foo
672 if ( count( $types ) == 1 ) {
673 $urlParam['type'] = $types[0];
674 }
675
676 if ( $extraUrlParams !== false ) {
677 $urlParam = array_merge( $urlParam, $extraUrlParams );
678 }
679
680 $s .= MediaWikiServices::getInstance()->getLinkRenderer()->makeKnownLink(
681 SpecialPage::getTitleFor( 'Log' ),
682 $context->msg( 'log-fulllog' )->text(),
683 [],
684 $urlParam
685 );
686 }
687
688 if ( $logBody && $msgKey[0] ) {
689 $s .= '</div>';
690 }
691
692 if ( $wrap != '' ) { // Wrap message in html
693 $s = str_replace( '$1', $s, $wrap );
694 }
695
696 /* hook can return false, if we don't want the message to be emitted (Wikia BugId:7093) */
697 if ( Hooks::run( 'LogEventsListShowLogExtract', [ &$s, $types, $page, $user, $param ] ) ) {
698 // $out can be either an OutputPage object or a String-by-reference
699 if ( $out instanceof OutputPage ) {
700 $out->addHTML( $s );
701 } else {
702 $out = $s;
703 }
704 }
705
706 return $numRows;
707 }
708
709 /**
710 * SQL clause to skip forbidden log types for this user
711 *
712 * @param IDatabase $db
713 * @param string $audience Public/user
714 * @param User $user User to check, or null to use $wgUser
715 * @return string|bool String on success, false on failure.
716 */
717 public static function getExcludeClause( $db, $audience = 'public', User $user = null ) {
718 global $wgLogRestrictions;
719
720 if ( $audience != 'public' && $user === null ) {
721 global $wgUser;
722 $user = $wgUser;
723 }
724
725 // Reset the array, clears extra "where" clauses when $par is used
726 $hiddenLogs = [];
727
728 // Don't show private logs to unprivileged users
729 foreach ( $wgLogRestrictions as $logType => $right ) {
730 if ( $audience == 'public' || !$user->isAllowed( $right ) ) {
731 $hiddenLogs[] = $logType;
732 }
733 }
734 if ( count( $hiddenLogs ) == 1 ) {
735 return 'log_type != ' . $db->addQuotes( $hiddenLogs[0] );
736 } elseif ( $hiddenLogs ) {
737 return 'log_type NOT IN (' . $db->makeList( $hiddenLogs ) . ')';
738 }
739
740 return false;
741 }
742 }