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