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