Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| Manager | |
100.00% |
5 / 5 |
|
100.00% |
3 / 3 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
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 | public function __construct( |
| 32 | private readonly Config $config, |
| 33 | private readonly MobileContext $mobileContext, |
| 34 | ) { |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Returns information if the AMC mode is available for current session |
| 39 | * @return bool |
| 40 | * @throws ConfigException |
| 41 | */ |
| 42 | public function isAvailable() { |
| 43 | return $this->mobileContext->shouldDisplayMobileView() |
| 44 | && $this->config->get( self::AMC_MODE_CONFIG_NAME ) |
| 45 | && !$this->mobileContext->getUser()->isAnon(); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Get the mode identifier (used in configs) |
| 50 | * |
| 51 | * @return string |
| 52 | */ |
| 53 | public function getModeIdentifier() { |
| 54 | return self::AMC_MODE_IDENTIFIER; |
| 55 | } |
| 56 | } |