wiki.techinc.nl/includes/specials/SpecialPreferences.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

203 lines
5.8 KiB
PHP
Raw Normal View History

<?php
2010-06-21 12:59:04 +00:00
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2010-06-21 12:59:04 +00:00
* http://www.gnu.org/copyleft/gpl.html
*
* @file
2010-06-21 12:59:04 +00:00
*/
namespace MediaWiki\Specials;
use MediaWiki\Context\IContextSource;
use MediaWiki\Html\Html;
use MediaWiki\HTMLForm\HTMLForm;
use MediaWiki\MediaWikiServices;
use MediaWiki\Preferences\PreferencesFactory;
use MediaWiki\SpecialPage\SpecialPage;
use MediaWiki\User\Options\UserOptionsManager;
use MediaWiki\User\User;
use OOUI\FieldLayout;
use OOUI\SearchInputWidget;
use PermissionsError;
use PreferencesFormOOUI;
/**
* A special page that allows users to change their preferences
*
* @ingroup SpecialPage
*/
class SpecialPreferences extends SpecialPage {
private PreferencesFactory $preferencesFactory;
private UserOptionsManager $userOptionsManager;
/**
* @param PreferencesFactory|null $preferencesFactory
* @param UserOptionsManager|null $userOptionsManager
*/
public function __construct(
?PreferencesFactory $preferencesFactory = null,
?UserOptionsManager $userOptionsManager = null
) {
parent::__construct( 'Preferences' );
// This class is extended and therefore falls back to global state - T265924
$services = MediaWikiServices::getInstance();
$this->preferencesFactory = $preferencesFactory ?? $services->getPreferencesFactory();
$this->userOptionsManager = $userOptionsManager ?? $services->getUserOptionsManager();
}
public function doesWrites() {
return true;
}
public function execute( $par ) {
$this->setHeaders();
$this->outputHeader();
$out = $this->getOutput();
$out->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc.
$this->requireNamedUser( 'prefsnologintext2' );
$this->checkReadOnly();
if ( $par == 'reset' ) {
$this->showResetForm();
return;
}
$out->addModules( 'mediawiki.special.preferences.ooui' );
$out->addModuleStyles( [
'mediawiki.special.preferences.styles.ooui',
'oojs-ui-widgets.styles',
] );
$session = $this->getRequest()->getSession();
if ( $session->get( 'specialPreferencesSaveSuccess' ) ) {
// Remove session data for the success message
$session->remove( 'specialPreferencesSaveSuccess' );
$out->addModuleStyles( 'mediawiki.notification.convertmessagebox.styles' );
$out->addHTML(
Html::successBox(
Html::element(
'p',
[],
$this->msg( 'savedprefs' )->text()
),
'mw-preferences-messagebox mw-notify-success'
)
);
}
$this->addHelpLink( 'Help:Preferences' );
// Load the user from the primary DB to reduce CAS errors on double post (T95839)
if ( $this->getRequest()->wasPosted() ) {
$user = $this->getUser()->getInstanceForUpdate() ?: $this->getUser();
} else {
$user = $this->getUser();
}
$htmlForm = $this->getFormObject( $user, $this->getContext() );
Revert "Special:Preferences: Use OOjs UI" and follow-ups The number of issues with the new interface is unacceptable and we will not be able to fix them reasonably quickly. See subtasks of T180538 for the list of issues, raised both by the Wikimedia community and by WMF employees. I should have pushed back harder against the merging of this half-baked change with the promise that we'll fix it later. I convinced myself that the regressions were not so noticeable and that the issues that were pointed out will in fact be fixed by someone. Predictably, however, regressions were bad and the only person fixing the issues was me. I am not going to work nights to make this page decent again within a reasonable timeframe; I'm not sure if I'd even be able to since many issues are problems with the design rather than the implementation. No one else seems to be working on improving it, therefore I am reverting the change. On the bright side, this work has resulted in a number of improvements to HTMLForm and Preferences code, which are not being reverted here: <https://gerrit.wikimedia.org/r/#/q/topic:T117781>. If anyone reattempts this, I recommend gating the new interface behind a configuration variable and URL parameter, like we did with $wgOOUIEditPage in the past, and testing thoroughly in production before enabling it for everyone. * Revert "Special:Preferences: Use OOjs UI" This reverts commit 486e566cfef612de6773df435a74d5fc37e27174. * Revert "Preferences: Show preview of edit fonts in edit font selector" This reverts commit 6634ff729dc7f6d0f541639dbdf3c4d9f786ddf6. * Revert "Follow-Up Iae63b6994: Add missing editfont dependency" This reverts commit ce42fdf151c39f91cf4077673219fa6228a54d7f. * Revert "Preferences: Improve visual appearance by “unboxing” sections" This reverts commit c9415bb0059f4dae4abc5e39a8af844328333120. * Revert "Remove box-shadow from preference panels for ooui-apex" This reverts commit a934b82ca27971e8f0553a7ab7c8ee30fccf3283. * Revert "Preferences: Don't show the watchlist token; just link to ResetTokens" This reverts commit e8c9102fc7b66460c33f643b0dea7190cb89ac83. * Revert "mw.special.preferences: Make the "Basic information" section more compact" This reverts commit d48b7260f30c1ec57046a1f8e4c82057aed45e5f. * Revert "mw.special.preferences: Widen the dropdown of the "Time zone" field" This reverts commit afd5f1417efdd463d86186257c4ec77dd4a442ce. Bug: T117781 Bug: T180538 Change-Id: I44b5daea1828f71881b5bd35218f5ecb7ab7f36e
2017-12-02 21:15:35 +00:00
$sectionTitles = $htmlForm->getPreferenceSections();
$prefTabs = [];
foreach ( $sectionTitles as $key ) {
$prefTabs[] = [
'name' => $key,
'label' => $htmlForm->getLegend( $key ),
];
}
$out->addJsConfigVars( 'wgPreferencesTabs', $prefTabs );
$out->addHTML( new FieldLayout(
new SearchInputWidget( [
'placeholder' => $this->msg( 'searchprefs' )->text(),
] ),
[
'classes' => [ 'mw-prefs-search' ],
'label' => $this->msg( 'searchprefs' )->text(),
'invisibleLabel' => true,
'infusable' => true,
]
) );
$htmlForm->show();
2003-04-14 23:10:40 +00:00
}
/**
* Get the preferences form to use.
* @param User $user
* @param IContextSource $context
* @return PreferencesFormOOUI|HTMLForm
*/
protected function getFormObject( $user, IContextSource $context ) {
$form = $this->preferencesFactory->getForm( $user, $context, PreferencesFormOOUI::class );
return $form;
}
protected function showResetForm() {
if ( !$this->getAuthority()->isAllowed( 'editmyoptions' ) ) {
throw new PermissionsError( 'editmyoptions' );
}
$this->getOutput()->addWikiMsg( 'prefs-reset-intro' );
$desc = [
'confirm' => [
'type' => 'check',
'label-message' => 'prefs-reset-confirm',
'required' => true,
],
];
// TODO: disable the submit button if the checkbox is not checked
HTMLForm::factory( 'ooui', $desc, $this->getContext(), 'prefs-restore' )
->setTitle( $this->getPageTitle( 'reset' ) ) // Reset subpage
->setSubmitTextMsg( 'restoreprefs' )
->setSubmitDestructive()
->setSubmitCallback( [ $this, 'submitReset' ] )
->showCancel()
->setCancelTarget( $this->getPageTitle() )
->show();
}
public function submitReset( $formData ) {
if ( !$this->getAuthority()->isAllowed( 'editmyoptions' ) ) {
throw new PermissionsError( 'editmyoptions' );
}
$user = $this->getUser()->getInstanceForUpdate();
2024-05-27 06:15:03 +00:00
$this->userOptionsManager->resetAllOptions( $user );
$user->saveSettings();
// Set session data for the success message
$this->getRequest()->getSession()->set( 'specialPreferencesSaveSuccess', 1 );
$url = $this->getPageTitle()->getFullUrlForRedirect();
$this->getOutput()->redirect( $url );
return true;
2003-07-01 12:47:44 +00:00
}
protected function getGroupName() {
return 'login';
}
2003-04-14 23:10:40 +00:00
}
/**
* Retain the old class name for backwards compatibility.
* @deprecated since 1.41
*/
class_alias( SpecialPreferences::class, 'SpecialPreferences' );