Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 30 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| OATHAuthOOUIHTMLForm | |
0.00% |
0 / 30 |
|
0.00% |
0 / 6 |
56 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| show | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| displayForm | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| getDescriptors | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getLogger | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| wrapFieldSetSection | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
2 | |||
| onSubmit | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| onSuccess | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Extension\OATHAuth\HTMLForm; |
| 4 | |
| 5 | use MediaWiki\Context\IContextSource; |
| 6 | use MediaWiki\Extension\OATHAuth\Module\IModule; |
| 7 | use MediaWiki\Extension\OATHAuth\OATHAuthModuleRegistry; |
| 8 | use MediaWiki\Extension\OATHAuth\OATHUser; |
| 9 | use MediaWiki\Extension\OATHAuth\OATHUserRepository; |
| 10 | use MediaWiki\HTMLForm\OOUIHTMLForm; |
| 11 | use MediaWiki\Logger\LoggerFactory; |
| 12 | use MediaWiki\Status\Status; |
| 13 | use OOUI\FieldsetLayout; |
| 14 | use OOUI\HtmlSnippet; |
| 15 | use OOUI\Layout; |
| 16 | use OOUI\PanelLayout; |
| 17 | use OOUI\Widget; |
| 18 | use Psr\Log\LoggerInterface; |
| 19 | |
| 20 | abstract class OATHAuthOOUIHTMLForm extends OOUIHTMLForm { |
| 21 | |
| 22 | protected LoggerInterface $logger; |
| 23 | |
| 24 | protected ?Layout $layoutContainer = null; |
| 25 | |
| 26 | /** |
| 27 | * Make the form-wrapper panel padded |
| 28 | */ |
| 29 | protected bool $panelPadded = true; |
| 30 | |
| 31 | /** |
| 32 | * Make the form-wrapper panel framed |
| 33 | */ |
| 34 | protected bool $panelFramed = true; |
| 35 | |
| 36 | public function __construct( |
| 37 | protected readonly OATHUser $oathUser, |
| 38 | protected readonly OATHUserRepository $oathRepo, |
| 39 | protected readonly IModule $module, |
| 40 | IContextSource $context, |
| 41 | protected readonly OATHAuthModuleRegistry $moduleRegistry, |
| 42 | ) { |
| 43 | $this->logger = $this->getLogger(); |
| 44 | |
| 45 | parent::__construct( $this->getDescriptors(), $context, "oathauth" ); |
| 46 | } |
| 47 | |
| 48 | /** @inheritDoc */ |
| 49 | public function show( $layout = null ): Status|bool { |
| 50 | $this->layoutContainer = $layout; |
| 51 | return parent::show(); |
| 52 | } |
| 53 | |
| 54 | /** @inheritDoc */ |
| 55 | public function displayForm( $submitResult ) { |
| 56 | if ( !$this->layoutContainer instanceof Layout ) { |
| 57 | parent::displayForm( $submitResult ); |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | $this->layoutContainer->appendContent( new HtmlSnippet( |
| 62 | $this->getHTML( $submitResult ) |
| 63 | ) ); |
| 64 | } |
| 65 | |
| 66 | protected function getDescriptors(): array { |
| 67 | return []; |
| 68 | } |
| 69 | |
| 70 | private function getLogger(): LoggerInterface { |
| 71 | return LoggerFactory::getInstance( 'authentication' ); |
| 72 | } |
| 73 | |
| 74 | /** @inheritDoc */ |
| 75 | protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) { |
| 76 | // to get a user-visible effect, wrap the fieldset into a framed panel layout |
| 77 | $layout = new PanelLayout( [ |
| 78 | 'expanded' => false, |
| 79 | 'infusable' => false, |
| 80 | 'padded' => $this->panelPadded, |
| 81 | 'framed' => $this->panelFramed, |
| 82 | ] ); |
| 83 | |
| 84 | $layout->appendContent( |
| 85 | new FieldsetLayout( [ |
| 86 | 'label' => $legend, |
| 87 | 'infusable' => false, |
| 88 | 'items' => [ |
| 89 | new Widget( [ |
| 90 | 'content' => new HtmlSnippet( $section ) |
| 91 | ] ), |
| 92 | ], |
| 93 | ] + $attributes ) |
| 94 | ); |
| 95 | return $layout; |
| 96 | } |
| 97 | |
| 98 | abstract public function onSubmit( array $formData ): Status|bool|array|string; |
| 99 | |
| 100 | abstract public function onSuccess(): void; |
| 101 | } |