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