- static function profilePreferences( $user, IContextSource $context, &$defaultPreferences ) {
- global $wgContLang, $wgParser;
-
- $authManager = AuthManager::singleton();
- $config = $context->getConfig();
- // retrieving user name for GENDER and misc.
- $userName = $user->getName();
-
- # # User info #####################################
- // Information panel
- $defaultPreferences['username'] = [
- 'type' => 'info',
- 'label-message' => [ 'username', $userName ],
- 'default' => $userName,
- 'section' => 'personal/info',
- ];
-
- $lang = $context->getLanguage();
-
- # Get groups to which the user belongs
- $userEffectiveGroups = $user->getEffectiveGroups();
- $userGroupMemberships = $user->getGroupMemberships();
- $userGroups = $userMembers = $userTempGroups = $userTempMembers = [];
- foreach ( $userEffectiveGroups as $ueg ) {
- if ( $ueg == '*' ) {
- // Skip the default * group, seems useless here
- continue;
- }
-
- if ( isset( $userGroupMemberships[$ueg] ) ) {
- $groupStringOrObject = $userGroupMemberships[$ueg];
- } else {
- $groupStringOrObject = $ueg;
- }
-
- $userG = UserGroupMembership::getLink( $groupStringOrObject, $context, 'html' );
- $userM = UserGroupMembership::getLink( $groupStringOrObject, $context, 'html',
- $userName );
-
- // Store expiring groups separately, so we can place them before non-expiring
- // groups in the list. This is to avoid the ambiguity of something like
- // "administrator, bureaucrat (until X date)" -- users might wonder whether the
- // expiry date applies to both groups, or just the last one
- if ( $groupStringOrObject instanceof UserGroupMembership &&
- $groupStringOrObject->getExpiry()
- ) {
- $userTempGroups[] = $userG;
- $userTempMembers[] = $userM;
- } else {
- $userGroups[] = $userG;
- $userMembers[] = $userM;
- }
- }
- sort( $userGroups );
- sort( $userMembers );
- sort( $userTempGroups );
- sort( $userTempMembers );
- $userGroups = array_merge( $userTempGroups, $userGroups );
- $userMembers = array_merge( $userTempMembers, $userMembers );
-
- $defaultPreferences['usergroups'] = [
- 'type' => 'info',
- 'label' => $context->msg( 'prefs-memberingroups' )->numParams(
- count( $userGroups ) )->params( $userName )->parse(),
- 'default' => $context->msg( 'prefs-memberingroups-type' )
- ->rawParams( $lang->commaList( $userGroups ), $lang->commaList( $userMembers ) )
- ->escaped(),
- 'raw' => true,
- 'section' => 'personal/info',
- ];
-
- $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
-
- $editCount = $linkRenderer->makeLink( SpecialPage::getTitleFor( "Contributions", $userName ),
- $lang->formatNum( $user->getEditCount() ) );
-
- $defaultPreferences['editcount'] = [
- 'type' => 'info',
- 'raw' => true,
- 'label-message' => 'prefs-edits',
- 'default' => $editCount,
- 'section' => 'personal/info',
- ];
-
- if ( $user->getRegistration() ) {
- $displayUser = $context->getUser();
- $userRegistration = $user->getRegistration();
- $defaultPreferences['registrationdate'] = [
- 'type' => 'info',
- 'label-message' => 'prefs-registration',
- 'default' => $context->msg(
- 'prefs-registration-date-time',
- $lang->userTimeAndDate( $userRegistration, $displayUser ),
- $lang->userDate( $userRegistration, $displayUser ),
- $lang->userTime( $userRegistration, $displayUser )
- )->parse(),
- 'section' => 'personal/info',
- ];
- }
-
- $canViewPrivateInfo = $user->isAllowed( 'viewmyprivateinfo' );
- $canEditPrivateInfo = $user->isAllowed( 'editmyprivateinfo' );
-
- // Actually changeable stuff
- $defaultPreferences['realname'] = [
- // (not really "private", but still shouldn't be edited without permission)
- 'type' => $canEditPrivateInfo && $authManager->allowsPropertyChange( 'realname' )
- ? 'text' : 'info',
- 'default' => $user->getRealName(),
- 'section' => 'personal/info',
- 'label-message' => 'yourrealname',
- 'help-message' => 'prefs-help-realname',
- ];
-
- if ( $canEditPrivateInfo && $authManager->allowsAuthenticationDataChange(
- new PasswordAuthenticationRequest(), false )->isGood()
- ) {
- $link = $linkRenderer->makeLink( SpecialPage::getTitleFor( 'ChangePassword' ),
- $context->msg( 'prefs-resetpass' )->text(), [],
- [ 'returnto' => SpecialPage::getTitleFor( 'Preferences' )->getPrefixedText() ] );
-
- $defaultPreferences['password'] = [
- 'type' => 'info',
- 'raw' => true,
- 'default' => $link,
- 'label-message' => 'yourpassword',
- 'section' => 'personal/info',
- ];
- }
- // Only show prefershttps if secure login is turned on
- if ( $config->get( 'SecureLogin' ) && wfCanIPUseHTTPS( $context->getRequest()->getIP() ) ) {
- $defaultPreferences['prefershttps'] = [
- 'type' => 'toggle',
- 'label-message' => 'tog-prefershttps',
- 'help-message' => 'prefs-help-prefershttps',
- 'section' => 'personal/info'
- ];
- }
-
- // Language
- $languages = Language::fetchLanguageNames( null, 'mw' );
- $languageCode = $config->get( 'LanguageCode' );
- if ( !array_key_exists( $languageCode, $languages ) ) {
- $languages[$languageCode] = $languageCode;
- }
- ksort( $languages );
-
- $options = [];
- foreach ( $languages as $code => $name ) {
- $display = LanguageCode::bcp47( $code ) . ' - ' . $name;
- $options[$display] = $code;
- }
- $defaultPreferences['language'] = [
- 'type' => 'select',
- 'section' => 'personal/i18n',
- 'options' => $options,
- 'label-message' => 'yourlanguage',
- ];
-
- $defaultPreferences['gender'] = [
- 'type' => 'radio',
- 'section' => 'personal/i18n',
- 'options' => [
- $context->msg( 'parentheses' )
- ->params( $context->msg( 'gender-unknown' )->plain() )
- ->escaped() => 'unknown',
- $context->msg( 'gender-female' )->escaped() => 'female',
- $context->msg( 'gender-male' )->escaped() => 'male',
- ],
- 'label-message' => 'yourgender',
- 'help-message' => 'prefs-help-gender',
- ];
-
- // see if there are multiple language variants to choose from
- if ( !$config->get( 'DisableLangConversion' ) ) {
- foreach ( LanguageConverter::$languagesWithVariants as $langCode ) {
- if ( $langCode == $wgContLang->getCode() ) {
- $variants = $wgContLang->getVariants();
-
- if ( count( $variants ) <= 1 ) {
- continue;
- }
-
- $variantArray = [];
- foreach ( $variants as $v ) {
- $v = str_replace( '_', '-', strtolower( $v ) );
- $variantArray[$v] = $lang->getVariantname( $v, false );
- }
-
- $options = [];
- foreach ( $variantArray as $code => $name ) {
- $display = LanguageCode::bcp47( $code ) . ' - ' . $name;
- $options[$display] = $code;
- }
-
- $defaultPreferences['variant'] = [
- 'label-message' => 'yourvariant',
- 'type' => 'select',
- 'options' => $options,
- 'section' => 'personal/i18n',
- 'help-message' => 'prefs-help-variant',
- ];
- } else {
- $defaultPreferences["variant-$langCode"] = [
- 'type' => 'api',
- ];
- }
- }
- }
-
- // Stuff from Language::getExtraUserToggles()
- // FIXME is this dead code? $extraUserToggles doesn't seem to be defined for any language
- $toggles = $wgContLang->getExtraUserToggles();
-
- foreach ( $toggles as $toggle ) {
- $defaultPreferences[$toggle] = [
- 'type' => 'toggle',
- 'section' => 'personal/i18n',
- 'label-message' => "tog-$toggle",
- ];
- }
-
- // show a preview of the old signature first
- $oldsigWikiText = $wgParser->preSaveTransform(
- '~~~',
- $context->getTitle(),
- $user,
- ParserOptions::newFromContext( $context )
- );
- $oldsigHTML = $context->getOutput()->parseInline( $oldsigWikiText, true, true );
- $defaultPreferences['oldsig'] = [
- 'type' => 'info',
- 'raw' => true,
- 'label-message' => 'tog-oldsig',
- 'default' => $oldsigHTML,
- 'section' => 'personal/signature',
- ];
- $defaultPreferences['nickname'] = [
- 'type' => $authManager->allowsPropertyChange( 'nickname' ) ? 'text' : 'info',
- 'maxlength' => $config->get( 'MaxSigChars' ),
- 'label-message' => 'yournick',
- 'validation-callback' => [ 'Preferences', 'validateSignature' ],
- 'section' => 'personal/signature',
- 'filter-callback' => [ 'Preferences', 'cleanSignature' ],
- ];
- $defaultPreferences['fancysig'] = [
- 'type' => 'toggle',
- 'label-message' => 'tog-fancysig',
- // show general help about signature at the bottom of the section
- 'help-message' => 'prefs-help-signature',
- 'section' => 'personal/signature'
- ];
-
- # # Email stuff
-
- if ( $config->get( 'EnableEmail' ) ) {
- if ( $canViewPrivateInfo ) {
- $helpMessages[] = $config->get( 'EmailConfirmToEdit' )
- ? 'prefs-help-email-required'
- : 'prefs-help-email';
-
- if ( $config->get( 'EnableUserEmail' ) ) {
- // additional messages when users can send email to each other
- $helpMessages[] = 'prefs-help-email-others';
- }
-
- $emailAddress = $user->getEmail() ? htmlspecialchars( $user->getEmail() ) : '';
- if ( $canEditPrivateInfo && $authManager->allowsPropertyChange( 'emailaddress' ) ) {
- $link = $linkRenderer->makeLink(
- SpecialPage::getTitleFor( 'ChangeEmail' ),
- $context->msg( $user->getEmail() ? 'prefs-changeemail' : 'prefs-setemail' )->text(),
- [],
- [ 'returnto' => SpecialPage::getTitleFor( 'Preferences' )->getPrefixedText() ] );
-
- $emailAddress .= $emailAddress == '' ? $link : (
- $context->msg( 'word-separator' )->escaped()
- . $context->msg( 'parentheses' )->rawParams( $link )->escaped()
- );
- }
-
- $defaultPreferences['emailaddress'] = [
- 'type' => 'info',
- 'raw' => true,
- 'default' => $emailAddress,
- 'label-message' => 'youremail',
- 'section' => 'personal/email',
- 'help-messages' => $helpMessages,
- # 'cssclass' chosen below
- ];
- }
-
- $disableEmailPrefs = false;
-
- if ( $config->get( 'EmailAuthentication' ) ) {
- $emailauthenticationclass = 'mw-email-not-authenticated';
- if ( $user->getEmail() ) {
- if ( $user->getEmailAuthenticationTimestamp() ) {
- // date and time are separate parameters to facilitate localisation.
- // $time is kept for backward compat reasons.
- // 'emailauthenticated' is also used in SpecialConfirmemail.php
- $displayUser = $context->getUser();
- $emailTimestamp = $user->getEmailAuthenticationTimestamp();
- $time = $lang->userTimeAndDate( $emailTimestamp, $displayUser );
- $d = $lang->userDate( $emailTimestamp, $displayUser );
- $t = $lang->userTime( $emailTimestamp, $displayUser );
- $emailauthenticated = $context->msg( 'emailauthenticated',
- $time, $d, $t )->parse() . '<br />';
- $disableEmailPrefs = false;
- $emailauthenticationclass = 'mw-email-authenticated';
- } else {
- $disableEmailPrefs = true;
- $emailauthenticated = $context->msg( 'emailnotauthenticated' )->parse() . '<br />' .
- $linkRenderer->makeKnownLink(
- SpecialPage::getTitleFor( 'Confirmemail' ),
- $context->msg( 'emailconfirmlink' )->text()
- ) . '<br />';
- $emailauthenticationclass = "mw-email-not-authenticated";
- }
- } else {
- $disableEmailPrefs = true;
- $emailauthenticated = $context->msg( 'noemailprefs' )->escaped();
- $emailauthenticationclass = 'mw-email-none';
- }
-
- if ( $canViewPrivateInfo ) {
- $defaultPreferences['emailauthentication'] = [
- 'type' => 'info',
- 'raw' => true,
- 'section' => 'personal/email',
- 'label-message' => 'prefs-emailconfirm-label',
- 'default' => $emailauthenticated,
- # Apply the same CSS class used on the input to the message:
- 'cssclass' => $emailauthenticationclass,
- ];
- }
- }
-
- if ( $config->get( 'EnableUserEmail' ) && $user->isAllowed( 'sendemail' ) ) {
- $defaultPreferences['disablemail'] = [
- 'id' => 'wpAllowEmail',
- 'type' => 'toggle',
- 'invert' => true,
- 'section' => 'personal/email',
- 'label-message' => 'allowemail',
- 'disabled' => $disableEmailPrefs,
- ];
-
- $defaultPreferences['email-allow-new-users'] = [
- 'id' => 'wpAllowEmailFromNewUsers',
- 'type' => 'toggle',
- 'section' => 'personal/email',
- 'label-message' => 'email-allow-new-users-label',
- 'disabled' => $disableEmailPrefs,
- ];
-
- $defaultPreferences['ccmeonemails'] = [
- 'type' => 'toggle',
- 'section' => 'personal/email',
- 'label-message' => 'tog-ccmeonemails',
- 'disabled' => $disableEmailPrefs,
- ];
-
- if ( $config->get( 'EnableUserEmailBlacklist' ) ) {
- $lookup = CentralIdLookup::factory();
- $ids = $user->getOption( 'email-blacklist', [] );
- $names = $ids ? $lookup->namesFromCentralIds( $ids, $user ) : [];
-
- $defaultPreferences['email-blacklist'] = [
- 'type' => 'usersmultiselect',
- 'label-message' => 'email-blacklist-label',
- 'section' => 'personal/email',
- 'default' => implode( "\n", $names ),
- 'disabled' => $disableEmailPrefs,
- ];
- }
- }
-
- if ( $config->get( 'EnotifWatchlist' ) ) {
- $defaultPreferences['enotifwatchlistpages'] = [
- 'type' => 'toggle',
- 'section' => 'personal/email',
- 'label-message' => 'tog-enotifwatchlistpages',
- 'disabled' => $disableEmailPrefs,
- ];
- }
- if ( $config->get( 'EnotifUserTalk' ) ) {
- $defaultPreferences['enotifusertalkpages'] = [
- 'type' => 'toggle',
- 'section' => 'personal/email',
- 'label-message' => 'tog-enotifusertalkpages',
- 'disabled' => $disableEmailPrefs,
- ];
- }
- if ( $config->get( 'EnotifUserTalk' ) || $config->get( 'EnotifWatchlist' ) ) {
- if ( $config->get( 'EnotifMinorEdits' ) ) {
- $defaultPreferences['enotifminoredits'] = [
- 'type' => 'toggle',
- 'section' => 'personal/email',
- 'label-message' => 'tog-enotifminoredits',
- 'disabled' => $disableEmailPrefs,
- ];
- }
-
- if ( $config->get( 'EnotifRevealEditorAddress' ) ) {
- $defaultPreferences['enotifrevealaddr'] = [
- 'type' => 'toggle',
- 'section' => 'personal/email',
- 'label-message' => 'tog-enotifrevealaddr',
- 'disabled' => $disableEmailPrefs,
- ];
- }
- }
- }