MediaWiki  master
PreferencesFormOOUI.php
Go to the documentation of this file.
1 <?php
27  // Override default value from HTMLForm
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  function wrapForm( $html ) {
101  $html = Xml::tags( 'div', [ 'id' => 'preferences' ], $html );
102 
103  return parent::wrapForm( $html );
104  }
105 
109  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  function filterDataForSubmit( $data ) {
141  foreach ( $this->mFlatFields as $fieldname => $field ) {
142  if ( $field instanceof HTMLNestedFilterable ) {
143  // @phan-suppress-next-next-line PhanUndeclaredProperty All HTMLForm fields have mParams,
144  // but the instanceof confuses phan, which doesn't support intersections
145  $info = $field->mParams;
146  $prefix = $info['prefix'] ?? $fieldname;
147  foreach ( $field->filterDataForSubmit( $data[$fieldname] ) as $key => $value ) {
148  $data["$prefix$key"] = $value;
149  }
150  unset( $data[$fieldname] );
151  }
152  }
153 
154  return $data;
155  }
156 
157  protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) {
158  $layout = parent::wrapFieldSetSection( $legend, $section, $attributes, $isRoot );
159 
160  $layout->addClasses( [ 'mw-prefs-fieldset-wrapper' ] );
161  $layout->removeClasses( [ 'oo-ui-panelLayout-framed' ] );
162 
163  return $layout;
164  }
165 
170  function getBody() {
171  $tabPanels = [];
172  foreach ( $this->mFieldTree as $key => $val ) {
173  if ( !is_array( $val ) ) {
174  wfDebug( __METHOD__ . " encountered a field not attached to a section: '$key'" );
175  continue;
176  }
177  $label = $this->getLegend( $key );
178  $content =
179  $this->getHeaderText( $key ) .
180  $this->displaySection(
181  $this->mFieldTree[$key],
182  "",
183  "mw-prefsection-$key-"
184  ) .
185  $this->getFooterText( $key );
186 
187  $tabPanels[] = new OOUI\TabPanelLayout( 'mw-prefsection-' . $key, [
188  'classes' => [ 'mw-htmlform-autoinfuse-lazy' ],
189  'label' => $label,
190  'content' => new OOUI\FieldsetLayout( [
191  'classes' => [ 'mw-prefs-section-fieldset' ],
192  'id' => "mw-prefsection-$key",
193  'label' => $label,
194  'items' => [
195  new OOUI\Widget( [
196  'content' => new OOUI\HtmlSnippet( $content )
197  ] ),
198  ],
199  ] ),
200  'expanded' => false,
201  'framed' => true,
202  ] );
203  }
204 
205  $indexLayout = new OOUI\IndexLayout( [
206  'infusable' => true,
207  'expanded' => false,
208  'autoFocus' => false,
209  'classes' => [ 'mw-prefs-tabs' ],
210  ] );
211  $indexLayout->addTabPanels( $tabPanels );
212 
213  return new OOUI\PanelLayout( [
214  'framed' => true,
215  'expanded' => false,
216  'classes' => [ 'mw-prefs-tabs-wrapper' ],
217  'content' => $indexLayout
218  ] );
219  }
220 
227  function getLegend( $key ) {
228  $legend = parent::getLegend( $key );
229  Hooks::run( 'PreferencesGetLegend', [ $this, $key, &$legend ] );
230  return $legend;
231  }
232 
238  return array_keys( array_filter( $this->mFieldTree, 'is_array' ) );
239  }
240 }
getBody()
Get the whole body of the form.
getHeaderText( $section=null)
wrapFieldSetSection( $legend, $section, $attributes, $isRoot)
setOptionsEditable( $optionsEditable)
displaySection( $fields, $sectionName='', $fieldsetIDPrefix='', &$hasUserVisibleFields=false)
Definition: HTMLForm.php:1675
filterDataForSubmit( $data)
Separate multi-option preferences into multiple preferences, since we have to store them separately...
getExtraSuccessRedirectParameters()
Get extra parameters for the query string when redirecting after successful save. ...
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
getTitle()
Get the title.
Definition: HTMLForm.php:1620
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:130
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
getPreferenceSections()
Get the keys of each top level preference section.
getFooterText( $section=null)
Get footer text.
Definition: HTMLForm.php:900
Compact stacked vertical format for forms, implemented using OOUI widgets.
getLegend( $key)
Get the "<legend>" for a given section key.
$content
Definition: router.php:78
setPrivateInfoEditable( $editable)
Whether the.
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200