MediaWiki  1.34.0
OATHAuthOOUIHTMLForm.php
Go to the documentation of this file.
1 <?php
2 
4 
9 use OOUI\FieldsetLayout;
10 use OOUI\HtmlSnippet;
11 use OOUI\Layout;
12 use OOUI\PanelLayout;
13 use OOUI\Widget;
14 use OOUIHTMLForm;
15 use Psr\Log\LoggerInterface;
16 
17 abstract class OATHAuthOOUIHTMLForm extends OOUIHTMLForm implements IManageForm {
21  protected $oathUser;
25  protected $oathRepo;
29  protected $module;
30 
34  protected $logger;
35 
39  protected $layoutContainer = null;
40 
45  protected $panelPadded = true;
46 
51  protected $panelFramed = true;
52 
61  $this->oathUser = $oathUser;
62  $this->oathRepo = $oathRepo;
63  $this->module = $module;
64  $this->logger = $this->getLogger();
65 
66  parent::__construct( $this->getDescriptors(), null, "oathauth" );
67  }
68 
72  public function show( $layout = null ) {
73  $this->layoutContainer = $layout;
74  return parent::show();
75  }
76 
80  public function displayForm( $submitResult ) {
81  if ( !$this->layoutContainer instanceof Layout ) {
82  return parent::displayForm( $submitResult );
83  }
84 
85  $this->layoutContainer->appendContent( new HtmlSnippet(
86  $this->getHTML( $submitResult )
87  ) );
88  }
89 
93  protected function getDescriptors() {
94  return [];
95  }
96 
100  private function getLogger() {
101  return LoggerFactory::getInstance( 'authentication' );
102  }
103 
104  protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) {
105  // to get a user visible effect, wrap the fieldset into a framed panel layout
106  $layout = new PanelLayout( array_merge( [
107  'expanded' => false,
108  'padded' => true,
109  'framed' => false,
110  'infusable' => false,
111  ], [
112  'padded' => $this->panelPadded,
113  'framed' => $this->panelFramed
114  ] ) );
115 
116  $layout->appendContent(
117  new FieldsetLayout( [
118  'label' => $legend,
119  'infusable' => false,
120  'items' => [
121  new Widget( [
122  'content' => new HtmlSnippet( $section )
123  ] ),
124  ],
125  ] + $attributes )
126  );
127  return $layout;
128  }
129 
134  abstract public function onSubmit( array $formData );
135 
136  abstract public function onSuccess();
137 }
MediaWiki\Extension\OATHAuth\HTMLForm\OATHAuthOOUIHTMLForm\$oathRepo
OATHUserRepository $oathRepo
Definition: OATHAuthOOUIHTMLForm.php:25
MediaWiki\Extension\OATHAuth\HTMLForm\OATHAuthOOUIHTMLForm\displayForm
displayForm( $submitResult)
Display the form (sending to the context's OutputPage object), with an appropriate error message or s...
Definition: OATHAuthOOUIHTMLForm.php:80
MediaWiki\Extension\OATHAuth\OATHUser
Class representing a user from OATH's perspective.
Definition: OATHUser.php:28
MediaWiki\Extension\OATHAuth\HTMLForm\OATHAuthOOUIHTMLForm\onSubmit
onSubmit(array $formData)
MediaWiki\Logger\LoggerFactory\getInstance
static getInstance( $channel)
Get a named logger instance from the currently configured logger factory.
Definition: LoggerFactory.php:92
MediaWiki\Extension\OATHAuth\HTMLForm\OATHAuthOOUIHTMLForm\$panelPadded
bool $panelPadded
Make the form-wrapper panel padded.
Definition: OATHAuthOOUIHTMLForm.php:45
MediaWiki\Extension\OATHAuth\HTMLForm\OATHAuthOOUIHTMLForm
Definition: OATHAuthOOUIHTMLForm.php:17
OOUIHTMLForm
Compact stacked vertical format for forms, implemented using OOUI widgets.
Definition: OOUIHTMLForm.php:27
MediaWiki\Extension\OATHAuth\HTMLForm\OATHAuthOOUIHTMLForm\$layoutContainer
Layout null $layoutContainer
Definition: OATHAuthOOUIHTMLForm.php:39
MediaWiki\Extension\OATHAuth\OATHUserRepository
Definition: OATHUserRepository.php:33
MediaWiki\Logger\LoggerFactory
PSR-3 logger instance factory.
Definition: LoggerFactory.php:45
MediaWiki\Extension\OATHAuth\HTMLForm\OATHAuthOOUIHTMLForm\onSuccess
onSuccess()
MediaWiki\Extension\OATHAuth\HTMLForm
Definition: IManageForm.php:3
MediaWiki\Extension\OATHAuth\HTMLForm\OATHAuthOOUIHTMLForm\$logger
LoggerInterface $logger
Definition: OATHAuthOOUIHTMLForm.php:34
MediaWiki\Extension\OATHAuth\HTMLForm\OATHAuthOOUIHTMLForm\$panelFramed
bool $panelFramed
Make the form-wrapper panel framed.
Definition: OATHAuthOOUIHTMLForm.php:51
MediaWiki\Extension\OATHAuth\HTMLForm\OATHAuthOOUIHTMLForm\wrapFieldSetSection
wrapFieldSetSection( $legend, $section, $attributes, $isRoot)
Wraps the given $section into an user-visible fieldset.Legend text for the fieldset The section conte...
Definition: OATHAuthOOUIHTMLForm.php:104
MediaWiki\Extension\OATHAuth\HTMLForm\OATHAuthOOUIHTMLForm\getDescriptors
getDescriptors()
Definition: OATHAuthOOUIHTMLForm.php:93
HTMLForm\getHTML
getHTML( $submitResult)
Returns the raw HTML generated by the form.
Definition: HTMLForm.php:1062
MediaWiki\Extension\OATHAuth\HTMLForm\OATHAuthOOUIHTMLForm\__construct
__construct(OATHUser $oathUser, OATHUserRepository $oathRepo, IModule $module)
Initialize the form.
Definition: OATHAuthOOUIHTMLForm.php:60
MediaWiki\Extension\OATHAuth\HTMLForm\OATHAuthOOUIHTMLForm\$module
IModule $module
Definition: OATHAuthOOUIHTMLForm.php:29
MediaWiki\Extension\OATHAuth\HTMLForm\OATHAuthOOUIHTMLForm\$oathUser
OATHUser $oathUser
Definition: OATHAuthOOUIHTMLForm.php:21
MediaWiki\Extension\OATHAuth\HTMLForm\OATHAuthOOUIHTMLForm\show
show( $layout=null)
bool|Status
Definition: OATHAuthOOUIHTMLForm.php:72
MediaWiki\Extension\OATHAuth\HTMLForm\IManageForm
Definition: IManageForm.php:10
MediaWiki\Extension\OATHAuth\HTMLForm\OATHAuthOOUIHTMLForm\getLogger
getLogger()
Definition: OATHAuthOOUIHTMLForm.php:100
MediaWiki\Extension\OATHAuth\IModule
Definition: IModule.php:9