* Moving hardcoded styles into CSS.
[lhc/web/wiklou.git] / includes / SpecialPreferences.php
index 84d383a..b4e91e4 100644 (file)
@@ -8,7 +8,7 @@
 if( !defined( 'MEDIAWIKI' ) )
        die();
 
-/* to get a list of languages in setting user's language preference */
+/** to get a list of languages in setting user's language preference */
 require_once('languages/Names.php');
 
 /**
@@ -39,7 +39,7 @@ class PreferencesForm {
         * Load some values
         */
        function PreferencesForm( &$request ) { 
-               global $wgLang, $wgContLang, $wgAllowRealName;
+               global $wgLang, $wgContLang, $wgUser, $wgAllowRealName;
                
                $this->mQuickbar = $request->getVal( 'wpQuickbar' );
                $this->mOldpass = $request->getVal( 'wpOldpass' );
@@ -56,18 +56,21 @@ class PreferencesForm {
                $this->mEmailFlag = $request->getCheck( 'wpEmailFlag' ) ? 1 : 0;
                $this->mNick = $request->getVal( 'wpNick' );
                $this->mUserLanguage = $request->getVal( 'wpUserLanguage' );
-        $this->mUserVariant = $request->getVal( 'wpUserVariant' );
+               $this->mUserVariant = $request->getVal( 'wpUserVariant' );
                $this->mSearch = $request->getVal( 'wpSearch' );
                $this->mRecent = $request->getVal( 'wpRecent' );
                $this->mHourDiff = $request->getVal( 'wpHourDiff' );
                $this->mSearchLines = $request->getVal( 'wpSearchLines' );
                $this->mSearchChars = $request->getVal( 'wpSearchChars' );
                $this->mImageSize = $request->getVal( 'wpImageSize' );
+               $this->mThumbSize = $request->getInt( 'wpThumbSize' );
 
                $this->mAction = $request->getVal( 'action' );
                $this->mReset = $request->getCheck( 'wpReset' );
                $this->mPosted = $request->wasPosted();
-               $this->mSaveprefs = $request->getCheck( 'wpSaveprefs' ) && $this->mPosted;
+               $this->mSaveprefs = $request->getCheck( 'wpSaveprefs' ) &&
+                       $this->mPosted &&
+                       $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
 
                # User toggles  (the big ugly unsorted list of checkboxes)
                $this->mToggles = array();
@@ -91,12 +94,17 @@ class PreferencesForm {
                                }
                        }
                }
