MediaWiki master
UnsafeLogFormatter.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Logging;
4
6
8
9 public function __construct( LogEntry $entry ) {
10 parent::__construct( $entry );
11
12 $params = [ $entry->getParameters() ];
13 array_walk_recursive( $params, static function ( $val ) {
14 if ( $val instanceof \__PHP_Incomplete_Class ) {
15 // Despite being documented, the '__PHP_Incomplete_Class_Name' property can't be accessed,
16 // because '__PHP_Incomplete_Class' disallows accessing any of its properties.
17 // This works though…
18 $className = ( (array)$val )['__PHP_Incomplete_Class_Name'];
19 $logger = LoggerFactory::getInstance( 'unsafe-logentry' );
20 if ( class_exists( $className ) ) {
21 $logger->error( "Log entry params contain forbidden class '$className'" );
22 } else {
23 // This may be reached after uninstalling an extension that previously allowed a class
24 $logger->warning( "Log entry params contain non-existent class '$className'" );
25 }
26 }
27 } );
28 }
29
31 protected function getActionMessage() {
32 return $this->getPerformerElement() .
33 $this->msg( 'word-separator' )->escaped() .
34 $this->msg( 'log-unknown-action',
35 $this->entry->getTarget()->getPrefixedText(),
36 $this->entry->getFullType()
37 )->parse() .
38 $this->msg( 'word-separator' )->escaped() .
39 $this->msg( 'log-unsafe-logentry' )->escaped();
40 }
41
42 // Override functions which may access parameters to avoid exceptions and warnings elsewhere
43
45 protected function getMessageKey() {
46 return "log-unsafe-logentry";
47 }
48
50 protected function getMessageParameters() {
51 return [];
52 }
53
55 protected function getParametersForApi() {
56 return [];
57 }
58
60 public function getIRCActionText() {
61 return '';
62 }
63
65 protected function extractParameters() {
66 return [];
67 }
68
69}
Create PSR-3 logger objects.
Implements the default log formatting.
getPerformerElement()
Provides the name of the user who performed the log action.
msg( $key,... $params)
Shortcut for wfMessage which honors local context.
getIRCActionText()
Even uglier hack to maintain backwards compatibility with IRC bots (T36508).getActionText() string Te...
getMessageParameters()
Formats parameters intended for action message from array of all parameters.There are three hardcoded...
getMessageKey()
Returns a key to be used for formatting the action sentence.Default is logentry-TYPE-SUBTYPE for mode...
getActionMessage()
Returns a sentence describing the log action.Usually a Message object is returned,...
getParametersForApi()
Get the array of parameters, converted from legacy format if necessary.1.25 to override array
extractParameters()
Extracts the optional extra parameters for use in action messages.The array indexes start from number...
An individual log entry.
Definition LogEntry.php:24
getParameters()
Get the extra parameters stored for this message.