fix whitespace fixes
[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, $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;
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 $this->mUsedToggles[ 'uselivepreview' ] = true;
468
469 # Enotif
470 # <FIXME>
471 $this->mUserEmail = htmlspecialchars( $this->mUserEmail );
472 $this->mRealName = htmlspecialchars( $this->mRealName );
473 $rawNick = $this->mNick;
474 $this->mNick = htmlspecialchars( $this->mNick );
475 if ( !$this->mEmailFlag ) { $emfc = 'checked="checked"'; }
476 else { $emfc = ''; }
477
478
479 if ($wgEmailAuthentication && ($this->mUserEmail != '') ) {
480 if( $wgUser->getEmailAuthenticationTimestamp() ) {
481 $emailauthenticated = wfMsg('emailauthenticated',$wgLang->timeanddate($wgUser->getEmailAuthenticationTimestamp(), true ) ).'<br />';
482 $disableEmailPrefs = false;
483 } else {
484 $disableEmailPrefs = true;
485 $skin = $wgUser->getSkin();
486 $emailauthenticated = wfMsg('emailnotauthenticated').'<br />' .
487 $skin->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Confirmemail' ),
488 wfMsg( 'emailconfirmlink' ) );
489 }
490 } else {
491 $emailauthenticated = '';
492 $disableEmailPrefs = false;
493 }
494
495 if ($this->mUserEmail == '') {
496 $emailauthenticated = wfMsg( 'noemailprefs' );
497 }
498
499 $ps = $this->namespacesCheckboxes();
500
501 $enotifwatchlistpages = ($wgEnotifWatchlist) ? $this->getToggle( 'enotifwatchlistpages', false, $disableEmailPrefs ) : '';
502 $enotifusertalkpages = ($wgEnotifUserTalk) ? $this->getToggle( 'enotifusertalkpages', false, $disableEmailPrefs ) : '';
503 $enotifminoredits = ($wgEnotifWatchlist && $wgEnotifMinorEdits) ? $this->getToggle( 'enotifminoredits', false, $disableEmailPrefs ) : '';
504 $enotifrevealaddr = (($wgEnotifWatchlist || $wgEnotifUserTalk) && $wgEnotifRevealEditorAddress) ? $this->getToggle( 'enotifrevealaddr', false, $disableEmailPrefs ) : '';
505 $prefs_help_email_enotif = ( $wgEnotifWatchlist || $wgEnotifUserTalk) ? ' ' . wfMsg('prefs-help-email-enotif') : '';
506 $prefs_help_realname = '';
507
508 # </FIXME>
509
510 $wgOut->addHTML( "<form action=\"$action\" method='post'>" );
511 $wgOut->addHTML( "<div id='preferences'>" );
512
513 # User data
514 #
515
516 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg('prefs-personal') . "</legend>\n<table>\n");
517
518 $wgOut->addHTML(
519 $this->addRow(
520 wfMsg( 'username'),
521 $wgUser->getName()
522 )
523 );
524
525 $wgOut->addHTML(
526 $this->addRow(
527 wfMsg( 'uid' ),
528 $wgUser->getID()
529 )
530 );
531
532
533 if ($wgAllowRealName) {
534 $wgOut->addHTML(
535 $this->addRow(
536 '<label for="wpRealName">' . wfMsg('yourrealname') . '</label>',
537 "<input type='text' name='wpRealName' id='wpRealName' value=\"{$this->mRealName}\" size='25' />"
538 )
539 );
540 }
541 if ($wgEnableEmail) {
542 $wgOut->addHTML(
543 $this->addRow(
544 '<label for="wpUserEmail">' . wfMsg( 'youremail' ) . '</label>',
545 "<input type='text' name='wpUserEmail' id='wpUserEmail' value=\"{$this->mUserEmail}\" size='25' />"
546 )
547 );
548 }
549
550 global $wgParser;
551 if( !empty( $this->mToggles['fancysig'] ) &&
552 false === $wgParser->validateSig( $rawNick ) ) {
553 $invalidSig = $this->addRow(
554 '&nbsp;',
555 '<span class="error">' . wfMsgHtml( 'badsig' ) . '<span>'
556 );
557 } else {
558 $invalidSig = '';
559 }
560
561 $wgOut->addHTML(
562 $this->addRow(
563 '<label for="wpNick">' . wfMsg( 'yournick' ) . '</label>',
564 "<input type='text' name='wpNick' id='wpNick' value=\"{$this->mNick}\" size='25' />"
565 ) .
566 $invalidSig .
567 # FIXME: The <input> part should be where the &nbsp; is, getToggle() needs
568 # to be changed to out return its output in two parts. -ævar
569 $this->addRow(
570 '&nbsp;',
571 $this->getToggle( 'fancysig' )
572 )
573 );
574
575 /**
576 * Make sure the site language is in the list; a custom language code
577 * might not have a defined name...
578 */
579 $languages = $wgLang->getLanguageNames();
580 if( !array_key_exists( $wgContLanguageCode, $languages ) ) {
581 $languages[$wgContLanguageCode] = $wgContLanguageCode;
582 }
583 ksort( $languages );
584
585 /**
586 * If a bogus value is set, default to the content language.
587 * Otherwise, no default is selected and the user ends up
588 * with an Afrikaans interface since it's first in the list.
589 */
590 $selectedLang = isset( $languages[$this->mUserLanguage] ) ? $this->mUserLanguage : $wgContLanguageCode;
591 $selbox = null;
592 foreach($languages as $code => $name) {
593 global $IP;
594 /* only add languages that have a file */
595 $langfile="$IP/languages/Language".str_replace('-', '_', ucfirst($code)).".php";
596 if(file_exists($langfile) || $code == $wgContLanguageCode) {
597 $sel = ($code == $selectedLang)? ' selected="selected"' : '';
598 $selbox .= "<option value=\"$code\"$sel>$code - $name</option>\n";
599 }
600 }
601 $wgOut->addHTML(
602 $this->addRow(
603 '<label for="wpUserLanguage">' . wfMsg('yourlanguage') . '</label>',
604 "<select name='wpUserLanguage' id='wpUserLanguage'>$selbox</select>"
605 )
606 );
607
608 /* see if there are multiple language variants to choose from*/
609 if(!$wgDisableLangConversion) {
610 $variants = $wgContLang->getVariants();
611 $variantArray = array();
612
613 foreach($variants as $v) {
614 $v = str_replace( '_', '-', strtolower($v));
615 if( array_key_exists( $v, $languages ) ) {
616 // If it doesn't have a name, we'll pretend it doesn't exist
617 $variantArray[$v] = $languages[$v];
618 }
619 }
620
621 $selbox = null;
622 foreach($variantArray as $code => $name) {
623 $sel = $code == $this->mUserVariant ? 'selected="selected"' : '';
624 $selbox .= "<option value=\"$code\" $sel>$code - $name</option>";
625 }
626
627 if(count($variantArray) > 1) {
628 $wgOut->addHtml(
629 $this->addRow( wfMsg( 'yourvariant' ), "<select name='wpUserVariant'>$selbox</select>" )
630 );
631 }
632 }
633 $wgOut->addHTML('</table>');
634
635 # Password
636 $this->mOldpass = htmlspecialchars( $this->mOldpass );
637 $this->mNewpass = htmlspecialchars( $this->mNewpass );
638 $this->mRetypePass = htmlspecialchars( $this->mRetypePass );
639
640 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'changepassword' ) . '</legend><table>');
641 $wgOut->addHTML(
642 $this->addRow(
643 '<label for="wpOldpass">' . wfMsg( 'oldpassword' ) . '</label>',
644 "<input type='password' name='wpOldpass' id='wpOldpass' value=\"{$this->mOldpass}\" size='20' />"
645 ) .
646 $this->addRow(
647 '<label for="wpNewpass">' . wfMsg( 'newpassword' ) . '</label>',
648 "<input type='password' name='wpNewpass' id='wpNewpass' value=\"{$this->mNewpass}\" size='20' />"
649 ) .
650 $this->addRow(
651 '<label for="wpRetypePass">' . wfMsg( 'retypenew' ) . '</label>',
652 "<input type='password' name='wpRetypePass' id='wpRetypePass' value=\"{$this->mRetypePass}\" size='20' />"
653 ) .
654 "</table>\n" .
655 $this->getToggle( "rememberpassword" ) . "</fieldset>\n\n" );
656
657 # <FIXME>
658 # Enotif
659 if ($wgEnableEmail) {
660 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'email' ) . '</legend>' );
661 $wgOut->addHTML(
662 $emailauthenticated.
663 $enotifrevealaddr.
664 $enotifwatchlistpages.
665 $enotifusertalkpages.
666 $enotifminoredits );
667 if ($wgEnableUserEmail) {
668 $emf = wfMsg( 'allowemail' );
669 $disabled = $disableEmailPrefs ? ' disabled="disabled"' : '';
670 $wgOut->addHTML(
671 "<div><input type='checkbox' $emfc $disabled value='1' name='wpEmailFlag' id='wpEmailFlag' /> <label for='wpEmailFlag'>$emf</label></div>" );
672 }
673
674 $wgOut->addHTML( '</fieldset>' );
675 }
676 # </FIXME>
677
678 if ($wgAllowRealName || $wgEnableEmail) {
679 $wgOut->addHTML("<div class='prefsectiontip'>");
680 $rn = $wgAllowRealName ? wfMsg('prefs-help-realname') : '';
681 $em = $wgEnableEmail ? '<br />' . wfMsg('prefs-help-email') : '';
682 $wgOut->addHTML( $rn . $em . '</div>');
683 }
684
685 $wgOut->addHTML( '</fieldset>' );
686
687 # Quickbar
688 #
689 if ($this->mSkin == 'cologneblue' || $this->mSkin == 'standard') {
690 $wgOut->addHtml( "<fieldset>\n<legend>" . wfMsg( 'qbsettings' ) . "</legend>\n" );
691 for ( $i = 0; $i < count( $qbs ); ++$i ) {
692 if ( $i == $this->mQuickbar ) { $checked = ' checked="checked"'; }
693 else { $checked = ""; }
694 $wgOut->addHTML( "<div><label><input type='radio' name='wpQuickbar' value=\"$i\"$checked />{$qbs[$i]}</label></div>\n" );
695 }
696 $wgOut->addHtml( "</fieldset>\n\n" );
697 } else {
698 # Need to output a hidden option even if the relevant skin is not in use,
699 # otherwise the preference will get reset to 0 on submit
700 $wgOut->addHTML( "<input type='hidden' name='wpQuickbar' value='{$this->mQuickbar}' />" );
701 }
702
703 # Skin
704 #
705 $wgOut->addHTML( "<fieldset>\n<legend>\n" . wfMsg('skin') . "</legend>\n" );
706 $mptitle = Title::newMainPage();
707 $previewtext = wfMsg('skinpreview');
708 # Only show members of $wgValidSkinNames rather than
709 # $skinNames (skins is all skin names from Language.php)
710 foreach ($wgValidSkinNames as $skinkey => $skinname ) {
711 if ( in_array( $skinkey, $wgSkipSkins ) ) {
712 continue;
713 }
714 $checked = $skinkey == $this->mSkin ? ' checked="checked"' : '';
715 $sn = isset( $skinNames[$skinkey] ) ? $skinNames[$skinkey] : $skinname;
716
717 $mplink = htmlspecialchars($mptitle->getLocalURL("useskin=$skinkey"));
718 $previewlink = "<a target='_blank' href=\"$mplink\">$previewtext</a>";
719 if( $skinkey == $wgDefaultSkin )
720 $sn .= ' (' . wfMsg( 'default' ) . ')';
721 $wgOut->addHTML( "<input type='radio' name='wpSkin' id=\"wpSkin$skinkey\" value=\"$skinkey\"$checked /> <label for=\"wpSkin$skinkey\">{$sn}</label> $previewlink<br/>\n" );
722 }
723 $wgOut->addHTML( "</fieldset>\n\n" );
724
725 # Math
726 #
727 global $wgUseTeX;
728 if( $wgUseTeX ) {
729 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg('math') . '</legend>' );
730 foreach ( $mathopts as $k => $v ) {
731 $checked = $k == $this->mMath ? ' checked="checked"' : '';
732 $wgOut->addHTML( "<div><label><input type='radio' name='wpMath' value=\"$k\"$checked /> ".wfMsg($v)."</label></div>\n" );
733 }
734 $wgOut->addHTML( "</fieldset>\n\n" );
735 }
736
737 # Files
738 #
739 $wgOut->addHTML("<fieldset>
740 <legend>" . wfMsg( 'files' ) . "</legend>
741 <div><label for='wpImageSize'>" . wfMsg('imagemaxsize') . "</label> <select id='wpImageSize' name='wpImageSize'>");
742
743 $imageLimitOptions = null;
744 foreach ( $wgImageLimits as $index => $limits ) {
745 $selected = ($index == $this->mImageSize) ? 'selected="selected"' : '';
746 $imageLimitOptions .= "<option value=\"{$index}\" {$selected}>{$limits[0]}×{$limits[1]}". wfMsgHtml('unit-pixel') ."</option>\n";
747 }
748
749 $imageThumbOptions = null;
750 $wgOut->addHTML( "{$imageLimitOptions}</select></div>
751 <div><label for='wpThumbSize'>" . wfMsg('thumbsize') . "</label> <select name='wpThumbSize' id='wpThumbSize'>");
752 foreach ( $wgThumbLimits as $index => $size ) {
753 $selected = ($index == $this->mThumbSize) ? 'selected="selected"' : '';
754 $imageThumbOptions .= "<option value=\"{$index}\" {$selected}>{$size}". wfMsgHtml('unit-pixel') ."</option>\n";
755 }
756 $wgOut->addHTML( "{$imageThumbOptions}</select></div></fieldset>\n\n");
757
758 # Date format
759 #
760 # Date/Time
761 #
762
763 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'datetime' ) . "</legend>\n" );
764
765 if ($dateopts) {
766 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'dateformat' ) . "</legend>\n" );
767 $idCnt = 0;
768 $epoch = '20010115161234';
769 foreach($dateopts as $key => $option) {
770 if( $key == MW_DATE_DEFAULT ) {
771 $formatted = wfMsgHtml( 'datedefault' );
772 } else {
773 $formatted = htmlspecialchars( $wgLang->timeanddate( $epoch, false, $key ) );
774 }
775 ($key == $this->mDate) ? $checked = ' checked="checked"' : $checked = '';
776 $wgOut->addHTML( "<div><input type='radio' name=\"wpDate\" id=\"wpDate$idCnt\" ".
777 "value=\"$key\"$checked /> <label for=\"wpDate$idCnt\">$formatted</label></div>\n" );
778 $idCnt++;
779 }
780 $wgOut->addHTML( "</fieldset>\n" );
781 }
782
783 $nowlocal = $wgLang->time( $now = wfTimestampNow(), true );
784 $nowserver = $wgLang->time( $now, false );
785
786 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'timezonelegend' ). '</legend><table>' .
787 $this->addRow( wfMsg( 'servertime' ), $nowserver ) .
788 $this->addRow( wfMsg( 'localtime' ), $nowlocal ) .
789 $this->addRow(
790 '<label for="wpHourDiff">' . wfMsg( 'timezoneoffset' ) . '</label>',
791 "<input type='text' name='wpHourDiff' id='wpHourDiff' value=\"" . htmlspecialchars( $this->mHourDiff ) . "\" size='6' />"
792 ) . "<tr><td colspan='2'>
793 <input type='button' value=\"" . wfMsg( 'guesstimezone' ) ."\"
794 onclick='javascript:guessTimezone()' id='guesstimezonebutton' style='display:none;' />
795 </td></tr></table></fieldset>
796 <div class='prefsectiontip'>¹" . wfMsg( 'timezonetext' ) . "</div>
797 </fieldset>\n\n" );
798
799 # Editing
800 #
801 global $wgLivePreview;
802 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'textboxsize' ) . '</legend>
803 <div>
804 <label for="wpRows">' . wfMsg( 'rows' ) . "</label> <input type='text' name='wpRows' id='wpRows' value=\"{$this->mRows}\" size='3' />
805 <label for='wpCols'>" . wfMsg( 'columns' ) . "</label> <input type='text' name='wpCols' id='wpCols' value=\"{$this->mCols}\" size='3' />
806 </div>" .
807 $this->getToggles( array(
808 'editsection',
809 'editsectiononrightclick',
810 'editondblclick',
811 'editwidth',
812 'showtoolbar',
813 'previewonfirst',
814 'previewontop',
815 'watchdefault',
816 'minordefault',
817 'externaleditor',
818 'externaldiff',
819 $wgLivePreview ? 'uselivepreview' : false, )
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 ?>