Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 24
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
EntryPage
0.00% covered (danger)
0.00%
0 / 24
0.00% covered (danger)
0.00%
0 / 3
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 1
6
 getTitle
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Extension\SecurePoll\Pages;
4
5use MediaWiki\Extension\SecurePoll\SpecialSecurePoll;
6use MediaWiki\Linker\LinkRenderer;
7use MediaWiki\SpecialPage\SpecialPage;
8use MediaWiki\Title\Title;
9use Wikimedia\Rdbms\ILoadBalancer;
10
11/**
12 * The entry page for SecurePoll. Shows a list of elections.
13 */
14class EntryPage extends ActionPage {
15    /** @var LinkRenderer */
16    private $linkRenderer;
17    /** @var ILoadBalancer */
18    private $loadBalancer;
19
20    /**
21     * @param SpecialSecurePoll $specialPage
22     * @param LinkRenderer $linkRenderer
23     * @param ILoadBalancer $loadBalancer
24     */
25    public function __construct(
26        SpecialSecurePoll $specialPage,
27        LinkRenderer $linkRenderer,
28        ILoadBalancer $loadBalancer
29    ) {
30        parent::__construct( $specialPage );
31        $this->linkRenderer = $linkRenderer;
32        $this->loadBalancer = $loadBalancer;
33    }
34
35    /**
36     * Execute the subpage.
37     * @param array $params Array of subpage parameters.
38     */
39    public function execute( $params ) {
40        $pager = new MainElectionsPager( $this, $this->linkRenderer, $this->loadBalancer );
41        $out = $this->specialPage->getOutput();
42        $out->addWikiMsg( 'securepoll-entry-text' );
43        $out->addParserOutputContent( $pager->getBodyOutput() );
44        $out->addHTML( $pager->getNavigationBar() );
45
46        $links = [
47            $this->linkRenderer->makeLink(
48                SpecialPage::getTitleFor( 'SecurePoll', 'archived' ),
49                $this->msg( 'securepoll-entry-archived' )->text()
50            ),
51        ];
52
53        if ( $this->specialPage->getUser()->isAllowed( 'securepoll-create-poll' ) ) {
54            $links[] = $this->linkRenderer->makeLink(
55                SpecialPage::getTitleFor( 'SecurePoll', 'create' ),
56                $this->msg( 'securepoll-entry-createpoll' )->text()
57            );
58        }
59
60        $subtitle = implode( ' | ', array_filter( $links, static function ( $link ) {
61            return (bool)$link;
62        } ) );
63
64        $out->setSubtitle( $subtitle );
65    }
66
67    /**
68     * @return Title
69     */
70    public function getTitle() {
71        return $this->specialPage->getPageTitle( 'entry' );
72    }
73}