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