Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 27 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
SpecialSecurePoll | |
0.00% |
0 / 27 |
|
0.00% |
0 / 5 |
110 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
doesWrites | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
30 | |||
getSubpage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setSubtitle | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\SecurePoll; |
4 | |
5 | use MediaWiki\Extension\SecurePoll\Pages\ActionPage; |
6 | use MediaWiki\Extension\SecurePoll\Pages\EntryPage; |
7 | use MediaWiki\SpecialPage\SpecialPage; |
8 | |
9 | /** |
10 | * The page that's initially called by MediaWiki when navigating to |
11 | * Special:SecurePoll. The actual pages are not actually subclasses of |
12 | * this or of SpecialPage, they're subclassed from ActionPage. |
13 | */ |
14 | class SpecialSecurePoll extends SpecialPage { |
15 | /** @var Context */ |
16 | public $sp_context; |
17 | |
18 | /** @var ActionPageFactory */ |
19 | private $actionPageFactory; |
20 | |
21 | /** |
22 | * Constructor |
23 | * @param ActionPageFactory $actionPageFactory |
24 | */ |
25 | public function __construct( |
26 | ActionPageFactory $actionPageFactory |
27 | ) { |
28 | parent::__construct( 'SecurePoll' ); |
29 | $this->sp_context = new Context; |
30 | |
31 | $this->actionPageFactory = $actionPageFactory; |
32 | } |
33 | |
34 | public function doesWrites() { |
35 | return true; |
36 | } |
37 | |
38 | /** |
39 | * Show the special page |
40 | * |
41 | * @param string|null $subPage parameter passed to the page or null |
42 | */ |
43 | public function execute( $subPage ) { |
44 | $out = $this->getOutput(); |
45 | |
46 | $this->setHeaders(); |
47 | |
48 | $out->addModuleStyles( 'ext.securepoll.special' ); |
49 | |
50 | if ( $subPage === null || $subPage === '' ) { |
51 | $subPage = 'entry'; |
52 | } |
53 | $params = explode( '/', $subPage ); |
54 | $pageName = array_shift( $params ); |
55 | $page = $this->getSubpage( $pageName ); |
56 | if ( !$page ) { |
57 | $out->addWikiMsg( 'securepoll-invalid-page', $pageName ); |
58 | return; |
59 | } |
60 | |
61 | if ( !( $page instanceof EntryPage ) ) { |
62 | $this->setSubtitle(); |
63 | } |
64 | |
65 | $page->execute( $params ); |
66 | } |
67 | |
68 | /** |
69 | * Get a _ActionPage subclass object for the given subpage name |
70 | * @param string $name |
71 | * @return null|ActionPage |
72 | */ |
73 | public function getSubpage( $name ) { |
74 | return $this->actionPageFactory->getPage( $name, $this ); |
75 | } |
76 | |
77 | /** |
78 | * Set a navigation subtitle. |
79 | * Each argument is a two-element array giving a Title object to be used as |
80 | * a link target, and the link text. |
81 | * @param array ...$links |
82 | */ |
83 | public function setSubtitle( ...$links ) { |
84 | $title = $this->getPageTitle(); |
85 | $linkRenderer = $this->getLinkRenderer(); |
86 | |
87 | $subtitle = '< ' . $linkRenderer->makeKnownLink( $title, $title->getText() ); |
88 | $pipe = $this->msg( 'pipe-separator' )->escaped(); |
89 | foreach ( $links as $link ) { |
90 | [ $title, $text ] = $link; |
91 | $subtitle .= $pipe . $linkRenderer->makeKnownLink( $title, $text ); |
92 | } |
93 | $this->getOutput()->setSubtitle( $subtitle ); |
94 | } |
95 | } |