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 | public $required = self::OPTIONAL; |
13 | |
14 | /** @var bool Whether to use the campaign field from the request */ |
15 | private $useCampaignField; |
16 | |
17 | /** @var string Campaign to log */ |
18 | public $campaign = ''; |
19 | |
20 | /** @var string|null returnto title to log */ |
21 | public $returnTo; |
22 | |
23 | /** @var string|null returntoquery to log */ |
24 | public $returnToQuery; |
25 | |
26 | /** |
27 | * @param WebRequest $request Request to load data from |
28 | * @param bool $useCampaignField Whether to actually use the 'campaign' field |
29 | */ |
30 | public function __construct( WebRequest $request, $useCampaignField ) { |
31 | $this->useCampaignField = $useCampaignField; |
32 | if ( $useCampaignField ) { |
33 | $this->campaign = $request->getVal( 'campaign', '' ); |
34 | if ( strlen( $this->campaign ) > 40 ) { |
35 | $this->campaign = ''; |
36 | } |
37 | } |
38 | |
39 | $this->returnTo = $request->getVal( 'returnto' ); |
40 | $this->returnToQuery = $request->getVal( 'returntoquery' ); |
41 | } |
42 | |
43 | /** |
44 | * @inheritDoc |
45 | */ |
46 | public function getFieldInfo() { |
47 | if ( $this->useCampaignField ) { |
48 | return [ |
49 | 'campaign' => [ |
50 | 'type' => 'hidden', |
51 | 'value' => $this->campaign, |
52 | 'label' => wfMessage( 'campaigns-campaign-label' ), |
53 | 'help' => wfMessage( 'campaigns-campaign-help' ), |
54 | 'optional' => true, |
55 | ], |
56 | ]; |
57 | } |
58 | |
59 | return []; |
60 | } |
61 | |
62 | public function loadFromSubmission( array $data ) { |
63 | // We always want to use this request, even if the 'campaign' field got |
64 | // lost or is invalid, so ignore parent's return value. |
65 | parent::loadFromSubmission( $data ); |
66 | |
67 | // Ignore invalid campaigns, but still use the request. |
68 | if ( strlen( $this->campaign ) > 40 ) { |
69 | $this->campaign = ''; |
70 | } |
71 | |
72 | return true; |
73 | } |
74 | } |