rm. redundant function
[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 # Clean up the signature a little
231 $this->mNick = Parser::cleanSig( $this->mNick );
232
233 $wgUser->setOption( 'language', $this->mUserLanguage );
234 $wgUser->setOption( 'variant', $this->mUserVariant );
235 $wgUser->setOption( 'nickname', $this->mNick );
236 $wgUser->setOption( 'quickbar', $this->mQuickbar );
237 $wgUser->setOption( 'skin', $this->mSkin );
238 global $wgUseTeX;
239 if( $wgUseTeX ) {
240 $wgUser->setOption( 'math', $this->mMath );
241 }
242 $wgUser->setOption( 'date', $this->validateDate( $this->mDate, 0, 20 ) );
243 $wgUser->setOption( 'searchlimit', $this->validateIntOrNull( $this->mSearch ) );
244 $wgUser->setOption( 'contextlines', $this->validateIntOrNull( $this->mSearchLines ) );
245 $wgUser->setOption( 'contextchars', $this->validateIntOrNull( $this->mSearchChars ) );
246 $wgUser->setOption( 'rclimit', $this->validateIntOrNull( $this->mRecent ) );
247 $wgUser->setOption( 'rows', $this->validateInt( $this->mRows, 4, 1000 ) );
248 $wgUser->setOption( 'cols', $this->validateInt( $this->mCols, 4, 1000 ) );
249 $wgUser->setOption( 'stubthreshold', $this->validateIntOrNull( $this->mStubs ) );
250 $wgUser->setOption( 'timecorrection', $this->validateTimeZone( $this->mHourDiff, -12, 14 ) );
251 $wgUser->setOption( 'imagesize', $this->mImageSize );
252 $wgUser->setOption( 'thumbsize', $this->mThumbSize );
253 $wgUser->setOption( 'underline', $this->validateInt($this->mUnderline, 0, 2) );
254
255 # Set search namespace options
256 foreach( $this->mSearchNs as $i => $value ) {
257 $wgUser->setOption( "searchNs{$i}", $value );
258 }
259
260 if( $wgEnableEmail && $wgEnableUserEmail ) {
261 $wgUser->setOption( 'disablemail', $this->mEmailFlag );
262 }
263
264 # Set user toggles
265 foreach ( $this->mToggles as $tname => $tvalue ) {
266 $wgUser->setOption( $tname, $tvalue );
267 }
268 if (!$wgAuth->updateExternalDB($wgUser)) {
269 $this->mainPrefsForm( wfMsg( 'externaldberror' ) );
270 return;
271 }
272 $wgUser->setCookies();
273 $wgUser->saveSettings();
274
275 $error = false;
276 if( $wgEnableEmail ) {
277 $newadr = $this->mUserEmail;
278 $oldadr = $wgUser->getEmail();
279 if( ($newadr != '') && ($newadr != $oldadr) ) {
280 # the user has supplied a new email address on the login page
281 if( $wgUser->isValidEmailAddr( $newadr ) ) {
282 $wgUser->mEmail = $newadr; # new behaviour: set this new emailaddr from login-page into user database record
283 $wgUser->mEmailAuthenticated = null; # but flag as "dirty" = unauthenticated
284 $wgUser->saveSettings();
285 if ($wgEmailAuthentication) {
286 # Mail a temporary password to the dirty address.
287 # User can come back through the confirmation URL to re-enable email.
288 $result = $wgUser->sendConfirmationMail();
289 if( WikiError::isError( $result ) ) {
290 $error = wfMsg( 'mailerror', htmlspecialchars( $result->getMessage() ) );
291 } else {
292 $error = wfMsg( 'eauthentsent', $wgUser->getName() );
293 }
294 }
295 } else {
296 $error = wfMsg( 'invalidemailaddress' );
297 }
298 } else {
299 $wgUser->setEmail( $this->mUserEmail );
300 $wgUser->setCookies();
301 $wgUser->saveSettings();
302 }
303 }
304
305 if( $needRedirect && $error === false ) {
306 $title =& Title::makeTitle( NS_SPECIAL, "Preferences" );
307 $wgOut->redirect($title->getFullURL('success'));
308 return;
309 }
310
311 $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
312 $po = ParserOptions::newFromUser( $wgUser );
313 $this->mainPrefsForm( $error === false ? 'success' : 'error', $error);
314 }
315
316 /**
317 * @access private
318 */
319 function resetPrefs() {
320 global $wgUser, $wgLang, $wgContLang, $wgAllowRealName;
321
322 $this->mOldpass = $this->mNewpass = $this->mRetypePass = '';
323 $this->mUserEmail = $wgUser->getEmail();
324 $this->mUserEmailAuthenticationtimestamp = $wgUser->getEmailAuthenticationtimestamp();
325 $this->mRealName = ($wgAllowRealName) ? $wgUser->getRealName() : '';
326 $this->mUserLanguage = $wgUser->getOption( 'language' );
327 if( empty( $this->mUserLanguage ) ) {
328 # Quick hack for conversions, where this value is blank
329 global $wgContLanguageCode;
330 $this->mUserLanguage = $wgContLanguageCode;
331 }
332 $this->mUserVariant = $wgUser->getOption( 'variant');
333 $this->mEmailFlag = $wgUser->getOption( 'disablemail' ) == 1 ? 1 : 0;
334 $this->mNick = $wgUser->getOption( 'nickname' );
335
336 $this->mQuickbar = $wgUser->getOption( 'quickbar' );
337 $this->mSkin = Skin::normalizeKey( $wgUser->getOption( 'skin' ) );
338 $this->mMath = $wgUser->getOption( 'math' );
339 $this->mDate = $wgUser->getOption( 'date' );
340 $this->mRows = $wgUser->getOption( 'rows' );
341 $this->mCols = $wgUser->getOption( 'cols' );
342 $this->mStubs = $wgUser->getOption( 'stubthreshold' );
343 $this->mHourDiff = $wgUser->getOption( 'timecorrection' );
344 $this->mSearch = $wgUser->getOption( 'searchlimit' );
345 $this->mSearchLines = $wgUser->getOption( 'contextlines' );
346 $this->mSearchChars = $wgUser->getOption( 'contextchars' );
347 $this->mImageSize = $wgUser->getOption( 'imagesize' );
348 $this->mThumbSize = $wgUser->getOption( 'thumbsize' );
349 $this->mRecent = $wgUser->getOption( 'rclimit' );
350 $this->mUnderline = $wgUser->getOption( 'underline' );
351
352 $togs = $wgLang->getUserToggles();
353 foreach ( $togs as $tname ) {
354 $ttext = wfMsg('tog-'.$tname);
355 $this->mToggles[$tname] = $wgUser->getOption( $tname );
356 }
357
358 $namespaces = $wgContLang->getNamespaces();
359 foreach ( $namespaces as $i => $namespace ) {
360 if ( $i >= NS_MAIN ) {
361 $this->mSearchNs[$i] = $wgUser->getOption( 'searchNs'.$i );
362 }
363 }
364 }
365
366 /**
367 * @access private
368 */
369 function namespacesCheckboxes() {
370 global $wgContLang, $wgUser;
371
372 # Determine namespace checkboxes
373 $namespaces = $wgContLang->getNamespaces();
374 $r1 = null;
375
376 foreach ( $namespaces as $i => $name ) {
377 if ($i < 0)
378 continue;
379 $checked = $this->mSearchNs[$i] ? "checked='checked'" : '';
380 $name = str_replace( '_', ' ', $namespaces[$i] );
381
382 if ( empty($name) )
383 $name = wfMsg( 'blanknamespace' );
384
385 $r1 .= "<input type='checkbox' value='1' name='wpNs$i' id='wpNs$i' {$checked}/> <label for='wpNs$i'>{$name}</label><br />\n";
386 }
387 return $r1;
388 }
389
390
391 function getToggle( $tname, $trailer = false, $disabled = false ) {
392 global $wgUser, $wgLang;
393
394 $this->mUsedToggles[$tname] = true;
395 $ttext = $wgLang->getUserToggle( $tname );
396
397 $checked = $wgUser->getOption( $tname ) == 1 ? ' checked="checked"' : '';
398 $disabled = $disabled ? ' disabled="disabled"' : '';
399 $trailer = $trailer ? $trailer : '';
400 return "<div class='toggle'><input type='checkbox' value='1' id=\"$tname\" name=\"wpOp$tname\"$checked$disabled />" .
401 " <span class='toggletext'><label for=\"$tname\">$ttext</label>$trailer</span></div>\n";
402 }
403
404 function getToggles( $items ) {
405 $out = "";
406 foreach( $items as $item ) {
407 if( $item === false )
408 continue;
409 if( is_array( $item ) ) {
410 list( $key, $trailer ) = $item;
411 } else {
412 $key = $item;
413 $trailer = false;
414 }
415 $out .= $this->getToggle( $key, $trailer );
416 }
417 return $out;
418 }
419
420 function addRow($td1, $td2) {
421 return "<tr><td align='right'>$td1</td><td align='left'>$td2</td></tr>";
422 }
423
424 /**
425 * @access private
426 */
427 function mainPrefsForm( $status , $message = '' ) {
428 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgValidSkinNames;
429 global $wgAllowRealName, $wgImageLimits, $wgThumbLimits;
430 global $wgDisableLangConversion;
431 global $wgEnotifWatchlist, $wgEnotifUserTalk,$wgEnotifMinorEdits;
432 global $wgRCShowWatchingUsers, $wgEnotifRevealEditorAddress;
433 global $wgEnableEmail, $wgEnableUserEmail, $wgEmailAuthentication;
434 global $wgContLanguageCode, $wgDefaultSkin, $wgSkipSkins;
435
436 $wgOut->setPageTitle( wfMsg( 'preferences' ) );
437 $wgOut->setArticleRelated( false );
438 $wgOut->setRobotpolicy( 'noindex,nofollow' );
439
440 if ( $this->mSuccess || 'success' == $status ) {
441 $wgOut->addWikitext( '<div class="successbox"><strong>'. wfMsg( 'savedprefs' ) . '</strong></div>' );
442 } else if ( 'error' == $status ) {
443 $wgOut->addWikitext( '<div class="errorbox"><strong>' . $message . '</strong></div>' );
444 } else if ( '' != $status ) {
445 $wgOut->addWikitext( $message . "\n----" );
446 }
447
448 $qbs = $wgLang->getQuickbarSettings();
449 $skinNames = $wgLang->getSkinNames();
450 $mathopts = $wgLang->getMathNames();
451 $dateopts = $wgLang->getDateFormats();
452 $togs = $wgLang->getUserToggles();
453
454 $titleObj = Title::makeTitle( NS_SPECIAL, 'Preferences' );
455 $action = $titleObj->escapeLocalURL();
456
457 # Pre-expire some toggles so they won't show if disabled
458 $this->mUsedToggles[ 'shownumberswatching' ] = true;
459 $this->mUsedToggles[ 'showupdated' ] = true;
460 $this->mUsedToggles[ 'enotifwatchlistpages' ] = true;
461 $this->mUsedToggles[ 'enotifusertalkpages' ] = true;
462 $this->mUsedToggles[ 'enotifminoredits' ] = true;
463 $this->mUsedToggles[ 'enotifrevealaddr' ] = true;
464
465 # Enotif
466 # <FIXME>
467 $this->mUserEmail = htmlspecialchars( $this->mUserEmail );
468 $this->mRealName = htmlspecialchars( $this->mRealName );
469 $rawNick = $this->mNick;
470 $this->mNick = htmlspecialchars( $this->mNick );
471 if ( !$this->mEmailFlag ) { $emfc = 'checked="checked"'; }
472 else { $emfc = ''; }
473
474
475 if ($wgEmailAuthentication && ($this->mUserEmail != '') ) {
476 if( $wgUser->getEmailAuthenticationTimestamp() ) {
477 $emailauthenticated = wfMsg('emailauthenticated',$wgLang->timeanddate($wgUser->getEmailAuthenticationTimestamp(), true ) ).'<br />';
478 $disableEmailPrefs = false;
479 } else {
480 $disableEmailPrefs = true;
481 $skin = $wgUser->getSkin();
482 $emailauthenticated = wfMsg('emailnotauthenticated').'<br />' .
483 $skin->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Confirmemail' ),
484 wfMsg( 'emailconfirmlink' ) );
485 }
486 } else {
487 $emailauthenticated = '';
488 $disableEmailPrefs = false;
489 }
490
491 if ($this->mUserEmail == '') {
492 $emailauthenticated = wfMsg( 'noemailprefs' );
493 }
494
495 $ps = $this->namespacesCheckboxes();
496
497 $enotifwatchlistpages = ($wgEnotifWatchlist) ? $this->getToggle( 'enotifwatchlistpages', false, $disableEmailPrefs ) : '';
498 $enotifusertalkpages = ($wgEnotifUserTalk) ? $this->getToggle( 'enotifusertalkpages', false, $disableEmailPrefs ) : '';
499 $enotifminoredits = ($wgEnotifWatchlist && $wgEnotifMinorEdits) ? $this->getToggle( 'enotifminoredits', false, $disableEmailPrefs ) : '';
500 $enotifrevealaddr = (($wgEnotifWatchlist || $wgEnotifUserTalk) && $wgEnotifRevealEditorAddress) ? $this->getToggle( 'enotifrevealaddr', false, $disableEmailPrefs ) : '';
501 $prefs_help_email_enotif = ( $wgEnotifWatchlist || $wgEnotifUserTalk) ? ' ' . wfMsg('prefs-help-email-enotif') : '';
502 $prefs_help_realname = '';
503
504 # </FIXME>
505
506 $wgOut->addHTML( "<form action=\"$action\" method='post'>" );
507 $wgOut->addHTML( "<div id='preferences'>" );
508
509 # User data
510 #
511
512 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg('prefs-personal') . "</legend>\n<table>\n");
513
514 $wgOut->addHTML(
515 $this->addRow(
516 wfMsg( 'username'),
517 $wgUser->getName()
518 )
519 );
520
521 $wgOut->addHTML(
522 $this->addRow(
523 wfMsg( 'uid' ),
524 $wgUser->getID()
525 )
526 );
527
528
529 if ($wgAllowRealName) {
530 $wgOut->addHTML(
531 $this->addRow(
532 '<label for="wpRealName">' . wfMsg('yourrealname') . '</label>',
533 "<input type='text' name='wpRealName' id='wpRealName' value=\"{$this->mRealName}\" size='25' />"
534 )
535 );
536 }
537 if ($wgEnableEmail) {
538 $wgOut->addHTML(
539 $this->addRow(
540 '<label for="wpUserEmail">' . wfMsg( 'youremail' ) . '</label>',
541 "<input type='text' name='wpUserEmail' id='wpUserEmail' value=\"{$this->mUserEmail}\" size='25' />"
542 )
543 );
544 }
545
546 global $wgParser;
547 if( !empty( $this->mToggles['fancysig'] ) &&
548 false === $wgParser->validateSig( $rawNick ) ) {
549 $invalidSig = $this->addRow(
550 '&nbsp;',
551 '<span class="error">' . wfMsgHtml( 'badsig' ) . '<span>'
552 );
553 } else {
554 $invalidSig = '';
555 }
556
557 $wgOut->addHTML(
558 $this->addRow(
559 '<label for="wpNick">' . wfMsg( 'yournick' ) . '</label>',
560 "<input type='text' name='wpNick' id='wpNick' value=\"{$this->mNick}\" size='25' />"
561 ) .
562 $invalidSig .
563 # FIXME: The <input> part should be where the &nbsp; is, getToggle() needs
564 # to be changed to out return its output in two parts. -ævar
565 $this->addRow(
566 '&nbsp;',
567 $this->getToggle( 'fancysig' )
568 )
569 );
570
571 /**
572 * Make sure the site language is in the list; a custom language code
573 * might not have a defined name...
574 */
575 $languages = $wgLang->getLanguageNames();
576 if( !array_key_exists( $wgContLanguageCode, $languages ) ) {
577 $languages[$wgContLanguageCode] = $wgContLanguageCode;
578 }
579 ksort( $languages );
580
581 /**
582 * If a bogus value is set, default to the content language.
583 * Otherwise, no default is selected and the user ends up
584 * with an Afrikaans interface since it's first in the list.
585 */
586 $selectedLang = isset( $languages[$this->mUserLanguage] ) ? $this->mUserLanguage : $wgContLanguageCode;
587 $selbox = null;
588 foreach($languages as $code => $name) {
589 global $IP;
590 /* only add languages that have a file */
591 $langfile="$IP/languages/Language".str_replace('-', '_', ucfirst($code)).".php";
592 if(file_exists($langfile) || $code == $wgContLanguageCode) {
593 $sel = ($code == $selectedLang)? ' selected="selected"' : '';
594 $selbox .= "<option value=\"$code\"$sel>$code - $name</option>\n";
595 }
596 }
597 $wgOut->addHTML(
598 $this->addRow(
599 '<label for="wpUserLanguage">' . wfMsg('yourlanguage') . '</label>',
600 "<select name='wpUserLanguage' id='wpUserLanguage'>$selbox</select>"
601 )
602 );
603
604 /* see if there are multiple language variants to choose from*/
605 if(!$wgDisableLangConversion) {
606 $variants = $wgContLang->getVariants();
607 $variantArray = array();
608
609 foreach($variants as $v) {
610 $v = str_replace( '_', '-', strtolower($v));
611 if( array_key_exists( $v, $languages ) ) {
612 // If it doesn't have a name, we'll pretend it doesn't exist
613 $variantArray[$v] = $languages[$v];
614 }
615 }
616
617 $selbox = null;
618 foreach($variantArray as $code => $name) {
619 $sel = $code == $this->mUserVariant ? 'selected="selected"' : '';
620 $selbox .= "<option value=\"$code\" $sel>$code - $name</option>";
621 }
622
623 if(count($variantArray) > 1) {
624 $wgOut->addHtml(
625 $this->addRow( wfMsg( 'yourvariant' ), "<select name='wpUserVariant'>$selbox</select>" )
626 );
627 }
628 }
629 $wgOut->addHTML('</table>');
630
631 # Password
632 $this->mOldpass = htmlspecialchars( $this->mOldpass );
633 $this->mNewpass = htmlspecialchars( $this->mNewpass );
634 $this->mRetypePass = htmlspecialchars( $this->mRetypePass );
635
636 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'changepassword' ) . '</legend><table>');
637 $wgOut->addHTML(
638 $this->addRow(
639 '<label for="wpOldpass">' . wfMsg( 'oldpassword' ) . '</label>',
640 "<input type='password' name='wpOldpass' id='wpOldpass' value=\"{$this->mOldpass}\" size='20' />"
641 ) .
642 $this->addRow(
643 '<label for="wpNewpass">' . wfMsg( 'newpassword' ) . '</label>',
644 "<input type='password' name='wpNewpass' id='wpNewpass' value=\"{$this->mNewpass}\" size='20' />"
645 ) .
646 $this->addRow(
647 '<label for="wpRetypePass">' . wfMsg( 'retypenew' ) . '</label>',
648 "<input type='password' name='wpRetypePass' id='wpRetypePass' value=\"{$this->mRetypePass}\" size='20' />"
649 ) .
650 "</table>\n" .
651 $this->getToggle( "rememberpassword" ) . "</fieldset>\n\n" );
652
653 # <FIXME>
654 # Enotif
655 if ($wgEnableEmail) {
656 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'email' ) . '</legend>' );
657 $wgOut->addHTML(
658 $emailauthenticated.
659 $enotifrevealaddr.
660 $enotifwatchlistpages.
661 $enotifusertalkpages.
662 $enotifminoredits );
663 if ($wgEnableUserEmail) {
664 $emf = wfMsg( 'allowemail' );
665 $disabled = $disableEmailPrefs ? ' disabled="disabled"' : '';
666 $wgOut->addHTML(
667 "<div><input type='checkbox' $emfc $disabled value='1' name='wpEmailFlag' id='wpEmailFlag' /> <label for='wpEmailFlag'>$emf</label></div>" );
668 }
669
670 $wgOut->addHTML( '</fieldset>' );
671 }
672 # </FIXME>
673
674 if ($wgAllowRealName || $wgEnableEmail) {
675 $wgOut->addHTML("<div class='prefsectiontip'>");
676 $rn = $wgAllowRealName ? wfMsg('prefs-help-realname') : '';
677 $em = $wgEnableEmail ? '<br />' . wfMsg('prefs-help-email') : '';
678 $wgOut->addHTML( $rn . $em . '</div>');
679 }
680
681 $wgOut->addHTML( '</fieldset>' );
682
683 # Quickbar
684 #
685 if ($this->mSkin == 'cologneblue' || $this->mSkin == 'standard') {
686 $wgOut->addHtml( "<fieldset>\n<legend>" . wfMsg( 'qbsettings' ) . "</legend>\n" );
687 for ( $i = 0; $i < count( $qbs ); ++$i ) {
688 if ( $i == $this->mQuickbar ) { $checked = ' checked="checked"'; }
689 else { $checked = ""; }
690 $wgOut->addHTML( "<div><label><input type='radio' name='wpQuickbar' value=\"$i\"$checked />{$qbs[$i]}</label></div>\n" );
691 }
692 $wgOut->addHtml( "</fieldset>\n\n" );
693 } else {
694 # Need to output a hidden option even if the relevant skin is not in use,
695 # otherwise the preference will get reset to 0 on submit
696 $wgOut->addHTML( "<input type='hidden' name='wpQuickbar' value='{$this->mQuickbar}' />" );
697 }
698
699 # Skin
700 #
701 $wgOut->addHTML( "<fieldset>\n<legend>\n" . wfMsg('skin') . "</legend>\n" );
702 $mptitle = Title::newMainPage();
703 $previewtext = wfMsg('skinpreview');
704 # Only show members of $wgValidSkinNames rather than
705 # $skinNames (skins is all skin names from Language.php)
706 foreach ($wgValidSkinNames as $skinkey => $skinname ) {
707 if ( in_array( $skinkey, $wgSkipSkins ) ) {
708 continue;
709 }
710 $checked = $skinkey == $this->mSkin ? ' checked="checked"' : '';
711 $sn = isset( $skinNames[$skinkey] ) ? $skinNames[$skinkey] : $skinname;
712
713 $mplink = htmlspecialchars($mptitle->getLocalURL("useskin=$skinkey"));
714 $previewlink = "<a target='_blank' href=\"$mplink\">$previewtext</a>";
715 if( $skinkey == $wgDefaultSkin )
716 $sn .= ' (' . wfMsg( 'default' ) . ')';
717 $wgOut->addHTML( "<input type='radio' name='wpSkin' id=\"wpSkin$skinkey\" value=\"$skinkey\"$checked /> <label for=\"wpSkin$skinkey\">{$sn}</label> $previewlink<br/>\n" );
718 }
719 $wgOut->addHTML( "</fieldset>\n\n" );
720
721 # Math
722 #
723 global $wgUseTeX;
724 if( $wgUseTeX ) {
725 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg('math') . '</legend>' );
726 foreach ( $mathopts as $k => $v ) {
727 $checked = $k == $this->mMath ? ' checked="checked"' : '';
728 $wgOut->addHTML( "<div><label><input type='radio' name='wpMath' value=\"$k\"$checked /> ".wfMsg($v)."</label></div>\n" );
729 }
730 $wgOut->addHTML( "</fieldset>\n\n" );
731 }
732
733 # Files
734 #
735 $wgOut->addHTML("<fieldset>
736 <legend>" . wfMsg( 'files' ) . "</legend>
737 <div><label for='wpImageSize'>" . wfMsg('imagemaxsize') . "</label> <select id='wpImageSize' name='wpImageSize'>");
738
739 $imageLimitOptions = null;
740 foreach ( $wgImageLimits as $index => $limits ) {
741 $selected = ($index == $this->mImageSize) ? 'selected="selected"' : '';
742 $imageLimitOptions .= "<option value=\"{$index}\" {$selected}>{$limits[0]}×{$limits[1]}". wfMsgHtml('unit-pixel') ."</option>\n";
743 }
744
745 $imageThumbOptions = null;
746 $wgOut->addHTML( "{$imageLimitOptions}</select></div>
747 <div><label for='wpThumbSize'>" . wfMsg('thumbsize') . "</label> <select name='wpThumbSize' id='wpThumbSize'>");
748 foreach ( $wgThumbLimits as $index => $size ) {
749 $selected = ($index == $this->mThumbSize) ? 'selected="selected"' : '';
750 $imageThumbOptions .= "<option value=\"{$index}\" {$selected}>{$size}". wfMsgHtml('unit-pixel') ."</option>\n";
751 }
752 $wgOut->addHTML( "{$imageThumbOptions}</select></div></fieldset>\n\n");
753
754 # Date format
755 #
756 # Date/Time
757 #
758
759 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'datetime' ) . "</legend>\n" );
760
761 if ($dateopts) {
762 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'dateformat' ) . "</legend>\n" );
763 $idCnt = 0;
764 $epoch = '20010115161234';
765 foreach($dateopts as $key => $option) {
766 if( $key == MW_DATE_DEFAULT ) {
767 $formatted = wfMsgHtml( 'datedefault' );
768 } else {
769 $formatted = htmlspecialchars( $wgLang->timeanddate( $epoch, false, $key ) );
770 }
771 ($key == $this->mDate) ? $checked = ' checked="checked"' : $checked = '';
772 $wgOut->addHTML( "<div><input type='radio' name=\"wpDate\" id=\"wpDate$idCnt\" ".
773 "value=\"$key\"$checked /> <label for=\"wpDate$idCnt\">$formatted</label></div>\n" );
774 $idCnt++;
775 }
776 $wgOut->addHTML( "</fieldset>\n" );
777 }
778
779 $nowlocal = $wgLang->time( $now = wfTimestampNow(), true );
780 $nowserver = $wgLang->time( $now, false );
781
782 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'timezonelegend' ). '</legend><table>' .
783 $this->addRow( wfMsg( 'servertime' ), $nowserver ) .
784 $this->addRow( wfMsg( 'localtime' ), $nowlocal ) .
785 $this->addRow(
786 '<label for="wpHourDiff">' . wfMsg( 'timezoneoffset' ) . '</label>',
787 "<input type='text' name='wpHourDiff' id='wpHourDiff' value=\"" . htmlspecialchars( $this->mHourDiff ) . "\" size='6' />"
788 ) . "<tr><td colspan='2'>
789 <input type='button' value=\"" . wfMsg( 'guesstimezone' ) ."\"
790 onclick='javascript:guessTimezone()' id='guesstimezonebutton' style='display:none;' />
791 </td></tr></table></fieldset>
792 <div class='prefsectiontip'>¹" . wfMsg( 'timezonetext' ) . "</div>
793 </fieldset>\n\n" );
794
795 # Editing
796 #
797 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'textboxsize' ) . '</legend>
798 <div>
799 <label for="wpRows">' . wfMsg( 'rows' ) . "</label> <input type='text' name='wpRows' id='wpRows' value=\"{$this->mRows}\" size='3' />
800 <label for='wpCols'>" . wfMsg( 'columns' ) . "</label> <input type='text' name='wpCols' id='wpCols' value=\"{$this->mCols}\" size='3' />
801 </div>" .
802 $this->getToggles( array(
803 'editsection',
804 'editsectiononrightclick',
805 'editondblclick',
806 'editwidth',
807 'showtoolbar',
808 'previewonfirst',
809 'previewontop',
810 'watchdefault',
811 'minordefault',
812 'externaleditor',
813 'externaldiff' )
814 ) . '</fieldset>'
815 );
816
817 $wgOut->addHTML( '<fieldset><legend>' . htmlspecialchars(wfMsg('prefs-rc')) . '</legend>' .
818 '<label for="wpRecent">' . wfMsg ( 'recentchangescount' ) .
819 "</label> <input type='text' name='wpRecent' id='wpRecent' value=\"$this->mRecent\" size='3' />" .
820 $this->getToggles( array(
821 'hideminor',
822 $wgRCShowWatchingUsers ? 'shownumberswatching' : false,
823 'usenewrc' )
824 ) . '</fieldset>'
825 );
826
827 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'searchresultshead' ) . '</legend><table>' .
828 $this->addRow(
829 '<label for="wpSearch">' . wfMsg( 'resultsperpage' ) . '</label>',
830 "<input type='text' name='wpSearch' id='wpSearch' value=\"$this->mSearch\" size='4' />"
831 ) .
832 $this->addRow(
833 '<label for="wpSearchLines">' . wfMsg( 'contextlines' ) . '</label>',
834 "<input type='text' name='wpSearchLines' id='wpSearchLines' value=\"$this->mSearchLines\" size='4' />"
835 ) .
836 $this->addRow(
837 '<label for="wpSearchChars">' . wfMsg( 'contextchars' ) . '</label>',
838 "<input type='text' name='wpSearchChars' id='wpSearchChars' value=\"$this->mSearchChars\" size='4' />"
839 ) .
840 "</table><fieldset><legend>" . wfMsg( 'defaultns' ) . "</legend>$ps</fieldset></fieldset>" );
841
842 # Misc
843 #
844 $wgOut->addHTML('<fieldset><legend>' . wfMsg('prefs-misc') . '</legend>');
845 $wgOut->addHTML(
846 '<label for="wpStubs">' . htmlspecialchars ( wfMsg ( 'stubthreshold' ) ) . '</label>' .
847 " <input type='text' name='wpStubs' id='wpStubs' value=\"$this->mStubs\" size='6' />"
848 );
849 $msgUnderline = htmlspecialchars( wfMsg ( 'tog-underline' ) );
850 $msgUnderlinenever = htmlspecialchars( wfMsg ( 'underline-never' ) );
851 $msgUnderlinealways = htmlspecialchars( wfMsg ( 'underline-always' ) );
852 $msgUnderlinedefault = htmlspecialchars( wfMsg ( 'underline-default' ) );
853 $uopt = $wgUser->getOption("underline");
854 $s0 = $uopt == 0 ? ' selected="selected"' : '';
855 $s1 = $uopt == 1 ? ' selected="selected"' : '';
856 $s2 = $uopt == 2 ? ' selected="selected"' : '';
857 $wgOut->addHTML("
858 <div class='toggle'><label for='wpOpunderline'>$msgUnderline</label>
859 <select name='wpOpunderline' id='wpOpunderline'>
860 <option value=\"0\"$s0>$msgUnderlinenever</option>
861 <option value=\"1\"$s1>$msgUnderlinealways</option>
862 <option value=\"2\"$s2>$msgUnderlinedefault</option>
863 </select>
864 </div>
865 ");
866 foreach ( $togs as $tname ) {
867 if( !array_key_exists( $tname, $this->mUsedToggles ) ) {
868 $wgOut->addHTML( $this->getToggle( $tname ) );
869 }
870 }
871 $wgOut->addHTML( '</fieldset>' );
872
873 $token = $wgUser->editToken();
874 $wgOut->addHTML( "
875 <div id='prefsubmit'>
876 <div>
877 <input type='submit' name='wpSaveprefs' class='btnSavePrefs' value=\"" . wfMsgHtml( 'saveprefs' ) . "\" accesskey=\"".
878 wfMsgHtml('accesskey-save')."\" title=\"".wfMsgHtml('tooltip-save')."\" />
879 <input type='submit' name='wpReset' value=\"" . wfMsgHtml( 'resetprefs' ) . "\" />
880 </div>
881
882 </div>
883
884 <input type='hidden' name='wpEditToken' value='{$token}' />
885 </div></form>\n" );
886
887 $wgOut->addWikiText( '<div class="prefcache">' . wfMsg('clearyourcache') . '</div>' );
888
889 }
890 }
891 ?>