2004-02-18 02:15:00 +00:00
|
|
|
<?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.,
|
2010-06-21 13:16:32 +00:00
|
|
|
* 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
|
2010-08-15 07:16:58 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
2010-06-21 12:59:04 +00:00
|
|
|
*/
|
2004-09-02 23:28:24 +00:00
|
|
|
|
2023-09-13 11:10:05 +00:00
|
|
|
namespace MediaWiki\Specials;
|
|
|
|
|
|
2024-02-08 14:56:54 +00:00
|
|
|
use MediaWiki\Context\IContextSource;
|
2023-02-16 19:27:21 +00:00
|
|
|
use MediaWiki\Html\Html;
|
2024-02-08 15:30:18 +00:00
|
|
|
use MediaWiki\HTMLForm\HTMLForm;
|
2017-11-07 03:10:14 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2020-10-18 11:35:42 +00:00
|
|
|
use MediaWiki\Preferences\PreferencesFactory;
|
2023-09-15 09:32:18 +00:00
|
|
|
use MediaWiki\SpecialPage\SpecialPage;
|
2023-11-29 10:21:43 +00:00
|
|
|
use MediaWiki\User\Options\UserOptionsManager;
|
2023-09-19 12:13:45 +00:00
|
|
|
use MediaWiki\User\User;
|
2024-01-04 17:21:36 +00:00
|
|
|
use OOUI\FieldLayout;
|
|
|
|
|
use OOUI\SearchInputWidget;
|
2023-09-13 11:10:05 +00:00
|
|
|
use PermissionsError;
|
|
|
|
|
use PreferencesFormOOUI;
|
2017-11-07 03:10:14 +00:00
|
|
|
|
2010-08-15 07:16:58 +00:00
|
|
|
/**
|
|
|
|
|
* A special page that allows users to change their preferences
|
|
|
|
|
*
|
|
|
|
|
* @ingroup SpecialPage
|
|
|
|
|
*/
|
2009-04-24 01:31:17 +00:00
|
|
|
class SpecialPreferences extends SpecialPage {
|
2020-10-18 11:35:42 +00:00
|
|
|
|
2023-08-28 15:32:58 +00:00
|
|
|
private PreferencesFactory $preferencesFactory;
|
|
|
|
|
private UserOptionsManager $userOptionsManager;
|
2020-10-18 11:35:42 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param PreferencesFactory|null $preferencesFactory
|
|
|
|
|
* @param UserOptionsManager|null $userOptionsManager
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(
|
2024-10-16 18:58:33 +00:00
|
|
|
?PreferencesFactory $preferencesFactory = null,
|
|
|
|
|
?UserOptionsManager $userOptionsManager = null
|
2020-10-18 11:35:42 +00:00
|
|
|
) {
|
2009-04-24 01:31:17 +00:00
|
|
|
parent::__construct( 'Preferences' );
|
2020-10-21 18:41:25 +00:00
|
|
|
// This class is extended and therefore falls back to global state - T265924
|
2020-10-18 11:35:42 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
$this->preferencesFactory = $preferencesFactory ?? $services->getPreferencesFactory();
|
|
|
|
|
$this->userOptionsManager = $userOptionsManager ?? $services->getUserOptionsManager();
|
2018-05-01 13:59:29 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-14 22:35:31 +00:00
|
|
|
public function doesWrites() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-22 18:32:48 +00:00
|
|
|
public function execute( $par ) {
|
2009-04-24 07:46:19 +00:00
|
|
|
$this->setHeaders();
|
|
|
|
|
$this->outputHeader();
|
2011-08-22 18:32:48 +00:00
|
|
|
$out = $this->getOutput();
|
2013-05-09 14:51:30 +00:00
|
|
|
$out->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc.
|
2009-04-24 07:50:45 +00:00
|
|
|
|
2022-04-11 01:39:33 +00:00
|
|
|
$this->requireNamedUser( 'prefsnologintext2' );
|
2011-11-15 01:34:19 +00:00
|
|
|
$this->checkReadOnly();
|
2009-04-24 07:50:45 +00:00
|
|
|
|
2009-04-24 07:46:19 +00:00
|
|
|
if ( $par == 'reset' ) {
|
2009-04-24 01:31:17 +00:00
|
|
|
$this->showResetForm();
|
2013-05-09 14:51:30 +00:00
|
|
|
|
2007-10-12 10:27:57 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2010-10-04 22:16:18 +00:00
|
|
|
|
2018-09-18 18:46:46 +00:00
|
|
|
$out->addModules( 'mediawiki.special.preferences.ooui' );
|
2018-12-12 15:57:57 +00:00
|
|
|
$out->addModuleStyles( [
|
|
|
|
|
'mediawiki.special.preferences.styles.ooui',
|
2023-02-20 12:01:05 +00:00
|
|
|
'oojs-ui-widgets.styles',
|
2018-12-12 15:57:57 +00:00
|
|
|
] );
|
2007-10-12 10:27:57 +00:00
|
|
|
|
2016-08-22 04:36:09 +00:00
|
|
|
$session = $this->getRequest()->getSession();
|
|
|
|
|
if ( $session->get( 'specialPreferencesSaveSuccess' ) ) {
|
2016-01-09 22:41:46 +00:00
|
|
|
// Remove session data for the success message
|
2016-08-22 04:36:09 +00:00
|
|
|
$session->remove( 'specialPreferencesSaveSuccess' );
|
2015-10-14 17:20:28 +00:00
|
|
|
$out->addModuleStyles( 'mediawiki.notification.convertmessagebox.styles' );
|
2016-01-09 22:41:46 +00:00
|
|
|
|
2016-09-26 22:32:54 +00:00
|
|
|
$out->addHTML(
|
2022-04-27 00:41:06 +00:00
|
|
|
Html::successBox(
|
|
|
|
|
Html::element(
|
|
|
|
|
'p',
|
|
|
|
|
[],
|
|
|
|
|
$this->msg( 'savedprefs' )->text()
|
|
|
|
|
),
|
|
|
|
|
'mw-preferences-messagebox mw-notify-success'
|
2015-10-14 17:20:28 +00:00
|
|
|
)
|
2009-04-24 01:31:17 +00:00
|
|
|
);
|
2005-08-19 13:27:32 +00:00
|
|
|
}
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2015-05-02 11:37:19 +00:00
|
|
|
$this->addHelpLink( 'Help:Preferences' );
|
2015-03-04 23:25:56 +00:00
|
|
|
|
2021-09-01 21:04:40 +00:00
|
|
|
// Load the user from the primary DB to reduce CAS errors on double post (T95839)
|
2016-04-14 23:22:54 +00:00
|
|
|
if ( $this->getRequest()->wasPosted() ) {
|
|
|
|
|
$user = $this->getUser()->getInstanceForUpdate() ?: $this->getUser();
|
|
|
|
|
} else {
|
|
|
|
|
$user = $this->getUser();
|
|
|
|
|
}
|
2015-12-13 04:35:22 +00:00
|
|
|
|
2017-08-10 17:15:16 +00:00
|
|
|
$htmlForm = $this->getFormObject( $user, $this->getContext() );
|
2017-12-02 21:15:35 +00:00
|
|
|
$sectionTitles = $htmlForm->getPreferenceSections();
|
|
|
|
|
|
2018-09-18 18:46:46 +00:00
|
|
|
$prefTabs = [];
|
|
|
|
|
foreach ( $sectionTitles as $key ) {
|
|
|
|
|
$prefTabs[] = [
|
|
|
|
|
'name' => $key,
|
|
|
|
|
'label' => $htmlForm->getLegend( $key ),
|
|
|
|
|
];
|
2015-11-01 00:34:46 +00:00
|
|
|
}
|
2018-09-18 18:46:46 +00:00
|
|
|
$out->addJsConfigVars( 'wgPreferencesTabs', $prefTabs );
|
2018-05-03 13:17:41 +00:00
|
|
|
|
2024-01-04 17:21:36 +00:00
|
|
|
$out->addHTML( new FieldLayout(
|
|
|
|
|
new SearchInputWidget( [
|
2023-03-01 22:38:31 +00:00
|
|
|
'placeholder' => $this->msg( 'searchprefs' )->text(),
|
|
|
|
|
] ),
|
|
|
|
|
[
|
|
|
|
|
'classes' => [ 'mw-prefs-search' ],
|
|
|
|
|
'label' => $this->msg( 'searchprefs' )->text(),
|
|
|
|
|
'invisibleLabel' => true,
|
|
|
|
|
'infusable' => true,
|
|
|
|
|
]
|
|
|
|
|
) );
|
2009-04-24 01:31:17 +00:00
|
|
|
$htmlForm->show();
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
2009-04-24 07:50:45 +00:00
|
|
|
|
2017-08-10 17:15:16 +00:00
|
|
|
/**
|
|
|
|
|
* Get the preferences form to use.
|
2020-10-27 17:13:40 +00:00
|
|
|
* @param User $user
|
|
|
|
|
* @param IContextSource $context
|
2019-04-14 00:43:33 +00:00
|
|
|
* @return PreferencesFormOOUI|HTMLForm
|
2017-08-10 17:15:16 +00:00
|
|
|
*/
|
|
|
|
|
protected function getFormObject( $user, IContextSource $context ) {
|
2020-10-18 11:35:42 +00:00
|
|
|
$form = $this->preferencesFactory->getForm( $user, $context, PreferencesFormOOUI::class );
|
2017-11-07 03:10:14 +00:00
|
|
|
return $form;
|
2017-08-10 17:15:16 +00:00
|
|
|
}
|
|
|
|
|
|
2017-11-07 03:15:24 +00:00
|
|
|
protected function showResetForm() {
|
2021-03-04 20:16:50 +00:00
|
|
|
if ( !$this->getAuthority()->isAllowed( 'editmyoptions' ) ) {
|
2013-06-10 19:30:43 +00:00
|
|
|
throw new PermissionsError( 'editmyoptions' );
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-22 18:32:48 +00:00
|
|
|
$this->getOutput()->addWikiMsg( 'prefs-reset-intro' );
|
2009-04-24 07:50:45 +00:00
|
|
|
|
2022-05-10 05:18:17 +00:00
|
|
|
$desc = [
|
|
|
|
|
'confirm' => [
|
|
|
|
|
'type' => 'check',
|
|
|
|
|
'label-message' => 'prefs-reset-confirm',
|
|
|
|
|
'required' => true,
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
// TODO: disable the submit button if the checkbox is not checked
|
2022-05-15 20:58:23 +00:00
|
|
|
HTMLForm::factory( 'ooui', $desc, $this->getContext(), 'prefs-restore' )
|
|
|
|
|
->setTitle( $this->getPageTitle( 'reset' ) ) // Reset subpage
|
2020-09-08 14:20:44 +00:00
|
|
|
->setSubmitTextMsg( 'restoreprefs' )
|
|
|
|
|
->setSubmitDestructive()
|
|
|
|
|
->setSubmitCallback( [ $this, 'submitReset' ] )
|
2022-05-10 05:18:17 +00:00
|
|
|
->showCancel()
|
|
|
|
|
->setCancelTarget( $this->getPageTitle() )
|
2020-09-08 14:20:44 +00:00
|
|
|
->show();
|
2004-04-01 13:03:05 +00:00
|
|
|
}
|
2009-04-24 07:50:45 +00:00
|
|
|
|
2011-08-22 18:32:48 +00:00
|
|
|
public function submitReset( $formData ) {
|
2021-03-04 20:16:50 +00:00
|
|
|
if ( !$this->getAuthority()->isAllowed( 'editmyoptions' ) ) {
|
2013-06-10 19:30:43 +00:00
|
|
|
throw new PermissionsError( 'editmyoptions' );
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-22 04:17:36 +00:00
|
|
|
$user = $this->getUser()->getInstanceForUpdate();
|
2024-05-27 06:15:03 +00:00
|
|
|
$this->userOptionsManager->resetAllOptions( $user );
|
2011-08-22 18:32:48 +00:00
|
|
|
$user->saveSettings();
|
2009-04-24 07:50:45 +00:00
|
|
|
|
2016-01-09 22:41:46 +00:00
|
|
|
// Set session data for the success message
|
2016-08-22 04:36:09 +00:00
|
|
|
$this->getRequest()->getSession()->set( 'specialPreferencesSaveSuccess', 1 );
|
2009-04-24 07:50:45 +00:00
|
|
|
|
2016-02-07 13:07:20 +00:00
|
|
|
$url = $this->getPageTitle()->getFullUrlForRedirect();
|
2011-08-22 18:32:48 +00:00
|
|
|
$this->getOutput()->redirect( $url );
|
2009-04-24 07:50:45 +00:00
|
|
|
|
2009-04-24 01:31:17 +00:00
|
|
|
return true;
|
2003-07-01 12:47:44 +00:00
|
|
|
}
|
2013-03-07 20:15:54 +00:00
|
|
|
|
|
|
|
|
protected function getGroupName() {
|
2023-03-24 18:03:57 +00:00
|
|
|
return 'login';
|
2013-03-07 20:15:54 +00:00
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
2023-09-13 11:10:05 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retain the old class name for backwards compatibility.
|
|
|
|
|
* @deprecated since 1.41
|
|
|
|
|
*/
|
|
|
|
|
class_alias( SpecialPreferences::class, 'SpecialPreferences' );
|