Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
6 / 6 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
Manager | |
100.00% |
6 / 6 |
|
100.00% |
3 / 3 |
5 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
isAvailable | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
3 | |||
getModeIdentifier | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace MobileFrontend\Amc; |
4 | |
5 | use MediaWiki\Config\Config; |
6 | use MediaWiki\Config\ConfigException; |
7 | use MobileContext; |
8 | |
9 | /** |
10 | * Advanced Mobile Contributions Manager |
11 | * |
12 | * @package MobileFrontend\Amc |
13 | */ |
14 | final class Manager { |
15 | /** |
16 | * A config name used to enable/disable the AMC mode |
17 | */ |
18 | private const AMC_MODE_CONFIG_NAME = 'MFAdvancedMobileContributions'; |
19 | |
20 | /** |
21 | * Mode identifier used in feature configs |
22 | */ |
23 | private const AMC_MODE_IDENTIFIER = 'amc'; |
24 | |
25 | /** |
26 | * Change tag |
27 | * All edits when has AMC enabled will be tagged with AMC_EDIT_TAG |
28 | */ |
29 | public const AMC_EDIT_TAG = 'advanced mobile edit'; |
30 | |
31 | /** |
32 | * MobileContext used to retrieve shouldDisplayMobileView and user information |
33 | * |
34 | * @var MobileContext |
35 | */ |
36 | private $mobileContext; |
37 | |
38 | /** |
39 | * System config |
40 | * @var Config |
41 | */ |
42 | private $config; |
43 | |
44 | /** |
45 | * @param Config $config |
46 | * @param MobileContext $mobileContext |
47 | */ |
48 | public function __construct( Config $config, MobileContext $mobileContext ) { |
49 | $this->config = $config; |
50 | $this->mobileContext = $mobileContext; |
51 | } |
52 | |
53 | /** |
54 | * Returns information if the AMC mode is available for current session |
55 | * @return bool |
56 | * @throws ConfigException |
57 | */ |
58 | public function isAvailable() { |
59 | return $this->mobileContext->shouldDisplayMobileView() |
60 | && $this->config->get( self::AMC_MODE_CONFIG_NAME ) |
61 | && !$this->mobileContext->getUser()->isAnon(); |
62 | } |
63 | |
64 | /** |
65 | * Get the mode identifier (used in configs) |
66 | * |
67 | * @return string |
68 | */ |
69 | public function getModeIdentifier() { |
70 | return self::AMC_MODE_IDENTIFIER; |
71 | } |
72 | } |