MediaWiki  master
PreferencesFormOOUI.php
Go to the documentation of this file.
1 <?php
27  // Override default value from HTMLForm
28  protected $mSubSectionBeforeFields = false;
29 
30  private $modifiedUser;
31 
35  public function setModifiedUser( $user ) {
36  $this->modifiedUser = $user;
37  }
38 
42  public function getModifiedUser() {
43  if ( $this->modifiedUser === null ) {
44  return $this->getUser();
45  } else {
46  return $this->modifiedUser;
47  }
48  }
49 
57  return [];
58  }
59 
64  function wrapForm( $html ) {
65  $html = Xml::tags( 'div', [ 'id' => 'preferences' ], $html );
66 
67  return parent::wrapForm( $html );
68  }
69 
73  function getButtons() {
74  if ( !$this->getModifiedUser()->isAllowedAny( 'editmyprivateinfo', 'editmyoptions' ) ) {
75  return '';
76  }
77 
78  $html = parent::getButtons();
79 
80  if ( $this->getModifiedUser()->isAllowed( 'editmyoptions' ) ) {
81  $t = $this->getTitle()->getSubpage( 'reset' );
82 
83  $html .= new OOUI\ButtonWidget( [
84  'infusable' => true,
85  'id' => 'mw-prefs-restoreprefs',
86  'label' => $this->msg( 'restoreprefs' )->text(),
87  'href' => $t->getLinkURL(),
88  'flags' => [ 'destructive' ],
89  'framed' => false,
90  ] );
91 
92  $html = Xml::tags( 'div', [ 'class' => 'mw-prefs-buttons' ], $html );
93  }
94 
95  return $html;
96  }
97 
104  function filterDataForSubmit( $data ) {
105  foreach ( $this->mFlatFields as $fieldname => $field ) {
106  if ( $field instanceof HTMLNestedFilterable ) {
107  $info = $field->mParams;
108  $prefix = $info['prefix'] ?? $fieldname;
109  foreach ( $field->filterDataForSubmit( $data[$fieldname] ) as $key => $value ) {
110  $data["$prefix$key"] = $value;
111  }
112  unset( $data[$fieldname] );
113  }
114  }
115 
116  return $data;
117  }
118 
119  protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) {
120  $layout = parent::wrapFieldSetSection( $legend, $section, $attributes, $isRoot );
121 
122  $layout->addClasses( [ 'mw-prefs-fieldset-wrapper' ] );
123  $layout->removeClasses( [ 'oo-ui-panelLayout-framed' ] );
124 
125  return $layout;
126  }
127 
132  function getBody() {
133  $tabPanels = [];
134  foreach ( $this->mFieldTree as $key => $val ) {
135  if ( !is_array( $val ) ) {
136  wfDebug( __METHOD__ . " encountered a field not attached to a section: '$key'" );
137  continue;
138  }
139  $label = $this->getLegend( $key );
140  $content =
141  $this->getHeaderText( $key ) .
142  $this->displaySection(
143  $this->mFieldTree[$key],
144  "",
145  "mw-prefsection-$key-"
146  ) .
147  $this->getFooterText( $key );
148 
149  $tabPanels[] = new OOUI\TabPanelLayout( 'mw-prefsection-' . $key, [
150  'classes' => [ 'mw-htmlform-autoinfuse-lazy' ],
151  'label' => $label,
152  'content' => new OOUI\FieldsetLayout( [
153  'classes' => [ 'mw-prefs-section-fieldset' ],
154  'id' => "mw-prefsection-$key",
155  'label' => $label,
156  'items' => [
157  new OOUI\Widget( [
158  'content' => new OOUI\HtmlSnippet( $content )
159  ] ),
160  ],
161  ] ),
162  'expanded' => false,
163  'framed' => true,
164  ] );
165  }
166 
167  $indexLayout = new OOUI\IndexLayout( [
168  'infusable' => true,
169  'expanded' => false,
170  'autoFocus' => false,
171  'classes' => [ 'mw-prefs-tabs' ],
172  ] );
173  $indexLayout->addTabPanels( $tabPanels );
174 
175  return new OOUI\PanelLayout( [
176  'framed' => true,
177  'expanded' => false,
178  'classes' => [ 'mw-prefs-tabs-wrapper' ],
179  'content' => $indexLayout
180  ] );
181  }
182 
189  function getLegend( $key ) {
190  $legend = parent::getLegend( $key );
191  Hooks::run( 'PreferencesGetLegend', [ $this, $key, &$legend ] );
192  return $legend;
193  }
194 
200  return array_keys( array_filter( $this->mFieldTree, 'is_array' ) );
201  }
202 }
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition: hooks.txt:1971
getBody()
Get the whole body of the form.
getHeaderText( $section=null)
wrapFieldSetSection( $legend, $section, $attributes, $isRoot)
$value
displaySection( $fields, $sectionName='', $fieldsetIDPrefix='', &$hasUserVisibleFields=false)
Definition: HTMLForm.php:1667
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
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:1612
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:130
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:767
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
usually copyright or history_copyright This message must be in HTML not wikitext if the section is included from a template $section
Definition: hooks.txt:3038
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
getPreferenceSections()
Get the keys of each top level preference section.
getFooterText( $section=null)
Get footer text.
Definition: HTMLForm.php:895
Compact stacked vertical format for forms, implemented using OOUI widgets.
getLegend( $key)
Get the "<legend>" for a given section key.
$content
Definition: pageupdater.txt:72
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1454
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200