Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 30 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| DisableForm | |
0.00% |
0 / 30 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 1 |
| onSuccess | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDescriptors | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
6 | |||
| onSubmit | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Extension\OATHAuth\HTMLForm; |
| 4 | |
| 5 | use MediaWiki\CheckUser\Services\CheckUserInsert; |
| 6 | use MediaWiki\Logging\ManualLogEntry; |
| 7 | use MediaWiki\MediaWikiServices; |
| 8 | use MediaWiki\Message\Message; |
| 9 | use MediaWiki\Registration\ExtensionRegistry; |
| 10 | use MediaWiki\Status\Status; |
| 11 | |
| 12 | class DisableForm extends OATHAuthOOUIHTMLForm { |
| 13 | |
| 14 | public function onSuccess(): void { |
| 15 | $this->getOutput()->addWikiMsg( 'oathauth-disabledoath' ); |
| 16 | } |
| 17 | |
| 18 | protected function getDescriptors(): array { |
| 19 | $this->setSubmitTextMsg( 'oathauth-disable-generic' ); |
| 20 | $this->setSubmitDestructive(); |
| 21 | |
| 22 | $disableWarning = $this->msg( |
| 23 | 'oathauth-disable-method-warning', |
| 24 | $this->module->getDisplayName() |
| 25 | )->parseAsBlock(); |
| 26 | $customMessage = $this->module->getDisableWarningMessage(); |
| 27 | if ( $customMessage instanceof Message ) { |
| 28 | $disableWarning .= $customMessage->parseAsBlock(); |
| 29 | } |
| 30 | |
| 31 | return [ |
| 32 | 'warning' => [ |
| 33 | 'type' => 'info', |
| 34 | 'raw' => true, |
| 35 | 'default' => $disableWarning |
| 36 | ] |
| 37 | ]; |
| 38 | } |
| 39 | |
| 40 | public function onSubmit( array $formData ): Status|bool|array|string { |
| 41 | $this->oathRepo->removeAllOfType( |
| 42 | $this->oathUser, |
| 43 | $this->module->getName(), |
| 44 | $this->getRequest()->getIP(), |
| 45 | true |
| 46 | ); |
| 47 | |
| 48 | if ( !$this->oathUser->getKeys() && ExtensionRegistry::getInstance()->isLoaded( 'CheckUser' ) ) { |
| 49 | $logEntry = new ManualLogEntry( 'oath', 'disable-self' ); |
| 50 | $logEntry->setPerformer( $this->getUser() ); |
| 51 | $logEntry->setTarget( $this->getUser()->getUserPage() ); |
| 52 | /** @var CheckUserInsert $checkUserInsert */ |
| 53 | $checkUserInsert = MediaWikiServices::getInstance()->get( 'CheckUserInsert' ); |
| 54 | $checkUserInsert->updateCheckUserData( $logEntry->getRecentChange() ); |
| 55 | } |
| 56 | |
| 57 | return true; |
| 58 | } |
| 59 | } |