Debian Codegraph @

extensions/OATHAuth/src/HTMLForm/OATHAuthOOUIHTMLForm.php

raw symbols SCIP
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 * @var OATHUser
21 */
22 protected $oathUser;
23 /**
24 * @var OATHUserRepository
25 */
26 protected $oathRepo;
27 /**
28 * @var IModule
29 */
30 protected $module;
31
32 /**
33 * @var LoggerInterface
34 */
35 protected $logger;
36
37 /**
38 * @var Layout|null
39 */
40 protected $layoutContainer = null;
41
42 /**
43 * Make the form-wrapper panel padded
44 * @var bool
45 */
46 protected $panelPadded = true;
47
48 /**
49 * Make the form-wrapper panel framed
50 * @var bool
51 */
52 protected $panelFramed = true;
53
54 /**
55 * Initialize the form
56 *
57 * @param OATHUser $oathUser
58 * @param OATHUserRepository $oathRepo
59 * @param IModule $module
60 * @param IContextSource $context
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 * @inheritDoc
78 */
79 public function show( $layout = null ) {
80 $this->layoutContainer = $layout;
81 return parent::show();
82 }
83
84 /**
85 * @inheritDoc
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 * @return array
100 */
101 protected function getDescriptors() {
102 return [];
103 }
104
105 private function getLogger(): LoggerInterface {
106 return LoggerFactory::getInstance( 'authentication' );
107 }
108
109 /**
110 * @inheritDoc
111 */
112 protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) {
113 // to get a user visible effect, wrap the fieldset into a framed panel layout
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 * @param array $formData
137 * @return array|bool
138 */
139 abstract public function onSubmit( array $formData );
140
141 abstract public function onSuccess();
142 }