* Polishing and documentation
[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 * Helper function for user information panel
446 * @param $td1 label for an item
447 * @param $td2 item or null
448 * @param $td3 optional help or null
449 * @return xhtml block
450 */
451 function tableRow( $td1, $td2 = null, $td3 = null ) {
452 global $wgContLang;
453
454 $align['align'] = $wgContLang->isRtl() ? 'right' : 'left';
455
456 if ( is_null( $td3 ) ) {
457 $td3 = '';
458 } else {
459 $td3 = Xml::tags( 'tr', null,
460 Xml::tags( 'td', array( 'colspan' => '2' ), $td3 )
461 );
462 }
463
464 if ( is_null( $td2 ) ) {
465 $td1 = Xml::tags( 'td', $align + array( 'colspan' => '2' ), $td1 );
466 $td2 = '';
467 } else {
468 $td1 = Xml::tags( 'td', $align, $td1 );
469 $td2 = Xml::tags( 'td', $align, $td2 );
470 }
471
472 return Xml::tags( 'tr', null, $td1 . $td2 ). $td3 . "\n";
473
474 }
475
476 /**
477 * @access private
478 */
479 function mainPrefsForm( $status , $message = '' ) {
480 global $wgUser, $wgOut, $wgLang, $wgContLang;
481 global $wgAllowRealName, $wgImageLimits, $wgThumbLimits;
482 global $wgDisableLangConversion;
483 global $wgEnotifWatchlist, $wgEnotifUserTalk,$wgEnotifMinorEdits;
484 global $wgRCShowWatchingUsers, $wgEnotifRevealEditorAddress;
485 global $wgEnableEmail, $wgEnableUserEmail, $wgEmailAuthentication;
486 global $wgContLanguageCode, $wgDefaultSkin, $wgSkipSkins, $wgAuth;
487
488 $wgOut->setPageTitle( wfMsg( 'preferences' ) );
489 $wgOut->setArticleRelated( false );
490 $wgOut->setRobotpolicy( 'noindex,nofollow' );
491
492 if ( $this->mSuccess || 'success' == $status ) {
493 $wgOut->addWikitext( '<div class="successbox"><strong>'. wfMsg( 'savedprefs' ) . '</strong></div>' );
494 } else if ( 'error' == $status ) {
495 $wgOut->addWikitext( '<div class="errorbox"><strong>' . $message . '</strong></div>' );
496 } else if ( '' != $status ) {
497 $wgOut->addWikitext( $message . "\n----" );
498 }
499
500 $qbs = $wgLang->getQuickbarSettings();
501 $skinNames = $wgLang->getSkinNames();
502 $mathopts = $wgLang->getMathNames();
503 $dateopts = $wgLang->getDatePreferences();
504 $togs = User::getToggles();
505
506 $titleObj = SpecialPage::getTitleFor( 'Preferences' );
507 $action = $titleObj->escapeLocalURL();
508
509 # Pre-expire some toggles so they won't show if disabled
510 $this->mUsedToggles[ 'shownumberswatching' ] = true;
511 $this->mUsedToggles[ 'showupdated' ] = true;
512 $this->mUsedToggles[ 'enotifwatchlistpages' ] = true;
513 $this->mUsedToggles[ 'enotifusertalkpages' ] = true;
514 $this->mUsedToggles[ 'enotifminoredits' ] = true;
515 $this->mUsedToggles[ 'enotifrevealaddr' ] = true;
516 $this->mUsedToggles[ 'ccmeonemails' ] = true;
517 $this->mUsedToggles[ 'uselivepreview' ] = true;
518
519
520 if ( !$this->mEmailFlag ) { $emfc = 'checked="checked"'; }
521 else { $emfc = ''; }
522
523
524 if ($wgEmailAuthentication && ($this->mUserEmail != '') ) {
525 if( $wgUser->getEmailAuthenticationTimestamp() ) {
526 $emailauthenticated = wfMsg('emailauthenticated',$wgLang->timeanddate($wgUser->getEmailAuthenticationTimestamp(), true ) ).'<br />';
527 $disableEmailPrefs = false;
528 } else {
529 $disableEmailPrefs = true;
530 $skin = $wgUser->getSkin();
531 $emailauthenticated = wfMsg('emailnotauthenticated').'<br />' .
532 $skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Confirmemail' ),
533 wfMsg( 'emailconfirmlink' ) );
534 }
535 } else {
536 $emailauthenticated = '';
537 $disableEmailPrefs = false;
538 }
539
540 if ($this->mUserEmail == '') {
541 $emailauthenticated = wfMsg( 'noemailprefs' );
542 }
543
544 $ps = $this->namespacesCheckboxes();
545
546 $enotifwatchlistpages = ($wgEnotifWatchlist) ? $this->getToggle( 'enotifwatchlistpages', false, $disableEmailPrefs ) : '';
547 $enotifusertalkpages = ($wgEnotifUserTalk) ? $this->getToggle( 'enotifusertalkpages', false, $disableEmailPrefs ) : '';
548 $enotifminoredits = ($wgEnotifWatchlist && $wgEnotifMinorEdits) ? $this->getToggle( 'enotifminoredits', false, $disableEmailPrefs ) : '';
549 $enotifrevealaddr = (($wgEnotifWatchlist || $wgEnotifUserTalk) && $wgEnotifRevealEditorAddress) ? $this->getToggle( 'enotifrevealaddr', false, $disableEmailPrefs ) : '';
550
551 # </FIXME>
552
553 $wgOut->addHTML( "<form action=\"$action\" method='post'>" );
554 $wgOut->addHTML( "<div id='preferences'>" );
555
556 # User data
557
558 $wgOut->addHTML(
559 Xml::openElement( 'fieldset ' ) .
560 Xml::element( 'legend', null, wfMsg('prefs-personal') ) .
561 Xml::openElement( 'table' ) .
562 $this->tableRow( Xml::element( 'h2', null, wfMsg( 'prefs-personal' ) ) )
563 );
564
565 $userInformationHtml =
566 $this->tableRow( wfMsgHtml( 'username' ), htmlspecialchars( $wgUser->getName() ) ) .
567 $this->tableRow( wfMsgHtml( 'uid' ), htmlspecialchars( $wgUser->getID() ) );
568
569 if( wfRunHooks( 'PreferencesUserInformationPanel', array( $this, &$userInformationHtml ) ) ) {
570 $wgOut->addHtml( $userInformationHtml );
571 }
572
573 if ( $wgAllowRealName ) {
574 $wgOut->addHTML(
575 $this->tableRow(
576 Xml::label( wfMsg('yourrealname'), 'wpRealName' ),
577 Xml::input( 'wpRealName', 25, $this->mRealName, array( 'id' => 'wpRealName' ) ),
578 Xml::tags('div', array( 'class' => 'prefsectiontip' ),
579 wfMsgExt( 'prefs-help-realname', 'parseinline' )
580 )
581 )
582 );
583 }
584 if ( $wgEnableEmail ) {
585 $wgOut->addHTML(
586 $this->tableRow(
587 Xml::label( wfMsg('youremail'), 'wpUserEmail' ),
588 Xml::input( 'wpUserEmail', 25, $this->mUserEmail, array( 'id' => 'wpUserEmail' ) ),
589 Xml::tags('div', array( 'class' => 'prefsectiontip' ),
590 wfMsgExt( 'prefs-help-email', 'parseinline' )
591 )
592 )
593 );
594 }
595
596 global $wgParser;
597 if( !empty( $this->mToggles['fancysig'] ) &&
598 false === $wgParser->validateSig( $this->mNick ) ) {
599 $invalidSig = $this->tableRow(
600 '&nbsp;',
601 Xml::element( 'span', array( 'class' => 'error' ), wfMsg( 'badsig' ) )
602 );
603 } else {
604 $invalidSig = '';
605 }
606
607 $wgOut->addHTML(
608 $this->tableRow(
609 Xml::label( wfMsg( 'yournick' ), 'wpNick' ),
610 Xml::input( 'wpNick', 25, $this->mNick, array( 'id' => 'wpNick' ) )
611 ) .
612 $invalidSig .
613 $this->tableRow( '&nbsp;', $this->getToggle( 'fancysig' ) )
614 );
615
616 list( $lsLabel, $lsSelect) = Xml::languageSelector( $this->mUserLanguage );
617 $wgOut->addHTML(
618 $this->tableRow( $lsLabel, $lsSelect )
619 );
620
621 /* see if there are multiple language variants to choose from*/
622 if(!$wgDisableLangConversion) {
623 $variants = $wgContLang->getVariants();
624 $variantArray = array();
625
626 $languages = Language::getLanguageNames( true );
627 foreach($variants as $v) {
628 $v = str_replace( '_', '-', strtolower($v));
629 if( array_key_exists( $v, $languages ) ) {
630 // If it doesn't have a name, we'll pretend it doesn't exist
631 $variantArray[$v] = $languages[$v];
632 }
633 }
634
635 $options = "\n";
636 foreach( $variantArray as $code => $name ) {
637 $selected = ($code == $this->mUserVariant);
638 $options .= Xml::option( "$code - $name", $code, $selected ) . "\n";
639 }
640
641 if(count($variantArray) > 1) {
642 $wgOut->addHtml(
643 $this->tableRow(
644 Xml::label( wfMsg( 'yourvariant' ), 'wpUserVariant' ),
645 Xml::tags( 'select',
646 array( 'name' => 'wpUserVariant', 'id' => 'wpUserVariant' ),
647 $options
648 )
649 )
650 );
651 }
652 }
653
654 # Password
655 if( $wgAuth->allowPasswordChange() ) {
656 $wgOut->addHTML(
657 $this->tableRow( Xml::element( 'h2', null, wfMsg( 'changepassword' ) ) ) .
658 $this->tableRow(
659 Xml::label( wfMsg( 'oldpassword' ), 'wpOldpass' ),
660 Xml::input( 'wpOldpass', 25, $this->mOldpass, array( 'id' => 'wpOldpass' ) )
661 ) .
662 $this->tableRow(
663 Xml::label( wfMsg( 'newpassword' ), 'wpNewpass' ),
664 Xml::input( 'wpNewpass', 25, $this->mNewpass, array( 'id' => 'wpNewpass' ) )
665 ) .
666 $this->tableRow(
667 Xml::label( wfMsg( 'retypenew' ), 'wpRetypePass' ),
668 Xml::input( 'wpRetypePass', 25, $this->mRetypePass, array( 'id' => 'wpRetypePass' ) )
669 ) .
670 Xml::tags( 'tr', null,
671 Xml::tags( 'td', array( 'colspan' => '2' ),
672 $this->getToggle( "rememberpassword" )
673 )
674 )
675 );
676 }
677
678 # <FIXME>
679 # Enotif
680 if ( $wgEnableEmail ) {
681
682 $moreEmail = '';
683 if ($wgEnableUserEmail) {
684 $emf = wfMsg( 'allowemail' );
685 $disabled = $disableEmailPrefs ? ' disabled="disabled"' : '';
686 $moreEmail =
687 "<input type='checkbox' $emfc $disabled value='1' name='wpEmailFlag' id='wpEmailFlag' /> <label for='wpEmailFlag'>$emf</label>";
688 }
689
690
691 $wgOut->addHTML(
692 $this->tableRow( Xml::element( 'h2', null, wfMsg( 'email' ) ) ) .
693 $this->tableRow(
694 $emailauthenticated.
695 $enotifrevealaddr.
696 $enotifwatchlistpages.
697 $enotifusertalkpages.
698 $enotifminoredits.
699 $moreEmail.
700 $this->getToggle( 'ccmeonemails' )
701 )
702 );
703 }
704 # </FIXME>
705
706 $wgOut->addHTML(
707 Xml::closeElement( 'table' ) .
708 Xml::closeElement( 'fieldset' )
709 );
710
711
712 # Quickbar
713 #
714 if ($this->mSkin == 'cologneblue' || $this->mSkin == 'standard') {
715 $wgOut->addHtml( "<fieldset>\n<legend>" . wfMsg( 'qbsettings' ) . "</legend>\n" );
716 for ( $i = 0; $i < count( $qbs ); ++$i ) {
717 if ( $i == $this->mQuickbar ) { $checked = ' checked="checked"'; }
718 else { $checked = ""; }
719 $wgOut->addHTML( "<div><label><input type='radio' name='wpQuickbar' value=\"$i\"$checked />{$qbs[$i]}</label></div>\n" );
720 }
721 $wgOut->addHtml( "</fieldset>\n\n" );
722 } else {
723 # Need to output a hidden option even if the relevant skin is not in use,
724 # otherwise the preference will get reset to 0 on submit
725 $wgOut->addHtml( wfHidden( 'wpQuickbar', $this->mQuickbar ) );
726 }
727
728 # Skin
729 #
730 $wgOut->addHTML( "<fieldset>\n<legend>\n" . wfMsg('skin') . "</legend>\n" );
731 $mptitle = Title::newMainPage();
732 $previewtext = wfMsg('skinpreview');
733 # Only show members of Skin::getSkinNames() rather than
734 # $skinNames (skins is all skin names from Language.php)
735 $validSkinNames = Skin::getSkinNames();
736 # Sort by UI skin name. First though need to update validSkinNames as sometimes
737 # the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI).
738 foreach ($validSkinNames as $skinkey => & $skinname ) {
739 if ( isset( $skinNames[$skinkey] ) ) {
740 $skinname = $skinNames[$skinkey];
741 }
742 }
743 asort($validSkinNames);
744 foreach ($validSkinNames as $skinkey => $sn ) {
745 if ( in_array( $skinkey, $wgSkipSkins ) ) {
746 continue;
747 }
748 $checked = $skinkey == $this->mSkin ? ' checked="checked"' : '';
749
750 $mplink = htmlspecialchars($mptitle->getLocalURL("useskin=$skinkey"));
751 $previewlink = "<a target='_blank' href=\"$mplink\">$previewtext</a>";
752 if( $skinkey == $wgDefaultSkin )
753 $sn .= ' (' . wfMsg( 'default' ) . ')';
754 $wgOut->addHTML( "<input type='radio' name='wpSkin' id=\"wpSkin$skinkey\" value=\"$skinkey\"$checked /> <label for=\"wpSkin$skinkey\">{$sn}</label> $previewlink<br />\n" );
755 }
756 $wgOut->addHTML( "</fieldset>\n\n" );
757
758 # Math
759 #
760 global $wgUseTeX;
761 if( $wgUseTeX ) {
762 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg('math') . '</legend>' );
763 foreach ( $mathopts as $k => $v ) {
764 $checked = ($k == $this->mMath);
765 $wgOut->addHTML(
766 Xml::openElement( 'div' ) .
767 Xml::radioLabel( wfMsg( $v ), 'wpMath', $k, "mw-sp-math-$k", $checked ) .
768 Xml::closeElement( 'div' ) . "\n"
769 );
770 }
771 $wgOut->addHTML( "</fieldset>\n\n" );
772 }
773
774 # Files
775 #
776 $wgOut->addHTML(
777 "<fieldset>\n" . Xml::element( 'legend', null, wfMsg( 'files' ) ) . "\n"
778 );
779
780 $imageLimitOptions = null;
781 foreach ( $wgImageLimits as $index => $limits ) {
782 $selected = ($index == $this->mImageSize);
783 $imageLimitOptions .= Xml::option( "{$limits[0]}ร—{$limits[1]}" .
784 wfMsg('unit-pixel'), $index, $selected );
785 }
786
787 $imageSizeId = 'wpImageSize';
788 $wgOut->addHTML(
789 "<div>" . Xml::label( wfMsg('imagemaxsize'), $imageSizeId ) . " " .
790 Xml::openElement( 'select', array( 'name' => $imageSizeId, 'id' => $imageSizeId ) ) .
791 $imageLimitOptions .
792 Xml::closeElement( 'select' ) . "</div>\n"
793 );
794
795 $imageThumbOptions = null;
796 foreach ( $wgThumbLimits as $index => $size ) {
797 $selected = ($index == $this->mThumbSize);
798 $imageThumbOptions .= Xml::option($size . wfMsg('unit-pixel'), $index,
799 $selected);
800 }
801
802 $thumbSizeId = 'wpThumbSize';
803 $wgOut->addHTML(
804 "<div>" . Xml::label( wfMsg('thumbsize'), $thumbSizeId ) . " " .
805 Xml::openElement( 'select', array( 'name' => $thumbSizeId, 'id' => $thumbSizeId ) ) .
806 $imageThumbOptions .
807 Xml::closeElement( 'select' ) . "</div>\n"
808 );
809
810 $wgOut->addHTML( "</fieldset>\n\n" );
811
812 # Date format
813 #
814 # Date/Time
815 #
816
817 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'datetime' ) . "</legend>\n" );
818
819 if ($dateopts) {
820 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'dateformat' ) . "</legend>\n" );
821 $idCnt = 0;
822 $epoch = '20010115161234'; # Wikipedia day
823 foreach( $dateopts as $key ) {
824 if( $key == 'default' ) {
825 $formatted = wfMsgHtml( 'datedefault' );
826 } else {
827 $formatted = htmlspecialchars( $wgLang->timeanddate( $epoch, false, $key ) );
828 }
829 ($key == $this->mDate) ? $checked = ' checked="checked"' : $checked = '';
830 $wgOut->addHTML( "<div><input type='radio' name=\"wpDate\" id=\"wpDate$idCnt\" ".
831 "value=\"$key\"$checked /> <label for=\"wpDate$idCnt\">$formatted</label></div>\n" );
832 $idCnt++;
833 }
834 $wgOut->addHTML( "</fieldset>\n" );
835 }
836
837 $nowlocal = $wgLang->time( $now = wfTimestampNow(), true );
838 $nowserver = $wgLang->time( $now, false );
839
840 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'timezonelegend' ). '</legend><table>' .
841 $this->addRow( wfMsg( 'servertime' ), $nowserver ) .
842 $this->addRow( wfMsg( 'localtime' ), $nowlocal ) .
843 $this->addRow(
844 '<label for="wpHourDiff">' . wfMsg( 'timezoneoffset' ) . '</label>',
845 "<input type='text' name='wpHourDiff' id='wpHourDiff' value=\"" . htmlspecialchars( $this->mHourDiff ) . "\" size='6' />"
846 ) . "<tr><td colspan='2'>
847 <input type='button' value=\"" . wfMsg( 'guesstimezone' ) ."\"
848 onclick='javascript:guessTimezone()' id='guesstimezonebutton' style='display:none;' />
849 </td></tr></table><div class='prefsectiontip'>ยน" . wfMsg( 'timezonetext' ) . "</div></fieldset>
850 </fieldset>\n\n" );
851
852 # Editing
853 #
854 global $wgLivePreview;
855 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'textboxsize' ) . '</legend>
856 <div>' .
857 wfInputLabel( wfMsg( 'rows' ), 'wpRows', 'wpRows', 3, $this->mRows ) .
858 ' ' .
859 wfInputLabel( wfMsg( 'columns' ), 'wpCols', 'wpCols', 3, $this->mCols ) .
860 "</div>" .
861 $this->getToggles( array(
862 'editsection',
863 'editsectiononrightclick',
864 'editondblclick',
865 'editwidth',
866 'showtoolbar',
867 'previewonfirst',
868 'previewontop',
869 'minordefault',
870 'externaleditor',
871 'externaldiff',
872 $wgLivePreview ? 'uselivepreview' : false,
873 'forceeditsummary',
874 ) ) . '</fieldset>'
875 );
876
877 # Recent changes
878 $wgOut->addHtml( '<fieldset><legend>' . wfMsgHtml( 'prefs-rc' ) . '</legend>' );
879
880 $rc = '<table><tr>';
881 $rc .= '<td>' . Xml::label( wfMsg( 'recentchangesdays' ), 'wpRecentDays' ) . '</td>';
882 $rc .= '<td>' . Xml::input( 'wpRecentDays', 3, $this->mRecentDays, array( 'id' => 'wpRecentDays' ) ) . '</td>';
883 $rc .= '</tr><tr>';
884 $rc .= '<td>' . Xml::label( wfMsg( 'recentchangescount' ), 'wpRecent' ) . '</td>';
885 $rc .= '<td>' . Xml::input( 'wpRecent', 3, $this->mRecent, array( 'id' => 'wpRecent' ) ) . '</td>';
886 $rc .= '</tr></table>';
887 $wgOut->addHtml( $rc );
888
889 $wgOut->addHtml( '<br />' );
890
891 $toggles[] = 'hideminor';
892 if( $wgRCShowWatchingUsers )
893 $toggles[] = 'shownumberswatching';
894 $toggles[] = 'usenewrc';
895 $wgOut->addHtml( $this->getToggles( $toggles ) );
896
897 $wgOut->addHtml( '</fieldset>' );
898
899 # Watchlist
900 $wgOut->addHtml( '<fieldset><legend>' . wfMsgHtml( 'prefs-watchlist' ) . '</legend>' );
901
902 $wgOut->addHtml( wfInputLabel( wfMsg( 'prefs-watchlist-days' ), 'wpWatchlistDays', 'wpWatchlistDays', 3, $this->mWatchlistDays ) );
903 $wgOut->addHtml( '<br /><br />' );
904
905 $wgOut->addHtml( $this->getToggle( 'extendwatchlist' ) );
906 $wgOut->addHtml( wfInputLabel( wfMsg( 'prefs-watchlist-edits' ), 'wpWatchlistEdits', 'wpWatchlistEdits', 3, $this->mWatchlistEdits ) );
907 $wgOut->addHtml( '<br /><br />' );
908
909 $wgOut->addHtml( $this->getToggles( array( 'watchlisthideown', 'watchlisthidebots', 'watchlisthideminor' ) ) );
910
911 if( $wgUser->isAllowed( 'createpage' ) || $wgUser->isAllowed( 'createtalk' ) )
912 $wgOut->addHtml( $this->getToggle( 'watchcreations' ) );
913 foreach( array( 'edit' => 'watchdefault', 'move' => 'watchmoves', 'delete' => 'watchdeletion' ) as $action => $toggle ) {
914 if( $wgUser->isAllowed( $action ) )
915 $wgOut->addHtml( $this->getToggle( $toggle ) );
916 }
917 $this->mUsedToggles['watchcreations'] = true;
918 $this->mUsedToggles['watchdefault'] = true;
919 $this->mUsedToggles['watchmoves'] = true;
920 $this->mUsedToggles['watchdeletion'] = true;
921
922 $wgOut->addHtml( '</fieldset>' );
923
924 # Search
925 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'searchresultshead' ) . '</legend><table>' .
926 $this->addRow(
927 wfLabel( wfMsg( 'resultsperpage' ), 'wpSearch' ),
928 wfInput( 'wpSearch', 4, $this->mSearch, array( 'id' => 'wpSearch' ) )
929 ) .
930 $this->addRow(
931 wfLabel( wfMsg( 'contextlines' ), 'wpSearchLines' ),
932 wfInput( 'wpSearchLines', 4, $this->mSearchLines, array( 'id' => 'wpSearchLines' ) )
933 ) .
934 $this->addRow(
935 wfLabel( wfMsg( 'contextchars' ), 'wpSearchChars' ),
936 wfInput( 'wpSearchChars', 4, $this->mSearchChars, array( 'id' => 'wpSearchChars' ) )
937 ) .
938 "</table><fieldset><legend>" . wfMsg( 'defaultns' ) . "</legend>$ps</fieldset></fieldset>" );
939
940 # Misc
941 #
942 $wgOut->addHTML('<fieldset><legend>' . wfMsg('prefs-misc') . '</legend>');
943 $wgOut->addHTML( wfInputLabel( wfMsg( 'stubthreshold' ),
944 'wpStubs', 'wpStubs', 6, $this->mStubs ) );
945 $msgUnderline = htmlspecialchars( wfMsg ( 'tog-underline' ) );
946 $msgUnderlinenever = htmlspecialchars( wfMsg ( 'underline-never' ) );
947 $msgUnderlinealways = htmlspecialchars( wfMsg ( 'underline-always' ) );
948 $msgUnderlinedefault = htmlspecialchars( wfMsg ( 'underline-default' ) );
949 $uopt = $wgUser->getOption("underline");
950 $s0 = $uopt == 0 ? ' selected="selected"' : '';
951 $s1 = $uopt == 1 ? ' selected="selected"' : '';
952 $s2 = $uopt == 2 ? ' selected="selected"' : '';
953 $wgOut->addHTML("
954 <div class='toggle'><p><label for='wpOpunderline'>$msgUnderline</label>
955 <select name='wpOpunderline' id='wpOpunderline'>
956 <option value=\"0\"$s0>$msgUnderlinenever</option>
957 <option value=\"1\"$s1>$msgUnderlinealways</option>
958 <option value=\"2\"$s2>$msgUnderlinedefault</option>
959 </select></p></div>");
960
961 foreach ( $togs as $tname ) {
962 if( !array_key_exists( $tname, $this->mUsedToggles ) ) {
963 $wgOut->addHTML( $this->getToggle( $tname ) );
964 }
965 }
966 $wgOut->addHTML( '</fieldset>' );
967
968 $token = $wgUser->editToken();
969 $skin = $wgUser->getSkin();
970 $wgOut->addHTML( "
971 <div id='prefsubmit'>
972 <div>
973 <input type='submit' name='wpSaveprefs' class='btnSavePrefs' value=\"" . wfMsgHtml( 'saveprefs' ) . '"'.$skin->tooltipAndAccesskey('save')." />
974 <input type='submit' name='wpReset' value=\"" . wfMsgHtml( 'resetprefs' ) . "\" />
975 </div>
976
977 </div>
978
979 <input type='hidden' name='wpEditToken' value='{$token}' />
980 </div></form>\n" );
981
982 $wgOut->addHtml( Xml::tags( 'div', array( 'class' => "prefcache" ),
983 wfMsgExt( 'clearyourcache', 'parseinline' ) )
984 );
985
986 }
987 }
988 ?>