Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
CampaignsAuthenticationRequest | |
0.00% |
0 / 22 |
|
0.00% |
0 / 3 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
getFieldInfo | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 | |||
loadFromSubmission | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\Campaigns; |
4 | |
5 | use MediaWiki\Auth\AuthenticationRequest; |
6 | use MediaWiki\Request\WebRequest; |
7 | |
8 | /** |
9 | * An authentication request to grab the custom field passed to the creation form. |
10 | */ |
11 | class CampaignsAuthenticationRequest extends AuthenticationRequest { |
12 | /** @var int */ |
13 | public $required = self::OPTIONAL; |
14 | |
15 | /** @var bool Whether to use the campaign field from the request */ |
16 | private $useCampaignField; |
17 | |
18 | /** @var string Campaign to log */ |
19 | public $campaign = ''; |
20 | |
21 | /** @var string|null returnto title to log */ |
22 | public $returnTo; |
23 | |
24 | /** @var string|null returntoquery to log */ |
25 | public $returnToQuery; |
26 | |
27 | /** |
28 | * @param WebRequest $request Request to load data from |
29 | * @param bool $useCampaignField Whether to actually use the 'campaign' field |
30 | */ |
31 | public function __construct( WebRequest $request, $useCampaignField ) { |
32 | $this->useCampaignField = $useCampaignField; |
33 | if ( $useCampaignField ) { |
34 | $this->campaign = $request->getVal( 'campaign', '' ); |
35 | if ( strlen( $this->campaign ) > 40 ) { |
36 | $this->campaign = ''; |
37 | } |
38 | } |
39 | |
40 | $this->returnTo = $request->getVal( 'returnto' ); |
41 | $this->returnToQuery = $request->getVal( 'returntoquery' ); |
42 | } |
43 | |
44 | /** |
45 | * @inheritDoc |
46 | */ |
47 | public function getFieldInfo() { |
48 | if ( $this->useCampaignField ) { |
49 | return [ |
50 | 'campaign' => [ |
51 | 'type' => 'hidden', |
52 | 'value' => $this->campaign, |
53 | 'label' => wfMessage( 'campaigns-campaign-label' ), |
54 | 'help' => wfMessage( 'campaigns-campaign-help' ), |
55 | 'optional' => true, |
56 | ], |
57 | ]; |
58 | } |
59 | |
60 | return []; |
61 | } |
62 | |
63 | /** @inheritDoc */ |
64 | public function loadFromSubmission( array $data ) { |
65 | // We always want to use this request, even if the 'campaign' field got |
66 | // lost or is invalid, so ignore parent's return value. |
67 | parent::loadFromSubmission( $data ); |
68 | |
69 | // Ignore invalid campaigns, but still use the request. |
70 | if ( strlen( $this->campaign ) > 40 ) { |
71 | $this->campaign = ''; |
72 | } |
73 | |
74 | return true; |
75 | } |
76 | } |