35 protected $mSubSectionBeforeFields =
false;
38 private $modifiedUser;
41 private $privateInfoEditable =
true;
44 private $optionsEditable =
true;
47 private $useMobileLayout;
53 $this->modifiedUser = $user;
60 if ( $this->modifiedUser ===
null ) {
63 return $this->modifiedUser;
71 return $this->privateInfoEditable;
79 $this->privateInfoEditable = $editable;
87 return $this->optionsEditable;
94 $this->optionsEditable = $optionsEditable;
109 $html = Xml::tags(
'div', [
'id' =>
'preferences' ], $html );
111 return parent::wrapForm( $html );
121 foreach ( $this->mFlatFields as $fieldname => $field ) {
123 $info = $field->mParams;
124 $prefix = $info[
'prefix'] ?? $fieldname;
125 foreach ( $field->filterDataForSubmit( $data[$fieldname] ) as $key => $value ) {
126 $data[
"$prefix$key"] = $value;
128 unset( $data[$fieldname] );
136 $layout = parent::wrapFieldSetSection( $legend, $section, $attributes, $isRoot );
138 $layout->addClasses( [
'mw-prefs-fieldset-wrapper' ] );
139 $layout->removeClasses( [
'oo-ui-panelLayout-framed' ] );
144 private function isMobileLayout() {
145 if ( $this->useMobileLayout ===
null ) {
146 $skin = $this->getSkin();
147 $this->useMobileLayout =
false;
148 $this->getHookRunner()->onPreferencesGetLayout( $this->useMobileLayout,
149 $skin->getSkinName(), [
'isResponsive' => $skin->isResponsive() ] );
151 return $this->useMobileLayout;
159 if ( $this->isMobileLayout() && $this->
getTitle()->isSpecial(
'Preferences' ) ) {
160 foreach ( $descriptor as $_ => &$info ) {
161 if ( isset( $info[
'type'] ) && in_array( $info[
'type'], [
'check',
'toggle' ] ) ) {
162 unset( $info[
'type'] );
163 $info[
'class'] = HTMLToggleSwitchField::class;
164 } elseif ( isset( $info[
'class'] ) && $info[
'class'] === HTMLCheckField::class ) {
165 $info[
'class'] = HTMLToggleSwitchField::class;
169 return parent::addFields( $descriptor );
177 if ( $this->isMobileLayout() ) {
181 'oojs-ui.styles.icons-user',
182 'oojs-ui.styles.icons-editing-core',
183 'oojs-ui.styles.icons-editing-advanced',
184 'oojs-ui.styles.icons-wikimediaui',
185 'oojs-ui.styles.icons-content',
186 'oojs-ui.styles.icons-moderation',
187 'oojs-ui.styles.icons-interactions',
188 'oojs-ui.styles.icons-movement',
189 'oojs-ui.styles.icons-wikimedia',
190 'oojs-ui.styles.icons-media',
191 'oojs-ui.styles.icons-accessibility',
192 'oojs-ui.styles.icons-layout',
195 $form = $this->createMobilePreferencesForm();
197 $form = $this->createDesktopPreferencesForm();
212 $legend = parent::getLegend( $key );
213 $this->getHookRunner()->onPreferencesGetLegend( $this, $key, $legend );
222 return array_keys( array_filter( $this->mFieldTree,
'is_array' ) );
229 private function createMobilePreferencesForm() {
230 $sectionButtons = [];
231 $sectionContents = [];
232 $iconNames = $this->getIconNames();
234 foreach ( $this->mFieldTree as $key => $val ) {
235 if ( !is_array( $val ) ) {
236 wfDebug( __METHOD__ .
" encountered a field not attached to a section: '$key'" );
245 "mw-prefsection-$key-"
250 $label = (
new OOUI\Tag(
'div' ) )->appendContent(
251 (
new OOUI\Tag(
'h5' ) )->appendContent( $label )->addClasses( [
'mw-prefs-title' ] ),
252 $this->createMobileDescription( $key )
254 $contentDiv = $this->createContentMobile( $key, $label, $content );
256 $sectionButton =
new OOUI\ButtonWidget( [
257 'id' =>
'mw-mobile-prefs-' . $key,
258 'icon' => $iconNames[ $key ] ??
'settings',
259 'label' =>
new OOUI\HtmlSnippet( $label->toString() ),
261 'classes' => [
'mw-mobile-prefsection' ],
264 $sectionButtons[] = $sectionButton;
265 $sectionContents[] = $contentDiv;
268 $buttonGroup =
new OOUI\ButtonGroupWidget( [
269 'classes' => [
'mw-mobile-prefs-sections' ],
272 $buttonGroup->addItems( $sectionButtons );
273 $form = (
new OOUI\Tag(
'div' ) )
274 ->setAttributes( [
'id' =>
'mw-prefs-container' ] )
275 ->addClasses( [
'mw-mobile-prefs-container' ] )
276 ->appendContent( $buttonGroup )
277 ->appendContent( $sectionContents );
286 private function getIconNames() {
288 'personal' =>
'userAvatar',
289 'rendering' =>
'palette',
291 'rc' =>
'recentChanges',
292 'watchlist' =>
'watchlist',
293 'searchoptions' =>
'search',
298 $this->getHookRunner()->onPreferencesGetIcon( $hookIcons );
299 $iconNames += $hookIcons;
309 private function createMobileDescription( $key ) {
310 $prefDescriptionMsg = $this->
msg(
"prefs-description-" . $key );
311 $prefDescription = $prefDescriptionMsg->exists() ? $prefDescriptionMsg->text() :
"";
312 $prefDescriptionElement = (
new OOUI\Tag(
'p' ) )
313 ->appendContent( $prefDescription )
314 ->addClasses( [
'mw-prefs-description' ] );
316 return $prefDescriptionElement;
326 private function createContentMobile( $key, $label, $content ) {
327 $contentDiv = (
new OOUI\Tag(
'div' ) );
328 $contentDiv->addClasses( [
329 'mw-prefs-content-page',
330 'mw-prefs-section-fieldset',
332 $contentDiv->setAttributes( [
333 'id' =>
'mw-mobile-prefs-' . $key
335 $contentBody = (
new OOUI\Tag(
'div' ) )
336 ->addClasses( [
'mw-htmlform-autoinfuse-lazy' ] )
338 'id' =>
'mw-mobile-prefs-' . $key .
'-content'
340 $contentHeader = (
new OOUI\Tag(
'div' ) )->setAttributes( [
341 'id' =>
'mw-mobile-prefs-' . $key .
'-head'
343 $contentHeader->addClasses( [
'mw-prefs-content-head' ] );
344 $contentHeaderTitle = (
new OOUI\Tag(
'h5' ) )->setAttributes( [
345 'id' =>
'mw-mobile-prefs-' . $key .
'-title',
347 $contentHeaderTitle->appendContent( $label )->addClasses( [
'mw-prefs-header-title' ] );
348 $formContent =
new OOUI\Widget( [
349 'content' =>
new OOUI\HtmlSnippet( $content )
351 $hiddenForm = (
new OOUI\Tag(
'div' ) )->appendContent( $formContent );
352 $contentHeader->appendContent( $contentHeaderTitle );
353 $contentBody->appendContent( $contentHeader );
354 $contentBody->appendContent( $hiddenForm );
355 $contentDiv->appendContent( $contentBody );
364 private function createDesktopPreferencesForm() {
366 foreach ( $this->mFieldTree as $key => $val ) {
367 if ( !is_array( $val ) ) {
368 wfDebug( __METHOD__ .
" encountered a field not attached to a section: '$key'" );
377 "mw-prefsection-$key-"
381 $tabPanels[] =
new OOUI\TabPanelLayout(
'mw-prefsection-' . $key, [
382 'classes' => [
'mw-htmlform-autoinfuse-lazy' ],
384 'content' =>
new OOUI\FieldsetLayout( [
385 'classes' => [
'mw-prefs-section-fieldset' ],
386 'id' =>
"mw-prefsection-$key",
390 'content' =>
new OOUI\HtmlSnippet( $content )
399 $indexLayout =
new OOUI\IndexLayout( [
402 'autoFocus' =>
false,
403 'classes' => [
'mw-prefs-tabs' ],
405 $indexLayout->addTabPanels( $tabPanels );
407 $form =
new OOUI\PanelLayout( [
410 'classes' => [
'mw-prefs-tabs-wrapper' ],
411 'content' => $indexLayout
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.