Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
93.33% |
14 / 15 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
ConfirmEditHandler | |
93.33% |
14 / 15 |
|
0.00% |
0 / 1 |
5.01 | |
0.00% |
0 / 1 |
onEditFilterMergedContent | |
93.33% |
14 / 15 |
|
0.00% |
0 / 1 |
5.01 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\AbuseFilter\Hooks\Handlers; |
4 | |
5 | use MediaWiki\Content\Content; |
6 | use MediaWiki\Context\IContextSource; |
7 | use MediaWiki\Extension\ConfirmEdit\Hooks; |
8 | use MediaWiki\Hook\EditFilterMergedContentHook; |
9 | use MediaWiki\Registration\ExtensionRegistry; |
10 | use MediaWiki\Status\Status; |
11 | use MediaWiki\User\User; |
12 | |
13 | /** |
14 | * Integration with Extension:ConfirmEdit, if loaded. |
15 | */ |
16 | class ConfirmEditHandler implements EditFilterMergedContentHook { |
17 | |
18 | /** @inheritDoc */ |
19 | public function onEditFilterMergedContent( |
20 | IContextSource $context, Content $content, Status $status, $summary, User $user, $minoredit |
21 | ) { |
22 | if ( !ExtensionRegistry::getInstance()->isLoaded( 'ConfirmEdit' ) ) { |
23 | return true; |
24 | } |
25 | $simpleCaptcha = Hooks::getInstance(); |
26 | // In WMF production, AbuseFilter is loaded after ConfirmEdit. That means, |
27 | // Extension:ConfirmEdit's EditFilterMergedContent hook has already run, and that hook |
28 | // is responsible for deciding whether to show a CAPTCHA via the SimpleCaptcha::confirmEditMerged |
29 | // method. |
30 | // Here, we look to see if: |
31 | // 1. CaptchaConsequence in AbuseFilter modified the global SimpleCaptcha instance to say that |
32 | // we should force showing a Captcha |
33 | // 2. that the Captcha hasn't yet been solved |
34 | // 3. ConfirmEdit's EditFilterMergedContent handler has already run (ConfirmEdit was loaded |
35 | // ahead of AbuseFilter via wfLoadExtension()) |
36 | // If all conditions are true, we invoke SimpleCaptcha's ConfirmEditMerged method, which |
37 | // will run in a narrower scope (not invoking ConfirmEdit's onConfirmEditTriggersCaptcha hook, |
38 | // for example), and will just make sure that the status is modified to present a CAPTCHA to |
39 | // the user. |
40 | if ( $simpleCaptcha->shouldForceShowCaptcha() && |
41 | !$simpleCaptcha->isCaptchaSolved() && |
42 | $simpleCaptcha->editFilterMergedContentHandlerAlreadyInvoked() ) { |
43 | return $simpleCaptcha->confirmEditMerged( |
44 | $context, |
45 | $content, |
46 | $status, |
47 | $summary, |
48 | $user, |
49 | $minoredit |
50 | ); |
51 | } |
52 | return true; |
53 | } |
54 | |
55 | } |