a781254352683b426a9a972767ed04d21787ec45
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
22 * Form to edit user preferences.
24 class PreferencesFormOOUI
extends OOUIHTMLForm
implements PreferencesForm
{
25 // Override default value from HTMLForm
26 protected $mSubSectionBeforeFields = false;
28 private $modifiedUser;
33 public function setModifiedUser( $user ) {
34 $this->modifiedUser
= $user;
40 public function getModifiedUser() {
41 if ( $this->modifiedUser
=== null ) {
42 return $this->getUser();
44 return $this->modifiedUser
;
49 * Get extra parameters for the query string when redirecting after
54 public function getExtraSuccessRedirectParameters() {
62 function wrapForm( $html ) {
63 $html = Xml
::tags( 'div', [ 'id' => 'preferences' ], $html );
65 return parent
::wrapForm( $html );
71 function getButtons() {
72 if ( !$this->getModifiedUser()->isAllowedAny( 'editmyprivateinfo', 'editmyoptions' ) ) {
76 $html = parent
::getButtons();
78 if ( $this->getModifiedUser()->isAllowed( 'editmyoptions' ) ) {
79 $t = $this->getTitle()->getSubpage( 'reset' );
81 $html .= new OOUI\
ButtonWidget( [
83 'id' => 'mw-prefs-restoreprefs',
84 'label' => $this->msg( 'restoreprefs' )->text(),
85 'href' => $t->getLinkURL(),
86 'flags' => [ 'destructive' ],
90 $html = Xml
::tags( 'div', [ 'class' => 'mw-prefs-buttons' ], $html );
97 * Separate multi-option preferences into multiple preferences, since we
98 * have to store them separately
102 function filterDataForSubmit( $data ) {
103 foreach ( $this->mFlatFields
as $fieldname => $field ) {
104 if ( $field instanceof HTMLNestedFilterable
) {
105 $info = $field->mParams
;
106 $prefix = isset( $info['prefix'] ) ?
$info['prefix'] : $fieldname;
107 foreach ( $field->filterDataForSubmit( $data[$fieldname] ) as $key => $value ) {
108 $data["$prefix$key"] = $value;
110 unset( $data[$fieldname] );
118 * Get the whole body of the form.
122 return $this->displaySection( $this->mFieldTree
, '', 'mw-prefsection-' );
126 * Get the "<legend>" for a given section key. Normally this is the
127 * prefs-$key message but we'll allow extensions to override it.
131 function getLegend( $key ) {
132 $legend = parent
::getLegend( $key );
133 Hooks
::run( 'PreferencesGetLegend', [ $this, $key, &$legend ] );
138 * Get the keys of each top level preference section.
139 * @return array of section keys
141 function getPreferenceSections() {
142 return array_keys( array_filter( $this->mFieldTree
, 'is_array' ) );