| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\OATHAuth\HTMLForm; |
| 4 |
|
| 5 |
use MediaWiki\Context\IContextSource; |
| 6 |
use MediaWiki\Extension\OATHAuth\IModule; |
| 7 |
use MediaWiki\Extension\OATHAuth\OATHUser; |
| 8 |
use MediaWiki\Extension\OATHAuth\OATHUserRepository; |
| 9 |
use MediaWiki\HTMLForm\OOUIHTMLForm; |
| 10 |
use MediaWiki\Logger\LoggerFactory; |
| 11 |
use OOUI\FieldsetLayout; |
| 12 |
use OOUI\HtmlSnippet; |
| 13 |
use OOUI\Layout; |
| 14 |
use OOUI\PanelLayout; |
| 15 |
use OOUI\Widget; |
| 16 |
use Psr\Log\LoggerInterface; |
| 17 |
|
| 18 |
abstract class OATHAuthOOUIHTMLForm extends OOUIHTMLForm implements IManageForm { |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
protected $oathUser; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
protected $oathRepo; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
protected $module; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
protected $logger; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
protected $layoutContainer = null; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
protected $panelPadded = true; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
protected $panelFramed = true; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
public function __construct( |
| 63 |
OATHUser $oathUser, |
| 64 |
OATHUserRepository $oathRepo, |
| 65 |
IModule $module, |
| 66 |
IContextSource $context |
| 67 |
) { |
| 68 |
$this->oathUser = $oathUser; |
| 69 |
$this->oathRepo = $oathRepo; |
| 70 |
$this->module = $module; |
| 71 |
$this->logger = $this->getLogger(); |
| 72 |
|
| 73 |
parent::__construct( $this->getDescriptors(), $context, "oathauth" ); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
public function show( $layout = null ) { |
| 80 |
$this->layoutContainer = $layout; |
| 81 |
return parent::show(); |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
public function displayForm( $submitResult ) { |
| 88 |
if ( !$this->layoutContainer instanceof Layout ) { |
| 89 |
parent::displayForm( $submitResult ); |
| 90 |
return; |
| 91 |
} |
| 92 |
|
| 93 |
$this->layoutContainer->appendContent( new HtmlSnippet( |
| 94 |
$this->getHTML( $submitResult ) |
| 95 |
) ); |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
protected function getDescriptors() { |
| 102 |
return []; |
| 103 |
} |
| 104 |
|
| 105 |
private function getLogger(): LoggerInterface { |
| 106 |
return LoggerFactory::getInstance( 'authentication' ); |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) { |
| 113 |
|
| 114 |
$layout = new PanelLayout( [ |
| 115 |
'expanded' => false, |
| 116 |
'infusable' => false, |
| 117 |
'padded' => $this->panelPadded, |
| 118 |
'framed' => $this->panelFramed, |
| 119 |
] ); |
| 120 |
|
| 121 |
$layout->appendContent( |
| 122 |
new FieldsetLayout( [ |
| 123 |
'label' => $legend, |
| 124 |
'infusable' => false, |
| 125 |
'items' => [ |
| 126 |
new Widget( [ |
| 127 |
'content' => new HtmlSnippet( $section ) |
| 128 |
] ), |
| 129 |
], |
| 130 |
] + $attributes ) |
| 131 |
); |
| 132 |
return $layout; |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
abstract public function onSubmit( array $formData ); |
| 140 |
|
| 141 |
abstract public function onSuccess(); |
| 142 |
} |