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
|
|
|
|
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 {
|
|
|
|
|
function __construct() {
|
|
|
|
|
parent::__construct( 'Preferences' );
|
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 ) {
|
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
|
|
|
|
2011-08-22 18:32:48 +00:00
|
|
|
$out->addModules( 'mediawiki.special.preferences' );
|
2015-11-01 00:34:46 +00:00
|
|
|
$out->addModuleStyles( 'mediawiki.special.preferences.styles' );
|
2007-10-12 10:27:57 +00:00
|
|
|
|
2016-01-09 22:41:46 +00:00
|
|
|
$request = $this->getRequest();
|
|
|
|
|
if ( $request->getSessionData( 'specialPreferencesSaveSuccess' ) ) {
|
|
|
|
|
// Remove session data for the success message
|
|
|
|
|
$request->setSessionData( 'specialPreferencesSaveSuccess', null );
|
|
|
|
|
|
2011-08-22 18:32:48 +00:00
|
|
|
$out->wrapWikiMsg(
|
2015-08-02 00:03:57 +00:00
|
|
|
Html::rawElement(
|
2015-06-07 00:51:41 +00:00
|
|
|
'div',
|
2015-08-02 00:03:57 +00:00
|
|
|
array(
|
|
|
|
|
'class' => 'mw-preferences-messagebox successbox',
|
|
|
|
|
'id' => 'mw-preferences-success'
|
|
|
|
|
),
|
|
|
|
|
Html::element( 'p', array(), '$1' )
|
2015-06-07 00:51:41 +00:00
|
|
|
),
|
2009-04-24 01:31:17 +00:00
|
|
|
'savedprefs'
|
|
|
|
|
);
|
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)
|
|
|
|
|
$user = $this->getUser()->getInstanceForUpdate() ?: $this->getUser();
|
|
|
|
|
|
|
|
|
|
$htmlForm = Preferences::getFormObject( $user, $this->getContext() );
|
2009-04-27 14:07:13 +00:00
|
|
|
$htmlForm->setSubmitCallback( array( 'Preferences', 'tryUISubmit' ) );
|
2015-11-01 00:34:46 +00:00
|
|
|
$sectionTitles = $htmlForm->getPreferenceSections();
|
2005-08-19 13:27:32 +00:00
|
|
|
|
2015-11-01 00:34:46 +00:00
|
|
|
$prefTabs = '';
|
|
|
|
|
foreach ( $sectionTitles as $key ) {
|
|
|
|
|
$prefTabs .= Html::rawElement( 'li',
|
|
|
|
|
array(
|
|
|
|
|
'role' => 'presentation',
|
|
|
|
|
'class' => ( $key === 'personal' ) ? 'selected' : null
|
|
|
|
|
),
|
|
|
|
|
Html::rawElement( 'a',
|
|
|
|
|
array(
|
|
|
|
|
'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',
|
|
|
|
|
array(
|
|
|
|
|
'id' => 'preftoc',
|
|
|
|
|
'role' => 'tablist'
|
|
|
|
|
),
|
|
|
|
|
$prefTabs )
|
|
|
|
|
);
|
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
|
|
|
|
2011-08-22 18:32:48 +00:00
|
|
|
private 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
|
2013-09-27 20:52:44 +00:00
|
|
|
$htmlForm = new HTMLForm( array(), $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();
|
2011-08-22 18:32:48 +00:00
|
|
|
$htmlForm->setSubmitCallback( array( $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
|
|
|
|
|
$this->getRequest()->setSessionData( 'specialPreferencesSaveSuccess', 1 );
|
2009-04-24 07:50:45 +00:00
|
|
|
|
2016-01-09 22:41:46 +00:00
|
|
|
$url = $this->getPageTitle()->getFullURL();
|
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
|
|
|
}
|