X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2FSpecialPreferences.php;h=a3b5617ae2e036ce5b966a23514f904e77e2fc23;hb=e052c4f566ab01d69c3b47dc8e039b721b673709;hp=35b40a4e54753dd82d02a9a6fe00d94fd6033caf;hpb=e7b1a9e8e3b76daa1e2735864ce9800a98307e88;p=lhc%2Fweb%2Fwiklou.git
diff --git a/includes/SpecialPreferences.php b/includes/SpecialPreferences.php
index 35b40a4e54..a3b5617ae2 100644
--- a/includes/SpecialPreferences.php
+++ b/includes/SpecialPreferences.php
@@ -5,12 +5,6 @@
* @subpackage SpecialPage
*/
-if( !defined( 'MEDIAWIKI' ) )
- die();
-
-/** to get a list of languages in setting user's language preference */
-require_once('languages/Names.php');
-
/**
* Entry point that create the "Preferences" object
*/
@@ -33,14 +27,15 @@ class PreferencesForm {
var $mUserLanguage, $mUserVariant;
var $mSearch, $mRecent, $mHourDiff, $mSearchLines, $mSearchChars, $mAction;
var $mReset, $mPosted, $mToggles, $mSearchNs, $mRealName, $mImageSize;
+ var $mUnderline;
/**
* Constructor
* Load some values
*/
- function PreferencesForm( &$request ) {
+ function PreferencesForm( &$request ) {
global $wgLang, $wgContLang, $wgUser, $wgAllowRealName;
-
+
$this->mQuickbar = $request->getVal( 'wpQuickbar' );
$this->mOldpass = $request->getVal( 'wpOldpass' );
$this->mNewpass = $request->getVal( 'wpNewpass' );
@@ -52,8 +47,8 @@ class PreferencesForm {
$this->mMath = $request->getVal( 'wpMath' );
$this->mDate = $request->getVal( 'wpDate' );
$this->mUserEmail = $request->getVal( 'wpUserEmail' );
- $this->mRealName = ($wgAllowRealName) ? $request->getVal( 'wpRealName' ) : '';
- $this->mEmailFlag = $request->getCheck( 'wpEmailFlag' ) ? 1 : 0;
+ $this->mRealName = $wgAllowRealName ? $request->getVal( 'wpRealName' ) : '';
+ $this->mEmailFlag = $request->getCheck( 'wpEmailFlag' ) ? 0 : 1;
$this->mNick = $request->getVal( 'wpNick' );
$this->mUserLanguage = $request->getVal( 'wpUserLanguage' );
$this->mUserVariant = $request->getVal( 'wpUserVariant' );
@@ -64,10 +59,12 @@ class PreferencesForm {
$this->mSearchChars = $request->getVal( 'wpSearchChars' );
$this->mImageSize = $request->getVal( 'wpImageSize' );
$this->mThumbSize = $request->getInt( 'wpThumbSize' );
-
+ $this->mUnderline = $request->getInt( 'wpOpunderline' );
$this->mAction = $request->getVal( 'action' );
$this->mReset = $request->getCheck( 'wpReset' );
$this->mPosted = $request->wasPosted();
+ $this->mSuccess = $request->getCheck( 'success' );
+
$this->mSaveprefs = $request->getCheck( 'wpSaveprefs' ) &&
$this->mPosted &&
$wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
@@ -80,9 +77,9 @@ class PreferencesForm {
$this->mToggles[$tname] = $request->getCheck( "wpOp$tname" ) ? 1 : 0;
}
}
-
+
$this->mUsedToggles = array();
-
+
# Search namespace options
# Note: namespaces don't necessarily have consecutive keys
$this->mSearchNs = array();
@@ -103,7 +100,7 @@ class PreferencesForm {
function execute() {
global $wgUser, $wgOut;
-
+
if ( $wgUser->isAnon() ) {
$wgOut->errorpage( 'prefsnologin', 'prefsnologintext' );
return;
@@ -114,7 +111,7 @@ class PreferencesForm {
}
if ( $this->mReset ) {
$this->resetPrefs();
- $this->mainPrefsForm( wfMsg( 'prefsreset' ) );
+ $this->mainPrefsForm( 'reset', wfMsg( 'prefsreset' ) );
} else if ( $this->mSaveprefs ) {
$this->savePreferences();
} else {
@@ -122,7 +119,6 @@ class PreferencesForm {
$this->mainPrefsForm( '' );
}
}
-
/**
* @access private
*/
@@ -145,6 +141,16 @@ class PreferencesForm {
}
}
+ /**
+ * @access private
+ */
+ function validateDate( &$val, $min = 0, $max=0x7fffffff ) {
+ if ( ( sprintf('%d', $val) === $val && $val >= $min && $val <= $max ) || $val == 'ISO 8601' )
+ return $val;
+ else
+ return 0;
+ }
+
/**
* Used to validate the user inputed timezone before saving it as
* 'timeciorrection', will return '00:00' if fed bogus data.
@@ -181,35 +187,62 @@ class PreferencesForm {
* @access private
*/
function savePreferences() {
- global $wgUser, $wgLang, $wgOut;
+ global $wgUser, $wgOut, $wgParser;
global $wgEnableUserEmail, $wgEnableEmail;
global $wgEmailAuthentication, $wgMinimalPasswordLength;
+ global $wgAuth;
+
if ( '' != $this->mNewpass ) {
if ( $this->mNewpass != $this->mRetypePass ) {
- $this->mainPrefsForm( wfMsg( 'badretype' ) );
+ $this->mainPrefsForm( 'error', wfMsg( 'badretype' ) );
return;
}
if ( strlen( $this->mNewpass ) < $wgMinimalPasswordLength ) {
- $this->mainPrefsForm( wfMsg( 'passwordtooshort', $wgMinimalPasswordLength ) );
+ $this->mainPrefsForm( 'error', wfMsg( 'passwordtooshort', $wgMinimalPasswordLength ) );
return;
}
if (!$wgUser->checkPassword( $this->mOldpass )) {
- $this->mainPrefsForm( wfMsg( 'wrongpassword' ) );
+ $this->mainPrefsForm( 'error', wfMsg( 'wrongpassword' ) );
+ return;
+ }
+ if (!$wgAuth->setPassword( $wgUser, $this->mNewpass )) {
+ $this->mainPrefsForm( 'error', wfMsg( 'externaldberror' ) );
return;
}
$wgUser->setPassword( $this->mNewpass );
+ $this->mNewpass = $this->mOldpass = $this->mRetypePass = '';
+
}
$wgUser->setRealName( $this->mRealName );
+
+ if( $wgUser->getOption( 'language' ) !== $this->mUserLanguage ) {
+ $needRedirect = true;
+ } else {
+ $needRedirect = false;
+ }
+
+ # Validate the signature and clean it up as needed
+ if( $this->mToggles['fancysig'] ) {
+ if( Parser::validateSig( $this->mNick ) !== false ) {
+ $this->mNick = $wgParser->cleanSig( $this->mNick );
+ } else {
+ $this->mainPrefsForm( 'error', wfMsg( 'badsig' ) );
+ }
+ }
+
$wgUser->setOption( 'language', $this->mUserLanguage );
- $wgUser->setOption( 'variant', $this->mUserVariant );
+ $wgUser->setOption( 'variant', $this->mUserVariant );
$wgUser->setOption( 'nickname', $this->mNick );
$wgUser->setOption( 'quickbar', $this->mQuickbar );
$wgUser->setOption( 'skin', $this->mSkin );
- $wgUser->setOption( 'math', $this->mMath );
- $wgUser->setOption( 'date', $this->mDate );
+ global $wgUseTeX;
+ if( $wgUseTeX ) {
+ $wgUser->setOption( 'math', $this->mMath );
+ }
+ $wgUser->setOption( 'date', $this->validateDate( $this->mDate, 0, 20 ) );
$wgUser->setOption( 'searchlimit', $this->validateIntOrNull( $this->mSearch ) );
$wgUser->setOption( 'contextlines', $this->validateIntOrNull( $this->mSearchLines ) );
$wgUser->setOption( 'contextchars', $this->validateIntOrNull( $this->mSearchChars ) );
@@ -220,12 +253,13 @@ class PreferencesForm {
$wgUser->setOption( 'timecorrection', $this->validateTimeZone( $this->mHourDiff, -12, 14 ) );
$wgUser->setOption( 'imagesize', $this->mImageSize );
$wgUser->setOption( 'thumbsize', $this->mThumbSize );
+ $wgUser->setOption( 'underline', $this->validateInt($this->mUnderline, 0, 2) );
# Set search namespace options
foreach( $this->mSearchNs as $i => $value ) {
$wgUser->setOption( "searchNs{$i}", $value );
}
-
+
if( $wgEnableEmail && $wgEnableUserEmail ) {
$wgUser->setOption( 'disablemail', $this->mEmailFlag );
}
@@ -234,43 +268,52 @@ class PreferencesForm {
foreach ( $this->mToggles as $tname => $tvalue ) {
$wgUser->setOption( $tname, $tvalue );
}
+ if (!$wgAuth->updateExternalDB($wgUser)) {
+ $this->mainPrefsForm( wfMsg( 'externaldberror' ) );
+ return;
+ }
$wgUser->setCookies();
$wgUser->saveSettings();
-
+
+ $error = false;
if( $wgEnableEmail ) {
- $newadr = strtolower( $this->mUserEmail );
- $oldadr = strtolower($wgUser->getEmail());
- if (($newadr <> '') && ($newadr <> $oldadr)) { # the user has supplied a new email address on the login page
- # prepare for authentication and mail a temporary password to newadr
- require_once( 'SpecialUserlogin.php' );
- if ( !$wgUser->isValidEmailAddr( $newadr ) ) {
- $this->mainPrefsForm( wfMsg( 'invalidemailaddress' ) );
- return;
- }
- $wgUser->mEmail = $newadr; # new behaviour: set this new emailaddr from login-page into user database record
- $wgUser->mEmailAuthenticationtimestamp = 0; # but flag as "dirty" = unauthenticated
- $wgUser->saveSettings();
- if ($wgEmailAuthentication) {
- # mail a temporary password to the dirty address
- # on "save options", this user will be logged-out automatically
- $error = LoginForm::mailPasswordInternal( $wgUser, true, $dummy );
- if ($error === '') {
- return LoginForm::mainLoginForm( wfMsg( 'passwordsentforemailauthentication', $wgUser->getName() ) );
- } else {
- return LoginForm::mainLoginForm( wfMsg( 'mailerror', $error ) );
+ $newadr = $this->mUserEmail;
+ $oldadr = $wgUser->getEmail();
+ if( ($newadr != '') && ($newadr != $oldadr) ) {
+ # the user has supplied a new email address on the login page
+ if( $wgUser->isValidEmailAddr( $newadr ) ) {
+ $wgUser->mEmail = $newadr; # new behaviour: set this new emailaddr from login-page into user database record
+ $wgUser->mEmailAuthenticated = null; # but flag as "dirty" = unauthenticated
+ $wgUser->saveSettings();
+ if ($wgEmailAuthentication) {
+ # Mail a temporary password to the dirty address.
+ # User can come back through the confirmation URL to re-enable email.
+ $result = $wgUser->sendConfirmationMail();
+ if( WikiError::isError( $result ) ) {
+ $error = wfMsg( 'mailerror', htmlspecialchars( $result->getMessage() ) );
+ } else {
+ $error = wfMsg( 'eauthentsent', $wgUser->getName() );
+ }
}
- # if user returns, that new email address gets authenticated in checkpassword()
+ } else {
+ $error = wfMsg( 'invalidemailaddress' );
}
} else {
- $wgUser->setEmail( strtolower($this->mUserEmail) );
+ $wgUser->setEmail( $this->mUserEmail );
$wgUser->setCookies();
$wgUser->saveSettings();
}
}
+ if( $needRedirect && $error === false ) {
+ $title =& Title::makeTitle( NS_SPECIAL, "Preferences" );
+ $wgOut->redirect($title->getFullURL('success'));
+ return;
+ }
+
$wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
$po = ParserOptions::newFromUser( $wgUser );
- $this->mainPrefsForm( wfMsg( 'savedprefs' ) );
+ $this->mainPrefsForm( $error === false ? 'success' : 'error', $error);
}
/**
@@ -289,13 +332,12 @@ class PreferencesForm {
global $wgContLanguageCode;
$this->mUserLanguage = $wgContLanguageCode;
}
- $this->mUserVariant = $wgUser->getOption( 'variant');
- if ( 1 == $wgUser->getOption( 'disablemail' ) ) { $this->mEmailFlag = 1; }
- else { $this->mEmailFlag = 0; }
+ $this->mUserVariant = $wgUser->getOption( 'variant');
+ $this->mEmailFlag = $wgUser->getOption( 'disablemail' ) == 1 ? 1 : 0;
$this->mNick = $wgUser->getOption( 'nickname' );
$this->mQuickbar = $wgUser->getOption( 'quickbar' );
- $this->mSkin = $wgUser->getOption( 'skin' );
+ $this->mSkin = Skin::normalizeKey( $wgUser->getOption( 'skin' ) );
$this->mMath = $wgUser->getOption( 'math' );
$this->mDate = $wgUser->getOption( 'date' );
$this->mRows = $wgUser->getOption( 'rows' );
@@ -308,6 +350,7 @@ class PreferencesForm {
$this->mImageSize = $wgUser->getOption( 'imagesize' );
$this->mThumbSize = $wgUser->getOption( 'thumbsize' );
$this->mRecent = $wgUser->getOption( 'rclimit' );
+ $this->mUnderline = $wgUser->getOption( 'underline' );
$togs = $wgLang->getUserToggles();
foreach ( $togs as $tname ) {
@@ -317,7 +360,7 @@ class PreferencesForm {
$namespaces = $wgContLang->getNamespaces();
foreach ( $namespaces as $i => $namespace ) {
- if ( $i >= 0 ) {
+ if ( $i >= NS_MAIN ) {
$this->mSearchNs[$i] = $wgUser->getOption( 'searchNs'.$i );
}
}
@@ -327,76 +370,83 @@ class PreferencesForm {
* @access private
*/
function namespacesCheckboxes() {
- global $wgContLang, $wgUser;
-
+ global $wgContLang;
+
# Determine namespace checkboxes
$namespaces = $wgContLang->getNamespaces();
- $r1 = '';
+ $r1 = null;
foreach ( $namespaces as $i => $name ) {
- # Skip special or anything similar
- if ( $i >= 0 ) {
- $checked = '';
- if ( $this->mSearchNs[$i] ) {
- $checked = ' checked="checked"';
- }
- $name = str_replace( '_', ' ', $namespaces[$i] );
- if ( '' == $name ) {
- $name = wfMsg( 'blanknamespace' );
- }
+ if ($i < 0)
+ continue;
+ $checked = $this->mSearchNs[$i] ? "checked='checked'" : '';
+ $name = str_replace( '_', ' ', $namespaces[$i] );
- if ( 0 != $i ) {
- $r1 .= ' ';
- }
- $r1 .= "\n";
- }
+ if ( empty($name) )
+ $name = wfMsg( 'blanknamespace' );
+
+ $r1 .= "
\n";
}
-
return $r1;
}
- function getToggle( $tname, $trailer = false) {
+ function getToggle( $tname, $trailer = false, $disabled = false ) {
global $wgUser, $wgLang;
-
+
$this->mUsedToggles[$tname] = true;
$ttext = $wgLang->getUserToggle( $tname );
-
- if ( 1 == $wgUser->getOption( $tname ) ) {
- $checked = ' checked="checked"';
- } else {
- $checked = '';
- }
- $trailer =($trailer) ? $trailer : '';
- return "
" . htmlspecialchars( $err ) . "
\n" ); + if ( $this->mSuccess || 'success' == $status ) { + $wgOut->addWikitext( '