+
+               # Validate language
+               if ( !preg_match( '/^[a-z\-]*$/', $this->mUserLanguage ) ) {
+                       $this->mUserLanguage = 'nolanguage';
+               }
        }
 
        function execute() {
-               global $wgUser, $wgOut, $wgUseDynamicDates;
+               global $wgUser, $wgOut;
                
-               if ( 0 == $wgUser->getID() ) {
+               if ( $wgUser->isAnon() ) {
                        $wgOut->errorpage( 'prefsnologin', 'prefsnologintext' );
                        return;
                }
@@ -138,7 +146,13 @@ class PreferencesForm {
        }
 
        /**
+        * Used to validate the user inputed timezone before saving it as
+        * 'timeciorrection', will return '00:00' if fed bogus data.
+        * Note: It's not a 100% correct implementation timezone-wise, it will
+        * accept stuff like '14:30',
         * @access private
+        * @param string $s the user input
+        * @return string
         */
        function validateTimeZone( $s ) {
                if ( $s !== '' ) {
@@ -152,8 +166,10 @@ class PreferencesForm {
                                $hour = intval( $minute / 60 );
                                $minute = abs( $minute ) % 60;
                        }
-                       $hour = min( $hour, 15 );
-                       $hour = max( $hour, -15 );
+                       # Max is +14:00 and min is -12:00, see:
+                       # http://en.wikipedia.org/wiki/Timezone
+                       $hour = min( $hour, 14 );
+                       $hour = max( $hour, -12 );
                        $minute = min( $minute, 59 );
                        $minute = max( $minute, 0 );
                        $s = sprintf( "%02d:%02d", $hour, $minute );
@@ -167,7 +183,7 @@ class PreferencesForm {
        function savePreferences() {
                global $wgUser, $wgLang, $wgOut;
                global $wgEnableUserEmail, $wgEnableEmail;
-               global $wgEmailAuthentication;
+               global $wgEmailAuthentication, $wgMinimalPasswordLength;
 
                if ( '' != $this->mNewpass ) {
                        if ( $this->mNewpass != $this->mRetypePass ) {
@@ -175,6 +191,11 @@ class PreferencesForm {
                                return;
                        }
 
+                       if ( strlen( $this->mNewpass ) < $wgMinimalPasswordLength ) {
+                               $this->mainPrefsForm( wfMsg( 'passwordtooshort', $wgMinimalPasswordLength ) );
+                               return;
+                       }
+
                        if (!$wgUser->checkPassword( $this->mOldpass )) {
                                $this->mainPrefsForm( wfMsg( 'wrongpassword' ) );
                                return;
@@ -183,7 +204,7 @@ class PreferencesForm {
                }
                $wgUser->setRealName( $this->mRealName );
                $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 );
@@ -198,6 +219,7 @@ class PreferencesForm {
                $wgUser->setOption( 'stubthreshold', $this->validateIntOrNull( $this->mStubs ) );
                $wgUser->setOption( 'timecorrection', $this->validateTimeZone( $this->mHourDiff, -12, 14 ) );
                $wgUser->setOption( 'imagesize', $this->mImageSize );
+               $wgUser->setOption( 'thumbsize', $this->mThumbSize );
 
                # Set search namespace options
                foreach( $this->mSearchNs as $i => $value ) {
@@ -227,7 +249,7 @@ class PreferencesForm {
                                }
                                $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();
+                               $wgUser->saveSettings();
                                if ($wgEmailAuthentication) {
                                        # mail a temporary password to the dirty address
                                        # on "save options", this user will be logged-out automatically
@@ -267,7 +289,7 @@ class PreferencesForm {
                        global $wgContLanguageCode;
                        $this->mUserLanguage = $wgContLanguageCode;
                }
-        $this->mUserVariant = $wgUser->getOption( 'variant');
+               $this->mUserVariant = $wgUser->getOption( 'variant');
                if ( 1 == $wgUser->getOption( 'disablemail' ) ) { $this->mEmailFlag = 1; }
                else { $this->mEmailFlag = 0; }
                $this->mNick = $wgUser->getOption( 'nickname' );
@@ -284,6 +306,7 @@ class PreferencesForm {
                $this->mSearchLines = $wgUser->getOption( 'contextlines' );
                $this->mSearchChars = $wgUser->getOption( 'contextchars' );
                $this->mImageSize = $wgUser->getOption( 'imagesize' );
+               $this->mThumbSize = $wgUser->getOption( 'thumbsize' );
                $this->mRecent = $wgUser->getOption( 'rclimit' );
 
                $togs = $wgLang->getUserToggles();
@@ -354,8 +377,8 @@ class PreferencesForm {
         * @access private
         */
        function mainPrefsForm( $err ) {
-               global $wgUser, $wgOut, $wgLang, $wgContLang, $wgUseDynamicDates, $wgValidSkinNames;
-               global $wgAllowRealName, $wgImageLimits;
+               global $wgUser, $wgOut, $wgLang, $wgContLang, $wgValidSkinNames;
+               global $wgAllowRealName, $wgImageLimits, $wgThumbLimits;
                global $wgLanguageNames, $wgDisableLangConversion;
                global $wgEmailNotificationForWatchlistPages, $wgEmailNotificationForUserTalkPages,$wgEmailNotificationForMinorEdits;
                global $wgRCShowWatchingUsers, $wgEmailNotificationRevealPageEditorAddress;
@@ -388,6 +411,7 @@ class PreferencesForm {
                $cp = wfMsg( 'changepassword' );
                $sk = wfMsg( 'skin' );
                $math = wfMsg( 'math' );
+               $files = wfMsg( 'files' );
                $dateFormat = wfMsg('dateformat');
                $opw = wfMsg( 'oldpassword' );
                $npw = wfMsg( 'newpassword' );
@@ -431,10 +455,10 @@ class PreferencesForm {
 
                if ($wgEmailAuthentication && ($this->mUserEmail != '') ) {
                        if ($wgUser->getEmailAuthenticationtimestamp() != 0) {
-                               $emailauthenticated = wfMsg('emailauthenticated',$wgLang->timeanddate($wgUser->getEmailAuthenticationtimestamp(), true ) ).'<br>';
+                               $emailauthenticated = wfMsg('emailauthenticated',$wgLang->timeanddate($wgUser->getEmailAuthenticationtimestamp(), true ) ).'<br />';
                                $disabled = '';
                        } else {
-                               $emailauthenticated = wfMsg('emailnotauthenticated').'<br>';
+                               $emailauthenticated = wfMsg('emailnotauthenticated').'<br />';
                                $disabled = ' '.wfMsg('disableduntilauthent');
                        }
                } else {
@@ -459,7 +483,7 @@ class PreferencesForm {
 
                        if ($wgAllowRealName) {
                        $wgOut->addHTML("<div><label>$yrn: <input type='text' name=\"wpRealName\" value=\"{$this->mRealName}\" size='20' /></label></div>");
-                       $prefs_help_realname = wfMsg('prefs-help-realname').'<br>';
+                       $prefs_help_realname = wfMsg('prefs-help-realname').'<br />';
                }
                
                if( $wgEnableEmail ) {
@@ -476,16 +500,28 @@ class PreferencesForm {
                        }
                }
                
+               $fancysig = $this->getToggle( 'fancysig' );
                $wgOut->addHTML("
-               <div><label>$ynn: <input type='text' name=\"wpNick\" value=\"{$this->mNick}\" size='12' /></label></div>
+               <div><label>$ynn: <input type='text' name=\"wpNick\" value=\"{$this->mNick}\" size='25' /></label></div>
+               <div>$fancysig<br /></div>
                <div><label>$yl: <select name=\"wpUserLanguage\">\n");
 
+               /**
+                * If a bogus value is set, default to the content language.
+                * Otherwise, no default is selected and the user ends up
+                * with an Afrikaans interface since it's first in the list.
+                */
+               if( isset( $wgLanguageNames[$this->mUserLanguage] ) ) {
+                       $selectedLang = $this->mUserLanguage;
+               } else {
+                       $selectedLang = $wgContLanguageCode;
+               }
                foreach($wgLanguageNames as $code => $name) {
                        global $IP;
                        /* only add languages that have a file */
                        $langfile="$IP/languages/Language".str_replace('-', '_', ucfirst($code)).".php";
                        if(file_exists($langfile) || $code == $wgContLanguageCode) {
-                               $sel = ($code == $this->mUserLanguage)? 'selected="selected"' : '';
+                               $sel = ($code == $selectedLang)? 'selected="selected"' : '';
                                $wgOut->addHtml("\t<option value=\"$code\" $sel>$code - $name</option>\n");
                        }
                }
@@ -529,18 +565,17 @@ class PreferencesForm {
        </fieldset>
        <div class='prefsectiontip'>".$prefs_help_realname.wfMsg('prefs-help-email').$prefs_help_email_enotif."</div>\n</fieldset>\n" );
 
-       
                # Quickbar setting
                #
-               $wgOut->addHtml( "<fieldset>\n<legend>$qb</legend>\n" );
-               for ( $i = 0; $i < count( $qbs ); ++$i ) {
-                       if ( $i == $this->mQuickbar ) { $checked = ' checked="checked"'; }
-                       else { $checked = ""; }
-                       $wgOut->addHTML( "<div><label><input type='radio' name=\"wpQuickbar\"
-       value=\"$i\"$checked /> {$qbs[$i]}</label></div>\n" );
+               if ($this->mSkin == 'cologneblue' || $this->mSkin == 'standard') {
+                       $wgOut->addHtml( "<fieldset>\n<legend>$qb</legend>\n" );
+                       for ( $i = 0; $i < count( $qbs ); ++$i ) {
+                               if ( $i == $this->mQuickbar ) { $checked = ' checked="checked"'; }
+                               else { $checked = ""; }
+                               $wgOut->addHTML( "<div><label><input type='radio' name=\"wpQuickbar\" value=\"$i\"$checked />{$qbs[$i]}</label></div>\n" );
+                       }
+                       $wgOut->addHtml( "</fieldset>\n\n" );
                }
-               $wgOut->addHtml('<div class="prefsectiontip">'.wfMsg('qbsettingsnote').'</div>');
-               $wgOut->addHtml( "</fieldset>\n\n" );
 
                # Skin setting
                #
@@ -562,8 +597,7 @@ class PreferencesForm {
                        if( $skinkey == $wgDefaultSkin ) {
                                $sn .= ' (' . wfMsg( 'default' ) . ')';
                        }
-                       $wgOut->addHTML( "<div><label><input type='radio' name=\"wpSkin\"
-       value=\"$skinkey\"$checked /> {$sn}</label></div>\n" );
+                       $wgOut->addHTML( "<div><label><input type='radio' name=\"wpSkin\" value=\"$skinkey\"$checked /> {$sn}</label></div>\n" );
                }
                $wgOut->addHTML( "</fieldset>\n\n" );
 
@@ -577,67 +611,87 @@ class PreferencesForm {
        value=\"$i\"$checked /> ".wfMsg($mathopts[$i])."</label></div>\n" );
                }
                $wgOut->addHTML( "</fieldset>\n\n" );
-               
-               # Date format
+
+               # Files
                #
-               if ( $wgUseDynamicDates ) {
+               $wgOut->addHTML("<fieldset>
+                       <legend>$files</legend>
+                       <div><label>" . wfMsg('imagemaxsize') . "<select name=\"wpImageSize\">");
+                       
+                       $imageLimitOptions = null;
+                       foreach ( $wgImageLimits as $index => $limits ) {
+                               $selected = ($index == $this->mImageSize) ? 'selected="selected"' : '';
+                               $imageLimitOptions .= "<option value=\"{$index}\" {$selected}>{$limits[0]}x{$limits[1]}</option>\n";
+                       }
+                       
+                       $imageThumbOptions = null;
+                       $wgOut->addHTML( "{$imageLimitOptions}</select></label></div>
+                               <div><label>" . wfMsg('thumbsize') . "<select name=\"wpThumbSize\">");
+                       foreach ( $wgThumbLimits as $index => $size ) {
+                               $selected = ($index == $this->mThumbSize) ? 'selected="selected"' : '';
+                               $imageThumbOptions .= "<option value=\"{$index}\" {$selected}>{$size}px</option>\n";
+                       }
+                       $wgOut->addHTML( "{$imageThumbOptions}</select></label></div></fieldset>\n\n");
+
+                # Date format
+                #
+               if ($dateopts) {
                        $wgOut->addHTML( "<fieldset>\n<legend>$dateFormat</legend>\n" );
-                       for ( $i = 0; $i < count( $dateopts ); ++$i) {
-                               if ( $i == $this->mDate ) {
-                                       $checked = ' checked="checked"';
-                               } else {
-                                       $checked = "";
-                               }
+                       foreach($dateopts as $key => $option) {
+                               ($key == $this->mDate) ? $checked = ' checked="checked"' : $checked = '';
                                $wgOut->addHTML( "<div><label><input type='radio' name=\"wpDate\" ".
-                                       "value=\"$i\"$checked /> {$dateopts[$i]}</label></div>\n" );
+                                       "value=\"$key\"$checked />$option</label></div>\n" );
                        }
                        $wgOut->addHTML( "</fieldset>\n\n");
                }
-               
-               # Textbox rows, cols
+
+               # Time zone
                #
+               
                $nowlocal = $wgLang->time( $now = wfTimestampNow(), true );
                $nowserver = $wgLang->time( $now, false );
+                
+               $wgOut->addHTML( "<fieldset>
+                       <legend>$timezone</legend>
+                       <div><b>$tzServerTime:</b>" .  $nowserver . "</div>
+                       <div><b>$ltz:</b> $nowlocal</div>
+                       <div><label>$tzo*: <input type='text' name=\"wpHourDiff\" value=\"" . htmlspecialchars( $this->mHourDiff ) . "\" size='6' /></label></div>
+                       <div><input type=\"button\" value=\"$tzGuess\" onclick=\"javascript:guessTimezone()\" id=\"guesstimezonebutton\" style=\"display:none\" /></div>
+                       <div class='prefsectiontip'>* {$tzt}</div>
+               </fieldset>\n\n" );             
+               
+               # Editing
+               #
                $wgOut->addHTML( "<fieldset>
        <legend>$tbs</legend>\n
                <div>
                        <label>$tbr: <input type='text' name=\"wpRows\" value=\"{$this->mRows}\" size='6' /></label>
                        <label>$tbc: <input type='text' name=\"wpCols\" value=\"{$this->mCols}\" size='6' /></label>
                </div> " .
+               $this->getToggle( "editsection" ) .
+               $this->getToggle( "editsectiononrightclick" ) .
+               $this->getToggle( "editondblclick" ) .
                $this->getToggle( "editwidth" ) .
                $this->getToggle( "showtoolbar" ) .
                $this->getToggle( "previewonfirst" ) .
                $this->getToggle( "previewontop" ) .
                $this->getToggle( "watchdefault" ) .
-               $this->getToggle( "minordefault" ) . "
-       </fieldset>
+               $this->getToggle( "minordefault" ) . 
+               $this->getToggle( "externaleditor" ) .
+               $this->getToggle( "externaldiff" ) .
+               "
+       </fieldset>");
        
-       <fieldset>
-               <legend>$timezone</legend>
-               <div><b>$tzServerTime:</b> $nowserver</div>
-               <div><b>$ltz:</b> $nowlocal</div>
-               <div><label>$tzo*: <input type='text' name=\"wpHourDiff\" value=\"" . htmlspecialchars( $this->mHourDiff ) . "\" size='6' /></label></div>
-               <div><input type=\"button\" value=\"$tzGuess\" onclick=\"javascript:guessTimezone()\" id=\"guesstimezonebutton\" style=\"display:none\" /></div>
-               <div class='prefsectiontip'>* {$tzt}</div>
-       </fieldset>\n\n" );
-
                $shownumberswatching = ($wgRCShowWatchingUsers) ? $this->getToggle('shownumberswatching') : '';
 
                $wgOut->addHTML( "
        <fieldset><legend>".wfMsg('prefs-rc')."</legend>
                <div><label>$rcc: <input type='text' name=\"wpRecent\" value=\"$this->mRecent\" size='6' /></label></div>" .
                $this->getToggle( "hideminor" ) . $shownumberswatching .
-               $this->getToggle( "usenewrc" ) . $this->getToggle('showupdated', wfMsg('updatedmarker')) .
+               $this->getToggle( "usenewrc" ) . 
+               $this->getToggle( "rcusemodstyle" ) .
+               $this->getToggle('showupdated', wfMsg('updatedmarker')) .
                "<div><label>$stt: <input type='text' name=\"wpStubs\" value=\"$this->mStubs\" size='6' /></label></div>
-                <div><label>".wfMsg('imagemaxsize')."<select name=\"wpImageSize\">");
-               
-               $imageLimitOptions='';
-               foreach ( $wgImageLimits as $index => $limits ) {
-                       $selected = ($index == $this->mImageSize) ? 'selected="selected"' : '';
-                       $imageLimitOptions .= "<option value=\"{$index}\" {$selected}>{$limits[0]}x{$limits[1]}</option>\n";
-               }
-               $wgOut->addHTML( "{$imageLimitOptions}</select></label></div>
-
        </fieldset>
        
        <fieldset>
@@ -656,6 +710,7 @@ class PreferencesForm {
                # Various checkbox options
                #
                $wgOut->addHTML("<fieldset><legend>".wfMsg('prefs-misc')."</legend>");
+
                foreach ( $togs as $tname ) {
                        if( !array_key_exists( $tname, $this->mUsedToggles ) ) {
                                $wgOut->addHTML( $this->getToggle( $tname ) );
@@ -663,6 +718,7 @@ class PreferencesForm {
                }
                $wgOut->addHTML( "</fieldset>\n\n" );
 
+               $token = htmlspecialchars( $wgUser->editToken() );
                $wgOut->addHTML( "
        <div id='prefsubmit'>
        <div>
@@ -673,6 +729,7 @@ class PreferencesForm {
        
        </div>
        
+       <input type='hidden' name='wpEditToken' value=\"{$token}\" />
        </form>\n" );
        }
 }