29use 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() );
92 parent::execute( $subPage );
94 if ( $this->requestedModule instanceof
IModule ) {
121 $canEnable = $this->
getUser()->isAllowed(
'oathauth-enable' );
123 if ( $this->action === static::ACTION_ENABLE && !$canEnable ) {
132 if ( $this->action === static::ACTION_ENABLE && !$this->
getRequest()->wasPosted() ) {
139 $this->action = $this->
getRequest()->getVal(
'action',
'' );
143 $moduleKey = $this->
getRequest()->getVal(
'module',
'' );
144 $this->requestedModule = $this->auth->getModuleByKey( $moduleKey );
148 return $this->authUser->getModule() instanceof
IModule;
152 return $this->
hasEnabled() ? $this->authUser->getModule() :
null;
171 foreach ( $this->auth->getAllModules() as $key => $module ) {
181 'oathauth-ui-general-help'
195 return $this->
getOutput()->addHTML( (
string)$panel );
205 $modulePanel =
new PanelLayout( [
210 $headerLayout =
new HorizontalLayout();
212 $label =
new LabelWidget( [
216 $button =
new ButtonWidget( [
218 wfMessage(
'oathauth-disable-generic' )->text() :
219 wfMessage(
'oathauth-enable-generic' )->text(),
220 'href' => $this->
getOutput()->getTitle()->getLocalURL( [
222 static::ACTION_DISABLE : static::ACTION_ENABLE,
223 'module' => $module->
getName(),
227 $headerLayout->addItems( [ $button ] );
229 $headerLayout->addItems( [ $label ] );
231 $modulePanel->appendContent( $headerLayout );
232 $modulePanel->appendContent(
new HtmlSnippet(
243 $form = $module->
getManageForm( $this->action, $this->authUser, $this->userRepo );
249 $form->setSubmitCallback( [ $form,
'onSubmit' ] );
250 if ( $form->show( $panel ) ) {
256 $this->
getOutput()->addHTML( Html::element(
'h2', [], $message->
text() ) );
260 if ( !$this->requestedModule instanceof
IModule ) {
270 if ( $this->requestedModule instanceof
IModule ) {
271 if ( $this->requestedModule->getName() === $module->
getName() ) {
292 if ( !( $form instanceof
HTMLForm ) ) {
295 $implements = class_implements( $form );
296 if ( !isset( $implements[IManageForm::class] ) ) {
308 if ( !$form->
hasField(
'module' ) ) {
311 if ( !$form->
hasField(
'action' ) ) {
322 $displayName = $this->requestedModule->getDisplayName();
324 wfMessage(
'oathauth-disable-page-title', $displayName )->text() :
325 wfMessage(
'oathauth-enable-page-title', $displayName )->text();
326 $this->
getOutput()->setPageTitle( $pageTitle );
338 return in_array( $this->action, [ static::ACTION_ENABLE, static::ACTION_DISABLE ] );
342 foreach ( $this->auth->getAllModules() as $key => $module ) {
351 return (
bool)$this->
getRequest()->getVal(
'warn',
false ) &&
352 $this->requestedModule instanceof
IModule &&
357 $panel =
new PanelLayout( [
362 $headerMessage = $this->
isSwitch() ?
363 wfMessage(
'oathauth-switch-method-warning-header' ) :
364 wfMessage(
'oathauth-disable-method-warning-header' );
365 $genericMessage = $this->
isSwitch() ?
367 'oathauth-switch-method-warning',
369 $this->requestedModule->getDisplayName()
373 $panel->appendContent(
new HtmlSnippet(
374 $genericMessage->parseAsBlock()
377 $customMessage = $this->
getEnabled()->getDisableWarningMessage();
378 if ( $customMessage instanceof
Message ) {
379 $panel->appendContent(
new HtmlSnippet(
380 $customMessage->parseAsBlock()
384 $button =
new ButtonWidget( [
385 'label' =>
wfMessage(
'oathauth-disable-method-warning-button-label' )->plain(),
387 'action' => $this->action,
388 'module' => $this->requestedModule->getName()
390 'flags' => [
'primary',
'progressive' ]
392 $panel->appendContent( $button );
394 $this->
getOutput()->setPageTitle( $headerMessage );
395 $this->
getOutput()->addHTML( $panel->toString() );
399 return $this->requestedModule instanceof
IModule &&
400 $this->action === static::ACTION_ENABLE &&
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Exceptions for config failures.
This class is a collection of static functions that serve two purposes:
The Message class provides methods which fulfil two basic services:
text()
Returns the message text.
Show an error when a user tries to do something they do not have the necessary permissions for.
Parent class for all special pages.
getOutput()
Get the OutputPage being used for this instance.
requireLogin( $reasonMsg='exception-nologin-text', $titleMsg='exception-nologin')
If the user is not logged in, throws UserNotLoggedIn error.
checkLoginSecurityLevel( $level=null)
Verifies that the user meets the security level, possibly reauthenticating them in the process.
getUser()
Shortcut to get the User executing this instance.
getRequest()
Get the WebRequest being used for this instance.
displayRestrictionError()
Output an error message telling the user what access level they have to have.
Redirect a user to the login page.