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