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