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