Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 45 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
RenameuserLogFormatter | |
0.00% |
0 / 44 |
|
0.00% |
0 / 5 |
272 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getMessageParameters | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
20 | |||
myPageLink | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
getMessageKey | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
getPreloadTitles | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Logging; |
4 | |
5 | use MediaWiki\Message\Message; |
6 | use MediaWiki\Title\Title; |
7 | use MediaWiki\Title\TitleParser; |
8 | |
9 | /** |
10 | * LogFormatter for renameuser/renameuser logs |
11 | */ |
12 | class RenameuserLogFormatter extends LogFormatter { |
13 | private TitleParser $titleParser; |
14 | |
15 | public function __construct( |
16 | LogEntry $entry, |
17 | TitleParser $titleParser |
18 | ) { |
19 | parent::__construct( $entry ); |
20 | $this->titleParser = $titleParser; |
21 | } |
22 | |
23 | /** |
24 | * @inheritDoc |
25 | */ |
26 | protected function getMessageParameters() { |
27 | $params = parent::getMessageParameters(); |
28 | /* Current format: |
29 | * 1,2,3: normal logformatter params |
30 | * 4: old username (linked) |
31 | * (legaciest doesn't have this at all, all in comment) |
32 | * (legacier uses this as new name and stores old name in target) |
33 | * 5: new username (linked) |
34 | * 6: number of edits the user had at the time |
35 | * (not available except in newest log entries) |
36 | * 7: new username (raw format for GENDER) |
37 | * Note that the arrays are zero-indexed, while message parameters |
38 | * start from 1, so substract one to get array entries below. |
39 | */ |
40 | |
41 | if ( !isset( $params[3] ) ) { |
42 | // The oldest format |
43 | return $params; |
44 | } elseif ( !isset( $params[4] ) ) { |
45 | // See comments above |
46 | $params[4] = $params[3]; |
47 | $params[3] = $this->entry->getTarget()->getText(); |
48 | } |
49 | |
50 | if ( isset( $params[5] ) ) { |
51 | // Make sure number of edits is formatted |
52 | $params[5] = Message::numParam( $params[5] ); |
53 | } |
54 | |
55 | // Nice link to old user page |
56 | $title = Title::makeTitleSafe( NS_USER, $params[3] ); |
57 | // @phan-suppress-next-line SecurityCheck-DoubleEscaped |
58 | $link = $this->myPageLink( $title, $params[3], |
59 | [ 'redirect' => 'no' ] ); |
60 | // @phan-suppress-next-line SecurityCheck-XSS |
61 | $params[3] = Message::rawParam( $link ); |
62 | |
63 | // Nice link to new user page |
64 | $title = Title::makeTitleSafe( NS_USER, $params[4] ); |
65 | // @phan-suppress-next-line SecurityCheck-DoubleEscaped |
66 | $link = $this->myPageLink( $title, $params[4] ); |
67 | // @phan-suppress-next-line SecurityCheck-XSS |
68 | $params[4] = Message::rawParam( $link ); |
69 | // GENDER support (using new user page) |
70 | $params[6] = $title->getText(); |
71 | |
72 | return $params; |
73 | } |
74 | |
75 | /** |
76 | * @param Title|null $title |
77 | * @param string $text |
78 | * @param array $query |
79 | * @return string wikitext or html |
80 | * @return-taint onlysafefor_html |
81 | */ |
82 | protected function myPageLink( ?Title $title, $text, $query = [] ) { |
83 | if ( !$this->plaintext ) { |
84 | if ( !$title instanceof Title ) { |
85 | $link = htmlspecialchars( $text ); |
86 | } else { |
87 | $link = $this->getLinkRenderer()->makeLink( $title, $text, [], $query ); |
88 | } |
89 | } else { |
90 | if ( !$title instanceof Title ) { |
91 | $link = "[[User:$text]]"; |
92 | } else { |
93 | $link = '[[' . $title->getPrefixedText() . ']]'; |
94 | } |
95 | } |
96 | |
97 | return $link; |
98 | } |
99 | |
100 | public function getMessageKey() { |
101 | $key = parent::getMessageKey(); |
102 | $params = $this->extractParameters(); |
103 | |
104 | // Very old log format, everything in comment |
105 | if ( !isset( $params[3] ) ) { |
106 | // Message: logentry-renameuser-renameuser-legaciest |
107 | return "$key-legaciest"; |
108 | } elseif ( !isset( $params[5] ) ) { |
109 | // Message: logentry-renameuser-renameuser-legacier |
110 | return "$key-legacier"; |
111 | } |
112 | |
113 | // Message: logentry-renameuser-renameuser |
114 | return $key; |
115 | } |
116 | |
117 | public function getPreloadTitles() { |
118 | $params = $this->extractParameters(); |
119 | if ( !isset( $params[3] ) ) { |
120 | // Very old log format, everything in comment - legaciest |
121 | return []; |
122 | } |
123 | if ( !isset( $params[4] ) ) { |
124 | // Old log format - legacier |
125 | $newUserName = $params[3]; |
126 | } else { |
127 | $newUserName = $params[4]; |
128 | } |
129 | |
130 | $title = $this->titleParser->makeTitleValueSafe( NS_USER, $newUserName ); |
131 | if ( $title ) { |
132 | return [ $title ]; |
133 | } |
134 | |
135 | return []; |
136 | } |
137 | } |
138 | |
139 | /** @deprecated class alias since 1.44 */ |
140 | class_alias( RenameuserLogFormatter::class, 'RenameuserLogFormatter' ); |