b3ee207f4666d3d9b00789411398d01ec59b517e
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.
50 protected static $defaultPreferences = null;
53 protected static $saveFilters = array(
54 'timecorrection' => array( 'Preferences', 'filterTimezoneInput' ),
55 'cols' => array( 'Preferences', 'filterIntval' ),
56 'rows' => array( 'Preferences', 'filterIntval' ),
57 'rclimit' => array( 'Preferences', 'filterIntval' ),
58 'wllimit' => array( 'Preferences', 'filterIntval' ),
59 'searchlimit' => array( 'Preferences', 'filterIntval' ),
62 // Stuff that shouldn't be saved as a preference.
63 private static $saveBlacklist = array(
71 static function getSaveBlacklist() {
72 return self
::$saveBlacklist;
78 * @param IContextSource $context
81 static function getPreferences( $user, IContextSource
$context ) {
82 if ( self
::$defaultPreferences ) {
83 return self
::$defaultPreferences;
86 $defaultPreferences = array();
88 self
::profilePreferences( $user, $context, $defaultPreferences );
89 self
::skinPreferences( $user, $context, $defaultPreferences );
90 self
::datetimePreferences( $user, $context, $defaultPreferences );
91 self
::filesPreferences( $user, $context, $defaultPreferences );
92 self
::renderingPreferences( $user, $context, $defaultPreferences );
93 self
::editingPreferences( $user, $context, $defaultPreferences );
94 self
::rcPreferences( $user, $context, $defaultPreferences );
95 self
::watchlistPreferences( $user, $context, $defaultPreferences );
96 self
::searchPreferences( $user, $context, $defaultPreferences );
97 self
::miscPreferences( $user, $context, $defaultPreferences );
99 Hooks
::run( 'GetPreferences', array( $user, &$defaultPreferences ) );
101 self
::loadPreferenceValues( $user, $context, $defaultPreferences );
102 self
::$defaultPreferences = $defaultPreferences;
103 return $defaultPreferences;
107 * Loads existing values for a given array of preferences
108 * @throws MWException
110 * @param IContextSource $context
111 * @param array $defaultPreferences Array to load values for
114 static function loadPreferenceValues( $user, $context, &$defaultPreferences ) {
115 # # Remove preferences that wikis don't want to use
116 foreach ( $context->getConfig()->get( 'HiddenPrefs' ) as $pref ) {
117 if ( isset( $defaultPreferences[$pref] ) ) {
118 unset( $defaultPreferences[$pref] );
122 # # Make sure that form fields have their parent set. See bug 41337.
123 $dummyForm = new HTMLForm( array(), $context );
125 $disable = !$user->isAllowed( 'editmyoptions' );
127 $defaultOptions = User
::getDefaultOptions();
128 # # Prod in defaults from the user
129 foreach ( $defaultPreferences as $name => &$info ) {
130 $prefFromUser = self
::getOptionFromUser( $name, $info, $user );
131 if ( $disable && !in_array( $name, self
::$saveBlacklist ) ) {
132 $info['disabled'] = 'disabled';
134 $field = HTMLForm
::loadInputFromParameters( $name, $info, $dummyForm ); // For validation
135 $globalDefault = isset( $defaultOptions[$name] )
136 ?
$defaultOptions[$name]
139 // If it validates, set it as the default
140 if ( isset( $info['default'] ) ) {
141 // Already set, no problem
143 } elseif ( !is_null( $prefFromUser ) && // Make sure we're not just pulling nothing
144 $field->validate( $prefFromUser, $user->getOptions() ) === true ) {
145 $info['default'] = $prefFromUser;
146 } elseif ( $field->validate( $globalDefault, $user->getOptions() ) === true ) {
147 $info['default'] = $globalDefault;
149 throw new MWException( "Global default '$globalDefault' is invalid for field $name" );
153 return $defaultPreferences;
157 * Pull option from a user account. Handles stuff like array-type preferences.
159 * @param string $name
162 * @return array|string
164 static function getOptionFromUser( $name, $info, $user ) {
165 $val = $user->getOption( $name );
167 // Handling for multiselect preferences
168 if ( ( isset( $info['type'] ) && $info['type'] == 'multiselect' ) ||
169 ( isset( $info['class'] ) && $info['class'] == 'HTMLMultiSelectField' ) ) {
170 $options = HTMLFormField
::flattenOptions( $info['options'] );
171 $prefix = isset( $info['prefix'] ) ?
$info['prefix'] : $name;
174 foreach ( $options as $value ) {
175 if ( $user->getOption( "$prefix$value" ) ) {
181 // Handling for checkmatrix preferences
182 if ( ( isset( $info['type'] ) && $info['type'] == 'checkmatrix' ) ||
183 ( isset( $info['class'] ) && $info['class'] == 'HTMLCheckMatrix' ) ) {
184 $columns = HTMLFormField
::flattenOptions( $info['columns'] );
185 $rows = HTMLFormField
::flattenOptions( $info['rows'] );
186 $prefix = isset( $info['prefix'] ) ?
$info['prefix'] : $name;
189 foreach ( $columns as $column ) {
190 foreach ( $rows as $row ) {
191 if ( $user->getOption( "$prefix$column-$row" ) ) {
192 $val[] = "$column-$row";
203 * @param IContextSource $context
204 * @param array $defaultPreferences
207 static function profilePreferences( $user, IContextSource
$context, &$defaultPreferences ) {
208 global $wgAuth, $wgContLang, $wgParser;
210 $config = $context->getConfig();
211 // retrieving user name for GENDER and misc.
212 $userName = $user->getName();
214 # # User info #####################################
216 $defaultPreferences['username'] = array(
218 'label-message' => array( 'username', $userName ),
219 'default' => $userName,
220 'section' => 'personal/info',
223 # Get groups to which the user belongs
224 $userEffectiveGroups = $user->getEffectiveGroups();
225 $userGroups = $userMembers = array();
226 foreach ( $userEffectiveGroups as $ueg ) {
228 // Skip the default * group, seems useless here
231 $groupName = User
::getGroupName( $ueg );
232 $userGroups[] = User
::makeGroupLinkHTML( $ueg, $groupName );
234 $memberName = User
::getGroupMember( $ueg, $userName );
235 $userMembers[] = User
::makeGroupLinkHTML( $ueg, $memberName );
237 asort( $userGroups );
238 asort( $userMembers );
240 $lang = $context->getLanguage();
242 $defaultPreferences['usergroups'] = array(
244 'label' => $context->msg( 'prefs-memberingroups' )->numParams(
245 count( $userGroups ) )->params( $userName )->parse(),
246 'default' => $context->msg( 'prefs-memberingroups-type' )
247 ->rawParams( $lang->commaList( $userGroups ), $lang->commaList( $userMembers ) )
250 'section' => 'personal/info',
253 $editCount = Linker
::link( SpecialPage
::getTitleFor( "Contributions", $userName ),
254 $lang->formatNum( $user->getEditCount() ) );
256 $defaultPreferences['editcount'] = array(
259 'label-message' => 'prefs-edits',
260 'default' => $editCount,
261 'section' => 'personal/info',
264 if ( $user->getRegistration() ) {
265 $displayUser = $context->getUser();
266 $userRegistration = $user->getRegistration();
267 $defaultPreferences['registrationdate'] = array(
269 'label-message' => 'prefs-registration',
270 'default' => $context->msg(
271 'prefs-registration-date-time',
272 $lang->userTimeAndDate( $userRegistration, $displayUser ),
273 $lang->userDate( $userRegistration, $displayUser ),
274 $lang->userTime( $userRegistration, $displayUser )
276 'section' => 'personal/info',
280 $canViewPrivateInfo = $user->isAllowed( 'viewmyprivateinfo' );
281 $canEditPrivateInfo = $user->isAllowed( 'editmyprivateinfo' );
283 // Actually changeable stuff
284 $defaultPreferences['realname'] = array(
285 // (not really "private", but still shouldn't be edited without permission)
286 'type' => $canEditPrivateInfo && $wgAuth->allowPropChange( 'realname' ) ?
'text' : 'info',
287 'default' => $user->getRealName(),
288 'section' => 'personal/info',
289 'label-message' => 'yourrealname',
290 'help-message' => 'prefs-help-realname',
293 if ( $canEditPrivateInfo && $wgAuth->allowPasswordChange() ) {
294 $link = Linker
::link( SpecialPage
::getTitleFor( 'ChangePassword' ),
295 $context->msg( 'prefs-resetpass' )->escaped(), array(),
296 array( 'returnto' => SpecialPage
::getTitleFor( 'Preferences' )->getPrefixedText() ) );
298 $defaultPreferences['password'] = array(
302 'label-message' => 'yourpassword',
303 'section' => 'personal/info',
306 // Only show prefershttps if secure login is turned on
307 if ( $config->get( 'SecureLogin' ) && wfCanIPUseHTTPS( $context->getRequest()->getIP() ) ) {
308 $defaultPreferences['prefershttps'] = array(
310 'label-message' => 'tog-prefershttps',
311 'help-message' => 'prefs-help-prefershttps',
312 'section' => 'personal/info'
317 $languages = Language
::fetchLanguageNames( null, 'mw' );
318 $languageCode = $config->get( 'LanguageCode' );
319 if ( !array_key_exists( $languageCode, $languages ) ) {
320 $languages[$languageCode] = $languageCode;
325 foreach ( $languages as $code => $name ) {
326 $display = wfBCP47( $code ) . ' - ' . $name;
327 $options[$display] = $code;
329 $defaultPreferences['language'] = array(
331 'section' => 'personal/i18n',
332 'options' => $options,
333 'label-message' => 'yourlanguage',
336 $defaultPreferences['gender'] = array(
338 'section' => 'personal/i18n',
340 $context->msg( 'parentheses' )
341 ->params( $context->msg( 'gender-unknown' )->plain() )
342 ->escaped() => 'unknown',
343 $context->msg( 'gender-female' )->escaped() => 'female',
344 $context->msg( 'gender-male' )->escaped() => 'male',
346 'label-message' => 'yourgender',
347 'help-message' => 'prefs-help-gender',
350 // see if there are multiple language variants to choose from
351 if ( !$config->get( 'DisableLangConversion' ) ) {
352 foreach ( LanguageConverter
::$languagesWithVariants as $langCode ) {
353 if ( $langCode == $wgContLang->getCode() ) {
354 $variants = $wgContLang->getVariants();
356 if ( count( $variants ) <= 1 ) {
360 $variantArray = array();
361 foreach ( $variants as $v ) {
362 $v = str_replace( '_', '-', strtolower( $v ) );
363 $variantArray[$v] = $lang->getVariantname( $v, false );
367 foreach ( $variantArray as $code => $name ) {
368 $display = wfBCP47( $code ) . ' - ' . $name;
369 $options[$display] = $code;
372 $defaultPreferences['variant'] = array(
373 'label-message' => 'yourvariant',
375 'options' => $options,
376 'section' => 'personal/i18n',
377 'help-message' => 'prefs-help-variant',
380 $defaultPreferences["variant-$langCode"] = array(
387 // Stuff from Language::getExtraUserToggles()
388 // FIXME is this dead code? $extraUserToggles doesn't seem to be defined for any language
389 $toggles = $wgContLang->getExtraUserToggles();
391 foreach ( $toggles as $toggle ) {
392 $defaultPreferences[$toggle] = array(
394 'section' => 'personal/i18n',
395 'label-message' => "tog-$toggle",
399 // show a preview of the old signature first
400 $oldsigWikiText = $wgParser->preSaveTransform(
402 $context->getTitle(),
404 ParserOptions
::newFromContext( $context )
406 $oldsigHTML = $context->getOutput()->parseInline( $oldsigWikiText, true, true );
407 $defaultPreferences['oldsig'] = array(
410 'label-message' => 'tog-oldsig',
411 'default' => $oldsigHTML,
412 'section' => 'personal/signature',
414 $defaultPreferences['nickname'] = array(
415 'type' => $wgAuth->allowPropChange( 'nickname' ) ?
'text' : 'info',
416 'maxlength' => $config->get( 'MaxSigChars' ),
417 'label-message' => 'yournick',
418 'validation-callback' => array( 'Preferences', 'validateSignature' ),
419 'section' => 'personal/signature',
420 'filter-callback' => array( 'Preferences', 'cleanSignature' ),
422 $defaultPreferences['fancysig'] = array(
424 'label-message' => 'tog-fancysig',
425 // show general help about signature at the bottom of the section
426 'help-message' => 'prefs-help-signature',
427 'section' => 'personal/signature'
432 if ( $config->get( 'EnableEmail' ) ) {
433 if ( $canViewPrivateInfo ) {
434 $helpMessages[] = $config->get( 'EmailConfirmToEdit' )
435 ?
'prefs-help-email-required'
436 : 'prefs-help-email';
438 if ( $config->get( 'EnableUserEmail' ) ) {
439 // additional messages when users can send email to each other
440 $helpMessages[] = 'prefs-help-email-others';
443 $emailAddress = $user->getEmail() ?
htmlspecialchars( $user->getEmail() ) : '';
444 if ( $canEditPrivateInfo && $wgAuth->allowPropChange( 'emailaddress' ) ) {
445 $link = Linker
::link(
446 SpecialPage
::getTitleFor( 'ChangeEmail' ),
447 $context->msg( $user->getEmail() ?
'prefs-changeemail' : 'prefs-setemail' )->escaped(),
449 array( 'returnto' => SpecialPage
::getTitleFor( 'Preferences' )->getPrefixedText() ) );
451 $emailAddress .= $emailAddress == '' ?
$link : (
452 $context->msg( 'word-separator' )->escaped()
453 . $context->msg( 'parentheses' )->rawParams( $link )->escaped()
457 $defaultPreferences['emailaddress'] = array(
460 'default' => $emailAddress,
461 'label-message' => 'youremail',
462 'section' => 'personal/email',
463 'help-messages' => $helpMessages,
464 # 'cssclass' chosen below
468 $disableEmailPrefs = false;
470 if ( $config->get( 'EmailAuthentication' ) ) {
471 $emailauthenticationclass = 'mw-email-not-authenticated';
472 if ( $user->getEmail() ) {
473 if ( $user->getEmailAuthenticationTimestamp() ) {
474 // date and time are separate parameters to facilitate localisation.
475 // $time is kept for backward compat reasons.
476 // 'emailauthenticated' is also used in SpecialConfirmemail.php
477 $displayUser = $context->getUser();
478 $emailTimestamp = $user->getEmailAuthenticationTimestamp();
479 $time = $lang->userTimeAndDate( $emailTimestamp, $displayUser );
480 $d = $lang->userDate( $emailTimestamp, $displayUser );
481 $t = $lang->userTime( $emailTimestamp, $displayUser );
482 $emailauthenticated = $context->msg( 'emailauthenticated',
483 $time, $d, $t )->parse() . '<br />';
484 $disableEmailPrefs = false;
485 $emailauthenticationclass = 'mw-email-authenticated';
487 $disableEmailPrefs = true;
488 $emailauthenticated = $context->msg( 'emailnotauthenticated' )->parse() . '<br />' .
490 SpecialPage
::getTitleFor( 'Confirmemail' ),
491 $context->msg( 'emailconfirmlink' )->escaped()
493 $emailauthenticationclass = "mw-email-not-authenticated";
496 $disableEmailPrefs = true;
497 $emailauthenticated = $context->msg( 'noemailprefs' )->escaped();
498 $emailauthenticationclass = 'mw-email-none';
501 if ( $canViewPrivateInfo ) {
502 $defaultPreferences['emailauthentication'] = array(
505 'section' => 'personal/email',
506 'label-message' => 'prefs-emailconfirm-label',
507 'default' => $emailauthenticated,
508 # Apply the same CSS class used on the input to the message:
509 'cssclass' => $emailauthenticationclass,
511 $defaultPreferences['emailaddress']['cssclass'] = $emailauthenticationclass;
515 if ( $config->get( 'EnableUserEmail' ) && $user->isAllowed( 'sendemail' ) ) {
516 $defaultPreferences['disablemail'] = array(
519 'section' => 'personal/email',
520 'label-message' => 'allowemail',
521 'disabled' => $disableEmailPrefs,
523 $defaultPreferences['ccmeonemails'] = array(
525 'section' => 'personal/email',
526 'label-message' => 'tog-ccmeonemails',
527 'disabled' => $disableEmailPrefs,
531 if ( $config->get( 'EnotifWatchlist' ) ) {
532 $defaultPreferences['enotifwatchlistpages'] = array(
534 'section' => 'personal/email',
535 'label-message' => 'tog-enotifwatchlistpages',
536 'disabled' => $disableEmailPrefs,
539 if ( $config->get( 'EnotifUserTalk' ) ) {
540 $defaultPreferences['enotifusertalkpages'] = array(
542 'section' => 'personal/email',
543 'label-message' => 'tog-enotifusertalkpages',
544 'disabled' => $disableEmailPrefs,
547 if ( $config->get( 'EnotifUserTalk' ) ||
$config->get( 'EnotifWatchlist' ) ) {
548 $defaultPreferences['enotifminoredits'] = array(
550 'section' => 'personal/email',
551 'label-message' => 'tog-enotifminoredits',
552 'disabled' => $disableEmailPrefs,
555 if ( $config->get( 'EnotifRevealEditorAddress' ) ) {
556 $defaultPreferences['enotifrevealaddr'] = array(
558 'section' => 'personal/email',
559 'label-message' => 'tog-enotifrevealaddr',
560 'disabled' => $disableEmailPrefs,
569 * @param IContextSource $context
570 * @param array $defaultPreferences
573 static function skinPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
574 # # Skin #####################################
576 // Skin selector, if there is at least one valid skin
577 $skinOptions = self
::generateSkinOptions( $user, $context );
578 if ( $skinOptions ) {
579 $defaultPreferences['skin'] = array(
581 'options' => $skinOptions,
583 'section' => 'rendering/skin',
587 $config = $context->getConfig();
588 $allowUserCss = $config->get( 'AllowUserCss' );
589 $allowUserJs = $config->get( 'AllowUserJs' );
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 ( $allowUserCss ||
$allowUserJs ) {
594 $linkTools = array();
595 $userName = $user->getName();
597 if ( $allowUserCss ) {
598 $cssPage = Title
::makeTitleSafe( NS_USER
, $userName . '/common.css' );
599 $linkTools[] = Linker
::link( $cssPage, $context->msg( 'prefs-custom-css' )->escaped() );
602 if ( $allowUserJs ) {
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 IContextSource $context
620 * @param array $defaultPreferences
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 IContextSource $context
641 * @param array $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' => 'rendering/dateformat',
657 $now = wfTimestampNow();
658 $lang = $context->getLanguage();
659 $nowlocal = Xml
::element( 'span', array( 'id' => 'wpLocalTime' ),
660 $lang->userTime( $now, $user ) );
661 $nowserver = $lang->userTime( $now, $user,
662 array( 'format' => false, 'timecorrection' => false ) ) .
663 Html
::hidden( 'wpServerTime', (int)substr( $now, 8, 2 ) * 60 +
(int)substr( $now, 10, 2 ) );
665 $defaultPreferences['nowserver'] = array(
668 'label-message' => 'servertime',
669 'default' => $nowserver,
670 'section' => 'rendering/timeoffset',
673 $defaultPreferences['nowlocal'] = array(
676 'label-message' => 'localtime',
677 'default' => $nowlocal,
678 'section' => 'rendering/timeoffset',
681 // Grab existing pref.
682 $tzOffset = $user->getOption( 'timecorrection' );
683 $tz = explode( '|', $tzOffset, 3 );
685 $tzOptions = self
::getTimezoneOptions( $context );
687 $tzSetting = $tzOffset;
688 if ( count( $tz ) > 1 && $tz[0] == 'Offset' ) {
690 $tzSetting = sprintf( '%+03d:%02d', floor( $minDiff / 60 ), abs( $minDiff ) %
60 );
691 } elseif ( count( $tz ) > 1 && $tz[0] == 'ZoneInfo' &&
692 !in_array( $tzOffset, HTMLFormField
::flattenOptions( $tzOptions ) )
694 # Timezone offset can vary with DST
695 $userTZ = timezone_open( $tz[2] );
696 if ( $userTZ !== false ) {
697 $minDiff = floor( timezone_offset_get( $userTZ, date_create( 'now' ) ) / 60 );
698 $tzSetting = "ZoneInfo|$minDiff|{$tz[2]}";
702 $defaultPreferences['timecorrection'] = array(
703 'class' => 'HTMLSelectOrOtherField',
704 'label-message' => 'timezonelegend',
705 'options' => $tzOptions,
706 'default' => $tzSetting,
708 'section' => 'rendering/timeoffset',
714 * @param IContextSource $context
715 * @param array $defaultPreferences
717 static function renderingPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
718 # # Diffs ####################################
719 $defaultPreferences['diffonly'] = array(
721 'section' => 'rendering/diffs',
722 'label-message' => 'tog-diffonly',
724 $defaultPreferences['norollbackdiff'] = array(
726 'section' => 'rendering/diffs',
727 'label-message' => 'tog-norollbackdiff',
730 # # Page Rendering ##############################
731 if ( $context->getConfig()->get( 'AllowUserCssPrefs' ) ) {
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,
754 // This is not a raw HTML message; label-raw is needed for the manual <a></a>
755 'label-raw' => $context->msg( 'stub-threshold' )->rawParams(
756 '<a href="#" class="stub">' .
757 $context->msg( 'stub-threshold-sample-link' )->parse() .
761 $defaultPreferences['showhiddencats'] = array(
763 'section' => 'rendering/advancedrendering',
764 'label-message' => 'tog-showhiddencats'
767 $defaultPreferences['numberheadings'] = array(
769 'section' => 'rendering/advancedrendering',
770 'label-message' => 'tog-numberheadings',
776 * @param IContextSource $context
777 * @param array $defaultPreferences
779 static function editingPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
780 # # Editing #####################################
781 $defaultPreferences['editsectiononrightclick'] = array(
783 'section' => 'editing/advancedediting',
784 'label-message' => 'tog-editsectiononrightclick',
786 $defaultPreferences['editondblclick'] = array(
788 'section' => 'editing/advancedediting',
789 'label-message' => 'tog-editondblclick',
792 if ( $context->getConfig()->get( 'AllowUserCssPrefs' ) ) {
793 $defaultPreferences['editfont'] = array(
795 'section' => 'editing/editor',
796 'label-message' => 'editfont-style',
798 $context->msg( 'editfont-default' )->text() => 'default',
799 $context->msg( 'editfont-monospace' )->text() => 'monospace',
800 $context->msg( 'editfont-sansserif' )->text() => 'sans-serif',
801 $context->msg( 'editfont-serif' )->text() => 'serif',
805 $defaultPreferences['cols'] = array(
807 'label-message' => 'columns',
808 'section' => 'editing/editor',
812 $defaultPreferences['rows'] = array(
814 'label-message' => 'rows',
815 'section' => 'editing/editor',
819 if ( $user->isAllowed( 'minoredit' ) ) {
820 $defaultPreferences['minordefault'] = array(
822 'section' => 'editing/editor',
823 'label-message' => 'tog-minordefault',
826 $defaultPreferences['forceeditsummary'] = array(
828 'section' => 'editing/editor',
829 'label-message' => 'tog-forceeditsummary',
831 $defaultPreferences['useeditwarning'] = array(
833 'section' => 'editing/editor',
834 'label-message' => 'tog-useeditwarning',
836 $defaultPreferences['showtoolbar'] = array(
838 'section' => 'editing/editor',
839 'label-message' => 'tog-showtoolbar',
842 $defaultPreferences['previewonfirst'] = array(
844 'section' => 'editing/preview',
845 'label-message' => 'tog-previewonfirst',
847 $defaultPreferences['previewontop'] = array(
849 'section' => 'editing/preview',
850 'label-message' => 'tog-previewontop',
852 $defaultPreferences['uselivepreview'] = array(
854 'section' => 'editing/preview',
855 'label-message' => 'tog-uselivepreview',
862 * @param IContextSource $context
863 * @param array $defaultPreferences
865 static function rcPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
866 $config = $context->getConfig();
867 $rcMaxAge = $config->get( 'RCMaxAge' );
868 # # RecentChanges #####################################
869 $defaultPreferences['rcdays'] = array(
871 'label-message' => 'recentchangesdays',
872 'section' => 'rc/displayrc',
874 'max' => ceil( $rcMaxAge / ( 3600 * 24 ) ),
875 'help' => $context->msg( 'recentchangesdays-max' )->numParams(
876 ceil( $rcMaxAge / ( 3600 * 24 ) ) )->escaped()
878 $defaultPreferences['rclimit'] = array(
880 'label-message' => 'recentchangescount',
881 'help-message' => 'prefs-help-recentchangescount',
882 'section' => 'rc/displayrc',
884 $defaultPreferences['usenewrc'] = array(
886 'label-message' => 'tog-usenewrc',
887 'section' => 'rc/advancedrc',
889 $defaultPreferences['hideminor'] = array(
891 'label-message' => 'tog-hideminor',
892 'section' => 'rc/advancedrc',
895 if ( $user->useRCPatrol() ) {
896 $defaultPreferences['hidepatrolled'] = array(
898 'section' => 'rc/advancedrc',
899 'label-message' => 'tog-hidepatrolled',
903 if ( $user->useNPPatrol() ) {
904 $defaultPreferences['newpageshidepatrolled'] = array(
906 'section' => 'rc/advancedrc',
907 'label-message' => 'tog-newpageshidepatrolled',
911 if ( $config->get( 'RCShowWatchingUsers' ) ) {
912 $defaultPreferences['shownumberswatching'] = array(
914 'section' => 'rc/advancedrc',
915 'label-message' => 'tog-shownumberswatching',
922 * @param IContextSource $context
923 * @param array $defaultPreferences
925 static function watchlistPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
926 $config = $context->getConfig();
927 $watchlistdaysMax = ceil( $config->get( 'RCMaxAge' ) / ( 3600 * 24 ) );
929 # # Watchlist #####################################
930 if ( $user->isAllowed( 'editmywatchlist' ) ) {
931 $editWatchlistLinks = array();
932 $editWatchlistModes = array(
933 'edit' => array( 'EditWatchlist', false ),
934 'raw' => array( 'EditWatchlist', 'raw' ),
935 'clear' => array( 'EditWatchlist', 'clear' ),
937 foreach ( $editWatchlistModes as $editWatchlistMode => $mode ) {
938 // Messages: prefs-editwatchlist-edit, prefs-editwatchlist-raw, prefs-editwatchlist-clear
939 $editWatchlistLinks[] = Linker
::linkKnown(
940 SpecialPage
::getTitleFor( $mode[0], $mode[1] ),
941 $context->msg( "prefs-editwatchlist-{$editWatchlistMode}" )->parse()
945 $defaultPreferences['editwatchlist'] = array(
948 'default' => $context->getLanguage()->pipeList( $editWatchlistLinks ),
949 'label-message' => 'prefs-editwatchlist-label',
950 'section' => 'watchlist/editwatchlist',
954 $defaultPreferences['watchlistdays'] = array(
957 'max' => $watchlistdaysMax,
958 'section' => 'watchlist/displaywatchlist',
959 'help' => $context->msg( 'prefs-watchlist-days-max' )->numParams(
960 $watchlistdaysMax )->escaped(),
961 'label-message' => 'prefs-watchlist-days',
963 $defaultPreferences['wllimit'] = array(
967 'label-message' => 'prefs-watchlist-edits',
968 'help' => $context->msg( 'prefs-watchlist-edits-max' )->escaped(),
969 'section' => 'watchlist/displaywatchlist',
971 $defaultPreferences['extendwatchlist'] = array(
973 'section' => 'watchlist/advancedwatchlist',
974 'label-message' => 'tog-extendwatchlist',
976 $defaultPreferences['watchlisthideminor'] = array(
978 'section' => 'watchlist/advancedwatchlist',
979 'label-message' => 'tog-watchlisthideminor',
981 $defaultPreferences['watchlisthidebots'] = array(
983 'section' => 'watchlist/advancedwatchlist',
984 'label-message' => 'tog-watchlisthidebots',
986 $defaultPreferences['watchlisthideown'] = array(
988 'section' => 'watchlist/advancedwatchlist',
989 'label-message' => 'tog-watchlisthideown',
991 $defaultPreferences['watchlisthideanons'] = array(
993 'section' => 'watchlist/advancedwatchlist',
994 'label-message' => 'tog-watchlisthideanons',
996 $defaultPreferences['watchlisthideliu'] = array(
998 'section' => 'watchlist/advancedwatchlist',
999 'label-message' => 'tog-watchlisthideliu',
1002 if ( $user->useRCPatrol() ) {
1003 $defaultPreferences['watchlisthidepatrolled'] = array(
1005 'section' => 'watchlist/advancedwatchlist',
1006 'label-message' => 'tog-watchlisthidepatrolled',
1010 $watchTypes = array(
1011 'edit' => 'watchdefault',
1012 'move' => 'watchmoves',
1013 'delete' => 'watchdeletion'
1017 if ( $user->isAllowed( 'createpage' ) ||
$user->isAllowed( 'createtalk' ) ) {
1018 $watchTypes['read'] = 'watchcreations';
1021 if ( $user->isAllowed( 'rollback' ) ) {
1022 $watchTypes['rollback'] = 'watchrollback';
1025 foreach ( $watchTypes as $action => $pref ) {
1026 if ( $user->isAllowed( $action ) ) {
1028 // tog-watchdefault, tog-watchmoves, tog-watchdeletion, tog-watchcreations
1029 // tog-watchrollback
1030 $defaultPreferences[$pref] = array(
1032 'section' => 'watchlist/advancedwatchlist',
1033 'label-message' => "tog-$pref",
1038 if ( $config->get( 'EnableAPI' ) ) {
1039 $defaultPreferences['watchlisttoken'] = array(
1042 $defaultPreferences['watchlisttoken-info'] = array(
1044 'section' => 'watchlist/tokenwatchlist',
1045 'label-message' => 'prefs-watchlist-token',
1046 'default' => $user->getTokenFromOption( 'watchlisttoken' ),
1047 'help-message' => 'prefs-help-watchlist-token2',
1054 * @param IContextSource $context
1055 * @param array $defaultPreferences
1057 static function searchPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
1058 foreach ( MWNamespace
::getValidNamespaces() as $n ) {
1059 $defaultPreferences['searchNs' . $n] = array(
1066 * Dummy, kept for backwards-compatibility.
1068 static function miscPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
1072 * @param User $user The User object
1073 * @param IContextSource $context
1074 * @return array Text/links to display as key; $skinkey as value
1076 static function generateSkinOptions( $user, IContextSource
$context ) {
1079 $mptitle = Title
::newMainPage();
1080 $previewtext = $context->msg( 'skin-preview' )->escaped();
1082 # Only show skins that aren't disabled in $wgSkipSkins
1083 $validSkinNames = Skin
::getAllowedSkins();
1085 # Sort by UI skin name. First though need to update validSkinNames as sometimes
1086 # the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI).
1087 foreach ( $validSkinNames as $skinkey => &$skinname ) {
1088 $msg = $context->msg( "skinname-{$skinkey}" );
1089 if ( $msg->exists() ) {
1090 $skinname = htmlspecialchars( $msg->text() );
1093 asort( $validSkinNames );
1095 $config = $context->getConfig();
1096 $defaultSkin = $config->get( 'DefaultSkin' );
1097 $allowUserCss = $config->get( 'AllowUserCss' );
1098 $allowUserJs = $config->get( 'AllowUserJs' );
1100 $foundDefault = false;
1101 foreach ( $validSkinNames as $skinkey => $sn ) {
1102 $linkTools = array();
1104 # Mark the default skin
1105 if ( strcasecmp( $skinkey, $defaultSkin ) === 0 ) {
1106 $linkTools[] = $context->msg( 'default' )->escaped();
1107 $foundDefault = true;
1110 # Create preview link
1111 $mplink = htmlspecialchars( $mptitle->getLocalURL( array( 'useskin' => $skinkey ) ) );
1112 $linkTools[] = "<a target='_blank' href=\"$mplink\">$previewtext</a>";
1114 # Create links to user CSS/JS pages
1115 if ( $allowUserCss ) {
1116 $cssPage = Title
::makeTitleSafe( NS_USER
, $user->getName() . '/' . $skinkey . '.css' );
1117 $linkTools[] = Linker
::link( $cssPage, $context->msg( 'prefs-custom-css' )->escaped() );
1120 if ( $allowUserJs ) {
1121 $jsPage = Title
::makeTitleSafe( NS_USER
, $user->getName() . '/' . $skinkey . '.js' );
1122 $linkTools[] = Linker
::link( $jsPage, $context->msg( 'prefs-custom-js' )->escaped() );
1125 $display = $sn . ' ' . $context->msg( 'parentheses' )
1126 ->rawParams( $context->getLanguage()->pipeList( $linkTools ) )
1128 $ret[$display] = $skinkey;
1131 if ( !$foundDefault ) {
1132 // If the default skin is not available, things are going to break horribly because the
1133 // default value for skin selector will not be a valid value. Let's just not show it then.
1141 * @param IContextSource $context
1144 static function getDateOptions( IContextSource
$context ) {
1145 $lang = $context->getLanguage();
1146 $dateopts = $lang->getDatePreferences();
1151 if ( !in_array( 'default', $dateopts ) ) {
1152 $dateopts[] = 'default'; // Make sure default is always valid
1156 // FIXME KLUGE: site default might not be valid for user language
1157 global $wgDefaultUserOptions;
1158 if ( !in_array( $wgDefaultUserOptions['date'], $dateopts ) ) {
1159 $wgDefaultUserOptions['date'] = 'default';
1162 $epoch = wfTimestampNow();
1163 foreach ( $dateopts as $key ) {
1164 if ( $key == 'default' ) {
1165 $formatted = $context->msg( 'datedefault' )->escaped();
1167 $formatted = htmlspecialchars( $lang->timeanddate( $epoch, false, $key ) );
1169 $ret[$formatted] = $key;
1176 * @param IContextSource $context
1179 static function getImageSizes( IContextSource
$context ) {
1181 $pixels = $context->msg( 'unit-pixel' )->text();
1183 foreach ( $context->getConfig()->get( 'ImageLimits' ) as $index => $limits ) {
1184 $display = "{$limits[0]}×{$limits[1]}" . $pixels;
1185 $ret[$display] = $index;
1192 * @param IContextSource $context
1195 static function getThumbSizes( IContextSource
$context ) {
1197 $pixels = $context->msg( 'unit-pixel' )->text();
1199 foreach ( $context->getConfig()->get( 'ThumbLimits' ) as $index => $size ) {
1200 $display = $size . $pixels;
1201 $ret[$display] = $index;
1208 * @param string $signature
1209 * @param array $alldata
1210 * @param HTMLForm $form
1211 * @return bool|string
1213 static function validateSignature( $signature, $alldata, $form ) {
1215 $maxSigChars = $form->getConfig()->get( 'MaxSigChars' );
1216 if ( mb_strlen( $signature ) > $maxSigChars ) {
1217 return Xml
::element( 'span', array( 'class' => 'error' ),
1218 $form->msg( 'badsiglength' )->numParams( $maxSigChars )->text() );
1219 } elseif ( isset( $alldata['fancysig'] ) &&
1220 $alldata['fancysig'] &&
1221 $wgParser->validateSig( $signature ) === false
1223 return Xml
::element(
1225 array( 'class' => 'error' ),
1226 $form->msg( 'badsig' )->text()
1234 * @param string $signature
1235 * @param array $alldata
1236 * @param HTMLForm $form
1239 static function cleanSignature( $signature, $alldata, $form ) {
1240 if ( isset( $alldata['fancysig'] ) && $alldata['fancysig'] ) {
1242 $signature = $wgParser->cleanSig( $signature );
1244 // When no fancy sig used, make sure ~{3,5} get removed.
1245 $signature = Parser
::cleanSigInSig( $signature );
1253 * @param IContextSource $context
1254 * @param string $formClass
1255 * @param array $remove Array of items to remove
1258 static function getFormObject(
1260 IContextSource
$context,
1261 $formClass = 'PreferencesForm',
1262 array $remove = array()
1264 $formDescriptor = Preferences
::getPreferences( $user, $context );
1265 if ( count( $remove ) ) {
1266 $removeKeys = array_flip( $remove );
1267 $formDescriptor = array_diff_key( $formDescriptor, $removeKeys );
1270 // Remove type=api preferences. They are not intended for rendering in the form.
1271 foreach ( $formDescriptor as $name => $info ) {
1272 if ( isset( $info['type'] ) && $info['type'] === 'api' ) {
1273 unset( $formDescriptor[$name] );
1278 * @var $htmlForm PreferencesForm
1280 $htmlForm = new $formClass( $formDescriptor, $context, 'prefs' );
1282 $htmlForm->setModifiedUser( $user );
1283 $htmlForm->setId( 'mw-prefs-form' );
1284 $htmlForm->setSubmitText( $context->msg( 'saveprefs' )->text() );
1285 # Used message keys: 'accesskey-preferences-save', 'tooltip-preferences-save'
1286 $htmlForm->setSubmitTooltip( 'preferences-save' );
1287 $htmlForm->setSubmitID( 'prefsubmit' );
1288 $htmlForm->setSubmitCallback( array( 'Preferences', 'tryFormSubmit' ) );
1294 * @param IContextSource $context
1297 static function getTimezoneOptions( IContextSource
$context ) {
1300 $localTZoffset = $context->getConfig()->get( 'LocalTZoffset' );
1301 $timeZoneList = self
::getTimeZoneList( $context->getLanguage() );
1303 $timestamp = MWTimestamp
::getLocalInstance();
1304 // Check that the LocalTZoffset is the same as the local time zone offset
1305 if ( $localTZoffset == $timestamp->format( 'Z' ) / 60 ) {
1306 $timezoneName = $timestamp->getTimezone()->getName();
1307 // Localize timezone
1308 if ( isset( $timeZoneList[$timezoneName] ) ) {
1309 $timezoneName = $timeZoneList[$timezoneName]['name'];
1311 $server_tz_msg = $context->msg(
1312 'timezoneuseserverdefault',
1316 $tzstring = sprintf(
1318 floor( $localTZoffset / 60 ),
1319 abs( $localTZoffset ) %
60
1321 $server_tz_msg = $context->msg( 'timezoneuseserverdefault', $tzstring )->text();
1323 $opt[$server_tz_msg] = "System|$localTZoffset";
1324 $opt[$context->msg( 'timezoneuseoffset' )->text()] = 'other';
1325 $opt[$context->msg( 'guesstimezone' )->text()] = 'guess';
1327 foreach ( $timeZoneList as $timeZoneInfo ) {
1328 $region = $timeZoneInfo['region'];
1329 if ( !isset( $opt[$region] ) ) {
1330 $opt[$region] = array();
1332 $opt[$region][$timeZoneInfo['name']] = $timeZoneInfo['timecorrection'];
1338 * @param string $value
1339 * @param array $alldata
1342 static function filterIntval( $value, $alldata ) {
1343 return intval( $value );
1348 * @param array $alldata
1351 static function filterTimezoneInput( $tz, $alldata ) {
1352 $data = explode( '|', $tz, 3 );
1353 switch ( $data[0] ) {
1358 $data = explode( ':', $tz, 2 );
1359 if ( count( $data ) == 2 ) {
1360 $data[0] = intval( $data[0] );
1361 $data[1] = intval( $data[1] );
1362 $minDiff = abs( $data[0] ) * 60 +
$data[1];
1363 if ( $data[0] < 0 ) {
1364 $minDiff = - $minDiff;
1367 $minDiff = intval( $data[0] ) * 60;
1370 # Max is +14:00 and min is -12:00, see:
1371 # https://en.wikipedia.org/wiki/Timezone
1372 $minDiff = min( $minDiff, 840 ); # 14:00
1373 $minDiff = max( $minDiff, - 720 ); # -12:00
1374 return 'Offset|' . $minDiff;
1379 * Handle the form submission if everything validated properly
1381 * @param array $formData
1382 * @param PreferencesForm $form
1383 * @return bool|Status|string
1385 static function tryFormSubmit( $formData, $form ) {
1388 $user = $form->getModifiedUser();
1389 $hiddenPrefs = $form->getConfig()->get( 'HiddenPrefs' );
1392 if ( !$user->isAllowedAny( 'editmyprivateinfo', 'editmyoptions' ) ) {
1393 return Status
::newFatal( 'mypreferencesprotected' );
1397 foreach ( array_keys( $formData ) as $name ) {
1398 if ( isset( self
::$saveFilters[$name] ) ) {
1400 call_user_func( self
::$saveFilters[$name], $formData[$name], $formData );
1404 // Fortunately, the realname field is MUCH simpler
1405 // (not really "private", but still shouldn't be edited without permission)
1406 if ( !in_array( 'realname', $hiddenPrefs )
1407 && $user->isAllowed( 'editmyprivateinfo' )
1408 && array_key_exists( 'realname', $formData )
1410 $realName = $formData['realname'];
1411 $user->setRealName( $realName );
1414 if ( $user->isAllowed( 'editmyoptions' ) ) {
1415 foreach ( self
::$saveBlacklist as $b ) {
1416 unset( $formData[$b] );
1419 # If users have saved a value for a preference which has subsequently been disabled
1420 # via $wgHiddenPrefs, we don't want to destroy that setting in case the preference
1421 # is subsequently re-enabled
1422 foreach ( $hiddenPrefs as $pref ) {
1423 # If the user has not set a non-default value here, the default will be returned
1424 # and subsequently discarded
1425 $formData[$pref] = $user->getOption( $pref, null, true );
1428 // Keep old preferences from interfering due to back-compat code, etc.
1429 $user->resetOptions( 'unused', $form->getContext() );
1431 foreach ( $formData as $key => $value ) {
1432 $user->setOption( $key, $value );
1435 Hooks
::run( 'PreferencesFormPreSave', array( $formData, $form, $user, &$result ) );
1438 $wgAuth->updateExternalDB( $user );
1439 $user->saveSettings();
1445 * @param array $formData
1446 * @param PreferencesForm $form
1449 public static function tryUISubmit( $formData, $form ) {
1450 $res = self
::tryFormSubmit( $formData, $form );
1453 $urlOptions = array( 'success' => 1 );
1455 if ( $res === 'eauth' ) {
1456 $urlOptions['eauth'] = 1;
1459 $urlOptions +
= $form->getExtraSuccessRedirectParameters();
1461 $url = $form->getTitle()->getFullURL( $urlOptions );
1463 $form->getContext()->getOutput()->redirect( $url );
1466 return Status
::newGood();
1470 * Get a list of all time zones
1471 * @param Language $language Language used for the localized names
1472 * @return array A list of all time zones. The system name of the time zone is used as key and
1473 * the value is an array which contains localized name, the timecorrection value used for
1474 * preferences and the region
1477 public static function getTimeZoneList( Language
$language ) {
1478 $identifiers = DateTimeZone
::listIdentifiers();
1479 if ( $identifiers === false ) {
1482 sort( $identifiers );
1485 'Africa' => wfMessage( 'timezoneregion-africa' )->inLanguage( $language )->text(),
1486 'America' => wfMessage( 'timezoneregion-america' )->inLanguage( $language )->text(),
1487 'Antarctica' => wfMessage( 'timezoneregion-antarctica' )->inLanguage( $language )->text(),
1488 'Arctic' => wfMessage( 'timezoneregion-arctic' )->inLanguage( $language )->text(),
1489 'Asia' => wfMessage( 'timezoneregion-asia' )->inLanguage( $language )->text(),
1490 'Atlantic' => wfMessage( 'timezoneregion-atlantic' )->inLanguage( $language )->text(),
1491 'Australia' => wfMessage( 'timezoneregion-australia' )->inLanguage( $language )->text(),
1492 'Europe' => wfMessage( 'timezoneregion-europe' )->inLanguage( $language )->text(),
1493 'Indian' => wfMessage( 'timezoneregion-indian' )->inLanguage( $language )->text(),
1494 'Pacific' => wfMessage( 'timezoneregion-pacific' )->inLanguage( $language )->text(),
1496 asort( $tzRegions );
1498 $timeZoneList = array();
1500 $now = new DateTime();
1502 foreach ( $identifiers as $identifier ) {
1503 $parts = explode( '/', $identifier, 2 );
1505 // DateTimeZone::listIdentifiers() returns a number of
1506 // backwards-compatibility entries. This filters them out of the
1507 // list presented to the user.
1508 if ( count( $parts ) !== 2 ||
!array_key_exists( $parts[0], $tzRegions ) ) {
1513 $parts[0] = $tzRegions[$parts[0]];
1515 $dateTimeZone = new DateTimeZone( $identifier );
1516 $minDiff = floor( $dateTimeZone->getOffset( $now ) / 60 );
1518 $display = str_replace( '_', ' ', $parts[0] . '/' . $parts[1] );
1519 $value = "ZoneInfo|$minDiff|$identifier";
1521 $timeZoneList[$identifier] = array(
1523 'timecorrection' => $value,
1524 'region' => $parts[0],
1528 return $timeZoneList;
1532 /** Some tweaks to allow js prefs to work */
1533 class PreferencesForm
extends HTMLForm
{
1534 // Override default value from HTMLForm
1535 protected $mSubSectionBeforeFields = false;
1537 private $modifiedUser;
1542 public function setModifiedUser( $user ) {
1543 $this->modifiedUser
= $user;
1549 public function getModifiedUser() {
1550 if ( $this->modifiedUser
=== null ) {
1551 return $this->getUser();
1553 return $this->modifiedUser
;
1558 * Get extra parameters for the query string when redirecting after
1563 public function getExtraSuccessRedirectParameters() {
1568 * @param string $html
1571 function wrapForm( $html ) {
1572 $html = Xml
::tags( 'div', array( 'id' => 'preferences' ), $html );
1574 return parent
::wrapForm( $html );
1580 function getButtons() {
1582 $attrs = array( 'id' => 'mw-prefs-restoreprefs' );
1584 if ( !$this->getModifiedUser()->isAllowedAny( 'editmyprivateinfo', 'editmyoptions' ) ) {
1588 $html = parent
::getButtons();
1590 if ( $this->getModifiedUser()->isAllowed( 'editmyoptions' ) ) {
1591 $t = SpecialPage
::getTitleFor( 'Preferences', 'reset' );
1593 $html .= "\n" . Linker
::link( $t, $this->msg( 'restoreprefs' )->escaped(),
1594 Html
::buttonAttributes( $attrs, array( 'mw-ui-quiet' ) ) );
1596 $html = Xml
::tags( 'div', array( 'class' => 'mw-prefs-buttons' ), $html );
1603 * Separate multi-option preferences into multiple preferences, since we
1604 * have to store them separately
1605 * @param array $data
1608 function filterDataForSubmit( $data ) {
1609 foreach ( $this->mFlatFields
as $fieldname => $field ) {
1610 if ( $field instanceof HTMLNestedFilterable
) {
1611 $info = $field->mParams
;
1612 $prefix = isset( $info['prefix'] ) ?
$info['prefix'] : $fieldname;
1613 foreach ( $field->filterDataForSubmit( $data[$fieldname] ) as $key => $value ) {
1614 $data["$prefix$key"] = $value;
1616 unset( $data[$fieldname] );
1624 * Get the whole body of the form.
1627 function getBody() {
1628 return $this->displaySection( $this->mFieldTree
, '', 'mw-prefsection-' );
1632 * Get the "<legend>" for a given section key. Normally this is the
1633 * prefs-$key message but we'll allow extensions to override it.
1634 * @param string $key
1637 function getLegend( $key ) {
1638 $legend = parent
::getLegend( $key );
1639 Hooks
::run( 'PreferencesGetLegend', array( $this, $key, &$legend ) );