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.
26 class PreferencesFormOOUI
extends OOUIHTMLForm
{
27 // Override default value from HTMLForm
28 protected $mSubSectionBeforeFields = false;
31 private $modifiedUser;
34 private $privateInfoEditable = true;
37 private $optionsEditable = true;
42 public function setModifiedUser( $user ) {
43 $this->modifiedUser
= $user;
49 public function getModifiedUser() {
50 if ( $this->modifiedUser
=== null ) {
51 return $this->getUser();
53 return $this->modifiedUser
;
60 public function isPrivateInfoEditable() {
61 return $this->privateInfoEditable
;
66 * @param bool $editable
68 public function setPrivateInfoEditable( $editable ) {
69 $this->privateInfoEditable
= $editable;
75 public function areOptionsEditable() {
76 return $this->optionsEditable
;
80 * @param bool $optionsEditable
82 public function setOptionsEditable( $optionsEditable ) {
83 $this->optionsEditable
= $optionsEditable;
87 * Get extra parameters for the query string when redirecting after
92 public function getExtraSuccessRedirectParameters() {
100 function wrapForm( $html ) {
101 $html = Xml
::tags( 'div', [ 'id' => 'preferences' ], $html );
103 return parent
::wrapForm( $html );
109 function getButtons() {
110 if ( !$this->areOptionsEditable() && !$this->isPrivateInfoEditable() ) {
114 $html = parent
::getButtons();
116 if ( $this->areOptionsEditable() ) {
117 $t = $this->getTitle()->getSubpage( 'reset' );
119 $html .= new OOUI\
ButtonWidget( [
121 'id' => 'mw-prefs-restoreprefs',
122 'label' => $this->msg( 'restoreprefs' )->text(),
123 'href' => $t->getLinkURL(),
124 'flags' => [ 'destructive' ],
128 $html = Xml
::tags( 'div', [ 'class' => 'mw-prefs-buttons' ], $html );
135 * Separate multi-option preferences into multiple preferences, since we
136 * have to store them separately
140 function filterDataForSubmit( $data ) {
141 foreach ( $this->mFlatFields
as $fieldname => $field ) {
142 if ( $field instanceof HTMLNestedFilterable
) {
143 // @phan-suppress-next-next-line PhanUndeclaredProperty All HTMLForm fields have mParams,
144 // but the instanceof confuses phan, which doesn't support intersections
145 $info = $field->mParams
;
146 $prefix = $info['prefix'] ??
$fieldname;
147 foreach ( $field->filterDataForSubmit( $data[$fieldname] ) as $key => $value ) {
148 $data["$prefix$key"] = $value;
150 unset( $data[$fieldname] );
157 protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) {
158 $layout = parent
::wrapFieldSetSection( $legend, $section, $attributes, $isRoot );
160 $layout->addClasses( [ 'mw-prefs-fieldset-wrapper' ] );
161 $layout->removeClasses( [ 'oo-ui-panelLayout-framed' ] );
167 * Get the whole body of the form.
172 foreach ( $this->mFieldTree
as $key => $val ) {
173 if ( !is_array( $val ) ) {
174 wfDebug( __METHOD__
. " encountered a field not attached to a section: '$key'" );
177 $label = $this->getLegend( $key );
179 $this->getHeaderText( $key ) .
180 $this->displaySection(
181 $this->mFieldTree
[$key],
183 "mw-prefsection-$key-"
185 $this->getFooterText( $key );
187 $tabPanels[] = new OOUI\
TabPanelLayout( 'mw-prefsection-' . $key, [
188 'classes' => [ 'mw-htmlform-autoinfuse-lazy' ],
190 'content' => new OOUI\
FieldsetLayout( [
191 'classes' => [ 'mw-prefs-section-fieldset' ],
192 'id' => "mw-prefsection-$key",
196 'content' => new OOUI\
HtmlSnippet( $content )
205 $indexLayout = new OOUI\
IndexLayout( [
208 'autoFocus' => false,
209 'classes' => [ 'mw-prefs-tabs' ],
211 $indexLayout->addTabPanels( $tabPanels );
213 return new OOUI\
PanelLayout( [
216 'classes' => [ 'mw-prefs-tabs-wrapper' ],
217 'content' => $indexLayout
222 * Get the "<legend>" for a given section key. Normally this is the
223 * prefs-$key message but we'll allow extensions to override it.
227 function getLegend( $key ) {
228 $legend = parent
::getLegend( $key );
229 Hooks
::run( 'PreferencesGetLegend', [ $this, $key, &$legend ] );
234 * Get the keys of each top level preference section.
235 * @return string[] List of section keys
237 function getPreferenceSections() {
238 return array_keys( array_filter( $this->mFieldTree
, 'is_array' ) );