X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FPreferences.php;h=3fe6a8cc0ec08043fece7e4752c97025f95d5ace;hb=e0e8f92227f6a62a836d167378116680ac6ae9d1;hp=bfdc538ff4fd57e0b037eb7636bbb15c7d1df60f;hpb=bd548f36e959edfc89cf04d6136dd058a849b7b2;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Preferences.php b/includes/Preferences.php index bfdc538ff4..3fe6a8cc0e 100644 --- a/includes/Preferences.php +++ b/includes/Preferences.php @@ -171,7 +171,7 @@ class Preferences { asort( $userGroups ); asort( $userMembers ); - $lang = $context->getLang(); + $lang = $context->getLanguage(); $defaultPreferences['usergroups'] = array( 'type' => 'info', @@ -193,14 +193,16 @@ class Preferences { ); if ( $user->getRegistration() ) { + $displayUser = $context->getUser(); + $userRegistration = $user->getRegistration(); $defaultPreferences['registrationdate'] = array( 'type' => 'info', 'label-message' => 'prefs-registration', 'default' => $context->msg( 'prefs-registration-date-time', - $lang->timeanddate( $user->getRegistration(), true ), - $lang->date( $user->getRegistration(), true ), - $lang->time( $user->getRegistration(), true ) + $lang->userTimeAndDate( $userRegistration, $displayUser ), + $lang->userDate( $userRegistration, $displayUser ), + $lang->userTime( $userRegistration, $displayUser ) )->parse(), 'section' => 'personal/info', ); @@ -368,9 +370,11 @@ class Preferences { // date and time are separate parameters to facilitate localisation. // $time is kept for backward compat reasons. // 'emailauthenticated' is also used in SpecialConfirmemail.php - $time = $lang->timeAndDate( $user->getEmailAuthenticationTimestamp(), true ); - $d = $lang->date( $user->getEmailAuthenticationTimestamp(), true ); - $t = $lang->time( $user->getEmailAuthenticationTimestamp(), true ); + $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() . '
'; $disableEmailPrefs = false; @@ -485,7 +489,7 @@ class Preferences { $defaultPreferences['commoncssjs'] = array( 'type' => 'info', 'raw' => true, - 'default' => $context->getLang()->pipeList( $linkTools ), + 'default' => $context->getLanguage()->pipeList( $linkTools ), 'label-message' => 'prefs-common-css-js', 'section' => 'rendering/skin', ); @@ -493,7 +497,7 @@ class Preferences { $selectedSkin = $user->getOption( 'skin' ); if ( in_array( $selectedSkin, array( 'cologneblue', 'standard' ) ) ) { - $settings = array_flip( $context->getLang()->getQuickbarSettings() ); + $settings = array_flip( $context->getLanguage()->getQuickbarSettings() ); $defaultPreferences['quickbar'] = array( 'type' => 'radio', @@ -545,7 +549,7 @@ class Preferences { // Info $now = wfTimestampNow(); - $lang = $context->getLang(); + $lang = $context->getLanguage(); $nowlocal = Xml::element( 'span', array( 'id' => 'wpLocalTime' ), $lang->time( $now, true ) ); $nowserver = $lang->time( $now, false ) . @@ -845,15 +849,18 @@ class Preferences { * @param $defaultPreferences */ static function watchlistPreferences( $user, IContextSource $context, &$defaultPreferences ) { - global $wgUseRCPatrol, $wgEnableAPI; + global $wgUseRCPatrol, $wgEnableAPI, $wgRCMaxAge; + $watchlistdaysMax = ceil( $wgRCMaxAge / ( 3600 * 24 ) ); + ## Watchlist ##################################### $defaultPreferences['watchlistdays'] = array( 'type' => 'float', 'min' => 0, - 'max' => 7, + 'max' => $watchlistdaysMax, 'section' => 'watchlist/displaywatchlist', - 'help' => $context->msg( 'prefs-watchlist-days-max' )->escaped(), + 'help' => $context->msg( 'prefs-watchlist-days-max' )->numParams( + $watchlistdaysMax )->text(), 'label-message' => 'prefs-watchlist-days', ); $defaultPreferences['wllimit'] = array( @@ -1082,7 +1089,7 @@ class Preferences { $linkTools[] = Linker::link( $jsPage, $context->msg( 'prefs-custom-js' )->escaped() ); } - $display = $sn . ' ' . $context->msg( 'parentheses', $context->getLang()->pipeList( $linkTools ) )->text(); + $display = $sn . ' ' . $context->msg( 'parentheses', $context->getLanguage()->pipeList( $linkTools ) )->text(); $ret[$display] = $skinkey; } @@ -1094,7 +1101,8 @@ class Preferences { * @return array */ static function getDateOptions( IContextSource $context ) { - $dateopts = $context->getLang()->getDatePreferences(); + $lang = $context->getLanguage(); + $dateopts = $lang->getDatePreferences(); $ret = array(); @@ -1115,7 +1123,7 @@ class Preferences { if ( $key == 'default' ) { $formatted = $context->msg( 'datedefault' )->escaped(); } else { - $formatted = htmlspecialchars( $context->getLang()->timeanddate( $epoch, false, $key ) ); + $formatted = htmlspecialchars( $lang->timeanddate( $epoch, false, $key ) ); } $ret[$formatted] = $key; } @@ -1160,19 +1168,20 @@ class Preferences { } /** - * @param $signature - * @param $alldata + * @param $signature string + * @param $alldata array + * @param $form HTMLForm * @return bool|string */ - static function validateSignature( $signature, $alldata ) { + static function validateSignature( $signature, $alldata, $form ) { global $wgParser, $wgMaxSigChars; if ( mb_strlen( $signature ) > $wgMaxSigChars ) { return Xml::element( 'span', array( 'class' => 'error' ), - wfMessage( 'badsiglength' )->numParams( $wgMaxSigChars )->text() ); + $form->msg( 'badsiglength' )->numParams( $wgMaxSigChars )->text() ); } elseif ( isset( $alldata['fancysig'] ) && $alldata['fancysig'] && false === $wgParser->validateSig( $signature ) ) { - return Xml::element( 'span', array( 'class' => 'error' ), wfMsg( 'badsig' ) ); + return Xml::element( 'span', array( 'class' => 'error' ), $form->msg( 'badsig' )->text() ); } else { return true; } @@ -1181,37 +1190,21 @@ class Preferences { /** * @param $signature string * @param $alldata array + * @param $form HTMLForm * @return string */ - static function cleanSignature( $signature, $alldata ) { - global $wgParser; + static function cleanSignature( $signature, $alldata, $form ) { if ( isset( $alldata['fancysig'] ) && $alldata['fancysig'] ) { + global $wgParser; $signature = $wgParser->cleanSig( $signature ); } else { // When no fancy sig used, make sure ~{3,5} get removed. - $signature = $wgParser->cleanSigInSig( $signature ); + $signature = Parser::cleanSigInSig( $signature ); } return $signature; } - /** - * @param $email - * @param $alldata - * @return bool|String - */ - static function validateEmail( $email, $alldata ) { - if ( $email && !Sanitizer::validateEmail( $email ) ) { - return wfMsgExt( 'invalidemailaddress', 'parseinline' ); - } - - global $wgEmailConfirmToEdit; - if ( $wgEmailConfirmToEdit && !$email ) { - return wfMsgExt( 'noemailtitle', 'parseinline' ); - } - return true; - } - /** * @param $user User * @param $context IContextSource @@ -1225,11 +1218,15 @@ class Preferences { $removeKeys = array_flip( $remove ); $formDescriptor = array_diff_key( $formDescriptor, $removeKeys ); } + + /** + * @var $htmlForm PreferencesForm + */ $htmlForm = new $formClass( $formDescriptor, $context, 'prefs' ); $htmlForm->setModifiedUser( $user ); $htmlForm->setId( 'mw-prefs-form' ); - $htmlForm->setSubmitText( wfMsg( 'saveprefs' ) ); + $htmlForm->setSubmitText( $context->msg( 'saveprefs' )->text() ); # Used message keys: 'accesskey-preferences-save', 'tooltip-preferences-save' $htmlForm->setSubmitTooltip( 'preferences-save' ); $htmlForm->setSubmitID( 'prefsubmit' ); @@ -1344,7 +1341,7 @@ class Preferences { /** * @param $formData - * @param $form HTMLForm + * @param $form PreferencesForm * @param $entryPoint string * @return bool|Status|string */ @@ -1403,6 +1400,7 @@ class Preferences { /** * @param $formData + * @param $form PreferencesForm * @return Status */ public static function tryUISubmit( $formData, $form ) { @@ -1425,7 +1423,7 @@ class Preferences { return Status::newGood(); } - /* + /** * Try to set a user's email address. * This does *not* try to validate the address. * Caller is responsible for checking $wgAuth. @@ -1443,8 +1441,6 @@ class Preferences { # 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. @@ -1455,7 +1451,7 @@ class Preferences { } $info = 'eauth'; } - } else { + } elseif ( $newaddr != $oldaddr ) { // if the address is the same, don't change it $user->setEmail( $newaddr ); } if ( $oldaddr != $newaddr ) { @@ -1467,10 +1463,13 @@ class Preferences { } /** + * @deprecated in 1.19; will be removed in 1.20. * @param $user User * @return array */ public static function loadOldSearchNs( $user ) { + wfDeprecated( __METHOD__, '1.19' ); + $searchableNamespaces = SearchEngine::searchableNamespaces(); // Back compat with old format $arr = array(); @@ -1487,12 +1486,21 @@ class Preferences { /** 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(); @@ -1529,7 +1537,7 @@ class PreferencesForm extends HTMLForm { $t = SpecialPage::getTitleFor( 'Preferences', 'reset' ); - $html .= "\n" . Linker::link( $t, wfMsgHtml( 'restoreprefs' ) ); + $html .= "\n" . Linker::link( $t, $this->msg( 'restoreprefs' )->escaped() ); $html = Xml::tags( 'div', array( 'class' => 'mw-prefs-buttons' ), $html ); @@ -1559,10 +1567,24 @@ class PreferencesForm extends HTMLForm { return $data; } + /** * Get the whole body of the form. + * @return string */ function getBody() { return $this->displaySection( $this->mFieldTree, '', 'mw-prefsection-' ); } + + /** + * Get the for a given section key. Normally this is the + * prefs-$key message but we'll allow extensions to override it. + * @param $key string + * @return string + */ + function getLegend( $key ) { + $legend = parent::getLegend( $key ); + wfRunHooks( 'PreferencesGetLegend', array( $this, $key, &$legend ) ); + return $legend; + } }