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