MediaWiki  1.32.5
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  // to get a user visible effect, wrap the fieldset into a framed panel layout
121  if ( $isRoot ) {
122  // Mimic TabPanelLayout
123  $wrapper = new OOUI\PanelLayout( [
124  'expanded' => false,
125  'scrollable' => true,
126  // Framed and padded for no-JS, frame hidden with CSS
127  'framed' => true,
128  'infusable' => false,
129  'classes' => [ 'oo-ui-stackLayout oo-ui-indexLayout-stackLayout' ]
130  ] );
131  $layout = new OOUI\PanelLayout( [
132  'expanded' => false,
133  'scrollable' => true,
134  'infusable' => false,
135  'classes' => [ 'oo-ui-tabPanelLayout' ]
136  ] );
137  $wrapper->appendContent( $layout );
138  } else {
139  $wrapper = $layout = new OOUI\PanelLayout( [
140  'expanded' => false,
141  'padded' => true,
142  'framed' => true,
143  'infusable' => false,
144  ] );
145  }
146 
147  $layout->appendContent(
148  new OOUI\FieldsetLayout( [
149  'label' => $legend,
150  'infusable' => false,
151  'items' => [
152  new OOUI\Widget( [
153  'content' => new OOUI\HtmlSnippet( $section )
154  ] ),
155  ],
156  ] + $attributes )
157  );
158  return $wrapper;
159  }
160 
165  function getBody() {
166  // Construct fake tabs to avoid FOUC. The structure mimics OOUI's tabPanelLayout.
167  // TODO: Consider creating an infusable TabPanelLayout in OOUI-PHP.
168  $fakeTabs = [];
169  foreach ( $this->getPreferenceSections() as $i => $key ) {
170  $fakeTabs[] =
172  'div',
173  [
174  'class' =>
175  'oo-ui-widget oo-ui-widget-enabled oo-ui-optionWidget ' .
176  'oo-ui-tabOptionWidget oo-ui-labelElement' .
177  ( $i === 0 ? ' oo-ui-optionWidget-selected' : '' )
178  ],
180  'a',
181  [
182  'class' => 'oo-ui-labelElement-label',
183  // Make this a usable link instead of a span so the tabs
184  // can be used before JS runs
185  'href' => '#mw-prefsection-' . $key
186  ],
187  $this->getLegend( $key )
188  )
189  );
190  }
191  $fakeTabsHtml = Html::rawElement(
192  'div',
193  [ 'class' => 'oo-ui-layout oo-ui-panelLayout oo-ui-indexLayout-tabPanel' ],
195  'div',
196  [ 'class' => 'oo-ui-widget oo-ui-widget-enabled oo-ui-selectWidget ' .
197  'oo-ui-selectWidget-depressed oo-ui-tabSelectWidget' ],
198  implode( $fakeTabs )
199  )
200  );
201 
202  return Html::rawElement(
203  'div',
204  [ 'class' => 'oo-ui-layout oo-ui-panelLayout oo-ui-panelLayout-framed mw-prefs-faketabs' ],
206  'div',
207  [ 'class' => 'oo-ui-layout oo-ui-menuLayout oo-ui-menuLayout-static ' .
208  'oo-ui-menuLayout-top oo-ui-menuLayout-showMenu oo-ui-indexLayout' ],
210  'div',
211  [ 'class' => 'oo-ui-menuLayout-menu' ],
212  $fakeTabsHtml
213  ) .
215  'div',
216  [ 'class' => 'oo-ui-menuLayout-content mw-htmlform-autoinfuse-lazy' ],
217  $this->displaySection( $this->mFieldTree, '', 'mw-prefsection-' )
218  )
219  )
220  );
221  }
222 
229  function getLegend( $key ) {
230  $aliasKey = ( $key === 'optoutwatchlist' || $key === 'optoutrc' ) ? 'opt-out' : $key;
231  $legend = parent::getLegend( $aliasKey );
232  Hooks::run( 'PreferencesGetLegend', [ $this, $key, &$legend ] );
233  return $legend;
234  }
235 
241  return array_keys( array_filter( $this->mFieldTree, 'is_array' ) );
242  }
243 }
PreferencesFormOOUI
Form to edit user preferences.
Definition: PreferencesFormOOUI.php:26
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:244
PreferencesFormOOUI\getPreferenceSections
getPreferenceSections()
Get the keys of each top level preference section.
Definition: PreferencesFormOOUI.php:240
PreferencesFormOOUI\getExtraSuccessRedirectParameters
getExtraSuccessRedirectParameters()
Get extra parameters for the query string when redirecting after successful save.
Definition: PreferencesFormOOUI.php:56
ContextSource\msg
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:168
PreferencesFormOOUI\wrapForm
wrapForm( $html)
Definition: PreferencesFormOOUI.php:64
ContextSource\getUser
getUser()
Definition: ContextSource.php:120
PreferencesFormOOUI\getModifiedUser
getModifiedUser()
Definition: PreferencesFormOOUI.php:42
PreferencesFormOOUI\getLegend
getLegend( $key)
Get the "<legend>" for a given section key.
Definition: PreferencesFormOOUI.php:229
php
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
OOUIHTMLForm
Compact stacked vertical format for forms, implemented using OOUI widgets.
Definition: OOUIHTMLForm.php:27
PreferencesFormOOUI\$modifiedUser
$modifiedUser
Definition: PreferencesFormOOUI.php:30
$html
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:2044
PreferencesFormOOUI\getBody
getBody()
Get the whole body of the form.
Definition: PreferencesFormOOUI.php:165
PreferencesFormOOUI\setModifiedUser
setModifiedUser( $user)
Definition: PreferencesFormOOUI.php:35
PreferencesFormOOUI\wrapFieldSetSection
wrapFieldSetSection( $legend, $section, $attributes, $isRoot)
Wraps the given $section into an user-visible fieldset.
Definition: PreferencesFormOOUI.php:119
$value
$value
Definition: styleTest.css.php:49
Xml\tags
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:132
PreferencesFormOOUI\$mSubSectionBeforeFields
$mSubSectionBeforeFields
Definition: PreferencesFormOOUI.php:28
HTMLForm\displaySection
displaySection( $fields, $sectionName='', $fieldsetIDPrefix='', &$hasUserVisibleFields=false)
Definition: HTMLForm.php:1646
text
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
Definition: All_system_messages.txt:1267
HTMLNestedFilterable
Definition: HTMLNestedFilterable.php:3
$section
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:3098
as
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
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:210
HTMLForm\getTitle
getTitle()
Get the title.
Definition: HTMLForm.php:1591
PreferencesFormOOUI\getButtons
getButtons()
Definition: PreferencesFormOOUI.php:73
PreferencesFormOOUI\filterDataForSubmit
filterDataForSubmit( $data)
Separate multi-option preferences into multiple preferences, since we have to store them separately.
Definition: PreferencesFormOOUI.php:104
$t
$t
Definition: testCompression.php:69
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:232
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200