970e3436ea652095a39a2966169ade7373abb568
[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 $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 = User::getToggles();
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 ) {
160 global $wgLang, $wgContLang;
161 if ( $val !== false && (
162 in_array( $val, (array)$wgLang->getDatePreferences() ) ||
163 in_array( $val, (array)$wgContLang->getDatePreferences() ) ) )
164 {
165 return $val;
166 } else {
167 return $wgLang->getDefaultDateFormat();
168 }
169 }
170
171 /**
172 * Used to validate the user inputed timezone before saving it as
173 * 'timeciorrection', will return '00:00' if fed bogus data.
174 * Note: It's not a 100% correct implementation timezone-wise, it will
175 * accept stuff like '14:30',
176 * @access private
177 * @param string $s the user input
178 * @return string
179 */
180 function validateTimeZone( $s ) {
181 if ( $s !== '' ) {
182 if ( strpos( $s, ':' ) ) {
183 # HH:MM
184 $array = explode( ':' , $s );
185 $hour = intval( $array[0] );
186 $minute = intval( $array[1] );
187 } else {
188 $minute = intval( $s * 60 );
189 $hour = intval( $minute / 60 );
190 $minute = abs( $minute ) % 60;
191 }
192 # Max is +14:00 and min is -12:00, see:
193 # http://en.wikipedia.org/wiki/Timezone
194 $hour = min( $hour, 14 );
195 $hour = max( $hour, -12 );
196 $minute = min( $minute, 59 );
197 $minute = max( $minute, 0 );
198 $s = sprintf( "%02d:%02d", $hour, $minute );
199 }
200 return $s;
201 }
202
203 /**
204 * @access private
205 */
206 function savePreferences() {
207 global $wgUser, $wgOut, $wgParser;
208 global $wgEnableUserEmail, $wgEnableEmail;
209 global $wgEmailAuthentication;
210 global $wgAuth;
211
212
213 if ( '' != $this->mNewpass && $wgAuth->allowPasswordChange() ) {
214 if ( $this->mNewpass != $this->mRetypePass ) {
215 $this->mainPrefsForm( 'error', wfMsg( 'badretype' ) );
216 return;
217 }
218
219 if (!$wgUser->checkPassword( $this->mOldpass )) {
220 $this->mainPrefsForm( 'error', wfMsg( 'wrongpassword' ) );
221 return;
222 }
223
224 try {
225 $wgUser->setPassword( $this->mNewpass );
226 $this->mNewpass = $this->mOldpass = $this->mRetypePass = '';
227 } catch( PasswordError $e ) {
228 $this->mainPrefsForm( 'error', $e->getMessage() );
229 return;
230 }
231 }
232 $wgUser->setRealName( $this->mRealName );
233
234 if( $wgUser->getOption( 'language' ) !== $this->mUserLanguage ) {
235 $needRedirect = true;
236 } else {
237 $needRedirect = false;
238 }
239
240 # Validate the signature and clean it up as needed
241 if( $this->mToggles['fancysig'] ) {
242 if( Parser::validateSig( $this->mNick ) !== false ) {
243 $this->mNick = $wgParser->cleanSig( $this->mNick );
244 } else {
245 $this->mainPrefsForm( 'error', wfMsg( 'badsig' ) );
246 }
247 } else {
248 // When no fancy sig used, make sure ~{3,5} get removed.
249 $this->mNick = $wgParser->cleanSigInSig( $this->mNick );
250 }
251
252 $wgUser->setOption( 'language', $this->mUserLanguage );
253 $wgUser->setOption( 'variant', $this->mUserVariant );
254 $wgUser->setOption( 'nickname', $this->mNick );
255 $wgUser->setOption( 'quickbar', $this->mQuickbar );
256 $wgUser->setOption( 'skin', $this->mSkin );
257 global $wgUseTeX;
258 if( $wgUseTeX ) {
259 $wgUser->setOption( 'math', $this->mMath );
260 }
261 $wgUser->setOption( 'date', $this->validateDate( $this->mDate ) );
262 $wgUser->setOption( 'searchlimit', $this->validateIntOrNull( $this->mSearch ) );
263 $wgUser->setOption( 'contextlines', $this->validateIntOrNull( $this->mSearchLines ) );
264 $wgUser->setOption( 'contextchars', $this->validateIntOrNull( $this->mSearchChars ) );
265 $wgUser->setOption( 'rclimit', $this->validateIntOrNull( $this->mRecent ) );
266 $wgUser->setOption( 'wllimit', $this->validateIntOrNull( $this->mWatchlistEdits, 0, 1000 ) );
267 $wgUser->setOption( 'rows', $this->validateInt( $this->mRows, 4, 1000 ) );
268 $wgUser->setOption( 'cols', $this->validateInt( $this->mCols, 4, 1000 ) );
269 $wgUser->setOption( 'stubthreshold', $this->validateIntOrNull( $this->mStubs ) );
270 $wgUser->setOption( 'timecorrection', $this->validateTimeZone( $this->mHourDiff, -12, 14 ) );
271 $wgUser->setOption( 'imagesize', $this->mImageSize );
272 $wgUser->setOption( 'thumbsize', $this->mThumbSize );
273 $wgUser->setOption( 'underline', $this->validateInt($this->mUnderline, 0, 2) );
274 $wgUser->setOption( 'watchlistdays', $this->validateFloat( $this->mWatchlistDays, 0, 7 ) );
275
276 # Set search namespace options
277 foreach( $this->mSearchNs as $i => $value ) {
278 $wgUser->setOption( "searchNs{$i}", $value );
279 }
280
281 if( $wgEnableEmail && $wgEnableUserEmail ) {
282 $wgUser->setOption( 'disablemail', $this->mEmailFlag );
283 }
284
285 # Set user toggles
286 foreach ( $this->mToggles as $tname => $tvalue ) {
287 $wgUser->setOption( $tname, $tvalue );
288 }
289 if (!$wgAuth->updateExternalDB($wgUser)) {
290 $this->mainPrefsForm( wfMsg( 'externaldberror' ) );
291 return;
292 }
293 $wgUser->setCookies();
294 $wgUser->saveSettings();
295
296 $error = false;
297 if( $wgEnableEmail ) {
298 $newadr = $this->mUserEmail;
299 $oldadr = $wgUser->getEmail();
300 if( ($newadr != '') && ($newadr != $oldadr) ) {
301 # the user has supplied a new email address on the login page
302 if( $wgUser->isValidEmailAddr( $newadr ) ) {
303 $wgUser->mEmail = $newadr; # new behaviour: set this new emailaddr from login-page into user database record
304 $wgUser->mEmailAuthenticated = null; # but flag as "dirty" = unauthenticated
305 $wgUser->saveSettings();
306 if ($wgEmailAuthentication) {
307 # Mail a temporary password to the dirty address.
308 # User can come back through the confirmation URL to re-enable email.
309 $result = $wgUser->sendConfirmationMail();
310 if( WikiError::isError( $result ) ) {
311 $error = wfMsg( 'mailerror', htmlspecialchars( $result->getMessage() ) );
312 } else {
313 $error = wfMsg( 'eauthentsent', $wgUser->getName() );
314 }
315 }
316 } else {
317 $error = wfMsg( 'invalidemailaddress' );
318 }
319 } else {
320 $wgUser->setEmail( $this->mUserEmail );
321 $wgUser->setCookies();
322 $wgUser->saveSettings();
323 }
324 }
325
326 if( $needRedirect && $error === false ) {
327 $title =& SpecialPage::getTitleFor( "Preferences" );
328 $wgOut->redirect($title->getFullURL('success'));
329 return;
330 }
331
332 $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
333 $this->mainPrefsForm( $error === false ? 'success' : 'error', $error);
334 }
335
336 /**
337 * @access private
338 */
339 function resetPrefs() {
340 global $wgUser, $wgLang, $wgContLang, $wgContLanguageCode, $wgAllowRealName;
341
342 $this->mOldpass = $this->mNewpass = $this->mRetypePass = '';
343 $this->mUserEmail = $wgUser->getEmail();
344 $this->mUserEmailAuthenticationtimestamp = $wgUser->getEmailAuthenticationtimestamp();
345 $this->mRealName = ($wgAllowRealName) ? $wgUser->getRealName() : '';
346
347 # language value might be blank, default to content language
348 $this->mUserLanguage = $wgUser->getOption( 'language', $wgContLanguageCode );
349
350 $this->mUserVariant = $wgUser->getOption( 'variant');
351 $this->mEmailFlag = $wgUser->getOption( 'disablemail' ) == 1 ? 1 : 0;
352 $this->mNick = $wgUser->getOption( 'nickname' );
353
354 $this->mQuickbar = $wgUser->getOption( 'quickbar' );
355 $this->mSkin = Skin::normalizeKey( $wgUser->getOption( 'skin' ) );
356 $this->mMath = $wgUser->getOption( 'math' );
357 $this->mDate = $wgUser->getDatePreference();
358 $this->mRows = $wgUser->getOption( 'rows' );
359 $this->mCols = $wgUser->getOption( 'cols' );
360 $this->mStubs = $wgUser->getOption( 'stubthreshold' );
361 $this->mHourDiff = $wgUser->getOption( 'timecorrection' );
362 $this->mSearch = $wgUser->getOption( 'searchlimit' );
363 $this->mSearchLines = $wgUser->getOption( 'contextlines' );
364 $this->mSearchChars = $wgUser->getOption( 'contextchars' );
365 $this->mImageSize = $wgUser->getOption( 'imagesize' );
366 $this->mThumbSize = $wgUser->getOption( 'thumbsize' );
367 $this->mRecent = $wgUser->getOption( 'rclimit' );
368 $this->mWatchlistEdits = $wgUser->getOption( 'wllimit' );
369 $this->mUnderline = $wgUser->getOption( 'underline' );
370 $this->mWatchlistDays = $wgUser->getOption( 'watchlistdays' );
371
372 $togs = User::getToggles();
373 foreach ( $togs as $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;
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, $wgAuth;
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->getDatePreferences();
471 $togs = User::getToggles();
472
473 $titleObj = SpecialPage::getTitleFor( '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[ 'ccmeonemails' ] = true;
484 $this->mUsedToggles[ 'uselivepreview' ] = true;
485
486 # Enotif
487 # <FIXME>
488 $this->mUserEmail = htmlspecialchars( $this->mUserEmail );
489 $this->mRealName = htmlspecialchars( $this->mRealName );
490 $rawNick = $this->mNick;
491 $this->mNick = htmlspecialchars( $this->mNick );
492 if ( !$this->mEmailFlag ) { $emfc = 'checked="checked"'; }
493 else { $emfc = ''; }
494
495
496 if ($wgEmailAuthentication && ($this->mUserEmail != '') ) {
497 if( $wgUser->getEmailAuthenticationTimestamp() ) {
498 $emailauthenticated = wfMsg('emailauthenticated',$wgLang->timeanddate($wgUser->getEmailAuthenticationTimestamp(), true ) ).'<br />';
499 $disableEmailPrefs = false;
500 } else {
501 $disableEmailPrefs = true;
502 $skin = $wgUser->getSkin();
503 $emailauthenticated = wfMsg('emailnotauthenticated').'<br />' .
504 $skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Confirmemail' ),
505 wfMsg( 'emailconfirmlink' ) );
506 }
507 } else {
508 $emailauthenticated = '';
509 $disableEmailPrefs = false;
510 }
511
512 if ($this->mUserEmail == '') {
513 $emailauthenticated = wfMsg( 'noemailprefs' );
514 }
515
516 $ps = $this->namespacesCheckboxes();
517
518 $enotifwatchlistpages = ($wgEnotifWatchlist) ? $this->getToggle( 'enotifwatchlistpages', false, $disableEmailPrefs ) : '';
519 $enotifusertalkpages = ($wgEnotifUserTalk) ? $this->getToggle( 'enotifusertalkpages', false, $disableEmailPrefs ) : '';
520 $enotifminoredits = ($wgEnotifWatchlist && $wgEnotifMinorEdits) ? $this->getToggle( 'enotifminoredits', false, $disableEmailPrefs ) : '';
521 $enotifrevealaddr = (($wgEnotifWatchlist || $wgEnotifUserTalk) && $wgEnotifRevealEditorAddress) ? $this->getToggle( 'enotifrevealaddr', false, $disableEmailPrefs ) : '';
522
523 # </FIXME>
524
525 $wgOut->addHTML( "<form action=\"$action\" method='post'>" );
526 $wgOut->addHTML( "<div id='preferences'>" );
527
528 # User data
529 #
530
531 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg('prefs-personal') . "</legend>\n<table>\n");
532
533 $userInformationHtml =
534 $this->addRow(
535 wfMsg( 'username'),
536 $wgUser->getName()
537 ) .
538 $this->addRow(
539 wfMsg( 'uid' ),
540 $wgUser->getID()
541 );
542
543 if( wfRunHooks( 'PreferencesUserInformationPanel', array( $this, &$userInformationHtml ) ) ) {
544 $wgOut->addHtml( $userInformationHtml );
545 }
546
547
548 if ($wgAllowRealName) {
549 $wgOut->addHTML(
550 $this->addRow(
551 '<label for="wpRealName">' . wfMsg('yourrealname') . '</label>',
552 "<input type='text' name='wpRealName' id='wpRealName' value=\"{$this->mRealName}\" size='25' />"
553 )
554 );
555 }
556 if ($wgEnableEmail) {
557 $wgOut->addHTML(
558 $this->addRow(
559 '<label for="wpUserEmail">' . wfMsg( 'youremail' ) . '</label>',
560 "<input type='text' name='wpUserEmail' id='wpUserEmail' value=\"{$this->mUserEmail}\" size='25' />"
561 )
562 );
563 }
564
565 global $wgParser;
566 if( !empty( $this->mToggles['fancysig'] ) &&
567 false === $wgParser->validateSig( $rawNick ) ) {
568 $invalidSig = $this->addRow(
569 '&nbsp;',
570 '<span class="error">' . wfMsgHtml( 'badsig' ) . '<span>'
571 );
572 } else {
573 $invalidSig = '';
574 }
575
576 $wgOut->addHTML(
577 $this->addRow(
578 '<label for="wpNick">' . wfMsg( 'yournick' ) . '</label>',
579 "<input type='text' name='wpNick' id='wpNick' value=\"{$this->mNick}\" size='25' />"
580 ) .
581 $invalidSig .
582 # FIXME: The <input> part should be where the &nbsp; is, getToggle() needs
583 # to be changed to out return its output in two parts. -รฆvar
584 $this->addRow(
585 '&nbsp;',
586 $this->getToggle( 'fancysig' )
587 )
588 );
589
590 /**
591 * Make sure the site language is in the list; a custom language code
592 * might not have a defined name...
593 */
594 $languages = Language::getLanguageNames( true );
595 if( !array_key_exists( $wgContLanguageCode, $languages ) ) {
596 $languages[$wgContLanguageCode] = $wgContLanguageCode;
597 }
598 ksort( $languages );
599
600 /**
601 * If a bogus value is set, default to the content language.
602 * Otherwise, no default is selected and the user ends up
603 * with an Afrikaans interface since it's first in the list.
604 */
605 $selectedLang = isset( $languages[$this->mUserLanguage] ) ? $this->mUserLanguage : $wgContLanguageCode;
606 $options = "\n";
607 foreach( $languages as $code => $name ) {
608 $selected = ($code == $selectedLang);
609 $options .= Xml::option( "$code - $name", $code, $selected ) . "\n";
610 }
611 $wgOut->addHTML(
612 $this->addRow(
613 '<label for="wpUserLanguage">' . wfMsg('yourlanguage') . '</label>',
614 "<select name='wpUserLanguage' id='wpUserLanguage'>$options</select>"
615 )
616 );
617
618 /* see if there are multiple language variants to choose from*/
619 if(!$wgDisableLangConversion) {
620 $variants = $wgContLang->getVariants();
621 $variantArray = array();
622
623 foreach($variants as $v) {
624 $v = str_replace( '_', '-', strtolower($v));
625 if( array_key_exists( $v, $languages ) ) {
626 // If it doesn't have a name, we'll pretend it doesn't exist
627 $variantArray[$v] = $languages[$v];
628 }
629 }
630
631 $options = "\n";
632 foreach( $variantArray as $code => $name ) {
633 $selected = ($code == $this->mUserVariant);
634 $options .= Xml::option( "$code - $name", $code, $selected ) . "\n";
635 }
636
637 if(count($variantArray) > 1) {
638 $wgOut->addHtml(
639 $this->addRow( wfMsg( 'yourvariant' ),
640 "<select name='wpUserVariant'>$options</select>" )
641 );
642 }
643 }
644 $wgOut->addHTML('</table>');
645
646 # Password
647 if( $wgAuth->allowPasswordChange() ) {
648 $this->mOldpass = htmlspecialchars( $this->mOldpass );
649 $this->mNewpass = htmlspecialchars( $this->mNewpass );
650 $this->mRetypePass = htmlspecialchars( $this->mRetypePass );
651
652 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'changepassword' ) . '</legend><table>');
653 $wgOut->addHTML(
654 $this->addRow(
655 '<label for="wpOldpass">' . wfMsg( 'oldpassword' ) . '</label>',
656 "<input type='password' name='wpOldpass' id='wpOldpass' value=\"{$this->mOldpass}\" size='20' />"
657 ) .
658 $this->addRow(
659 '<label for="wpNewpass">' . wfMsg( 'newpassword' ) . '</label>',
660 "<input type='password' name='wpNewpass' id='wpNewpass' value=\"{$this->mNewpass}\" size='20' />"
661 ) .
662 $this->addRow(
663 '<label for="wpRetypePass">' . wfMsg( 'retypenew' ) . '</label>',
664 "<input type='password' name='wpRetypePass' id='wpRetypePass' value=\"{$this->mRetypePass}\" size='20' />"
665 ) .
666 "</table>\n" .
667 $this->getToggle( "rememberpassword" ) . "</fieldset>\n\n" );
668 }
669
670 # <FIXME>
671 # Enotif
672 if ($wgEnableEmail) {
673 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'email' ) . '</legend>' );
674 $wgOut->addHTML(
675 $emailauthenticated.
676 $enotifrevealaddr.
677 $enotifwatchlistpages.
678 $enotifusertalkpages.
679 $enotifminoredits );
680 if ($wgEnableUserEmail) {
681 $emf = wfMsg( 'allowemail' );
682 $disabled = $disableEmailPrefs ? ' disabled="disabled"' : '';
683 $wgOut->addHTML(
684 "<div><input type='checkbox' $emfc $disabled value='1' name='wpEmailFlag' id='wpEmailFlag' /> <label for='wpEmailFlag'>$emf</label></div>" );
685 }
686 $wgOut->addHtml( $this->getToggle( 'ccmeonemails' ) );
687
688 $wgOut->addHTML( '</fieldset>' );
689 }
690 # </FIXME>
691
692 # Show little "help" tips for the real name and email address options
693 if( $wgAllowRealName || $wgEnableEmail ) {
694 if( $wgAllowRealName )
695 $tips[] = wfMsg( 'prefs-help-realname' );
696 if( $wgEnableEmail )
697 $tips[] = wfMsg( 'prefs-help-email' );
698 $wgOut->addHtml( '<div class="prefsectiontip">' . implode( '<br />', $tips ) . '</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( wfHidden( 'wpQuickbar', $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 Skin::getSkinNames() rather than
725 # $skinNames (skins is all skin names from Language.php)
726 $validSkinNames = Skin::getSkinNames();
727 # Sort by UI skin name. First though need to update validSkinNames as sometimes
728 # the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI).
729 foreach ($validSkinNames as $skinkey => & $skinname ) {
730 if ( isset( $skinNames[$skinkey] ) ) {
731 $skinname = $skinNames[$skinkey];
732 }
733 }
734 asort($validSkinNames);
735 foreach ($validSkinNames as $skinkey => $sn ) {
736 if ( in_array( $skinkey, $wgSkipSkins ) ) {
737 continue;
738 }
739 $checked = $skinkey == $this->mSkin ? ' checked="checked"' : '';
740
741 $mplink = htmlspecialchars($mptitle->getLocalURL("useskin=$skinkey"));
742 $previewlink = "<a target='_blank' href=\"$mplink\">$previewtext</a>";
743 if( $skinkey == $wgDefaultSkin )
744 $sn .= ' (' . wfMsg( 'default' ) . ')';
745 $wgOut->addHTML( "<input type='radio' name='wpSkin' id=\"wpSkin$skinkey\" value=\"$skinkey\"$checked /> <label for=\"wpSkin$skinkey\">{$sn}</label> $previewlink<br />\n" );
746 }
747 $wgOut->addHTML( "</fieldset>\n\n" );
748
749 # Math
750 #
751 global $wgUseTeX;
752 if( $wgUseTeX ) {
753 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg('math') . '</legend>' );
754 foreach ( $mathopts as $k => $v ) {
755 $checked = $k == $this->mMath ? ' checked="checked"' : '';
756 $wgOut->addHTML( "<div><label><input type='radio' name='wpMath' value=\"$k\"$checked /> ".wfMsg($v)."</label></div>\n" );
757 }
758 $wgOut->addHTML( "</fieldset>\n\n" );
759 }
760
761 # Files
762 #
763 $wgOut->addHTML(
764 "<fieldset>\n" . Xml::element( 'legend', null, wfMsg( 'files' ) ) . "\n"
765 );
766
767 $imageLimitOptions = null;
768 foreach ( $wgImageLimits as $index => $limits ) {
769 $selected = ($index == $this->mImageSize);
770 $imageLimitOptions .= Xml::option( "{$limits[0]}ร—{$limits[1]}" .
771 wfMsg('unit-pixel'), $index, $selected );
772 }
773
774 $imageSizeId = 'wpImageSize';
775 $wgOut->addHTML(
776 "<div>" . Xml::label( wfMsg('imagemaxsize'), $imageSizeId ) . " " .
777 Xml::openElement( 'select', array( 'name' => $imageSizeId, 'id' => $imageSizeId ) ) .
778 $imageLimitOptions .
779 Xml::closeElement( 'select' ) . "</div>\n"
780 );
781
782 $imageThumbOptions = null;
783 foreach ( $wgThumbLimits as $index => $size ) {
784 $selected = ($index == $this->mThumbSize);
785 $imageThumbOptions .= Xml::option($size . wfMsg('unit-pixel'), $index,
786 $selected);
787 }
788
789 $thumbSizeId = 'wpThumbSize';
790 $wgOut->addHTML(
791 "<div>" . Xml::label( wfMsg('thumbsize'), $thumbSizeId ) . " " .
792 Xml::openElement( 'select', array( 'name' => $thumbSizeId, 'id' => $thumbSizeId ) ) .
793 $imageThumbOptions .
794 Xml::closeElement( 'select' ) . "</div>\n"
795 );
796
797 $wgOut->addHTML( "</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 = '20010115161234'; # Wikipedia day
810 foreach( $dateopts as $key ) {
811 if( $key == '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><div class='prefsectiontip'>ยน" . wfMsg( 'timezonetext' ) . "</div></fieldset>
837 </fieldset>\n\n" );
838
839 # Editing
840 #
841 global $wgLivePreview;
842 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'textboxsize' ) . '</legend>
843 <div>' .
844 wfInputLabel( wfMsg( 'rows' ), 'wpRows', 'wpRows', 3, $this->mRows ) .
845 ' ' .
846 wfInputLabel( wfMsg( 'columns' ), 'wpCols', 'wpCols', 3, $this->mCols ) .
847 "</div>" .
848 $this->getToggles( array(
849 'editsection',
850 'editsectiononrightclick',
851 'editondblclick',
852 'editwidth',
853 'showtoolbar',
854 'previewonfirst',
855 'previewontop',
856 'minordefault',
857 'externaleditor',
858 'externaldiff',
859 $wgLivePreview ? 'uselivepreview' : false,
860 'forceeditsummary',
861 ) ) . '</fieldset>'
862 );
863
864 $wgOut->addHTML( '<fieldset><legend>' . htmlspecialchars(wfMsg('prefs-rc')) . '</legend>' .
865 wfInputLabel( wfMsg( 'recentchangescount' ),
866 'wpRecent', 'wpRecent', 3, $this->mRecent ) .
867 $this->getToggles( array(
868 'hideminor',
869 $wgRCShowWatchingUsers ? 'shownumberswatching' : false,
870 'usenewrc' )
871 ) . '</fieldset>'
872 );
873
874 # Watchlist
875 $wgOut->addHtml( '<fieldset><legend>' . wfMsgHtml( 'prefs-watchlist' ) . '</legend>' );
876
877 $wgOut->addHtml( wfInputLabel( wfMsg( 'prefs-watchlist-days' ), 'wpWatchlistDays', 'wpWatchlistDays', 3, $this->mWatchlistDays ) );
878 $wgOut->addHtml( '<br /><br />' );
879
880 $wgOut->addHtml( $this->getToggle( 'extendwatchlist' ) );
881 $wgOut->addHtml( wfInputLabel( wfMsg( 'prefs-watchlist-edits' ), 'wpWatchlistEdits', 'wpWatchlistEdits', 3, $this->mWatchlistEdits ) );
882 $wgOut->addHtml( '<br /><br />' );
883
884 $wgOut->addHtml( $this->getToggles( array( 'watchlisthideown', 'watchlisthidebots', 'watchlisthideminor' ) ) );
885
886 if( $wgUser->isAllowed( 'createpage' ) || $wgUser->isAllowed( 'createtalk' ) )
887 $wgOut->addHtml( $this->getToggle( 'watchcreations' ) );
888 foreach( array( 'edit' => 'watchdefault', 'move' => 'watchmoves', 'delete' => 'watchdeletion' ) as $action => $toggle ) {
889 if( $wgUser->isAllowed( $action ) )
890 $wgOut->addHtml( $this->getToggle( $toggle ) );
891 }
892 $this->mUsedToggles['watchcreations'] = true;
893 $this->mUsedToggles['watchdefault'] = true;
894 $this->mUsedToggles['watchmoves'] = true;
895 $this->mUsedToggles['watchdeletion'] = true;
896
897 $wgOut->addHtml( '</fieldset>' );
898
899 # Search
900 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'searchresultshead' ) . '</legend><table>' .
901 $this->addRow(
902 wfLabel( wfMsg( 'resultsperpage' ), 'wpSearch' ),
903 wfInput( 'wpSearch', 4, $this->mSearch, array( 'id' => 'wpSearch' ) )
904 ) .
905 $this->addRow(
906 wfLabel( wfMsg( 'contextlines' ), 'wpSearchLines' ),
907 wfInput( 'wpSearchLines', 4, $this->mSearchLines, array( 'id' => 'wpSearchLines' ) )
908 ) .
909 $this->addRow(
910 wfLabel( wfMsg( 'contextchars' ), 'wpSearchChars' ),
911 wfInput( 'wpSearchChars', 4, $this->mSearchChars, array( 'id' => 'wpSearchChars' ) )
912 ) .
913 "</table><fieldset><legend>" . wfMsg( 'defaultns' ) . "</legend>$ps</fieldset></fieldset>" );
914
915 # Misc
916 #
917 $wgOut->addHTML('<fieldset><legend>' . wfMsg('prefs-misc') . '</legend>');
918 $wgOut->addHTML( wfInputLabel( wfMsg( 'stubthreshold' ),
919 'wpStubs', 'wpStubs', 6, $this->mStubs ) );
920 $msgUnderline = htmlspecialchars( wfMsg ( 'tog-underline' ) );
921 $msgUnderlinenever = htmlspecialchars( wfMsg ( 'underline-never' ) );
922 $msgUnderlinealways = htmlspecialchars( wfMsg ( 'underline-always' ) );
923 $msgUnderlinedefault = htmlspecialchars( wfMsg ( 'underline-default' ) );
924 $uopt = $wgUser->getOption("underline");
925 $s0 = $uopt == 0 ? ' selected="selected"' : '';
926 $s1 = $uopt == 1 ? ' selected="selected"' : '';
927 $s2 = $uopt == 2 ? ' selected="selected"' : '';
928 $wgOut->addHTML("
929 <div class='toggle'><p><label for='wpOpunderline'>$msgUnderline</label>
930 <select name='wpOpunderline' id='wpOpunderline'>
931 <option value=\"0\"$s0>$msgUnderlinenever</option>
932 <option value=\"1\"$s1>$msgUnderlinealways</option>
933 <option value=\"2\"$s2>$msgUnderlinedefault</option>
934 </select></p></div>");
935
936 foreach ( $togs as $tname ) {
937 if( !array_key_exists( $tname, $this->mUsedToggles ) ) {
938 $wgOut->addHTML( $this->getToggle( $tname ) );
939 }
940 }
941 $wgOut->addHTML( '</fieldset>' );
942
943 $token = $wgUser->editToken();
944 $skin = $wgUser->getSkin();
945 $wgOut->addHTML( "
946 <div id='prefsubmit'>
947 <div>
948 <input type='submit' name='wpSaveprefs' class='btnSavePrefs' value=\"" . wfMsgHtml( 'saveprefs' ) . '"'.$skin->tooltipAndAccesskey('save')." />
949 <input type='submit' name='wpReset' value=\"" . wfMsgHtml( 'resetprefs' ) . "\" />
950 </div>
951
952 </div>
953
954 <input type='hidden' name='wpEditToken' value='{$token}' />
955 </div></form>\n" );
956
957 $wgOut->addWikiText( '<div class="prefcache">' . wfMsg('clearyourcache') . '</div>' );
958
959 }
960 }
961 ?>