36 private $preferencesFactory;
39 private $userOptionsManager;
49 parent::__construct(
'Preferences' );
51 $services = MediaWikiServices::getInstance();
52 $this->preferencesFactory = $preferencesFactory ?? $services->getPreferencesFactory();
53 $this->userOptionsManager = $userOptionsManager ?? $services->getUserOptionsManager();
64 $out->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc.
69 if ( $par ==
'reset' ) {
75 $out->addModules(
'mediawiki.special.preferences.ooui' );
76 $out->addModuleStyles( [
77 'mediawiki.special.preferences.styles.ooui',
78 'mediawiki.widgets.TagMultiselectWidget.styles',
80 $out->addModuleStyles(
'oojs-ui-widgets.styles' );
83 if ( $session->get(
'specialPreferencesSaveSuccess' ) ) {
85 $session->remove(
'specialPreferencesSaveSuccess' );
86 $out->addModuleStyles(
'mediawiki.notification.convertmessagebox.styles' );
93 $this->
msg(
'savedprefs' )->text()
95 'mw-preferences-messagebox mw-notify-success'
104 $user = $this->
getUser()->getInstanceForUpdate() ?: $this->
getUser();
110 $sectionTitles = $htmlForm->getPreferenceSections();
113 foreach ( $sectionTitles as $key ) {
116 'label' => $htmlForm->getLegend( $key ),
119 $out->addJsConfigVars(
'wgPreferencesTabs', $prefTabs );
131 $form = $this->preferencesFactory->getForm( $user, $context, PreferencesFormOOUI::class );
136 if ( !$this->
getAuthority()->isAllowed(
'editmyoptions' ) ) {
140 $this->
getOutput()->addWikiMsg(
'prefs-reset-intro' );
145 'label-message' =>
'prefs-reset-confirm',
150 HTMLForm::factory(
'ooui', $desc, $this->
getContext(),
'prefs-restore' )
152 ->setSubmitTextMsg(
'restoreprefs' )
153 ->setSubmitDestructive()
154 ->setSubmitCallback( [ $this,
'submitReset' ] )
162 if ( !$this->
getAuthority()->isAllowed(
'editmyoptions' ) ) {
166 $user = $this->
getUser()->getInstanceForUpdate();
167 $this->userOptionsManager->resetOptions( $user, $this->
getContext(),
'all' );
168 $user->saveSettings();
171 $this->
getRequest()->getSession()->set(
'specialPreferencesSaveSuccess', 1 );
Show an error when a user tries to do something they do not have the necessary permissions for.
Parent class for all special pages.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
getUser()
Shortcut to get the User executing this instance.
requireNamedUser( $reasonMsg='exception-nologin-text', $titleMsg='exception-nologin')
If the user is not logged in or is a temporary user, throws UserNotLoggedIn.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getAuthority()
Shortcut to get the Authority executing this instance.
getRequest()
Get the WebRequest being used for this instance.
checkReadOnly()
If the wiki is currently in readonly mode, throws a ReadOnlyError.
getPageTitle( $subpage=false)
Get a self-referential title object.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
A special page that allows users to change their preferences.
execute( $par)
Default execute method Checks user permissions.
doesWrites()
Indicates whether this special page may perform database writes.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
__construct(PreferencesFactory $preferencesFactory=null, UserOptionsManager $userOptionsManager=null)
getFormObject( $user, IContextSource $context)
Get the preferences form to use.
Interface for objects which can provide a MediaWiki context on request.