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