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