8b972b01a64ff28d80502b3c52b452cbeaac5dfe
[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->errorpage( '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 if ($wgAllowRealName || $wgEnableEmail) {
695 $wgOut->addHTML("<div class='prefsectiontip'>");
696 $rn = $wgAllowRealName ? wfMsg('prefs-help-realname') : '';
697 $em = $wgEnableEmail ? '<br />' . wfMsg('prefs-help-email') : '';
698 $wgOut->addHTML( $rn . $em . '</div>');
699 }
700
701 $wgOut->addHTML( '</fieldset>' );
702
703 # Quickbar
704 #
705 if ($this->mSkin == 'cologneblue' || $this->mSkin == 'standard') {
706 $wgOut->addHtml( "<fieldset>\n<legend>" . wfMsg( 'qbsettings' ) . "</legend>\n" );
707 for ( $i = 0; $i < count( $qbs ); ++$i ) {
708 if ( $i == $this->mQuickbar ) { $checked = ' checked="checked"'; }
709 else { $checked = ""; }
710 $wgOut->addHTML( "<div><label><input type='radio' name='wpQuickbar' value=\"$i\"$checked />{$qbs[$i]}</label></div>\n" );
711 }
712 $wgOut->addHtml( "</fieldset>\n\n" );
713 } else {
714 # Need to output a hidden option even if the relevant skin is not in use,
715 # otherwise the preference will get reset to 0 on submit
716 $wgOut->addHTML( "<input type='hidden' name='wpQuickbar' value='{$this->mQuickbar}' />" );
717 }
718
719 # Skin
720 #
721 $wgOut->addHTML( "<fieldset>\n<legend>\n" . wfMsg('skin') . "</legend>\n" );
722 $mptitle = Title::newMainPage();
723 $previewtext = wfMsg('skinpreview');
724 # Only show members of $wgValidSkinNames rather than
725 # $skinNames (skins is all skin names from Language.php)
726 foreach ($wgValidSkinNames as $skinkey => $skinname ) {
727 if ( in_array( $skinkey, $wgSkipSkins ) ) {
728 continue;
729 }
730 $checked = $skinkey == $this->mSkin ? ' checked="checked"' : '';
731 $sn = isset( $skinNames[$skinkey] ) ? $skinNames[$skinkey] : $skinname;
732
733 $mplink = htmlspecialchars($mptitle->getLocalURL("useskin=$skinkey"));
734 $previewlink = "<a target='_blank' href=\"$mplink\">$previewtext</a>";
735 if( $skinkey == $wgDefaultSkin )
736 $sn .= ' (' . wfMsg( 'default' ) . ')';
737 $wgOut->addHTML( "<input type='radio' name='wpSkin' id=\"wpSkin$skinkey\" value=\"$skinkey\"$checked /> <label for=\"wpSkin$skinkey\">{$sn}</label> $previewlink<br/>\n" );
738 }
739 $wgOut->addHTML( "</fieldset>\n\n" );
740
741 # Math
742 #
743 global $wgUseTeX;
744 if( $wgUseTeX ) {
745 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg('math') . '</legend>' );
746 foreach ( $mathopts as $k => $v ) {
747 $checked = $k == $this->mMath ? ' checked="checked"' : '';
748 $wgOut->addHTML( "<div><label><input type='radio' name='wpMath' value=\"$k\"$checked /> ".wfMsg($v)."</label></div>\n" );
749 }
750 $wgOut->addHTML( "</fieldset>\n\n" );
751 }
752
753 # Files
754 #
755 $wgOut->addHTML("<fieldset>
756 <legend>" . wfMsg( 'files' ) . "</legend>
757 <div><label for='wpImageSize'>" . wfMsg('imagemaxsize') . "</label> <select id='wpImageSize' name='wpImageSize'>");
758
759 $imageLimitOptions = null;
760 foreach ( $wgImageLimits as $index => $limits ) {
761 $selected = ($index == $this->mImageSize) ? 'selected="selected"' : '';
762 $imageLimitOptions .= "<option value=\"{$index}\" {$selected}>{$limits[0]}ร—{$limits[1]}". wfMsgHtml('unit-pixel') ."</option>\n";
763 }
764
765 $imageThumbOptions = null;
766 $wgOut->addHTML( "{$imageLimitOptions}</select></div>
767 <div><label for='wpThumbSize'>" . wfMsg('thumbsize') . "</label> <select name='wpThumbSize' id='wpThumbSize'>");
768 foreach ( $wgThumbLimits as $index => $size ) {
769 $selected = ($index == $this->mThumbSize) ? 'selected="selected"' : '';
770 $imageThumbOptions .= "<option value=\"{$index}\" {$selected}>{$size}". wfMsgHtml('unit-pixel') ."</option>\n";
771 }
772 $wgOut->addHTML( "{$imageThumbOptions}</select></div></fieldset>\n\n");
773
774 # Date format
775 #
776 # Date/Time
777 #
778
779 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'datetime' ) . "</legend>\n" );
780
781 if ($dateopts) {
782 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'dateformat' ) . "</legend>\n" );
783 $idCnt = 0;
784 $epoch = '20010408091234';
785 foreach($dateopts as $key => $option) {
786 if( $key == MW_DATE_DEFAULT ) {
787 $formatted = wfMsgHtml( 'datedefault' );
788 } else {
789 $formatted = htmlspecialchars( $wgLang->timeanddate( $epoch, false, $key ) );
790 }
791 ($key == $this->mDate) ? $checked = ' checked="checked"' : $checked = '';
792 $wgOut->addHTML( "<div><input type='radio' name=\"wpDate\" id=\"wpDate$idCnt\" ".
793 "value=\"$key\"$checked /> <label for=\"wpDate$idCnt\">$formatted</label></div>\n" );
794 $idCnt++;
795 }
796 $wgOut->addHTML( "</fieldset>\n" );
797 }
798
799 $nowlocal = $wgLang->time( $now = wfTimestampNow(), true );
800 $nowserver = $wgLang->time( $now, false );
801
802 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'timezonelegend' ). '</legend><table>' .
803 $this->addRow( wfMsg( 'servertime' ), $nowserver ) .
804 $this->addRow( wfMsg( 'localtime' ), $nowlocal ) .
805 $this->addRow(
806 '<label for="wpHourDiff">' . wfMsg( 'timezoneoffset' ) . '</label>',
807 "<input type='text' name='wpHourDiff' id='wpHourDiff' value=\"" . htmlspecialchars( $this->mHourDiff ) . "\" size='6' />"
808 ) . "<tr><td colspan='2'>
809 <input type='button' value=\"" . wfMsg( 'guesstimezone' ) ."\"
810 onclick='javascript:guessTimezone()' id='guesstimezonebutton' style='display:none;' />
811 </td></tr></table></fieldset>
812 <div class='prefsectiontip'>ยน" . wfMsg( 'timezonetext' ) . "</div>
813 </fieldset>\n\n" );
814
815 # Editing
816 #
817 global $wgLivePreview, $wgUseRCPatrol;
818 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'textboxsize' ) . '</legend>
819 <div>
820 <label for="wpRows">' . wfMsg( 'rows' ) . "</label> <input type='text' name='wpRows' id='wpRows' value=\"{$this->mRows}\" size='3' />
821 <label for='wpCols'>" . wfMsg( 'columns' ) . "</label> <input type='text' name='wpCols' id='wpCols' value=\"{$this->mCols}\" size='3' />
822 </div>" .
823 $this->getToggles( array(
824 'editsection',
825 'editsectiononrightclick',
826 'editondblclick',
827 'editwidth',
828 'showtoolbar',
829 'previewonfirst',
830 'previewontop',
831 'watchcreations',
832 'watchdefault',
833 'minordefault',
834 'externaleditor',
835 'externaldiff',
836 $wgLivePreview ? 'uselivepreview' : false,
837 $wgUser->isAllowed( 'patrol' ) && $wgUseRCPatrol ? 'autopatrol' : false,
838 'forceeditsummary',
839 ) ) . '</fieldset>'
840 );
841 $this->mUsedToggles['autopatrol'] = true; # Don't show this up for users who can't; the handler below is dumb and doesn't know it
842
843 $wgOut->addHTML( '<fieldset><legend>' . htmlspecialchars(wfMsg('prefs-rc')) . '</legend>' .
844 '<label for="wpRecent">' . wfMsg ( 'recentchangescount' ) .
845 "</label> <input type='text' name='wpRecent' id='wpRecent' value=\"$this->mRecent\" size='3' />" .
846 $this->getToggles( array(
847 'hideminor',
848 $wgRCShowWatchingUsers ? 'shownumberswatching' : false,
849 'usenewrc' )
850 ) . '</fieldset>'
851 );
852
853 # Watchlist
854 $wgOut->addHTML( '<fieldset><legend>' . wfMsgHtml( 'prefs-watchlist' ) . '</legend>' );
855
856 $wgOut->addHTML( '<label for="wpWatchlistDays">' . wfMsgHtml( 'prefs-watchlist-days' ) . '</label> ' );
857 $wgOut->addHTML( '<input type="text" name="wpWatchlistDays" id="wpWatchlistDays" value="' . $this->mWatchlistDays . '" size="3" />' );
858 $wgOut->addHTML( '<br /><br />' ); # Spacing
859 $wgOut->addHTML( $this->getToggles( array( 'watchlisthideown', 'watchlisthidebots', 'extendwatchlist' ) ) );
860 $wgOut->addHTML( '<label for="wpWatchlistEdits">' . wfMsgHtml( 'prefs-watchlist-edits' ) . '</label> ' );
861 $wgOut->addHTML( '<input type="text" name="wpWatchlistEdits" id="wpWatchlistEdits" value="' . $this->mWatchlistEdits . '" size="3" />' );
862
863 $wgOut->addHTML( '</fieldset>' );
864
865 # Search
866 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'searchresultshead' ) . '</legend><table>' .
867 $this->addRow(
868 '<label for="wpSearch">' . wfMsg( 'resultsperpage' ) . '</label>',
869 "<input type='text' name='wpSearch' id='wpSearch' value=\"$this->mSearch\" size='4' />"
870 ) .
871 $this->addRow(
872 '<label for="wpSearchLines">' . wfMsg( 'contextlines' ) . '</label>',
873 "<input type='text' name='wpSearchLines' id='wpSearchLines' value=\"$this->mSearchLines\" size='4' />"
874 ) .
875 $this->addRow(
876 '<label for="wpSearchChars">' . wfMsg( 'contextchars' ) . '</label>',
877 "<input type='text' name='wpSearchChars' id='wpSearchChars' value=\"$this->mSearchChars\" size='4' />"
878 ) .
879 "</table><fieldset><legend>" . wfMsg( 'defaultns' ) . "</legend>$ps</fieldset></fieldset>" );
880
881 # Misc
882 #
883 $wgOut->addHTML('<fieldset><legend>' . wfMsg('prefs-misc') . '</legend>');
884 $wgOut->addHTML(
885 '<label for="wpStubs">' . htmlspecialchars ( wfMsg ( 'stubthreshold' ) ) . '</label>' .
886 " <input type='text' name='wpStubs' id='wpStubs' value=\"$this->mStubs\" size='6' />"
887 );
888 $msgUnderline = htmlspecialchars( wfMsg ( 'tog-underline' ) );
889 $msgUnderlinenever = htmlspecialchars( wfMsg ( 'underline-never' ) );
890 $msgUnderlinealways = htmlspecialchars( wfMsg ( 'underline-always' ) );
891 $msgUnderlinedefault = htmlspecialchars( wfMsg ( 'underline-default' ) );
892 $uopt = $wgUser->getOption("underline");
893 $s0 = $uopt == 0 ? ' selected="selected"' : '';
894 $s1 = $uopt == 1 ? ' selected="selected"' : '';
895 $s2 = $uopt == 2 ? ' selected="selected"' : '';
896 $wgOut->addHTML("
897 <div class='toggle'><label for='wpOpunderline'>$msgUnderline</label>
898 <select name='wpOpunderline' id='wpOpunderline'>
899 <option value=\"0\"$s0>$msgUnderlinenever</option>
900 <option value=\"1\"$s1>$msgUnderlinealways</option>
901 <option value=\"2\"$s2>$msgUnderlinedefault</option>
902 </select>
903 </div>
904 ");
905 foreach ( $togs as $tname ) {
906 if( !array_key_exists( $tname, $this->mUsedToggles ) ) {
907 $wgOut->addHTML( $this->getToggle( $tname ) );
908 }
909 }
910 $wgOut->addHTML( '</fieldset>' );
911
912 $token = $wgUser->editToken();
913 $wgOut->addHTML( "
914 <div id='prefsubmit'>
915 <div>
916 <input type='submit' name='wpSaveprefs' class='btnSavePrefs' value=\"" . wfMsgHtml( 'saveprefs' ) . "\" accesskey=\"".
917 wfMsgHtml('accesskey-save')."\" title=\"".wfMsgHtml('tooltip-save')."\" />
918 <input type='submit' name='wpReset' value=\"" . wfMsgHtml( 'resetprefs' ) . "\" />
919 </div>
920
921 </div>
922
923 <input type='hidden' name='wpEditToken' value='{$token}' />
924 </div></form>\n" );
925
926 $wgOut->addWikiText( '<div class="prefcache">' . wfMsg('clearyourcache') . '</div>' );
927
928 }
929 }
930 ?>