Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
78.26% |
18 / 23 |
|
28.57% |
2 / 7 |
CRAP | |
0.00% |
0 / 1 |
| UnsafeLogFormatter | |
78.26% |
18 / 23 |
|
28.57% |
2 / 7 |
9.83 | |
0.00% |
0 / 1 |
| __construct | |
90.00% |
9 / 10 |
|
0.00% |
0 / 1 |
3.01 | |||
| getActionMessage | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
| getMessageKey | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getMessageParameters | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getParametersForApi | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getIRCActionText | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| extractParameters | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Logging; |
| 4 | |
| 5 | use MediaWiki\Logger\LoggerFactory; |
| 6 | |
| 7 | class UnsafeLogFormatter extends LogFormatter { |
| 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 | |
| 30 | /** @inheritDoc */ |
| 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 | |
| 44 | /** @inheritDoc */ |
| 45 | protected function getMessageKey() { |
| 46 | return "log-unsafe-logentry"; |
| 47 | } |
| 48 | |
| 49 | /** @inheritDoc */ |
| 50 | protected function getMessageParameters() { |
| 51 | return []; |
| 52 | } |
| 53 | |
| 54 | /** @inheritDoc */ |
| 55 | protected function getParametersForApi() { |
| 56 | return []; |
| 57 | } |
| 58 | |
| 59 | /** @inheritDoc */ |
| 60 | public function getIRCActionText() { |
| 61 | return ''; |
| 62 | } |
| 63 | |
| 64 | /** @inheritDoc */ |
| 65 | protected function extractParameters() { |
| 66 | return []; |
| 67 | } |
| 68 | |
| 69 | } |