34 protected $mSubSectionBeforeFields =
false;
37 private $modifiedUser;
40 private $privateInfoEditable =
true;
43 private $optionsEditable =
true;
46 private $useMobileLayout;
52 $this->modifiedUser = $user;
59 if ( $this->modifiedUser ===
null ) {
62 return $this->modifiedUser;
70 return $this->privateInfoEditable;
78 $this->privateInfoEditable = $editable;
86 return $this->optionsEditable;
93 $this->optionsEditable = $optionsEditable;
108 $html = Xml::tags(
'div', [
'id' =>
'preferences' ], $html );
110 return parent::wrapForm( $html );
120 foreach ( $this->mFlatFields as $fieldname => $field ) {
122 $info = $field->mParams;
123 $prefix = $info[
'prefix'] ?? $fieldname;
124 foreach ( $field->filterDataForSubmit( $data[$fieldname] ) as $key => $value ) {
125 $data[
"$prefix$key"] = $value;
127 unset( $data[$fieldname] );
135 $layout = parent::wrapFieldSetSection( $legend, $section, $attributes, $isRoot );
137 $layout->addClasses( [
'mw-prefs-fieldset-wrapper' ] );
138 $layout->removeClasses( [
'oo-ui-panelLayout-framed' ] );
143 private function isMobileLayout() {
144 if ( $this->useMobileLayout ===
null ) {
145 $skin = $this->getSkin();
146 $this->useMobileLayout =
false;
147 $this->getHookRunner()->onPreferencesGetLayout( $this->useMobileLayout,
148 $skin->getSkinName(), [
'isResponsive' => $skin->isResponsive() ] );
150 return $this->useMobileLayout;
158 if ( $this->isMobileLayout() && $this->
getTitle()->isSpecial(
'Preferences' ) ) {
159 foreach ( $descriptor as $_ => &$info ) {
160 if ( isset( $info[
'type'] ) && in_array( $info[
'type'], [
'check',
'toggle' ] ) ) {
161 unset( $info[
'type'] );
162 $info[
'class'] = HTMLToggleSwitchField::class;
163 } elseif ( isset( $info[
'class'] ) && $info[
'class'] === HTMLCheckField::class ) {
164 $info[
'class'] = HTMLToggleSwitchField::class;
168 return parent::addFields( $descriptor );
176 if ( $this->isMobileLayout() ) {
180 'oojs-ui.styles.icons-user',
181 'oojs-ui.styles.icons-editing-core',
182 'oojs-ui.styles.icons-editing-advanced',
183 'oojs-ui.styles.icons-wikimediaui',
184 'oojs-ui.styles.icons-content',
185 'oojs-ui.styles.icons-moderation',
186 'oojs-ui.styles.icons-interactions',
187 'oojs-ui.styles.icons-movement',
188 'oojs-ui.styles.icons-wikimedia',
189 'oojs-ui.styles.icons-media',
190 'oojs-ui.styles.icons-accessibility',
191 'oojs-ui.styles.icons-layout',
194 $form = $this->createMobilePreferencesForm();
196 $form = $this->createDesktopPreferencesForm();
211 $legend = parent::getLegend( $key );
212 $this->getHookRunner()->onPreferencesGetLegend( $this, $key, $legend );
221 return array_keys( array_filter( $this->mFieldTree,
'is_array' ) );
228 private function createMobilePreferencesForm() {
229 $sectionButtons = [];
230 $sectionContents = [];
231 $iconNames = $this->getIconNames();
233 foreach ( $this->mFieldTree as $key => $val ) {
234 if ( !is_array( $val ) ) {
235 wfDebug( __METHOD__ .
" encountered a field not attached to a section: '$key'" );
244 "mw-prefsection-$key-"
249 $label = (
new OOUI\Tag(
'div' ) )->appendContent(
250 (
new OOUI\Tag(
'h5' ) )->appendContent( $label )->addClasses( [
'mw-prefs-title' ] ),
251 $this->createMobileDescription( $key )
253 $contentDiv = $this->createContentMobile( $key, $label, $content );
255 $sectionButton =
new OOUI\ButtonWidget( [
256 'id' =>
'mw-mobile-prefs-' . $key,
257 'icon' => $iconNames[ $key ] ??
'settings',
258 'label' =>
new OOUI\HtmlSnippet( $label->toString() ),
260 'classes' => [
'mw-mobile-prefsection' ],
263 $sectionButtons[] = $sectionButton;
264 $sectionContents[] = $contentDiv;
267 $buttonGroup =
new OOUI\ButtonGroupWidget( [
268 'classes' => [
'mw-mobile-prefs-sections' ],
271 $buttonGroup->addItems( $sectionButtons );
272 $form = (
new OOUI\Tag(
'div' ) )
273 ->setAttributes( [
'id' =>
'mw-prefs-container' ] )
274 ->addClasses( [
'mw-mobile-prefs-container' ] )
275 ->appendContent( $buttonGroup )
276 ->appendContent( $sectionContents );
285 private function getIconNames() {
287 'personal' =>
'userAvatar',
288 'rendering' =>
'palette',
290 'rc' =>
'recentChanges',
291 'watchlist' =>
'watchlist',
292 'searchoptions' =>
'search',
297 $this->getHookRunner()->onPreferencesGetIcon( $hookIcons );
298 $iconNames += $hookIcons;
308 private function createMobileDescription( $key ) {
309 $prefDescriptionMsg = $this->
msg(
"prefs-description-" . $key );
310 $prefDescription = $prefDescriptionMsg->exists() ? $prefDescriptionMsg->text() :
"";
311 $prefDescriptionElement = (
new OOUI\Tag(
'p' ) )
312 ->appendContent( $prefDescription )
313 ->addClasses( [
'mw-prefs-description' ] );
315 return $prefDescriptionElement;
325 private function createContentMobile( $key, $label, $content ) {
326 $contentDiv = (
new OOUI\Tag(
'div' ) );
327 $contentDiv->addClasses( [
328 'mw-prefs-content-page',
329 'mw-prefs-section-fieldset',
331 $contentDiv->setAttributes( [
332 'id' =>
'mw-mobile-prefs-' . $key
334 $contentBody = (
new OOUI\Tag(
'div' ) )
335 ->addClasses( [
'mw-htmlform-autoinfuse-lazy' ] )
337 'id' =>
'mw-mobile-prefs-' . $key .
'-content'
339 $contentHeader = (
new OOUI\Tag(
'div' ) )->setAttributes( [
340 'id' =>
'mw-mobile-prefs-' . $key .
'-head'
342 $contentHeader->addClasses( [
'mw-prefs-content-head' ] );
343 $contentHeaderTitle = (
new OOUI\Tag(
'h5' ) )->setAttributes( [
344 'id' =>
'mw-mobile-prefs-' . $key .
'-title',
346 $contentHeaderTitle->appendContent( $label )->addClasses( [
'mw-prefs-header-title' ] );
347 $formContent =
new OOUI\Widget( [
348 'content' =>
new OOUI\HtmlSnippet( $content )
350 $hiddenForm = (
new OOUI\Tag(
'div' ) )->appendContent( $formContent );
351 $contentHeader->appendContent( $contentHeaderTitle );
352 $contentBody->appendContent( $contentHeader );
353 $contentBody->appendContent( $hiddenForm );
354 $contentDiv->appendContent( $contentBody );
363 private function createDesktopPreferencesForm() {
365 foreach ( $this->mFieldTree as $key => $val ) {
366 if ( !is_array( $val ) ) {
367 wfDebug( __METHOD__ .
" encountered a field not attached to a section: '$key'" );
376 "mw-prefsection-$key-"
380 $tabPanels[] =
new OOUI\TabPanelLayout(
'mw-prefsection-' . $key, [
381 'classes' => [
'mw-htmlform-autoinfuse-lazy' ],
383 'content' =>
new OOUI\FieldsetLayout( [
384 'classes' => [
'mw-prefs-section-fieldset' ],
385 'id' =>
"mw-prefsection-$key",
389 'content' =>
new OOUI\HtmlSnippet( $content )
398 $indexLayout =
new OOUI\IndexLayout( [
401 'autoFocus' =>
false,
402 'classes' => [
'mw-prefs-tabs' ],
404 $indexLayout->addTabPanels( $tabPanels );
406 $form =
new OOUI\PanelLayout( [
409 'classes' => [
'mw-prefs-tabs-wrapper' ],
410 'content' => $indexLayout
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.