Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
EditInSequence | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
56 | |
0.00% |
0 / 1 |
isEnabled | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
shouldLoadEditInSequence | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
isEditInSequenceEdit | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace ProofreadPage; |
4 | |
5 | use ExtensionRegistry; |
6 | use IContextSource; |
7 | use MediaWiki\Extension\BetaFeatures\BetaFeatures; |
8 | |
9 | class EditInSequence { |
10 | /** url parameter for edit-in-sequence */ |
11 | public const URLPARAMNAME = 'prp_editinsequence'; |
12 | public const TAGNAME = 'proofreadpage-editinsequence'; |
13 | public const BETA_FEATURE_NAME = 'proofreadpage-editinsequence'; |
14 | public const USER_AGENT_NAME = 'EditInSequence'; |
15 | |
16 | /** |
17 | * Check if we are edit-in-sequence is enabled for a particular wiki |
18 | * @param IContextSource $context |
19 | * @return bool |
20 | */ |
21 | public static function isEnabled( IContextSource $context ): bool { |
22 | // By default if beta features is not present, enable by default, |
23 | // else respect beta feature setting |
24 | $isBetaFeatureEnabled = true; |
25 | if ( ExtensionRegistry::getInstance()->isLoaded( 'BetaFeatures' ) ) { |
26 | $isBetaFeatureEnabled = BetaFeatures::isFeatureEnabled( |
27 | $context->getUser(), |
28 | 'proofreadpage-editinsequence' |
29 | ); |
30 | } |
31 | return $context->getConfig()->get( 'ProofreadPageEnableEditInSequence' ) && $isBetaFeatureEnabled; |
32 | } |
33 | |
34 | /** |
35 | * Make sure we are supposed to load edit-in-sequence (i.e. edit-in-sequence is enabled |
36 | * for the wiki and the user is in edit-in-sequence mode) |
37 | * @param IContextSource $context |
38 | * @return bool |
39 | */ |
40 | public static function shouldLoadEditInSequence( IContextSource $context ): bool { |
41 | return $context->getConfig()->get( 'ProofreadPageEnableEditInSequence' ) |
42 | && $context->getRequest()->getBool( self::URLPARAMNAME ); |
43 | } |
44 | |
45 | /** |
46 | * Check if we are saving a edit made using the editinsequence mode |
47 | * @param IContextSource $context |
48 | * @return bool |
49 | */ |
50 | public static function isEditInSequenceEdit( IContextSource $context ): bool { |
51 | return self::isEnabled( $context ) && |
52 | $context->getRequest()->getHeader( 'X-USER-AGENT' ) === self::USER_AGENT_NAME; |
53 | } |
54 | } |