MediaWiki REL1_31
PreferencesForm.php
Go to the documentation of this file.
1<?php
22
27 // Override default value from HTMLForm
28 protected $mSubSectionBeforeFields = false;
29
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}
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
Object handling generic submission, CSRF protection, layout and other logic for UI forms.
Definition HTMLForm.php:130
getTitle()
Get the title.
displaySection( $fields, $sectionName='', $fieldsetIDPrefix='', &$hasUserVisibleFields=false)
MediaWikiServices is the service locator for the application scope of MediaWiki.
Form to edit user preferences.
getBody()
Get the whole body of the form.
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.
getPreferenceSections()
Get the keys of each top level preference section.
getLegend( $key)
Get the "<legend>" for a given section key.
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:18
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:2013
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:2056
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 local account $user
Definition hooks.txt:247