Fixes per Gangleri's request:
[mediawiki.git] / includes / SpecialPreferences.php
blob1ade3079c555db0a3483815992140e13abc192c2
1 <?php
2 /**
3 * Hold things related to displaying and saving user preferences.
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
8 /**
9 * Entry point that create the "Preferences" object
11 function wfSpecialPreferences() {
12 global $wgRequest;
14 $form = new PreferencesForm( $wgRequest );
15 $form->execute();
18 /**
19 * Preferences form handling
20 * This object will show the preferences form and can save it as well.
21 * @package MediaWiki
22 * @subpackage SpecialPage
24 class PreferencesForm {
25 var $mQuickbar, $mOldpass, $mNewpass, $mRetypePass, $mStubs;
26 var $mRows, $mCols, $mSkin, $mMath, $mDate, $mUserEmail, $mEmailFlag, $mNick;
27 var $mUserLanguage, $mUserVariant;
28 var $mSearch, $mRecent, $mHourDiff, $mSearchLines, $mSearchChars, $mAction;
29 var $mReset, $mPosted, $mToggles, $mSearchNs, $mRealName, $mImageSize;
30 var $mUnderline, $mWatchlistEdits;
32 /**
33 * Constructor
34 * Load some values
36 function PreferencesForm( &$request ) {
37 global $wgLang, $wgContLang, $wgUser, $wgAllowRealName;
39 $this->mQuickbar = $request->getVal( 'wpQuickbar' );
40 $this->mOldpass = $request->getVal( 'wpOldpass' );
41 $this->mNewpass = $request->getVal( 'wpNewpass' );
42 $this->mRetypePass =$request->getVal( 'wpRetypePass' );
43 $this->mStubs = $request->getVal( 'wpStubs' );
44 $this->mRows = $request->getVal( 'wpRows' );
45 $this->mCols = $request->getVal( 'wpCols' );
46 $this->mSkin = $request->getVal( 'wpSkin' );
47 $this->mMath = $request->getVal( 'wpMath' );
48 $this->mDate = $request->getVal( 'wpDate' );
49 $this->mUserEmail = $request->getVal( 'wpUserEmail' );
50 $this->mRealName = $wgAllowRealName ? $request->getVal( 'wpRealName' ) : '';
51 $this->mEmailFlag = $request->getCheck( 'wpEmailFlag' ) ? 0 : 1;
52 $this->mNick = $request->getVal( 'wpNick' );
53 $this->mUserLanguage = $request->getVal( 'wpUserLanguage' );
54 $this->mUserVariant = $request->getVal( 'wpUserVariant' );
55 $this->mSearch = $request->getVal( 'wpSearch' );
56 $this->mRecent = $request->getVal( 'wpRecent' );
57 $this->mHourDiff = $request->getVal( 'wpHourDiff' );
58 $this->mSearchLines = $request->getVal( 'wpSearchLines' );
59 $this->mSearchChars = $request->getVal( 'wpSearchChars' );
60 $this->mImageSize = $request->getVal( 'wpImageSize' );
61 $this->mThumbSize = $request->getInt( 'wpThumbSize' );
62 $this->mUnderline = $request->getInt( 'wpOpunderline' );
63 $this->mAction = $request->getVal( 'action' );
64 $this->mReset = $request->getCheck( 'wpReset' );
65 $this->mPosted = $request->wasPosted();
66 $this->mSuccess = $request->getCheck( 'success' );
67 $this->mWatchlistDays = $request->getVal( 'wpWatchlistDays' );
68 $this->mWatchlistEdits = $request->getVal( 'wpWatchlistEdits' );
70 $this->mSaveprefs = $request->getCheck( 'wpSaveprefs' ) &&
71 $this->mPosted &&
72 $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
74 # User toggles (the big ugly unsorted list of checkboxes)
75 $this->mToggles = array();
76 if ( $this->mPosted ) {
77 $togs = $wgLang->getUserToggles();
78 foreach ( $togs as $tname ) {
79 $this->mToggles[$tname] = $request->getCheck( "wpOp$tname" ) ? 1 : 0;
83 $this->mUsedToggles = array();
85 # Search namespace options
86 # Note: namespaces don't necessarily have consecutive keys
87 $this->mSearchNs = array();
88 if ( $this->mPosted ) {
89 $namespaces = $wgContLang->getNamespaces();
90 foreach ( $namespaces as $i => $namespace ) {
91 if ( $i >= 0 ) {
92 $this->mSearchNs[$i] = $request->getCheck( "wpNs$i" ) ? 1 : 0;
97 # Validate language
98 if ( !preg_match( '/^[a-z\-]*$/', $this->mUserLanguage ) ) {
99 $this->mUserLanguage = 'nolanguage';
103 function execute() {
104 global $wgUser, $wgOut;
106 if ( $wgUser->isAnon() ) {
107 $wgOut->showErrorPage( 'prefsnologin', 'prefsnologintext' );
108 return;
110 if ( wfReadOnly() ) {
111 $wgOut->readOnlyPage();
112 return;
114 if ( $this->mReset ) {
115 $this->resetPrefs();
116 $this->mainPrefsForm( 'reset', wfMsg( 'prefsreset' ) );
117 } else if ( $this->mSaveprefs ) {
118 $this->savePreferences();
119 } else {
120 $this->resetPrefs();
121 $this->mainPrefsForm( '' );
125 * @access private
127 function validateInt( &$val, $min=0, $max=0x7fffffff ) {
128 $val = intval($val);
129 $val = min($val, $max);
130 $val = max($val, $min);
131 return $val;
135 * @access private
137 function validateFloat( &$val, $min, $max=0x7fffffff ) {
138 $val = floatval( $val );
139 $val = min( $val, $max );
140 $val = max( $val, $min );
141 return( $val );
145 * @access private
147 function validateIntOrNull( &$val, $min=0, $max=0x7fffffff ) {
148 $val = trim($val);
149 if($val === '') {
150 return $val;
151 } else {
152 return $this->validateInt( $val, $min, $max );
157 * @access private
159 function validateDate( &$val, $min = 0, $max=0x7fffffff ) {
160 if ( ( sprintf('%d', $val) === $val && $val >= $min && $val <= $max ) || $val == 'ISO 8601' )
161 return $val;
162 else
163 return 0;
167 * Used to validate the user inputed timezone before saving it as
168 * 'timeciorrection', will return '00:00' if fed bogus data.
169 * Note: It's not a 100% correct implementation timezone-wise, it will
170 * accept stuff like '14:30',
171 * @access private
172 * @param string $s the user input
173 * @return string
175 function validateTimeZone( $s ) {
176 if ( $s !== '' ) {
177 if ( strpos( $s, ':' ) ) {
178 # HH:MM
179 $array = explode( ':' , $s );
180 $hour = intval( $array[0] );
181 $minute = intval( $array[1] );
182 } else {
183 $minute = intval( $s * 60 );
184 $hour = intval( $minute / 60 );
185 $minute = abs( $minute ) % 60;
187 # Max is +14:00 and min is -12:00, see:
188 # http://en.wikipedia.org/wiki/Timezone
189 $hour = min( $hour, 14 );
190 $hour = max( $hour, -12 );
191 $minute = min( $minute, 59 );
192 $minute = max( $minute, 0 );
193 $s = sprintf( "%02d:%02d", $hour, $minute );
195 return $s;
199 * @access private
201 function savePreferences() {
202 global $wgUser, $wgOut, $wgParser;
203 global $wgEnableUserEmail, $wgEnableEmail;
204 global $wgEmailAuthentication, $wgMinimalPasswordLength;
205 global $wgAuth;
208 if ( '' != $this->mNewpass ) {
209 if ( $this->mNewpass != $this->mRetypePass ) {
210 $this->mainPrefsForm( 'error', wfMsg( 'badretype' ) );
211 return;
214 if ( strlen( $this->mNewpass ) < $wgMinimalPasswordLength ) {
215 $this->mainPrefsForm( 'error', wfMsg( 'passwordtooshort', $wgMinimalPasswordLength ) );
216 return;
219 if (!$wgUser->checkPassword( $this->mOldpass )) {
220 $this->mainPrefsForm( 'error', wfMsg( 'wrongpassword' ) );
221 return;
223 if (!$wgAuth->setPassword( $wgUser, $this->mNewpass )) {
224 $this->mainPrefsForm( 'error', wfMsg( 'externaldberror' ) );
225 return;
227 $wgUser->setPassword( $this->mNewpass );
228 $this->mNewpass = $this->mOldpass = $this->mRetypePass = '';
231 $wgUser->setRealName( $this->mRealName );
233 if( $wgUser->getOption( 'language' ) !== $this->mUserLanguage ) {
234 $needRedirect = true;
235 } else {
236 $needRedirect = false;
239 # Validate the signature and clean it up as needed
240 if( $this->mToggles['fancysig'] ) {
241 if( Parser::validateSig( $this->mNick ) !== false ) {
242 $this->mNick = $wgParser->cleanSig( $this->mNick );
243 } else {
244 $this->mainPrefsForm( 'error', wfMsg( 'badsig' ) );
248 $wgUser->setOption( 'language', $this->mUserLanguage );
249 $wgUser->setOption( 'variant', $this->mUserVariant );
250 $wgUser->setOption( 'nickname', $this->mNick );
251 $wgUser->setOption( 'quickbar', $this->mQuickbar );
252 $wgUser->setOption( 'skin', $this->mSkin );
253 global $wgUseTeX;
254 if( $wgUseTeX ) {
255 $wgUser->setOption( 'math', $this->mMath );
257 $wgUser->setOption( 'date', $this->validateDate( $this->mDate, 0, 20 ) );
258 $wgUser->setOption( 'searchlimit', $this->validateIntOrNull( $this->mSearch ) );
259 $wgUser->setOption( 'contextlines', $this->validateIntOrNull( $this->mSearchLines ) );
260 $wgUser->setOption( 'contextchars', $this->validateIntOrNull( $this->mSearchChars ) );
261 $wgUser->setOption( 'rclimit', $this->validateIntOrNull( $this->mRecent ) );
262 $wgUser->setOption( 'wllimit', $this->validateIntOrNull( $this->mWatchlistEdits, 0, 1000 ) );
263 $wgUser->setOption( 'rows', $this->validateInt( $this->mRows, 4, 1000 ) );
264 $wgUser->setOption( 'cols', $this->validateInt( $this->mCols, 4, 1000 ) );
265 $wgUser->setOption( 'stubthreshold', $this->validateIntOrNull( $this->mStubs ) );
266 $wgUser->setOption( 'timecorrection', $this->validateTimeZone( $this->mHourDiff, -12, 14 ) );
267 $wgUser->setOption( 'imagesize', $this->mImageSize );
268 $wgUser->setOption( 'thumbsize', $this->mThumbSize );
269 $wgUser->setOption( 'underline', $this->validateInt($this->mUnderline, 0, 2) );
270 $wgUser->setOption( 'watchlistdays', $this->validateFloat( $this->mWatchlistDays, 0, 7 ) );
272 # Set search namespace options
273 foreach( $this->mSearchNs as $i => $value ) {
274 $wgUser->setOption( "searchNs{$i}", $value );
277 if( $wgEnableEmail && $wgEnableUserEmail ) {
278 $wgUser->setOption( 'disablemail', $this->mEmailFlag );
281 # Set user toggles
282 foreach ( $this->mToggles as $tname => $tvalue ) {
283 $wgUser->setOption( $tname, $tvalue );
285 if (!$wgAuth->updateExternalDB($wgUser)) {
286 $this->mainPrefsForm( wfMsg( 'externaldberror' ) );
287 return;
289 $wgUser->setCookies();
290 $wgUser->saveSettings();
292 $error = false;
293 if( $wgEnableEmail ) {
294 $newadr = $this->mUserEmail;
295 $oldadr = $wgUser->getEmail();
296 if( ($newadr != '') && ($newadr != $oldadr) ) {
297 # the user has supplied a new email address on the login page
298 if( $wgUser->isValidEmailAddr( $newadr ) ) {
299 $wgUser->mEmail = $newadr; # new behaviour: set this new emailaddr from login-page into user database record
300 $wgUser->mEmailAuthenticated = null; # but flag as "dirty" = unauthenticated
301 $wgUser->saveSettings();
302 if ($wgEmailAuthentication) {
303 # Mail a temporary password to the dirty address.
304 # User can come back through the confirmation URL to re-enable email.
305 $result = $wgUser->sendConfirmationMail();
306 if( WikiError::isError( $result ) ) {
307 $error = wfMsg( 'mailerror', htmlspecialchars( $result->getMessage() ) );
308 } else {
309 $error = wfMsg( 'eauthentsent', $wgUser->getName() );
312 } else {
313 $error = wfMsg( 'invalidemailaddress' );
315 } else {
316 $wgUser->setEmail( $this->mUserEmail );
317 $wgUser->setCookies();
318 $wgUser->saveSettings();
322 if( $needRedirect && $error === false ) {
323 $title =& Title::makeTitle( NS_SPECIAL, "Preferences" );
324 $wgOut->redirect($title->getFullURL('success'));
325 return;
328 $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
329 $po = ParserOptions::newFromUser( $wgUser );
330 $this->mainPrefsForm( $error === false ? 'success' : 'error', $error);
334 * @access private
336 function resetPrefs() {
337 global $wgUser, $wgLang, $wgContLang, $wgAllowRealName;
339 $this->mOldpass = $this->mNewpass = $this->mRetypePass = '';
340 $this->mUserEmail = $wgUser->getEmail();
341 $this->mUserEmailAuthenticationtimestamp = $wgUser->getEmailAuthenticationtimestamp();
342 $this->mRealName = ($wgAllowRealName) ? $wgUser->getRealName() : '';
343 $this->mUserLanguage = $wgUser->getOption( 'language' );
344 if( empty( $this->mUserLanguage ) ) {
345 # Quick hack for conversions, where this value is blank
346 global $wgContLanguageCode;
347 $this->mUserLanguage = $wgContLanguageCode;
349 $this->mUserVariant = $wgUser->getOption( 'variant');
350 $this->mEmailFlag = $wgUser->getOption( 'disablemail' ) == 1 ? 1 : 0;
351 $this->mNick = $wgUser->getOption( 'nickname' );
353 $this->mQuickbar = $wgUser->getOption( 'quickbar' );
354 $this->mSkin = Skin::normalizeKey( $wgUser->getOption( 'skin' ) );
355 $this->mMath = $wgUser->getOption( 'math' );
356 $this->mDate = $wgUser->getOption( 'date' );
357 $this->mRows = $wgUser->getOption( 'rows' );
358 $this->mCols = $wgUser->getOption( 'cols' );
359 $this->mStubs = $wgUser->getOption( 'stubthreshold' );
360 $this->mHourDiff = $wgUser->getOption( 'timecorrection' );
361 $this->mSearch = $wgUser->getOption( 'searchlimit' );
362 $this->mSearchLines = $wgUser->getOption( 'contextlines' );
363 $this->mSearchChars = $wgUser->getOption( 'contextchars' );
364 $this->mImageSize = $wgUser->getOption( 'imagesize' );
365 $this->mThumbSize = $wgUser->getOption( 'thumbsize' );
366 $this->mRecent = $wgUser->getOption( 'rclimit' );
367 $this->mWatchlistEdits = $wgUser->getOption( 'wllimit' );
368 $this->mUnderline = $wgUser->getOption( 'underline' );
369 $this->mWatchlistDays = $wgUser->getOption( 'watchlistdays' );
371 $togs = $wgLang->getUserToggles();
372 foreach ( $togs as $tname ) {
373 $ttext = wfMsg('tog-'.$tname);
374 $this->mToggles[$tname] = $wgUser->getOption( $tname );
377 $namespaces = $wgContLang->getNamespaces();
378 foreach ( $namespaces as $i => $namespace ) {
379 if ( $i >= NS_MAIN ) {
380 $this->mSearchNs[$i] = $wgUser->getOption( 'searchNs'.$i );
386 * @access private
388 function namespacesCheckboxes() {
389 global $wgContLang;
391 # Determine namespace checkboxes
392 $namespaces = $wgContLang->getNamespaces();
393 $r1 = null;
395 foreach ( $namespaces as $i => $name ) {
396 if ($i < 0)
397 continue;
398 $checked = $this->mSearchNs[$i] ? "checked='checked'" : '';
399 $name = str_replace( '_', ' ', $namespaces[$i] );
401 if ( empty($name) )
402 $name = wfMsg( 'blanknamespace' );
404 $r1 .= "<input type='checkbox' value='1' name='wpNs$i' id='wpNs$i' {$checked}/> <label for='wpNs$i'>{$name}</label><br />\n";
406 return $r1;
410 function getToggle( $tname, $trailer = false, $disabled = false ) {
411 global $wgUser, $wgLang;
413 $this->mUsedToggles[$tname] = true;
414 $ttext = $wgLang->getUserToggle( $tname );
416 $checked = $wgUser->getOption( $tname ) == 1 ? ' checked="checked"' : '';
417 $disabled = $disabled ? ' disabled="disabled"' : '';
418 $trailer = $trailer ? $trailer : '';
419 return "<div class='toggle'><input type='checkbox' value='1' id=\"$tname\" name=\"wpOp$tname\"$checked$disabled />" .
420 " <span class='toggletext'><label for=\"$tname\">$ttext</label>$trailer</span></div>\n";
423 function getToggles( $items ) {
424 $out = "";
425 foreach( $items as $item ) {
426 if( $item === false )
427 continue;
428 if( is_array( $item ) ) {
429 list( $key, $trailer ) = $item;
430 } else {
431 $key = $item;
432 $trailer = false;
434 $out .= $this->getToggle( $key, $trailer );
436 return $out;
439 function addRow($td1, $td2) {
440 return "<tr><td align='right'>$td1</td><td align='left'>$td2</td></tr>";
444 * @access private
446 function mainPrefsForm( $status , $message = '' ) {
447 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgValidSkinNames;
448 global $wgAllowRealName, $wgImageLimits, $wgThumbLimits;
449 global $wgDisableLangConversion;
450 global $wgEnotifWatchlist, $wgEnotifUserTalk,$wgEnotifMinorEdits;
451 global $wgRCShowWatchingUsers, $wgEnotifRevealEditorAddress;
452 global $wgEnableEmail, $wgEnableUserEmail, $wgEmailAuthentication;
453 global $wgContLanguageCode, $wgDefaultSkin, $wgSkipSkins;
455 $wgOut->setPageTitle( wfMsg( 'preferences' ) );
456 $wgOut->setArticleRelated( false );
457 $wgOut->setRobotpolicy( 'noindex,nofollow' );
459 if ( $this->mSuccess || 'success' == $status ) {
460 $wgOut->addWikitext( '<div class="successbox"><strong>'. wfMsg( 'savedprefs' ) . '</strong></div>' );
461 } else if ( 'error' == $status ) {
462 $wgOut->addWikitext( '<div class="errorbox"><strong>' . $message . '</strong></div>' );
463 } else if ( '' != $status ) {
464 $wgOut->addWikitext( $message . "\n----" );
467 $qbs = $wgLang->getQuickbarSettings();
468 $skinNames = $wgLang->getSkinNames();
469 $mathopts = $wgLang->getMathNames();
470 $dateopts = $wgLang->getDateFormats();
471 $togs = $wgLang->getUserToggles();
473 $titleObj = Title::makeTitle( NS_SPECIAL, 'Preferences' );
474 $action = $titleObj->escapeLocalURL();
476 # Pre-expire some toggles so they won't show if disabled
477 $this->mUsedToggles[ 'shownumberswatching' ] = true;
478 $this->mUsedToggles[ 'showupdated' ] = true;
479 $this->mUsedToggles[ 'enotifwatchlistpages' ] = true;
480 $this->mUsedToggles[ 'enotifusertalkpages' ] = true;
481 $this->mUsedToggles[ 'enotifminoredits' ] = true;
482 $this->mUsedToggles[ 'enotifrevealaddr' ] = true;
483 $this->mUsedToggles[ 'uselivepreview' ] = true;
485 # Enotif
486 # <FIXME>
487 $this->mUserEmail = htmlspecialchars( $this->mUserEmail );
488 $this->mRealName = htmlspecialchars( $this->mRealName );
489 $rawNick = $this->mNick;
490 $this->mNick = htmlspecialchars( $this->mNick );
491 if ( !$this->mEmailFlag ) { $emfc = 'checked="checked"'; }
492 else { $emfc = ''; }
495 if ($wgEmailAuthentication && ($this->mUserEmail != '') ) {
496 if( $wgUser->getEmailAuthenticationTimestamp() ) {
497 $emailauthenticated = wfMsg('emailauthenticated',$wgLang->timeanddate($wgUser->getEmailAuthenticationTimestamp(), true ) ).'<br />';
498 $disableEmailPrefs = false;
499 } else {
500 $disableEmailPrefs = true;
501 $skin = $wgUser->getSkin();
502 $emailauthenticated = wfMsg('emailnotauthenticated').'<br />' .
503 $skin->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Confirmemail' ),
504 wfMsg( 'emailconfirmlink' ) );
506 } else {
507 $emailauthenticated = '';
508 $disableEmailPrefs = false;
511 if ($this->mUserEmail == '') {
512 $emailauthenticated = wfMsg( 'noemailprefs' );
515 $ps = $this->namespacesCheckboxes();
517 $enotifwatchlistpages = ($wgEnotifWatchlist) ? $this->getToggle( 'enotifwatchlistpages', false, $disableEmailPrefs ) : '';
518 $enotifusertalkpages = ($wgEnotifUserTalk) ? $this->getToggle( 'enotifusertalkpages', false, $disableEmailPrefs ) : '';
519 $enotifminoredits = ($wgEnotifWatchlist && $wgEnotifMinorEdits) ? $this->getToggle( 'enotifminoredits', false, $disableEmailPrefs ) : '';
520 $enotifrevealaddr = (($wgEnotifWatchlist || $wgEnotifUserTalk) && $wgEnotifRevealEditorAddress) ? $this->getToggle( 'enotifrevealaddr', false, $disableEmailPrefs ) : '';
521 $prefs_help_email_enotif = ( $wgEnotifWatchlist || $wgEnotifUserTalk) ? ' ' . wfMsg('prefs-help-email-enotif') : '';
522 $prefs_help_realname = '';
524 # </FIXME>
526 $wgOut->addHTML( "<form action=\"$action\" method='post'>" );
527 $wgOut->addHTML( "<div id='preferences'>" );
529 # User data
532 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg('prefs-personal') . "</legend>\n<table>\n");
534 $wgOut->addHTML(
535 $this->addRow(
536 wfMsg( 'username'),
537 $wgUser->getName()
541 $wgOut->addHTML(
542 $this->addRow(
543 wfMsg( 'uid' ),
544 $wgUser->getID()
549 if ($wgAllowRealName) {
550 $wgOut->addHTML(
551 $this->addRow(
552 '<label for="wpRealName">' . wfMsg('yourrealname') . '</label>',
553 "<input type='text' name='wpRealName' id='wpRealName' value=\"{$this->mRealName}\" size='25' />"
557 if ($wgEnableEmail) {
558 $wgOut->addHTML(
559 $this->addRow(
560 '<label for="wpUserEmail">' . wfMsg( 'youremail' ) . '</label>',
561 "<input type='text' name='wpUserEmail' id='wpUserEmail' value=\"{$this->mUserEmail}\" size='25' />"
566 global $wgParser;
567 if( !empty( $this->mToggles['fancysig'] ) &&
568 false === $wgParser->validateSig( $rawNick ) ) {
569 $invalidSig = $this->addRow(
570 '&nbsp;',
571 '<span class="error">' . wfMsgHtml( 'badsig' ) . '<span>'
573 } else {
574 $invalidSig = '';
577 $wgOut->addHTML(
578 $this->addRow(
579 '<label for="wpNick">' . wfMsg( 'yournick' ) . '</label>',
580 "<input type='text' name='wpNick' id='wpNick' value=\"{$this->mNick}\" size='25' />"
582 $invalidSig .
583 # FIXME: The <input> part should be where the &nbsp; is, getToggle() needs
584 # to be changed to out return its output in two parts. -รฆvar
585 $this->addRow(
586 '&nbsp;',
587 $this->getToggle( 'fancysig' )
592 * Make sure the site language is in the list; a custom language code
593 * might not have a defined name...
595 $languages = $wgLang->getLanguageNames();
596 if( !array_key_exists( $wgContLanguageCode, $languages ) ) {
597 $languages[$wgContLanguageCode] = $wgContLanguageCode;
599 ksort( $languages );
602 * If a bogus value is set, default to the content language.
603 * Otherwise, no default is selected and the user ends up
604 * with an Afrikaans interface since it's first in the list.
606 $selectedLang = isset( $languages[$this->mUserLanguage] ) ? $this->mUserLanguage : $wgContLanguageCode;
607 $selbox = null;
608 foreach($languages as $code => $name) {
609 global $IP;
610 /* only add languages that have a file */
611 $langfile="$IP/languages/Language".str_replace('-', '_', ucfirst($code)).".php";
612 if(file_exists($langfile) || $code == $wgContLanguageCode) {
613 $sel = ($code == $selectedLang)? ' selected="selected"' : '';
614 $selbox .= "<option value=\"$code\"$sel>$code - $name</option>\n";
617 $wgOut->addHTML(
618 $this->addRow(
619 '<label for="wpUserLanguage">' . wfMsg('yourlanguage') . '</label>',
620 "<select name='wpUserLanguage' id='wpUserLanguage'>$selbox</select>"
624 /* see if there are multiple language variants to choose from*/
625 if(!$wgDisableLangConversion) {
626 $variants = $wgContLang->getVariants();
627 $variantArray = array();
629 foreach($variants as $v) {
630 $v = str_replace( '_', '-', strtolower($v));
631 if( array_key_exists( $v, $languages ) ) {
632 // If it doesn't have a name, we'll pretend it doesn't exist
633 $variantArray[$v] = $languages[$v];
637 $selbox = null;
638 foreach($variantArray as $code => $name) {
639 $sel = $code == $this->mUserVariant ? 'selected="selected"' : '';
640 $selbox .= "<option value=\"$code\" $sel>$code - $name</option>";
643 if(count($variantArray) > 1) {
644 $wgOut->addHtml(
645 $this->addRow( wfMsg( 'yourvariant' ), "<select name='wpUserVariant'>$selbox</select>" )
649 $wgOut->addHTML('</table>');
651 # Password
652 $this->mOldpass = htmlspecialchars( $this->mOldpass );
653 $this->mNewpass = htmlspecialchars( $this->mNewpass );
654 $this->mRetypePass = htmlspecialchars( $this->mRetypePass );
656 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'changepassword' ) . '</legend><table>');
657 $wgOut->addHTML(
658 $this->addRow(
659 '<label for="wpOldpass">' . wfMsg( 'oldpassword' ) . '</label>',
660 "<input type='password' name='wpOldpass' id='wpOldpass' value=\"{$this->mOldpass}\" size='20' />"
662 $this->addRow(
663 '<label for="wpNewpass">' . wfMsg( 'newpassword' ) . '</label>',
664 "<input type='password' name='wpNewpass' id='wpNewpass' value=\"{$this->mNewpass}\" size='20' />"
666 $this->addRow(
667 '<label for="wpRetypePass">' . wfMsg( 'retypenew' ) . '</label>',
668 "<input type='password' name='wpRetypePass' id='wpRetypePass' value=\"{$this->mRetypePass}\" size='20' />"
670 "</table>\n" .
671 $this->getToggle( "rememberpassword" ) . "</fieldset>\n\n" );
673 # <FIXME>
674 # Enotif
675 if ($wgEnableEmail) {
676 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'email' ) . '</legend>' );
677 $wgOut->addHTML(
678 $emailauthenticated.
679 $enotifrevealaddr.
680 $enotifwatchlistpages.
681 $enotifusertalkpages.
682 $enotifminoredits );
683 if ($wgEnableUserEmail) {
684 $emf = wfMsg( 'allowemail' );
685 $disabled = $disableEmailPrefs ? ' disabled="disabled"' : '';
686 $wgOut->addHTML(
687 "<div><input type='checkbox' $emfc $disabled value='1' name='wpEmailFlag' id='wpEmailFlag' /> <label for='wpEmailFlag'>$emf</label></div>" );
690 $wgOut->addHTML( '</fieldset>' );
692 # </FIXME>
694 if ($wgAllowRealName || $wgEnableEmail) {
695 $wgOut->addHTML("<div class='prefsectiontip'>");
696 $rn = $wgAllowRealName ? wfMsg('prefs-help-realname') : '';
697 $em = $wgEnableEmail ? '<br />' . wfMsg('prefs-help-email') : '';
698 $wgOut->addHTML( $rn . $em . '</div>');
701 $wgOut->addHTML( '</fieldset>' );
703 # Quickbar
705 if ($this->mSkin == 'cologneblue' || $this->mSkin == 'standard') {
706 $wgOut->addHtml( "<fieldset>\n<legend>" . wfMsg( 'qbsettings' ) . "</legend>\n" );
707 for ( $i = 0; $i < count( $qbs ); ++$i ) {
708 if ( $i == $this->mQuickbar ) { $checked = ' checked="checked"'; }
709 else { $checked = ""; }
710 $wgOut->addHTML( "<div><label><input type='radio' name='wpQuickbar' value=\"$i\"$checked />{$qbs[$i]}</label></div>\n" );
712 $wgOut->addHtml( "</fieldset>\n\n" );
713 } else {
714 # Need to output a hidden option even if the relevant skin is not in use,
715 # otherwise the preference will get reset to 0 on submit
716 $wgOut->addHtml( wfHidden( 'wpQuickbar', $this->mQuickbar ) );
719 # Skin
721 $wgOut->addHTML( "<fieldset>\n<legend>\n" . wfMsg('skin') . "</legend>\n" );
722 $mptitle = Title::newMainPage();
723 $previewtext = wfMsg('skinpreview');
724 # Only show members of $wgValidSkinNames rather than
725 # $skinNames (skins is all skin names from Language.php)
726 foreach ($wgValidSkinNames as $skinkey => $skinname ) {
727 if ( in_array( $skinkey, $wgSkipSkins ) ) {
728 continue;
730 $checked = $skinkey == $this->mSkin ? ' checked="checked"' : '';
731 $sn = isset( $skinNames[$skinkey] ) ? $skinNames[$skinkey] : $skinname;
733 $mplink = htmlspecialchars($mptitle->getLocalURL("useskin=$skinkey"));
734 $previewlink = "<a target='_blank' href=\"$mplink\">$previewtext</a>";
735 if( $skinkey == $wgDefaultSkin )
736 $sn .= ' (' . wfMsg( 'default' ) . ')';
737 $wgOut->addHTML( "<input type='radio' name='wpSkin' id=\"wpSkin$skinkey\" value=\"$skinkey\"$checked /> <label for=\"wpSkin$skinkey\">{$sn}</label> $previewlink<br/>\n" );
739 $wgOut->addHTML( "</fieldset>\n\n" );
741 # Math
743 global $wgUseTeX;
744 if( $wgUseTeX ) {
745 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg('math') . '</legend>' );
746 foreach ( $mathopts as $k => $v ) {
747 $checked = $k == $this->mMath ? ' checked="checked"' : '';
748 $wgOut->addHTML( "<div><label><input type='radio' name='wpMath' value=\"$k\"$checked /> ".wfMsg($v)."</label></div>\n" );
750 $wgOut->addHTML( "</fieldset>\n\n" );
753 # Files
755 $wgOut->addHTML("<fieldset>
756 <legend>" . wfMsg( 'files' ) . "</legend>
757 <div><label for='wpImageSize'>" . wfMsg('imagemaxsize') . "</label> <select id='wpImageSize' name='wpImageSize'>");
759 $imageLimitOptions = null;
760 foreach ( $wgImageLimits as $index => $limits ) {
761 $selected = ($index == $this->mImageSize) ? 'selected="selected"' : '';
762 $imageLimitOptions .= "<option value=\"{$index}\" {$selected}>{$limits[0]}ร—{$limits[1]}". wfMsgHtml('unit-pixel') ."</option>\n";
765 $imageThumbOptions = null;
766 $wgOut->addHTML( "{$imageLimitOptions}</select></div>
767 <div><label for='wpThumbSize'>" . wfMsg('thumbsize') . "</label> <select name='wpThumbSize' id='wpThumbSize'>");
768 foreach ( $wgThumbLimits as $index => $size ) {
769 $selected = ($index == $this->mThumbSize) ? 'selected="selected"' : '';
770 $imageThumbOptions .= "<option value=\"{$index}\" {$selected}>{$size}". wfMsgHtml('unit-pixel') ."</option>\n";
772 $wgOut->addHTML( "{$imageThumbOptions}</select></div></fieldset>\n\n");
774 # Date format
776 # Date/Time
779 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'datetime' ) . "</legend>\n" );
781 if ($dateopts) {
782 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'dateformat' ) . "</legend>\n" );
783 $idCnt = 0;
784 $epoch = '20010408091234';
785 foreach($dateopts as $key => $option) {
786 if( $key == MW_DATE_DEFAULT ) {
787 $formatted = wfMsgHtml( 'datedefault' );
788 } else {
789 $formatted = htmlspecialchars( $wgLang->timeanddate( $epoch, false, $key ) );
791 ($key == $this->mDate) ? $checked = ' checked="checked"' : $checked = '';
792 $wgOut->addHTML( "<div><input type='radio' name=\"wpDate\" id=\"wpDate$idCnt\" ".
793 "value=\"$key\"$checked /> <label for=\"wpDate$idCnt\">$formatted</label></div>\n" );
794 $idCnt++;
796 $wgOut->addHTML( "</fieldset>\n" );
799 $nowlocal = $wgLang->time( $now = wfTimestampNow(), true );
800 $nowserver = $wgLang->time( $now, false );
802 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'timezonelegend' ). '</legend><table>' .
803 $this->addRow( wfMsg( 'servertime' ), $nowserver ) .
804 $this->addRow( wfMsg( 'localtime' ), $nowlocal ) .
805 $this->addRow(
806 '<label for="wpHourDiff">' . wfMsg( 'timezoneoffset' ) . '</label>',
807 "<input type='text' name='wpHourDiff' id='wpHourDiff' value=\"" . htmlspecialchars( $this->mHourDiff ) . "\" size='6' />"
808 ) . "<tr><td colspan='2'>
809 <input type='button' value=\"" . wfMsg( 'guesstimezone' ) ."\"
810 onclick='javascript:guessTimezone()' id='guesstimezonebutton' style='display:none;' />
811 </td></tr></table></fieldset>
812 <div class='prefsectiontip'>ยน" . wfMsg( 'timezonetext' ) . "</div>
813 </fieldset>\n\n" );
815 # Editing
817 global $wgLivePreview, $wgUseRCPatrol;
818 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'textboxsize' ) . '</legend>
819 <div>' .
820 wfInputLabel( wfMsg( 'rows' ), 'wpRows', 'wpRows', 3, $this->mRows ) .
821 ' ' .
822 wfInputLabel( wfMsg( 'columns' ), 'wpCols', 'wpCols', 3, $this->mCols ) .
823 "</div>" .
824 $this->getToggles( array(
825 'editsection',
826 'editsectiononrightclick',
827 'editondblclick',
828 'editwidth',
829 'showtoolbar',
830 'previewonfirst',
831 'previewontop',
832 'watchcreations',
833 'watchdefault',
834 'minordefault',
835 'externaleditor',
836 'externaldiff',
837 $wgLivePreview ? 'uselivepreview' : false,
838 $wgUser->isAllowed( 'patrol' ) && $wgUseRCPatrol ? 'autopatrol' : false,
839 'forceeditsummary',
840 ) ) . '</fieldset>'
842 $this->mUsedToggles['autopatrol'] = true; # Don't show this up for users who can't; the handler below is dumb and doesn't know it
844 $wgOut->addHTML( '<fieldset><legend>' . htmlspecialchars(wfMsg('prefs-rc')) . '</legend>' .
845 wfInputLabel( wfMsg( 'recentchangescount' ),
846 'wpRecent', 'wpRecent', 3, $this->mRecent ) .
847 $this->getToggles( array(
848 'hideminor',
849 $wgRCShowWatchingUsers ? 'shownumberswatching' : false,
850 'usenewrc' )
851 ) . '</fieldset>'
854 # Watchlist
855 $wgOut->addHTML( '<fieldset><legend>' . wfMsgHtml( 'prefs-watchlist' ) . '</legend>' );
857 $wgOut->addHTML( wfInputLabel( wfMsg( 'prefs-watchlist-days' ),
858 'wpWatchlistDays', 'wpWatchlistDays', 3, $this->mWatchlistDays ) );
859 $wgOut->addHTML( '<br /><br />' ); # Spacing
860 $wgOut->addHTML( $this->getToggles( array( 'watchlisthideown', 'watchlisthidebots', 'extendwatchlist' ) ) );
861 $wgOut->addHTML( wfInputLabel( wfMsg( 'prefs-watchlist-edits' ),
862 'wpWatchlistEdits', 'wpWatchlistEdits', 3, $this->mWatchlistEdits ) );
864 $wgOut->addHTML( '</fieldset>' );
866 # Search
867 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'searchresultshead' ) . '</legend><table>' .
868 $this->addRow(
869 wfLabel( wfMsg( 'resultsperpage' ), 'wpSearch' ),
870 wfInput( 'wpSearch', 4, $this->mSearch, array( 'id' => 'wpSearch' ) )
872 $this->addRow(
873 wfLabel( wfMsg( 'contextlines' ), 'wpSearchLines' ),
874 wfInput( 'wpSearchLines', 4, $this->mSearchLines, array( 'id' => 'wpSearchLines' ) )
876 $this->addRow(
877 wfLabel( wfMsg( 'contextchars' ), 'wpSearchChars' ),
878 wfInput( 'wpSearchChars', 4, $this->mSearchChars, array( 'id' => 'wpSearchChars' ) )
880 "</table><fieldset><legend>" . wfMsg( 'defaultns' ) . "</legend>$ps</fieldset></fieldset>" );
882 # Misc
884 $wgOut->addHTML('<fieldset><legend>' . wfMsg('prefs-misc') . '</legend>');
885 $wgOut->addHTML( wfInputLabel( wfMsg( 'stubthreshold' ),
886 'wpStubs', 'wpStubs', 6, $this->mStubs ) );
887 $msgUnderline = htmlspecialchars( wfMsg ( 'tog-underline' ) );
888 $msgUnderlinenever = htmlspecialchars( wfMsg ( 'underline-never' ) );
889 $msgUnderlinealways = htmlspecialchars( wfMsg ( 'underline-always' ) );
890 $msgUnderlinedefault = htmlspecialchars( wfMsg ( 'underline-default' ) );
891 $uopt = $wgUser->getOption("underline");
892 $s0 = $uopt == 0 ? ' selected="selected"' : '';
893 $s1 = $uopt == 1 ? ' selected="selected"' : '';
894 $s2 = $uopt == 2 ? ' selected="selected"' : '';
895 $wgOut->addHTML("
896 <div class='toggle'><label for='wpOpunderline'>$msgUnderline</label>
897 <select name='wpOpunderline' id='wpOpunderline'>
898 <option value=\"0\"$s0>$msgUnderlinenever</option>
899 <option value=\"1\"$s1>$msgUnderlinealways</option>
900 <option value=\"2\"$s2>$msgUnderlinedefault</option>
901 </select>
902 </div>
904 foreach ( $togs as $tname ) {
905 if( !array_key_exists( $tname, $this->mUsedToggles ) ) {
906 $wgOut->addHTML( $this->getToggle( $tname ) );
909 $wgOut->addHTML( '</fieldset>' );
911 $token = $wgUser->editToken();
912 $wgOut->addHTML( "
913 <div id='prefsubmit'>
914 <div>
915 <input type='submit' name='wpSaveprefs' class='btnSavePrefs' value=\"" . wfMsgHtml( 'saveprefs' ) . "\" accesskey=\"".
916 wfMsgHtml('accesskey-save')."\" title=\"".wfMsgHtml('tooltip-save')."\" />
917 <input type='submit' name='wpReset' value=\"" . wfMsgHtml( 'resetprefs' ) . "\" />
918 </div>
920 </div>
922 <input type='hidden' name='wpEditToken' value='{$token}' />
923 </div></form>\n" );
925 $wgOut->addWikiText( '<div class="prefcache">' . wfMsg('clearyourcache') . '</div>' );