Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 33
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
OATHAuthOOUIHTMLForm
0.00% covered (danger)
0.00%
0 / 33
0.00% covered (danger)
0.00%
0 / 6
56
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 show
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 displayForm
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
6
 getDescriptors
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getLogger
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 wrapFieldSetSection
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
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
3namespace MediaWiki\Extension\OATHAuth\HTMLForm;
4
5use IContextSource;
6use MediaWiki\Extension\OATHAuth\IModule;
7use MediaWiki\Extension\OATHAuth\OATHUser;
8use MediaWiki\Extension\OATHAuth\OATHUserRepository;
9use MediaWiki\Logger\LoggerFactory;
10use OOUI\FieldsetLayout;
11use OOUI\HtmlSnippet;
12use OOUI\Layout;
13use OOUI\PanelLayout;
14use OOUI\Widget;
15use OOUIHTMLForm;
16use Psr\Log\LoggerInterface;
17
18abstract 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}