MediaWiki  master
PreferencesFormOOUI.php
Go to the documentation of this file.
1 <?php
28  protected $mSubSectionBeforeFields = false;
29 
31  private $modifiedUser;
32 
34  private $privateInfoEditable = true;
35 
37  private $optionsEditable = true;
38 
42  public function setModifiedUser( $user ) {
43  $this->modifiedUser = $user;
44  }
45 
49  public function getModifiedUser() {
50  if ( $this->modifiedUser === null ) {
51  return $this->getUser();
52  } else {
53  return $this->modifiedUser;
54  }
55  }
56 
60  public function isPrivateInfoEditable() {
62  }
63 
68  public function setPrivateInfoEditable( $editable ) {
69  $this->privateInfoEditable = $editable;
70  }
71 
75  public function areOptionsEditable() {
77  }
78 
82  public function setOptionsEditable( $optionsEditable ) {
83  $this->optionsEditable = $optionsEditable;
84  }
85 
93  return [];
94  }
95 
100  public function wrapForm( $html ) {
101  $html = Xml::tags( 'div', [ 'id' => 'preferences' ], $html );
102 
103  return parent::wrapForm( $html );
104  }
105 
109  public function getButtons() {
110  if ( !$this->areOptionsEditable() && !$this->isPrivateInfoEditable() ) {
111  return '';
112  }
113 
114  $html = parent::getButtons();
115 
116  if ( $this->areOptionsEditable() ) {
117  $t = $this->getTitle()->getSubpage( 'reset' );
118 
119  $html .= new OOUI\ButtonWidget( [
120  'infusable' => true,
121  'id' => 'mw-prefs-restoreprefs',
122  'label' => $this->msg( 'restoreprefs' )->text(),
123  'href' => $t->getLinkURL(),
124  'flags' => [ 'destructive' ],
125  'framed' => false,
126  ] );
127 
128  $html = Xml::tags( 'div', [ 'class' => 'mw-prefs-buttons' ], $html );
129  }
130 
131  return $html;
132  }
133 
140  public function filterDataForSubmit( $data ) {
141  foreach ( $this->mFlatFields as $fieldname => $field ) {
142  if ( $field instanceof HTMLNestedFilterable ) {
143  $info = $field->mParams;
144  $prefix = $info['prefix'] ?? $fieldname;
145  foreach ( $field->filterDataForSubmit( $data[$fieldname] ) as $key => $value ) {
146  $data["$prefix$key"] = $value;
147  }
148  unset( $data[$fieldname] );
149  }
150  }
151 
152  return $data;
153  }
154 
155  protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) {
156  $layout = parent::wrapFieldSetSection( $legend, $section, $attributes, $isRoot );
157 
158  $layout->addClasses( [ 'mw-prefs-fieldset-wrapper' ] );
159  $layout->removeClasses( [ 'oo-ui-panelLayout-framed' ] );
160 
161  return $layout;
162  }
163 
168  public function getBody() {
169  $tabPanels = [];
170  foreach ( $this->mFieldTree as $key => $val ) {
171  if ( !is_array( $val ) ) {
172  wfDebug( __METHOD__ . " encountered a field not attached to a section: '$key'" );
173  continue;
174  }
175  $label = $this->getLegend( $key );
176  $content =
177  $this->getHeaderText( $key ) .
178  $this->displaySection(
179  $val,
180  "",
181  "mw-prefsection-$key-"
182  ) .
183  $this->getFooterText( $key );
184 
185  $tabPanels[] = new OOUI\TabPanelLayout( 'mw-prefsection-' . $key, [
186  'classes' => [ 'mw-htmlform-autoinfuse-lazy' ],
187  'label' => $label,
188  'content' => new OOUI\FieldsetLayout( [
189  'classes' => [ 'mw-prefs-section-fieldset' ],
190  'id' => "mw-prefsection-$key",
191  'label' => $label,
192  'items' => [
193  new OOUI\Widget( [
194  'content' => new OOUI\HtmlSnippet( $content )
195  ] ),
196  ],
197  ] ),
198  'expanded' => false,
199  'framed' => true,
200  ] );
201  }
202 
203  $indexLayout = new OOUI\IndexLayout( [
204  'infusable' => true,
205  'expanded' => false,
206  'autoFocus' => false,
207  'classes' => [ 'mw-prefs-tabs' ],
208  ] );
209  $indexLayout->addTabPanels( $tabPanels );
210 
211  $header = $this->formatFormHeader();
212  $form = new OOUI\PanelLayout( [
213  'framed' => true,
214  'expanded' => false,
215  'classes' => [ 'mw-prefs-tabs-wrapper' ],
216  'content' => $indexLayout
217  ] );
218 
219  return $header . $form;
220  }
221 
228  public function getLegend( $key ) {
229  $legend = parent::getLegend( $key );
230  $this->getHookRunner()->onPreferencesGetLegend( $this, $key, $legend );
231  return $legend;
232  }
233 
238  public function getPreferenceSections() {
239  return array_keys( array_filter( $this->mFieldTree, 'is_array' ) );
240  }
241 }
PreferencesFormOOUI
Form to edit user preferences.
Definition: PreferencesFormOOUI.php:26
PreferencesFormOOUI\getPreferenceSections
getPreferenceSections()
Get the keys of each top level preference section.
Definition: PreferencesFormOOUI.php:238
PreferencesFormOOUI\getExtraSuccessRedirectParameters
getExtraSuccessRedirectParameters()
Get extra parameters for the query string when redirecting after successful save.
Definition: PreferencesFormOOUI.php:92
PreferencesFormOOUI\areOptionsEditable
areOptionsEditable()
Definition: PreferencesFormOOUI.php:75
PreferencesFormOOUI\wrapForm
wrapForm( $html)
Definition: PreferencesFormOOUI.php:100
PreferencesFormOOUI\$modifiedUser
User null $modifiedUser
Definition: PreferencesFormOOUI.php:31
PreferencesFormOOUI\$mSubSectionBeforeFields
bool $mSubSectionBeforeFields
Override default value from HTMLForm.
Definition: PreferencesFormOOUI.php:28
ContextSource\getUser
getUser()
Definition: ContextSource.php:136
PreferencesFormOOUI\getModifiedUser
getModifiedUser()
Definition: PreferencesFormOOUI.php:49
PreferencesFormOOUI\getLegend
getLegend( $key)
Get the "<legend>" for a given section key.
Definition: PreferencesFormOOUI.php:228
OOUIHTMLForm
Compact stacked vertical format for forms, implemented using OOUI widgets.
Definition: OOUIHTMLForm.php:29
PreferencesFormOOUI\setPrivateInfoEditable
setPrivateInfoEditable( $editable)
Whether the.
Definition: PreferencesFormOOUI.php:68
PreferencesFormOOUI\isPrivateInfoEditable
isPrivateInfoEditable()
Definition: PreferencesFormOOUI.php:60
PreferencesFormOOUI\setOptionsEditable
setOptionsEditable( $optionsEditable)
Definition: PreferencesFormOOUI.php:82
OOUIHTMLForm\formatFormHeader
formatFormHeader()
Definition: OOUIHTMLForm.php:250
wfDebug
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:894
ContextSource\msg
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:197
PreferencesFormOOUI\getBody
getBody()
Get the whole body of the form.
Definition: PreferencesFormOOUI.php:168
$content
$content
Definition: router.php:76
PreferencesFormOOUI\setModifiedUser
setModifiedUser( $user)
Definition: PreferencesFormOOUI.php:42
PreferencesFormOOUI\wrapFieldSetSection
wrapFieldSetSection( $legend, $section, $attributes, $isRoot)
Wraps the given $section into an user-visible fieldset.Stability: stableto overrideLegend text for th...
Definition: PreferencesFormOOUI.php:155
$header
$header
Definition: updateCredits.php:37
Xml\tags
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:132
PreferencesFormOOUI\$optionsEditable
bool $optionsEditable
Definition: PreferencesFormOOUI.php:37
HTMLForm\displaySection
displaySection( $fields, $sectionName='', $fieldsetIDPrefix='', &$hasUserVisibleFields=false)
Definition: HTMLForm.php:1721
HTMLNestedFilterable
Definition: HTMLNestedFilterable.php:3
HTMLForm\getTitle
getTitle()
Definition: HTMLForm.php:1666
PreferencesFormOOUI\getButtons
getButtons()
Definition: PreferencesFormOOUI.php:109
PreferencesFormOOUI\filterDataForSubmit
filterDataForSubmit( $data)
Separate multi-option preferences into multiple preferences, since we have to store them separately.
Definition: PreferencesFormOOUI.php:140
$t
$t
Definition: testCompression.php:74
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:67
OOUIHTMLForm\getHeaderText
getHeaderText( $section=null)
Get header text.
Definition: OOUIHTMLForm.php:241
HTMLForm\getFooterText
getFooterText( $section=null)
Get footer text.
Definition: HTMLForm.php:925
PreferencesFormOOUI\$privateInfoEditable
bool $privateInfoEditable
Definition: PreferencesFormOOUI.php:34