Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ConfirmEdit | |
0.00% |
0 / 18 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
| validate | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
20 | |||
| enabled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Flow\SpamFilter; |
| 4 | |
| 5 | use Flow\Model\AbstractRevision; |
| 6 | use Flow\Model\HtmlRenderingInformation; |
| 7 | use MediaWiki\Context\IContextSource; |
| 8 | use MediaWiki\Extension\ConfirmEdit\Services\CaptchaFactory; |
| 9 | use MediaWiki\MediaWikiServices; |
| 10 | use MediaWiki\Registration\ExtensionRegistry; |
| 11 | use MediaWiki\Status\Status; |
| 12 | use MediaWiki\Title\Title; |
| 13 | |
| 14 | class ConfirmEdit implements SpamFilter { |
| 15 | /** |
| 16 | * @param IContextSource $context |
| 17 | * @param AbstractRevision $newRevision |
| 18 | * @param AbstractRevision|null $oldRevision |
| 19 | * @param Title $title |
| 20 | * @param Title $ownerTitle |
| 21 | * @return Status |
| 22 | */ |
| 23 | public function validate( |
| 24 | IContextSource $context, |
| 25 | AbstractRevision $newRevision, |
| 26 | ?AbstractRevision $oldRevision, |
| 27 | Title $title, |
| 28 | Title $ownerTitle |
| 29 | ) { |
| 30 | $newContent = $newRevision->getContentInWikitext(); |
| 31 | $oldContent = ( $oldRevision !== null ) ? $oldRevision->getContentInWikitext() : ''; |
| 32 | |
| 33 | $services = MediaWikiServices::getInstance(); |
| 34 | /** @var CaptchaFactory $captchaFactory */ |
| 35 | $captchaFactory = $services->get( 'ConfirmEditCaptchaFactory' ); |
| 36 | $captcha = $captchaFactory->getGlobalInstance(); |
| 37 | $wikiPage = $services->getWikiPageFactory()->newFromTitle( $title ); |
| 38 | |
| 39 | // first check if the submitted content is offensive (as flagged by |
| 40 | // ConfirmEdit), next check for a (valid) captcha to have been entered |
| 41 | if ( |
| 42 | $captcha->shouldCheck( $wikiPage, $newContent, '', $context, $oldContent ) && |
| 43 | !$captcha->passCaptchaLimitedFromRequest( $context->getRequest(), $context->getUser() ) |
| 44 | ) { |
| 45 | // getting here means we submitted bad content without good captcha |
| 46 | // result (or any captcha result at all) - let's get the captcha |
| 47 | // information (HTML, modules, etc.) to display as error message! |
| 48 | $captchaInfo = $captcha->getFormInformation( 1, $context->getOutput() ); |
| 49 | $captchaRenderingInfo = HtmlRenderingInformation::fromArray( |
| 50 | $captchaInfo |
| 51 | ); |
| 52 | |
| 53 | $msg = wfMessage( 'flow-spam-confirmedit-form' )->rawParams( $captchaInfo['html'] ); |
| 54 | $status = Status::newFatal( $msg ); |
| 55 | $status->setResult( false, $captchaRenderingInfo ); |
| 56 | return $status; |
| 57 | } |
| 58 | |
| 59 | return Status::newGood(); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Checks if ConfirmEdit is installed. |
| 64 | * |
| 65 | * @return bool |
| 66 | */ |
| 67 | public function enabled() { |
| 68 | return ExtensionRegistry::getInstance()->isLoaded( 'ConfirmEdit' ); |
| 69 | } |
| 70 | } |