34 use LanguageConverter;
47 use Psr\Log\LoggerAwareTrait;
48 use Psr\Log\NullLogger;
53 use UnexpectedValueException;
92 $this->logger =
new NullLogger();
114 OutputPage::setupOOUI(
133 $this->logger->debug(
"Created form descriptor for user '{$user->getName()}'" );
148 # # Remove preferences that wikis don't want to use
149 foreach ( $this->config->get(
'HiddenPrefs' )
as $pref ) {
150 if ( isset( $defaultPreferences[$pref] ) ) {
151 unset( $defaultPreferences[$pref] );
155 # # Make sure that form fields have their parent set. See T43337.
158 $disable = !
$user->isAllowed(
'editmyoptions' );
161 $userOptions =
$user->getOptions();
162 $this->
applyFilters( $userOptions, $defaultPreferences,
'filterForForm' );
163 # # Prod in defaults from the user
164 foreach ( $defaultPreferences
as $name => &$info ) {
167 $info[
'disabled'] =
'disabled';
170 $globalDefault = $defaultOptions[
$name] ??
null;
173 if ( isset( $info[
'default'] ) ) {
176 } elseif ( !is_null( $prefFromUser ) &&
177 $field->validate( $prefFromUser,
$user->getOptions() ) ===
true ) {
178 $info[
'default'] = $prefFromUser;
179 } elseif ( $field->validate( $globalDefault,
$user->getOptions() ) ===
true ) {
180 $info[
'default'] = $globalDefault;
182 throw new MWException(
"Global default '$globalDefault' is invalid for field $name" );
186 return $defaultPreferences;
198 $val = $userOptions[
$name] ??
null;
201 if ( ( isset( $info[
'type'] ) && $info[
'type'] ==
'multiselect' ) ||
204 $prefix = $info[
'prefix'] ??
$name;
208 if ( $userOptions[
"$prefix$value"] ??
false ) {
215 if ( ( isset( $info[
'type'] ) && $info[
'type'] ==
'checkmatrix' ) ||
219 $prefix = $info[
'prefix'] ??
$name;
222 foreach ( $columns
as $column ) {
224 if ( $userOptions[
"$prefix$column-$row"] ??
false ) {
225 $val[] =
"$column-$row";
247 $userName =
$user->getName();
249 # # User info #####################################
251 $defaultPreferences[
'username'] = [
253 'label-message' => [
'username', $userName ],
254 'default' => $userName,
255 'section' =>
'personal/info',
260 # Get groups to which the user belongs
261 $userEffectiveGroups =
$user->getEffectiveGroups();
262 $userGroupMemberships =
$user->getGroupMemberships();
263 $userGroups = $userMembers = $userTempGroups = $userTempMembers = [];
264 foreach ( $userEffectiveGroups
as $ueg ) {
270 if ( isset( $userGroupMemberships[$ueg] ) ) {
271 $groupStringOrObject = $userGroupMemberships[$ueg];
273 $groupStringOrObject = $ueg;
287 $userTempGroups[] = $userG;
288 $userTempMembers[] = $userM;
290 $userGroups[] = $userG;
291 $userMembers[] = $userM;
295 sort( $userMembers );
296 sort( $userTempGroups );
297 sort( $userTempMembers );
298 $userGroups = array_merge( $userTempGroups, $userGroups );
299 $userMembers = array_merge( $userTempMembers, $userMembers );
301 $defaultPreferences[
'usergroups'] = [
303 'label' =>
$context->
msg(
'prefs-memberingroups' )->numParams(
304 count( $userGroups ) )->params( $userName )->parse(),
305 'default' =>
$context->
msg(
'prefs-memberingroups-type' )
306 ->rawParams(
$lang->commaList( $userGroups ),
$lang->commaList( $userMembers ) )
309 'section' =>
'personal/info',
313 $formattedEditCount =
$lang->formatNum(
$user->getEditCount() );
314 $editCount = $this->linkRenderer->makeLink( $contribTitle, $formattedEditCount );
316 $defaultPreferences[
'editcount'] = [
319 'label-message' =>
'prefs-edits',
320 'default' => $editCount,
321 'section' =>
'personal/info',
324 if (
$user->getRegistration() ) {
326 $userRegistration =
$user->getRegistration();
327 $defaultPreferences[
'registrationdate'] = [
329 'label-message' =>
'prefs-registration',
331 'prefs-registration-date-time',
332 $lang->userTimeAndDate( $userRegistration, $displayUser ),
333 $lang->userDate( $userRegistration, $displayUser ),
334 $lang->userTime( $userRegistration, $displayUser )
336 'section' =>
'personal/info',
340 $canViewPrivateInfo =
$user->isAllowed(
'viewmyprivateinfo' );
341 $canEditPrivateInfo =
$user->isAllowed(
'editmyprivateinfo' );
344 $defaultPreferences[
'realname'] = [
346 'type' => $canEditPrivateInfo && $this->authManager->allowsPropertyChange(
'realname' )
348 'default' =>
$user->getRealName(),
349 'section' =>
'personal/info',
350 'label-message' =>
'yourrealname',
351 'help-message' =>
'prefs-help-realname',
354 if ( $canEditPrivateInfo && $this->authManager->allowsAuthenticationDataChange(
357 $defaultPreferences[
'password'] = [
360 'default' => (
string)
new \OOUI\ButtonWidget( [
364 'label' =>
$context->
msg(
'prefs-resetpass' )->text(),
366 'label-message' =>
'yourpassword',
367 'section' =>
'personal/info',
371 if ( $this->config->get(
'SecureLogin' ) && $canIPUseHTTPS ) {
372 $defaultPreferences[
'prefershttps'] = [
374 'label-message' =>
'tog-prefershttps',
375 'help-message' =>
'prefs-help-prefershttps',
376 'section' =>
'personal/info'
382 $languageCode = $this->config->get(
'LanguageCode' );
383 if ( !array_key_exists( $languageCode,
$languages ) ) {
394 $defaultPreferences[
'language'] = [
396 'section' =>
'personal/i18n',
398 'label-message' =>
'yourlanguage',
401 $defaultPreferences[
'gender'] = [
403 'section' =>
'personal/i18n',
406 ->params(
$context->
msg(
'gender-unknown' )->plain() )
407 ->escaped() =>
'unknown',
408 $context->
msg(
'gender-female' )->escaped() =>
'female',
409 $context->
msg(
'gender-male' )->escaped() =>
'male',
411 'label-message' =>
'yourgender',
412 'help-message' =>
'prefs-help-gender',
416 if ( !$this->config->get(
'DisableLangConversion' ) ) {
417 foreach ( LanguageConverter::$languagesWithVariants
as $langCode ) {
418 if ( $langCode == $this->contLang->getCode() ) {
419 if ( !$this->contLang->hasVariants() ) {
423 $variants = $this->contLang->getVariants();
425 foreach ( $variants
as $v ) {
426 $v = str_replace(
'_',
'-', strtolower( $v ) );
427 $variantArray[$v] =
$lang->getVariantname( $v,
false );
436 $defaultPreferences[
'variant'] = [
437 'label-message' =>
'yourvariant',
440 'section' =>
'personal/i18n',
441 'help-message' =>
'prefs-help-variant',
444 $defaultPreferences[
"variant-$langCode"] = [
453 $toggles = $this->contLang->getExtraUserToggles();
455 foreach ( $toggles
as $toggle ) {
456 $defaultPreferences[$toggle] = [
458 'section' =>
'personal/i18n',
459 'label-message' =>
"tog-$toggle",
471 $defaultPreferences[
'oldsig'] = [
474 'label-message' =>
'tog-oldsig',
475 'default' => $oldsigHTML,
476 'section' =>
'personal/signature',
478 $defaultPreferences[
'nickname'] = [
479 'type' => $this->authManager->allowsPropertyChange(
'nickname' ) ?
'text' :
'info',
480 'maxlength' => $this->config->get(
'MaxSigChars' ),
481 'label-message' =>
'yournick',
482 'validation-callback' =>
function ( $signature, $alldata,
HTMLForm $form ) {
485 'section' =>
'personal/signature',
486 'filter-callback' =>
function ( $signature,
array $alldata,
HTMLForm $form ) {
490 $defaultPreferences[
'fancysig'] = [
492 'label-message' =>
'tog-fancysig',
494 'help-message' =>
'prefs-help-signature',
495 'section' =>
'personal/signature'
500 if ( $this->config->get(
'EnableEmail' ) ) {
501 if ( $canViewPrivateInfo ) {
502 $helpMessages[] = $this->config->get(
'EmailConfirmToEdit' )
503 ?
'prefs-help-email-required'
504 :
'prefs-help-email';
506 if ( $this->config->get(
'EnableUserEmail' ) ) {
508 $helpMessages[] =
'prefs-help-email-others';
511 $emailAddress =
$user->getEmail() ? htmlspecialchars(
$user->getEmail() ) :
'';
512 if ( $canEditPrivateInfo && $this->authManager->allowsPropertyChange(
'emailaddress' ) ) {
513 $button = new \OOUI\ButtonWidget( [
521 $emailAddress .= $emailAddress ==
'' ? $button : (
'<br />' . $button );
524 $defaultPreferences[
'emailaddress'] = [
527 'default' => $emailAddress,
528 'label-message' =>
'youremail',
529 'section' =>
'personal/email',
530 'help-messages' => $helpMessages,
531 # 'cssclass' chosen below
535 $disableEmailPrefs =
false;
537 if ( $this->config->get(
'EmailAuthentication' ) ) {
538 $emailauthenticationclass =
'mw-email-not-authenticated';
539 if (
$user->getEmail() ) {
540 if (
$user->getEmailAuthenticationTimestamp() ) {
545 $emailTimestamp =
$user->getEmailAuthenticationTimestamp();
546 $time =
$lang->userTimeAndDate( $emailTimestamp, $displayUser );
547 $d =
$lang->userDate( $emailTimestamp, $displayUser );
548 $t =
$lang->userTime( $emailTimestamp, $displayUser );
549 $emailauthenticated =
$context->
msg(
'emailauthenticated',
550 $time, $d,
$t )->parse() .
'<br />';
551 $disableEmailPrefs =
false;
552 $emailauthenticationclass =
'mw-email-authenticated';
554 $disableEmailPrefs =
true;
555 $emailauthenticated =
$context->
msg(
'emailnotauthenticated' )->parse() .
'<br />' .
556 new \OOUI\ButtonWidget( [
558 'label' =>
$context->
msg(
'emailconfirmlink' )->text(),
560 $emailauthenticationclass =
"mw-email-not-authenticated";
563 $disableEmailPrefs =
true;
564 $emailauthenticated =
$context->
msg(
'noemailprefs' )->escaped();
565 $emailauthenticationclass =
'mw-email-none';
568 if ( $canViewPrivateInfo ) {
569 $defaultPreferences[
'emailauthentication'] = [
572 'section' =>
'personal/email',
573 'label-message' =>
'prefs-emailconfirm-label',
574 'default' => $emailauthenticated,
575 # Apply the same CSS class used on the input to the message:
576 'cssclass' => $emailauthenticationclass,
581 if ( $this->config->get(
'EnableUserEmail' ) &&
$user->isAllowed(
'sendemail' ) ) {
582 $defaultPreferences[
'disablemail'] = [
583 'id' =>
'wpAllowEmail',
586 'section' =>
'personal/email',
587 'label-message' =>
'allowemail',
588 'disabled' => $disableEmailPrefs,
591 $defaultPreferences[
'email-allow-new-users'] = [
592 'id' =>
'wpAllowEmailFromNewUsers',
594 'section' =>
'personal/email',
595 'label-message' =>
'email-allow-new-users-label',
596 'disabled' => $disableEmailPrefs,
599 $defaultPreferences[
'ccmeonemails'] = [
601 'section' =>
'personal/email',
602 'label-message' =>
'tog-ccmeonemails',
603 'disabled' => $disableEmailPrefs,
606 if ( $this->config->get(
'EnableUserEmailBlacklist' ) ) {
607 $defaultPreferences[
'email-blacklist'] = [
608 'type' =>
'usersmultiselect',
609 'label-message' =>
'email-blacklist-label',
610 'section' =>
'personal/email',
611 'disabled' => $disableEmailPrefs,
617 if ( $this->config->get(
'EnotifWatchlist' ) ) {
618 $defaultPreferences[
'enotifwatchlistpages'] = [
620 'section' =>
'personal/email',
621 'label-message' =>
'tog-enotifwatchlistpages',
622 'disabled' => $disableEmailPrefs,
625 if ( $this->config->get(
'EnotifUserTalk' ) ) {
626 $defaultPreferences[
'enotifusertalkpages'] = [
628 'section' =>
'personal/email',
629 'label-message' =>
'tog-enotifusertalkpages',
630 'disabled' => $disableEmailPrefs,
633 if ( $this->config->get(
'EnotifUserTalk' ) || $this->config->get(
'EnotifWatchlist' ) ) {
634 if ( $this->config->get(
'EnotifMinorEdits' ) ) {
635 $defaultPreferences[
'enotifminoredits'] = [
637 'section' =>
'personal/email',
638 'label-message' =>
'tog-enotifminoredits',
639 'disabled' => $disableEmailPrefs,
643 if ( $this->config->get(
'EnotifRevealEditorAddress' ) ) {
644 $defaultPreferences[
'enotifrevealaddr'] = [
646 'section' =>
'personal/email',
647 'label-message' =>
'tog-enotifrevealaddr',
648 'disabled' => $disableEmailPrefs,
662 # # Skin #####################################
666 if ( $skinOptions ) {
667 $defaultPreferences[
'skin'] = [
669 'options' => $skinOptions,
670 'section' =>
'rendering/skin',
674 $allowUserCss = $this->config->get(
'AllowUserCss' );
675 $allowUserJs = $this->config->get(
'AllowUserJs' );
676 # Create links to user CSS/JS pages for all skins
677 # This code is basically copied from generateSkinOptions(). It'd
678 # be nice to somehow merge this back in there to avoid redundancy.
679 if ( $allowUserCss || $allowUserJs ) {
681 $userName =
$user->getName();
683 if ( $allowUserCss ) {
685 $cssLinkText =
$context->
msg(
'prefs-custom-css' )->text();
686 $linkTools[] = $this->linkRenderer->makeLink( $cssPage, $cssLinkText );
689 if ( $allowUserJs ) {
691 $jsLinkText =
$context->
msg(
'prefs-custom-js' )->text();
692 $linkTools[] = $this->linkRenderer->makeLink( $jsPage, $jsLinkText );
695 $defaultPreferences[
'commoncssjs'] = [
699 'label-message' =>
'prefs-common-config',
700 'section' =>
'rendering/skin',
710 # # Files #####################################
711 $defaultPreferences[
'imagesize'] = [
714 'label-message' =>
'imagemaxsize',
715 'section' =>
'rendering/files',
717 $defaultPreferences[
'thumbsize'] = [
720 'label-message' =>
'thumbsize',
721 'section' =>
'rendering/files',
732 # # Date and time #####################################
734 if ( $dateOptions ) {
735 $defaultPreferences[
'date'] = [
737 'options' => $dateOptions,
738 'section' =>
'rendering/dateformat',
745 $nowlocal =
Xml::element(
'span', [
'id' =>
'wpLocalTime' ],
748 [
'format' =>
false,
'timecorrection' =>
false ] ) .
749 Html::hidden(
'wpServerTime', (
int)substr( $now, 8, 2 ) * 60 + (
int)substr( $now, 10, 2 ) );
751 $defaultPreferences[
'nowserver'] = [
754 'label-message' =>
'servertime',
755 'default' => $nowserver,
756 'section' =>
'rendering/timeoffset',
759 $defaultPreferences[
'nowlocal'] = [
762 'label-message' =>
'localtime',
763 'default' => $nowlocal,
764 'section' =>
'rendering/timeoffset',
768 $tzOffset =
$user->getOption(
'timecorrection' );
769 $tz = explode(
'|', $tzOffset, 3 );
773 $tzSetting = $tzOffset;
774 if (
count( $tz ) > 1 && $tz[0] ==
'ZoneInfo' &&
779 $userTZ =
new DateTimeZone( $tz[2] );
780 $minDiff = floor( $userTZ->getOffset(
new DateTime(
'now' ) ) / 60 );
781 $tzSetting =
"ZoneInfo|$minDiff|{$tz[2]}";
782 }
catch ( Exception
$e ) {
787 if (
count( $tz ) > 1 && $tz[0] ==
'Offset' ) {
789 $tzSetting = sprintf(
'%+03d:%02d', floor( $minDiff / 60 ), abs( $minDiff ) % 60 );
792 $defaultPreferences[
'timecorrection'] = [
794 'label-message' =>
'timezonelegend',
795 'options' => $tzOptions,
796 'default' => $tzSetting,
798 'section' =>
'rendering/timeoffset',
799 'id' =>
'wpTimeCorrection',
809 # # Diffs ####################################
810 $defaultPreferences[
'diffonly'] = [
812 'section' =>
'rendering/diffs',
813 'label-message' =>
'tog-diffonly',
815 $defaultPreferences[
'norollbackdiff'] = [
817 'section' =>
'rendering/diffs',
818 'label-message' =>
'tog-norollbackdiff',
821 # # Page Rendering ##############################
822 if ( $this->config->get(
'AllowUserCssPrefs' ) ) {
823 $defaultPreferences[
'underline'] = [
826 $l10n->
msg(
'underline-never' )->text() => 0,
827 $l10n->
msg(
'underline-always' )->text() => 1,
828 $l10n->
msg(
'underline-default' )->text() => 2,
830 'label-message' =>
'tog-underline',
831 'section' =>
'rendering/advancedrendering',
835 $stubThresholdValues = [ 50, 100, 500, 1000, 2000, 5000, 10000 ];
836 $stubThresholdOptions = [ $l10n->
msg(
'stub-threshold-disabled' )->text() => 0 ];
837 foreach ( $stubThresholdValues
as $value ) {
838 $stubThresholdOptions[$l10n->
msg(
'size-bytes',
$value )->text()] =
$value;
841 $defaultPreferences[
'stubthreshold'] = [
843 'section' =>
'rendering/advancedrendering',
844 'options' => $stubThresholdOptions,
846 'label-raw' => $l10n->
msg(
'stub-threshold' )->rawParams(
847 '<a href="#" class="stub">' .
848 $l10n->
msg(
'stub-threshold-sample-link' )->parse() .
852 $defaultPreferences[
'showhiddencats'] = [
854 'section' =>
'rendering/advancedrendering',
855 'label-message' =>
'tog-showhiddencats'
858 $defaultPreferences[
'numberheadings'] = [
860 'section' =>
'rendering/advancedrendering',
861 'label-message' =>
'tog-numberheadings',
871 # # Editing #####################################
872 $defaultPreferences[
'editsectiononrightclick'] = [
874 'section' =>
'editing/advancedediting',
875 'label-message' =>
'tog-editsectiononrightclick',
877 $defaultPreferences[
'editondblclick'] = [
879 'section' =>
'editing/advancedediting',
880 'label-message' =>
'tog-editondblclick',
883 if ( $this->config->get(
'AllowUserCssPrefs' ) ) {
884 $defaultPreferences[
'editfont'] = [
886 'section' =>
'editing/editor',
887 'label-message' =>
'editfont-style',
889 $l10n->
msg(
'editfont-monospace' )->text() =>
'monospace',
890 $l10n->
msg(
'editfont-sansserif' )->text() =>
'sans-serif',
891 $l10n->
msg(
'editfont-serif' )->text() =>
'serif',
896 if (
$user->isAllowed(
'minoredit' ) ) {
897 $defaultPreferences[
'minordefault'] = [
899 'section' =>
'editing/editor',
900 'label-message' =>
'tog-minordefault',
904 $defaultPreferences[
'forceeditsummary'] = [
906 'section' =>
'editing/editor',
907 'label-message' =>
'tog-forceeditsummary',
909 $defaultPreferences[
'useeditwarning'] = [
911 'section' =>
'editing/editor',
912 'label-message' =>
'tog-useeditwarning',
915 $defaultPreferences[
'previewonfirst'] = [
917 'section' =>
'editing/preview',
918 'label-message' =>
'tog-previewonfirst',
920 $defaultPreferences[
'previewontop'] = [
922 'section' =>
'editing/preview',
923 'label-message' =>
'tog-previewontop',
925 $defaultPreferences[
'uselivepreview'] = [
927 'section' =>
'editing/preview',
928 'label-message' =>
'tog-uselivepreview',
938 $rcMaxAge = $this->config->get(
'RCMaxAge' );
939 # # RecentChanges #####################################
940 $defaultPreferences[
'rcdays'] = [
942 'label-message' =>
'recentchangesdays',
943 'section' =>
'rc/displayrc',
945 'max' => ceil( $rcMaxAge / ( 3600 * 24 ) ),
946 'help' => $l10n->
msg(
'recentchangesdays-max' )->numParams(
947 ceil( $rcMaxAge / ( 3600 * 24 ) ) )->escaped()
949 $defaultPreferences[
'rclimit'] = [
953 'label-message' =>
'recentchangescount',
954 'help-message' =>
'prefs-help-recentchangescount',
955 'section' =>
'rc/displayrc',
958 $defaultPreferences[
'usenewrc'] = [
960 'label-message' =>
'tog-usenewrc',
961 'section' =>
'rc/advancedrc',
963 $defaultPreferences[
'hideminor'] = [
965 'label-message' =>
'tog-hideminor',
966 'section' =>
'rc/advancedrc',
968 $defaultPreferences[
'rcfilters-rc-collapsed'] = [
971 $defaultPreferences[
'rcfilters-wl-collapsed'] = [
974 $defaultPreferences[
'rcfilters-saved-queries'] = [
977 $defaultPreferences[
'rcfilters-wl-saved-queries'] = [
981 $defaultPreferences[
'rcfilters-limit'] = [
984 $defaultPreferences[
'rcfilters-saved-queries-versionbackup'] = [
987 $defaultPreferences[
'rcfilters-wl-saved-queries-versionbackup'] = [
991 if ( $this->config->get(
'RCWatchCategoryMembership' ) ) {
992 $defaultPreferences[
'hidecategorization'] = [
994 'label-message' =>
'tog-hidecategorization',
995 'section' =>
'rc/advancedrc',
999 if (
$user->useRCPatrol() ) {
1000 $defaultPreferences[
'hidepatrolled'] = [
1002 'section' =>
'rc/advancedrc',
1003 'label-message' =>
'tog-hidepatrolled',
1007 if (
$user->useNPPatrol() ) {
1008 $defaultPreferences[
'newpageshidepatrolled'] = [
1010 'section' =>
'rc/advancedrc',
1011 'label-message' =>
'tog-newpageshidepatrolled',
1015 if ( $this->config->get(
'RCShowWatchingUsers' ) ) {
1016 $defaultPreferences[
'shownumberswatching'] = [
1018 'section' =>
'rc/advancedrc',
1019 'label-message' =>
'tog-shownumberswatching',
1023 $defaultPreferences[
'rcenhancedfilters-disable'] = [
1025 'section' =>
'rc/optoutrc',
1026 'label-message' =>
'rcfilters-preference-label',
1027 'help-message' =>
'rcfilters-preference-help',
1039 $watchlistdaysMax = ceil( $this->config->get(
'RCMaxAge' ) / ( 3600 * 24 ) );
1041 # # Watchlist #####################################
1042 if (
$user->isAllowed(
'editmywatchlist' ) ) {
1043 $editWatchlistLinks =
'';
1044 $editWatchlistLinksOld = [];
1045 $editWatchlistModes = [
1046 'edit' => [
'subpage' =>
false,
'flags' => [] ],
1047 'raw' => [
'subpage' =>
'raw',
'flags' => [] ],
1048 'clear' => [
'subpage' =>
'clear',
'flags' => [
'destructive' ] ],
1050 foreach ( $editWatchlistModes
as $mode =>
$options ) {
1052 $editWatchlistLinks .=
1053 new \OOUI\ButtonWidget( [
1056 'label' =>
new \OOUI\HtmlSnippet(
1057 $context->
msg(
"prefs-editwatchlist-{$mode}" )->parse()
1062 $defaultPreferences[
'editwatchlist'] = [
1065 'default' => $editWatchlistLinks,
1066 'label-message' =>
'prefs-editwatchlist-label',
1067 'section' =>
'watchlist/editwatchlist',
1071 $defaultPreferences[
'watchlistdays'] = [
1074 'max' => $watchlistdaysMax,
1075 'section' =>
'watchlist/displaywatchlist',
1076 'help' =>
$context->
msg(
'prefs-watchlist-days-max' )->numParams(
1077 $watchlistdaysMax )->escaped(),
1078 'label-message' =>
'prefs-watchlist-days',
1080 $defaultPreferences[
'wllimit'] = [
1084 'label-message' =>
'prefs-watchlist-edits',
1085 'help' =>
$context->
msg(
'prefs-watchlist-edits-max' )->escaped(),
1086 'section' =>
'watchlist/displaywatchlist',
1089 $defaultPreferences[
'extendwatchlist'] = [
1091 'section' =>
'watchlist/advancedwatchlist',
1092 'label-message' =>
'tog-extendwatchlist',
1094 $defaultPreferences[
'watchlisthideminor'] = [
1096 'section' =>
'watchlist/advancedwatchlist',
1097 'label-message' =>
'tog-watchlisthideminor',
1099 $defaultPreferences[
'watchlisthidebots'] = [
1101 'section' =>
'watchlist/advancedwatchlist',
1102 'label-message' =>
'tog-watchlisthidebots',
1104 $defaultPreferences[
'watchlisthideown'] = [
1106 'section' =>
'watchlist/advancedwatchlist',
1107 'label-message' =>
'tog-watchlisthideown',
1109 $defaultPreferences[
'watchlisthideanons'] = [
1111 'section' =>
'watchlist/advancedwatchlist',
1112 'label-message' =>
'tog-watchlisthideanons',
1114 $defaultPreferences[
'watchlisthideliu'] = [
1116 'section' =>
'watchlist/advancedwatchlist',
1117 'label-message' =>
'tog-watchlisthideliu',
1124 $defaultPreferences[
'watchlistreloadautomatically'] = [
1126 'section' =>
'watchlist/advancedwatchlist',
1127 'label-message' =>
'tog-watchlistreloadautomatically',
1131 $defaultPreferences[
'watchlistunwatchlinks'] = [
1133 'section' =>
'watchlist/advancedwatchlist',
1134 'label-message' =>
'tog-watchlistunwatchlinks',
1137 if ( $this->config->get(
'RCWatchCategoryMembership' ) ) {
1138 $defaultPreferences[
'watchlisthidecategorization'] = [
1140 'section' =>
'watchlist/advancedwatchlist',
1141 'label-message' =>
'tog-watchlisthidecategorization',
1145 if (
$user->useRCPatrol() ) {
1146 $defaultPreferences[
'watchlisthidepatrolled'] = [
1148 'section' =>
'watchlist/advancedwatchlist',
1149 'label-message' =>
'tog-watchlisthidepatrolled',
1154 'edit' =>
'watchdefault',
1155 'move' =>
'watchmoves',
1156 'delete' =>
'watchdeletion'
1160 if (
$user->isAllowed(
'createpage' ) ||
$user->isAllowed(
'createtalk' ) ) {
1161 $watchTypes[
'read'] =
'watchcreations';
1164 if (
$user->isAllowed(
'rollback' ) ) {
1165 $watchTypes[
'rollback'] =
'watchrollback';
1168 if (
$user->isAllowed(
'upload' ) ) {
1169 $watchTypes[
'upload'] =
'watchuploads';
1172 foreach ( $watchTypes
as $action => $pref ) {
1177 $defaultPreferences[$pref] = [
1179 'section' =>
'watchlist/advancedwatchlist',
1180 'label-message' =>
"tog-$pref",
1185 $defaultPreferences[
'watchlisttoken'] = [
1189 $tokenButton = new \OOUI\ButtonWidget( [
1193 'label' =>
$context->
msg(
'prefs-watchlist-managetokens' )->text(),
1195 $defaultPreferences[
'watchlisttoken-info'] = [
1197 'section' =>
'watchlist/tokenwatchlist',
1198 'label-message' =>
'prefs-watchlist-token',
1199 'help-message' =>
'prefs-help-tokenmanagement',
1201 'default' => (
string)$tokenButton,
1204 $defaultPreferences[
'wlenhancedfilters-disable'] = [
1206 'section' =>
'watchlist/optoutwatchlist',
1207 'label-message' =>
'rcfilters-watchlist-preference-label',
1208 'help-message' =>
'rcfilters-watchlist-preference-help',
1217 $defaultPreferences[
'searchNs' . $n] = [
1232 $previewtext =
$context->
msg(
'skin-preview' )->escaped();
1234 # Only show skins that aren't disabled in $wgSkipSkins
1237 foreach ( $validSkinNames
as $skinkey => &$skinname ) {
1239 if ( $msg->exists() ) {
1240 $skinname = htmlspecialchars( $msg->text() );
1244 $defaultSkin = $this->config->get(
'DefaultSkin' );
1245 $allowUserCss = $this->config->get(
'AllowUserCss' );
1246 $allowUserJs = $this->config->get(
'AllowUserJs' );
1248 # Sort by the internal name, so that the ordering is the same for each display language,
1249 # especially if some skin names are translated to use a different alphabet and some are not.
1250 uksort( $validSkinNames,
function ( $a, $b )
use ( $defaultSkin ) {
1251 # Display the default first in the list by comparing it as lesser than any other.
1252 if ( strcasecmp( $a, $defaultSkin ) === 0 ) {
1255 if ( strcasecmp( $b, $defaultSkin ) === 0 ) {
1258 return strcasecmp( $a, $b );
1261 $foundDefault =
false;
1262 foreach ( $validSkinNames
as $skinkey => $sn ) {
1265 # Mark the default skin
1266 if ( strcasecmp( $skinkey, $defaultSkin ) === 0 ) {
1267 $linkTools[] =
$context->
msg(
'default' )->escaped();
1268 $foundDefault =
true;
1271 # Create preview link
1272 $mplink = htmlspecialchars( $mptitle->getLocalURL( [
'useskin' => $skinkey ] ) );
1273 $linkTools[] =
"<a target='_blank' href=\"$mplink\">$previewtext</a>";
1275 # Create links to user CSS/JS pages
1276 if ( $allowUserCss ) {
1278 $cssLinkText =
$context->
msg(
'prefs-custom-css' )->text();
1279 $linkTools[] = $this->linkRenderer->makeLink( $cssPage, $cssLinkText );
1282 if ( $allowUserJs ) {
1284 $jsLinkText =
$context->
msg(
'prefs-custom-js' )->text();
1285 $linkTools[] = $this->linkRenderer->makeLink( $jsPage, $jsLinkText );
1288 $display = $sn .
' ' .
$context->
msg(
'parentheses' )
1291 $ret[$display] = $skinkey;
1294 if ( !$foundDefault ) {
1309 $dateopts =
$lang->getDatePreferences();
1314 if ( !in_array(
'default', $dateopts ) ) {
1315 $dateopts[] =
'default';
1325 foreach ( $dateopts
as $key ) {
1326 if ( $key ==
'default' ) {
1327 $formatted =
$context->
msg(
'datedefault' )->escaped();
1329 $formatted = htmlspecialchars(
$lang->timeanddate( $epoch,
false, $key ) );
1331 $ret[$formatted] = $key;
1343 $pixels = $l10n->
msg(
'unit-pixel' )->text();
1345 foreach ( $this->config->get(
'ImageLimits' )
as $index => $limits ) {
1347 $display =
"{$limits[0]}\u{200E}×{$limits[1]}$pixels";
1348 $ret[$display] = $index;
1360 $pixels = $l10n->
msg(
'unit-pixel' )->text();
1362 foreach ( $this->config->get(
'ThumbLimits' )
as $index => $size ) {
1363 $display = $size . $pixels;
1364 $ret[$display] = $index;
1377 $maxSigChars = $this->config->get(
'MaxSigChars' );
1378 if ( mb_strlen( $signature ) > $maxSigChars ) {
1380 $form->
msg(
'badsiglength' )->numParams( $maxSigChars )->text() );
1381 } elseif ( isset( $alldata[
'fancysig'] ) &&
1382 $alldata[
'fancysig'] &&
1387 [
'class' =>
'error' ],
1388 $form->
msg(
'badsig' )->text()
1403 if ( isset( $alldata[
'fancysig'] ) && $alldata[
'fancysig'] ) {
1404 $signature =
$parser->cleanSig( $signature );
1407 $signature = Parser::cleanSigInSig( $signature );
1430 if (
count( $remove ) ) {
1431 $removeKeys = array_flip( $remove );
1437 if ( isset( $info[
'type'] ) && $info[
'type'] ===
'api' ) {
1447 $htmlForm->setModifiedUser(
$user );
1448 $htmlForm->setId(
'mw-prefs-form' );
1449 $htmlForm->setAutocomplete(
'off' );
1450 $htmlForm->setSubmitText(
$context->
msg(
'saveprefs' )->text() );
1451 # Used message keys: 'accesskey-preferences-save', 'tooltip-preferences-save'
1452 $htmlForm->setSubmitTooltip(
'preferences-save' );
1453 $htmlForm->setSubmitID(
'prefcontrol' );
1454 $htmlForm->setSubmitCallback(
1470 $localTZoffset = $this->config->get(
'LocalTZoffset' );
1475 if ( $localTZoffset == $timestamp->format(
'Z' ) / 60 ) {
1476 $timezoneName = $timestamp->getTimezone()->getName();
1478 if ( isset( $timeZoneList[$timezoneName] ) ) {
1479 $timezoneName = $timeZoneList[$timezoneName][
'name'];
1482 'timezoneuseserverdefault',
1486 $tzstring = sprintf(
1488 floor( $localTZoffset / 60 ),
1489 abs( $localTZoffset ) % 60
1491 $server_tz_msg =
$context->
msg(
'timezoneuseserverdefault', $tzstring )->text();
1493 $opt[$server_tz_msg] =
"System|$localTZoffset";
1497 foreach ( $timeZoneList
as $timeZoneInfo ) {
1498 $region = $timeZoneInfo[
'region'];
1499 if ( !isset(
$opt[$region] ) ) {
1502 $opt[$region][$timeZoneInfo[
'name']] = $timeZoneInfo[
'timecorrection'];
1517 $user = $form->getModifiedUser();
1518 $hiddenPrefs = $this->config->get(
'HiddenPrefs' );
1521 if ( !
$user->isAllowedAny(
'editmyprivateinfo',
'editmyoptions' ) ) {
1531 if ( !in_array(
'realname', $hiddenPrefs )
1532 &&
$user->isAllowed(
'editmyprivateinfo' )
1533 && array_key_exists(
'realname', $formData )
1535 $realName = $formData[
'realname'];
1536 $user->setRealName( $realName );
1539 if (
$user->isAllowed(
'editmyoptions' ) ) {
1540 $oldUserOptions =
$user->getOptions();
1543 unset( $formData[$b] );
1546 # If users have saved a value for a preference which has subsequently been disabled
1547 # via $wgHiddenPrefs, we don't want to destroy that setting in case the preference
1548 # is subsequently re-enabled
1549 foreach ( $hiddenPrefs
as $pref ) {
1550 # If the user has not set a non-default value here, the default will be returned
1551 # and subsequently discarded
1552 $formData[$pref] =
$user->getOption( $pref,
null,
true );
1557 isset( $formData[
'rclimit'] ) &&
1558 intval( $formData[
'rclimit' ] ) !==
$user->getIntOption(
'rclimit' )
1560 $formData[
'rcfilters-limit'] = $formData[
'rclimit'];
1566 foreach ( $formData
as $key =>
$value ) {
1571 'PreferencesFormPreSave',
1577 $user->saveSettings();
1592 if ( !isset( $desc[
'filter'] ) || !isset( $preferences[$preference] ) ) {
1595 $filterDesc = $desc[
'filter'];
1596 if ( $filterDesc instanceof
Filter ) {
1597 $filter = $filterDesc;
1598 } elseif ( class_exists( $filterDesc ) ) {
1599 $filter =
new $filterDesc();
1600 } elseif ( is_callable( $filterDesc ) ) {
1601 $filter = $filterDesc();
1603 throw new UnexpectedValueException(
1604 "Unrecognized filter type for preference '$preference'"
1607 $preferences[$preference] = $filter->$verb( $preferences[$preference] );
1622 if (
$res ===
true ) {
1626 if (
$res ===
'eauth' ) {
1627 $urlOptions[
'eauth'] = 1;
1630 $urlOptions += $form->getExtraSuccessRedirectParameters();
1632 $url = $form->
getTitle()->getFullURL( $urlOptions );
1652 $identifiers = DateTimeZone::listIdentifiers();
1653 if ( $identifiers ===
false ) {
1656 sort( $identifiers );
1659 'Africa' =>
wfMessage(
'timezoneregion-africa' )->inLanguage( $language )->text(),
1660 'America' =>
wfMessage(
'timezoneregion-america' )->inLanguage( $language )->text(),
1661 'Antarctica' =>
wfMessage(
'timezoneregion-antarctica' )->inLanguage( $language )->text(),
1662 'Arctic' =>
wfMessage(
'timezoneregion-arctic' )->inLanguage( $language )->text(),
1663 'Asia' =>
wfMessage(
'timezoneregion-asia' )->inLanguage( $language )->text(),
1664 'Atlantic' =>
wfMessage(
'timezoneregion-atlantic' )->inLanguage( $language )->text(),
1665 'Australia' =>
wfMessage(
'timezoneregion-australia' )->inLanguage( $language )->text(),
1666 'Europe' =>
wfMessage(
'timezoneregion-europe' )->inLanguage( $language )->text(),
1667 'Indian' =>
wfMessage(
'timezoneregion-indian' )->inLanguage( $language )->text(),
1668 'Pacific' =>
wfMessage(
'timezoneregion-pacific' )->inLanguage( $language )->text(),
1670 asort( $tzRegions );
1674 $now =
new DateTime();
1676 foreach ( $identifiers
as $identifier ) {
1677 $parts = explode(
'/', $identifier, 2 );
1682 if (
count( $parts ) !== 2 || !array_key_exists( $parts[0], $tzRegions ) ) {
1687 $parts[0] = $tzRegions[$parts[0]];
1689 $dateTimeZone =
new DateTimeZone( $identifier );
1690 $minDiff = floor( $dateTimeZone->getOffset( $now ) / 60 );
1692 $display = str_replace(
'_',
' ', $parts[0] .
'/' . $parts[1] );
1693 $value =
"ZoneInfo|$minDiff|$identifier";
1695 $timeZoneList[$identifier] = [
1697 'timecorrection' =>
$value,
1698 'region' => $parts[0],
1702 return $timeZoneList;