33 private $modifiedUser;
36 private $privateInfoEditable =
true;
39 private $optionsEditable =
true;
42 private $useMobileLayout;
48 $this->modifiedUser = $user;
55 if ( $this->modifiedUser ===
null ) {
58 return $this->modifiedUser;
66 return $this->privateInfoEditable;
74 $this->privateInfoEditable = $editable;
82 return $this->optionsEditable;
89 $this->optionsEditable = $optionsEditable;
104 $html =
Xml::tags(
'div', [
'id' =>
'preferences' ], $html );
106 return parent::wrapForm( $html );
116 foreach ( $this->mFlatFields as $fieldname => $field ) {
118 $info = $field->mParams;
119 $prefix = $info[
'prefix'] ?? $fieldname;
120 foreach ( $field->filterDataForSubmit( $data[$fieldname] ) as $key => $value ) {
121 $data[
"$prefix$key"] = $value;
123 unset( $data[$fieldname] );
131 $layout = parent::wrapFieldSetSection( $legend, $section, $attributes, $isRoot );
133 $layout->addClasses( [
'mw-prefs-fieldset-wrapper' ] );
134 $layout->removeClasses( [
'oo-ui-panelLayout-framed' ] );
139 private function isMobileLayout() {
140 if ( $this->useMobileLayout ===
null ) {
142 $this->useMobileLayout =
false;
143 $this->getHookRunner()->onPreferencesGetLayout( $this->useMobileLayout,
144 $skin->getSkinName(), [
'isResponsive' => $skin->isResponsive() ] );
146 return $this->useMobileLayout;
154 if ( $this->isMobileLayout() && $this->
getTitle()->isSpecial(
'Preferences' ) ) {
155 foreach ( $descriptor as $_ => &$info ) {
156 if ( isset( $info[
'type'] ) && in_array( $info[
'type'], [
'check',
'toggle' ] ) ) {
157 unset( $info[
'type'] );
158 $info[
'class'] = HTMLToggleSwitchField::class;
159 } elseif ( isset( $info[
'class'] ) && $info[
'class'] === HTMLCheckField::class ) {
160 $info[
'class'] = HTMLToggleSwitchField::class;
172 if ( $this->isMobileLayout() ) {
176 'oojs-ui.styles.icons-user',
177 'oojs-ui.styles.icons-editing-core',
178 'oojs-ui.styles.icons-editing-advanced',
179 'oojs-ui.styles.icons-wikimediaui',
180 'oojs-ui.styles.icons-content',
181 'oojs-ui.styles.icons-moderation',
182 'oojs-ui.styles.icons-interactions',
183 'oojs-ui.styles.icons-movement',
184 'oojs-ui.styles.icons-wikimedia',
185 'oojs-ui.styles.icons-media',
186 'oojs-ui.styles.icons-accessibility',
187 'oojs-ui.styles.icons-layout',
190 $form = $this->createMobilePreferencesForm();
192 $form = $this->createDesktopPreferencesForm();
207 $legend = parent::getLegend( $key );
208 $this->getHookRunner()->onPreferencesGetLegend( $this, $key, $legend );
217 return array_keys( array_filter( $this->mFieldTree,
'is_array' ) );
224 private function createMobilePreferencesForm() {
225 $sectionButtons = [];
226 $sectionContents = [];
227 $iconNames = $this->getIconNames();
229 foreach ( $this->mFieldTree as $key => $val ) {
230 if ( !is_array( $val ) ) {
231 wfDebug( __METHOD__ .
" encountered a field not attached to a section: '$key'" );
240 "mw-prefsection-$key-"
245 $label = (
new OOUI\Tag(
'div' ) )->appendContent(
246 (
new OOUI\Tag(
'h5' ) )->appendContent( $label )->addClasses( [
'mw-prefs-title' ] ),
247 $this->createMobileDescription( $key )
249 $contentDiv = $this->createContentMobile( $key, $label,
$content );
251 $sectionButton =
new OOUI\ButtonWidget( [
252 'id' =>
'mw-mobile-prefs-' . $key,
253 'icon' => $iconNames[ $key ] ??
'settings',
254 'label' =>
new OOUI\HtmlSnippet( $label->toString() ),
256 'classes' => [
'mw-mobile-prefsection' ],
259 $sectionButtons[] = $sectionButton;
260 $sectionContents[] = $contentDiv;
263 $buttonGroup =
new OOUI\ButtonGroupWidget( [
264 'classes' => [
'mw-mobile-prefs-sections' ],
267 $buttonGroup->addItems( $sectionButtons );
268 $form = (
new OOUI\Tag(
'div' ) )
269 ->setAttributes( [
'id' =>
'mw-prefs-container' ] )
270 ->addClasses( [
'mw-mobile-prefs-container' ] )
271 ->appendContent( $buttonGroup )
272 ->appendContent( $sectionContents );
281 private function getIconNames() {
283 'personal' =>
'userAvatar',
284 'rendering' =>
'palette',
286 'rc' =>
'recentChanges',
287 'watchlist' =>
'watchlist',
288 'searchoptions' =>
'search',
293 $this->getHookRunner()->onPreferencesGetIcon( $hookIcons );
294 $iconNames += $hookIcons;
304 private function createMobileDescription( $key ) {
305 $prefDescriptionMsg = $this->
msg(
"prefs-description-" . $key );
306 $prefDescription = $prefDescriptionMsg->exists() ? $prefDescriptionMsg->text() :
"";
307 $prefDescriptionElement = (
new OOUI\Tag(
'p' ) )
308 ->appendContent( $prefDescription )
309 ->addClasses( [
'mw-prefs-description' ] );
311 return $prefDescriptionElement;
321 private function createContentMobile( $key, $label,
$content ) {
322 $contentDiv = (
new OOUI\Tag(
'div' ) );
323 $contentDiv->addClasses( [
324 'mw-prefs-content-page',
325 'mw-prefs-section-fieldset',
327 $contentDiv->setAttributes( [
328 'id' =>
'mw-mobile-prefs-' . $key
330 $contentBody = (
new OOUI\Tag(
'div' ) )
331 ->addClasses( [
'mw-htmlform-autoinfuse-lazy' ] )
333 'id' =>
'mw-mobile-prefs-' . $key .
'-content'
335 $contentHeader = (
new OOUI\Tag(
'div' ) )->setAttributes( [
336 'id' =>
'mw-mobile-prefs-' . $key .
'-head'
338 $contentHeader->addClasses( [
'mw-prefs-content-head' ] );
339 $contentHeaderTitle = (
new OOUI\Tag(
'h5' ) )->setAttributes( [
340 'id' =>
'mw-mobile-prefs-' . $key .
'-title',
342 $contentHeaderTitle->appendContent( $label )->addClasses( [
'mw-prefs-header-title' ] );
343 $formContent =
new OOUI\Widget( [
344 'content' =>
new OOUI\HtmlSnippet(
$content )
346 $hiddenForm = (
new OOUI\Tag(
'div' ) )->appendContent( $formContent );
347 $contentHeader->appendContent( $contentHeaderTitle );
348 $contentBody->appendContent( $contentHeader );
349 $contentBody->appendContent( $hiddenForm );
350 $contentDiv->appendContent( $contentBody );
359 private function createDesktopPreferencesForm() {
361 foreach ( $this->mFieldTree as $key => $val ) {
362 if ( !is_array( $val ) ) {
363 wfDebug( __METHOD__ .
" encountered a field not attached to a section: '$key'" );
372 "mw-prefsection-$key-"
376 $tabPanels[] =
new OOUI\TabPanelLayout(
'mw-prefsection-' . $key, [
377 'classes' => [
'mw-htmlform-autoinfuse-lazy' ],
379 'content' =>
new OOUI\FieldsetLayout( [
380 'classes' => [
'mw-prefs-section-fieldset' ],
381 'id' =>
"mw-prefsection-$key",
385 'content' =>
new OOUI\HtmlSnippet(
$content )
394 $indexLayout =
new OOUI\IndexLayout( [
397 'autoFocus' =>
false,
398 'classes' => [
'mw-prefs-tabs' ],
400 $indexLayout->addTabPanels( $tabPanels );
402 $form =
new OOUI\PanelLayout( [
405 'classes' => [
'mw-prefs-tabs-wrapper' ],
406 'content' => $indexLayout
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.