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