Debian Codegraph @

includes/logging/LogEventsList.php

raw symbols SCIP
1 <?php
2 /**
3 * Contain classes to list log entries
4 *
5 * Copyright © 2004 Brooke Vibber <[email protected]>
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\Context\ContextSource;
27 use MediaWiki\Context\IContextSource;
28 use MediaWiki\Context\RequestContext;
29 use MediaWiki\HookContainer\HookRunner;
30 use MediaWiki\Html\Html;
31 use MediaWiki\HTMLForm\Field\HTMLMultiSelectField;
32 use MediaWiki\HTMLForm\Field\HTMLSelectField;
33 use MediaWiki\HTMLForm\Field\HTMLTitleTextField;
34 use MediaWiki\HTMLForm\Field\HTMLUserTextField;
35 use MediaWiki\HTMLForm\HTMLForm;
36 use MediaWiki\Linker\Linker;
37 use MediaWiki\Linker\LinkRenderer;
38 use MediaWiki\Logger\LoggerFactory;
39 use MediaWiki\MainConfigNames;
40 use MediaWiki\MediaWikiServices;
41 use MediaWiki\Output\OutputPage;
42 use MediaWiki\Page\PageReference;
43 use MediaWiki\Pager\LogPager;
44 use MediaWiki\Parser\Sanitizer;
45 use MediaWiki\Permissions\Authority;
46 use MediaWiki\SpecialPage\SpecialPage;
47 use MediaWiki\Status\Status;
48 use MediaWiki\Xml\Xml;
49
50 class LogEventsList extends ContextSource {
51 public const NO_ACTION_LINK = 1;
52 public const NO_EXTRA_USER_LINKS = 2;
53 public const USE_CHECKBOXES = 4;
54
55 /** @var int */
56 public $flags;
57
58 /**
59 * @var bool
60 */
61 protected $showTagEditUI;
62
63 /**
64 * @var LinkRenderer|null
65 */
66 private $linkRenderer;
67
68 /** @var HookRunner */
69 private $hookRunner;
70
71 private LogFormatterFactory $logFormatterFactory;
72
73 /** @var MapCacheLRU */
74 private $tagsCache;
75
76 /**
77 * @param IContextSource $context
78 * @param LinkRenderer|null $linkRenderer
79 * @param int $flags Can be a combination of self::NO_ACTION_LINK,
80 * self::NO_EXTRA_USER_LINKS or self::USE_CHECKBOXES.
81 */
82 public function __construct( $context, $linkRenderer = null, $flags = 0 ) {
83 $this->setContext( $context );
84 $this->flags = $flags;
85 $this->showTagEditUI = ChangeTags::showTagEditingUI( $this->getAuthority() );
86 if ( $linkRenderer instanceof LinkRenderer ) {
87 $this->linkRenderer = $linkRenderer;
88 }
89 $services = MediaWikiServices::getInstance();
90 $this->hookRunner = new HookRunner( $services->getHookContainer() );
91 $this->logFormatterFactory = $services->getLogFormatterFactory();
92 $this->tagsCache = new MapCacheLRU( 50 );
93 }
94
95 /**
96 * @since 1.30
97 * @return LinkRenderer
98 */
99 protected function getLinkRenderer() {
100 if ( $this->linkRenderer !== null ) {
101 return $this->linkRenderer;
102 } else {
103 return MediaWikiServices::getInstance()->getLinkRenderer();
104 }
105 }
106
107 /**
108 * Show options for the log list
109 *
110 * @param string $type Log type
111 * @param int|string $year Use 0 to start with no year preselected.
112 * @param int|string $month A month in the 1..12 range. Use 0 to start with no month
113 * preselected.
114 * @param int|string $day A day in the 1..31 range. Use 0 to start with no month
115 * preselected.
116 * @return bool Whether the options are valid
117 */
118 public function showOptions( $type = '', $year = 0, $month = 0, $day = 0 ) {
119 $formDescriptor = [];
120
121 // Basic selectors
122 $formDescriptor['type'] = $this->getTypeMenuDesc();
123 $formDescriptor['user'] = [
124 'class' => HTMLUserTextField::class,
125 'label-message' => 'specialloguserlabel',
126 'name' => 'user',
127 'ipallowed' => true,
128 'iprange' => true,
129 'external' => true,
130 ];
131 $formDescriptor['page'] = [
132 'class' => HTMLTitleTextField::class,
133 'label-message' => 'speciallogtitlelabel',
134 'name' => 'page',
135 'required' => false,
136 ];
137
138 // Title pattern, if allowed
139 if ( !$this->getConfig()->get( MainConfigNames::MiserMode ) ) {
140 $formDescriptor['pattern'] = [
141 'type' => 'check',
142 'label-message' => 'log-title-wildcard',
143 'name' => 'pattern',
144 ];
145 }
146
147 // Add extra inputs if any
148 $extraInputsDescriptor = $this->getExtraInputsDesc( $type );
149 if ( $extraInputsDescriptor ) {
150 $formDescriptor[ 'extra' ] = $extraInputsDescriptor;
151 }
152
153 // Date menu
154 $formDescriptor['date'] = [
155 'type' => 'date',
156 'label-message' => 'date',
157 'default' => $year && $month && $day ? sprintf( "%04d-%02d-%02d", $year, $month, $day ) : '',
158 ];
159
160 // Tag filter
161 $formDescriptor['tagfilter'] = [
162 'type' => 'tagfilter',
163 'name' => 'tagfilter',
164 'label-message' => 'tag-filter',
165 ];
166 $formDescriptor['tagInvert'] = [
167 'type' => 'check',
168 'name' => 'tagInvert',
169 'label-message' => 'invert',
170 'hide-if' => [ '===', 'tagfilter', '' ],
171 ];
172
173 // Filter checkboxes, when work on all logs
174 if ( $type === '' ) {
175 $formDescriptor['filters'] = $this->getFiltersDesc();
176 }
177
178 // Action filter
179 $allowedActions = $this->getConfig()->get( MainConfigNames::ActionFilteredLogs );
180 if ( isset( $allowedActions[$type] ) ) {
181 $formDescriptor['subtype'] = $this->getActionSelectorDesc( $type, $allowedActions[$type] );
182 }
183
184 $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() );
185 $htmlForm
186 ->setTitle( SpecialPage::getTitleFor( 'Log' ) ) // Remove subpage
187 ->setSubmitTextMsg( 'logeventslist-submit' )
188 ->setMethod( 'GET' )
189 ->setWrapperLegendMsg( 'log' )
190 ->setFormIdentifier( 'logeventslist', true ) // T321154
191 // Set callback for data validation and log type description.
192 ->setSubmitCallback( static function ( $formData, $form ) {
193 $form->addPreHtml(
194 ( new LogPage( $formData['type'] ) )->getDescription()
195 ->setContext( $form->getContext() )->parseAsBlock()
196 );
197 return true;
198 } );
199
200 $result = $htmlForm->prepareForm()->trySubmit();
201 $htmlForm->displayForm( $result );
202 return $result === true || ( $result instanceof Status && $result->isGood() );
203 }
204
205 /**
206 * @return array Form descriptor
207 */
208 private function getFiltersDesc() {
209 $optionsMsg = [];
210 $filters = $this->getConfig()->get( MainConfigNames::FilterLogTypes );
211 foreach ( $filters as $type => $val ) {
212 $optionsMsg["logeventslist-{$type}-log"] = $type;
213 }
214 return [
215 'class' => HTMLMultiSelectField::class,
216 'label-message' => 'logeventslist-more-filters',
217 'flatlist' => true,
218 'options-messages' => $optionsMsg,
219 'default' => array_keys( array_intersect( $filters, [ false ] ) ),
220 ];
221 }
222
223 /**
224 * @return array Form descriptor
225 */
226 private function getTypeMenuDesc() {
227 $typesByName = [];
228 // Load the log names
229 foreach ( LogPage::validTypes() as $type ) {
230 $page = new LogPage( $type );
231 $pageText = $page->getName()->text();
232 if ( in_array( $pageText, $typesByName ) ) {
233 LoggerFactory::getInstance( 'error' )->error(
234 'The log type {log_type_one} has the same translation as {log_type_two} for {lang}. ' .
235 '{log_type_one} will not be displayed in the drop down menu on Special:Log.',
236 [
237 'log_type_one' => $type,
238 'log_type_two' => array_search( $pageText, $typesByName ),
239 'lang' => $this->getLanguage()->getCode(),
240 ]
241 );
242 continue;
243 }
244 if ( $this->getAuthority()->isAllowed( $page->getRestriction() ) ) {
245 $typesByName[$type] = $pageText;
246 }
247 }
248
249 asort( $typesByName );
250
251 // Always put "All public logs" on top
252 $public = $typesByName[''];
253 unset( $typesByName[''] );
254 $typesByName = [ '' => $public ] + $typesByName;
255
256 return [
257 'class' => HTMLSelectField::class,
258 'name' => 'type',
259 'options' => array_flip( $typesByName ),
260 'default' => '',
261 ];
262 }
263
264 /**
265 * @param string $type
266 * @return array Form descriptor
267 */
268 private function getExtraInputsDesc( $type ) {
269 if ( $type === 'suppress' ) {
270 return [
271 'type' => 'text',
272 'label-message' => 'revdelete-offender',
273 'name' => 'offender',
274 ];
275 } else {
276 // Allow extensions to add an extra input into the descriptor array.
277 $unused = ''; // Deprecated since 1.32, removed in 1.41
278 $formDescriptor = [];
279 $this->hookRunner->onLogEventsListGetExtraInputs( $type, $this, $unused, $formDescriptor );
280
281 return $formDescriptor;
282 }
283 }
284
285 /**
286 * Drop down menu for selection of actions that can be used to filter the log
287 * @param string $type
288 * @param array $actions
289 * @return array Form descriptor
290 */
291 private function getActionSelectorDesc( $type, $actions ) {
292 $actionOptions = [ 'log-action-filter-all' => '' ];
293
294 foreach ( $actions as $value => $_ ) {
295 $msgKey = "log-action-filter-$type-$value";
296 $actionOptions[ $msgKey ] = $value;
297 }
298
299 return [
300 'class' => HTMLSelectField::class,
301 'name' => 'subtype',
302 'options-messages' => $actionOptions,
303 'label-message' => 'log-action-filter-' . $type,
304 ];
305 }
306
307 /**
308 * @return string
309 */
310 public function beginLogEventsList() {
311 return "<ul class='mw-logevent-loglines'>\n";
312 }
313
314 /**
315 * @return string
316 */
317 public function endLogEventsList() {
318 return "</ul>\n";
319 }
320
321 /**
322 * @param stdClass $row A single row from the result set
323 * @return string Formatted HTML list item
324 */
325 public function logLine( $row ) {
326 $entry = DatabaseLogEntry::newFromRow( $row );
327 $formatter = $this->logFormatterFactory->newFromEntry( $entry );
328 $formatter->setContext( $this->getContext() );
329 $formatter->setShowUserToolLinks( !( $this->flags & self::NO_EXTRA_USER_LINKS ) );
330
331 $time = $this->getLanguage()->userTimeAndDate(
332 $entry->getTimestamp(),
333 $this->getUser()
334 );
335 // Link the time text to the specific log entry, see T207562
336 $timeLink = $this->getLinkRenderer()->makeKnownLink(
337 SpecialPage::getTitleValueFor( 'Log' ),
338 $time,
339 [],
340 [ 'logid' => $entry->getId() ]
341 );
342
343 $action = $formatter->getActionText();
344
345 if ( $this->flags & self::NO_ACTION_LINK ) {
346 $revert = '';
347 } else {
348 $revert = $formatter->getActionLinks();
349 if ( $revert != '' ) {
350 $revert = '<span class="mw-logevent-actionlink">' . $revert . '</span>';
351 }
352 }
353
354 $comment = $formatter->getComment();
355
356 // Some user can hide log items and have review links
357 $del = $this->getShowHideLinks( $row );
358
359 // Any tags...
360 [ $tagDisplay, $newClasses ] = $this->tagsCache->getWithSetCallback(
361 $this->tagsCache->makeKey(
362 $row->ts_tags ?? '',
363 $this->getUser()->getName(),
364 $this->getLanguage()->getCode()
365 ),
366 fn () => ChangeTags::formatSummaryRow(
367 $row->ts_tags,
368 'logevent',
369 $this->getContext()
370 )
371 );
372 $classes = array_merge(
373 [ 'mw-logline-' . $entry->getType() ],
374 $newClasses
375 );
376 $attribs = [
377 'data-mw-logid' => $entry->getId(),
378 'data-mw-logaction' => $entry->getFullType(),
379 ];
380 $ret = "$del $timeLink $action $comment $revert $tagDisplay";
381
382 // Let extensions add data
383 $this->hookRunner->onLogEventsListLineEnding( $this, $ret, $entry, $classes, $attribs );
384 $attribs = array_filter( $attribs,
385 [ Sanitizer::class, 'isReservedDataAttribute' ],
386 ARRAY_FILTER_USE_KEY
387 );
388 $attribs['class'] = $classes;
389
390 return Html::rawElement( 'li', $attribs, $ret ) . "\n";
391 }
392
393 /**
394 * @param stdClass $row
395 * @return string
396 */
397 private function getShowHideLinks( $row ) {
398 // We don't want to see the links and
399 if ( $this->flags == self::NO_ACTION_LINK ) {
400 return '';
401 }
402
403 // If change tag editing is available to this user, return the checkbox
404 if ( $this->flags & self::USE_CHECKBOXES && $this->showTagEditUI ) {
405 return Xml::check(
406 'showhiderevisions',
407 false,
408 [ 'name' => 'ids[' . $row->log_id . ']' ]
409 );
410 }
411
412 // no one can hide items from the suppress log.
413 if ( $row->log_type == 'suppress' ) {
414 return '';
415 }
416
417 $del = '';
418 $authority = $this->getAuthority();
419 // Don't show useless checkbox to people who cannot hide log entries
420 if ( $authority->isAllowed( 'deletedhistory' ) ) {
421 $canHide = $authority->isAllowed( 'deletelogentry' );
422 $canViewSuppressedOnly = $authority->isAllowed( 'viewsuppressed' ) &&
423 !$authority->isAllowed( 'suppressrevision' );
424 $entryIsSuppressed = self::isDeleted( $row, LogPage::DELETED_RESTRICTED );
425 $canViewThisSuppressedEntry = $canViewSuppressedOnly && $entryIsSuppressed;
426 if ( $row->log_deleted || $canHide ) {
427 // Show checkboxes instead of links.
428 if ( $canHide && $this->flags & self::USE_CHECKBOXES && !$canViewThisSuppressedEntry ) {
429 // If event was hidden from sysops
430 if ( !self::userCan( $row, LogPage::DELETED_RESTRICTED, $authority ) ) {
431 $del = Xml::check( 'deleterevisions', false, [ 'disabled' => 'disabled' ] );
432 } else {
433 $del = Xml::check(
434 'showhiderevisions',
435 false,
436 [ 'name' => 'ids[' . $row->log_id . ']' ]
437 );
438 }
439 } else {
440 // If event was hidden from sysops
441 if ( !self::userCan( $row, LogPage::DELETED_RESTRICTED, $authority ) ) {
442 $del = Linker::revDeleteLinkDisabled( $canHide );
443 } else {
444 $query = [
445 'target' => SpecialPage::getTitleFor( 'Log', $row->log_type )->getPrefixedDBkey(),
446 'type' => 'logging',
447 'ids' => $row->log_id,
448 ];
449 $del = Linker::revDeleteLink(
450 $query,
451 $entryIsSuppressed,
452 $canHide && !$canViewThisSuppressedEntry
453 );
454 }
455 }
456 }
457 }
458
459 return $del;
460 }
461
462 /**
463 * @param stdClass $row
464 * @param string|array $type
465 * @param string|array $action
466 * @return bool
467 */
468 public static function typeAction( $row, $type, $action ) {
469 $match = is_array( $type ) ?
470 in_array( $row->log_type, $type ) : $row->log_type == $type;
471 if ( $match ) {
472 $match = is_array( $action ) ?
473 in_array( $row->log_action, $action ) : $row->log_action == $action;
474 }
475
476 return $match;
477 }
478
479 /**
480 * Determine if the current user is allowed to view a particular
481 * field of this log row, if it's marked as deleted and/or restricted log type.
482 *
483 * @param stdClass $row
484 * @param int $field One of LogPage::DELETED_ACTION, ::DELETED_COMMENT, ::DELETED_USER, ::DELETED_RESTRICTED
485 * @param Authority $performer User to check
486 * @return bool
487 */
488 public static function userCan( $row, $field, Authority $performer ) {
489 return self::userCanBitfield( $row->log_deleted, $field, $performer ) &&
490 self::userCanViewLogType( $row->log_type, $performer );
491 }
492
493 /**
494 * Determine if the current user is allowed to view a particular
495 * field of this log row, if it's marked as deleted.
496 *
497 * @param int $bitfield Current field
498 * @param int $field One of LogPage::DELETED_ACTION, ::DELETED_COMMENT, ::DELETED_USER, ::DELETED_RESTRICTED
499 * @param Authority $performer User to check
500 * @return bool
501 */
502 public static function userCanBitfield( $bitfield, $field, Authority $performer ) {
503 if ( $bitfield & $field ) {
504 if ( $bitfield & LogPage::DELETED_RESTRICTED ) {
505 return $performer->isAllowedAny( 'suppressrevision', 'viewsuppressed' );
506 } else {
507 return $performer->isAllowed( 'deletedhistory' );
508 }
509 }
510 return true;
511 }
512
513 /**
514 * Determine if the current user is allowed to view a particular
515 * field of this log row, if it's marked as restricted log type.
516 *
517 * @param string $type
518 * @param Authority $performer User to check
519 * @return bool
520 */
521 public static function userCanViewLogType( $type, Authority $performer ) {
522 $logRestrictions = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogRestrictions );
523 if ( isset( $logRestrictions[$type] ) && !$performer->isAllowed( $logRestrictions[$type] ) ) {
524 return false;
525 }
526 return true;
527 }
528
529 /**
530 * @param stdClass $row
531 * @param int $field One of LogPage::DELETED_ACTION, ::DELETED_COMMENT, ::DELETED_USER, ::DELETED_RESTRICTED
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
542 * @param string|array $types Log types to show
543 * @param string|PageReference $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. $dbr->expr( 'log_action', '!=', '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 primary 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 // @phan-suppress-next-line PhanRedundantCondition
591 if ( !is_array( $msgKey ) ) {
592 $msgKey = [ $msgKey ];
593 }
594
595 // ???
596 // @phan-suppress-next-line PhanRedundantCondition
597 if ( $out instanceof OutputPage ) {
598 $context = $out->getContext();
599 } else {
600 $context = RequestContext::getMain();
601 }
602
603 $services = MediaWikiServices::getInstance();
604 // FIXME: Figure out how to inject this
605 $linkRenderer = $services->getLinkRenderer();
606
607 # Insert list of top 50 (or top $lim) items
608 $loglist = new LogEventsList( $context, $linkRenderer, $flags );
609 $pager = new LogPager(
610 $loglist,
611 $types,
612 $user,
613 $page,
614 false,
615 $conds,
616 false,
617 false,
618 false,
619 '',
620 '',
621 0,
622 $services->getLinkBatchFactory(),
623 $services->getActorNormalization(),
624 $services->getLogFormatterFactory()
625 );
626 // @phan-suppress-next-line PhanImpossibleCondition
627 if ( !$useRequestParams ) {
628 # Reset vars that may have been taken from the request
629 $pager->mLimit = 50;
630 $pager->mDefaultLimit = 50;
631 $pager->mOffset = "";
632 $pager->mIsBackwards = false;
633 }
634
635 // @phan-suppress-next-line PhanImpossibleCondition
636 if ( $param['useMaster'] ) {
637 $pager->mDb = $services->getConnectionProvider()->getPrimaryDatabase();
638 }
639 // @phan-suppress-next-line PhanImpossibleCondition
640 if ( isset( $param['offset'] ) ) { # Tell pager to ignore WebRequest offset
641 $pager->setOffset( $param['offset'] );
642 }
643
644 // @phan-suppress-next-line PhanSuspiciousValueComparison
645 if ( $lim > 0 ) {
646 $pager->mLimit = $lim;
647 }
648 // Fetch the log rows and build the HTML if needed
649 $logBody = $pager->getBody();
650 $numRows = $pager->getNumRows();
651
652 $s = '';
653
654 if ( $logBody ) {
655 if ( $msgKey[0] ) {
656 // @phan-suppress-next-line PhanParamTooFewUnpack Non-emptiness checked above
657 $msg = $context->msg( ...$msgKey );
658 if ( $page instanceof PageReference ) {
659 $msg->page( $page );
660 }
661 $s .= $msg->parseAsBlock();
662 }
663 $s .= $loglist->beginLogEventsList() .
664 $logBody .
665 $loglist->endLogEventsList();
666 // add styles for change tags
667 $context->getOutput()->addModuleStyles( 'mediawiki.interface.helpers.styles' );
668 // @phan-suppress-next-line PhanRedundantCondition
669 } elseif ( $showIfEmpty ) {
670 $s = Html::rawElement( 'div', [ 'class' => 'mw-warning-logempty' ],
671 $context->msg( 'logempty' )->parse() );
672 }
673
674 if ( $page instanceof PageReference ) {
675 $titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter();
676 $pageName = $titleFormatter->getPrefixedDBkey( $page );
677 } elseif ( $page != '' ) {
678 $pageName = $page;
679 } else {
680 $pageName = null;
681 }
682
683 if ( $numRows > $pager->mLimit ) { # Show "Full log" link
684 $urlParam = [];
685 if ( $pageName ) {
686 $urlParam['page'] = $pageName;
687 }
688
689 if ( $user != '' ) {
690 $urlParam['user'] = $user;
691 }
692
693 if ( !is_array( $types ) ) { # Make it an array, if it isn't
694 $types = [ $types ];
695 }
696
697 # If there is exactly one log type, we can link to Special:Log?type=foo
698 if ( count( $types ) == 1 ) {
699 $urlParam['type'] = $types[0];
700 }
701
702 // @phan-suppress-next-line PhanSuspiciousValueComparison
703 if ( $extraUrlParams !== false ) {
704 $urlParam = array_merge( $urlParam, $extraUrlParams );
705 }
706
707 $s .= $linkRenderer->makeKnownLink(
708 SpecialPage::getTitleFor( 'Log' ),
709 $context->msg( 'log-fulllog' )->text(),
710 [],
711 $urlParam
712 );
713 }
714
715 if ( $logBody && $msgKey[0] ) {
716 // TODO: The condition above is weird. Should this be done in any other cases?
717 // Or is it always true in practice?
718
719 // Mark as interface language (T60685)
720 $dir = $context->getLanguage()->getDir();
721 $lang = $context->getLanguage()->getHtmlCode();
722 $s = Html::rawElement( 'div', [
723 'class' => "mw-content-$dir",
724 'dir' => $dir,
725 'lang' => $lang,
726 ], $s );
727
728 // Wrap in warning box
729 $s = Html::warningBox(
730 $s,
731 'mw-warning-with-logexcerpt'
732 );
733 }
734
735 // @phan-suppress-next-line PhanSuspiciousValueComparison, PhanRedundantCondition
736 if ( $wrap != '' ) { // Wrap message in html
737 $s = str_replace( '$1', $s, $wrap );
738 }
739
740 /* hook can return false, if we don't want the message to be emitted (Wikia BugId:7093) */
741 $hookRunner = new HookRunner( $services->getHookContainer() );
742 if ( $hookRunner->onLogEventsListShowLogExtract( $s, $types, $pageName, $user, $param ) ) {
743 // $out can be either an OutputPage object or a String-by-reference
744 if ( $out instanceof OutputPage ) {
745 $out->addHTML( $s );
746 } else {
747 $out = $s;
748 }
749 }
750
751 return $numRows;
752 }
753
754 /**
755 * SQL clause to skip forbidden log types for this user
756 *
757 * @param \Wikimedia\Rdbms\IReadableDatabase $db
758 * @param string $audience Public/user
759 * @param Authority|null $performer User to check, required when audience isn't public
760 * @return string|false String on success, false on failure.
761 * @throws InvalidArgumentException
762 */
763 public static function getExcludeClause( $db, $audience = 'public', ?Authority $performer = null ) {
764 $logRestrictions = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LogRestrictions );
765
766 if ( $audience != 'public' && $performer === null ) {
767 throw new InvalidArgumentException(
768 'A User object must be given when checking for a user audience.'
769 );
770 }
771
772 // Reset the array, clears extra "where" clauses when $par is used
773 $hiddenLogs = [];
774
775 // Don't show private logs to unprivileged users
776 foreach ( $logRestrictions as $logType => $right ) {
777 if ( $audience == 'public' || !$performer->isAllowed( $right ) ) {
778 $hiddenLogs[] = $logType;
779 }
780 }
781 if ( count( $hiddenLogs ) == 1 ) {
782 return 'log_type != ' . $db->addQuotes( $hiddenLogs[0] );
783 } elseif ( $hiddenLogs ) {
784 return 'log_type NOT IN (' . $db->makeList( $hiddenLogs ) . ')';
785 }
786
787 return false;
788 }
789 }