28 use OOUI\ButtonWidget;
29 use OOUI\HorizontalLayout;
74 parent::__construct(
'OATHManage',
'oathauth-enable' );
77 $this->auth = $services->getService(
'OATHAuth' );
78 $this->userRepo = $services->getService(
'OATHUserRepository' );
79 $this->authUser = $this->userRepo->findByUser( $this->
getUser() );
91 parent::execute( $subPage );
93 if ( $this->requestedModule instanceof
IModule ) {
120 $canEnable = $this->
getUser()->isAllowed(
'oathauth-enable' );
122 if ( $this->action === static::ACTION_ENABLE && !$canEnable ) {
131 if ( $this->action === static::ACTION_ENABLE && !$this->
getRequest()->wasPosted() ) {
138 $this->action = $this->
getRequest()->getVal(
'action',
'' );
142 $moduleKey = $this->
getRequest()->getVal(
'module',
'' );
143 $this->requestedModule = $this->auth->getModuleByKey( $moduleKey );
147 return $this->authUser->getModule() instanceof
IModule;
151 return $this->
hasEnabled() ? $this->authUser->getModule() :
null;
170 foreach ( $this->auth->getAllModules() as $key => $module ) {
180 'oathauth-ui-general-help'
194 return $this->
getOutput()->addHTML( (
string)$panel );
204 $modulePanel =
new PanelLayout( [
209 $headerLayout =
new HorizontalLayout();
211 $label =
new LabelWidget( [
215 $button =
new ButtonWidget( [
217 wfMessage(
'oathauth-disable-generic' )->text() :
218 wfMessage(
'oathauth-enable-generic' )->text(),
221 static::ACTION_DISABLE : static::ACTION_ENABLE,
222 'module' => $module->
getName(),
226 $headerLayout->addItems( [ $button ] );
228 $headerLayout->addItems( [ $label ] );
230 $modulePanel->appendContent( $headerLayout );
231 $modulePanel->appendContent(
new HtmlSnippet(
242 $form = $module->
getManageForm( $this->action, $this->authUser, $this->userRepo );
248 $form->setSubmitCallback( [ $form,
'onSubmit' ] );
249 if ( $form->show( $panel ) ) {
255 $this->
getOutput()->addHTML( Html::element(
'h2', [], $message->text() ) );
259 if ( !$this->requestedModule instanceof
IModule ) {
269 if ( $this->requestedModule instanceof
IModule ) {
270 if ( $this->requestedModule->getName() === $module->
getName() ) {
291 if ( !( $form instanceof
HTMLForm ) ) {
294 $implements = class_implements( $form );
295 if ( !isset( $implements[IManageForm::class] ) ) {
307 if ( !$form->
hasField(
'module' ) ) {
310 if ( !$form->
hasField(
'action' ) ) {
321 $displayName = $this->requestedModule->getDisplayName();
323 wfMessage(
'oathauth-disable-page-title', $displayName )->text() :
324 wfMessage(
'oathauth-enable-page-title', $displayName )->text();
325 $this->
getOutput()->setPageTitle( $pageTitle );
337 return in_array( $this->action, [ static::ACTION_ENABLE, static::ACTION_DISABLE ] );
341 foreach ( $this->auth->getAllModules() as $key => $module ) {
350 return (
bool)$this->
getRequest()->getVal(
'warn',
false ) &&
351 $this->requestedModule instanceof
IModule &&
356 $panel =
new PanelLayout( [
361 $headerMessage = $this->
isSwitch() ?
362 wfMessage(
'oathauth-switch-method-warning-header' ) :
363 wfMessage(
'oathauth-disable-method-warning-header' );
364 $genericMessage = $this->
isSwitch() ?
366 'oathauth-switch-method-warning',
368 $this->requestedModule->getDisplayName()
372 $panel->appendContent(
new HtmlSnippet(
373 $genericMessage->parseAsBlock()
376 $customMessage = $this->
getEnabled()->getDisableWarningMessage();
377 if ( $customMessage instanceof
Message ) {
378 $panel->appendContent(
new HtmlSnippet(
379 $customMessage->parseAsBlock()
383 $button =
new ButtonWidget( [
384 'label' =>
wfMessage(
'oathauth-disable-method-warning-button-label' )->plain(),
386 'action' => $this->action,
387 'module' => $this->requestedModule->getName()
389 'flags' => [
'primary',
'progressive' ]
391 $panel->appendContent( $button );
393 $this->
getOutput()->setPageTitle( $headerMessage );
394 $this->
getOutput()->addHTML( $panel->toString() );
398 return $this->requestedModule instanceof
IModule &&
399 $this->action === static::ACTION_ENABLE &&