Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 48 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
BallotStatus | |
0.00% |
0 / 48 |
|
0.00% |
0 / 4 |
240 | |
0.00% |
0 / 1 |
spFatal | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
getIds | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
spGetHTML | |
0.00% |
0 / 34 |
|
0.00% |
0 / 1 |
90 | |||
spGetMessageText | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\SecurePoll\Ballots; |
4 | |
5 | use MediaWiki\Status\Status; |
6 | use OOUI\ButtonInputWidget; |
7 | use OOUI\MessageWidget; |
8 | |
9 | class BallotStatus extends Status { |
10 | /** @var true[] */ |
11 | public $ids = []; |
12 | |
13 | public function spFatal( $message, $id, $localized, ...$params ) { |
14 | $this->errors[] = [ |
15 | 'type' => 'error', |
16 | 'securepoll-id' => $id, |
17 | 'message' => $message, |
18 | 'params' => $params, |
19 | 'localized' => $localized |
20 | ]; |
21 | $this->ids[$id] = true; |
22 | $this->ok = false; |
23 | } |
24 | |
25 | public function getIds() { |
26 | return $this->ids; |
27 | } |
28 | |
29 | public function spGetHTML( $usedIds ) { |
30 | if ( !$this->errors ) { |
31 | return ''; |
32 | } |
33 | $s = '<ul>'; |
34 | $usedIds = []; |
35 | $text = ''; |
36 | foreach ( $this->errors as $error ) { |
37 | if ( !isset( $error['localized'] ) || !$error['localized'] ) { |
38 | $text = wfMessage( $error['message'], $error['params'] )->text(); |
39 | if ( isset( $error['securepoll-id'] ) ) { |
40 | $id = $error['securepoll-id']; |
41 | if ( !isset( $usedIds[$id] ) ) { |
42 | $name = explode( '_', urlencode( "$id" ) ); |
43 | $usedIds[ $name[0] . '_' . $name[1] ][] = urlencode( "$id" ); |
44 | } |
45 | } elseif ( !isset( $error['securepoll-id'] ) ) { |
46 | $s .= new MessageWidget( [ |
47 | 'type' => 'error', |
48 | 'label' => htmlspecialchars( $text ) |
49 | ] ) . "\n"; |
50 | } |
51 | } |
52 | } |
53 | |
54 | if ( count( $usedIds ) > 0 ) { |
55 | $error = new MessageWidget( [ |
56 | 'type' => 'error', |
57 | 'label' => htmlspecialchars( $text ) |
58 | ] ); |
59 | $buttonWidget = new ButtonInputWidget( [ |
60 | 'label' => wfMessage( 'securepoll-ballot-show-warnings' )->text(), |
61 | 'classes' => [ 'highlight-warnings-button' ], |
62 | 'infusable' => true, |
63 | 'data' => json_encode( $usedIds ), |
64 | 'showErrors' => false |
65 | ] ); |
66 | $error->appendContent( $buttonWidget ); |
67 | $s .= $error . "<br>"; |
68 | } |
69 | |
70 | $s .= "</ul>\n"; |
71 | return $s; |
72 | } |
73 | |
74 | public function spGetMessageText( $id ) { |
75 | foreach ( $this->errors as $error ) { |
76 | if ( !isset( $error['securepoll-id'] ) || $error['securepoll-id'] !== $id ) { |
77 | continue; |
78 | } |
79 | |
80 | return wfMessage( $error['message'], $error['params'] )->text(); |
81 | } |
82 | } |
83 | } |