3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
21 use MediaWiki\MediaWikiServices
;
24 * Form to edit user preferences.
26 class PreferencesFormLegacy
extends HTMLForm
implements PreferencesForm
{
27 // Override default value from HTMLForm
28 protected $mSubSectionBeforeFields = false;
30 private $modifiedUser;
35 public function setModifiedUser( $user ) {
36 $this->modifiedUser
= $user;
42 public function getModifiedUser() {
43 if ( $this->modifiedUser
=== null ) {
44 return $this->getUser();
46 return $this->modifiedUser
;
51 * Get extra parameters for the query string when redirecting after
56 public function getExtraSuccessRedirectParameters() {
64 function wrapForm( $html ) {
65 $html = Xml
::tags( 'div', [ 'id' => 'preferences' ], $html );
67 return parent
::wrapForm( $html );
73 function getButtons() {
74 $attrs = [ 'id' => 'mw-prefs-restoreprefs' ];
76 if ( !$this->getModifiedUser()->isAllowedAny( 'editmyprivateinfo', 'editmyoptions' ) ) {
80 $html = parent
::getButtons();
82 if ( $this->getModifiedUser()->isAllowed( 'editmyoptions' ) ) {
83 $t = $this->getTitle()->getSubpage( 'reset' );
85 $linkRenderer = MediaWikiServices
::getInstance()->getLinkRenderer();
86 $html .= "\n" . $linkRenderer->makeLink( $t, $this->msg( 'restoreprefs' )->text(),
87 Html
::buttonAttributes( $attrs, [ 'mw-ui-quiet' ] ) );
89 $html = Xml
::tags( 'div', [ 'class' => 'mw-prefs-buttons' ], $html );
96 * Separate multi-option preferences into multiple preferences, since we
97 * have to store them separately
101 function filterDataForSubmit( $data ) {
102 foreach ( $this->mFlatFields
as $fieldname => $field ) {
103 if ( $field instanceof HTMLNestedFilterable
) {
104 $info = $field->mParams
;
105 $prefix = isset( $info['prefix'] ) ?
$info['prefix'] : $fieldname;
106 foreach ( $field->filterDataForSubmit( $data[$fieldname] ) as $key => $value ) {
107 $data["$prefix$key"] = $value;
109 unset( $data[$fieldname] );
117 * Get the whole body of the form.
121 return $this->displaySection( $this->mFieldTree
, '', 'mw-prefsection-' );
125 * Get the "<legend>" for a given section key. Normally this is the
126 * prefs-$key message but we'll allow extensions to override it.
130 function getLegend( $key ) {
131 $legend = parent
::getLegend( $key );
132 Hooks
::run( 'PreferencesGetLegend', [ $this, $key, &$legend ] );
137 * Get the keys of each top level preference section.
138 * @return array of section keys
140 function getPreferenceSections() {
141 return array_keys( array_filter( $this->mFieldTree
, 'is_array' ) );