3 * Form to edit user preferences.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 * We're now using the HTMLForm object with some customisation to generate the
25 * Preferences form. This object handles generic submission, CSRF protection,
26 * layout and other logic in a reusable manner. We subclass it as a PreferencesForm
27 * to make some minor customisations.
29 * In order to generate the form, the HTMLForm object needs an array structure
30 * detailing the form fields available, and that's what this class is for. Each
31 * element of the array is a basic property-list, including the type of field,
32 * the label it is to be given in the form, callbacks for validation and
33 * 'filtering', and other pertinent information. Note that the 'default' field
34 * is named for generic forms, and does not represent the preference's default
35 * (which is stored in $wgDefaultUserOptions), but the default for the form
36 * field, which should be whatever the user has set for that preference. There
37 * is no need to override it unless you have some special storage logic (for
38 * instance, those not presently stored as options, but which are best set from
39 * the user preferences view).
41 * Field types are implemented as subclasses of the generic HTMLFormField
42 * object, and typically implement at least getInputHTML, which generates the
43 * HTML for the input field to be placed in the table.
45 * Once fields have been retrieved and validated, submission logic is handed
46 * over to the tryUISubmit static method of this class.
49 static $defaultPreferences = null;
50 static $saveFilters = array(
51 'timecorrection' => array( 'Preferences', 'filterTimezoneInput' ),
52 'cols' => array( 'Preferences', 'filterIntval' ),
53 'rows' => array( 'Preferences', 'filterIntval' ),
54 'rclimit' => array( 'Preferences', 'filterIntval' ),
55 'wllimit' => array( 'Preferences', 'filterIntval' ),
56 'searchlimit' => array( 'Preferences', 'filterIntval' ),
59 // Stuff that shouldn't be saved as a preference.
60 private static $saveBlacklist = array(
68 * @param $context IContextSource
71 static function getPreferences( $user, IContextSource
$context ) {
72 if ( self
::$defaultPreferences ) {
73 return self
::$defaultPreferences;
76 $defaultPreferences = array();
78 self
::profilePreferences( $user, $context, $defaultPreferences );
79 self
::skinPreferences( $user, $context, $defaultPreferences );
80 self
::filesPreferences( $user, $context, $defaultPreferences );
81 self
::datetimePreferences( $user, $context, $defaultPreferences );
82 self
::renderingPreferences( $user, $context, $defaultPreferences );
83 self
::editingPreferences( $user, $context, $defaultPreferences );
84 self
::rcPreferences( $user, $context, $defaultPreferences );
85 self
::watchlistPreferences( $user, $context, $defaultPreferences );
86 self
::searchPreferences( $user, $context, $defaultPreferences );
87 self
::miscPreferences( $user, $context, $defaultPreferences );
89 wfRunHooks( 'GetPreferences', array( $user, &$defaultPreferences ) );
91 ## Remove preferences that wikis don't want to use
92 global $wgHiddenPrefs;
93 foreach ( $wgHiddenPrefs as $pref ) {
94 if ( isset( $defaultPreferences[$pref] ) ) {
95 unset( $defaultPreferences[$pref] );
99 ## Make sure that form fields have their parent set. See bug 41337.
100 $dummyForm = new HTMLForm( array(), $context );
102 $disable = !$user->isAllowed( 'editmyoptions' );
104 ## Prod in defaults from the user
105 foreach ( $defaultPreferences as $name => &$info ) {
106 $prefFromUser = self
::getOptionFromUser( $name, $info, $user );
107 if ( $disable && !in_array( $name, self
::$saveBlacklist ) ) {
108 $info['disabled'] = 'disabled';
110 $field = HTMLForm
::loadInputFromParameters( $name, $info ); // For validation
111 $field->mParent
= $dummyForm;
112 $defaultOptions = User
::getDefaultOptions();
113 $globalDefault = isset( $defaultOptions[$name] )
114 ?
$defaultOptions[$name]
117 // If it validates, set it as the default
118 if ( isset( $info['default'] ) ) {
119 // Already set, no problem
121 } elseif ( !is_null( $prefFromUser ) && // Make sure we're not just pulling nothing
122 $field->validate( $prefFromUser, $user->getOptions() ) === true ) {
123 $info['default'] = $prefFromUser;
124 } elseif ( $field->validate( $globalDefault, $user->getOptions() ) === true ) {
125 $info['default'] = $globalDefault;
127 throw new MWException( "Global default '$globalDefault' is invalid for field $name" );
131 self
::$defaultPreferences = $defaultPreferences;
133 return $defaultPreferences;
137 * Pull option from a user account. Handles stuff like array-type preferences.
142 * @return array|String
144 static function getOptionFromUser( $name, $info, $user ) {
145 $val = $user->getOption( $name );
147 // Handling for multiselect preferences
148 if ( ( isset( $info['type'] ) && $info['type'] == 'multiselect' ) ||
149 ( isset( $info['class'] ) && $info['class'] == 'HTMLMultiSelectField' ) ) {
150 $options = HTMLFormField
::flattenOptions( $info['options'] );
151 $prefix = isset( $info['prefix'] ) ?
$info['prefix'] : $name;
154 foreach ( $options as $value ) {
155 if ( $user->getOption( "$prefix$value" ) ) {
161 // Handling for checkmatrix preferences
162 if ( ( isset( $info['type'] ) && $info['type'] == 'checkmatrix' ) ||
163 ( isset( $info['class'] ) && $info['class'] == 'HTMLCheckMatrix' ) ) {
164 $columns = HTMLFormField
::flattenOptions( $info['columns'] );
165 $rows = HTMLFormField
::flattenOptions( $info['rows'] );
166 $prefix = isset( $info['prefix'] ) ?
$info['prefix'] : $name;
169 foreach ( $columns as $column ) {
170 foreach ( $rows as $row ) {
171 if ( $user->getOption( "$prefix$column-$row" ) ) {
172 $val[] = "$column-$row";
183 * @param $context IContextSource
184 * @param $defaultPreferences
187 static function profilePreferences( $user, IContextSource
$context, &$defaultPreferences ) {
188 global $wgAuth, $wgContLang, $wgParser, $wgCookieExpiration, $wgLanguageCode,
189 $wgDisableTitleConversion, $wgDisableLangConversion, $wgMaxSigChars,
190 $wgEnableEmail, $wgEmailConfirmToEdit, $wgEnableUserEmail, $wgEmailAuthentication,
191 $wgEnotifWatchlist, $wgEnotifUserTalk, $wgEnotifRevealEditorAddress,
194 // retrieving user name for GENDER and misc.
195 $userName = $user->getName();
197 ## User info #####################################
199 $defaultPreferences['username'] = array(
201 'label-message' => array( 'username', $userName ),
202 'default' => $userName,
203 'section' => 'personal/info',
206 $defaultPreferences['userid'] = array(
208 'label-message' => array( 'uid', $userName ),
209 'default' => $user->getId(),
210 'section' => 'personal/info',
213 # Get groups to which the user belongs
214 $userEffectiveGroups = $user->getEffectiveGroups();
215 $userGroups = $userMembers = array();
216 foreach ( $userEffectiveGroups as $ueg ) {
218 // Skip the default * group, seems useless here
221 $groupName = User
::getGroupName( $ueg );
222 $userGroups[] = User
::makeGroupLinkHTML( $ueg, $groupName );
224 $memberName = User
::getGroupMember( $ueg, $userName );
225 $userMembers[] = User
::makeGroupLinkHTML( $ueg, $memberName );
227 asort( $userGroups );
228 asort( $userMembers );
230 $lang = $context->getLanguage();
232 $defaultPreferences['usergroups'] = array(
234 'label' => $context->msg( 'prefs-memberingroups' )->numParams(
235 count( $userGroups ) )->params( $userName )->parse(),
236 'default' => $context->msg( 'prefs-memberingroups-type',
237 $lang->commaList( $userGroups ),
238 $lang->commaList( $userMembers )
241 'section' => 'personal/info',
244 $editCount = Linker
::link( SpecialPage
::getTitleFor( "Contributions", $userName ),
245 $lang->formatNum( $user->getEditCount() ) );
247 $defaultPreferences['editcount'] = array(
250 'label-message' => 'prefs-edits',
251 'default' => $editCount,
252 'section' => 'personal/info',
255 if ( $user->getRegistration() ) {
256 $displayUser = $context->getUser();
257 $userRegistration = $user->getRegistration();
258 $defaultPreferences['registrationdate'] = array(
260 'label-message' => 'prefs-registration',
261 'default' => $context->msg(
262 'prefs-registration-date-time',
263 $lang->userTimeAndDate( $userRegistration, $displayUser ),
264 $lang->userDate( $userRegistration, $displayUser ),
265 $lang->userTime( $userRegistration, $displayUser )
267 'section' => 'personal/info',
271 $canViewPrivateInfo = $user->isAllowed( 'viewmyprivateinfo' );
272 $canEditPrivateInfo = $user->isAllowed( 'editmyprivateinfo' );
274 // Actually changeable stuff
275 $defaultPreferences['realname'] = array(
276 // (not really "private", but still shouldn't be edited without permission)
277 'type' => $canEditPrivateInfo && $wgAuth->allowPropChange( 'realname' ) ?
'text' : 'info',
278 'default' => $user->getRealName(),
279 'section' => 'personal/info',
280 'label-message' => 'yourrealname',
281 'help-message' => 'prefs-help-realname',
284 if ( $canEditPrivateInfo && $wgAuth->allowPasswordChange() ) {
285 $link = Linker
::link( SpecialPage
::getTitleFor( 'ChangePassword' ),
286 $context->msg( 'prefs-resetpass' )->escaped(), array(),
287 array( 'returnto' => SpecialPage
::getTitleFor( 'Preferences' )->getPrefixedText() ) );
289 $defaultPreferences['password'] = array(
293 'label-message' => 'yourpassword',
294 'section' => 'personal/info',
297 if ( $wgCookieExpiration > 0 ) {
298 $defaultPreferences['rememberpassword'] = array(
300 'label' => $context->msg( 'tog-rememberpassword' )->numParams(
301 ceil( $wgCookieExpiration / ( 3600 * 24 ) ) )->text(),
302 'section' => 'personal/info',
305 // Only show preferhttps if secure login is turned on
306 if ( $wgSecureLogin && wfCanIPUseHTTPS( $context->getRequest()->getIP() ) ) {
307 $defaultPreferences['prefershttps'] = array(
309 'label-message' => 'tog-prefershttps',
310 'help-message' => 'prefs-help-prefershttps',
311 'section' => 'personal/info'
316 $languages = Language
::fetchLanguageNames( null, 'mw' );
317 if ( !array_key_exists( $wgLanguageCode, $languages ) ) {
318 $languages[$wgLanguageCode] = $wgLanguageCode;
323 foreach ( $languages as $code => $name ) {
324 $display = wfBCP47( $code ) . ' - ' . $name;
325 $options[$display] = $code;
327 $defaultPreferences['language'] = array(
329 'section' => 'personal/i18n',
330 'options' => $options,
331 'label-message' => 'yourlanguage',
334 $defaultPreferences['gender'] = array(
336 'section' => 'personal/i18n',
338 $context->msg( 'parentheses',
339 $context->msg( 'gender-unknown' )->text()
340 )->text() => 'unknown',
341 $context->msg( 'gender-female' )->text() => 'female',
342 $context->msg( 'gender-male' )->text() => 'male',
344 'label-message' => 'yourgender',
345 'help-message' => 'prefs-help-gender',
348 // see if there are multiple language variants to choose from
349 if ( !$wgDisableLangConversion ) {
350 foreach ( LanguageConverter
::$languagesWithVariants as $langCode ) {
351 if ( $langCode == $wgContLang->getCode() ) {
352 $variants = $wgContLang->getVariants();
354 if ( count( $variants ) <= 1 ) {
358 $variantArray = array();
359 foreach ( $variants as $v ) {
360 $v = str_replace( '_', '-', strtolower( $v ) );
361 $variantArray[$v] = $lang->getVariantname( $v, false );
365 foreach ( $variantArray as $code => $name ) {
366 $display = wfBCP47( $code ) . ' - ' . $name;
367 $options[$display] = $code;
370 $defaultPreferences['variant'] = array(
371 'label-message' => 'yourvariant',
373 'options' => $options,
374 'section' => 'personal/i18n',
375 'help-message' => 'prefs-help-variant',
378 if ( !$wgDisableTitleConversion ) {
379 $defaultPreferences['noconvertlink'] = array(
381 'section' => 'personal/i18n',
382 'label-message' => 'tog-noconvertlink',
386 $defaultPreferences["variant-$langCode"] = array(
393 // Stuff from Language::getExtraUserToggles()
394 // FIXME is this dead code? $extraUserToggles doesn't seem to be defined for any language
395 $toggles = $wgContLang->getExtraUserToggles();
397 foreach ( $toggles as $toggle ) {
398 $defaultPreferences[$toggle] = array(
400 'section' => 'personal/i18n',
401 'label-message' => "tog-$toggle",
405 // show a preview of the old signature first
406 $oldsigWikiText = $wgParser->preSaveTransform(
408 $context->getTitle(),
410 ParserOptions
::newFromContext( $context )
412 $oldsigHTML = $context->getOutput()->parseInline( $oldsigWikiText, true, true );
413 $defaultPreferences['oldsig'] = array(
416 'label-message' => 'tog-oldsig',
417 'default' => $oldsigHTML,
418 'section' => 'personal/signature',
420 $defaultPreferences['nickname'] = array(
421 'type' => $wgAuth->allowPropChange( 'nickname' ) ?
'text' : 'info',
422 'maxlength' => $wgMaxSigChars,
423 'label-message' => 'yournick',
424 'validation-callback' => array( 'Preferences', 'validateSignature' ),
425 'section' => 'personal/signature',
426 'filter-callback' => array( 'Preferences', 'cleanSignature' ),
428 $defaultPreferences['fancysig'] = array(
430 'label-message' => 'tog-fancysig',
431 // show general help about signature at the bottom of the section
432 'help-message' => 'prefs-help-signature',
433 'section' => 'personal/signature'
438 if ( $wgEnableEmail ) {
439 if ( $canViewPrivateInfo ) {
440 $helpMessages[] = $wgEmailConfirmToEdit
441 ?
'prefs-help-email-required'
442 : 'prefs-help-email';
444 if ( $wgEnableUserEmail ) {
445 // additional messages when users can send email to each other
446 $helpMessages[] = 'prefs-help-email-others';
449 $emailAddress = $user->getEmail() ?
htmlspecialchars( $user->getEmail() ) : '';
450 if ( $canEditPrivateInfo && $wgAuth->allowPropChange( 'emailaddress' ) ) {
451 $link = Linker
::link(
452 SpecialPage
::getTitleFor( 'ChangeEmail' ),
453 $context->msg( $user->getEmail() ?
'prefs-changeemail' : 'prefs-setemail' )->escaped(),
455 array( 'returnto' => SpecialPage
::getTitleFor( 'Preferences' )->getPrefixedText() ) );
457 $emailAddress .= $emailAddress == '' ?
$link : (
458 $context->msg( 'word-separator' )->plain()
459 . $context->msg( 'parentheses' )->rawParams( $link )->plain()
463 $defaultPreferences['emailaddress'] = array(
466 'default' => $emailAddress,
467 'label-message' => 'youremail',
468 'section' => 'personal/email',
469 'help-messages' => $helpMessages,
470 # 'cssclass' chosen below
474 $disableEmailPrefs = false;
476 if ( $wgEmailAuthentication ) {
477 $emailauthenticationclass = 'mw-email-not-authenticated';
478 if ( $user->getEmail() ) {
479 if ( $user->getEmailAuthenticationTimestamp() ) {
480 // date and time are separate parameters to facilitate localisation.
481 // $time is kept for backward compat reasons.
482 // 'emailauthenticated' is also used in SpecialConfirmemail.php
483 $displayUser = $context->getUser();
484 $emailTimestamp = $user->getEmailAuthenticationTimestamp();
485 $time = $lang->userTimeAndDate( $emailTimestamp, $displayUser );
486 $d = $lang->userDate( $emailTimestamp, $displayUser );
487 $t = $lang->userTime( $emailTimestamp, $displayUser );
488 $emailauthenticated = $context->msg( 'emailauthenticated',
489 $time, $d, $t )->parse() . '<br />';
490 $disableEmailPrefs = false;
491 $emailauthenticationclass = 'mw-email-authenticated';
493 $disableEmailPrefs = true;
494 $emailauthenticated = $context->msg( 'emailnotauthenticated' )->parse() . '<br />' .
496 SpecialPage
::getTitleFor( 'Confirmemail' ),
497 $context->msg( 'emailconfirmlink' )->escaped()
499 $emailauthenticationclass = "mw-email-not-authenticated";
502 $disableEmailPrefs = true;
503 $emailauthenticated = $context->msg( 'noemailprefs' )->escaped();
504 $emailauthenticationclass = 'mw-email-none';
507 if ( $canViewPrivateInfo ) {
508 $defaultPreferences['emailauthentication'] = array(
511 'section' => 'personal/email',
512 'label-message' => 'prefs-emailconfirm-label',
513 'default' => $emailauthenticated,
514 # Apply the same CSS class used on the input to the message:
515 'cssclass' => $emailauthenticationclass,
517 $defaultPreferences['emailaddress']['cssclass'] = $emailauthenticationclass;
521 if ( $wgEnableUserEmail && $user->isAllowed( 'sendemail' ) ) {
522 $defaultPreferences['disablemail'] = array(
525 'section' => 'personal/email',
526 'label-message' => 'allowemail',
527 'disabled' => $disableEmailPrefs,
529 $defaultPreferences['ccmeonemails'] = array(
531 'section' => 'personal/email',
532 'label-message' => 'tog-ccmeonemails',
533 'disabled' => $disableEmailPrefs,
537 if ( $wgEnotifWatchlist ) {
538 $defaultPreferences['enotifwatchlistpages'] = array(
540 'section' => 'personal/email',
541 'label-message' => 'tog-enotifwatchlistpages',
542 'disabled' => $disableEmailPrefs,
545 if ( $wgEnotifUserTalk ) {
546 $defaultPreferences['enotifusertalkpages'] = array(
548 'section' => 'personal/email',
549 'label-message' => 'tog-enotifusertalkpages',
550 'disabled' => $disableEmailPrefs,
553 if ( $wgEnotifUserTalk ||
$wgEnotifWatchlist ) {
554 $defaultPreferences['enotifminoredits'] = array(
556 'section' => 'personal/email',
557 'label-message' => 'tog-enotifminoredits',
558 'disabled' => $disableEmailPrefs,
561 if ( $wgEnotifRevealEditorAddress ) {
562 $defaultPreferences['enotifrevealaddr'] = array(
564 'section' => 'personal/email',
565 'label-message' => 'tog-enotifrevealaddr',
566 'disabled' => $disableEmailPrefs,
575 * @param $context IContextSource
576 * @param $defaultPreferences
579 static function skinPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
580 ## Skin #####################################
581 global $wgAllowUserCss, $wgAllowUserJs;
583 $defaultPreferences['skin'] = array(
585 'options' => self
::generateSkinOptions( $user, $context ),
587 'section' => 'rendering/skin',
590 # Create links to user CSS/JS pages for all skins
591 # This code is basically copied from generateSkinOptions(). It'd
592 # be nice to somehow merge this back in there to avoid redundancy.
593 if ( $wgAllowUserCss ||
$wgAllowUserJs ) {
594 $linkTools = array();
595 $userName = $user->getName();
597 if ( $wgAllowUserCss ) {
598 $cssPage = Title
::makeTitleSafe( NS_USER
, $userName . '/common.css' );
599 $linkTools[] = Linker
::link( $cssPage, $context->msg( 'prefs-custom-css' )->escaped() );
602 if ( $wgAllowUserJs ) {
603 $jsPage = Title
::makeTitleSafe( NS_USER
, $userName . '/common.js' );
604 $linkTools[] = Linker
::link( $jsPage, $context->msg( 'prefs-custom-js' )->escaped() );
607 $defaultPreferences['commoncssjs'] = array(
610 'default' => $context->getLanguage()->pipeList( $linkTools ),
611 'label-message' => 'prefs-common-css-js',
612 'section' => 'rendering/skin',
619 * @param $context IContextSource
620 * @param $defaultPreferences Array
622 static function filesPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
623 ## Files #####################################
624 $defaultPreferences['imagesize'] = array(
626 'options' => self
::getImageSizes( $context ),
627 'label-message' => 'imagemaxsize',
628 'section' => 'rendering/files',
630 $defaultPreferences['thumbsize'] = array(
632 'options' => self
::getThumbSizes( $context ),
633 'label-message' => 'thumbsize',
634 'section' => 'rendering/files',
640 * @param $context IContextSource
641 * @param $defaultPreferences
644 static function datetimePreferences( $user, IContextSource
$context, &$defaultPreferences ) {
645 ## Date and time #####################################
646 $dateOptions = self
::getDateOptions( $context );
647 if ( $dateOptions ) {
648 $defaultPreferences['date'] = array(
650 'options' => $dateOptions,
652 'section' => 'datetime/dateformat',
657 $now = wfTimestampNow();
658 $lang = $context->getLanguage();
659 $nowlocal = Xml
::element( 'span', array( 'id' => 'wpLocalTime' ),
660 $lang->time( $now, true ) );
661 $nowserver = $lang->time( $now, false ) .
662 Html
::hidden( 'wpServerTime', (int)substr( $now, 8, 2 ) * 60 +
(int)substr( $now, 10, 2 ) );
664 $defaultPreferences['nowserver'] = array(
667 'label-message' => 'servertime',
668 'default' => $nowserver,
669 'section' => 'datetime/timeoffset',
672 $defaultPreferences['nowlocal'] = array(
675 'label-message' => 'localtime',
676 'default' => $nowlocal,
677 'section' => 'datetime/timeoffset',
680 // Grab existing pref.
681 $tzOffset = $user->getOption( 'timecorrection' );
682 $tz = explode( '|', $tzOffset, 3 );
684 $tzOptions = self
::getTimezoneOptions( $context );
686 $tzSetting = $tzOffset;
687 if ( count( $tz ) > 1 && $tz[0] == 'Offset' ) {
689 $tzSetting = sprintf( '%+03d:%02d', floor( $minDiff / 60 ), abs( $minDiff ) %
60 );
690 } elseif ( count( $tz ) > 1 && $tz[0] == 'ZoneInfo' &&
691 !in_array( $tzOffset, HTMLFormField
::flattenOptions( $tzOptions ) )
693 # Timezone offset can vary with DST
694 $userTZ = timezone_open( $tz[2] );
695 if ( $userTZ !== false ) {
696 $minDiff = floor( timezone_offset_get( $userTZ, date_create( 'now' ) ) / 60 );
697 $tzSetting = "ZoneInfo|$minDiff|{$tz[2]}";
701 $defaultPreferences['timecorrection'] = array(
702 'class' => 'HTMLSelectOrOtherField',
703 'label-message' => 'timezonelegend',
704 'options' => $tzOptions,
705 'default' => $tzSetting,
707 'section' => 'datetime/timeoffset',
713 * @param $context IContextSource
714 * @param $defaultPreferences Array
716 static function renderingPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
717 ## Diffs ####################################
718 $defaultPreferences['diffonly'] = array(
720 'section' => 'rendering/diffs',
721 'label-message' => 'tog-diffonly',
723 $defaultPreferences['norollbackdiff'] = array(
725 'section' => 'rendering/diffs',
726 'label-message' => 'tog-norollbackdiff',
729 ## Page Rendering ##############################
730 global $wgAllowUserCssPrefs;
731 if ( $wgAllowUserCssPrefs ) {
732 $defaultPreferences['underline'] = array(
735 $context->msg( 'underline-never' )->text() => 0,
736 $context->msg( 'underline-always' )->text() => 1,
737 $context->msg( 'underline-default' )->text() => 2,
739 'label-message' => 'tog-underline',
740 'section' => 'rendering/advancedrendering',
744 $stubThresholdValues = array( 50, 100, 500, 1000, 2000, 5000, 10000 );
745 $stubThresholdOptions = array( $context->msg( 'stub-threshold-disabled' )->text() => 0 );
746 foreach ( $stubThresholdValues as $value ) {
747 $stubThresholdOptions[$context->msg( 'size-bytes', $value )->text()] = $value;
750 $defaultPreferences['stubthreshold'] = array(
752 'section' => 'rendering/advancedrendering',
753 'options' => $stubThresholdOptions,
755 'label-raw' => $context->msg( 'stub-threshold' )->text(), // Raw HTML message. Yay?
758 $defaultPreferences['showhiddencats'] = array(
760 'section' => 'rendering/advancedrendering',
761 'label-message' => 'tog-showhiddencats'
764 if ( $wgAllowUserCssPrefs ) {
765 $defaultPreferences['justify'] = array(
767 'section' => 'rendering/advancedrendering',
768 'label-message' => 'tog-justify',
772 $defaultPreferences['numberheadings'] = array(
774 'section' => 'rendering/advancedrendering',
775 'label-message' => 'tog-numberheadings',
781 * @param $context IContextSource
782 * @param $defaultPreferences Array
784 static function editingPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
785 global $wgAllowUserCssPrefs;
787 ## Editing #####################################
788 $defaultPreferences['editsectiononrightclick'] = array(
790 'section' => 'editing/advancedediting',
791 'label-message' => 'tog-editsectiononrightclick',
793 $defaultPreferences['editondblclick'] = array(
795 'section' => 'editing/advancedediting',
796 'label-message' => 'tog-editondblclick',
799 if ( $wgAllowUserCssPrefs ) {
800 $defaultPreferences['editfont'] = array(
802 'section' => 'editing/editor',
803 'label-message' => 'editfont-style',
805 $context->msg( 'editfont-default' )->text() => 'default',
806 $context->msg( 'editfont-monospace' )->text() => 'monospace',
807 $context->msg( 'editfont-sansserif' )->text() => 'sans-serif',
808 $context->msg( 'editfont-serif' )->text() => 'serif',
812 $defaultPreferences['cols'] = array(
814 'label-message' => 'columns',
815 'section' => 'editing/editor',
819 $defaultPreferences['rows'] = array(
821 'label-message' => 'rows',
822 'section' => 'editing/editor',
826 if ( $user->isAllowed( 'minoredit' ) ) {
827 $defaultPreferences['minordefault'] = array(
829 'section' => 'editing/editor',
830 'label-message' => 'tog-minordefault',
833 $defaultPreferences['forceeditsummary'] = array(
835 'section' => 'editing/editor',
836 'label-message' => 'tog-forceeditsummary',
838 $defaultPreferences['useeditwarning'] = array(
840 'section' => 'editing/editor',
841 'label-message' => 'tog-useeditwarning',
843 $defaultPreferences['showtoolbar'] = array(
845 'section' => 'editing/editor',
846 'label-message' => 'tog-showtoolbar',
849 $defaultPreferences['previewonfirst'] = array(
851 'section' => 'editing/preview',
852 'label-message' => 'tog-previewonfirst',
854 $defaultPreferences['previewontop'] = array(
856 'section' => 'editing/preview',
857 'label-message' => 'tog-previewontop',
859 $defaultPreferences['uselivepreview'] = array(
861 'section' => 'editing/preview',
862 'label-message' => 'tog-uselivepreview',
869 * @param $context IContextSource
870 * @param $defaultPreferences Array
872 static function rcPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
873 global $wgRCMaxAge, $wgRCShowWatchingUsers;
875 ## RecentChanges #####################################
876 $defaultPreferences['rcdays'] = array(
878 'label-message' => 'recentchangesdays',
879 'section' => 'rc/displayrc',
881 'max' => ceil( $wgRCMaxAge / ( 3600 * 24 ) ),
882 'help' => $context->msg( 'recentchangesdays-max' )->numParams(
883 ceil( $wgRCMaxAge / ( 3600 * 24 ) ) )->text()
885 $defaultPreferences['rclimit'] = array(
887 'label-message' => 'recentchangescount',
888 'help-message' => 'prefs-help-recentchangescount',
889 'section' => 'rc/displayrc',
891 $defaultPreferences['usenewrc'] = array(
893 'label-message' => 'tog-usenewrc',
894 'section' => 'rc/advancedrc',
896 $defaultPreferences['hideminor'] = array(
898 'label-message' => 'tog-hideminor',
899 'section' => 'rc/advancedrc',
902 if ( $user->useRCPatrol() ) {
903 $defaultPreferences['hidepatrolled'] = array(
905 'section' => 'rc/advancedrc',
906 'label-message' => 'tog-hidepatrolled',
908 $defaultPreferences['newpageshidepatrolled'] = array(
910 'section' => 'rc/advancedrc',
911 'label-message' => 'tog-newpageshidepatrolled',
915 if ( $wgRCShowWatchingUsers ) {
916 $defaultPreferences['shownumberswatching'] = array(
918 'section' => 'rc/advancedrc',
919 'label-message' => 'tog-shownumberswatching',
926 * @param $context IContextSource
927 * @param $defaultPreferences
929 static function watchlistPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
930 global $wgUseRCPatrol, $wgEnableAPI, $wgRCMaxAge;
932 $watchlistdaysMax = ceil( $wgRCMaxAge / ( 3600 * 24 ) );
934 ## Watchlist #####################################
935 $defaultPreferences['watchlistdays'] = array(
938 'max' => $watchlistdaysMax,
939 'section' => 'watchlist/displaywatchlist',
940 'help' => $context->msg( 'prefs-watchlist-days-max' )->numParams(
941 $watchlistdaysMax )->text(),
942 'label-message' => 'prefs-watchlist-days',
944 $defaultPreferences['wllimit'] = array(
948 'label-message' => 'prefs-watchlist-edits',
949 'help' => $context->msg( 'prefs-watchlist-edits-max' )->escaped(),
950 'section' => 'watchlist/displaywatchlist',
952 $defaultPreferences['extendwatchlist'] = array(
954 'section' => 'watchlist/advancedwatchlist',
955 'label-message' => 'tog-extendwatchlist',
957 $defaultPreferences['watchlisthideminor'] = array(
959 'section' => 'watchlist/advancedwatchlist',
960 'label-message' => 'tog-watchlisthideminor',
962 $defaultPreferences['watchlisthidebots'] = array(
964 'section' => 'watchlist/advancedwatchlist',
965 'label-message' => 'tog-watchlisthidebots',
967 $defaultPreferences['watchlisthideown'] = array(
969 'section' => 'watchlist/advancedwatchlist',
970 'label-message' => 'tog-watchlisthideown',
972 $defaultPreferences['watchlisthideanons'] = array(
974 'section' => 'watchlist/advancedwatchlist',
975 'label-message' => 'tog-watchlisthideanons',
977 $defaultPreferences['watchlisthideliu'] = array(
979 'section' => 'watchlist/advancedwatchlist',
980 'label-message' => 'tog-watchlisthideliu',
983 if ( $wgUseRCPatrol ) {
984 $defaultPreferences['watchlisthidepatrolled'] = array(
986 'section' => 'watchlist/advancedwatchlist',
987 'label-message' => 'tog-watchlisthidepatrolled',
992 'edit' => 'watchdefault',
993 'move' => 'watchmoves',
994 'delete' => 'watchdeletion'
998 if ( $user->isAllowed( 'createpage' ) ||
$user->isAllowed( 'createtalk' ) ) {
999 $watchTypes['read'] = 'watchcreations';
1002 foreach ( $watchTypes as $action => $pref ) {
1003 if ( $user->isAllowed( $action ) ) {
1005 // tog-watchdefault, tog-watchmoves, tog-watchdeletion, tog-watchcreations
1006 $defaultPreferences[$pref] = array(
1008 'section' => 'watchlist/advancedwatchlist',
1009 'label-message' => "tog-$pref",
1014 if ( $wgEnableAPI ) {
1015 $defaultPreferences['watchlisttoken'] = array(
1018 $defaultPreferences['watchlisttoken-info'] = array(
1020 'section' => 'watchlist/tokenwatchlist',
1021 'label-message' => 'prefs-watchlist-token',
1022 'default' => $user->getTokenFromOption( 'watchlisttoken' ),
1023 'help-message' => 'prefs-help-watchlist-token2',
1030 * @param $context IContextSource
1031 * @param $defaultPreferences Array
1033 static function searchPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
1034 global $wgContLang, $wgVectorUseSimpleSearch;
1036 if ( $wgVectorUseSimpleSearch ) {
1037 $defaultPreferences['vector-simplesearch'] = array(
1039 'label-message' => 'vector-simplesearch-preference',
1040 'section' => 'searchoptions/displaysearchoptions',
1044 $defaultPreferences['searcheverything'] = array(
1046 'label-message' => 'searcheverything-enable',
1047 'section' => 'searchoptions/advancedsearchoptions',
1050 $nsOptions = $wgContLang->getFormattedNamespaces();
1051 $nsOptions[0] = $context->msg( 'blanknamespace' )->text();
1052 foreach ( $nsOptions as $ns => $name ) {
1054 unset( $nsOptions[$ns] );
1058 $defaultPreferences['searchnamespaces'] = array(
1059 'type' => 'multiselect',
1060 'label-message' => 'defaultns',
1061 'options' => array_flip( $nsOptions ),
1062 'section' => 'searchoptions/advancedsearchoptions',
1063 'prefix' => 'searchNs',
1068 * Dummy, kept for backwards-compatibility.
1070 static function miscPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
1074 * @param $user User The User object
1075 * @param $context IContextSource
1076 * @return Array: text/links to display as key; $skinkey as value
1078 static function generateSkinOptions( $user, IContextSource
$context ) {
1079 global $wgDefaultSkin, $wgAllowUserCss, $wgAllowUserJs;
1082 $mptitle = Title
::newMainPage();
1083 $previewtext = $context->msg( 'skin-preview' )->text();
1085 # Only show members of Skin::getSkinNames() rather than
1086 # $skinNames (skins is all skin names from Language.php)
1087 $validSkinNames = Skin
::getUsableSkins();
1089 # Sort by UI skin name. First though need to update validSkinNames as sometimes
1090 # the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI).
1091 foreach ( $validSkinNames as $skinkey => &$skinname ) {
1092 $msg = $context->msg( "skinname-{$skinkey}" );
1093 if ( $msg->exists() ) {
1094 $skinname = htmlspecialchars( $msg->text() );
1097 asort( $validSkinNames );
1099 foreach ( $validSkinNames as $skinkey => $sn ) {
1100 $linkTools = array();
1102 # Mark the default skin
1103 if ( $skinkey == $wgDefaultSkin ) {
1104 $linkTools[] = $context->msg( 'default' )->escaped();
1107 # Create preview link
1108 $mplink = htmlspecialchars( $mptitle->getLocalURL( array( 'useskin' => $skinkey ) ) );
1109 $linkTools[] = "<a target='_blank' href=\"$mplink\">$previewtext</a>";
1111 # Create links to user CSS/JS pages
1112 if ( $wgAllowUserCss ) {
1113 $cssPage = Title
::makeTitleSafe( NS_USER
, $user->getName() . '/' . $skinkey . '.css' );
1114 $linkTools[] = Linker
::link( $cssPage, $context->msg( 'prefs-custom-css' )->escaped() );
1117 if ( $wgAllowUserJs ) {
1118 $jsPage = Title
::makeTitleSafe( NS_USER
, $user->getName() . '/' . $skinkey . '.js' );
1119 $linkTools[] = Linker
::link( $jsPage, $context->msg( 'prefs-custom-js' )->escaped() );
1122 $display = $sn . ' ' . $context->msg(
1124 $context->getLanguage()->pipeList( $linkTools )
1126 $ret[$display] = $skinkey;
1133 * @param $context IContextSource
1136 static function getDateOptions( IContextSource
$context ) {
1137 $lang = $context->getLanguage();
1138 $dateopts = $lang->getDatePreferences();
1143 if ( !in_array( 'default', $dateopts ) ) {
1144 $dateopts[] = 'default'; // Make sure default is always valid
1148 // KLUGE: site default might not be valid for user language
1149 global $wgDefaultUserOptions;
1150 if ( !in_array( $wgDefaultUserOptions['date'], $dateopts ) ) {
1151 $wgDefaultUserOptions['date'] = 'default';
1154 $epoch = wfTimestampNow();
1155 foreach ( $dateopts as $key ) {
1156 if ( $key == 'default' ) {
1157 $formatted = $context->msg( 'datedefault' )->escaped();
1159 $formatted = htmlspecialchars( $lang->timeanddate( $epoch, false, $key ) );
1161 $ret[$formatted] = $key;
1168 * @param $context IContextSource
1171 static function getImageSizes( IContextSource
$context ) {
1172 global $wgImageLimits;
1175 $pixels = $context->msg( 'unit-pixel' )->text();
1177 foreach ( $wgImageLimits as $index => $limits ) {
1178 $display = "{$limits[0]}×{$limits[1]}" . $pixels;
1179 $ret[$display] = $index;
1186 * @param $context IContextSource
1189 static function getThumbSizes( IContextSource
$context ) {
1190 global $wgThumbLimits;
1193 $pixels = $context->msg( 'unit-pixel' )->text();
1195 foreach ( $wgThumbLimits as $index => $size ) {
1196 $display = $size . $pixels;
1197 $ret[$display] = $index;
1204 * @param $signature string
1205 * @param $alldata array
1206 * @param $form HTMLForm
1207 * @return bool|string
1209 static function validateSignature( $signature, $alldata, $form ) {
1210 global $wgParser, $wgMaxSigChars;
1211 if ( mb_strlen( $signature ) > $wgMaxSigChars ) {
1212 return Xml
::element( 'span', array( 'class' => 'error' ),
1213 $form->msg( 'badsiglength' )->numParams( $wgMaxSigChars )->text() );
1214 } elseif ( isset( $alldata['fancysig'] ) &&
1215 $alldata['fancysig'] &&
1216 $wgParser->validateSig( $signature ) === false
1218 return Xml
::element(
1220 array( 'class' => 'error' ),
1221 $form->msg( 'badsig' )->text()
1229 * @param $signature string
1230 * @param $alldata array
1231 * @param $form HTMLForm
1234 static function cleanSignature( $signature, $alldata, $form ) {
1235 if ( isset( $alldata['fancysig'] ) && $alldata['fancysig'] ) {
1237 $signature = $wgParser->cleanSig( $signature );
1239 // When no fancy sig used, make sure ~{3,5} get removed.
1240 $signature = Parser
::cleanSigInSig( $signature );
1248 * @param $context IContextSource
1249 * @param $formClass string
1250 * @param array $remove array of items to remove
1253 static function getFormObject(
1255 IContextSource
$context,
1256 $formClass = 'PreferencesForm',
1257 array $remove = array()
1259 $formDescriptor = Preferences
::getPreferences( $user, $context );
1260 if ( count( $remove ) ) {
1261 $removeKeys = array_flip( $remove );
1262 $formDescriptor = array_diff_key( $formDescriptor, $removeKeys );
1265 // Remove type=api preferences. They are not intended for rendering in the form.
1266 foreach ( $formDescriptor as $name => $info ) {
1267 if ( isset( $info['type'] ) && $info['type'] === 'api' ) {
1268 unset( $formDescriptor[$name] );
1273 * @var $htmlForm PreferencesForm
1275 $htmlForm = new $formClass( $formDescriptor, $context, 'prefs' );
1277 $htmlForm->setModifiedUser( $user );
1278 $htmlForm->setId( 'mw-prefs-form' );
1279 $htmlForm->setSubmitText( $context->msg( 'saveprefs' )->text() );
1280 # Used message keys: 'accesskey-preferences-save', 'tooltip-preferences-save'
1281 $htmlForm->setSubmitTooltip( 'preferences-save' );
1282 $htmlForm->setSubmitID( 'prefsubmit' );
1283 $htmlForm->setSubmitCallback( array( 'Preferences', 'tryFormSubmit' ) );
1289 * @param $context IContextSource
1292 static function getTimezoneOptions( IContextSource
$context ) {
1295 global $wgLocalTZoffset;
1296 $timestamp = MWTimestamp
::getLocalInstance();
1297 // Check that $wgLocalTZoffset is the same as the local time zone offset
1298 if ( $wgLocalTZoffset == $timestamp->format( 'Z' ) / 60 ) {
1299 $server_tz_msg = $context->msg(
1300 'timezoneuseserverdefault',
1301 $timestamp->getTimezone()->getName()
1304 $tzstring = sprintf(
1306 floor( $wgLocalTZoffset / 60 ),
1307 abs( $wgLocalTZoffset ) %
60
1309 $server_tz_msg = $context->msg( 'timezoneuseserverdefault', $tzstring )->text();
1311 $opt[$server_tz_msg] = "System|$wgLocalTZoffset";
1312 $opt[$context->msg( 'timezoneuseoffset' )->text()] = 'other';
1313 $opt[$context->msg( 'guesstimezone' )->text()] = 'guess';
1315 if ( function_exists( 'timezone_identifiers_list' ) ) {
1316 # Read timezone list
1317 $tzs = timezone_identifiers_list();
1320 $tzRegions = array();
1321 $tzRegions['Africa'] = $context->msg( 'timezoneregion-africa' )->text();
1322 $tzRegions['America'] = $context->msg( 'timezoneregion-america' )->text();
1323 $tzRegions['Antarctica'] = $context->msg( 'timezoneregion-antarctica' )->text();
1324 $tzRegions['Arctic'] = $context->msg( 'timezoneregion-arctic' )->text();
1325 $tzRegions['Asia'] = $context->msg( 'timezoneregion-asia' )->text();
1326 $tzRegions['Atlantic'] = $context->msg( 'timezoneregion-atlantic' )->text();
1327 $tzRegions['Australia'] = $context->msg( 'timezoneregion-australia' )->text();
1328 $tzRegions['Europe'] = $context->msg( 'timezoneregion-europe' )->text();
1329 $tzRegions['Indian'] = $context->msg( 'timezoneregion-indian' )->text();
1330 $tzRegions['Pacific'] = $context->msg( 'timezoneregion-pacific' )->text();
1331 asort( $tzRegions );
1333 $prefill = array_fill_keys( array_values( $tzRegions ), array() );
1334 $opt = array_merge( $opt, $prefill );
1336 $now = date_create( 'now' );
1338 foreach ( $tzs as $tz ) {
1339 $z = explode( '/', $tz, 2 );
1341 # timezone_identifiers_list() returns a number of
1342 # backwards-compatibility entries. This filters them out of the
1343 # list presented to the user.
1344 if ( count( $z ) != 2 ||
!array_key_exists( $z[0], $tzRegions ) ) {
1349 $z[0] = $tzRegions[$z[0]];
1351 $minDiff = floor( timezone_offset_get( timezone_open( $tz ), $now ) / 60 );
1353 $display = str_replace( '_', ' ', $z[0] . '/' . $z[1] );
1354 $value = "ZoneInfo|$minDiff|$tz";
1356 $opt[$z[0]][$display] = $value;
1367 static function filterIntval( $value, $alldata ) {
1368 return intval( $value );
1376 static function filterTimezoneInput( $tz, $alldata ) {
1377 $data = explode( '|', $tz, 3 );
1378 switch ( $data[0] ) {
1383 $data = explode( ':', $tz, 2 );
1384 if ( count( $data ) == 2 ) {
1385 $data[0] = intval( $data[0] );
1386 $data[1] = intval( $data[1] );
1387 $minDiff = abs( $data[0] ) * 60 +
$data[1];
1388 if ( $data[0] < 0 ) {
1389 $minDiff = - $minDiff;
1392 $minDiff = intval( $data[0] ) * 60;
1395 # Max is +14:00 and min is -12:00, see:
1396 # http://en.wikipedia.org/wiki/Timezone
1397 $minDiff = min( $minDiff, 840 ); # 14:00
1398 $minDiff = max( $minDiff, - 720 ); # -12:00
1399 return 'Offset|' . $minDiff;
1404 * Handle the form submission if everything validated properly
1407 * @param $form PreferencesForm
1408 * @param $entryPoint string
1409 * @return bool|Status|string
1411 static function tryFormSubmit( $formData, $form, $entryPoint = 'internal' ) {
1412 global $wgHiddenPrefs, $wgAuth;
1414 $user = $form->getModifiedUser();
1417 if ( !$user->isAllowedAny( 'editmyprivateinfo', 'editmyoptions' ) ) {
1418 return Status
::newFatal( 'mypreferencesprotected' );
1422 foreach ( array_keys( $formData ) as $name ) {
1423 if ( isset( self
::$saveFilters[$name] ) ) {
1425 call_user_func( self
::$saveFilters[$name], $formData[$name], $formData );
1429 // Fortunately, the realname field is MUCH simpler
1430 // (not really "private", but still shouldn't be edited without permission)
1431 if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->isAllowed( 'editmyprivateinfo' ) ) {
1432 $realName = $formData['realname'];
1433 $user->setRealName( $realName );
1436 if ( $user->isAllowed( 'editmyoptions' ) ) {
1437 foreach ( self
::$saveBlacklist as $b ) {
1438 unset( $formData[$b] );
1441 # If users have saved a value for a preference which has subsequently been disabled
1442 # via $wgHiddenPrefs, we don't want to destroy that setting in case the preference
1443 # is subsequently re-enabled
1444 foreach ( $wgHiddenPrefs as $pref ) {
1445 # If the user has not set a non-default value here, the default will be returned
1446 # and subsequently discarded
1447 $formData[$pref] = $user->getOption( $pref, null, true );
1450 // Keep old preferences from interfering due to back-compat code, etc.
1451 $user->resetOptions( 'unused', $form->getContext() );
1453 foreach ( $formData as $key => $value ) {
1454 $user->setOption( $key, $value );
1457 $user->saveSettings();
1460 $wgAuth->updateExternalDB( $user );
1467 * @param $form PreferencesForm
1470 public static function tryUISubmit( $formData, $form ) {
1471 $res = self
::tryFormSubmit( $formData, $form, 'ui' );
1474 $urlOptions = array( 'success' => 1 );
1476 if ( $res === 'eauth' ) {
1477 $urlOptions['eauth'] = 1;
1480 $urlOptions +
= $form->getExtraSuccessRedirectParameters();
1482 $url = $form->getTitle()->getFullURL( $urlOptions );
1484 $form->getContext()->getOutput()->redirect( $url );
1487 return Status
::newGood();
1491 * Try to set a user's email address.
1492 * This does *not* try to validate the address.
1493 * Caller is responsible for checking $wgAuth and 'editmyprivateinfo'
1496 * @deprecated in 1.20; use User::setEmailWithConfirmation() instead.
1498 * @param string $newaddr New email address
1499 * @return Array (true on success or Status on failure, info string)
1501 public static function trySetUserEmail( User
$user, $newaddr ) {
1502 wfDeprecated( __METHOD__
, '1.20' );
1504 $result = $user->setEmailWithConfirmation( $newaddr );
1505 if ( $result->isGood() ) {
1506 return array( true, $result->value
);
1508 return array( $result, 'mailerror' );
1513 * @deprecated in 1.19
1517 public static function loadOldSearchNs( $user ) {
1518 wfDeprecated( __METHOD__
, '1.19' );
1520 $searchableNamespaces = SearchEngine
::searchableNamespaces();
1521 // Back compat with old format
1524 foreach ( $searchableNamespaces as $ns => $name ) {
1525 if ( $user->getOption( 'searchNs' . $ns ) ) {
1534 /** Some tweaks to allow js prefs to work */
1535 class PreferencesForm
extends HTMLForm
{
1536 // Override default value from HTMLForm
1537 protected $mSubSectionBeforeFields = false;
1539 private $modifiedUser;
1544 public function setModifiedUser( $user ) {
1545 $this->modifiedUser
= $user;
1551 public function getModifiedUser() {
1552 if ( $this->modifiedUser
=== null ) {
1553 return $this->getUser();
1555 return $this->modifiedUser
;
1560 * Get extra parameters for the query string when redirecting after
1565 public function getExtraSuccessRedirectParameters() {
1570 * @param $html string
1573 function wrapForm( $html ) {
1574 $html = Xml
::tags( 'div', array( 'id' => 'preferences' ), $html );
1576 return parent
::wrapForm( $html );
1582 function getButtons() {
1583 if ( !$this->getModifiedUser()->isAllowedAny( 'editmyprivateinfo', 'editmyoptions' ) ) {
1587 $html = parent
::getButtons();
1589 if ( $this->getModifiedUser()->isAllowed( 'editmyoptions' ) ) {
1590 $t = SpecialPage
::getTitleFor( 'Preferences', 'reset' );
1592 $html .= "\n" . Linker
::link( $t, $this->msg( 'restoreprefs' )->escaped() );
1594 $html = Xml
::tags( 'div', array( 'class' => 'mw-prefs-buttons' ), $html );
1601 * Separate multi-option preferences into multiple preferences, since we
1602 * have to store them separately
1603 * @param $data array
1606 function filterDataForSubmit( $data ) {
1607 foreach ( $this->mFlatFields
as $fieldname => $field ) {
1608 if ( $field instanceof HTMLNestedFilterable
) {
1609 $info = $field->mParams
;
1610 $prefix = isset( $info['prefix'] ) ?
$info['prefix'] : $fieldname;
1611 foreach ( $field->filterDataForSubmit( $data[$fieldname] ) as $key => $value ) {
1612 $data["$prefix$key"] = $value;
1614 unset( $data[$fieldname] );
1622 * Get the whole body of the form.
1625 function getBody() {
1626 return $this->displaySection( $this->mFieldTree
, '', 'mw-prefsection-' );
1630 * Get the "<legend>" for a given section key. Normally this is the
1631 * prefs-$key message but we'll allow extensions to override it.
1632 * @param $key string
1635 function getLegend( $key ) {
1636 $legend = parent
::getLegend( $key );
1637 wfRunHooks( 'PreferencesGetLegend', array( $this, $key, &$legend ) );