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