6af866246b8a3a38c1b46f6987704afa00195259
[lhc/web/wiklou.git] / includes / SpecialPreferences.php
1 <?php
2 /**
3 * Hold things related to displaying and saving user preferences.
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 * Entry point that create the "Preferences" object
10 */
11 function wfSpecialPreferences() {
12 global $wgRequest;
13
14 $form = new PreferencesForm( $wgRequest );
15 $form->execute();
16 }
17
18 /**
19 * Preferences form handling
20 * This object will show the preferences form and can save it as well.
21 * @package MediaWiki
22 * @subpackage SpecialPage
23 */
24 class PreferencesForm {
25 var $mQuickbar, $mOldpass, $mNewpass, $mRetypePass, $mStubs;
26 var $mRows, $mCols, $mSkin, $mMath, $mDate, $mUserEmail, $mEmailFlag, $mNick;
27 var $mUserLanguage, $mUserVariant;
28 var $mSearch, $mRecent, $mHourDiff, $mSearchLines, $mSearchChars, $mAction;
29 var $mReset, $mPosted, $mToggles, $mSearchNs, $mRealName, $mImageSize;
30 var $mUnderline;
31
32 /**
33 * Constructor
34 * Load some values
35 */
36 function PreferencesForm( &$request ) {
37 global $wgLang, $wgContLang, $wgUser, $wgAllowRealName;
38
39 $this->mQuickbar = $request->getVal( 'wpQuickbar' );
40 $this->mOldpass = $request->getVal( 'wpOldpass' );
41 $this->mNewpass = $request->getVal( 'wpNewpass' );
42 $this->mRetypePass =$request->getVal( 'wpRetypePass' );
43 $this->mStubs = $request->getVal( 'wpStubs' );
44 $this->mRows = $request->getVal( 'wpRows' );
45 $this->mCols = $request->getVal( 'wpCols' );
46 $this->mSkin = $request->getVal( 'wpSkin' );
47 $this->mMath = $request->getVal( 'wpMath' );
48 $this->mDate = $request->getVal( 'wpDate' );
49 $this->mUserEmail = $request->getVal( 'wpUserEmail' );
50 $this->mRealName = $wgAllowRealName ? $request->getVal( 'wpRealName' ) : '';
51 $this->mEmailFlag = $request->getCheck( 'wpEmailFlag' ) ? 0 : 1;
52 $this->mNick = $request->getVal( 'wpNick' );
53 $this->mUserLanguage = $request->getVal( 'wpUserLanguage' );
54 $this->mUserVariant = $request->getVal( 'wpUserVariant' );
55 $this->mSearch = $request->getVal( 'wpSearch' );
56 $this->mRecent = $request->getVal( 'wpRecent' );
57 $this->mHourDiff = $request->getVal( 'wpHourDiff' );
58 $this->mSearchLines = $request->getVal( 'wpSearchLines' );
59 $this->mSearchChars = $request->getVal( 'wpSearchChars' );
60 $this->mImageSize = $request->getVal( 'wpImageSize' );
61 $this->mThumbSize = $request->getInt( 'wpThumbSize' );
62 $this->mUnderline = $request->getInt( 'wpOpunderline' );
63 $this->mAction = $request->getVal( 'action' );
64 $this->mReset = $request->getCheck( 'wpReset' );
65 $this->mPosted = $request->wasPosted();
66 $this->mSuccess = $request->getCheck( 'success' );
67 $this->mWatchlistDays = $request->getVal( 'wpWatchlistDays' );
68
69 $this->mSaveprefs = $request->getCheck( 'wpSaveprefs' ) &&
70 $this->mPosted &&
71 $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
72
73 # User toggles (the big ugly unsorted list of checkboxes)
74 $this->mToggles = array();
75 if ( $this->mPosted ) {
76 $togs = $wgLang->getUserToggles();
77 foreach ( $togs as $tname ) {
78 $this->mToggles[$tname] = $request->getCheck( "wpOp$tname" ) ? 1 : 0;
79 }
80 }
81
82 $this->mUsedToggles = array();
83
84 # Search namespace options
85 # Note: namespaces don't necessarily have consecutive keys
86 $this->mSearchNs = array();
87 if ( $this->mPosted ) {
88 $namespaces = $wgContLang->getNamespaces();
89 foreach ( $namespaces as $i => $namespace ) {
90 if ( $i >= 0 ) {
91 $this->mSearchNs[$i] = $request->getCheck( "wpNs$i" ) ? 1 : 0;
92 }
93 }
94 }
95
96 # Validate language
97 if ( !preg_match( '/^[a-z\-]*$/', $this->mUserLanguage ) ) {
98 $this->mUserLanguage = 'nolanguage';
99 }
100 }
101
102 function execute() {
103 global $wgUser, $wgOut;
104
105 if ( $wgUser->isAnon() ) {
106 $wgOut->errorpage( 'prefsnologin', 'prefsnologintext' );
107 return;
108 }
109 if ( wfReadOnly() ) {
110 $wgOut->readOnlyPage();
111 return;
112 }
113 if ( $this->mReset ) {
114 $this->resetPrefs();
115 $this->mainPrefsForm( 'reset', wfMsg( 'prefsreset' ) );
116 } else if ( $this->mSaveprefs ) {
117 $this->savePreferences();
118 } else {
119 $this->resetPrefs();
120 $this->mainPrefsForm( '' );
121 }
122 }
123 /**
124 * @access private
125 */
126 function validateInt( &$val, $min=0, $max=0x7fffffff ) {
127 $val = intval($val);
128 $val = min($val, $max);
129 $val = max($val, $min);
130 return $val;
131 }
132
133 /**
134 * @access private
135 */
136 function validateFloat( &$val, $min, $max=0x7fffffff ) {
137 $val = floatval( $val );
138 $val = min( $val, $max );
139 $val = max( $val, $min );
140 return( $val );
141 }
142
143 /**
144 * @access private
145 */
146 function validateIntOrNull( &$val, $min=0, $max=0x7fffffff ) {
147 $val = trim($val);
148 if($val === '') {
149 return $val;
150 } else {
151 return $this->validateInt( $val, $min, $max );
152 }
153 }
154
155 /**
156 * @access private
157 */
158 function validateDate( &$val, $min = 0, $max=0x7fffffff ) {
159 if ( ( sprintf('%d', $val) === $val && $val >= $min && $val <= $max ) || $val == 'ISO 8601' )
160 return $val;
161 else
162 return 0;
163 }
164
165 /**
166 * Used to validate the user inputed timezone before saving it as
167 * 'timeciorrection', will return '00:00' if fed bogus data.
168 * Note: It's not a 100% correct implementation timezone-wise, it will
169 * accept stuff like '14:30',
170 * @access private
171 * @param string $s the user input
172 * @return string
173 */
174 function validateTimeZone( $s ) {
175 if ( $s !== '' ) {
176 if ( strpos( $s, ':' ) ) {
177 # HH:MM
178 $array = explode( ':' , $s );
179 $hour = intval( $array[0] );
180 $minute = intval( $array[1] );
181 } else {
182 $minute = intval( $s * 60 );
183 $hour = intval( $minute / 60 );
184 $minute = abs( $minute ) % 60;
185 }
186 # Max is +14:00 and min is -12:00, see:
187 # http://en.wikipedia.org/wiki/Timezone
188 $hour = min( $hour, 14 );
189 $hour = max( $hour, -12 );
190 $minute = min( $minute, 59 );
191 $minute = max( $minute, 0 );
192 $s = sprintf( "%02d:%02d", $hour, $minute );
193 }
194 return $s;
195 }
196
197 /**
198 * @access private
199 */
200 function savePreferences() {
201 global $wgUser, $wgOut, $wgParser;
202 global $wgEnableUserEmail, $wgEnableEmail;
203 global $wgEmailAuthentication, $wgMinimalPasswordLength;
204 global $wgAuth;
205
206
207 if ( '' != $this->mNewpass ) {
208 if ( $this->mNewpass != $this->mRetypePass ) {
209 $this->mainPrefsForm( 'error', wfMsg( 'badretype' ) );
210 return;
211 }
212
213 if ( strlen( $this->mNewpass ) < $wgMinimalPasswordLength ) {
214 $this->mainPrefsForm( 'error', wfMsg( 'passwordtooshort', $wgMinimalPasswordLength ) );
215 return;
216 }
217
218 if (!$wgUser->checkPassword( $this->mOldpass )) {
219 $this->mainPrefsForm( 'error', wfMsg( 'wrongpassword' ) );
220 return;
221 }
222 if (!$wgAuth->setPassword( $wgUser, $this->mNewpass )) {
223 $this->mainPrefsForm( 'error', wfMsg( 'externaldberror' ) );
224 return;
225 }
226 $wgUser->setPassword( $this->mNewpass );
227 $this->mNewpass = $this->mOldpass = $this->mRetypePass = '';
228
229 }
230 $wgUser->setRealName( $this->mRealName );
231
232 if( $wgUser->getOption( 'language' ) !== $this->mUserLanguage ) {
233 $needRedirect = true;
234 } else {
235 $needRedirect = false;
236 }
237
238 # Validate the signature and clean it up as needed
239 if( $this->mToggles['fancysig'] ) {
240 if( Parser::validateSig( $this->mNick ) !== false ) {
241 $this->mNick = $wgParser->cleanSig( $this->mNick );
242 } else {
243 $this->mainPrefsForm( 'error', wfMsg( 'badsig' ) );
244 }
245 }
246
247 $wgUser->setOption( 'language', $this->mUserLanguage );
248 $wgUser->setOption( 'variant', $this->mUserVariant );
249 $wgUser->setOption( 'nickname', $this->mNick );
250 $wgUser->setOption( 'quickbar', $this->mQuickbar );
251 $wgUser->setOption( 'skin', $this->mSkin );
252 global $wgUseTeX;
253 if( $wgUseTeX ) {
254 $wgUser->setOption( 'math', $this->mMath );
255 }
256 $wgUser->setOption( 'date', $this->validateDate( $this->mDate, 0, 20 ) );
257 $wgUser->setOption( 'searchlimit', $this->validateIntOrNull( $this->mSearch ) );
258 $wgUser->setOption( 'contextlines', $this->validateIntOrNull( $this->mSearchLines ) );
259 $wgUser->setOption( 'contextchars', $this->validateIntOrNull( $this->mSearchChars ) );
260 $wgUser->setOption( 'rclimit', $this->validateIntOrNull( $this->mRecent ) );
261 $wgUser->setOption( 'rows', $this->validateInt( $this->mRows, 4, 1000 ) );
262 $wgUser->setOption( 'cols', $this->validateInt( $this->mCols, 4, 1000 ) );
263 $wgUser->setOption( 'stubthreshold', $this->validateIntOrNull( $this->mStubs ) );
264 $wgUser->setOption( 'timecorrection', $this->validateTimeZone( $this->mHourDiff, -12, 14 ) );
265 $wgUser->setOption( 'imagesize', $this->mImageSize );
266 $wgUser->setOption( 'thumbsize', $this->mThumbSize );
267 $wgUser->setOption( 'underline', $this->validateInt($this->mUnderline, 0, 2) );
268 $wgUser->setOption( 'watchlistdays', $this->validateFloat( $this->mWatchlistDays, 0.5, 5 ) );
269
270 # Set search namespace options
271 foreach( $this->mSearchNs as $i => $value ) {
272 $wgUser->setOption( "searchNs{$i}", $value );
273 }
274
275 if( $wgEnableEmail && $wgEnableUserEmail ) {
276 $wgUser->setOption( 'disablemail', $this->mEmailFlag );
277 }
278
279 # Set user toggles
280 foreach ( $this->mToggles as $tname => $tvalue ) {
281 $wgUser->setOption( $tname, $tvalue );
282 }
283 if (!$wgAuth->updateExternalDB($wgUser)) {
284 $this->mainPrefsForm( wfMsg( 'externaldberror' ) );
285 return;
286 }
287 $wgUser->setCookies();
288 $wgUser->saveSettings();
289
290 $error = false;
291 if( $wgEnableEmail ) {
292 $newadr = $this->mUserEmail;
293 $oldadr = $wgUser->getEmail();
294 if( ($newadr != '') && ($newadr != $oldadr) ) {
295 # the user has supplied a new email address on the login page
296 if( $wgUser->isValidEmailAddr( $newadr ) ) {
297 $wgUser->mEmail = $newadr; # new behaviour: set this new emailaddr from login-page into user database record
298 $wgUser->mEmailAuthenticated = null; # but flag as "dirty" = unauthenticated
299 $wgUser->saveSettings();
300 if ($wgEmailAuthentication) {
301 # Mail a temporary password to the dirty address.
302 # User can come back through the confirmation URL to re-enable email.
303 $result = $wgUser->sendConfirmationMail();
304 if( WikiError::isError( $result ) ) {
305 $error = wfMsg( 'mailerror', htmlspecialchars( $result->getMessage() ) );
306 } else {
307 $error = wfMsg( 'eauthentsent', $wgUser->getName() );
308 }
309 }
310 } else {
311 $error = wfMsg( 'invalidemailaddress' );
312 }
313 } else {
314 $wgUser->setEmail( $this->mUserEmail );
315 $wgUser->setCookies();
316 $wgUser->saveSettings();
317 }
318 }
319
320 if( $needRedirect && $error === false ) {
321 $title =& Title::makeTitle( NS_SPECIAL, "Preferences" );
322 $wgOut->redirect($title->getFullURL('success'));
323 return;
324 }
325
326 $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
327 $po = ParserOptions::newFromUser( $wgUser );
328 $this->mainPrefsForm( $error === false ? 'success' : 'error', $error);
329 }
330
331 /**
332 * @access private
333 */
334 function resetPrefs() {
335 global $wgUser, $wgLang, $wgContLang, $wgAllowRealName;
336
337 $this->mOldpass = $this->mNewpass = $this->mRetypePass = '';
338 $this->mUserEmail = $wgUser->getEmail();
339 $this->mUserEmailAuthenticationtimestamp = $wgUser->getEmailAuthenticationtimestamp();
340 $this->mRealName = ($wgAllowRealName) ? $wgUser->getRealName() : '';
341 $this->mUserLanguage = $wgUser->getOption( 'language' );
342 if( empty( $this->mUserLanguage ) ) {
343 # Quick hack for conversions, where this value is blank
344 global $wgContLanguageCode;
345 $this->mUserLanguage = $wgContLanguageCode;
346 }
347 $this->mUserVariant = $wgUser->getOption( 'variant');
348 $this->mEmailFlag = $wgUser->getOption( 'disablemail' ) == 1 ? 1 : 0;
349 $this->mNick = $wgUser->getOption( 'nickname' );
350
351 $this->mQuickbar = $wgUser->getOption( 'quickbar' );
352 $this->mSkin = Skin::normalizeKey( $wgUser->getOption( 'skin' ) );
353 $this->mMath = $wgUser->getOption( 'math' );
354 $this->mDate = $wgUser->getOption( 'date' );
355 $this->mRows = $wgUser->getOption( 'rows' );
356 $this->mCols = $wgUser->getOption( 'cols' );
357 $this->mStubs = $wgUser->getOption( 'stubthreshold' );
358 $this->mHourDiff = $wgUser->getOption( 'timecorrection' );
359 $this->mSearch = $wgUser->getOption( 'searchlimit' );
360 $this->mSearchLines = $wgUser->getOption( 'contextlines' );
361 $this->mSearchChars = $wgUser->getOption( 'contextchars' );
362 $this->mImageSize = $wgUser->getOption( 'imagesize' );
363 $this->mThumbSize = $wgUser->getOption( 'thumbsize' );
364 $this->mRecent = $wgUser->getOption( 'rclimit' );
365 $this->mUnderline = $wgUser->getOption( 'underline' );
366 $this->mWatchlistDays = $wgUser->getOption( 'watchlistdays' );
367
368 $togs = $wgLang->getUserToggles();
369 foreach ( $togs as $tname ) {
370 $ttext = wfMsg('tog-'.$tname);
371 $this->mToggles[$tname] = $wgUser->getOption( $tname );
372 }
373
374 $namespaces = $wgContLang->getNamespaces();
375 foreach ( $namespaces as $i => $namespace ) {
376 if ( $i >= NS_MAIN ) {
377 $this->mSearchNs[$i] = $wgUser->getOption( 'searchNs'.$i );
378 }
379 }
380 }
381
382 /**
383 * @access private
384 */
385 function namespacesCheckboxes() {
386 global $wgContLang;
387
388 # Determine namespace checkboxes
389 $namespaces = $wgContLang->getNamespaces();
390 $r1 = null;
391
392 foreach ( $namespaces as $i => $name ) {
393 if ($i < 0)
394 continue;
395 $checked = $this->mSearchNs[$i] ? "checked='checked'" : '';
396 $name = str_replace( '_', ' ', $namespaces[$i] );
397
398 if ( empty($name) )
399 $name = wfMsg( 'blanknamespace' );
400
401 $r1 .= "<input type='checkbox' value='1' name='wpNs$i' id='wpNs$i' {$checked}/> <label for='wpNs$i'>{$name}</label><br />\n";
402 }
403 return $r1;
404 }
405
406
407 function getToggle( $tname, $trailer = false, $disabled = false ) {
408 global $wgUser, $wgLang;
409
410 $this->mUsedToggles[$tname] = true;
411 $ttext = $wgLang->getUserToggle( $tname );
412
413 $checked = $wgUser->getOption( $tname ) == 1 ? ' checked="checked"' : '';
414 $disabled = $disabled ? ' disabled="disabled"' : '';
415 $trailer = $trailer ? $trailer : '';
416 return "<div class='toggle'><input type='checkbox' value='1' id=\"$tname\" name=\"wpOp$tname\"$checked$disabled />" .
417 " <span class='toggletext'><label for=\"$tname\">$ttext</label>$trailer</span></div>\n";
418 }
419
420 function getToggles( $items ) {
421 $out = "";
422 foreach( $items as $item ) {
423 if( $item === false )
424 continue;
425 if( is_array( $item ) ) {
426 list( $key, $trailer ) = $item;
427 } else {
428 $key = $item;
429 $trailer = false;
430 }
431 $out .= $this->getToggle( $key, $trailer );
432 }
433 return $out;
434 }
435
436 function addRow($td1, $td2) {
437 return "<tr><td align='right'>$td1</td><td align='left'>$td2</td></tr>";
438 }
439
440 /**
441 * @access private
442 */
443 function mainPrefsForm( $status , $message = '' ) {
444 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgValidSkinNames;
445 global $wgAllowRealName, $wgImageLimits, $wgThumbLimits;
446 global $wgDisableLangConversion;
447 global $wgEnotifWatchlist, $wgEnotifUserTalk,$wgEnotifMinorEdits;
448 global $wgRCShowWatchingUsers, $wgEnotifRevealEditorAddress;
449 global $wgEnableEmail, $wgEnableUserEmail, $wgEmailAuthentication;
450 global $wgContLanguageCode, $wgDefaultSkin, $wgSkipSkins;
451
452 $wgOut->setPageTitle( wfMsg( 'preferences' ) );
453 $wgOut->setArticleRelated( false );
454 $wgOut->setRobotpolicy( 'noindex,nofollow' );
455
456 if ( $this->mSuccess || 'success' == $status ) {
457 $wgOut->addWikitext( '<div class="successbox"><strong>'. wfMsg( 'savedprefs' ) . '</strong></div>' );
458 } else if ( 'error' == $status ) {
459 $wgOut->addWikitext( '<div class="errorbox"><strong>' . $message . '</strong></div>' );
460 } else if ( '' != $status ) {
461 $wgOut->addWikitext( $message . "\n----" );
462 }
463
464 $qbs = $wgLang->getQuickbarSettings();
465 $skinNames = $wgLang->getSkinNames();
466 $mathopts = $wgLang->getMathNames();
467 $dateopts = $wgLang->getDateFormats();
468 $togs = $wgLang->getUserToggles();
469
470 $titleObj = Title::makeTitle( NS_SPECIAL, 'Preferences' );
471 $action = $titleObj->escapeLocalURL();
472
473 # Pre-expire some toggles so they won't show if disabled
474 $this->mUsedToggles[ 'shownumberswatching' ] = true;
475 $this->mUsedToggles[ 'showupdated' ] = true;
476 $this->mUsedToggles[ 'enotifwatchlistpages' ] = true;
477 $this->mUsedToggles[ 'enotifusertalkpages' ] = true;
478 $this->mUsedToggles[ 'enotifminoredits' ] = true;
479 $this->mUsedToggles[ 'enotifrevealaddr' ] = true;
480 $this->mUsedToggles[ 'uselivepreview' ] = true;
481
482 # Enotif
483 # <FIXME>
484 $this->mUserEmail = htmlspecialchars( $this->mUserEmail );
485 $this->mRealName = htmlspecialchars( $this->mRealName );
486 $rawNick = $this->mNick;
487 $this->mNick = htmlspecialchars( $this->mNick );
488 if ( !$this->mEmailFlag ) { $emfc = 'checked="checked"'; }
489 else { $emfc = ''; }
490
491
492 if ($wgEmailAuthentication && ($this->mUserEmail != '') ) {
493 if( $wgUser->getEmailAuthenticationTimestamp() ) {
494 $emailauthenticated = wfMsg('emailauthenticated',$wgLang->timeanddate($wgUser->getEmailAuthenticationTimestamp(), true ) ).'<br />';
495 $disableEmailPrefs = false;
496 } else {
497 $disableEmailPrefs = true;
498 $skin = $wgUser->getSkin();
499 $emailauthenticated = wfMsg('emailnotauthenticated').'<br />' .
500 $skin->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Confirmemail' ),
501 wfMsg( 'emailconfirmlink' ) );
502 }
503 } else {
504 $emailauthenticated = '';
505 $disableEmailPrefs = false;
506 }
507
508 if ($this->mUserEmail == '') {
509 $emailauthenticated = wfMsg( 'noemailprefs' );
510 }
511
512 $ps = $this->namespacesCheckboxes();
513
514 $enotifwatchlistpages = ($wgEnotifWatchlist) ? $this->getToggle( 'enotifwatchlistpages', false, $disableEmailPrefs ) : '';
515 $enotifusertalkpages = ($wgEnotifUserTalk) ? $this->getToggle( 'enotifusertalkpages', false, $disableEmailPrefs ) : '';
516 $enotifminoredits = ($wgEnotifWatchlist && $wgEnotifMinorEdits) ? $this->getToggle( 'enotifminoredits', false, $disableEmailPrefs ) : '';
517 $enotifrevealaddr = (($wgEnotifWatchlist || $wgEnotifUserTalk) && $wgEnotifRevealEditorAddress) ? $this->getToggle( 'enotifrevealaddr', false, $disableEmailPrefs ) : '';
518 $prefs_help_email_enotif = ( $wgEnotifWatchlist || $wgEnotifUserTalk) ? ' ' . wfMsg('prefs-help-email-enotif') : '';
519 $prefs_help_realname = '';
520
521 # </FIXME>
522
523 $wgOut->addHTML( "<form action=\"$action\" method='post'>" );
524 $wgOut->addHTML( "<div id='preferences'>" );
525
526 # User data
527 #
528
529 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg('prefs-personal') . "</legend>\n<table>\n");
530
531 $wgOut->addHTML(
532 $this->addRow(
533 wfMsg( 'username'),
534 $wgUser->getName()
535 )
536 );
537
538 $wgOut->addHTML(
539 $this->addRow(
540 wfMsg( 'uid' ),
541 $wgUser->getID()
542 )
543 );
544
545
546 if ($wgAllowRealName) {
547 $wgOut->addHTML(
548 $this->addRow(
549 '<label for="wpRealName">' . wfMsg('yourrealname') . '</label>',
550 "<input type='text' name='wpRealName' id='wpRealName' value=\"{$this->mRealName}\" size='25' />"
551 )
552 );
553 }
554 if ($wgEnableEmail) {
555 $wgOut->addHTML(
556 $this->addRow(
557 '<label for="wpUserEmail">' . wfMsg( 'youremail' ) . '</label>',
558 "<input type='text' name='wpUserEmail' id='wpUserEmail' value=\"{$this->mUserEmail}\" size='25' />"
559 )
560 );
561 }
562
563 global $wgParser;
564 if( !empty( $this->mToggles['fancysig'] ) &&
565 false === $wgParser->validateSig( $rawNick ) ) {
566 $invalidSig = $this->addRow(
567 '&nbsp;',
568 '<span class="error">' . wfMsgHtml( 'badsig' ) . '<span>'
569 );
570 } else {
571 $invalidSig = '';
572 }
573
574 $wgOut->addHTML(
575 $this->addRow(
576 '<label for="wpNick">' . wfMsg( 'yournick' ) . '</label>',
577 "<input type='text' name='wpNick' id='wpNick' value=\"{$this->mNick}\" size='25' />"
578 ) .
579 $invalidSig .
580 # FIXME: The <input> part should be where the &nbsp; is, getToggle() needs
581 # to be changed to out return its output in two parts. -รฆvar
582 $this->addRow(
583 '&nbsp;',
584 $this->getToggle( 'fancysig' )
585 )
586 );
587
588 /**
589 * Make sure the site language is in the list; a custom language code
590 * might not have a defined name...
591 */
592 $languages = $wgLang->getLanguageNames();
593 if( !array_key_exists( $wgContLanguageCode, $languages ) ) {
594 $languages[$wgContLanguageCode] = $wgContLanguageCode;
595 }
596 ksort( $languages );
597
598 /**
599 * If a bogus value is set, default to the content language.
600 * Otherwise, no default is selected and the user ends up
601 * with an Afrikaans interface since it's first in the list.
602 */
603 $selectedLang = isset( $languages[$this->mUserLanguage] ) ? $this->mUserLanguage : $wgContLanguageCode;
604 $selbox = null;
605 foreach($languages as $code => $name) {
606 global $IP;
607 /* only add languages that have a file */
608 $langfile="$IP/languages/Language".str_replace('-', '_', ucfirst($code)).".php";
609 if(file_exists($langfile) || $code == $wgContLanguageCode) {
610 $sel = ($code == $selectedLang)? ' selected="selected"' : '';
611 $selbox .= "<option value=\"$code\"$sel>$code - $name</option>\n";
612 }
613 }
614 $wgOut->addHTML(
615 $this->addRow(
616 '<label for="wpUserLanguage">' . wfMsg('yourlanguage') . '</label>',
617 "<select name='wpUserLanguage' id='wpUserLanguage'>$selbox</select>"
618 )
619 );
620
621 /* see if there are multiple language variants to choose from*/
622 if(!$wgDisableLangConversion) {
623 $variants = $wgContLang->getVariants();
624 $variantArray = array();
625
626 foreach($variants as $v) {
627 $v = str_replace( '_', '-', strtolower($v));
628 if( array_key_exists( $v, $languages ) ) {
629 // If it doesn't have a name, we'll pretend it doesn't exist
630 $variantArray[$v] = $languages[$v];
631 }
632 }
633
634 $selbox = null;
635 foreach($variantArray as $code => $name) {
636 $sel = $code == $this->mUserVariant ? 'selected="selected"' : '';
637 $selbox .= "<option value=\"$code\" $sel>$code - $name</option>";
638 }
639
640 if(count($variantArray) > 1) {
641 $wgOut->addHtml(
642 $this->addRow( wfMsg( 'yourvariant' ), "<select name='wpUserVariant'>$selbox</select>" )
643 );
644 }
645 }
646 $wgOut->addHTML('</table>');
647
648 # Password
649 $this->mOldpass = htmlspecialchars( $this->mOldpass );
650 $this->mNewpass = htmlspecialchars( $this->mNewpass );
651 $this->mRetypePass = htmlspecialchars( $this->mRetypePass );
652
653 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'changepassword' ) . '</legend><table>');
654 $wgOut->addHTML(
655 $this->addRow(
656 '<label for="wpOldpass">' . wfMsg( 'oldpassword' ) . '</label>',
657 "<input type='password' name='wpOldpass' id='wpOldpass' value=\"{$this->mOldpass}\" size='20' />"
658 ) .
659 $this->addRow(
660 '<label for="wpNewpass">' . wfMsg( 'newpassword' ) . '</label>',
661 "<input type='password' name='wpNewpass' id='wpNewpass' value=\"{$this->mNewpass}\" size='20' />"
662 ) .
663 $this->addRow(
664 '<label for="wpRetypePass">' . wfMsg( 'retypenew' ) . '</label>',
665 "<input type='password' name='wpRetypePass' id='wpRetypePass' value=\"{$this->mRetypePass}\" size='20' />"
666 ) .
667 "</table>\n" .
668 $this->getToggle( "rememberpassword" ) . "</fieldset>\n\n" );
669
670 # <FIXME>
671 # Enotif
672 if ($wgEnableEmail) {
673 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'email' ) . '</legend>' );
674 $wgOut->addHTML(
675 $emailauthenticated.
676 $enotifrevealaddr.
677 $enotifwatchlistpages.
678 $enotifusertalkpages.
679 $enotifminoredits );
680 if ($wgEnableUserEmail) {
681 $emf = wfMsg( 'allowemail' );
682 $disabled = $disableEmailPrefs ? ' disabled="disabled"' : '';
683 $wgOut->addHTML(
684 "<div><input type='checkbox' $emfc $disabled value='1' name='wpEmailFlag' id='wpEmailFlag' /> <label for='wpEmailFlag'>$emf</label></div>" );
685 }
686
687 $wgOut->addHTML( '</fieldset>' );
688 }
689 # </FIXME>
690
691 if ($wgAllowRealName || $wgEnableEmail) {
692 $wgOut->addHTML("<div class='prefsectiontip'>");
693 $rn = $wgAllowRealName ? wfMsg('prefs-help-realname') : '';
694 $em = $wgEnableEmail ? '<br />' . wfMsg('prefs-help-email') : '';
695 $wgOut->addHTML( $rn . $em . '</div>');
696 }
697
698 $wgOut->addHTML( '</fieldset>' );
699
700 # Quickbar
701 #
702 if ($this->mSkin == 'cologneblue' || $this->mSkin == 'standard') {
703 $wgOut->addHtml( "<fieldset>\n<legend>" . wfMsg( 'qbsettings' ) . "</legend>\n" );
704 for ( $i = 0; $i < count( $qbs ); ++$i ) {
705 if ( $i == $this->mQuickbar ) { $checked = ' checked="checked"'; }
706 else { $checked = ""; }
707 $wgOut->addHTML( "<div><label><input type='radio' name='wpQuickbar' value=\"$i\"$checked />{$qbs[$i]}</label></div>\n" );
708 }
709 $wgOut->addHtml( "</fieldset>\n\n" );
710 } else {
711 # Need to output a hidden option even if the relevant skin is not in use,
712 # otherwise the preference will get reset to 0 on submit
713 $wgOut->addHTML( "<input type='hidden' name='wpQuickbar' value='{$this->mQuickbar}' />" );
714 }
715
716 # Skin
717 #
718 $wgOut->addHTML( "<fieldset>\n<legend>\n" . wfMsg('skin') . "</legend>\n" );
719 $mptitle = Title::newMainPage();
720 $previewtext = wfMsg('skinpreview');
721 # Only show members of $wgValidSkinNames rather than
722 # $skinNames (skins is all skin names from Language.php)
723 foreach ($wgValidSkinNames as $skinkey => $skinname ) {
724 if ( in_array( $skinkey, $wgSkipSkins ) ) {
725 continue;
726 }
727 $checked = $skinkey == $this->mSkin ? ' checked="checked"' : '';
728 $sn = isset( $skinNames[$skinkey] ) ? $skinNames[$skinkey] : $skinname;
729
730 $mplink = htmlspecialchars($mptitle->getLocalURL("useskin=$skinkey"));
731 $previewlink = "<a target='_blank' href=\"$mplink\">$previewtext</a>";
732 if( $skinkey == $wgDefaultSkin )
733 $sn .= ' (' . wfMsg( 'default' ) . ')';
734 $wgOut->addHTML( "<input type='radio' name='wpSkin' id=\"wpSkin$skinkey\" value=\"$skinkey\"$checked /> <label for=\"wpSkin$skinkey\">{$sn}</label> $previewlink<br/>\n" );
735 }
736 $wgOut->addHTML( "</fieldset>\n\n" );
737
738 # Math
739 #
740 global $wgUseTeX;
741 if( $wgUseTeX ) {
742 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg('math') . '</legend>' );
743 foreach ( $mathopts as $k => $v ) {
744 $checked = $k == $this->mMath ? ' checked="checked"' : '';
745 $wgOut->addHTML( "<div><label><input type='radio' name='wpMath' value=\"$k\"$checked /> ".wfMsg($v)."</label></div>\n" );
746 }
747 $wgOut->addHTML( "</fieldset>\n\n" );
748 }
749
750 # Files
751 #
752 $wgOut->addHTML("<fieldset>
753 <legend>" . wfMsg( 'files' ) . "</legend>
754 <div><label for='wpImageSize'>" . wfMsg('imagemaxsize') . "</label> <select id='wpImageSize' name='wpImageSize'>");
755
756 $imageLimitOptions = null;
757 foreach ( $wgImageLimits as $index => $limits ) {
758 $selected = ($index == $this->mImageSize) ? 'selected="selected"' : '';
759 $imageLimitOptions .= "<option value=\"{$index}\" {$selected}>{$limits[0]}ร—{$limits[1]}". wfMsgHtml('unit-pixel') ."</option>\n";
760 }
761
762 $imageThumbOptions = null;
763 $wgOut->addHTML( "{$imageLimitOptions}</select></div>
764 <div><label for='wpThumbSize'>" . wfMsg('thumbsize') . "</label> <select name='wpThumbSize' id='wpThumbSize'>");
765 foreach ( $wgThumbLimits as $index => $size ) {
766 $selected = ($index == $this->mThumbSize) ? 'selected="selected"' : '';
767 $imageThumbOptions .= "<option value=\"{$index}\" {$selected}>{$size}". wfMsgHtml('unit-pixel') ."</option>\n";
768 }
769 $wgOut->addHTML( "{$imageThumbOptions}</select></div></fieldset>\n\n");
770
771 # Date format
772 #
773 # Date/Time
774 #
775
776 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'datetime' ) . "</legend>\n" );
777
778 if ($dateopts) {
779 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'dateformat' ) . "</legend>\n" );
780 $idCnt = 0;
781 $epoch = '20010115161234';
782 foreach($dateopts as $key => $option) {
783 if( $key == MW_DATE_DEFAULT ) {
784 $formatted = wfMsgHtml( 'datedefault' );
785 } else {
786 $formatted = htmlspecialchars( $wgLang->timeanddate( $epoch, false, $key ) );
787 }
788 ($key == $this->mDate) ? $checked = ' checked="checked"' : $checked = '';
789 $wgOut->addHTML( "<div><input type='radio' name=\"wpDate\" id=\"wpDate$idCnt\" ".
790 "value=\"$key\"$checked /> <label for=\"wpDate$idCnt\">$formatted</label></div>\n" );
791 $idCnt++;
792 }
793 $wgOut->addHTML( "</fieldset>\n" );
794 }
795
796 $nowlocal = $wgLang->time( $now = wfTimestampNow(), true );
797 $nowserver = $wgLang->time( $now, false );
798
799 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'timezonelegend' ). '</legend><table>' .
800 $this->addRow( wfMsg( 'servertime' ), $nowserver ) .
801 $this->addRow( wfMsg( 'localtime' ), $nowlocal ) .
802 $this->addRow(
803 '<label for="wpHourDiff">' . wfMsg( 'timezoneoffset' ) . '</label>',
804 "<input type='text' name='wpHourDiff' id='wpHourDiff' value=\"" . htmlspecialchars( $this->mHourDiff ) . "\" size='6' />"
805 ) . "<tr><td colspan='2'>
806 <input type='button' value=\"" . wfMsg( 'guesstimezone' ) ."\"
807 onclick='javascript:guessTimezone()' id='guesstimezonebutton' style='display:none;' />
808 </td></tr></table></fieldset>
809 <div class='prefsectiontip'>ยน" . wfMsg( 'timezonetext' ) . "</div>
810 </fieldset>\n\n" );
811
812 # Editing
813 #
814 global $wgLivePreview, $wgUseRCPatrol;
815 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'textboxsize' ) . '</legend>
816 <div>
817 <label for="wpRows">' . wfMsg( 'rows' ) . "</label> <input type='text' name='wpRows' id='wpRows' value=\"{$this->mRows}\" size='3' />
818 <label for='wpCols'>" . wfMsg( 'columns' ) . "</label> <input type='text' name='wpCols' id='wpCols' value=\"{$this->mCols}\" size='3' />
819 </div>" .
820 $this->getToggles( array(
821 'editsection',
822 'editsectiononrightclick',
823 'editondblclick',
824 'editwidth',
825 'showtoolbar',
826 'previewonfirst',
827 'previewontop',
828 'watchcreations',
829 'watchdefault',
830 'minordefault',
831 'externaleditor',
832 'externaldiff',
833 $wgLivePreview ? 'uselivepreview' : false,
834 $wgUser->isAllowed( 'patrol' ) && $wgUseRCPatrol ? 'autopatrol' : false,
835 'forceeditsummary',
836 ) ) . '</fieldset>'
837 );
838 $this->mUsedToggles['autopatrol'] = true; # Don't show this up for users who can't; the handler below is dumb and doesn't know it
839
840 $wgOut->addHTML( '<fieldset><legend>' . htmlspecialchars(wfMsg('prefs-rc')) . '</legend>' .
841 '<label for="wpRecent">' . wfMsg ( 'recentchangescount' ) .
842 "</label> <input type='text' name='wpRecent' id='wpRecent' value=\"$this->mRecent\" size='3' />" .
843 $this->getToggles( array(
844 'hideminor',
845 $wgRCShowWatchingUsers ? 'shownumberswatching' : false,
846 'usenewrc' )
847 ) . '</fieldset>'
848 );
849
850 # Watchlist
851 $wgOut->addHTML( '<fieldset><legend>' . wfMsgHtml( 'prefs-watchlist' ) . '</legend>' );
852
853 $wgOut->addHTML( '<label for="wpWatchlistDays">' . wfMsgHtml( 'prefs-watchlist-days' ) . '</label> ' );
854 $wgOut->addHTML( '<input type="text" name="wpWatchlistDays" id="wpWatchlistDays" value="' . $this->mWatchlistDays . '" size="3" />' );
855 $wgOut->addHTML( '<p></p>' ); # Spacing
856 $wgOut->addHTML( $this->getToggles( array( 'watchlisthideown' ) ) );
857
858 $wgOut->addHTML( '</fieldset>' );
859
860 # Search
861 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'searchresultshead' ) . '</legend><table>' .
862 $this->addRow(
863 '<label for="wpSearch">' . wfMsg( 'resultsperpage' ) . '</label>',
864 "<input type='text' name='wpSearch' id='wpSearch' value=\"$this->mSearch\" size='4' />"
865 ) .
866 $this->addRow(
867 '<label for="wpSearchLines">' . wfMsg( 'contextlines' ) . '</label>',
868 "<input type='text' name='wpSearchLines' id='wpSearchLines' value=\"$this->mSearchLines\" size='4' />"
869 ) .
870 $this->addRow(
871 '<label for="wpSearchChars">' . wfMsg( 'contextchars' ) . '</label>',
872 "<input type='text' name='wpSearchChars' id='wpSearchChars' value=\"$this->mSearchChars\" size='4' />"
873 ) .
874 "</table><fieldset><legend>" . wfMsg( 'defaultns' ) . "</legend>$ps</fieldset></fieldset>" );
875
876 # Misc
877 #
878 $wgOut->addHTML('<fieldset><legend>' . wfMsg('prefs-misc') . '</legend>');
879 $wgOut->addHTML(
880 '<label for="wpStubs">' . htmlspecialchars ( wfMsg ( 'stubthreshold' ) ) . '</label>' .
881 " <input type='text' name='wpStubs' id='wpStubs' value=\"$this->mStubs\" size='6' />"
882 );
883 $msgUnderline = htmlspecialchars( wfMsg ( 'tog-underline' ) );
884 $msgUnderlinenever = htmlspecialchars( wfMsg ( 'underline-never' ) );
885 $msgUnderlinealways = htmlspecialchars( wfMsg ( 'underline-always' ) );
886 $msgUnderlinedefault = htmlspecialchars( wfMsg ( 'underline-default' ) );
887 $uopt = $wgUser->getOption("underline");
888 $s0 = $uopt == 0 ? ' selected="selected"' : '';
889 $s1 = $uopt == 1 ? ' selected="selected"' : '';
890 $s2 = $uopt == 2 ? ' selected="selected"' : '';
891 $wgOut->addHTML("
892 <div class='toggle'><label for='wpOpunderline'>$msgUnderline</label>
893 <select name='wpOpunderline' id='wpOpunderline'>
894 <option value=\"0\"$s0>$msgUnderlinenever</option>
895 <option value=\"1\"$s1>$msgUnderlinealways</option>
896 <option value=\"2\"$s2>$msgUnderlinedefault</option>
897 </select>
898 </div>
899 ");
900 foreach ( $togs as $tname ) {
901 if( !array_key_exists( $tname, $this->mUsedToggles ) ) {
902 $wgOut->addHTML( $this->getToggle( $tname ) );
903 }
904 }
905 $wgOut->addHTML( '</fieldset>' );
906
907 $token = $wgUser->editToken();
908 $wgOut->addHTML( "
909 <div id='prefsubmit'>
910 <div>
911 <input type='submit' name='wpSaveprefs' class='btnSavePrefs' value=\"" . wfMsgHtml( 'saveprefs' ) . "\" accesskey=\"".
912 wfMsgHtml('accesskey-save')."\" title=\"".wfMsgHtml('tooltip-save')."\" />
913 <input type='submit' name='wpReset' value=\"" . wfMsgHtml( 'resetprefs' ) . "\" />
914 </div>
915
916 </div>
917
918 <input type='hidden' name='wpEditToken' value='{$token}' />
919 </div></form>\n" );
920
921 $wgOut->addWikiText( '<div class="prefcache">' . wfMsg('clearyourcache') . '</div>' );
922
923 }
924 }
925 ?>