Debian Codegraph @

includes/logging/UnsafeLogFormatter.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Logging;
4
5 use LogEntry;
6 use LogFormatter;
7 use MediaWiki\Logger\LoggerFactory;
8
9 class UnsafeLogFormatter extends LogFormatter {
10
11 public function __construct( LogEntry $entry ) {
12 parent::__construct( $entry );
13
14 $params = [ $entry->getParameters() ];
15 array_walk_recursive( $params, static function ( $val ) {
16 if ( $val instanceof \__PHP_Incomplete_Class ) {
17 // Despite being documented, the '__PHP_Incomplete_Class_Name' property can't be accessed,
18 // because '__PHP_Incomplete_Class' disallows accessing any of its properties.
19 // This works though…
20 $className = ( (array)$val )['__PHP_Incomplete_Class_Name'];
21 $logger = LoggerFactory::getInstance( 'unsafe-logentry' );
22 if ( class_exists( $className ) ) {
23 $logger->error( "Log entry params contain forbidden class '$className'" );
24 } else {
25 // This may be reached after uninstalling an extension that previously allowed a class
26 $logger->warning( "Log entry params contain non-existent class '$className'" );
27 }
28 }
29 } );
30 }
31
32 /** @inheritDoc */
33 protected function getActionMessage() {
34 return $this->getPerformerElement() .
35 $this->msg( 'word-separator' )->escaped() .
36 $this->msg( 'log-unknown-action',
37 $this->entry->getTarget()->getPrefixedText(),
38 $this->entry->getFullType()
39 )->parse() .
40 $this->msg( 'word-separator' )->escaped() .
41 $this->msg( 'log-unsafe-logentry' )->escaped();
42 }
43
44 // Override functions which may access parameters to avoid exceptions and warnings elsewhere
45
46 /** @inheritDoc */
47 protected function getMessageKey() {
48 return "log-unsafe-logentry";
49 }
50
51 /** @inheritDoc */
52 protected function getMessageParameters() {
53 return [];
54 }
55
56 /** @inheritDoc */
57 protected function getParametersForApi() {
58 return [];
59 }
60
61 /** @inheritDoc */
62 public function getIRCActionText() {
63 return '';
64 }
65
66 /** @inheritDoc */
67 protected function extractParameters() {
68 return [];
69 }
70
71 }