X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FPreferences.php;h=c999a2ef81778367502c533b77710a89dd2dad22;hb=bbb0d379b9abfcd9a2f4573f1afbe2f85eb35155;hp=a2995ab4f5ac771199f918543d0f139f7c50d354;hpb=527e85fa9f090aea00396a120a6d2cc98971e9fe;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Preferences.php b/includes/Preferences.php index a2995ab4f5..c999a2ef81 100644 --- a/includes/Preferences.php +++ b/includes/Preferences.php @@ -131,7 +131,7 @@ class Preferences { * @return void */ static function profilePreferences( $user, &$defaultPreferences ) { - global $wgLang, $wgUser; + global $wgLang; ## User info ##################################### // Information panel $defaultPreferences['username'] = array( @@ -224,7 +224,7 @@ class Preferences { ); if ( $wgAuth->allowPasswordChange() ) { - $link = $wgUser->getSkin()->link( SpecialPage::getTitleFor( 'ChangePassword' ), + $link = Linker::link( SpecialPage::getTitleFor( 'ChangePassword' ), wfMsgHtml( 'prefs-resetpass' ), array(), array( 'returnto' => SpecialPage::getTitleFor( 'Preferences' ) ) ); @@ -314,7 +314,7 @@ class Preferences { // show a preview of the old signature first $oldsigWikiText = $wgParser->preSaveTransform( "~~~", new Title, $user, new ParserOptions ); - $oldsigHTML = $wgOut->parseInline( $oldsigWikiText ); + $oldsigHTML = $wgOut->parseInline( $oldsigWikiText, true, true ); $defaultPreferences['oldsig'] = array( 'type' => 'info', 'raw' => true, @@ -353,13 +353,20 @@ class Preferences { $helpMessages[] = 'prefs-help-email-others'; } + $link = Linker::link( + SpecialPage::getTitleFor( 'ChangeEmail' ), + wfMsgHtml( $user->getEmail() ? 'prefs-changeemail' : 'prefs-setemail' ), + array(), + array( 'returnto' => SpecialPage::getTitleFor( 'Preferences' ) ) ); + $defaultPreferences['emailaddress'] = array( - 'type' => $wgAuth->allowPropChange( 'emailaddress' ) ? 'email' : 'info', - 'default' => $user->getEmail(), - 'section' => 'personal/email', + 'type' => 'info', + 'raw' => true, + 'default' => $user->getEmail() + ? htmlspecialchars( $user->getEmail() ) . " ($link)" + : $link, 'label-message' => 'youremail', - 'help-messages' => $helpMessages, - 'validation-callback' => array( 'Preferences', 'validateEmail' ), + 'section' => 'personal/email', ); global $wgEmailAuthentication; @@ -382,14 +389,10 @@ class Preferences { $disableEmailPrefs = false; } else { $disableEmailPrefs = true; - $skin = $wgUser->getSkin(); $emailauthenticated = wfMsgExt( 'emailnotauthenticated', 'parseinline' ) . '
' . - $skin->link( + Linker::linkKnown( SpecialPage::getTitleFor( 'Confirmemail' ), - wfMsg( 'emailconfirmlink' ), - array(), - array(), - array( 'known', 'noclasses' ) + wfMsg( 'emailconfirmlink' ) ) . '
'; } } else { @@ -482,17 +485,16 @@ class Preferences { # This code is basically copied from generateSkinOptions(). It'd # be nice to somehow merge this back in there to avoid redundancy. if ( $wgAllowUserCss || $wgAllowUserJs ) { - $sk = $user->getSkin(); $linkTools = array(); if ( $wgAllowUserCss ) { $cssPage = Title::makeTitleSafe( NS_USER, $user->getName() . '/common.css' ); - $linkTools[] = $sk->link( $cssPage, wfMsgHtml( 'prefs-custom-css' ) ); + $linkTools[] = Linker::link( $cssPage, wfMsgHtml( 'prefs-custom-css' ) ); } if ( $wgAllowUserJs ) { $jsPage = Title::makeTitleSafe( NS_USER, $user->getName() . '/common.js' ); - $linkTools[] = $sk->link( $jsPage, wfMsgHtml( 'prefs-custom-js' ) ); + $linkTools[] = Linker::link( $jsPage, wfMsgHtml( 'prefs-custom-js' ) ); } $defaultPreferences['commoncssjs'] = array( @@ -745,11 +747,14 @@ class Preferences { 'section' => 'editing/advancedediting', 'label-message' => 'tog-showtoolbar', ); - $defaultPreferences['minordefault'] = array( - 'type' => 'toggle', - 'section' => 'editing/advancedediting', - 'label-message' => 'tog-minordefault', - ); + + if ( $user->isAllowed( 'minoredit' ) ) { + $defaultPreferences['minordefault'] = array( + 'type' => 'toggle', + 'section' => 'editing/advancedediting', + 'label-message' => 'tog-minordefault', + ); + } if ( $wgUseExternalEditor ) { $defaultPreferences['externaleditor'] = array( @@ -783,7 +788,7 @@ class Preferences { * @param $defaultPreferences Array */ static function rcPreferences( $user, &$defaultPreferences ) { - global $wgRCMaxAge, $wgUseRCPatrol, $wgLang; + global $wgRCMaxAge, $wgLang; ## RecentChanges ##################################### $defaultPreferences['rcdays'] = array( @@ -815,7 +820,7 @@ class Preferences { 'section' => 'rc/advancedrc', ); - if ( $wgUseRCPatrol ) { + if ( $user->useRCPatrol() ) { $defaultPreferences['hidepatrolled'] = array( 'type' => 'toggle', 'section' => 'rc/advancedrc', @@ -1055,7 +1060,6 @@ class Preferences { } } asort( $validSkinNames ); - $sk = $user->getSkin(); foreach ( $validSkinNames as $skinkey => $sn ) { $linkTools = array(); @@ -1072,12 +1076,12 @@ class Preferences { # Create links to user CSS/JS pages if ( $wgAllowUserCss ) { $cssPage = Title::makeTitleSafe( NS_USER, $user->getName() . '/' . $skinkey . '.css' ); - $linkTools[] = $sk->link( $cssPage, wfMsgHtml( 'prefs-custom-css' ) ); + $linkTools[] = Linker::link( $cssPage, wfMsgHtml( 'prefs-custom-css' ) ); } if ( $wgAllowUserJs ) { $jsPage = Title::makeTitleSafe( NS_USER, $user->getName() . '/' . $skinkey . '.js' ); - $linkTools[] = $sk->link( $jsPage, wfMsgHtml( 'prefs-custom-js' ) ); + $linkTools[] = Linker::link( $jsPage, wfMsgHtml( 'prefs-custom-js' ) ); } $display = $sn . ' ' . wfMsg( 'parentheses', $wgLang->pipeList( $linkTools ) ); @@ -1211,12 +1215,13 @@ class Preferences { /** * @param $user User + * @param $context RequestContext * @param $formClass string * @return HtmlForm */ - static function getFormObject( $user, $formClass = 'PreferencesForm' ) { + static function getFormObject( $user, RequestContext $context, $formClass = 'PreferencesForm' ) { $formDescriptor = Preferences::getPreferences( $user ); - $htmlForm = new $formClass( $formDescriptor, 'prefs' ); + $htmlForm = new $formClass( $formDescriptor, $context, 'prefs' ); $htmlForm->setId( 'mw-prefs-form' ); $htmlForm->setSubmitText( wfMsg( 'saveprefs' ) ); @@ -1240,7 +1245,7 @@ class Preferences { if ( $wgLocalTZoffset == date( 'Z' ) / 60 ) { $server_tz_msg = wfMsg( 'timezoneuseserverdefault', $wgLocaltimezone ); } else { - $tzstring = sprintf( '%+03d:%02d', floor( $wgLocalTZoffset / 60 ), abs( $wgLocalTZoffset ) % 60 ); + $tzstring = sprintf( '%+03d:%02d', floor( $wgLocalTZoffset / 60 ), abs( $wgLocalTZoffset ) % 60 ); $server_tz_msg = wfMsg( 'timezoneuseserverdefault', $tzstring ); } $opt[$server_tz_msg] = "System|$wgLocalTZoffset"; @@ -1339,7 +1344,7 @@ class Preferences { * @return bool|Status|string */ static function tryFormSubmit( $formData, $entryPoint = 'internal' ) { - global $wgUser, $wgEmailAuthentication, $wgEnableEmail; + global $wgUser; $result = true; @@ -1357,34 +1362,6 @@ class Preferences { 'emailaddress', ); - if ( $wgEnableEmail ) { - $newaddr = $formData['emailaddress']; - $oldaddr = $wgUser->getEmail(); - if ( ( $newaddr != '' ) && ( $newaddr != $oldaddr ) ) { - # the user has supplied a new email address on the login page - # new behaviour: set this new emailaddr from login-page into user database record - $wgUser->setEmail( $newaddr ); - # but flag as "dirty" = unauthenticated - $wgUser->invalidateEmail(); - if ( $wgEmailAuthentication ) { - # Mail a temporary password to the dirty address. - # User can come back through the confirmation URL to re-enable email. - $type = $oldaddr != '' ? 'changed' : 'set'; - $result = $wgUser->sendConfirmationMail( $type ); - if ( !$result->isGood() ) { - return htmlspecialchars( $result->getWikiText( 'mailerror' ) ); - } elseif ( $entryPoint == 'ui' ) { - $result = 'eauth'; - } - } - } else { - $wgUser->setEmail( $newaddr ); - } - if ( $oldaddr != $newaddr ) { - wfRunHooks( 'PrefsEmailAudit', array( $wgUser, $oldaddr, $newaddr ) ); - } - } - // Fortunately, the realname field is MUCH simpler global $wgHiddenPrefs; if ( !in_array( 'realname', $wgHiddenPrefs ) ) { @@ -1444,6 +1421,46 @@ class Preferences { return Status::newGood(); } + /* + * Try to set a user's email address. + * This does *not* try to validate the address. + * @param $user User + * @param $newaddr string New email address + * @return Array (true on success or Status on failure, info string) + */ + public static function trySetUserEmail( User $user, $newaddr ) { + global $wgEnableEmail, $wgEmailAuthentication; + $info = ''; // none + + if ( $wgEnableEmail ) { + $oldaddr = $user->getEmail(); + if ( ( $newaddr != '' ) && ( $newaddr != $oldaddr ) ) { + # The user has supplied a new email address on the login page + # new behaviour: set this new emailaddr from login-page into user database record + $user->setEmail( $newaddr ); + # But flag as "dirty" = unauthenticated + $user->invalidateEmail(); + if ( $wgEmailAuthentication ) { + # Mail a temporary password to the dirty address. + # User can come back through the confirmation URL to re-enable email. + $type = $oldaddr != '' ? 'changed' : 'set'; + $result = $user->sendConfirmationMail( $type ); + if ( !$result->isGood() ) { + return array( $result, 'mailerror' ); + } + $info = 'eauth'; + } + } else { + $user->setEmail( $newaddr ); + } + if ( $oldaddr != $newaddr ) { + wfRunHooks( 'PrefsEmailAudit', array( $user, $oldaddr, $newaddr ) ); + } + } + + return array( true, $info ); + } + /** * @param $user User * @return array @@ -1482,12 +1499,9 @@ class PreferencesForm extends HTMLForm { function getButtons() { $html = parent::getButtons(); - global $wgUser; - - $sk = $wgUser->getSkin(); $t = SpecialPage::getTitleFor( 'Preferences', 'reset' ); - $html .= "\n" . $sk->link( $t, wfMsgHtml( 'restoreprefs' ) ); + $html .= "\n" . Linker::link( $t, wfMsgHtml( 'restoreprefs' ) ); $html = Xml::tags( 'div', array( 'class' => 'mw-prefs-buttons' ), $html ); @@ -1517,4 +1531,10 @@ class PreferencesForm extends HTMLForm { return $data; } + /** + * Get the whole body of the form. + */ + function getBody() { + return $this->displaySection( $this->mFieldTree, '', 'mw-prefsection-' ); + } }