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