3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
20 use MediaWiki\Auth\AuthManager
;
21 use MediaWiki\Auth\PasswordAuthenticationRequest
;
22 use MediaWiki\MediaWikiServices
;
25 * We're now using the HTMLForm object with some customisation to generate the
26 * Preferences form. This object handles generic submission, CSRF protection,
27 * layout and other logic in a reusable manner. We subclass it as a PreferencesForm
28 * to make some minor customisations.
30 * In order to generate the form, the HTMLForm object needs an array structure
31 * detailing the form fields available, and that's what this class is for. Each
32 * element of the array is a basic property-list, including the type of field,
33 * the label it is to be given in the form, callbacks for validation and
34 * 'filtering', and other pertinent information. Note that the 'default' field
35 * is named for generic forms, and does not represent the preference's default
36 * (which is stored in $wgDefaultUserOptions), but the default for the form
37 * field, which should be whatever the user has set for that preference. There
38 * is no need to override it unless you have some special storage logic (for
39 * instance, those not presently stored as options, but which are best set from
40 * the user preferences view).
42 * Field types are implemented as subclasses of the generic HTMLFormField
43 * object, and typically implement at least getInputHTML, which generates the
44 * HTML for the input field to be placed in the table.
46 * Once fields have been retrieved and validated, submission logic is handed
47 * over to the tryUISubmit static method of this class.
51 protected static $saveFilters = [
52 'timecorrection' => [ 'Preferences', 'filterTimezoneInput' ],
53 'rclimit' => [ 'Preferences', 'filterIntval' ],
54 'wllimit' => [ 'Preferences', 'filterIntval' ],
55 'searchlimit' => [ 'Preferences', 'filterIntval' ],
58 // Stuff that shouldn't be saved as a preference.
59 private static $saveBlacklist = [
67 static function getSaveBlacklist() {
68 return self
::$saveBlacklist;
74 * @param IContextSource $context
77 static function getPreferences( $user, IContextSource
$context ) {
78 OutputPage
::setupOOUI(
79 strtolower( $context->getSkin()->getSkinName() ),
80 $context->getLanguage()->getDir()
83 $defaultPreferences = [];
85 self
::profilePreferences( $user, $context, $defaultPreferences );
86 self
::skinPreferences( $user, $context, $defaultPreferences );
87 self
::datetimePreferences( $user, $context, $defaultPreferences );
88 self
::filesPreferences( $user, $context, $defaultPreferences );
89 self
::renderingPreferences( $user, $context, $defaultPreferences );
90 self
::editingPreferences( $user, $context, $defaultPreferences );
91 self
::rcPreferences( $user, $context, $defaultPreferences );
92 self
::watchlistPreferences( $user, $context, $defaultPreferences );
93 self
::searchPreferences( $user, $context, $defaultPreferences );
94 self
::miscPreferences( $user, $context, $defaultPreferences );
96 Hooks
::run( 'GetPreferences', [ $user, &$defaultPreferences ] );
98 self
::loadPreferenceValues( $user, $context, $defaultPreferences );
99 return $defaultPreferences;
103 * Loads existing values for a given array of preferences
104 * @throws MWException
106 * @param IContextSource $context
107 * @param array &$defaultPreferences Array to load values for
110 static function loadPreferenceValues( $user, $context, &$defaultPreferences ) {
111 # # Remove preferences that wikis don't want to use
112 foreach ( $context->getConfig()->get( 'HiddenPrefs' ) as $pref ) {
113 if ( isset( $defaultPreferences[$pref] ) ) {
114 unset( $defaultPreferences[$pref] );
118 # # Make sure that form fields have their parent set. See T43337.
119 $dummyForm = new HTMLForm( [], $context );
121 $disable = !$user->isAllowed( 'editmyoptions' );
123 $defaultOptions = User
::getDefaultOptions();
124 # # Prod in defaults from the user
125 foreach ( $defaultPreferences as $name => &$info ) {
126 $prefFromUser = self
::getOptionFromUser( $name, $info, $user );
127 if ( $disable && !in_array( $name, self
::$saveBlacklist ) ) {
128 $info['disabled'] = 'disabled';
130 $field = HTMLForm
::loadInputFromParameters( $name, $info, $dummyForm ); // For validation
131 $globalDefault = isset( $defaultOptions[$name] )
132 ?
$defaultOptions[$name]
135 // If it validates, set it as the default
136 if ( isset( $info['default'] ) ) {
137 // Already set, no problem
139 } elseif ( !is_null( $prefFromUser ) && // Make sure we're not just pulling nothing
140 $field->validate( $prefFromUser, $user->getOptions() ) === true ) {
141 $info['default'] = $prefFromUser;
142 } elseif ( $field->validate( $globalDefault, $user->getOptions() ) === true ) {
143 $info['default'] = $globalDefault;
145 throw new MWException( "Global default '$globalDefault' is invalid for field $name" );
149 return $defaultPreferences;
153 * Pull option from a user account. Handles stuff like array-type preferences.
155 * @param string $name
158 * @return array|string
160 static function getOptionFromUser( $name, $info, $user ) {
161 $val = $user->getOption( $name );
163 // Handling for multiselect preferences
164 if ( ( isset( $info['type'] ) && $info['type'] == 'multiselect' ) ||
165 ( isset( $info['class'] ) && $info['class'] == 'HTMLMultiSelectField' ) ) {
166 $options = HTMLFormField
::flattenOptions( $info['options'] );
167 $prefix = isset( $info['prefix'] ) ?
$info['prefix'] : $name;
170 foreach ( $options as $value ) {
171 if ( $user->getOption( "$prefix$value" ) ) {
177 // Handling for checkmatrix preferences
178 if ( ( isset( $info['type'] ) && $info['type'] == 'checkmatrix' ) ||
179 ( isset( $info['class'] ) && $info['class'] == 'HTMLCheckMatrix' ) ) {
180 $columns = HTMLFormField
::flattenOptions( $info['columns'] );
181 $rows = HTMLFormField
::flattenOptions( $info['rows'] );
182 $prefix = isset( $info['prefix'] ) ?
$info['prefix'] : $name;
185 foreach ( $columns as $column ) {
186 foreach ( $rows as $row ) {
187 if ( $user->getOption( "$prefix$column-$row" ) ) {
188 $val[] = "$column-$row";
199 * @param IContextSource $context
200 * @param array &$defaultPreferences
203 static function profilePreferences( $user, IContextSource
$context, &$defaultPreferences ) {
204 global $wgContLang, $wgParser;
206 $authManager = AuthManager
::singleton();
207 $config = $context->getConfig();
208 // retrieving user name for GENDER and misc.
209 $userName = $user->getName();
211 # # User info #####################################
213 $defaultPreferences['username'] = [
215 'label-message' => [ 'username', $userName ],
216 'default' => $userName,
217 'section' => 'personal/info',
220 $lang = $context->getLanguage();
222 # Get groups to which the user belongs
223 $userEffectiveGroups = $user->getEffectiveGroups();
224 $userGroupMemberships = $user->getGroupMemberships();
225 $userGroups = $userMembers = $userTempGroups = $userTempMembers = [];
226 foreach ( $userEffectiveGroups as $ueg ) {
228 // Skip the default * group, seems useless here
232 if ( isset( $userGroupMemberships[$ueg] ) ) {
233 $groupStringOrObject = $userGroupMemberships[$ueg];
235 $groupStringOrObject = $ueg;
238 $userG = UserGroupMembership
::getLink( $groupStringOrObject, $context, 'html' );
239 $userM = UserGroupMembership
::getLink( $groupStringOrObject, $context, 'html',
242 // Store expiring groups separately, so we can place them before non-expiring
243 // groups in the list. This is to avoid the ambiguity of something like
244 // "administrator, bureaucrat (until X date)" -- users might wonder whether the
245 // expiry date applies to both groups, or just the last one
246 if ( $groupStringOrObject instanceof UserGroupMembership
&&
247 $groupStringOrObject->getExpiry()
249 $userTempGroups[] = $userG;
250 $userTempMembers[] = $userM;
252 $userGroups[] = $userG;
253 $userMembers[] = $userM;
257 sort( $userMembers );
258 sort( $userTempGroups );
259 sort( $userTempMembers );
260 $userGroups = array_merge( $userTempGroups, $userGroups );
261 $userMembers = array_merge( $userTempMembers, $userMembers );
263 $defaultPreferences['usergroups'] = [
265 'label' => $context->msg( 'prefs-memberingroups' )->numParams(
266 count( $userGroups ) )->params( $userName )->parse(),
267 'default' => $context->msg( 'prefs-memberingroups-type' )
268 ->rawParams( $lang->commaList( $userGroups ), $lang->commaList( $userMembers ) )
271 'section' => 'personal/info',
274 $linkRenderer = MediaWikiServices
::getInstance()->getLinkRenderer();
276 $editCount = $linkRenderer->makeLink( SpecialPage
::getTitleFor( "Contributions", $userName ),
277 $lang->formatNum( $user->getEditCount() ) );
279 $defaultPreferences['editcount'] = [
282 'label-message' => 'prefs-edits',
283 'default' => $editCount,
284 'section' => 'personal/info',
287 if ( $user->getRegistration() ) {
288 $displayUser = $context->getUser();
289 $userRegistration = $user->getRegistration();
290 $defaultPreferences['registrationdate'] = [
292 'label-message' => 'prefs-registration',
293 'default' => $context->msg(
294 'prefs-registration-date-time',
295 $lang->userTimeAndDate( $userRegistration, $displayUser ),
296 $lang->userDate( $userRegistration, $displayUser ),
297 $lang->userTime( $userRegistration, $displayUser )
299 'section' => 'personal/info',
303 $canViewPrivateInfo = $user->isAllowed( 'viewmyprivateinfo' );
304 $canEditPrivateInfo = $user->isAllowed( 'editmyprivateinfo' );
306 // Actually changeable stuff
307 $defaultPreferences['realname'] = [
308 // (not really "private", but still shouldn't be edited without permission)
309 'type' => $canEditPrivateInfo && $authManager->allowsPropertyChange( 'realname' )
311 'default' => $user->getRealName(),
312 'section' => 'personal/info',
313 'label-message' => 'yourrealname',
314 'help-message' => 'prefs-help-realname',
317 if ( $canEditPrivateInfo && $authManager->allowsAuthenticationDataChange(
318 new PasswordAuthenticationRequest(), false )->isGood()
320 $link = new OOUI\
ButtonWidget( [
321 'href' => SpecialPage
::getTitleFor( 'ChangePassword' )->getLinkURL( [
322 'returnto' => SpecialPage
::getTitleFor( 'Preferences' )->getPrefixedText()
324 'label' => $context->msg( 'prefs-resetpass' )->text(),
327 $defaultPreferences['password'] = [
330 'default' => (string)$link,
331 'label-message' => 'yourpassword',
332 'section' => 'personal/info',
335 // Only show prefershttps if secure login is turned on
336 if ( $config->get( 'SecureLogin' ) && wfCanIPUseHTTPS( $context->getRequest()->getIP() ) ) {
337 $defaultPreferences['prefershttps'] = [
339 'label-message' => 'tog-prefershttps',
340 'help-message' => 'prefs-help-prefershttps',
341 'section' => 'personal/info'
346 $languages = Language
::fetchLanguageNames( null, 'mw' );
347 $languageCode = $config->get( 'LanguageCode' );
348 if ( !array_key_exists( $languageCode, $languages ) ) {
349 $languages[$languageCode] = $languageCode;
354 foreach ( $languages as $code => $name ) {
355 $display = LanguageCode
::bcp47( $code ) . ' - ' . $name;
356 $options[$display] = $code;
358 $defaultPreferences['language'] = [
360 'section' => 'personal/i18n',
361 'options' => $options,
362 'label-message' => 'yourlanguage',
365 $defaultPreferences['gender'] = [
367 'section' => 'personal/i18n',
369 $context->msg( 'parentheses' )
370 ->params( $context->msg( 'gender-unknown' )->plain() )
371 ->escaped() => 'unknown',
372 $context->msg( 'gender-female' )->escaped() => 'female',
373 $context->msg( 'gender-male' )->escaped() => 'male',
375 'label-message' => 'yourgender',
376 'help-message' => 'prefs-help-gender',
379 // see if there are multiple language variants to choose from
380 if ( !$config->get( 'DisableLangConversion' ) ) {
381 foreach ( LanguageConverter
::$languagesWithVariants as $langCode ) {
382 if ( $langCode == $wgContLang->getCode() ) {
383 $variants = $wgContLang->getVariants();
385 if ( count( $variants ) <= 1 ) {
390 foreach ( $variants as $v ) {
391 $v = str_replace( '_', '-', strtolower( $v ) );
392 $variantArray[$v] = $lang->getVariantname( $v, false );
396 foreach ( $variantArray as $code => $name ) {
397 $display = LanguageCode
::bcp47( $code ) . ' - ' . $name;
398 $options[$display] = $code;
401 $defaultPreferences['variant'] = [
402 'label-message' => 'yourvariant',
404 'options' => $options,
405 'section' => 'personal/i18n',
406 'help-message' => 'prefs-help-variant',
409 $defaultPreferences["variant-$langCode"] = [
416 // Stuff from Language::getExtraUserToggles()
417 // FIXME is this dead code? $extraUserToggles doesn't seem to be defined for any language
418 $toggles = $wgContLang->getExtraUserToggles();
420 foreach ( $toggles as $toggle ) {
421 $defaultPreferences[$toggle] = [
423 'section' => 'personal/i18n',
424 'label-message' => "tog-$toggle",
428 // show a preview of the old signature first
429 $oldsigWikiText = $wgParser->preSaveTransform(
431 $context->getTitle(),
433 ParserOptions
::newFromContext( $context )
435 $oldsigHTML = $context->getOutput()->parseInline( $oldsigWikiText, true, true );
436 $defaultPreferences['oldsig'] = [
439 'label-message' => 'tog-oldsig',
440 'default' => $oldsigHTML,
441 'section' => 'personal/signature',
443 $defaultPreferences['nickname'] = [
444 'type' => $authManager->allowsPropertyChange( 'nickname' ) ?
'text' : 'info',
445 'maxlength' => $config->get( 'MaxSigChars' ),
446 'label-message' => 'yournick',
447 'validation-callback' => [ 'Preferences', 'validateSignature' ],
448 'section' => 'personal/signature',
449 'filter-callback' => [ 'Preferences', 'cleanSignature' ],
451 $defaultPreferences['fancysig'] = [
453 'label-message' => 'tog-fancysig',
454 // show general help about signature at the bottom of the section
455 'help-message' => 'prefs-help-signature',
456 'section' => 'personal/signature'
461 if ( $config->get( 'EnableEmail' ) ) {
462 if ( $canViewPrivateInfo ) {
463 $helpMessages[] = $config->get( 'EmailConfirmToEdit' )
464 ?
'prefs-help-email-required'
465 : 'prefs-help-email';
467 if ( $config->get( 'EnableUserEmail' ) ) {
468 // additional messages when users can send email to each other
469 $helpMessages[] = 'prefs-help-email-others';
472 $emailAddress = $user->getEmail() ?
htmlspecialchars( $user->getEmail() ) : '';
473 if ( $canEditPrivateInfo && $authManager->allowsPropertyChange( 'emailaddress' ) ) {
474 $link = new OOUI\
ButtonWidget( [
475 'href' => SpecialPage
::getTitleFor( 'ChangeEmail' )->getLinkURL( [
476 'returnto' => SpecialPage
::getTitleFor( 'Preferences' )->getPrefixedText()
479 $context->msg( $user->getEmail() ?
'prefs-changeemail' : 'prefs-setemail' )->text(),
482 $emailAddress .= $emailAddress == '' ?
$link : ( '<br />' . $link );
485 $defaultPreferences['emailaddress'] = [
488 'default' => $emailAddress,
489 'label-message' => 'youremail',
490 'section' => 'personal/email',
491 'help-messages' => $helpMessages,
492 # 'cssclass' chosen below
496 $disableEmailPrefs = false;
498 if ( $config->get( 'EmailAuthentication' ) ) {
499 $emailauthenticationclass = 'mw-email-not-authenticated';
500 if ( $user->getEmail() ) {
501 if ( $user->getEmailAuthenticationTimestamp() ) {
502 // date and time are separate parameters to facilitate localisation.
503 // $time is kept for backward compat reasons.
504 // 'emailauthenticated' is also used in SpecialConfirmemail.php
505 $displayUser = $context->getUser();
506 $emailTimestamp = $user->getEmailAuthenticationTimestamp();
507 $time = $lang->userTimeAndDate( $emailTimestamp, $displayUser );
508 $d = $lang->userDate( $emailTimestamp, $displayUser );
509 $t = $lang->userTime( $emailTimestamp, $displayUser );
510 $emailauthenticated = $context->msg( 'emailauthenticated',
511 $time, $d, $t )->parse() . '<br />';
512 $disableEmailPrefs = false;
513 $emailauthenticationclass = 'mw-email-authenticated';
515 $disableEmailPrefs = true;
516 $emailauthenticated = $context->msg( 'emailnotauthenticated' )->parse() . '<br />' .
517 new OOUI\
ButtonWidget( [
518 'href' => SpecialPage
::getTitleFor( 'Confirmemail' )->getLinkURL(),
519 'label' => $context->msg( 'emailconfirmlink' )->text(),
521 $emailauthenticationclass = "mw-email-not-authenticated";
524 $disableEmailPrefs = true;
525 $emailauthenticated = $context->msg( 'noemailprefs' )->escaped();
526 $emailauthenticationclass = 'mw-email-none';
529 if ( $canViewPrivateInfo ) {
530 $defaultPreferences['emailauthentication'] = [
533 'section' => 'personal/email',
534 'label-message' => 'prefs-emailconfirm-label',
535 'default' => $emailauthenticated,
536 # Apply the same CSS class used on the input to the message:
537 'cssclass' => $emailauthenticationclass,
542 if ( $config->get( 'EnableUserEmail' ) && $user->isAllowed( 'sendemail' ) ) {
543 $defaultPreferences['disablemail'] = [
546 'section' => 'personal/email',
547 'label-message' => 'allowemail',
548 'disabled' => $disableEmailPrefs,
550 $defaultPreferences['ccmeonemails'] = [
552 'section' => 'personal/email',
553 'label-message' => 'tog-ccmeonemails',
554 'disabled' => $disableEmailPrefs,
557 if ( $config->get( 'EnableUserEmailBlacklist' )
558 && !$disableEmailPrefs
559 && !(bool)$user->getOption( 'disablemail' )
561 $lookup = CentralIdLookup
::factory();
562 $ids = $user->getOption( 'email-blacklist', [] );
563 $names = $ids ?
$lookup->namesFromCentralIds( $ids, $user ) : [];
565 $defaultPreferences['email-blacklist'] = [
566 'type' => 'usersmultiselect',
567 'label-message' => 'email-blacklist-label',
568 'section' => 'personal/email',
569 'default' => implode( "\n", $names ),
574 if ( $config->get( 'EnotifWatchlist' ) ) {
575 $defaultPreferences['enotifwatchlistpages'] = [
577 'section' => 'personal/email',
578 'label-message' => 'tog-enotifwatchlistpages',
579 'disabled' => $disableEmailPrefs,
582 if ( $config->get( 'EnotifUserTalk' ) ) {
583 $defaultPreferences['enotifusertalkpages'] = [
585 'section' => 'personal/email',
586 'label-message' => 'tog-enotifusertalkpages',
587 'disabled' => $disableEmailPrefs,
590 if ( $config->get( 'EnotifUserTalk' ) ||
$config->get( 'EnotifWatchlist' ) ) {
591 if ( $config->get( 'EnotifMinorEdits' ) ) {
592 $defaultPreferences['enotifminoredits'] = [
594 'section' => 'personal/email',
595 'label-message' => 'tog-enotifminoredits',
596 'disabled' => $disableEmailPrefs,
600 if ( $config->get( 'EnotifRevealEditorAddress' ) ) {
601 $defaultPreferences['enotifrevealaddr'] = [
603 'section' => 'personal/email',
604 'label-message' => 'tog-enotifrevealaddr',
605 'disabled' => $disableEmailPrefs,
614 * @param IContextSource $context
615 * @param array &$defaultPreferences
618 static function skinPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
619 # # Skin #####################################
621 // Skin selector, if there is at least one valid skin
622 $skinOptions = self
::generateSkinOptions( $user, $context );
623 if ( $skinOptions ) {
624 $defaultPreferences['skin'] = [
626 'options' => $skinOptions,
627 'section' => 'rendering/skin',
631 $config = $context->getConfig();
632 $allowUserCss = $config->get( 'AllowUserCss' );
633 $allowUserJs = $config->get( 'AllowUserJs' );
634 # Create links to user CSS/JS pages for all skins
635 # This code is basically copied from generateSkinOptions(). It'd
636 # be nice to somehow merge this back in there to avoid redundancy.
637 if ( $allowUserCss ||
$allowUserJs ) {
639 $userName = $user->getName();
641 $linkRenderer = MediaWikiServices
::getInstance()->getLinkRenderer();
642 if ( $allowUserCss ) {
643 $cssPage = Title
::makeTitleSafe( NS_USER
, $userName . '/common.css' );
644 $linkTools[] = $linkRenderer->makeLink( $cssPage, $context->msg( 'prefs-custom-css' )->text() );
647 if ( $allowUserJs ) {
648 $jsPage = Title
::makeTitleSafe( NS_USER
, $userName . '/common.js' );
649 $linkTools[] = $linkRenderer->makeLink( $jsPage, $context->msg( 'prefs-custom-js' )->text() );
652 $defaultPreferences['commoncssjs'] = [
655 'default' => $context->getLanguage()->pipeList( $linkTools ),
656 'label-message' => 'prefs-common-css-js',
657 'section' => 'rendering/skin',
664 * @param IContextSource $context
665 * @param array &$defaultPreferences
667 static function filesPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
668 # # Files #####################################
669 $defaultPreferences['imagesize'] = [
671 'options' => self
::getImageSizes( $context ),
672 'label-message' => 'imagemaxsize',
673 'section' => 'rendering/files',
675 $defaultPreferences['thumbsize'] = [
677 'options' => self
::getThumbSizes( $context ),
678 'label-message' => 'thumbsize',
679 'section' => 'rendering/files',
685 * @param IContextSource $context
686 * @param array &$defaultPreferences
689 static function datetimePreferences( $user, IContextSource
$context, &$defaultPreferences ) {
690 # # Date and time #####################################
691 $dateOptions = self
::getDateOptions( $context );
692 if ( $dateOptions ) {
693 $defaultPreferences['date'] = [
695 'options' => $dateOptions,
696 'section' => 'rendering/dateformat',
701 $now = wfTimestampNow();
702 $lang = $context->getLanguage();
703 $nowlocal = Xml
::element( 'span', [ 'id' => 'wpLocalTime' ],
704 $lang->userTime( $now, $user ) );
705 $nowserver = $lang->userTime( $now, $user,
706 [ 'format' => false, 'timecorrection' => false ] ) .
707 Html
::hidden( 'wpServerTime', (int)substr( $now, 8, 2 ) * 60 +
(int)substr( $now, 10, 2 ) );
709 $defaultPreferences['nowserver'] = [
712 'label-message' => 'servertime',
713 'default' => $nowserver,
714 'section' => 'rendering/timeoffset',
717 $defaultPreferences['nowlocal'] = [
720 'label-message' => 'localtime',
721 'default' => $nowlocal,
722 'section' => 'rendering/timeoffset',
725 // Grab existing pref.
726 $tzOffset = $user->getOption( 'timecorrection' );
727 $tz = explode( '|', $tzOffset, 3 );
729 $tzOptions = self
::getTimezoneOptions( $context );
731 $tzSetting = $tzOffset;
732 if ( count( $tz ) > 1 && $tz[0] == 'ZoneInfo' &&
733 !in_array( $tzOffset, HTMLFormField
::flattenOptions( $tzOptions ) )
735 // Timezone offset can vary with DST
737 $userTZ = new DateTimeZone( $tz[2] );
738 $minDiff = floor( $userTZ->getOffset( new DateTime( 'now' ) ) / 60 );
739 $tzSetting = "ZoneInfo|$minDiff|{$tz[2]}";
740 } catch ( Exception
$e ) {
741 // User has an invalid time zone set. Fall back to just using the offset
745 if ( count( $tz ) > 1 && $tz[0] == 'Offset' ) {
747 $tzSetting = sprintf( '%+03d:%02d', floor( $minDiff / 60 ), abs( $minDiff ) %
60 );
750 $defaultPreferences['timecorrection'] = [
751 'class' => 'HTMLSelectOrOtherField',
752 'label-message' => 'timezonelegend',
753 'options' => $tzOptions,
754 'default' => $tzSetting,
756 'section' => 'rendering/timeoffset',
757 'id' => 'wpTimeCorrection',
763 * @param IContextSource $context
764 * @param array &$defaultPreferences
766 static function renderingPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
767 # # Diffs ####################################
768 $defaultPreferences['diffonly'] = [
770 'section' => 'rendering/diffs',
771 'label-message' => 'tog-diffonly',
773 $defaultPreferences['norollbackdiff'] = [
775 'section' => 'rendering/diffs',
776 'label-message' => 'tog-norollbackdiff',
779 # # Page Rendering ##############################
780 if ( $context->getConfig()->get( 'AllowUserCssPrefs' ) ) {
781 $defaultPreferences['underline'] = [
784 $context->msg( 'underline-never' )->text() => 0,
785 $context->msg( 'underline-always' )->text() => 1,
786 $context->msg( 'underline-default' )->text() => 2,
788 'label-message' => 'tog-underline',
789 'section' => 'rendering/advancedrendering',
793 $stubThresholdValues = [ 50, 100, 500, 1000, 2000, 5000, 10000 ];
794 $stubThresholdOptions = [ $context->msg( 'stub-threshold-disabled' )->text() => 0 ];
795 foreach ( $stubThresholdValues as $value ) {
796 $stubThresholdOptions[$context->msg( 'size-bytes', $value )->text()] = $value;
799 $defaultPreferences['stubthreshold'] = [
801 'section' => 'rendering/advancedrendering',
802 'options' => $stubThresholdOptions,
803 // This is not a raw HTML message; label-raw is needed for the manual <a></a>
804 'label-raw' => $context->msg( 'stub-threshold' )->rawParams(
805 '<a href="#" class="stub">' .
806 $context->msg( 'stub-threshold-sample-link' )->parse() .
810 $defaultPreferences['showhiddencats'] = [
812 'section' => 'rendering/advancedrendering',
813 'label-message' => 'tog-showhiddencats'
816 $defaultPreferences['numberheadings'] = [
818 'section' => 'rendering/advancedrendering',
819 'label-message' => 'tog-numberheadings',
825 * @param IContextSource $context
826 * @param array &$defaultPreferences
828 static function editingPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
829 # # Editing #####################################
830 $defaultPreferences['editsectiononrightclick'] = [
832 'section' => 'editing/advancedediting',
833 'label-message' => 'tog-editsectiononrightclick',
835 $defaultPreferences['editondblclick'] = [
837 'section' => 'editing/advancedediting',
838 'label-message' => 'tog-editondblclick',
841 if ( $context->getConfig()->get( 'AllowUserCssPrefs' ) ) {
842 $defaultPreferences['editfont'] = [
844 'section' => 'editing/editor',
845 'label-message' => 'editfont-style',
847 $context->msg( 'editfont-monospace' )->text() => 'monospace',
848 $context->msg( 'editfont-sansserif' )->text() => 'sans-serif',
849 $context->msg( 'editfont-serif' )->text() => 'serif',
854 if ( $user->isAllowed( 'minoredit' ) ) {
855 $defaultPreferences['minordefault'] = [
857 'section' => 'editing/editor',
858 'label-message' => 'tog-minordefault',
862 $defaultPreferences['forceeditsummary'] = [
864 'section' => 'editing/editor',
865 'label-message' => 'tog-forceeditsummary',
867 $defaultPreferences['useeditwarning'] = [
869 'section' => 'editing/editor',
870 'label-message' => 'tog-useeditwarning',
872 $defaultPreferences['showtoolbar'] = [
874 'section' => 'editing/editor',
875 'label-message' => 'tog-showtoolbar',
878 $defaultPreferences['previewonfirst'] = [
880 'section' => 'editing/preview',
881 'label-message' => 'tog-previewonfirst',
883 $defaultPreferences['previewontop'] = [
885 'section' => 'editing/preview',
886 'label-message' => 'tog-previewontop',
888 $defaultPreferences['uselivepreview'] = [
890 'section' => 'editing/preview',
891 'label-message' => 'tog-uselivepreview',
897 * @param IContextSource $context
898 * @param array &$defaultPreferences
900 static function rcPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
901 $config = $context->getConfig();
902 $rcMaxAge = $config->get( 'RCMaxAge' );
903 # # RecentChanges #####################################
904 $defaultPreferences['rcdays'] = [
906 'label-message' => 'recentchangesdays',
907 'section' => 'rc/displayrc',
909 'max' => ceil( $rcMaxAge / ( 3600 * 24 ) ),
910 'help' => $context->msg( 'recentchangesdays-max' )->numParams(
911 ceil( $rcMaxAge / ( 3600 * 24 ) ) )->escaped()
913 $defaultPreferences['rclimit'] = [
917 'label-message' => 'recentchangescount',
918 'help-message' => 'prefs-help-recentchangescount',
919 'section' => 'rc/displayrc',
921 $defaultPreferences['usenewrc'] = [
923 'label-message' => 'tog-usenewrc',
924 'section' => 'rc/advancedrc',
926 $defaultPreferences['hideminor'] = [
928 'label-message' => 'tog-hideminor',
929 'section' => 'rc/advancedrc',
931 $defaultPreferences['rcfilters-saved-queries'] = [
934 $defaultPreferences['rcfilters-wl-saved-queries'] = [
937 $defaultPreferences['rcfilters-saved-queries-versionbackup'] = [
940 $defaultPreferences['rcfilters-wl-saved-queries-versionbackup'] = [
943 $defaultPreferences['rcfilters-rclimit'] = [
947 if ( $config->get( 'RCWatchCategoryMembership' ) ) {
948 $defaultPreferences['hidecategorization'] = [
950 'label-message' => 'tog-hidecategorization',
951 'section' => 'rc/advancedrc',
955 if ( $user->useRCPatrol() ) {
956 $defaultPreferences['hidepatrolled'] = [
958 'section' => 'rc/advancedrc',
959 'label-message' => 'tog-hidepatrolled',
963 if ( $user->useNPPatrol() ) {
964 $defaultPreferences['newpageshidepatrolled'] = [
966 'section' => 'rc/advancedrc',
967 'label-message' => 'tog-newpageshidepatrolled',
971 if ( $config->get( 'RCShowWatchingUsers' ) ) {
972 $defaultPreferences['shownumberswatching'] = [
974 'section' => 'rc/advancedrc',
975 'label-message' => 'tog-shownumberswatching',
979 if ( $config->get( 'StructuredChangeFiltersShowPreference' ) ) {
980 $defaultPreferences['rcenhancedfilters-disable'] = [
982 'section' => 'rc/opt-out',
983 'label-message' => 'rcfilters-preference-label',
984 'help-message' => 'rcfilters-preference-help',
991 * @param IContextSource $context
992 * @param array &$defaultPreferences
994 static function watchlistPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
995 $config = $context->getConfig();
996 $watchlistdaysMax = ceil( $config->get( 'RCMaxAge' ) / ( 3600 * 24 ) );
998 # # Watchlist #####################################
999 if ( $user->isAllowed( 'editmywatchlist' ) ) {
1000 $editWatchlistLinks = '';
1001 $editWatchlistModes = [
1002 'edit' => [ 'EditWatchlist', false ],
1003 'raw' => [ 'EditWatchlist', 'raw' ],
1004 'clear' => [ 'EditWatchlist', 'clear' ],
1006 $linkRenderer = MediaWikiServices
::getInstance()->getLinkRenderer();
1007 foreach ( $editWatchlistModes as $editWatchlistMode => $mode ) {
1008 // Messages: prefs-editwatchlist-edit, prefs-editwatchlist-raw, prefs-editwatchlist-clear
1009 $editWatchlistLinks .=
1010 new OOUI\
ButtonWidget( [
1011 'href' => SpecialPage
::getTitleFor( $mode[0], $mode[1] )->getLinkURL(),
1012 'label' => new OOUI\
HtmlSnippet(
1013 $context->msg( "prefs-editwatchlist-{$editWatchlistMode}" )->parse()
1018 $defaultPreferences['editwatchlist'] = [
1021 'default' => $editWatchlistLinks,
1022 'label-message' => 'prefs-editwatchlist-label',
1023 'section' => 'watchlist/editwatchlist',
1027 $defaultPreferences['watchlistdays'] = [
1030 'max' => $watchlistdaysMax,
1031 'section' => 'watchlist/displaywatchlist',
1032 'help' => $context->msg( 'prefs-watchlist-days-max' )->numParams(
1033 $watchlistdaysMax )->escaped(),
1034 'label-message' => 'prefs-watchlist-days',
1036 $defaultPreferences['wllimit'] = [
1040 'label-message' => 'prefs-watchlist-edits',
1041 'help' => $context->msg( 'prefs-watchlist-edits-max' )->escaped(),
1042 'section' => 'watchlist/displaywatchlist',
1044 $defaultPreferences['extendwatchlist'] = [
1046 'section' => 'watchlist/advancedwatchlist',
1047 'label-message' => 'tog-extendwatchlist',
1049 $defaultPreferences['watchlisthideminor'] = [
1051 'section' => 'watchlist/advancedwatchlist',
1052 'label-message' => 'tog-watchlisthideminor',
1054 $defaultPreferences['watchlisthidebots'] = [
1056 'section' => 'watchlist/advancedwatchlist',
1057 'label-message' => 'tog-watchlisthidebots',
1059 $defaultPreferences['watchlisthideown'] = [
1061 'section' => 'watchlist/advancedwatchlist',
1062 'label-message' => 'tog-watchlisthideown',
1064 $defaultPreferences['watchlisthideanons'] = [
1066 'section' => 'watchlist/advancedwatchlist',
1067 'label-message' => 'tog-watchlisthideanons',
1069 $defaultPreferences['watchlisthideliu'] = [
1071 'section' => 'watchlist/advancedwatchlist',
1072 'label-message' => 'tog-watchlisthideliu',
1074 $defaultPreferences['watchlistreloadautomatically'] = [
1076 'section' => 'watchlist/advancedwatchlist',
1077 'label-message' => 'tog-watchlistreloadautomatically',
1079 $defaultPreferences['watchlistunwatchlinks'] = [
1081 'section' => 'watchlist/advancedwatchlist',
1082 'label-message' => 'tog-watchlistunwatchlinks',
1085 if ( $config->get( 'RCWatchCategoryMembership' ) ) {
1086 $defaultPreferences['watchlisthidecategorization'] = [
1088 'section' => 'watchlist/advancedwatchlist',
1089 'label-message' => 'tog-watchlisthidecategorization',
1093 if ( $user->useRCPatrol() ) {
1094 $defaultPreferences['watchlisthidepatrolled'] = [
1096 'section' => 'watchlist/advancedwatchlist',
1097 'label-message' => 'tog-watchlisthidepatrolled',
1102 'edit' => 'watchdefault',
1103 'move' => 'watchmoves',
1104 'delete' => 'watchdeletion'
1108 if ( $user->isAllowed( 'createpage' ) ||
$user->isAllowed( 'createtalk' ) ) {
1109 $watchTypes['read'] = 'watchcreations';
1112 if ( $user->isAllowed( 'rollback' ) ) {
1113 $watchTypes['rollback'] = 'watchrollback';
1116 if ( $user->isAllowed( 'upload' ) ) {
1117 $watchTypes['upload'] = 'watchuploads';
1120 foreach ( $watchTypes as $action => $pref ) {
1121 if ( $user->isAllowed( $action ) ) {
1123 // tog-watchdefault, tog-watchmoves, tog-watchdeletion, tog-watchcreations, tog-watchuploads
1124 // tog-watchrollback
1125 $defaultPreferences[$pref] = [
1127 'section' => 'watchlist/advancedwatchlist',
1128 'label-message' => "tog-$pref",
1133 if ( $config->get( 'EnableAPI' ) ) {
1134 $defaultPreferences['watchlisttoken'] = [
1137 $defaultPreferences['watchlisttoken-info'] = [
1139 'section' => 'watchlist/tokenwatchlist',
1140 'label-message' => 'prefs-watchlist-token',
1141 'default' => $user->getTokenFromOption( 'watchlisttoken' ),
1142 'help-message' => 'prefs-help-watchlist-token2',
1144 $defaultPreferences['watchlisttoken-info2'] = [
1146 'section' => 'watchlist/tokenwatchlist',
1148 'default' => $context->msg( 'prefs-help-watchlist-token2' )->parse(),
1155 * @param IContextSource $context
1156 * @param array &$defaultPreferences
1158 static function searchPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
1159 foreach ( MWNamespace
::getValidNamespaces() as $n ) {
1160 $defaultPreferences['searchNs' . $n] = [
1167 * Dummy, kept for backwards-compatibility.
1169 * @param IContextSource $context
1170 * @param array &$defaultPreferences
1172 static function miscPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
1176 * @param User $user The User object
1177 * @param IContextSource $context
1178 * @return array Text/links to display as key; $skinkey as value
1180 static function generateSkinOptions( $user, IContextSource
$context ) {
1183 $mptitle = Title
::newMainPage();
1184 $previewtext = $context->msg( 'skin-preview' )->escaped();
1186 $linkRenderer = MediaWikiServices
::getInstance()->getLinkRenderer();
1188 # Only show skins that aren't disabled in $wgSkipSkins
1189 $validSkinNames = Skin
::getAllowedSkins();
1191 # Sort by UI skin name. First though need to update validSkinNames as sometimes
1192 # the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI).
1193 foreach ( $validSkinNames as $skinkey => &$skinname ) {
1194 $msg = $context->msg( "skinname-{$skinkey}" );
1195 if ( $msg->exists() ) {
1196 $skinname = htmlspecialchars( $msg->text() );
1199 asort( $validSkinNames );
1201 $config = $context->getConfig();
1202 $defaultSkin = $config->get( 'DefaultSkin' );
1203 $allowUserCss = $config->get( 'AllowUserCss' );
1204 $allowUserJs = $config->get( 'AllowUserJs' );
1206 $foundDefault = false;
1207 foreach ( $validSkinNames as $skinkey => $sn ) {
1210 # Mark the default skin
1211 if ( strcasecmp( $skinkey, $defaultSkin ) === 0 ) {
1212 $linkTools[] = $context->msg( 'default' )->escaped();
1213 $foundDefault = true;
1216 # Create preview link
1217 $mplink = htmlspecialchars( $mptitle->getLocalURL( [ 'useskin' => $skinkey ] ) );
1218 $linkTools[] = "<a target='_blank' href=\"$mplink\">$previewtext</a>";
1220 # Create links to user CSS/JS pages
1221 if ( $allowUserCss ) {
1222 $cssPage = Title
::makeTitleSafe( NS_USER
, $user->getName() . '/' . $skinkey . '.css' );
1223 $linkTools[] = $linkRenderer->makeLink( $cssPage, $context->msg( 'prefs-custom-css' )->text() );
1226 if ( $allowUserJs ) {
1227 $jsPage = Title
::makeTitleSafe( NS_USER
, $user->getName() . '/' . $skinkey . '.js' );
1228 $linkTools[] = $linkRenderer->makeLink( $jsPage, $context->msg( 'prefs-custom-js' )->text() );
1231 $display = $sn . ' ' . $context->msg( 'parentheses' )
1232 ->rawParams( $context->getLanguage()->pipeList( $linkTools ) )
1234 $ret[$display] = $skinkey;
1237 if ( !$foundDefault ) {
1238 // If the default skin is not available, things are going to break horribly because the
1239 // default value for skin selector will not be a valid value. Let's just not show it then.
1247 * @param IContextSource $context
1250 static function getDateOptions( IContextSource
$context ) {
1251 $lang = $context->getLanguage();
1252 $dateopts = $lang->getDatePreferences();
1257 if ( !in_array( 'default', $dateopts ) ) {
1258 $dateopts[] = 'default'; // Make sure default is always valid T21237
1261 // FIXME KLUGE: site default might not be valid for user language
1262 global $wgDefaultUserOptions;
1263 if ( !in_array( $wgDefaultUserOptions['date'], $dateopts ) ) {
1264 $wgDefaultUserOptions['date'] = 'default';
1267 $epoch = wfTimestampNow();
1268 foreach ( $dateopts as $key ) {
1269 if ( $key == 'default' ) {
1270 $formatted = $context->msg( 'datedefault' )->escaped();
1272 $formatted = htmlspecialchars( $lang->timeanddate( $epoch, false, $key ) );
1274 $ret[$formatted] = $key;
1281 * @param IContextSource $context
1284 static function getImageSizes( IContextSource
$context ) {
1286 $pixels = $context->msg( 'unit-pixel' )->text();
1288 foreach ( $context->getConfig()->get( 'ImageLimits' ) as $index => $limits ) {
1289 // Note: A left-to-right marker (\u200e) is inserted, see T144386
1290 $display = "{$limits[0]}" . json_decode( '"\u200e"' ) . "×{$limits[1]}" . $pixels;
1291 $ret[$display] = $index;
1298 * @param IContextSource $context
1301 static function getThumbSizes( IContextSource
$context ) {
1303 $pixels = $context->msg( 'unit-pixel' )->text();
1305 foreach ( $context->getConfig()->get( 'ThumbLimits' ) as $index => $size ) {
1306 $display = $size . $pixels;
1307 $ret[$display] = $index;
1314 * @param string $signature
1315 * @param array $alldata
1316 * @param HTMLForm $form
1317 * @return bool|string
1319 static function validateSignature( $signature, $alldata, $form ) {
1321 $maxSigChars = $form->getConfig()->get( 'MaxSigChars' );
1322 if ( mb_strlen( $signature ) > $maxSigChars ) {
1323 return Xml
::element( 'span', [ 'class' => 'error' ],
1324 $form->msg( 'badsiglength' )->numParams( $maxSigChars )->text() );
1325 } elseif ( isset( $alldata['fancysig'] ) &&
1326 $alldata['fancysig'] &&
1327 $wgParser->validateSig( $signature ) === false
1329 return Xml
::element(
1331 [ 'class' => 'error' ],
1332 $form->msg( 'badsig' )->text()
1340 * @param string $signature
1341 * @param array $alldata
1342 * @param HTMLForm $form
1345 static function cleanSignature( $signature, $alldata, $form ) {
1346 if ( isset( $alldata['fancysig'] ) && $alldata['fancysig'] ) {
1348 $signature = $wgParser->cleanSig( $signature );
1350 // When no fancy sig used, make sure ~{3,5} get removed.
1351 $signature = Parser
::cleanSigInSig( $signature );
1359 * @param IContextSource $context
1360 * @param string $formClass
1361 * @param array $remove Array of items to remove
1362 * @return PreferencesForm|HTMLForm
1364 static function getFormObject(
1366 IContextSource
$context,
1367 $formClass = 'PreferencesForm',
1370 // We use ButtonWidgets in some of the getPreferences() functions
1371 $context->getOutput()->enableOOUI();
1373 $formDescriptor = self
::getPreferences( $user, $context );
1374 if ( count( $remove ) ) {
1375 $removeKeys = array_flip( $remove );
1376 $formDescriptor = array_diff_key( $formDescriptor, $removeKeys );
1379 // Remove type=api preferences. They are not intended for rendering in the form.
1380 foreach ( $formDescriptor as $name => $info ) {
1381 if ( isset( $info['type'] ) && $info['type'] === 'api' ) {
1382 unset( $formDescriptor[$name] );
1387 * @var $htmlForm PreferencesForm
1389 $htmlForm = new $formClass( $formDescriptor, $context, 'prefs' );
1391 $htmlForm->setModifiedUser( $user );
1392 $htmlForm->setId( 'mw-prefs-form' );
1393 $htmlForm->setAutocomplete( 'off' );
1394 $htmlForm->setSubmitText( $context->msg( 'saveprefs' )->text() );
1395 # Used message keys: 'accesskey-preferences-save', 'tooltip-preferences-save'
1396 $htmlForm->setSubmitTooltip( 'preferences-save' );
1397 $htmlForm->setSubmitID( 'prefcontrol' );
1398 $htmlForm->setSubmitCallback( [ 'Preferences', 'tryFormSubmit' ] );
1404 * @param IContextSource $context
1407 static function getTimezoneOptions( IContextSource
$context ) {
1410 $localTZoffset = $context->getConfig()->get( 'LocalTZoffset' );
1411 $timeZoneList = self
::getTimeZoneList( $context->getLanguage() );
1413 $timestamp = MWTimestamp
::getLocalInstance();
1414 // Check that the LocalTZoffset is the same as the local time zone offset
1415 if ( $localTZoffset == $timestamp->format( 'Z' ) / 60 ) {
1416 $timezoneName = $timestamp->getTimezone()->getName();
1417 // Localize timezone
1418 if ( isset( $timeZoneList[$timezoneName] ) ) {
1419 $timezoneName = $timeZoneList[$timezoneName]['name'];
1421 $server_tz_msg = $context->msg(
1422 'timezoneuseserverdefault',
1426 $tzstring = sprintf(
1428 floor( $localTZoffset / 60 ),
1429 abs( $localTZoffset ) %
60
1431 $server_tz_msg = $context->msg( 'timezoneuseserverdefault', $tzstring )->text();
1433 $opt[$server_tz_msg] = "System|$localTZoffset";
1434 $opt[$context->msg( 'timezoneuseoffset' )->text()] = 'other';
1435 $opt[$context->msg( 'guesstimezone' )->text()] = 'guess';
1437 foreach ( $timeZoneList as $timeZoneInfo ) {
1438 $region = $timeZoneInfo['region'];
1439 if ( !isset( $opt[$region] ) ) {
1442 $opt[$region][$timeZoneInfo['name']] = $timeZoneInfo['timecorrection'];
1448 * @param string $value
1449 * @param array $alldata
1452 static function filterIntval( $value, $alldata ) {
1453 return intval( $value );
1458 * @param array $alldata
1461 static function filterTimezoneInput( $tz, $alldata ) {
1462 $data = explode( '|', $tz, 3 );
1463 switch ( $data[0] ) {
1467 if ( count( $data ) === 3 ) {
1468 // Make sure this timezone exists
1470 new DateTimeZone( $data[2] );
1471 // If the constructor didn't throw, we know it's valid
1473 } catch ( Exception
$e ) {
1474 // Not a valid timezone
1479 // If the supplied timezone doesn't exist, fall back to the encoded offset
1480 return 'Offset|' . intval( $tz[1] );
1486 $data = explode( ':', $tz, 2 );
1487 if ( count( $data ) == 2 ) {
1488 $data[0] = intval( $data[0] );
1489 $data[1] = intval( $data[1] );
1490 $minDiff = abs( $data[0] ) * 60 +
$data[1];
1491 if ( $data[0] < 0 ) {
1492 $minDiff = - $minDiff;
1495 $minDiff = intval( $data[0] ) * 60;
1498 # Max is +14:00 and min is -12:00, see:
1499 # https://en.wikipedia.org/wiki/Timezone
1500 $minDiff = min( $minDiff, 840 ); # 14:00
1501 $minDiff = max( $minDiff, -720 ); # -12:00
1502 return 'Offset|' . $minDiff;
1507 * Handle the form submission if everything validated properly
1509 * @param array $formData
1510 * @param PreferencesForm $form
1511 * @return bool|Status|string
1513 static function tryFormSubmit( $formData, $form ) {
1514 $user = $form->getModifiedUser();
1515 $hiddenPrefs = $form->getConfig()->get( 'HiddenPrefs' );
1518 if ( !$user->isAllowedAny( 'editmyprivateinfo', 'editmyoptions' ) ) {
1519 return Status
::newFatal( 'mypreferencesprotected' );
1523 foreach ( array_keys( $formData ) as $name ) {
1524 if ( isset( self
::$saveFilters[$name] ) ) {
1526 call_user_func( self
::$saveFilters[$name], $formData[$name], $formData );
1530 // Fortunately, the realname field is MUCH simpler
1531 // (not really "private", but still shouldn't be edited without permission)
1533 if ( !in_array( 'realname', $hiddenPrefs )
1534 && $user->isAllowed( 'editmyprivateinfo' )
1535 && array_key_exists( 'realname', $formData )
1537 $realName = $formData['realname'];
1538 $user->setRealName( $realName );
1541 if ( $user->isAllowed( 'editmyoptions' ) ) {
1542 $oldUserOptions = $user->getOptions();
1544 foreach ( self
::$saveBlacklist as $b ) {
1545 unset( $formData[$b] );
1548 # If users have saved a value for a preference which has subsequently been disabled
1549 # via $wgHiddenPrefs, we don't want to destroy that setting in case the preference
1550 # is subsequently re-enabled
1551 foreach ( $hiddenPrefs as $pref ) {
1552 # If the user has not set a non-default value here, the default will be returned
1553 # and subsequently discarded
1554 $formData[$pref] = $user->getOption( $pref, null, true );
1557 // Keep old preferences from interfering due to back-compat code, etc.
1558 $user->resetOptions( 'unused', $form->getContext() );
1560 foreach ( $formData as $key => $value ) {
1561 $user->setOption( $key, $value );
1565 'PreferencesFormPreSave',
1566 [ $formData, $form, $user, &$result, $oldUserOptions ]
1570 MediaWiki\Auth\AuthManager
::callLegacyAuthPlugin( 'updateExternalDB', [ $user ] );
1571 $user->saveSettings();
1577 * @param array $formData
1578 * @param PreferencesForm $form
1581 public static function tryUISubmit( $formData, $form ) {
1582 $res = self
::tryFormSubmit( $formData, $form );
1587 if ( $res === 'eauth' ) {
1588 $urlOptions['eauth'] = 1;
1591 $urlOptions +
= $form->getExtraSuccessRedirectParameters();
1593 $url = $form->getTitle()->getFullURL( $urlOptions );
1595 $context = $form->getContext();
1596 // Set session data for the success message
1597 $context->getRequest()->getSession()->set( 'specialPreferencesSaveSuccess', 1 );
1599 $context->getOutput()->redirect( $url );
1602 return Status
::newGood();
1606 * Get a list of all time zones
1607 * @param Language $language Language used for the localized names
1608 * @return array A list of all time zones. The system name of the time zone is used as key and
1609 * the value is an array which contains localized name, the timecorrection value used for
1610 * preferences and the region
1613 public static function getTimeZoneList( Language
$language ) {
1614 $identifiers = DateTimeZone
::listIdentifiers();
1615 if ( $identifiers === false ) {
1618 sort( $identifiers );
1621 'Africa' => wfMessage( 'timezoneregion-africa' )->inLanguage( $language )->text(),
1622 'America' => wfMessage( 'timezoneregion-america' )->inLanguage( $language )->text(),
1623 'Antarctica' => wfMessage( 'timezoneregion-antarctica' )->inLanguage( $language )->text(),
1624 'Arctic' => wfMessage( 'timezoneregion-arctic' )->inLanguage( $language )->text(),
1625 'Asia' => wfMessage( 'timezoneregion-asia' )->inLanguage( $language )->text(),
1626 'Atlantic' => wfMessage( 'timezoneregion-atlantic' )->inLanguage( $language )->text(),
1627 'Australia' => wfMessage( 'timezoneregion-australia' )->inLanguage( $language )->text(),
1628 'Europe' => wfMessage( 'timezoneregion-europe' )->inLanguage( $language )->text(),
1629 'Indian' => wfMessage( 'timezoneregion-indian' )->inLanguage( $language )->text(),
1630 'Pacific' => wfMessage( 'timezoneregion-pacific' )->inLanguage( $language )->text(),
1632 asort( $tzRegions );
1636 $now = new DateTime();
1638 foreach ( $identifiers as $identifier ) {
1639 $parts = explode( '/', $identifier, 2 );
1641 // DateTimeZone::listIdentifiers() returns a number of
1642 // backwards-compatibility entries. This filters them out of the
1643 // list presented to the user.
1644 if ( count( $parts ) !== 2 ||
!array_key_exists( $parts[0], $tzRegions ) ) {
1649 $parts[0] = $tzRegions[$parts[0]];
1651 $dateTimeZone = new DateTimeZone( $identifier );
1652 $minDiff = floor( $dateTimeZone->getOffset( $now ) / 60 );
1654 $display = str_replace( '_', ' ', $parts[0] . '/' . $parts[1] );
1655 $value = "ZoneInfo|$minDiff|$identifier";
1657 $timeZoneList[$identifier] = [
1659 'timecorrection' => $value,
1660 'region' => $parts[0],
1664 return $timeZoneList;