MediaWiki REL1_34
AuthModule.php
Go to the documentation of this file.
1<?php
2
4
7use OOUI\HorizontalLayout;
8use OOUI\LabelWidget;
9use OOUI\ButtonWidget;
10use SpecialPage;
11
16 protected $userRepo;
20 protected $user;
24 protected $preferences;
25
31 public static function callback( $user, &$preferences ) {
32 $userRepo = MediaWikiServices::getInstance()->getService( 'OATHUserRepository' );
33 $handler = new static( $userRepo, $user, $preferences );
34 return $handler->execute();
35 }
36
37 protected function __construct( $userRepo, $user, &$preferences ) {
38 $this->userRepo = $userRepo;
39 $this->user = $user;
40 $this->preferences = &$preferences;
41 }
42
43 protected function execute() {
44 $oathUser = $this->userRepo->findByUser( $this->user );
45
46 // If there is no existing module in user, and the user is not allowed to enable it,
47 // we have nothing to show.
48 if ( $oathUser->getModule() === null && !$this->user->isAllowed( 'oathauth-enable' ) ) {
49 return true;
50 }
51 $module = $oathUser->getModule();
52
53 $moduleLabel = $module === null ?
54 wfMessage( 'oauthauth-ui-no-module' ) :
55 $module->getDisplayName();
56
57 $manageButton = new ButtonWidget( [
58 'href' => SpecialPage::getTitleFor( 'OATHManage' )->getLocalURL(),
59 'label' => wfMessage( 'oathauth-ui-manage' )->text()
60 ] );
61 $currentModuleLabel = new LabelWidget( [
62 'label' => $moduleLabel->text()
63 ] );
64 $control = new HorizontalLayout( [
65 'items' => [
66 $currentModuleLabel,
67 $manageButton
68 ]
69 ] );
70
71 $this->preferences['oathauth-module'] = [
72 'type' => 'info',
73 'raw' => true,
74 'default' => (string)$control,
75 'label-message' => 'oathauth-prefs-label',
76 'section' => 'personal/info', ];
77
78 return true;
79 }
80}
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
MediaWikiServices is the service locator for the application scope of MediaWiki.
static getInstance()
Returns the global default instance of the top level service locator.
Parent class for all special pages.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:51