Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 48 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
WikiSetLogFormatter | |
0.00% |
0 / 48 |
|
0.00% |
0 / 4 |
272 | |
0.00% |
0 / 1 |
formatWikiSetLink | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
formatType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
formatWikis | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
extractParameters | |
0.00% |
0 / 41 |
|
0.00% |
0 / 1 |
132 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\CentralAuth\LogFormatter; |
4 | |
5 | use LogFormatter; |
6 | use MediaWiki\Message\Message; |
7 | use UnexpectedValueException; |
8 | |
9 | /** |
10 | * Handles the following log types: |
11 | * - gblrights/deleteset |
12 | * - gblrights/newset |
13 | * - gblrights/setchange |
14 | * - gblrights/setnewtype |
15 | * - gblrights/setrename |
16 | * |
17 | * phan-taint-check gets very confused by $this->plaintext changing expected taint types everywhere, |
18 | * so manual annotations are needed. They should be correct for the non-plaintext mode (HTML output). |
19 | */ |
20 | class WikiSetLogFormatter extends LogFormatter { |
21 | |
22 | /** |
23 | * @param string $name |
24 | * @param-taint $name none |
25 | * @return string wikitext or html |
26 | * @return-taint onlysafefor_html |
27 | */ |
28 | private function formatWikiSetLink( $name ) { |
29 | if ( !$this->plaintext ) { |
30 | return $this->makePageLink( $this->entry->getTarget(), [], htmlspecialchars( $name ) ); |
31 | } |
32 | return $name; |
33 | } |
34 | |
35 | /** |
36 | * @param string $type |
37 | * |
38 | * @return string |
39 | */ |
40 | private function formatType( $type ): string { |
41 | // Give grep a chance to find the usages: |
42 | // centralauth-rightslog-set-optin, centralauth-rightslog-set-optout |
43 | return $this->msg( "centralauth-rightslog-set-$type" )->text(); |
44 | } |
45 | |
46 | /** |
47 | * @param string[] $wikis |
48 | * @param-taint $wikis none |
49 | * @return string Plain text |
50 | * @return-taint tainted |
51 | */ |
52 | private function formatWikis( array $wikis ): string { |
53 | if ( $wikis !== [] ) { |
54 | return $this->formatParameterValue( 'list', $wikis ); |
55 | } |
56 | return $this->msg( 'rightsnone' )->text(); |
57 | } |
58 | |
59 | protected function extractParameters() { |
60 | $params = parent::extractParameters(); |
61 | $action = $this->entry->getSubtype(); |
62 | |
63 | // Give grep a chance to find the usages: |
64 | // logentry-gblrights-deleteset, logentry-gblrights-newset |
65 | // logentry-gblrights-setchange, logentry-gblrights-setnewtype |
66 | // logentry-gblrights-setrename |
67 | switch ( $action ) { |
68 | case 'deleteset': |
69 | return [ |
70 | // 4::name |
71 | 3 => Message::rawParam( $this->formatWikiSetLink( $params[3] ) ), |
72 | ]; |
73 | case 'newset': |
74 | $wikis = $this->entry->isLegacy() |
75 | // shouldn't be empty |
76 | ? explode( ', ', $params[5] ) |
77 | : $this->entry->getParameters()['wikis']; |
78 | return [ |
79 | // 4::name |
80 | 3 => Message::rawParam( $this->formatWikiSetLink( $params[3] ) ), |
81 | // 5::type |
82 | 4 => $this->formatType( $params[4] ), |
83 | 5 => $this->formatWikis( $wikis ), |
84 | 6 => Message::numParam( count( $wikis ) ), |
85 | ]; |
86 | case 'setchange': |
87 | if ( $this->entry->isLegacy() ) { |
88 | $added = $params[4] !== '' ? explode( ', ', $params[4] ) : []; |
89 | $removed = $params[5] !== '' ? explode( ', ', $params[5] ) : []; |
90 | } else { |
91 | [ 'added' => $added, 'removed' => $removed ] = $this->entry->getParameters(); |
92 | } |
93 | return [ |
94 | // 4::name |
95 | 3 => Message::rawParam( $this->formatWikiSetLink( $params[3] ) ), |
96 | 4 => $this->formatWikis( $added ), |
97 | 5 => $this->formatWikis( $removed ), |
98 | 6 => Message::numParam( count( $added ) ), |
99 | 7 => Message::numParam( count( $removed ) ), |
100 | ]; |
101 | case 'setnewtype': |
102 | return [ |
103 | // 4::name |
104 | 3 => Message::rawParam( $this->formatWikiSetLink( $params[3] ) ), |
105 | // 5::oldType |
106 | 4 => $this->formatType( $params[4] ), |
107 | // 6::type |
108 | 5 => $this->formatType( $params[5] ), |
109 | ]; |
110 | case 'setrename': |
111 | return [ |
112 | // 4::name |
113 | 3 => Message::rawParam( $this->formatWikiSetLink( $params[3] ) ), |
114 | // 5::oldName |
115 | 4 => $params[4], |
116 | ]; |
117 | default: |
118 | throw new UnexpectedValueException( "Invalid log action: gblrights/$action" ); |
119 | } |
120 | } |
121 | |
122 | } |