use MWException;
use MWNamespace;
use MWTimestamp;
+use OutputPage;
use Parser;
use ParserOptions;
-use PreferencesForm;
+use PreferencesFormLegacy;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\NullLogger;
use Skin;
use SpecialPage;
+use SpecialPreferences;
use Status;
use Title;
use User;
public function getFormDescriptor( User $user, IContextSource $context ) {
$preferences = [];
+ if ( SpecialPreferences::isOouiEnabled( $context ) ) {
+ OutputPage::setupOOUI(
+ strtolower( $context->getSkin()->getSkinName() ),
+ $context->getLanguage()->getDir()
+ );
+ }
+
$canIPUseHTTPS = wfCanIPUseHTTPS( $context->getRequest()->getIP() );
$this->profilePreferences( $user, $context, $preferences, $canIPUseHTTPS );
$this->skinPreferences( $user, $context, $preferences );
protected function profilePreferences(
User $user, IContextSource $context, &$defaultPreferences, $canIPUseHTTPS
) {
+ $oouiEnabled = SpecialPreferences::isOouiEnabled( $context );
+
// retrieving user name for GENDER and misc.
$userName = $user->getName();
if ( $canEditPrivateInfo && $this->authManager->allowsAuthenticationDataChange(
new PasswordAuthenticationRequest(), false )->isGood()
) {
- $link = $this->linkRenderer->makeLink( SpecialPage::getTitleFor( 'ChangePassword' ),
- $context->msg( 'prefs-resetpass' )->text(), [],
- [ 'returnto' => SpecialPage::getTitleFor( 'Preferences' )->getPrefixedText() ] );
+ if ( $oouiEnabled ) {
+ $link = new \OOUI\ButtonWidget( [
+ 'href' => SpecialPage::getTitleFor( 'ChangePassword' )->getLinkURL( [
+ 'returnto' => SpecialPage::getTitleFor( 'Preferences' )->getPrefixedText()
+ ] ),
+ 'label' => $context->msg( 'prefs-resetpass' )->text(),
+ ] );
+ } else {
+ $link = $this->linkRenderer->makeLink( SpecialPage::getTitleFor( 'ChangePassword' ),
+ $context->msg( 'prefs-resetpass' )->text(), [],
+ [ 'returnto' => SpecialPage::getTitleFor( 'Preferences' )->getPrefixedText() ] );
+ }
+
$defaultPreferences['password'] = [
'type' => 'info',
'raw' => true,
- 'default' => $link,
+ 'default' => (string)$link,
'label-message' => 'yourpassword',
'section' => 'personal/info',
];
$languageCode = $this->config->get( 'LanguageCode' );
if ( !array_key_exists( $languageCode, $languages ) ) {
$languages[$languageCode] = $languageCode;
+ // Sort the array again
+ ksort( $languages );
}
- ksort( $languages );
$options = [];
foreach ( $languages as $code => $name ) {
$emailAddress = $user->getEmail() ? htmlspecialchars( $user->getEmail() ) : '';
if ( $canEditPrivateInfo && $this->authManager->allowsPropertyChange( 'emailaddress' ) ) {
- $link = $this->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()
- );
+ if ( $oouiEnabled ) {
+ $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 );
+ } else {
+ $link = $this->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'] = [
$emailauthenticationclass = 'mw-email-authenticated';
} else {
$disableEmailPrefs = true;
- $emailauthenticated = $context->msg( 'emailnotauthenticated' )->parse() . '<br />' .
- $this->linkRenderer->makeKnownLink(
- SpecialPage::getTitleFor( 'Confirmemail' ),
- $context->msg( 'emailconfirmlink' )->text()
- ) . '<br />';
+ if ( $oouiEnabled ) {
+ $emailauthenticated = $context->msg( 'emailnotauthenticated' )->parse() . '<br />' .
+ new \OOUI\ButtonWidget( [
+ 'href' => SpecialPage::getTitleFor( 'Confirmemail' )->getLinkURL(),
+ 'label' => $context->msg( 'emailconfirmlink' )->text(),
+ ] );
+ } else {
+ $emailauthenticated = $context->msg( 'emailnotauthenticated' )->parse() . '<br />' .
+ $this->linkRenderer->makeKnownLink(
+ SpecialPage::getTitleFor( 'Confirmemail' ),
+ $context->msg( 'emailconfirmlink' )->text()
+ ) . '<br />';
+ }
$emailauthenticationclass = "mw-email-not-authenticated";
}
} else {
'default' => $tzSetting,
'size' => 20,
'section' => 'rendering/timeoffset',
+ 'id' => 'wpTimeCorrection',
];
}
protected function watchlistPreferences(
User $user, IContextSource $context, &$defaultPreferences
) {
+ $oouiEnabled = SpecialPreferences::isOouiEnabled( $context );
+
$watchlistdaysMax = ceil( $this->config->get( 'RCMaxAge' ) / ( 3600 * 24 ) );
# # Watchlist #####################################
if ( $user->isAllowed( 'editmywatchlist' ) ) {
- $editWatchlistLinks = [];
+ $editWatchlistLinks = '';
+ $editWatchlistLinksOld = [];
$editWatchlistModes = [
- 'edit' => [ 'EditWatchlist', false ],
- 'raw' => [ 'EditWatchlist', 'raw' ],
- 'clear' => [ 'EditWatchlist', 'clear' ],
+ 'edit' => [ 'subpage' => false, 'flags' => [] ],
+ 'raw' => [ 'subpage' => 'raw', 'flags' => [] ],
+ 'clear' => [ 'subpage' => 'clear', 'flags' => [ 'destructive' ] ],
];
- foreach ( $editWatchlistModes as $editWatchlistMode => $mode ) {
+ foreach ( $editWatchlistModes as $mode => $options ) {
// Messages: prefs-editwatchlist-edit, prefs-editwatchlist-raw, prefs-editwatchlist-clear
- $editWatchlistLinks[] = $this->linkRenderer->makeKnownLink(
- SpecialPage::getTitleFor( $mode[0], $mode[1] ),
- new HtmlArmor( $context->msg( "prefs-editwatchlist-{$editWatchlistMode}" )->parse() )
- );
+ if ( $oouiEnabled ) {
+ $editWatchlistLinks .=
+ new \OOUI\ButtonWidget( [
+ 'href' => SpecialPage::getTitleFor( 'EditWatchlist', $options['subpage'] )->getLinkURL(),
+ 'flags' => $options[ 'flags' ],
+ 'label' => new \OOUI\HtmlSnippet(
+ $context->msg( "prefs-editwatchlist-{$mode}" )->parse()
+ ),
+ ] );
+ } else {
+ $editWatchlistLinksOld[] = $this->linkRenderer->makeKnownLink(
+ SpecialPage::getTitleFor( 'EditWatchlist', $options['subpage'] ),
+ new HtmlArmor( $context->msg( "prefs-editwatchlist-{$mode}" )->parse() )
+ );
+ }
}
$defaultPreferences['editwatchlist'] = [
'type' => 'info',
'raw' => true,
- 'default' => $context->getLanguage()->pipeList( $editWatchlistLinks ),
+ 'default' => $oouiEnabled ?
+ $editWatchlistLinks :
+ $context->getLanguage()->pipeList( $editWatchlistLinksOld ),
'label-message' => 'prefs-editwatchlist-label',
'section' => 'watchlist/editwatchlist',
];
$defaultPreferences['watchlisttoken'] = [
'type' => 'api',
];
- $defaultPreferences['watchlisttoken-info'] = [
- 'type' => 'info',
- 'section' => 'watchlist/tokenwatchlist',
- 'label-message' => 'prefs-watchlist-token',
- 'default' => $user->getTokenFromOption( 'watchlisttoken' ),
- 'help-message' => 'prefs-help-watchlist-token2',
- ];
+
+ if ( $oouiEnabled ) {
+ $tokenButton = new \OOUI\ButtonWidget( [
+ 'href' => SpecialPage::getTitleFor( 'ResetTokens' )->getLinkURL( [
+ 'returnto' => SpecialPage::getTitleFor( 'Preferences' )->getPrefixedText()
+ ] ),
+ 'label' => $context->msg( 'prefs-watchlist-managetokens' )->text(),
+ ] );
+ $defaultPreferences['watchlisttoken-info'] = [
+ 'type' => 'info',
+ 'section' => 'watchlist/tokenwatchlist',
+ 'label-message' => 'prefs-watchlist-token',
+ 'help-message' => 'prefs-help-tokenmanagement',
+ 'raw' => true,
+ 'default' => (string)$tokenButton,
+ ];
+ } else {
+ $defaultPreferences['watchlisttoken-info'] = [
+ 'type' => 'info',
+ 'section' => 'watchlist/tokenwatchlist',
+ 'label-message' => 'prefs-watchlist-token',
+ 'default' => $user->getTokenFromOption( 'watchlisttoken' ),
+ 'help-message' => 'prefs-help-watchlist-token2',
+ ];
+ }
}
/**
* @param IContextSource $context
* @param string $formClass
* @param array $remove Array of items to remove
- * @return PreferencesForm|HTMLForm
+ * @return HTMLForm
*/
public function getForm(
User $user,
IContextSource $context,
- $formClass = PreferencesForm::class,
+ $formClass = PreferencesFormLegacy::class,
array $remove = []
) {
+ if ( SpecialPreferences::isOouiEnabled( $context ) ) {
+ // We use ButtonWidgets in some of the getPreferences() functions
+ $context->getOutput()->enableOOUI();
+ }
+
$formDescriptor = $this->getFormDescriptor( $user, $context );
if ( count( $remove ) ) {
$removeKeys = array_flip( $remove );
}
/**
- * @var $htmlForm PreferencesForm
+ * @var $htmlForm HTMLForm
*/
$htmlForm = new $formClass( $formDescriptor, $context, 'prefs' );
# Used message keys: 'accesskey-preferences-save', 'tooltip-preferences-save'
$htmlForm->setSubmitTooltip( 'preferences-save' );
$htmlForm->setSubmitID( 'prefcontrol' );
- $htmlForm->setSubmitCallback( function ( array $formData, PreferencesForm $form ) {
+ $htmlForm->setSubmitCallback( function ( array $formData, HTMLForm $form ) {
return $this->submitForm( $formData, $form );
} );
* Handle the form submission if everything validated properly
*
* @param array $formData
- * @param PreferencesForm $form
+ * @param HTMLForm $form
* @return bool|Status|string
*/
- protected function saveFormData( $formData, PreferencesForm $form ) {
+ protected function saveFormData( $formData, HTMLForm $form ) {
$user = $form->getModifiedUser();
$hiddenPrefs = $this->config->get( 'HiddenPrefs' );
$result = true;
* @deprecated since 1.31, its inception
*
* @param array $formData
- * @param PreferencesForm $form
+ * @param HTMLForm $form
* @return bool|Status|string
*/
- public function legacySaveFormData( $formData, PreferencesForm $form ) {
+ public function legacySaveFormData( $formData, HTMLForm $form ) {
return $this->saveFormData( $formData, $form );
}
* Save the form data and reload the page
*
* @param array $formData
- * @param PreferencesForm $form
+ * @param HTMLForm $form
* @return Status
*/
- protected function submitForm( array $formData, PreferencesForm $form ) {
+ protected function submitForm( array $formData, HTMLForm $form ) {
$res = $this->saveFormData( $formData, $form );
- if ( $res ) {
+ if ( $res === true ) {
+ $context = $form->getContext();
$urlOptions = [];
if ( $res === 'eauth' ) {
$urlOptions['eauth'] = 1;
}
+ if (
+ $context->getRequest()->getFuzzyBool( 'ooui' ) !==
+ $context->getConfig()->get( 'OOUIPreferences' )
+ ) {
+ $urlOptions[ 'ooui' ] = $context->getRequest()->getFuzzyBool( 'ooui' ) ? 1 : 0;
+ }
+
$urlOptions += $form->getExtraSuccessRedirectParameters();
$url = $form->getTitle()->getFullURL( $urlOptions );
- $context = $form->getContext();
// Set session data for the success message
$context->getRequest()->getSession()->set( 'specialPreferencesSaveSuccess', 1 );
$context->getOutput()->redirect( $url );
}
- return Status::newGood();
+ return ( $res === true ? Status::newGood() : $res );
}
/**
* @deprecated since 1.31, its inception
*
* @param array $formData
- * @param PreferencesForm $form
+ * @param HTMLForm $form
* @return Status
*/
- public function legacySubmitForm( array $formData, PreferencesForm $form ) {
+ public function legacySubmitForm( array $formData, HTMLForm $form ) {
return $this->submitForm( $formData, $form );
}