3a5adbb07f742d68dad5d9645b105a9f62210c5c
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] );
117 protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) {
118 // to get a user visible effect, wrap the fieldset into a framed panel layout
120 // Mimic TabPanelLayout
121 $wrapper = new OOUI\
PanelLayout( [
123 'scrollable' => true,
124 // Framed and padded for no-JS, frame hidden with CSS
126 'infusable' => false,
127 'classes' => [ 'oo-ui-stackLayout oo-ui-indexLayout-stackLayout' ]
129 $layout = new OOUI\
PanelLayout( [
131 'scrollable' => true,
132 'infusable' => false,
133 'classes' => [ 'oo-ui-tabPanelLayout' ]
135 $wrapper->appendContent( $layout );
137 $wrapper = $layout = new OOUI\
PanelLayout( [
141 'infusable' => false,
145 $layout->appendContent(
146 new OOUI\
FieldsetLayout( [
148 'infusable' => false,
151 'content' => new OOUI\
HtmlSnippet( $section )
160 * Get the whole body of the form.
164 // Construct fake tabs to avoid FOUC. The structure mimics OOUI's tabPanelLayout.
165 // TODO: Consider creating an infusable TabPanelLayout in OOUI-PHP.
167 foreach ( $this->getPreferenceSections() as $i => $key ) {
173 'oo-ui-widget oo-ui-widget-enabled oo-ui-optionWidget '.
174 'oo-ui-tabOptionWidget oo-ui-labelElement' .
175 ( $i === 0 ?
' oo-ui-optionWidget-selected' : '' )
180 'class' => 'oo-ui-labelElement-label',
181 // Make this a usable link instead of a span so the tabs
182 // can be used before JS runs
183 'href' => '#mw-prefsection-' . $key
185 $this->getLegend( $key )
189 $fakeTabsHtml = Html
::rawElement(
191 [ 'class' => 'oo-ui-layout oo-ui-panelLayout oo-ui-indexLayout-tabPanel' ],
194 [ 'class' => 'oo-ui-widget oo-ui-widget-enabled oo-ui-selectWidget '.
195 'oo-ui-selectWidget-depressed oo-ui-tabSelectWidget' ],
200 return Html
::rawElement(
202 [ 'class' => 'oo-ui-layout oo-ui-panelLayout oo-ui-panelLayout-framed mw-prefs-faketabs' ],
205 [ 'class' => 'oo-ui-layout oo-ui-menuLayout oo-ui-menuLayout-static ' .
206 'oo-ui-menuLayout-top oo-ui-menuLayout-showMenu oo-ui-indexLayout' ],
209 [ 'class' => 'oo-ui-menuLayout-menu' ],
214 [ 'class' => 'oo-ui-menuLayout-content' ],
215 $this->displaySection( $this->mFieldTree
, '', 'mw-prefsection-' )
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 array of section keys
237 function getPreferenceSections() {
238 return array_keys( array_filter( $this->mFieldTree
, 'is_array' ) );