Slightly better prefs layout
[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 $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>\n";
383 }
384 return $r1;
385 }
386
387
388 function getToggle( $tname, $trailer = 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 $trailer = $trailer ? $trailer : '';
396 return "<div class='toggle'><input type='checkbox' value='1' id=\"$tname\" name=\"wpOp$tname\"$checked />" .
397 " <span class='toggletext'><label for=\"$tname\">$ttext</label>$trailer</span></div>\n";
398 }
399
400 function getToggles( $items ) {
401 $out = "";
402 foreach( $items as $item ) {
403 if( $item === false )
404 continue;
405 if( is_array( $item ) ) {
406 list( $key, $trailer ) = $item;
407 } else {
408 $key = $item;
409 $trailer = false;
410 }
411 $out .= $this->getToggle( $key, $trailer );
412 }
413 return $out;
414 }
415
416 function addRow($td1, $td2) {
417 return "<tr><td align='right'>$td1</td><td align='left'>$td2</td></tr>";
418 }
419
420 /**
421 * @access private
422 */
423 function mainPrefsForm( $status , $message = '' ) {
424 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgValidSkinNames;
425 global $wgAllowRealName, $wgImageLimits, $wgThumbLimits;
426 global $wgDisableLangConversion;
427 global $wgEnotifWatchlist, $wgEnotifUserTalk,$wgEnotifMinorEdits;
428 global $wgRCShowWatchingUsers, $wgEnotifRevealEditorAddress;
429 global $wgEnableEmail, $wgEnableUserEmail, $wgEmailAuthentication;
430 global $wgContLanguageCode, $wgDefaultSkin, $wgSkipSkins;
431
432 $wgOut->setPageTitle( wfMsg( 'preferences' ) );
433 $wgOut->setArticleRelated( false );
434 $wgOut->setRobotpolicy( 'noindex,nofollow' );
435
436 if ( $this->mSuccess || 'success' == $status ) {
437 $wgOut->addWikitext( '<div class="preferences-save-success"><strong>'. wfMsg( 'savedprefs' ) . '</strong></div>' );
438 } else if ( 'error' == $status ) {
439 $wgOut->addWikitext( '<div class="error"><strong>' . $message . '</strong></div>' );
440 } else if ( '' != $status ) {
441 $wgOut->addWikitext( $message . "\n----" );
442 }
443 $uname = $wgUser->getName();
444 $uid = $wgUser->getID();
445
446 $wgOut->addWikiText( '<div class="preferences-login">' . wfMsg( 'prefslogintext', $uname, $uid ) . '</div>' );
447
448 $qbs = $wgLang->getQuickbarSettings();
449 $skinNames = $wgLang->getSkinNames();
450 $mathopts = $wgLang->getMathNames();
451 $dateopts = $wgLang->getDateFormats();
452 $togs = $wgLang->getUserToggles();
453
454 $titleObj = Title::makeTitle( NS_SPECIAL, 'Preferences' );
455 $action = $titleObj->escapeLocalURL();
456
457 # Pre-expire some toggles so they won't show if disabled
458 $this->mUsedToggles[ 'shownumberswatching' ] = true;
459 $this->mUsedToggles[ 'showupdated' ] = true;
460 $this->mUsedToggles[ 'enotifwatchlistpages' ] = true;
461 $this->mUsedToggles[ 'enotifusertalkpages' ] = true;
462 $this->mUsedToggles[ 'enotifminoredits' ] = true;
463 $this->mUsedToggles[ 'enotifrevealaddr' ] = true;
464
465 # Enotif
466 # <FIXME>
467 $this->mUserEmail = htmlspecialchars( $this->mUserEmail );
468 $this->mRealName = htmlspecialchars( $this->mRealName );
469 $this->mNick = htmlspecialchars( $this->mNick );
470 if ( $this->mEmailFlag ) { $emfc = 'checked="checked"'; }
471 else { $emfc = ''; }
472
473 if ($wgEmailAuthentication && ($this->mUserEmail != '') ) {
474 if( $wgUser->getEmailAuthenticationTimestamp() ) {
475 $emailauthenticated = wfMsg('emailauthenticated',$wgLang->timeanddate($wgUser->getEmailAuthenticationTimestamp(), true ) ).'<br />';
476 } else {
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 }
485
486 if ($this->mUserEmail == '') {
487 $emailauthenticated = wfMsg( 'noemailprefs' );
488 }
489
490 $ps = $this->namespacesCheckboxes();
491
492 $enotifwatchlistpages = ($wgEnotifWatchlist) ? $this->getToggle( 'enotifwatchlistpages' ) : '';
493 $enotifusertalkpages = ($wgEnotifUserTalk) ? $this->getToggle( 'enotifusertalkpages' ) : '';
494 $enotifminoredits = ($wgEnotifWatchlist && $wgEnotifMinorEdits) ? $this->getToggle( 'enotifminoredits' ) : '';
495 $enotifrevealaddr = (($wgEnotifWatchlist || $wgEnotifUserTalk) && $wgEnotifRevealEditorAddress) ? $this->getToggle( 'enotifrevealaddr' ) : '';
496 $prefs_help_email_enotif = ( $wgEnotifWatchlist || $wgEnotifUserTalk) ? ' ' . wfMsg('prefs-help-email-enotif') : '';
497 $prefs_help_realname = '';
498
499 # </FIXME>
500
501 $wgOut->addHTML( "<form action=\"$action\" method='post'>" );
502 $wgOut->addHTML( "<div id='preferences'>" );
503
504 # User data
505 #
506
507 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg('prefs-personal') . "</legend>\n<table>\n");
508
509 if ($wgAllowRealName) {
510 $wgOut->addHTML(
511 $this->addRow(
512 wfMsg('yourrealname'),
513 "<input type='text' name='wpRealName' value=\"{$this->mRealName}\" size='25' />"
514 )
515 );
516 }
517 if ($wgEnableEmail) {
518 $wgOut->addHTML(
519 $this->addRow(
520 wfMsg( 'youremail' ),
521 "<input type='text' name='wpUserEmail' value=\"{$this->mUserEmail}\" size='25' />"
522 )
523 );
524 }
525
526 $wgOut->addHTML(
527 $this->addRow(
528 wfMsg( 'yournick' ),
529 "<input type='text' name='wpNick' value=\"{$this->mNick}\" size='25' />"
530 ) .
531 # FIXME: The <input> part should be where the &nbsp; is, getToggle() needs
532 # to be changed to out return its output in two parts. -ævar
533 $this->addRow(
534 '&nbsp;',
535 $this->getToggle( 'fancysig' )
536 )
537 );
538
539 /**
540 * If a bogus value is set, default to the content language.
541 * Otherwise, no default is selected and the user ends up
542 * with an Afrikaans interface since it's first in the list.
543 */
544 $languages = $wgLang->getLanguageNames();
545 $selectedLang = isset( $languages[$this->mUserLanguage] ) ? $this->mUserLanguage : $wgContLanguageCode;
546 $selbox = null;
547 foreach($languages as $code => $name) {
548 global $IP;
549 /* only add languages that have a file */
550 $langfile="$IP/languages/Language".str_replace('-', '_', ucfirst($code)).".php";
551 if(file_exists($langfile) || $code == $wgContLanguageCode) {
552 $sel = ($code == $selectedLang)? ' selected="selected"' : '';
553 $selbox .= "<option value=\"$code\"$sel>$code - $name</option>\n";
554 }
555 }
556 $wgOut->addHTML( $this->addRow( wfMsg('yourlanguage'), "<select name='wpUserLanguage'>$selbox</select>" ));
557
558 /* see if there are multiple language variants to choose from*/
559 if(!$wgDisableLangConversion) {
560 $variants = $wgContLang->getVariants();
561
562 foreach($variants as $v) {
563 $v = str_replace( '_', '-', strtolower($v));
564 if($name = $languages[$v]) {
565 $variantArray[$v] = $name;
566 }
567 }
568
569 $selbox = null;
570 foreach($variantArray as $code => $name) {
571 $sel = $code == $this->mUserVariant ? 'selected="selected"' : '';
572 $selbox .= "<option value=\"$code\" $sel>$code - $name</option>";
573 }
574
575 if(count($variantArray) > 1) {
576 $wgOut->addHtml(
577 $this->addRow( wfMsg( 'yourvariant' ), "<select name='wpUserVariant'>$selbox</select>" )
578 );
579 }
580 }
581 $wgOut->addHTML('</table>');
582
583 # Password
584 $this->mOldpass = htmlspecialchars( $this->mOldpass );
585 $this->mNewpass = htmlspecialchars( $this->mNewpass );
586 $this->mRetypePass = htmlspecialchars( $this->mRetypePass );
587
588 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'changepassword' ) . '</legend><table>');
589 $wgOut->addHTML(
590 $this->addRow( wfMsg( 'oldpassword' ), "<input type='password' name='wpOldpass' value=\"{$this->mOldpass}\" size='20' />" ) .
591 $this->addRow( wfMsg( 'newpassword' ), "<input type='password' name='wpNewpass' value=\"{$this->mNewpass}\" size='20' />" ) .
592 $this->addRow( wfMsg( 'retypenew' ), "<input type='password' name='wpRetypePass' value=\"{$this->mRetypePass}\" size='20' />" ) .
593 "</table>\n" .
594 $this->getToggle( "rememberpassword" ) . "</fieldset>\n\n" );
595
596 # <FIXME>
597 # Enotif
598 if ($wgEnableEmail) {
599 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'email' ) . '</legend>' );
600 $wgOut->addHTML(
601 $emailauthenticated.
602 $enotifrevealaddr.
603 $enotifwatchlistpages.
604 $enotifusertalkpages.
605 $enotifminoredits );
606 if ($wgEnableUserEmail) {
607 $emf = wfMsg( 'emailflag' );
608 $wgOut->addHTML(
609 "<div><input type='checkbox' $emfc value='1' name='wpEmailFlag' id='wpEmailFlag' /> <label for='wpEmailFlag'>$emf</label></div>" );
610 }
611
612 $wgOut->addHTML( '</fieldset>' );
613 }
614 # </FIXME>
615
616 if ($wgAllowRealName || $wgEnableEmail) {
617 $wgOut->addHTML("<div class='prefsectiontip'>");
618 $rn = $wgAllowRealName ? wfMsg('prefs-help-realname') : '';
619 $em = $wgEnableEmail ? '<br />' . wfMsg('prefs-help-email') : '';
620 $wgOut->addHTML( $rn . $em . '</div>');
621 }
622
623 $wgOut->addHTML( '</fieldset>' );
624
625 # Quickbar
626 #
627 if ($this->mSkin == 'cologneblue' || $this->mSkin == 'standard') {
628 $wgOut->addHtml( "<fieldset>\n<legend>" . wfMsg( 'qbsettings' ) . "</legend>\n" );
629 for ( $i = 0; $i < count( $qbs ); ++$i ) {
630 if ( $i == $this->mQuickbar ) { $checked = ' checked="checked"'; }
631 else { $checked = ""; }
632 $wgOut->addHTML( "<div><label><input type='radio' name='wpQuickbar' value=\"$i\"$checked />{$qbs[$i]}</label></div>\n" );
633 }
634 $wgOut->addHtml( "</fieldset>\n\n" );
635 } else {
636 # Need to output a hidden option even if the relevant skin is not in use,
637 # otherwise the preference will get reset to 0 on submit
638 $wgOut->addHTML( "<input type='hidden' name='wpQuickbar' value='{$this->mQuickbar}' />" );
639 }
640
641 # Skin
642 #
643 $wgOut->addHTML( "<fieldset>\n<legend>\n" . wfMsg('skin') . "</legend>\n" );
644 $mptitle = Title::newMainPage();
645 $previewtext = wfMsg('skinpreview');
646 # Only show members of $wgValidSkinNames rather than
647 # $skinNames (skins is all skin names from Language.php)
648 foreach ($wgValidSkinNames as $skinkey => $skinname ) {
649 if ( in_array( $skinkey, $wgSkipSkins ) ) {
650 continue;
651 }
652 $checked = $skinkey == $this->mSkin ? ' checked="checked"' : '';
653 $sn = isset( $skinNames[$skinkey] ) ? $skinNames[$skinkey] : $skinname;
654
655 $mplink = htmlspecialchars($mptitle->getLocalURL("useskin=$skinkey"));
656 $previewlink = "<a target='_blank' href=\"$mplink\">$previewtext</a>";
657 if( $skinkey == $wgDefaultSkin )
658 $sn .= ' (' . wfMsg( 'default' ) . ')';
659 $wgOut->addHTML( "<input type='radio' name='wpSkin' value=\"$skinkey\"$checked /> {$sn} $previewlink<br/>\n" );
660 }
661 $wgOut->addHTML( "</fieldset>\n\n" );
662
663 # Math
664 #
665 global $wgUseTeX;
666 if( $wgUseTeX ) {
667 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg('math') . '</legend>' );
668 foreach ( $mathopts as $k => $v ) {
669 $checked = $k == $this->mMath ? ' checked="checked"' : '';
670 $wgOut->addHTML( "<div><label><input type='radio' name='wpMath' value=\"$k\"$checked /> ".wfMsg($v)."</label></div>\n" );
671 }
672 $wgOut->addHTML( "</fieldset>\n\n" );
673 }
674
675 # Files
676 #
677 $wgOut->addHTML("<fieldset>
678 <legend>" . wfMsg( 'files' ) . "</legend>
679 <div><label>" . wfMsg('imagemaxsize') . "<select name=\"wpImageSize\">");
680
681 $imageLimitOptions = null;
682 foreach ( $wgImageLimits as $index => $limits ) {
683 $selected = ($index == $this->mImageSize) ? 'selected="selected"' : '';
684 $imageLimitOptions .= "<option value=\"{$index}\" {$selected}>{$limits[0]}×{$limits[1]}". wfMsgHtml('unit-pixel') ."</option>\n";
685 }
686
687 $imageThumbOptions = null;
688 $wgOut->addHTML( "{$imageLimitOptions}</select></label></div>
689 <div><label>" . wfMsg('thumbsize') . "<select name=\"wpThumbSize\">");
690 foreach ( $wgThumbLimits as $index => $size ) {
691 $selected = ($index == $this->mThumbSize) ? 'selected="selected"' : '';
692 $imageThumbOptions .= "<option value=\"{$index}\" {$selected}>{$size}". wfMsgHtml('unit-pixel') ."</option>\n";
693 }
694 $wgOut->addHTML( "{$imageThumbOptions}</select></label></div></fieldset>\n\n");
695
696 # Date format
697 #
698 if ($dateopts) {
699 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg('dateformat') . "</legend>\n" );
700 foreach($dateopts as $key => $option) {
701 ($key == $this->mDate) ? $checked = ' checked="checked"' : $checked = '';
702 $wgOut->addHTML( "<div><label><input type='radio' name=\"wpDate\" ".
703 "value=\"$key\"$checked /> $option</label></div>\n" );
704 }
705 $wgOut->addHTML( "</fieldset>\n\n");
706 }
707
708 # Time zone
709 #
710
711 $nowlocal = $wgLang->time( $now = wfTimestampNow(), true );
712 $nowserver = $wgLang->time( $now, false );
713
714 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'timezonelegend' ) . '</legend><table>' .
715 $this->addRow( wfMsg( 'servertime' ), $nowserver ) .
716 $this->addRow( wfMsg( 'localtime' ), $nowlocal ) .
717 $this->addRow(
718 wfMsg( 'timezoneoffset' ),
719 "<input type='text' name='wpHourDiff' value=\"" . htmlspecialchars( $this->mHourDiff ) . "\" size='6' />"
720 ) . "<tr><td colspan='2'>
721 <input type='button' value=\"" . wfMsg( 'guesstimezone' ) ."\"
722 onclick='javascript:guessTimezone()' id='guesstimezonebutton' style='display:none;' />
723 </td></tr></table>
724 <div class='prefsectiontip'>¹" . wfMsg( 'timezonetext' ) . "</div>
725 </fieldset>\n\n" );
726
727 # Editing
728 #
729 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'textboxsize' ) . '</legend>
730 <div>
731 <label>' . wfMsg( 'rows' ) . ": <input type='text' name='wpRows' value=\"{$this->mRows}\" size='6' /></label>
732 <label>" . wfMsg( 'columns' ) . ": <input type='text' name='wpCols' value=\"{$this->mCols}\" size='6' /></label>
733 </div>" .
734 $this->getToggles( array(
735 'editsection',
736 'editsectiononrightclick',
737 'editondblclick',
738 'editwidth',
739 'showtoolbar',
740 'previewonfirst',
741 'previewontop',
742 'watchdefault',
743 'minordefault',
744 'externaleditor',
745 'externaldiff' )
746 ) . '</fieldset>'
747 );
748
749 $wgOut->addHTML( '<fieldset><legend>' . htmlspecialchars(wfMsg('prefs-rc')) . '</legend>' .
750 wfMsg ( 'recentchangescount' ) . " <input type='text' name='wpRecent' value=\"$this->mRecent\" size='6' />" .
751 $this->getToggles( array(
752 'hideminor',
753 $wgRCShowWatchingUsers ? 'shownumberswatching' : false,
754 'usenewrc' )
755 ) . '</fieldset>'
756 );
757
758 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'searchresultshead' ) . '</legend><table>' .
759 $this->addRow( wfMsg( 'resultsperpage' ), "<input type='text' name='wpSearch' value=\"$this->mSearch\" size='4' />" ) .
760 $this->addRow( wfMsg( 'contextlines' ), "<input type='text' name='wpSearchLines' value=\"$this->mSearchLines\" size='4' />" ) .
761 $this->addRow( wfMsg( 'contextchars' ), "<input type='text' name='wpSearchChars' value=\"$this->mSearchChars\" size='4' />" ) .
762 "</table><fieldset><legend>" . wfMsg( 'defaultns' ) . "</legend>$ps</fieldset></fieldset>" );
763
764 # Misc
765 #
766 $wgOut->addHTML('<fieldset><legend>' . wfMsg('prefs-misc') . '</legend>');
767 $wgOut->addHTML( htmlspecialchars ( wfMsg ( 'stubthreshold' ) ) . " <input type='text' name=\"wpStubs\" value=\"$this->mStubs\" size='6' />");
768 $msgUnderline = htmlspecialchars(wfMsg("tog-underline"));
769 $msgUnderlinenever = htmlspecialchars(wfMsg("underline-never"));
770 $msgUnderlinealways = htmlspecialchars(wfMsg("underline-always"));
771 $msgUnderlinedefault = htmlspecialchars(wfMsg("underline-default"));
772 $uopt = $wgUser->getOption("underline");
773 $s0 = $uopt == 0 ? " selected=\"selected\"" : "";
774 $s1 = $uopt == 1 ? " selected=\"selected\"" : "";
775 $s2 = $uopt == 2 ? " selected=\"selected\"" : "";
776 $wgOut->addHTML("
777 <div class='toggle'><label>$msgUnderline
778 <select name=\"wpOpunderline\">
779 <option value=\"0\"$s0>$msgUnderlinenever</option>
780 <option value=\"1\"$s1>$msgUnderlinealways</option>
781 <option value=\"2\"$s2>$msgUnderlinedefault</option>
782 </select>
783 </label>
784 </div>
785 ");
786 foreach ( $togs as $tname ) {
787 if( !array_key_exists( $tname, $this->mUsedToggles ) ) {
788 $wgOut->addHTML( $this->getToggle( $tname ) );
789 }
790 }
791 $wgOut->addHTML( '</fieldset>' );
792
793 $token = $wgUser->editToken();
794 $wgOut->addHTML( "
795 <div id='prefsubmit'>
796 <div>
797 <input type='submit' name='wpSaveprefs' class='btnSavePrefs' value=\"" . wfMsg( 'saveprefs' ) . "\" accesskey=\"".
798 wfMsg('accesskey-save')."\" title=\"[alt-".wfMsg('accesskey-save')."]\" />
799 <input type='submit' name='wpReset' value=\"" . wfMsg( 'resetprefs' ) . "\" />
800 </div>
801
802 </div>
803
804 <input type='hidden' name='wpEditToken' value='{$token}' />
805 </div></form>\n" );
806
807 $wgOut->addWikiText( '<div class="prefcache">' . wfMsg('clearyourcache') . '</div>' );
808
809 }
810 }
811 ?>