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.
28 class PreferencesFormLegacy
extends HTMLForm
{
29 // Override default value from HTMLForm
30 protected $mSubSectionBeforeFields = false;
32 private $modifiedUser;
37 public function setModifiedUser( $user ) {
38 $this->modifiedUser
= $user;
44 public function getModifiedUser() {
45 if ( $this->modifiedUser
=== null ) {
46 return $this->getUser();
48 return $this->modifiedUser
;
53 * Get extra parameters for the query string when redirecting after
58 public function getExtraSuccessRedirectParameters() {
66 function wrapForm( $html ) {
67 $html = Xml
::tags( 'div', [ 'id' => 'preferences' ], $html );
69 return parent
::wrapForm( $html );
75 function getButtons() {
76 $attrs = [ 'id' => 'mw-prefs-restoreprefs' ];
78 if ( !$this->getModifiedUser()->isAllowedAny( 'editmyprivateinfo', 'editmyoptions' ) ) {
82 $html = parent
::getButtons();
84 if ( $this->getModifiedUser()->isAllowed( 'editmyoptions' ) ) {
85 $t = $this->getTitle()->getSubpage( 'reset' );
87 $linkRenderer = MediaWikiServices
::getInstance()->getLinkRenderer();
88 $html .= "\n" . $linkRenderer->makeLink( $t, $this->msg( 'restoreprefs' )->text(),
89 Html
::buttonAttributes( $attrs, [ 'mw-ui-quiet' ] ) );
91 $html = Xml
::tags( 'div', [ 'class' => 'mw-prefs-buttons' ], $html );
98 * Separate multi-option preferences into multiple preferences, since we
99 * have to store them separately
103 function filterDataForSubmit( $data ) {
104 foreach ( $this->mFlatFields
as $fieldname => $field ) {
105 if ( $field instanceof HTMLNestedFilterable
) {
106 $info = $field->mParams
;
107 $prefix = isset( $info['prefix'] ) ?
$info['prefix'] : $fieldname;
108 foreach ( $field->filterDataForSubmit( $data[$fieldname] ) as $key => $value ) {
109 $data["$prefix$key"] = $value;
111 unset( $data[$fieldname] );
119 * Get the whole body of the form.
123 return $this->displaySection( $this->mFieldTree
, '', 'mw-prefsection-' );
127 * Get the "<legend>" for a given section key. Normally this is the
128 * prefs-$key message but we'll allow extensions to override it.
132 function getLegend( $key ) {
133 $legend = parent
::getLegend( $key );
134 Hooks
::run( 'PreferencesGetLegend', [ $this, $key, &$legend ] );
139 * Get the keys of each top level preference section.
140 * @return array of section keys
142 function getPreferenceSections() {
143 return array_keys( array_filter( $this->mFieldTree
, 'is_array' ) );
147 // Retain the old class name for backwards compatibility.
148 // In the future, this alias will be changed to point to PreferencesFormOOUI.
149 class PreferencesForm
extends PreferencesFormLegacy
{
151 // Phan doesn't understand class_alias()?
152 // class_alias( PreferencesFormLegacy::class, 'PreferencesForm' );