Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 43
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
ArchivedPager
0.00% covered (danger)
0.00%
0 / 43
0.00% covered (danger)
0.00%
0 / 3
210
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 getQueryInfo
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
2
 getLinks
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 1
156
1<?php
2
3namespace MediaWiki\Extension\SecurePoll\Pages;
4
5use MediaWiki\Html\Html;
6use MediaWiki\Linker\LinkRenderer;
7use MediaWiki\Pager\IndexPager;
8use Wikimedia\Rdbms\ILoadBalancer;
9
10/**
11 * Pager for an archived election list. See TablePager documentation.
12 */
13class ArchivedPager extends ElectionPager {
14    private array $subpages = [
15        'unarchive' => [
16            'public' => false,
17            'visible-after-start' => false,
18            'visible-after-close' => true,
19        ]
20    ];
21    private LinkRenderer $linkRenderer;
22    private ILoadBalancer $loadBalancer;
23
24    public function __construct(
25        ArchivedPage $specialPage,
26        LinkRenderer $linkRenderer,
27        ILoadBalancer $loadBalancer
28    ) {
29        $this->mDefaultDirection = IndexPager::DIR_DESCENDING;
30        parent::__construct();
31        $this->page = $specialPage;
32        $this->linkRenderer = $linkRenderer;
33        $this->loadBalancer = $loadBalancer;
34    }
35
36    /**
37     * Return query paramters in array form to get archived elections
38     */
39    public function getQueryInfo(): array {
40        $subquery = $this->loadBalancer->getConnection( ILoadBalancer::DB_REPLICA )->newSelectQueryBuilder()
41            ->select( 'pr_entity' )
42            ->from( 'securepoll_properties' )
43            ->where( [ 'pr_key' => 'is-archived' ] )
44            ->caller( __METHOD__ );
45
46        return [
47            'tables' => 'securepoll_elections',
48            'fields' => '*',
49            'conds' => [
50                'el_entity IN (' . $subquery->getSQL() . ')',
51            ],
52        ];
53    }
54
55    /**
56     * @return string HTML
57     */
58    public function getLinks(): string {
59        $pollId = $this->mCurrentRow->el_entity;
60        $html = '';
61        $separator = $this->msg( 'pipe-separator' )->escaped();
62        foreach ( $this->subpages as $subpage => $props ) {
63            // Message keys used here:
64            // securepoll-subpage-unarchive
65            $linkText = $this->msg( "securepoll-subpage-$subpage" )->text();
66
67            if ( $html !== '' ) {
68                $html .= $separator;
69            }
70
71            $needsHyperlink =
72                ( $this->isAdmin || $props['public'] ) &&
73                (
74                    !$this->election->isStarted() ||
75                    ( $this->election->isStarted() && $this->election->isFinished() ) ||
76                    $props['visible-after-start']
77                ) &&
78                ( !$this->election->isFinished() || $props['visible-after-close'] );
79            if ( $needsHyperlink ) {
80                if ( isset( $props['link'] ) ) {
81                    $html .= $this->{$props['link']}( $pollId );
82                } else {
83                    $title = $this->page->specialPage->getPageTitle( "$subpage/$pollId" );
84                    $html .= $this->linkRenderer->makeKnownLink( $title, $linkText );
85                }
86            } else {
87                $html .= Html::element(
88                    'span',
89                    [ 'class' => 'securepoll-link-disabled' ],
90                    $linkText
91                );
92            }
93        }
94
95        return $html;
96    }
97}