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