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  $html = Xml::tags( 'div', [ 'class' => 'mw-prefs-buttons' ], $html );
118  }
119 
120  return $html;
121  }
122 
129  public function filterDataForSubmit( $data ) {
130  foreach ( $this->mFlatFields as $fieldname => $field ) {
131  if ( $field instanceof HTMLNestedFilterable ) {
132  $info = $field->mParams;
133  $prefix = $info['prefix'] ?? $fieldname;
134  foreach ( $field->filterDataForSubmit( $data[$fieldname] ) as $key => $value ) {
135  $data["$prefix$key"] = $value;
136  }
137  unset( $data[$fieldname] );
138  }
139  }
140 
141  return $data;
142  }
143 
144  protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) {
145  $layout = parent::wrapFieldSetSection( $legend, $section, $attributes, $isRoot );
146 
147  $layout->addClasses( [ 'mw-prefs-fieldset-wrapper' ] );
148  $layout->removeClasses( [ 'oo-ui-panelLayout-framed' ] );
149 
150  return $layout;
151  }
152 
157  public function getBody() {
158  $tabPanels = [];
159  foreach ( $this->mFieldTree as $key => $val ) {
160  if ( !is_array( $val ) ) {
161  wfDebug( __METHOD__ . " encountered a field not attached to a section: '$key'" );
162  continue;
163  }
164  $label = $this->getLegend( $key );
165  $content =
166  $this->getHeaderText( $key ) .
167  $this->displaySection(
168  $val,
169  "",
170  "mw-prefsection-$key-"
171  ) .
172  $this->getFooterText( $key );
173 
174  $tabPanels[] = new OOUI\TabPanelLayout( 'mw-prefsection-' . $key, [
175  'classes' => [ 'mw-htmlform-autoinfuse-lazy' ],
176  'label' => $label,
177  'content' => new OOUI\FieldsetLayout( [
178  'classes' => [ 'mw-prefs-section-fieldset' ],
179  'id' => "mw-prefsection-$key",
180  'label' => $label,
181  'items' => [
182  new OOUI\Widget( [
183  'content' => new OOUI\HtmlSnippet( $content )
184  ] ),
185  ],
186  ] ),
187  'expanded' => false,
188  'framed' => true,
189  ] );
190  }
191 
192  $indexLayout = new OOUI\IndexLayout( [
193  'infusable' => true,
194  'expanded' => false,
195  'autoFocus' => false,
196  'classes' => [ 'mw-prefs-tabs' ],
197  ] );
198  $indexLayout->addTabPanels( $tabPanels );
199 
200  $header = $this->formatFormHeader();
201  $form = new OOUI\PanelLayout( [
202  'framed' => true,
203  'expanded' => false,
204  'classes' => [ 'mw-prefs-tabs-wrapper' ],
205  'content' => $indexLayout
206  ] );
207 
208  return $header . $form;
209  }
210 
217  public function getLegend( $key ) {
218  $legend = parent::getLegend( $key );
219  $this->getHookRunner()->onPreferencesGetLegend( $this, $key, $legend );
220  return $legend;
221  }
222 
227  public function getPreferenceSections() {
228  return array_keys( array_filter( $this->mFieldTree, 'is_array' ) );
229  }
230 }
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
getFooterText( $section=null)
Get footer text.
Definition: HTMLForm.php:1045
getHeaderText( $section=null)
Get header text.
Definition: HTMLForm.php:950
displaySection( $fields, $sectionName='', $fieldsetIDPrefix='', &$hasUserVisibleFields=false)
Definition: HTMLForm.php:1879
Compact stacked vertical format for forms, implemented using OOUI widgets.
Form to edit user preferences.
filterDataForSubmit( $data)
Separate multi-option preferences into multiple preferences, since we have to store them separately.
getPreferenceSections()
Get the keys of each top level preference section.
getBody()
Get the whole body of the form.
bool $mSubSectionBeforeFields
Override default value from HTMLForm.
getLegend( $key)
Get the "<legend>" for a given section key.
wrapFieldSetSection( $legend, $section, $attributes, $isRoot)
Wraps the given $section into an user-visible fieldset.Stability: stableto overrideLegend text for th...
getExtraSuccessRedirectParameters()
Get extra parameters for the query string when redirecting after successful save.
setPrivateInfoEditable( $editable)
Whether the.
setOptionsEditable( $optionsEditable)
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:134
$content
Definition: router.php:76
$header