2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2010-06-21 12:59:04 +00:00
|
|
|
/**
|
2010-08-15 07:16:58 +00:00
|
|
|
* Implements Special:Preferences
|
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
|
|
|
|
|
* @ingroup SpecialPage
|
2010-06-21 12:59:04 +00:00
|
|
|
*/
|
2004-09-02 23:28:24 +00:00
|
|
|
|
2017-11-07 03:10:14 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
|
|
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 {
|
2018-05-01 13:59:29 +00:00
|
|
|
/**
|
|
|
|
|
* @var bool Whether OOUI should be enabled here
|
|
|
|
|
*/
|
|
|
|
|
private $oouiEnabled = false;
|
|
|
|
|
|
2009-04-24 01:31:17 +00:00
|
|
|
function __construct() {
|
|
|
|
|
parent::__construct( 'Preferences' );
|
2018-05-01 13:59:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if OOUI mode is enabled, by config or query string
|
2018-05-09 20:39:20 +00:00
|
|
|
*
|
|
|
|
|
* @since 1.32
|
2018-05-01 13:59:29 +00:00
|
|
|
* @param IContextSource $context The context.
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public static function isOouiEnabled( IContextSource $context ) {
|
|
|
|
|
return $context->getRequest()->getFuzzyBool( 'ooui',
|
|
|
|
|
$context->getConfig()->get( 'OOUIPreferences' )
|
|
|
|
|
);
|
2003-06-23 06:17:35 +00:00
|
|
|
}
|
2009-04-24 07:50:45 +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 ) {
|
2018-05-11 08:55:59 +00:00
|
|
|
$this->oouiEnabled = static::isOouiEnabled( $this->getContext() );
|
|
|
|
|
|
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
|
|
|
|
2013-11-08 20:00:00 +00:00
|
|
|
$this->requireLogin( '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-05-01 13:59:29 +00:00
|
|
|
if ( $this->oouiEnabled ) {
|
|
|
|
|
$out->addModules( 'mediawiki.special.preferences.ooui' );
|
|
|
|
|
$out->addModuleStyles( 'mediawiki.special.preferences.styles.ooui' );
|
2018-04-23 11:56:13 +00:00
|
|
|
$out->addModuleStyles( 'oojs-ui-widgets.styles' );
|
2018-05-01 13:59:29 +00:00
|
|
|
} else {
|
|
|
|
|
$out->addModules( 'mediawiki.special.preferences' );
|
|
|
|
|
$out->addModuleStyles( 'mediawiki.special.preferences.styles' );
|
|
|
|
|
}
|
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(
|
2015-08-02 00:03:57 +00:00
|
|
|
Html::rawElement(
|
2015-06-07 00:51:41 +00:00
|
|
|
'div',
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2015-10-14 17:20:28 +00:00
|
|
|
'class' => 'mw-preferences-messagebox mw-notify-success successbox',
|
|
|
|
|
'id' => 'mw-preferences-success',
|
|
|
|
|
'data-mw-autohide' => 'false',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2015-10-14 17:20:28 +00:00
|
|
|
Html::element( 'p', [], $this->msg( 'savedprefs' )->text() )
|
|
|
|
|
)
|
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
|
|
|
|
2015-12-13 04:35:22 +00:00
|
|
|
// Load the user from the master 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-05-01 13:59:29 +00:00
|
|
|
if ( $this->oouiEnabled ) {
|
|
|
|
|
$prefTabs = [];
|
|
|
|
|
foreach ( $sectionTitles as $key ) {
|
|
|
|
|
$prefTabs[] = [
|
|
|
|
|
'name' => $key,
|
|
|
|
|
'label' => $htmlForm->getLegend( $key ),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
$out->addJsConfigVars( 'wgPreferencesTabs', $prefTabs );
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
$prefTabs = '';
|
|
|
|
|
foreach ( $sectionTitles as $key ) {
|
|
|
|
|
$prefTabs .= Html::rawElement( 'li',
|
2017-12-02 21:15:35 +00:00
|
|
|
[
|
2018-05-01 13:59:29 +00:00
|
|
|
'role' => 'presentation',
|
|
|
|
|
'class' => ( $key === 'personal' ) ? 'selected' : null
|
2017-12-02 21:15:35 +00:00
|
|
|
],
|
2018-09-03 19:21:42 +00:00
|
|
|
Html::element( 'a',
|
2018-05-01 13:59:29 +00:00
|
|
|
[
|
|
|
|
|
'id' => 'preftab-' . $key,
|
|
|
|
|
'role' => 'tab',
|
|
|
|
|
'href' => '#mw-prefsection-' . $key,
|
|
|
|
|
'aria-controls' => 'mw-prefsection-' . $key,
|
|
|
|
|
'aria-selected' => ( $key === 'personal' ) ? 'true' : 'false',
|
|
|
|
|
'tabIndex' => ( $key === 'personal' ) ? 0 : -1,
|
|
|
|
|
],
|
|
|
|
|
$htmlForm->getLegend( $key )
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$out->addHTML(
|
|
|
|
|
Html::rawElement( 'ul',
|
|
|
|
|
[
|
|
|
|
|
'id' => 'preftoc',
|
|
|
|
|
'role' => 'tablist'
|
|
|
|
|
],
|
|
|
|
|
$prefTabs )
|
2017-12-02 21:15:35 +00:00
|
|
|
);
|
2015-11-01 00:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
2018-05-03 13:17:41 +00:00
|
|
|
$htmlForm->addHiddenField( 'ooui', $this->oouiEnabled ? '1' : '0' );
|
|
|
|
|
|
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.
|
|
|
|
|
* @param User $user The user.
|
|
|
|
|
* @param IContextSource $context The context.
|
2018-05-29 20:24:40 +00:00
|
|
|
* @return PreferencesFormLegacy|HTMLForm
|
2017-08-10 17:15:16 +00:00
|
|
|
*/
|
|
|
|
|
protected function getFormObject( $user, IContextSource $context ) {
|
2017-11-07 03:10:14 +00:00
|
|
|
$preferencesFactory = MediaWikiServices::getInstance()->getPreferencesFactory();
|
2018-05-01 13:59:29 +00:00
|
|
|
if ( $this->oouiEnabled ) {
|
|
|
|
|
$form = $preferencesFactory->getForm( $user, $context, PreferencesFormOOUI::class );
|
|
|
|
|
} else {
|
|
|
|
|
$form = $preferencesFactory->getForm( $user, $context, PreferencesFormLegacy::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() {
|
2013-06-10 19:30:43 +00:00
|
|
|
if ( !$this->getUser()->isAllowed( 'editmyoptions' ) ) {
|
|
|
|
|
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
|
|
|
|
2013-09-27 20:52:44 +00:00
|
|
|
$context = new DerivativeContext( $this->getContext() );
|
2013-12-24 08:07:04 +00:00
|
|
|
$context->setTitle( $this->getPageTitle( 'reset' ) ); // Reset subpage
|
2018-05-30 15:34:51 +00:00
|
|
|
$htmlForm = HTMLForm::factory( 'ooui', [], $context, 'prefs-restore' );
|
2009-04-24 07:50:45 +00:00
|
|
|
|
2012-03-19 17:09:23 +00:00
|
|
|
$htmlForm->setSubmitTextMsg( 'restoreprefs' );
|
2014-09-01 19:36:06 +00:00
|
|
|
$htmlForm->setSubmitDestructive();
|
2016-02-17 09:09:32 +00:00
|
|
|
$htmlForm->setSubmitCallback( [ $this, 'submitReset' ] );
|
2009-04-24 01:31:17 +00:00
|
|
|
$htmlForm->suppressReset();
|
2009-04-24 07:50:45 +00:00
|
|
|
|
2009-04-24 01:31:17 +00:00
|
|
|
$htmlForm->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 ) {
|
2013-06-10 19:30:43 +00:00
|
|
|
if ( !$this->getUser()->isAllowed( 'editmyoptions' ) ) {
|
|
|
|
|
throw new PermissionsError( 'editmyoptions' );
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-22 04:17:36 +00:00
|
|
|
$user = $this->getUser()->getInstanceForUpdate();
|
2013-10-12 20:48:26 +00:00
|
|
|
$user->resetOptions( 'all', $this->getContext() );
|
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() {
|
|
|
|
|
return 'users';
|
|
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|