* 'Listusers/'.'sysop' => 'Listusers/sysop'
[lhc/web/wiklou.git] / includes / SpecialPreferences.php
index 72b1692..4616fcc 100644 (file)
@@ -8,9 +8,6 @@
 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,6 +30,7 @@ class PreferencesForm {
        var $mUserLanguage, $mUserVariant;
        var $mSearch, $mRecent, $mHourDiff, $mSearchLines, $mSearchChars, $mAction;
        var $mReset, $mPosted, $mToggles, $mSearchNs, $mRealName, $mImageSize;
+       var $mUnderline;
 
        /**
         * Constructor
@@ -64,9 +62,11 @@ 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->mSaveprefs = $request->getCheck( 'wpSaveprefs' ) &&
                        $this->mPosted &&
                        $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
@@ -183,6 +183,8 @@ class PreferencesForm {
                global $wgUser, $wgLang, $wgOut;
                global $wgEnableUserEmail, $wgEnableEmail;
                global $wgEmailAuthentication, $wgMinimalPasswordLength;
+               global $wgAuth;
+
 
                if ( '' != $this->mNewpass ) {
                        if ( $this->mNewpass != $this->mRetypePass ) {
@@ -199,6 +201,10 @@ class PreferencesForm {
                                $this->mainPrefsForm( wfMsg( 'wrongpassword' ) );
                                return;
                        }
+                       if (!$wgAuth->setPassword( $wgUser, $this->mNewpass )) {
+                               $this->mainPrefsForm( wfMsg( 'externaldberror' ) );
+                               return;
+                       }
                        $wgUser->setPassword( $this->mNewpass );
                }
                $wgUser->setRealName( $this->mRealName );
@@ -207,8 +213,11 @@ class PreferencesForm {
                $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->validateInt( $this->mDate, 0, 10 ) );
                $wgUser->setOption( 'searchlimit', $this->validateIntOrNull( $this->mSearch ) );
                $wgUser->setOption( 'contextlines', $this->validateIntOrNull( $this->mSearchLines ) );
                $wgUser->setOption( 'contextchars', $this->validateIntOrNull( $this->mSearchChars ) );
@@ -219,6 +228,7 @@ 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 ) {
@@ -233,6 +243,10 @@ 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();
                
@@ -253,7 +267,7 @@ class PreferencesForm {
                                                if( WikiError::isError( $result ) ) {
                                                        $error = wfMsg( 'mailerror', $result->getMessage() );
                                                } else {
-                                                       $error = wfMsg( 'passwordsentforemailauthentication', $wgUser->getName() );
+                                                       $error = wfMsg( 'eauthentsent', $wgUser->getName() );
                                                }
                                        }
                                } else {
@@ -305,6 +319,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 ) {
@@ -383,11 +398,11 @@ class PreferencesForm {
        function mainPrefsForm( $err ) {
                global $wgUser, $wgOut, $wgLang, $wgContLang, $wgValidSkinNames;
                global $wgAllowRealName, $wgImageLimits, $wgThumbLimits;
-               global $wgLanguageNames, $wgDisableLangConversion;
-               global $wgEmailNotificationForWatchlistPages, $wgEmailNotificationForUserTalkPages,$wgEmailNotificationForMinorEdits;
-               global $wgRCShowWatchingUsers, $wgEmailNotificationRevealPageEditorAddress;
+               global $wgDisableLangConversion;
+               global $wgEnotifWatchlist, $wgEnotifUserTalk,$wgEnotifMinorEdits;
+               global $wgRCShowWatchingUsers, $wgEnotifRevealEditorAddress;
                global $wgEnableEmail, $wgEnableUserEmail, $wgEmailAuthentication;
-               global $wgContLanguageCode;
+               global $wgContLanguageCode, $wgDefaultSkin, $wgSkipSkins;
 
                $wgOut->setPageTitle( wfMsg( 'preferences' ) );
                $wgOut->setArticleRelated( false );
@@ -410,7 +425,14 @@ class PreferencesForm {
 
                $titleObj = Title::makeTitle( NS_SPECIAL, 'Preferences' );
                $action = $titleObj->escapeLocalURL();
-
+               
+               # Pre-expire some toggles so they won't show if disabled
+               $this->mUsedToggles[ 'shownumberswatching' ] = true;
+               $this->mUsedToggles[ 'showupdated' ] = true;
+               $this->mUsedToggles[ 'enotifwatchlistpages' ] = true;
+               $this->mUsedToggles[ 'enotifusertalkpages' ] = true;
+               $this->mUsedToggles[ 'enotifminoredits' ] = true;
+               $this->mUsedToggles[ 'enotifrevealaddr' ] = true;
 
                # Enotif
                # <FIXME>
@@ -423,30 +445,27 @@ class PreferencesForm {
                if ($wgEmailAuthentication && ($this->mUserEmail != '') ) {
                        if( $wgUser->getEmailAuthenticationTimestamp() ) {
                                $emailauthenticated = wfMsg('emailauthenticated',$wgLang->timeanddate($wgUser->getEmailAuthenticationTimestamp(), true ) ).'<br />';
-                               $disabled = '';
                        } else {
                                $skin = $wgUser->getSkin();
                                $emailauthenticated = wfMsg('emailnotauthenticated').'<br />' .
                                        $skin->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Confirmemail' ),
                                                wfMsg( 'emailconfirmlink' ) );
-                               $disabled = ' '.wfMsg('disableduntilauthent');
                        }
                } else {
                        $emailauthenticated = '';
-                       $disabled = false; // If it hasn't been set already the wiki will spew errors
                }
 
                if ($this->mUserEmail == '') {
-                       $disabled = ' '.wfMsg('disablednoemail');
+                       $emailauthenticated = wfMsg( 'noemailprefs' );
                }
 
                $ps = $this->namespacesCheckboxes();
 
-               $enotifwatchlistpages = ($wgEmailNotificationForWatchlistPages) ? $this->getToggle( 'enotifwatchlistpages', $disabled) : '';
-               $enotifusertalkpages = ($wgEmailNotificationForUserTalkPages) ? $this->getToggle( 'enotifusertalkpages', $disabled) : '';
-               $enotifminoredits = ($wgEmailNotificationForMinorEdits) ? $this->getToggle( 'enotifminoredits', $disabled) : '';
-               $enotifrevealaddr = ($wgEmailNotificationRevealPageEditorAddress) ? $this->getToggle( 'enotifrevealaddr', $disabled) : '';
-               $prefs_help_email_enotif = ( $wgEmailNotificationForWatchlistPages || $wgEmailNotificationForUserTalkPages) ? ' ' . wfMsg('prefs-help-email-enotif') : '';
+               $enotifwatchlistpages = ($wgEnotifWatchlist) ? $this->getToggle( 'enotifwatchlistpages' ) : '';
+               $enotifusertalkpages = ($wgEnotifUserTalk) ? $this->getToggle( 'enotifusertalkpages' ) : '';
+               $enotifminoredits = ($wgEnotifWatchlist && $wgEnotifMinorEdits) ? $this->getToggle( 'enotifminoredits' ) : '';
+               $enotifrevealaddr = (($wgEnotifWatchlist || $wgEnotifUserTalk) && $wgEnotifRevealEditorAddress) ? $this->getToggle( 'enotifrevealaddr' ) : '';
+               $prefs_help_email_enotif = ( $wgEnotifWatchlist || $wgEnotifUserTalk) ? ' ' . wfMsg('prefs-help-email-enotif') : '';
                $prefs_help_realname = '';
 
                # </FIXME>
@@ -493,9 +512,10 @@ class PreferencesForm {
                 * Otherwise, no default is selected and the user ends up
                 * with an Afrikaans interface since it's first in the list.
                 */
-               $selectedLang = isset( $wgLanguageNames[$this->mUserLanguage] ) ? $this->mUserLanguage : $wgContLanguageCode;
+               $languages = $wgLang->getLanguageNames();
+               $selectedLang = isset( $languages[$this->mUserLanguage] ) ? $this->mUserLanguage : $wgContLanguageCode;
                $selbox = null;
-               foreach($wgLanguageNames as $code => $name) {
+               foreach($languages as $code => $name) {
                        global $IP;
                        /* only add languages that have a file */
                        $langfile="$IP/languages/Language".str_replace('-', '_', ucfirst($code)).".php";
@@ -512,7 +532,7 @@ class PreferencesForm {
                
                        foreach($variants as $v) {
                                $v = str_replace( '_', '-', strtolower($v));
-                               if($name = $wgLanguageNames[$v]) {
+                               if($name = $languages[$v]) {
                                        $variantArray[$v] = $name;
                                }
                        }
@@ -557,7 +577,7 @@ class PreferencesForm {
                         if ($wgEnableUserEmail) {
                                $emf = wfMsg( 'emailflag' );
                                 $wgOut->addHTML(
-                                "<div><label><input type='checkbox' $emfc value=\"1\" name=\"wpEmailFlag\" />$emf.$disabled</label></div>" );
+                                "<div><label><input type='checkbox' $emfc value=\"1\" name=\"wpEmailFlag\" />$emf</label></div>" );
                         }
                        
                        $wgOut->addHTML( '</fieldset>' );
@@ -583,6 +603,10 @@ class PreferencesForm {
                                $wgOut->addHTML( "<div><label><input type='radio' name='wpQuickbar' value=\"$i\"$checked />{$qbs[$i]}</label></div>\n" );
                        }
                        $wgOut->addHtml( "</fieldset>\n\n" );
+               } else {
+                       # Need to output a hidden option even if the relevant skin is not in use, 
+                       # otherwise the preference will get reset to 0 on submit
+                       $wgOut->addHTML( "<input type='hidden' name='wpQuickbar' value='{$this->mQuickbar}' />" );
                }
 
                # Skin
@@ -591,8 +615,9 @@ class PreferencesForm {
                # Only show members of $wgValidSkinNames rather than
                # $skinNames (skins is all skin names from Language.php)
                foreach ($wgValidSkinNames as $skinkey => $skinname ) {
-                       global $wgDefaultSkin;
-                       
+                       if ( in_array( $skinkey, $wgSkipSkins ) ) {
+                               continue;
+                       }       
                        $checked = $skinkey == $this->mSkin ? ' checked="checked"' : '';
                        $sn = isset( $skinNames[$skinkey] ) ? $skinNames[$skinkey] : $skinname;
                        
@@ -604,12 +629,15 @@ class PreferencesForm {
 
                # Math
                #
-               $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg('math') . '</legend>' );
-               foreach ( $mathopts as $k => $v ) {
-                       $checked = $k == $this->mMath ? ' checked="checked"' : '';
-                       $wgOut->addHTML( "<div><label><input type='radio' name='wpMath' value=\"$k\"$checked /> ".wfMsg($v)."</label></div>\n" );
+               global $wgUseTeX;
+               if( $wgUseTeX ) {
+                       $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg('math') . '</legend>' );
+                       foreach ( $mathopts as $k => $v ) {
+                               $checked = $k == $this->mMath ? ' checked="checked"' : '';
+                               $wgOut->addHTML( "<div><label><input type='radio' name='wpMath' value=\"$k\"$checked /> ".wfMsg($v)."</label></div>\n" );
+                       }
+                       $wgOut->addHTML( "</fieldset>\n\n" );
                }
-               $wgOut->addHTML( "</fieldset>\n\n" );
 
                # Files
                #
@@ -699,12 +727,7 @@ class PreferencesForm {
                        $this->getToggles( array(
                                'hideminor',
                                $wgRCShowWatchingUsers ? 'shownumberswatching' : false,
-                               'usenewrc',
-                               'rcusemodstyle',
-                               array(
-                                       'showupdated',
-                                       wfMsg('updatedmarker')
-                               ) )
+                               'usenewrc' )
                        ) . '</fieldset>'
                );
        
@@ -718,6 +741,23 @@ class PreferencesForm {
                #
                $wgOut->addHTML('<fieldset><legend>' . wfMsg('prefs-misc') . '</legend>');
 
+               $msgUnderline = htmlspecialchars(wfMsg("tog-underline"));
+               $msgUnderlinenever = htmlspecialchars(wfMsg("underline-never"));
+               $msgUnderlinealways = htmlspecialchars(wfMsg("underline-always"));
+               $msgUnderlinedefault = htmlspecialchars(wfMsg("underline-default"));
+               $uopt = $wgUser->getOption("underline");
+               $s0 = $uopt == 0 ? " selected=\"selected\"" : "";
+               $s1 = $uopt == 1 ? " selected=\"selected\"" : "";
+               $s2 = $uopt == 2 ? " selected=\"selected\"" : "";
+               $wgOut->addHTML("
+<div class='toggle'><label>$msgUnderline 
+<select name=\"wpOpunderline\">
+<option value=\"0\"$s0>$msgUnderlinenever</option>
+<option value=\"1\"$s1>$msgUnderlinealways</option>
+<option value=\"2\"$s2>$msgUnderlinedefault</option>
+</select>
+</label></div>
+");
                foreach ( $togs as $tname ) {
                        if( !array_key_exists( $tname, $this->mUsedToggles ) ) {
                                $wgOut->addHTML( $this->getToggle( $tname ) );