MediaWiki  1.30.2
PreferencesForm.php
Go to the documentation of this file.
1 <?php
22 
26 class PreferencesForm extends HTMLForm {
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  $attrs = [ 'id' => 'mw-prefs-restoreprefs' ];
75 
76  if ( !$this->getModifiedUser()->isAllowedAny( 'editmyprivateinfo', 'editmyoptions' ) ) {
77  return '';
78  }
79 
80  $html = parent::getButtons();
81 
82  if ( $this->getModifiedUser()->isAllowed( 'editmyoptions' ) ) {
83  $t = $this->getTitle()->getSubpage( 'reset' );
84 
85  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
86  $html .= "\n" . $linkRenderer->makeLink( $t, $this->msg( 'restoreprefs' )->text(),
87  Html::buttonAttributes( $attrs, [ 'mw-ui-quiet' ] ) );
88 
89  $html = Xml::tags( 'div', [ 'class' => 'mw-prefs-buttons' ], $html );
90  }
91 
92  return $html;
93  }
94 
101  function filterDataForSubmit( $data ) {
102  foreach ( $this->mFlatFields as $fieldname => $field ) {
103  if ( $field instanceof HTMLNestedFilterable ) {
104  $info = $field->mParams;
105  $prefix = isset( $info['prefix'] ) ? $info['prefix'] : $fieldname;
106  foreach ( $field->filterDataForSubmit( $data[$fieldname] ) as $key => $value ) {
107  $data["$prefix$key"] = $value;
108  }
109  unset( $data[$fieldname] );
110  }
111  }
112 
113  return $data;
114  }
115 
120  function getBody() {
121  return $this->displaySection( $this->mFieldTree, '', 'mw-prefsection-' );
122  }
123 
130  function getLegend( $key ) {
131  $legend = parent::getLegend( $key );
132  Hooks::run( 'PreferencesGetLegend', [ $this, $key, &$legend ] );
133  return $legend;
134  }
135 
141  return array_keys( array_filter( $this->mFieldTree, 'is_array' ) );
142  }
143 }
$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
PreferencesForm\getPreferenceSections
getPreferenceSections()
Get the keys of each top level preference section.
Definition: PreferencesForm.php:140
Xml\tags
static tags( $element, $attribs=null, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:131
PreferencesForm\filterDataForSubmit
filterDataForSubmit( $data)
Separate multi-option preferences into multiple preferences, since we have to store them separately.
Definition: PreferencesForm.php:101
PreferencesForm\getExtraSuccessRedirectParameters
getExtraSuccessRedirectParameters()
Get extra parameters for the query string when redirecting after successful save.
Definition: PreferencesForm.php:56
text
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition: design.txt:12
ContextSource\msg
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:189
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
PreferencesForm\wrapForm
wrapForm( $html)
Definition: PreferencesForm.php:64
PreferencesForm\getLegend
getLegend( $key)
Get the "<legend>" for a given section key.
Definition: PreferencesForm.php:130
PreferencesForm\getBody
getBody()
Get the whole body of the form.
Definition: PreferencesForm.php:120
$linkRenderer
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 after processing after in associative array form before processing starts Return false to skip default processing and return $ret $linkRenderer
Definition: hooks.txt:1965
ContextSource\getUser
getUser()
Get the User object.
Definition: ContextSource.php:133
PreferencesForm\$modifiedUser
$modifiedUser
Definition: PreferencesForm.php:30
PreferencesForm\getButtons
getButtons()
Definition: PreferencesForm.php:73
Html\buttonAttributes
static buttonAttributes(array $attrs, array $modifiers=[])
Modifies a set of attributes meant for button elements and apply a set of default attributes when $wg...
Definition: Html.php:109
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
$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:1965
PreferencesForm\getModifiedUser
getModifiedUser()
Definition: PreferencesForm.php:42
PreferencesForm
Form to edit user preferences.
Definition: PreferencesForm.php:26
$value
$value
Definition: styleTest.css.php:45
HTMLForm\displaySection
displaySection( $fields, $sectionName='', $fieldsetIDPrefix='', &$hasUserVisibleFields=false)
Definition: HTMLForm.php:1634
PreferencesForm\setModifiedUser
setModifiedUser( $user)
Definition: PreferencesForm.php:35
PreferencesForm\$mSubSectionBeforeFields
$mSubSectionBeforeFields
Definition: PreferencesForm.php:28
HTMLNestedFilterable
Definition: HTMLNestedFilterable.php:3
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
HTMLForm\getTitle
getTitle()
Get the title.
Definition: HTMLForm.php:1580
$t
$t
Definition: testCompression.php:67
MediaWikiServices
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 MediaWikiServices
Definition: injection.txt:23
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:203
HTMLForm
Object handling generic submission, CSRF protection, layout and other logic for UI forms.
Definition: HTMLForm.php:128