<?php
/**
- * Form to edit user preferences.
- *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* over to the tryUISubmit static method of this class.
*/
class Preferences {
- /** @var array */
- protected static $defaultPreferences = null;
-
/** @var array */
protected static $saveFilters = [
'timecorrection' => [ 'Preferences', 'filterTimezoneInput' ],
* @return array|null
*/
static function getPreferences( $user, IContextSource $context ) {
- if ( self::$defaultPreferences ) {
- return self::$defaultPreferences;
- }
+ OutputPage::setupOOUI(
+ strtolower( $context->getSkin()->getSkinName() ),
+ $context->getLanguage()->getDir()
+ );
$defaultPreferences = [];
Hooks::run( 'GetPreferences', [ $user, &$defaultPreferences ] );
self::loadPreferenceValues( $user, $context, $defaultPreferences );
- self::$defaultPreferences = $defaultPreferences;
return $defaultPreferences;
}
if ( $canEditPrivateInfo && $authManager->allowsAuthenticationDataChange(
new PasswordAuthenticationRequest(), false )->isGood()
) {
- $link = $linkRenderer->makeLink( SpecialPage::getTitleFor( 'ChangePassword' ),
- $context->msg( 'prefs-resetpass' )->text(), [],
- [ 'returnto' => SpecialPage::getTitleFor( 'Preferences' )->getPrefixedText() ] );
+ $link = new OOUI\ButtonWidget( [
+ 'href' => SpecialPage::getTitleFor( 'ChangePassword' )->getLinkURL( [
+ 'returnto' => SpecialPage::getTitleFor( 'Preferences' )->getPrefixedText()
+ ] ),
+ 'label' => $context->msg( 'prefs-resetpass' )->text(),
+ ] );
$defaultPreferences['password'] = [
'type' => 'info',
'raw' => true,
- 'default' => $link,
+ 'default' => (string)$link,
'label-message' => 'yourpassword',
'section' => 'personal/info',
];
$options = [];
foreach ( $languages as $code => $name ) {
- $display = wfBCP47( $code ) . ' - ' . $name;
+ $display = LanguageCode::bcp47( $code ) . ' - ' . $name;
$options[$display] = $code;
}
$defaultPreferences['language'] = [
$options = [];
foreach ( $variantArray as $code => $name ) {
- $display = wfBCP47( $code ) . ' - ' . $name;
+ $display = LanguageCode::bcp47( $code ) . ' - ' . $name;
$options[$display] = $code;
}
$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()
- );
+ $link = new OOUI\ButtonWidget( [
+ 'href' => SpecialPage::getTitleFor( 'ChangeEmail' )->getLinkURL( [
+ 'returnto' => SpecialPage::getTitleFor( 'Preferences' )->getPrefixedText()
+ ] ),
+ 'label' =>
+ $context->msg( $user->getEmail() ? 'prefs-changeemail' : 'prefs-setemail' )->text(),
+ ] );
+
+ $emailAddress .= $emailAddress == '' ? $link : ( '<br />' . $link );
}
$defaultPreferences['emailaddress'] = [
} else {
$disableEmailPrefs = true;
$emailauthenticated = $context->msg( 'emailnotauthenticated' )->parse() . '<br />' .
- $linkRenderer->makeKnownLink(
- SpecialPage::getTitleFor( 'Confirmemail' ),
- $context->msg( 'emailconfirmlink' )->text()
- ) . '<br />';
+ new OOUI\ButtonWidget( [
+ 'href' => SpecialPage::getTitleFor( 'Confirmemail' )->getLinkURL(),
+ 'label' => $context->msg( 'emailconfirmlink' )->text(),
+ ] );
$emailauthenticationclass = "mw-email-not-authenticated";
}
} else {
'label-message' => 'tog-ccmeonemails',
'disabled' => $disableEmailPrefs,
];
+
+ if ( $config->get( 'EnableUserEmailBlacklist' )
+ && !$disableEmailPrefs
+ && !(bool)$user->getOption( 'disablemail' )
+ ) {
+ $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 ),
+ ];
+ }
}
if ( $config->get( 'EnotifWatchlist' ) ) {
$defaultPreferences['skin'] = [
'type' => 'radio',
'options' => $skinOptions,
- 'label' => ' ',
'section' => 'rendering/skin',
];
}
$defaultPreferences['date'] = [
'type' => 'radio',
'options' => $dateOptions,
- 'label' => ' ',
'section' => 'rendering/dateformat',
];
}
'default' => $tzSetting,
'size' => 20,
'section' => 'rendering/timeoffset',
+ 'id' => 'wpTimeCorrection',
];
}
$context->msg( 'editfont-monospace' )->text() => 'monospace',
$context->msg( 'editfont-sansserif' )->text() => 'sans-serif',
$context->msg( 'editfont-serif' )->text() => 'serif',
- $context->msg( 'editfont-default' )->text() => 'default',
]
];
}
$defaultPreferences['rcfilters-wl-saved-queries'] = [
'type' => 'api',
];
+ $defaultPreferences['rcfilters-saved-queries-versionbackup'] = [
+ 'type' => 'api',
+ ];
+ $defaultPreferences['rcfilters-wl-saved-queries-versionbackup'] = [
+ 'type' => 'api',
+ ];
$defaultPreferences['rcfilters-rclimit'] = [
'type' => 'api',
];
'label-message' => 'tog-shownumberswatching',
];
}
+
+ if ( $config->get( 'StructuredChangeFiltersShowPreference' ) ) {
+ $defaultPreferences['rcenhancedfilters-disable'] = [
+ 'type' => 'toggle',
+ 'section' => 'rc/opt-out',
+ 'label-message' => 'rcfilters-preference-label',
+ 'help-message' => 'rcfilters-preference-help',
+ ];
+ }
}
/**
# # Watchlist #####################################
if ( $user->isAllowed( 'editmywatchlist' ) ) {
- $editWatchlistLinks = [];
+ $editWatchlistLinks = '';
$editWatchlistModes = [
'edit' => [ 'EditWatchlist', false ],
'raw' => [ 'EditWatchlist', 'raw' ],
$linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
foreach ( $editWatchlistModes as $editWatchlistMode => $mode ) {
// Messages: prefs-editwatchlist-edit, prefs-editwatchlist-raw, prefs-editwatchlist-clear
- $editWatchlistLinks[] = $linkRenderer->makeKnownLink(
- SpecialPage::getTitleFor( $mode[0], $mode[1] ),
- new HtmlArmor( $context->msg( "prefs-editwatchlist-{$editWatchlistMode}" )->parse() )
- );
+ $editWatchlistLinks .=
+ new OOUI\ButtonWidget( [
+ 'href' => SpecialPage::getTitleFor( $mode[0], $mode[1] )->getLinkURL(),
+ 'label' => new OOUI\HtmlSnippet(
+ $context->msg( "prefs-editwatchlist-{$editWatchlistMode}" )->parse()
+ ),
+ ] );
}
$defaultPreferences['editwatchlist'] = [
'type' => 'info',
'raw' => true,
- 'default' => $context->getLanguage()->pipeList( $editWatchlistLinks ),
+ 'default' => $editWatchlistLinks,
'label-message' => 'prefs-editwatchlist-label',
'section' => 'watchlist/editwatchlist',
];
'default' => $user->getTokenFromOption( 'watchlisttoken' ),
'help-message' => 'prefs-help-watchlist-token2',
];
+ $defaultPreferences['watchlisttoken-info2'] = [
+ 'type' => 'info',
+ 'section' => 'watchlist/tokenwatchlist',
+ 'raw' => true,
+ 'default' => $context->msg( 'prefs-help-watchlist-token2' )->parse(),
+ ];
}
}
* @param IContextSource $context
* @param string $formClass
* @param array $remove Array of items to remove
- * @return PreferencesForm|HtmlForm
+ * @return PreferencesForm|HTMLForm
*/
static function getFormObject(
$user,
$formClass = 'PreferencesForm',
array $remove = []
) {
+ // We use ButtonWidgets in some of the getPreferences() functions
+ $context->getOutput()->enableOOUI();
+
$formDescriptor = self::getPreferences( $user, $context );
if ( count( $remove ) ) {
$removeKeys = array_flip( $remove );
$htmlForm->setSubmitText( $context->msg( 'saveprefs' )->text() );
# Used message keys: 'accesskey-preferences-save', 'tooltip-preferences-save'
$htmlForm->setSubmitTooltip( 'preferences-save' );
- $htmlForm->setSubmitID( 'prefsubmit' );
+ $htmlForm->setSubmitID( 'prefcontrol' );
$htmlForm->setSubmitCallback( [ 'Preferences', 'tryFormSubmit' ] );
return $htmlForm;
return $timeZoneList;
}
}
-
-/** Some tweaks to allow js prefs to work */
-class PreferencesForm extends HTMLForm {
- // Override default value from HTMLForm
- protected $mSubSectionBeforeFields = false;
-
- private $modifiedUser;
-
- /**
- * @param User $user
- */
- public function setModifiedUser( $user ) {
- $this->modifiedUser = $user;
- }
-
- /**
- * @return User
- */
- public function getModifiedUser() {
- if ( $this->modifiedUser === null ) {
- return $this->getUser();
- } else {
- return $this->modifiedUser;
- }
- }
-
- /**
- * Get extra parameters for the query string when redirecting after
- * successful save.
- *
- * @return array
- */
- public function getExtraSuccessRedirectParameters() {
- return [];
- }
-
- /**
- * @param string $html
- * @return string
- */
- function wrapForm( $html ) {
- $html = Xml::tags( 'div', [ 'id' => 'preferences' ], $html );
-
- return parent::wrapForm( $html );
- }
-
- /**
- * @return string
- */
- function getButtons() {
- $attrs = [ 'id' => 'mw-prefs-restoreprefs' ];
-
- if ( !$this->getModifiedUser()->isAllowedAny( 'editmyprivateinfo', 'editmyoptions' ) ) {
- return '';
- }
-
- $html = parent::getButtons();
-
- if ( $this->getModifiedUser()->isAllowed( 'editmyoptions' ) ) {
- $t = $this->getTitle()->getSubpage( 'reset' );
-
- $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
- $html .= "\n" . $linkRenderer->makeLink( $t, $this->msg( 'restoreprefs' )->text(),
- Html::buttonAttributes( $attrs, [ 'mw-ui-quiet' ] ) );
-
- $html = Xml::tags( 'div', [ 'class' => 'mw-prefs-buttons' ], $html );
- }
-
- return $html;
- }
-
- /**
- * Separate multi-option preferences into multiple preferences, since we
- * have to store them separately
- * @param array $data
- * @return array
- */
- function filterDataForSubmit( $data ) {
- foreach ( $this->mFlatFields as $fieldname => $field ) {
- if ( $field instanceof HTMLNestedFilterable ) {
- $info = $field->mParams;
- $prefix = isset( $info['prefix'] ) ? $info['prefix'] : $fieldname;
- foreach ( $field->filterDataForSubmit( $data[$fieldname] ) as $key => $value ) {
- $data["$prefix$key"] = $value;
- }
- unset( $data[$fieldname] );
- }
- }
-
- return $data;
- }
-
- /**
- * Get the whole body of the form.
- * @return string
- */
- function getBody() {
- return $this->displaySection( $this->mFieldTree, '', 'mw-prefsection-' );
- }
-
- /**
- * Get the "<legend>" for a given section key. Normally this is the
- * prefs-$key message but we'll allow extensions to override it.
- * @param string $key
- * @return string
- */
- function getLegend( $key ) {
- $legend = parent::getLegend( $key );
- Hooks::run( 'PreferencesGetLegend', [ $this, $key, &$legend ] );
- return $legend;
- }
-
- /**
- * Get the keys of each top level preference section.
- * @return array of section keys
- */
- function getPreferenceSections() {
- return array_keys( array_filter( $this->mFieldTree, 'is_array' ) );
- }
-}