Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 61 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
MainElectionsPager | |
0.00% |
0 / 61 |
|
0.00% |
0 / 4 |
380 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
getQueryInfo | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
2 | |||
getLinks | |
0.00% |
0 / 35 |
|
0.00% |
0 / 1 |
272 | |||
getLogLink | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\SecurePoll\Pages; |
4 | |
5 | use MediaWiki\Html\Html; |
6 | use MediaWiki\Linker\LinkRenderer; |
7 | use MediaWiki\Pager\IndexPager; |
8 | use MediaWiki\SpecialPage\SpecialPage; |
9 | use Wikimedia\Rdbms\ILoadBalancer; |
10 | |
11 | /** |
12 | * Pager for an election list. See TablePager documentation. |
13 | */ |
14 | class MainElectionsPager extends ElectionPager { |
15 | private array $subpages = [ |
16 | 'vote' => [ |
17 | 'public' => true, |
18 | 'visible-after-start' => true, |
19 | 'visible-after-close' => false, |
20 | ], |
21 | 'translate' => [ |
22 | 'public' => true, |
23 | 'visible-after-start' => true, |
24 | 'visible-after-close' => true, |
25 | ], |
26 | 'list' => [ |
27 | 'public' => true, |
28 | 'visible-after-start' => true, |
29 | 'visible-after-close' => true, |
30 | ], |
31 | 'edit' => [ |
32 | 'public' => false, |
33 | 'visible-after-start' => true, |
34 | 'visible-after-close' => false, |
35 | ], |
36 | 'votereligibility' => [ |
37 | 'public' => false, |
38 | 'visible-after-start' => true, |
39 | 'visible-after-close' => true, |
40 | ], |
41 | 'dump' => [ |
42 | 'public' => false, |
43 | 'visible-after-start' => true, |
44 | 'visible-after-close' => true, |
45 | ], |
46 | 'dump-blt' => [ |
47 | 'public' => false, |
48 | 'visible-after-start' => true, |
49 | 'visible-after-close' => true, |
50 | ], |
51 | 'tally' => [ |
52 | 'public' => false, |
53 | 'visible-after-start' => true, |
54 | 'visible-after-close' => true, |
55 | ], |
56 | 'log' => [ |
57 | 'public' => false, |
58 | 'visible-after-start' => true, |
59 | 'visible-after-close' => true, |
60 | 'link' => 'getLogLink' |
61 | ], |
62 | 'archive' => [ |
63 | 'public' => false, |
64 | 'visible-after-start' => false, |
65 | 'visible-after-close' => true, |
66 | ] |
67 | ]; |
68 | private LinkRenderer $linkRenderer; |
69 | private ILoadBalancer $loadBalancer; |
70 | |
71 | public function __construct( |
72 | EntryPage $specialPage, |
73 | LinkRenderer $linkRenderer, |
74 | ILoadBalancer $loadBalancer |
75 | ) { |
76 | $this->mDefaultDirection = IndexPager::DIR_DESCENDING; |
77 | parent::__construct(); |
78 | $this->page = $specialPage; |
79 | $this->linkRenderer = $linkRenderer; |
80 | $this->loadBalancer = $loadBalancer; |
81 | } |
82 | |
83 | public function getQueryInfo() { |
84 | $subquery = $this->loadBalancer->getConnection( ILoadBalancer::DB_REPLICA )->newSelectQueryBuilder() |
85 | ->select( 'pr_entity' ) |
86 | ->from( 'securepoll_properties' ) |
87 | ->where( [ 'pr_key' => 'is-archived' ] ) |
88 | ->caller( __METHOD__ ); |
89 | |
90 | return [ |
91 | 'tables' => 'securepoll_elections', |
92 | 'fields' => '*', |
93 | 'conds' => [ |
94 | 'el_entity NOT IN (' . $subquery->getSQL() . ')', |
95 | ], |
96 | ]; |
97 | } |
98 | |
99 | /** |
100 | * @return string HTML |
101 | */ |
102 | public function getLinks(): string { |
103 | $pollId = (int)$this->mCurrentRow->el_entity; |
104 | $html = ''; |
105 | $separator = $this->msg( 'pipe-separator' )->escaped(); |
106 | |
107 | // Only show "Logs" link if the page Special:SecurePollLog is enabled |
108 | if ( !$this->getConfig()->get( 'SecurePollUseLogging' ) ) { |
109 | unset( $this->subpages['log'] ); |
110 | } |
111 | |
112 | foreach ( $this->subpages as $subpage => $props ) { |
113 | // Message keys used here: |
114 | // securepoll-subpage-vote, securepoll-subpage-translate, |
115 | // securepoll-subpage-list, securepoll-subpage-dump, securepoll-subpage-dump-blt |
116 | // securepoll-subpage-tally, securepoll-subpage-votereligibility |
117 | // securepoll-subpage-log, securepoll-subpage-archive |
118 | $linkText = $this->msg( "securepoll-subpage-$subpage" )->text(); |
119 | if ( $subpage === "dump" ) { |
120 | $linkText .= ' (XML)'; |
121 | } |
122 | if ( $subpage === "dump-blt" ) { |
123 | $linkText = $this->msg( "securepoll-subpage-dump" )->text() . ' (BLT)'; |
124 | } |
125 | |
126 | if ( $html !== '' ) { |
127 | $html .= $separator; |
128 | } |
129 | |
130 | $needsHyperlink = |
131 | ( $this->isAdmin || $props['public'] ) && |
132 | ( |
133 | !$this->election->isStarted() || |
134 | ( $this->election->isStarted() && $this->election->isFinished() ) || |
135 | $props['visible-after-start'] |
136 | ) && |
137 | ( !$this->election->isFinished() || $props['visible-after-close'] ); |
138 | if ( $needsHyperlink ) { |
139 | if ( isset( $props['link'] ) ) { |
140 | $html .= $this->{$props['link']}( $pollId ); |
141 | } else { |
142 | if ( $subpage === "dump-blt" ) { |
143 | $title = $this->page->specialPage->getPageTitle( "dump/$pollId" ); |
144 | $html .= $this->linkRenderer->makeKnownLink( $title, $linkText, [], [ 'format' => 'blt' ] ); |
145 | } else { |
146 | $title = $this->page->specialPage->getPageTitle( "$subpage/$pollId" ); |
147 | $html .= $this->linkRenderer->makeKnownLink( $title, $linkText ); |
148 | } |
149 | } |
150 | } else { |
151 | $html .= Html::element( |
152 | 'span', |
153 | [ 'class' => 'securepoll-link-disabled' ], |
154 | $linkText |
155 | ); |
156 | } |
157 | } |
158 | |
159 | return $html; |
160 | } |
161 | |
162 | /** |
163 | * Generate the link to the logs on SecurePollLog for an election |
164 | * @return string HTML |
165 | */ |
166 | public function getLogLink( int $id ): string { |
167 | return $this->linkRenderer->makeLink( |
168 | SpecialPage::getTitleValueFor( 'SecurePollLog' ), |
169 | $this->msg( 'securepoll-subpage-log' )->text(), |
170 | [], |
171 | [ |
172 | 'type' => 'all', |
173 | 'election_name' => $this->page->context->getElection( $id )->title, |
174 | ] |
175 | ); |
176 | } |
177 | } |