Revert r21461 for now; a cleanup patch which doesn't change functionality but makes...
[lhc/web/wiklou.git] / includes / SpecialPreferences.php
1 <?php
2 /**
3 * Hold things related to displaying and saving user preferences.
4 * @addtogroup SpecialPage
5 */
6
7 /**
8 * Entry point that create the "Preferences" object
9 */
10 function wfSpecialPreferences() {
11 global $wgRequest;
12
13 $form = new PreferencesForm( $wgRequest );
14 $form->execute();
15 }
16
17 /**
18 * Preferences form handling
19 * This object will show the preferences form and can save it as well.
20 * @addtogroup SpecialPage
21 */
22 class PreferencesForm {
23 var $mQuickbar, $mOldpass, $mNewpass, $mRetypePass, $mStubs;
24 var $mRows, $mCols, $mSkin, $mMath, $mDate, $mUserEmail, $mEmailFlag, $mNick;
25 var $mUserLanguage, $mUserVariant;
26 var $mSearch, $mRecent, $mRecentDays, $mHourDiff, $mSearchLines, $mSearchChars, $mAction;
27 var $mReset, $mPosted, $mToggles, $mSearchNs, $mRealName, $mImageSize;
28 var $mUnderline, $mWatchlistEdits;
29
30 /**
31 * Constructor
32 * Load some values
33 */
34 function PreferencesForm( &$request ) {
35 global $wgContLang, $wgUser, $wgAllowRealName;
36
37 $this->mQuickbar = $request->getVal( 'wpQuickbar' );
38 $this->mOldpass = $request->getVal( 'wpOldpass' );
39 $this->mNewpass = $request->getVal( 'wpNewpass' );
40 $this->mRetypePass =$request->getVal( 'wpRetypePass' );
41 $this->mStubs = $request->getVal( 'wpStubs' );
42 $this->mRows = $request->getVal( 'wpRows' );
43 $this->mCols = $request->getVal( 'wpCols' );
44 $this->mSkin = $request->getVal( 'wpSkin' );
45 $this->mMath = $request->getVal( 'wpMath' );
46 $this->mDate = $request->getVal( 'wpDate' );
47 $this->mUserEmail = $request->getVal( 'wpUserEmail' );
48 $this->mRealName = $wgAllowRealName ? $request->getVal( 'wpRealName' ) : '';
49 $this->mEmailFlag = $request->getCheck( 'wpEmailFlag' ) ? 0 : 1;
50 $this->mNick = $request->getVal( 'wpNick' );
51 $this->mUserLanguage = $request->getVal( 'wpUserLanguage' );
52 $this->mUserVariant = $request->getVal( 'wpUserVariant' );
53 $this->mSearch = $request->getVal( 'wpSearch' );
54 $this->mRecent = $request->getVal( 'wpRecent' );
55 $this->mRecentDays = $request->getVal( 'wpRecentDays' );
56 $this->mHourDiff = $request->getVal( 'wpHourDiff' );
57 $this->mSearchLines = $request->getVal( 'wpSearchLines' );
58 $this->mSearchChars = $request->getVal( 'wpSearchChars' );
59 $this->mImageSize = $request->getVal( 'wpImageSize' );
60 $this->mThumbSize = $request->getInt( 'wpThumbSize' );
61 $this->mUnderline = $request->getInt( 'wpOpunderline' );
62 $this->mAction = $request->getVal( 'action' );
63 $this->mReset = $request->getCheck( 'wpReset' );
64 $this->mPosted = $request->wasPosted();
65 $this->mSuccess = $request->getCheck( 'success' );
66 $this->mWatchlistDays = $request->getVal( 'wpWatchlistDays' );
67 $this->mWatchlistEdits = $request->getVal( 'wpWatchlistEdits' );
68
69 $this->mSaveprefs = $request->getCheck( 'wpSaveprefs' ) &&
70 $this->mPosted &&
71 $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
72
73 # User toggles (the big ugly unsorted list of checkboxes)
74 $this->mToggles = array();
75 if ( $this->mPosted ) {
76 $togs = User::getToggles();
77 foreach ( $togs as $tname ) {
78 $this->mToggles[$tname] = $request->getCheck( "wpOp$tname" ) ? 1 : 0;
79 }
80 }
81
82 $this->mUsedToggles = array();
83
84 # Search namespace options
85 # Note: namespaces don't necessarily have consecutive keys
86 $this->mSearchNs = array();
87 if ( $this->mPosted ) {
88 $namespaces = $wgContLang->getNamespaces();
89 foreach ( $namespaces as $i => $namespace ) {
90 if ( $i >= 0 ) {
91 $this->mSearchNs[$i] = $request->getCheck( "wpNs$i" ) ? 1 : 0;
92 }
93 }
94 }
95
96 # Validate language
97 if ( !preg_match( '/^[a-z\-]*$/', $this->mUserLanguage ) ) {
98 $this->mUserLanguage = 'nolanguage';
99 }
100 }
101
102 function execute() {
103 global $wgUser, $wgOut;
104
105 if ( $wgUser->isAnon() ) {
106 $wgOut->showErrorPage( 'prefsnologin', 'prefsnologintext' );
107 return;
108 }
109 if ( wfReadOnly() ) {
110 $wgOut->readOnlyPage();
111 return;
112 }
113 if ( $this->mReset ) {
114 $this->resetPrefs();
115 $this->mainPrefsForm( 'reset', wfMsg( 'prefsreset' ) );
116 } else if ( $this->mSaveprefs ) {
117 $this->savePreferences();
118 } else {
119 $this->resetPrefs();
120 $this->mainPrefsForm( '' );
121 }
122 }
123 /**
124 * @access private
125 */
126 function validateInt( &$val, $min=0, $max=0x7fffffff ) {
127 $val = intval($val);
128 $val = min($val, $max);
129 $val = max($val, $min);
130 return $val;
131 }
132
133 /**
134 * @access private
135 */
136 function validateFloat( &$val, $min, $max=0x7fffffff ) {
137 $val = floatval( $val );
138 $val = min( $val, $max );
139 $val = max( $val, $min );
140 return( $val );
141 }
142
143 /**
144 * @access private
145 */
146 function validateIntOrNull( &$val, $min=0, $max=0x7fffffff ) {
147 $val = trim($val);
148 if($val === '') {
149 return $val;
150 } else {
151 return $this->validateInt( $val, $min, $max );
152 }
153 }
154
155 /**
156 * @access private
157 */
158 function validateDate( $val ) {
159 global $wgLang, $wgContLang;
160 if ( $val !== false && (
161 in_array( $val, (array)$wgLang->getDatePreferences() ) ||
162 in_array( $val, (array)$wgContLang->getDatePreferences() ) ) )
163 {
164 return $val;
165 } else {
166 return $wgLang->getDefaultDateFormat();
167 }
168 }
169
170 /**
171 * Used to validate the user inputed timezone before saving it as
172 * 'timecorrection', will return '00:00' if fed bogus data.
173 * Note: It's not a 100% correct implementation timezone-wise, it will
174 * accept stuff like '14:30',
175 * @access private
176 * @param string $s the user input
177 * @return string
178 */
179 function validateTimeZone( $s ) {
180 if ( $s !== '' ) {
181 if ( strpos( $s, ':' ) ) {
182 # HH:MM
183 $array = explode( ':' , $s );
184 $hour = intval( $array[0] );
185 $minute = intval( $array[1] );
186 } else {
187 $minute = intval( $s * 60 );
188 $hour = intval( $minute / 60 );
189 $minute = abs( $minute ) % 60;
190 }
191 # Max is +14:00 and min is -12:00, see:
192 # http://en.wikipedia.org/wiki/Timezone
193 $hour = min( $hour, 14 );
194 $hour = max( $hour, -12 );
195 $minute = min( $minute, 59 );
196 $minute = max( $minute, 0 );
197 $s = sprintf( "%02d:%02d", $hour, $minute );
198 }
199 return $s;
200 }
201
202 /**
203 * @access private
204 */
205 function savePreferences() {
206 global $wgUser, $wgOut, $wgParser;
207 global $wgEnableUserEmail, $wgEnableEmail;
208 global $wgEmailAuthentication;
209 global $wgAuth;
210
211
212 if ( '' != $this->mNewpass && $wgAuth->allowPasswordChange() ) {
213 if ( $this->mNewpass != $this->mRetypePass ) {
214 $this->mainPrefsForm( 'error', wfMsg( 'badretype' ) );
215 return;
216 }
217
218 if (!$wgUser->checkPassword( $this->mOldpass )) {
219 $this->mainPrefsForm( 'error', wfMsg( 'wrongpassword' ) );
220 return;
221 }
222
223 try {
224 $wgUser->setPassword( $this->mNewpass );
225 $this->mNewpass = $this->mOldpass = $this->mRetypePass = '';
226 } catch( PasswordError $e ) {
227 $this->mainPrefsForm( 'error', $e->getMessage() );
228 return;
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 } else {
247 // When no fancy sig used, make sure ~{3,5} get removed.
248 $this->mNick = $wgParser->cleanSigInSig( $this->mNick );
249 }
250
251 $wgUser->setOption( 'language', $this->mUserLanguage );
252 $wgUser->setOption( 'variant', $this->mUserVariant );
253 $wgUser->setOption( 'nickname', $this->mNick );
254 $wgUser->setOption( 'quickbar', $this->mQuickbar );
255 $wgUser->setOption( 'skin', $this->mSkin );
256 global $wgUseTeX;
257 if( $wgUseTeX ) {
258 $wgUser->setOption( 'math', $this->mMath );
259 }
260 $wgUser->setOption( 'date', $this->validateDate( $this->mDate ) );
261 $wgUser->setOption( 'searchlimit', $this->validateIntOrNull( $this->mSearch ) );
262 $wgUser->setOption( 'contextlines', $this->validateIntOrNull( $this->mSearchLines ) );
263 $wgUser->setOption( 'contextchars', $this->validateIntOrNull( $this->mSearchChars ) );
264 $wgUser->setOption( 'rclimit', $this->validateIntOrNull( $this->mRecent ) );
265 $wgUser->setOption( 'rcdays', $this->validateInt( $this->mRecentDays, 1, 7 ) );
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->mRecentDays = $wgUser->getOption( 'rcdays' );
369 $this->mWatchlistEdits = $wgUser->getOption( 'wllimit' );
370 $this->mUnderline = $wgUser->getOption( 'underline' );
371 $this->mWatchlistDays = $wgUser->getOption( 'watchlistdays' );
372
373 $togs = User::getToggles();
374 foreach ( $togs as $tname ) {
375 $this->mToggles[$tname] = $wgUser->getOption( $tname );
376 }
377
378 $namespaces = $wgContLang->getNamespaces();
379 foreach ( $namespaces as $i => $namespace ) {
380 if ( $i >= NS_MAIN ) {
381 $this->mSearchNs[$i] = $wgUser->getOption( 'searchNs'.$i );
382 }
383 }
384 }
385
386 /**
387 * @access private
388 */
389 function namespacesCheckboxes() {
390 global $wgContLang;
391
392 # Determine namespace checkboxes
393 $namespaces = $wgContLang->getNamespaces();
394 $r1 = null;
395
396 foreach ( $namespaces as $i => $name ) {
397 if ($i < 0)
398 continue;
399 $checked = $this->mSearchNs[$i] ? "checked='checked'" : '';
400 $name = str_replace( '_', ' ', $namespaces[$i] );
401
402 if ( empty($name) )
403 $name = wfMsg( 'blanknamespace' );
404
405 $r1 .= "<input type='checkbox' value='1' name='wpNs$i' id='wpNs$i' {$checked}/> <label for='wpNs$i'>{$name}</label><br />\n";
406 }
407 return $r1;
408 }
409
410
411 function getToggle( $tname, $trailer = false, $disabled = false ) {
412 global $wgUser, $wgLang;
413
414 $this->mUsedToggles[$tname] = true;
415 $ttext = $wgLang->getUserToggle( $tname );
416
417 $checked = $wgUser->getOption( $tname ) == 1 ? ' checked="checked"' : '';
418 $disabled = $disabled ? ' disabled="disabled"' : '';
419 $trailer = $trailer ? $trailer : '';
420 return "<div class='toggle'><input type='checkbox' value='1' id=\"$tname\" name=\"wpOp$tname\"$checked$disabled />" .
421 " <span class='toggletext'><label for=\"$tname\">$ttext</label>$trailer</span></div>\n";
422 }
423
424 function getToggles( $items ) {
425 $out = "";
426 foreach( $items as $item ) {
427 if( $item === false )
428 continue;
429 if( is_array( $item ) ) {
430 list( $key, $trailer ) = $item;
431 } else {
432 $key = $item;
433 $trailer = false;
434 }
435 $out .= $this->getToggle( $key, $trailer );
436 }
437 return $out;
438 }
439
440 function addRow($td1, $td2) {
441 return "<tr><td align='right'>$td1</td><td align='left'>$td2</td></tr>";
442 }
443
444 /**
445 * @access private
446 */
447 function mainPrefsForm( $status , $message = '' ) {
448 global $wgUser, $wgOut, $wgLang, $wgContLang;
449 global $wgAllowRealName, $wgImageLimits, $wgThumbLimits;
450 global $wgDisableLangConversion;
451 global $wgEnotifWatchlist, $wgEnotifUserTalk,$wgEnotifMinorEdits;
452 global $wgRCShowWatchingUsers, $wgEnotifRevealEditorAddress;
453 global $wgEnableEmail, $wgEnableUserEmail, $wgEmailAuthentication;
454 global $wgContLanguageCode, $wgDefaultSkin, $wgSkipSkins, $wgAuth;
455
456 $wgOut->setPageTitle( wfMsg( 'preferences' ) );
457 $wgOut->setArticleRelated( false );
458 $wgOut->setRobotpolicy( 'noindex,nofollow' );
459
460 if ( $this->mSuccess || 'success' == $status ) {
461 $wgOut->addWikitext( '<div class="successbox"><strong>'. wfMsg( 'savedprefs' ) . '</strong></div>' );
462 } else if ( 'error' == $status ) {
463 $wgOut->addWikitext( '<div class="errorbox"><strong>' . $message . '</strong></div>' );
464 } else if ( '' != $status ) {
465 $wgOut->addWikitext( $message . "\n----" );
466 }
467
468 $qbs = $wgLang->getQuickbarSettings();
469 $skinNames = $wgLang->getSkinNames();
470 $mathopts = $wgLang->getMathNames();
471 $dateopts = $wgLang->getDatePreferences();
472 $togs = User::getToggles();
473
474 $titleObj = SpecialPage::getTitleFor( 'Preferences' );
475 $action = $titleObj->escapeLocalURL();
476
477 # Pre-expire some toggles so they won't show if disabled
478 $this->mUsedToggles[ 'shownumberswatching' ] = true;
479 $this->mUsedToggles[ 'showupdated' ] = true;
480 $this->mUsedToggles[ 'enotifwatchlistpages' ] = true;
481 $this->mUsedToggles[ 'enotifusertalkpages' ] = true;
482 $this->mUsedToggles[ 'enotifminoredits' ] = true;
483 $this->mUsedToggles[ 'enotifrevealaddr' ] = true;
484 $this->mUsedToggles[ 'ccmeonemails' ] = true;
485 $this->mUsedToggles[ 'uselivepreview' ] = true;
486
487 # Enotif
488 # <FIXME>
489 $this->mUserEmail = htmlspecialchars( $this->mUserEmail );
490 $this->mRealName = htmlspecialchars( $this->mRealName );
491 $rawNick = $this->mNick;
492 $this->mNick = htmlspecialchars( $this->mNick );
493 if ( !$this->mEmailFlag ) { $emfc = 'checked="checked"'; }
494 else { $emfc = ''; }
495
496
497 if ($wgEmailAuthentication && ($this->mUserEmail != '') ) {
498 if( $wgUser->getEmailAuthenticationTimestamp() ) {
499 $emailauthenticated = wfMsg('emailauthenticated',$wgLang->timeanddate($wgUser->getEmailAuthenticationTimestamp(), true ) ).'<br />';
500 $disableEmailPrefs = false;
501 } else {
502 $disableEmailPrefs = true;
503 $skin = $wgUser->getSkin();
504 $emailauthenticated = wfMsg('emailnotauthenticated').'<br />' .
505 $skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Confirmemail' ),
506 wfMsg( 'emailconfirmlink' ) );
507 }
508 } else {
509 $emailauthenticated = '';
510 $disableEmailPrefs = false;
511 }
512
513 if ($this->mUserEmail == '') {
514 $emailauthenticated = wfMsg( 'noemailprefs' );
515 }
516
517 $ps = $this->namespacesCheckboxes();
518
519 $enotifwatchlistpages = ($wgEnotifWatchlist) ? $this->getToggle( 'enotifwatchlistpages', false, $disableEmailPrefs ) : '';
520 $enotifusertalkpages = ($wgEnotifUserTalk) ? $this->getToggle( 'enotifusertalkpages', false, $disableEmailPrefs ) : '';
521 $enotifminoredits = ($wgEnotifWatchlist && $wgEnotifMinorEdits) ? $this->getToggle( 'enotifminoredits', false, $disableEmailPrefs ) : '';
522 $enotifrevealaddr = (($wgEnotifWatchlist || $wgEnotifUserTalk) && $wgEnotifRevealEditorAddress) ? $this->getToggle( 'enotifrevealaddr', false, $disableEmailPrefs ) : '';
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 $userInformationHtml =
535 $this->addRow(
536 wfMsg( 'username'),
537 $wgUser->getName()
538 ) .
539 $this->addRow(
540 wfMsg( 'uid' ),
541 $wgUser->getID()
542 );
543
544 if( wfRunHooks( 'PreferencesUserInformationPanel', array( $this, &$userInformationHtml ) ) ) {
545 $wgOut->addHtml( $userInformationHtml );
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 = Language::getLanguageNames( true );
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 $options = "\n";
608 foreach( $languages as $code => $name ) {
609 $selected = ($code == $selectedLang);
610 $options .= Xml::option( "$code - $name", $code, $selected ) . "\n";
611 }
612 $wgOut->addHTML(
613 $this->addRow(
614 '<label for="wpUserLanguage">' . wfMsg('yourlanguage') . '</label>',
615 "<select name='wpUserLanguage' id='wpUserLanguage'>$options</select>"
616 )
617 );
618
619 /* see if there are multiple language variants to choose from*/
620 if(!$wgDisableLangConversion) {
621 $variants = $wgContLang->getVariants();
622 $variantArray = array();
623
624 foreach($variants as $v) {
625 $v = str_replace( '_', '-', strtolower($v));
626 if( array_key_exists( $v, $languages ) ) {
627 // If it doesn't have a name, we'll pretend it doesn't exist
628 $variantArray[$v] = $languages[$v];
629 }
630 }
631
632 $options = "\n";
633 foreach( $variantArray as $code => $name ) {
634 $selected = ($code == $this->mUserVariant);
635 $options .= Xml::option( "$code - $name", $code, $selected ) . "\n";
636 }
637
638 if(count($variantArray) > 1) {
639 $wgOut->addHtml(
640 $this->addRow( wfMsg( 'yourvariant' ),
641 "<select name='wpUserVariant'>$options</select>" )
642 );
643 }
644 }
645 $wgOut->addHTML('</table>');
646
647 # Password
648 if( $wgAuth->allowPasswordChange() ) {
649 $this->mOldpass = htmlspecialchars( $this->mOldpass );
650 $this->mNewpass = htmlspecialchars( $this->mNewpass );
651 $this->mRetypePass = htmlspecialchars( $this->mRetypePass );
652
653 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'changepassword' ) . '</legend><table>');
654 $wgOut->addHTML(
655 $this->addRow(
656 '<label for="wpOldpass">' . wfMsg( 'oldpassword' ) . '</label>',
657 "<input type='password' name='wpOldpass' id='wpOldpass' value=\"{$this->mOldpass}\" size='20' />"
658 ) .
659 $this->addRow(
660 '<label for="wpNewpass">' . wfMsg( 'newpassword' ) . '</label>',
661 "<input type='password' name='wpNewpass' id='wpNewpass' value=\"{$this->mNewpass}\" size='20' />"
662 ) .
663 $this->addRow(
664 '<label for="wpRetypePass">' . wfMsg( 'retypenew' ) . '</label>',
665 "<input type='password' name='wpRetypePass' id='wpRetypePass' value=\"{$this->mRetypePass}\" size='20' />"
666 ) .
667 "</table>\n" .
668 $this->getToggle( "rememberpassword" ) . "</fieldset>\n\n" );
669 }
670
671 # <FIXME>
672 # Enotif
673 if ($wgEnableEmail) {
674 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'email' ) . '</legend>' );
675 $wgOut->addHTML(
676 $emailauthenticated.
677 $enotifrevealaddr.
678 $enotifwatchlistpages.
679 $enotifusertalkpages.
680 $enotifminoredits );
681 if ($wgEnableUserEmail) {
682 $emf = wfMsg( 'allowemail' );
683 $disabled = $disableEmailPrefs ? ' disabled="disabled"' : '';
684 $wgOut->addHTML(
685 "<div><input type='checkbox' $emfc $disabled value='1' name='wpEmailFlag' id='wpEmailFlag' /> <label for='wpEmailFlag'>$emf</label></div>" );
686 }
687 $wgOut->addHtml( $this->getToggle( 'ccmeonemails' ) );
688
689 $wgOut->addHTML( '</fieldset>' );
690 }
691 # </FIXME>
692
693 # Show little "help" tips for the real name and email address options
694 if( $wgAllowRealName || $wgEnableEmail ) {
695 if( $wgAllowRealName )
696 $tips[] = wfMsg( 'prefs-help-realname' );
697 if( $wgEnableEmail )
698 $tips[] = wfMsg( 'prefs-help-email' );
699 $wgOut->addHtml( '<div class="prefsectiontip">' . implode( '<br />', $tips ) . '</div>' );
700 }
701
702 $wgOut->addHTML( '</fieldset>' );
703
704 # Quickbar
705 #
706 if ($this->mSkin == 'cologneblue' || $this->mSkin == 'standard') {
707 $wgOut->addHtml( "<fieldset>\n<legend>" . wfMsg( 'qbsettings' ) . "</legend>\n" );
708 for ( $i = 0; $i < count( $qbs ); ++$i ) {
709 if ( $i == $this->mQuickbar ) { $checked = ' checked="checked"'; }
710 else { $checked = ""; }
711 $wgOut->addHTML( "<div><label><input type='radio' name='wpQuickbar' value=\"$i\"$checked />{$qbs[$i]}</label></div>\n" );
712 }
713 $wgOut->addHtml( "</fieldset>\n\n" );
714 } else {
715 # Need to output a hidden option even if the relevant skin is not in use,
716 # otherwise the preference will get reset to 0 on submit
717 $wgOut->addHtml( wfHidden( 'wpQuickbar', $this->mQuickbar ) );
718 }
719
720 # Skin
721 #
722 $wgOut->addHTML( "<fieldset>\n<legend>\n" . wfMsg('skin') . "</legend>\n" );
723 $mptitle = Title::newMainPage();
724 $previewtext = wfMsg('skinpreview');
725 # Only show members of Skin::getSkinNames() rather than
726 # $skinNames (skins is all skin names from Language.php)
727 $validSkinNames = Skin::getSkinNames();
728 # Sort by UI skin name. First though need to update validSkinNames as sometimes
729 # the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI).
730 foreach ($validSkinNames as $skinkey => & $skinname ) {
731 if ( isset( $skinNames[$skinkey] ) ) {
732 $skinname = $skinNames[$skinkey];
733 }
734 }
735 asort($validSkinNames);
736 foreach ($validSkinNames as $skinkey => $sn ) {
737 if ( in_array( $skinkey, $wgSkipSkins ) ) {
738 continue;
739 }
740 $checked = $skinkey == $this->mSkin ? ' checked="checked"' : '';
741
742 $mplink = htmlspecialchars($mptitle->getLocalURL("useskin=$skinkey"));
743 $previewlink = "<a target='_blank' href=\"$mplink\">$previewtext</a>";
744 if( $skinkey == $wgDefaultSkin )
745 $sn .= ' (' . wfMsg( 'default' ) . ')';
746 $wgOut->addHTML( "<input type='radio' name='wpSkin' id=\"wpSkin$skinkey\" value=\"$skinkey\"$checked /> <label for=\"wpSkin$skinkey\">{$sn}</label> $previewlink<br />\n" );
747 }
748 $wgOut->addHTML( "</fieldset>\n\n" );
749
750 # Math
751 #
752 global $wgUseTeX;
753 if( $wgUseTeX ) {
754 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg('math') . '</legend>' );
755 foreach ( $mathopts as $k => $v ) {
756 $checked = $k == $this->mMath ? ' checked="checked"' : '';
757 $wgOut->addHTML( "<div><label><input type='radio' name='wpMath' value=\"$k\"$checked /> ".wfMsg($v)."</label></div>\n" );
758 }
759 $wgOut->addHTML( "</fieldset>\n\n" );
760 }
761
762 # Files
763 #
764 $wgOut->addHTML(
765 "<fieldset>\n" . Xml::element( 'legend', null, wfMsg( 'files' ) ) . "\n"
766 );
767
768 $imageLimitOptions = null;
769 foreach ( $wgImageLimits as $index => $limits ) {
770 $selected = ($index == $this->mImageSize);
771 $imageLimitOptions .= Xml::option( "{$limits[0]}ร—{$limits[1]}" .
772 wfMsg('unit-pixel'), $index, $selected );
773 }
774
775 $imageSizeId = 'wpImageSize';
776 $wgOut->addHTML(
777 "<div>" . Xml::label( wfMsg('imagemaxsize'), $imageSizeId ) . " " .
778 Xml::openElement( 'select', array( 'name' => $imageSizeId, 'id' => $imageSizeId ) ) .
779 $imageLimitOptions .
780 Xml::closeElement( 'select' ) . "</div>\n"
781 );
782
783 $imageThumbOptions = null;
784 foreach ( $wgThumbLimits as $index => $size ) {
785 $selected = ($index == $this->mThumbSize);
786 $imageThumbOptions .= Xml::option($size . wfMsg('unit-pixel'), $index,
787 $selected);
788 }
789
790 $thumbSizeId = 'wpThumbSize';
791 $wgOut->addHTML(
792 "<div>" . Xml::label( wfMsg('thumbsize'), $thumbSizeId ) . " " .
793 Xml::openElement( 'select', array( 'name' => $thumbSizeId, 'id' => $thumbSizeId ) ) .
794 $imageThumbOptions .
795 Xml::closeElement( 'select' ) . "</div>\n"
796 );
797
798 $wgOut->addHTML( "</fieldset>\n\n" );
799
800 # Date format
801 #
802 # Date/Time
803 #
804
805 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'datetime' ) . "</legend>\n" );
806
807 if ($dateopts) {
808 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'dateformat' ) . "</legend>\n" );
809 $idCnt = 0;
810 $epoch = '20010115161234'; # Wikipedia day
811 foreach( $dateopts as $key ) {
812 if( $key == 'default' ) {
813 $formatted = wfMsgHtml( 'datedefault' );
814 } else {
815 $formatted = htmlspecialchars( $wgLang->timeanddate( $epoch, false, $key ) );
816 }
817 ($key == $this->mDate) ? $checked = ' checked="checked"' : $checked = '';
818 $wgOut->addHTML( "<div><input type='radio' name=\"wpDate\" id=\"wpDate$idCnt\" ".
819 "value=\"$key\"$checked /> <label for=\"wpDate$idCnt\">$formatted</label></div>\n" );
820 $idCnt++;
821 }
822 $wgOut->addHTML( "</fieldset>\n" );
823 }
824
825 $nowlocal = $wgLang->time( $now = wfTimestampNow(), true );
826 $nowserver = $wgLang->time( $now, false );
827
828 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'timezonelegend' ). '</legend><table>' .
829 $this->addRow( wfMsg( 'servertime' ), $nowserver ) .
830 $this->addRow( wfMsg( 'localtime' ), $nowlocal ) .
831 $this->addRow(
832 '<label for="wpHourDiff">' . wfMsg( 'timezoneoffset' ) . '</label>',
833 "<input type='text' name='wpHourDiff' id='wpHourDiff' value=\"" . htmlspecialchars( $this->mHourDiff ) . "\" size='6' />"
834 ) . "<tr><td colspan='2'>
835 <input type='button' value=\"" . wfMsg( 'guesstimezone' ) ."\"
836 onclick='javascript:guessTimezone()' id='guesstimezonebutton' style='display:none;' />
837 </td></tr></table><div class='prefsectiontip'>ยน" . wfMsg( 'timezonetext' ) . "</div></fieldset>
838 </fieldset>\n\n" );
839
840 # Editing
841 #
842 global $wgLivePreview;
843 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'textboxsize' ) . '</legend>
844 <div>' .
845 wfInputLabel( wfMsg( 'rows' ), 'wpRows', 'wpRows', 3, $this->mRows ) .
846 ' ' .
847 wfInputLabel( wfMsg( 'columns' ), 'wpCols', 'wpCols', 3, $this->mCols ) .
848 "</div>" .
849 $this->getToggles( array(
850 'editsection',
851 'editsectiononrightclick',
852 'editondblclick',
853 'editwidth',
854 'showtoolbar',
855 'previewonfirst',
856 'previewontop',
857 'minordefault',
858 'externaleditor',
859 'externaldiff',
860 $wgLivePreview ? 'uselivepreview' : false,
861 'forceeditsummary',
862 ) ) . '</fieldset>'
863 );
864
865 # Recent changes
866 $wgOut->addHtml( '<fieldset><legend>' . wfMsgHtml( 'prefs-rc' ) . '</legend>' );
867
868 $rc = '<table><tr>';
869 $rc .= '<td>' . Xml::label( wfMsg( 'recentchangesdays' ), 'wpRecentDays' ) . '</td>';
870 $rc .= '<td>' . Xml::input( 'wpRecentDays', 3, $this->mRecentDays, array( 'id' => 'wpRecentDays' ) ) . '</td>';
871 $rc .= '</tr><tr>';
872 $rc .= '<td>' . Xml::label( wfMsg( 'recentchangescount' ), 'wpRecent' ) . '</td>';
873 $rc .= '<td>' . Xml::input( 'wpRecent', 3, $this->mRecent, array( 'id' => 'wpRecent' ) ) . '</td>';
874 $rc .= '</tr></table>';
875 $wgOut->addHtml( $rc );
876
877 $wgOut->addHtml( '<br />' );
878
879 $toggles[] = 'hideminor';
880 if( $wgRCShowWatchingUsers )
881 $toggles[] = 'shownumberswatching';
882 $toggles[] = 'usenewrc';
883 $wgOut->addHtml( $this->getToggles( $toggles ) );
884
885 $wgOut->addHtml( '</fieldset>' );
886
887 # Watchlist
888 $wgOut->addHtml( '<fieldset><legend>' . wfMsgHtml( 'prefs-watchlist' ) . '</legend>' );
889
890 $wgOut->addHtml( wfInputLabel( wfMsg( 'prefs-watchlist-days' ), 'wpWatchlistDays', 'wpWatchlistDays', 3, $this->mWatchlistDays ) );
891 $wgOut->addHtml( '<br /><br />' );
892
893 $wgOut->addHtml( $this->getToggle( 'extendwatchlist' ) );
894 $wgOut->addHtml( wfInputLabel( wfMsg( 'prefs-watchlist-edits' ), 'wpWatchlistEdits', 'wpWatchlistEdits', 3, $this->mWatchlistEdits ) );
895 $wgOut->addHtml( '<br /><br />' );
896
897 $wgOut->addHtml( $this->getToggles( array( 'watchlisthideown', 'watchlisthidebots', 'watchlisthideminor' ) ) );
898
899 if( $wgUser->isAllowed( 'createpage' ) || $wgUser->isAllowed( 'createtalk' ) )
900 $wgOut->addHtml( $this->getToggle( 'watchcreations' ) );
901 foreach( array( 'edit' => 'watchdefault', 'move' => 'watchmoves', 'delete' => 'watchdeletion' ) as $action => $toggle ) {
902 if( $wgUser->isAllowed( $action ) )
903 $wgOut->addHtml( $this->getToggle( $toggle ) );
904 }
905 $this->mUsedToggles['watchcreations'] = true;
906 $this->mUsedToggles['watchdefault'] = true;
907 $this->mUsedToggles['watchmoves'] = true;
908 $this->mUsedToggles['watchdeletion'] = true;
909
910 $wgOut->addHtml( '</fieldset>' );
911
912 # Search
913 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'searchresultshead' ) . '</legend><table>' .
914 $this->addRow(
915 wfLabel( wfMsg( 'resultsperpage' ), 'wpSearch' ),
916 wfInput( 'wpSearch', 4, $this->mSearch, array( 'id' => 'wpSearch' ) )
917 ) .
918 $this->addRow(
919 wfLabel( wfMsg( 'contextlines' ), 'wpSearchLines' ),
920 wfInput( 'wpSearchLines', 4, $this->mSearchLines, array( 'id' => 'wpSearchLines' ) )
921 ) .
922 $this->addRow(
923 wfLabel( wfMsg( 'contextchars' ), 'wpSearchChars' ),
924 wfInput( 'wpSearchChars', 4, $this->mSearchChars, array( 'id' => 'wpSearchChars' ) )
925 ) .
926 "</table><fieldset><legend>" . wfMsg( 'defaultns' ) . "</legend>$ps</fieldset></fieldset>" );
927
928 # Misc
929 #
930 $wgOut->addHTML('<fieldset><legend>' . wfMsg('prefs-misc') . '</legend>');
931 $wgOut->addHTML( wfInputLabel( wfMsg( 'stubthreshold' ),
932 'wpStubs', 'wpStubs', 6, $this->mStubs ) );
933 $msgUnderline = htmlspecialchars( wfMsg ( 'tog-underline' ) );
934 $msgUnderlinenever = htmlspecialchars( wfMsg ( 'underline-never' ) );
935 $msgUnderlinealways = htmlspecialchars( wfMsg ( 'underline-always' ) );
936 $msgUnderlinedefault = htmlspecialchars( wfMsg ( 'underline-default' ) );
937 $uopt = $wgUser->getOption("underline");
938 $s0 = $uopt == 0 ? ' selected="selected"' : '';
939 $s1 = $uopt == 1 ? ' selected="selected"' : '';
940 $s2 = $uopt == 2 ? ' selected="selected"' : '';
941 $wgOut->addHTML("
942 <div class='toggle'><p><label for='wpOpunderline'>$msgUnderline</label>
943 <select name='wpOpunderline' id='wpOpunderline'>
944 <option value=\"0\"$s0>$msgUnderlinenever</option>
945 <option value=\"1\"$s1>$msgUnderlinealways</option>
946 <option value=\"2\"$s2>$msgUnderlinedefault</option>
947 </select></p></div>");
948
949 foreach ( $togs as $tname ) {
950 if( !array_key_exists( $tname, $this->mUsedToggles ) ) {
951 $wgOut->addHTML( $this->getToggle( $tname ) );
952 }
953 }
954 $wgOut->addHTML( '</fieldset>' );
955
956 $token = $wgUser->editToken();
957 $skin = $wgUser->getSkin();
958 $wgOut->addHTML( "
959 <div id='prefsubmit'>
960 <div>
961 <input type='submit' name='wpSaveprefs' class='btnSavePrefs' value=\"" . wfMsgHtml( 'saveprefs' ) . '"'.$skin->tooltipAndAccesskey('save')." />
962 <input type='submit' name='wpReset' value=\"" . wfMsgHtml( 'resetprefs' ) . "\" />
963 </div>
964
965 </div>
966
967 <input type='hidden' name='wpEditToken' value='{$token}' />
968 </div></form>\n" );
969
970 $wgOut->addWikiText( '<div class="prefcache">' . wfMsg('clearyourcache') . '</div>' );
971
972 }
973 }
974 ?>