3 * Hold things related to displaying and saving user preferences.
9 * Entry point that create the "Preferences" object
11 function wfSpecialPreferences() {
14 $form = new PreferencesForm( $wgRequest );
19 * Preferences form handling
20 * This object will show the preferences form and can save it as well.
21 * @ingroup SpecialPage
23 class PreferencesForm
{
24 var $mQuickbar, $mStubs;
25 var $mRows, $mCols, $mSkin, $mMath, $mDate, $mUserEmail, $mEmailFlag, $mNick;
26 var $mUserLanguage, $mUserVariant;
27 var $mSearch, $mRecent, $mRecentDays, $mTimeZone, $mHourDiff, $mSearchLines, $mSearchChars, $mAction;
28 var $mReset, $mPosted, $mToggles, $mSearchNs, $mRealName, $mImageSize;
29 var $mUnderline, $mWatchlistEdits;
35 function __construct( &$request ) {
36 global $wgContLang, $wgUser, $wgAllowRealName;
38 $this->mQuickbar
= $request->getVal( 'wpQuickbar' );
39 $this->mStubs
= $request->getVal( 'wpStubs' );
40 $this->mRows
= $request->getVal( 'wpRows' );
41 $this->mCols
= $request->getVal( 'wpCols' );
42 $this->mSkin
= Skin
::normalizeKey( $request->getVal( 'wpSkin' ) );
43 $this->mMath
= $request->getVal( 'wpMath' );
44 $this->mDate
= $request->getVal( 'wpDate' );
45 $this->mUserEmail
= $request->getVal( 'wpUserEmail' );
46 $this->mRealName
= $wgAllowRealName ?
$request->getVal( 'wpRealName' ) : '';
47 $this->mEmailFlag
= $request->getCheck( 'wpEmailFlag' ) ?
0 : 1;
48 $this->mNick
= $request->getVal( 'wpNick' );
49 $this->mUserLanguage
= $request->getVal( 'wpUserLanguage' );
50 $this->mUserVariant
= $request->getVal( 'wpUserVariant' );
51 $this->mSearch
= $request->getVal( 'wpSearch' );
52 $this->mRecent
= $request->getVal( 'wpRecent' );
53 $this->mRecentDays
= $request->getVal( 'wpRecentDays' );
54 $this->mTimeZone
= $request->getVal( 'wpTimeZone' );
55 $this->mHourDiff
= $request->getVal( 'wpHourDiff' );
56 $this->mSearchLines
= $request->getVal( 'wpSearchLines' );
57 $this->mSearchChars
= $request->getVal( 'wpSearchChars' );
58 $this->mImageSize
= $request->getVal( 'wpImageSize' );
59 $this->mThumbSize
= $request->getInt( 'wpThumbSize' );
60 $this->mUnderline
= $request->getInt( 'wpOpunderline' );
61 $this->mAction
= $request->getVal( 'action' );
62 $this->mReset
= $request->getCheck( 'wpReset' );
63 $this->mRestoreprefs
= $request->getCheck( 'wpRestore' );
64 $this->mPosted
= $request->wasPosted();
65 $this->mSuccess
= $request->getCheck( 'success' );
66 $this->mWatchlistDays
= $request->getVal( 'wpWatchlistDays' );
67 $this->mWatchlistEdits
= $request->getVal( 'wpWatchlistEdits' );
68 $this->mDisableMWSuggest
= $request->getCheck( 'wpDisableMWSuggest' );
70 $this->mSaveprefs
= $request->getCheck( 'wpSaveprefs' ) &&
72 $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
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;
83 $this->mUsedToggles
= array();
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 ) {
92 $this->mSearchNs
[$i] = $request->getCheck( "wpNs$i" ) ?
1 : 0;
98 if ( !preg_match( '/^[a-z\-]*$/', $this->mUserLanguage
) ) {
99 $this->mUserLanguage
= 'nolanguage';
102 wfRunHooks( 'InitPreferencesForm', array( $this, $request ) );
106 global $wgUser, $wgOut, $wgTitle;
108 if ( $wgUser->isAnon() ) {
109 $wgOut->showErrorPage( 'prefsnologin', 'prefsnologintext', array($wgTitle->getPrefixedDBkey()) );
112 if ( wfReadOnly() ) {
113 $wgOut->readOnlyPage();
116 if ( $this->mReset
) {
118 $this->mainPrefsForm( 'reset', wfMsg( 'prefsreset' ) );
119 } else if ( $this->mSaveprefs
) {
120 $this->savePreferences();
121 } else if ( $this->mRestoreprefs
) {
122 $this->restorePreferences();
125 $this->mainPrefsForm( '' );
131 function validateInt( &$val, $min=0, $max=0x7fffffff ) {
133 $val = min($val, $max);
134 $val = max($val, $min);
141 function validateFloat( &$val, $min, $max=0x7fffffff ) {
142 $val = floatval( $val );
143 $val = min( $val, $max );
144 $val = max( $val, $min );
151 function validateIntOrNull( &$val, $min=0, $max=0x7fffffff ) {
156 return $this->validateInt( $val, $min, $max );
163 function validateDate( $val ) {
164 global $wgLang, $wgContLang;
165 if ( $val !== false && (
166 in_array( $val, (array)$wgLang->getDatePreferences() ) ||
167 in_array( $val, (array)$wgContLang->getDatePreferences() ) ) )
171 return $wgLang->getDefaultDateFormat();
176 * Used to validate the user inputed timezone before saving it as
177 * 'timecorrection', will return 'System' if fed bogus data.
179 * @param string $tz the user input Zoneinfo timezone
180 * @param string $s the user input offset string
183 function validateTimeZone( $tz, $s ) {
184 $data = explode( '|', $tz, 3 );
185 switch ( $data[0] ) {
191 $data = explode( ':', $s, 2 );
193 if( count( $data ) == 2 ) {
194 $data[0] = intval( $data[0] );
195 $data[1] = intval( $data[1] );
196 $minDiff = abs( $data[0] ) * 60 +
$data[1];
197 if ( $data[0] < 0 ) $minDiff = -$minDiff;
199 $minDiff = intval( $data[0] ) * 60;
202 # Max is +14:00 and min is -12:00, see:
203 # http://en.wikipedia.org/wiki/Timezone
204 $minDiff = min( $minDiff, 840 ); # 14:00
205 $minDiff = max( $minDiff, -720 ); # -12:00
206 return 'Offset|'.$minDiff;
213 function savePreferences() {
214 global $wgUser, $wgOut, $wgParser;
215 global $wgEnableUserEmail, $wgEnableEmail;
216 global $wgEmailAuthentication, $wgRCMaxAge;
217 global $wgAuth, $wgEmailConfirmToEdit;
219 $wgUser->setRealName( $this->mRealName
);
220 $oldOptions = $wgUser->mOptions
;
222 if( $wgUser->getOption( 'language' ) !== $this->mUserLanguage
) {
223 $needRedirect = true;
225 $needRedirect = false;
228 # Validate the signature and clean it up as needed
229 global $wgMaxSigChars;
230 if( mb_strlen( $this->mNick
) > $wgMaxSigChars ) {
232 $this->mainPrefsForm( 'error',
233 wfMsgExt( 'badsiglength', 'parsemag', $wgLang->formatNum( $wgMaxSigChars ) ) );
235 } elseif( $this->mToggles
['fancysig'] ) {
236 if( $wgParser->validateSig( $this->mNick
) !== false ) {
237 $this->mNick
= $wgParser->cleanSig( $this->mNick
);
239 $this->mainPrefsForm( 'error', wfMsg( 'badsig' ) );
243 // When no fancy sig used, make sure ~{3,5} get removed.
244 $this->mNick
= $wgParser->cleanSigInSig( $this->mNick
);
247 $wgUser->setOption( 'language', $this->mUserLanguage
);
248 $wgUser->setOption( 'variant', $this->mUserVariant
);
249 $wgUser->setOption( 'nickname', $this->mNick
);
250 $wgUser->setOption( 'quickbar', $this->mQuickbar
);
251 global $wgAllowUserSkin;
252 if( $wgAllowUserSkin ) {
253 $wgUser->setOption( 'skin', $this->mSkin
);
257 $wgUser->setOption( 'math', $this->mMath
);
259 $wgUser->setOption( 'date', $this->validateDate( $this->mDate
) );
260 $wgUser->setOption( 'searchlimit', $this->validateIntOrNull( $this->mSearch
) );
261 $wgUser->setOption( 'contextlines', $this->validateIntOrNull( $this->mSearchLines
) );
262 $wgUser->setOption( 'contextchars', $this->validateIntOrNull( $this->mSearchChars
) );
263 $wgUser->setOption( 'rclimit', $this->validateIntOrNull( $this->mRecent
) );
264 $wgUser->setOption( 'rcdays', $this->validateInt($this->mRecentDays
, 1, ceil($wgRCMaxAge / (3600*24))));
265 $wgUser->setOption( 'wllimit', $this->validateIntOrNull( $this->mWatchlistEdits
, 0, 1000 ) );
266 $wgUser->setOption( 'rows', $this->validateInt( $this->mRows
, 4, 1000 ) );
267 $wgUser->setOption( 'cols', $this->validateInt( $this->mCols
, 4, 1000 ) );
268 $wgUser->setOption( 'stubthreshold', $this->validateIntOrNull( $this->mStubs
) );
269 $wgUser->setOption( 'timecorrection', $this->validateTimeZone( $this->mTimeZone
, $this->mHourDiff
) );
270 $wgUser->setOption( 'imagesize', $this->mImageSize
);
271 $wgUser->setOption( 'thumbsize', $this->mThumbSize
);
272 $wgUser->setOption( 'underline', $this->validateInt($this->mUnderline
, 0, 2) );
273 $wgUser->setOption( 'watchlistdays', $this->validateFloat( $this->mWatchlistDays
, 0, 7 ) );
274 $wgUser->setOption( 'disablesuggest', $this->mDisableMWSuggest
);
276 # Set search namespace options
277 foreach( $this->mSearchNs
as $i => $value ) {
278 $wgUser->setOption( "searchNs{$i}", $value );
281 if( $wgEnableEmail && $wgEnableUserEmail ) {
282 $wgUser->setOption( 'disablemail', $this->mEmailFlag
);
286 foreach ( $this->mToggles
as $tname => $tvalue ) {
287 $wgUser->setOption( $tname, $tvalue );
291 if( $wgEnableEmail ) {
292 $newadr = $this->mUserEmail
;
293 $oldadr = $wgUser->getEmail();
294 if( ($newadr != '') && ($newadr != $oldadr) ) {
295 # the user has supplied a new email address on the login page
296 if( $wgUser->isValidEmailAddr( $newadr ) ) {
297 # new behaviour: set this new emailaddr from login-page into user database record
298 $wgUser->setEmail( $newadr );
299 # but flag as "dirty" = unauthenticated
300 $wgUser->invalidateEmail();
301 if ($wgEmailAuthentication) {
302 # Mail a temporary password to the dirty address.
303 # User can come back through the confirmation URL to re-enable email.
304 $result = $wgUser->sendConfirmationMail();
305 if( WikiError
::isError( $result ) ) {
306 $error = wfMsg( 'mailerror', htmlspecialchars( $result->getMessage() ) );
308 $error = wfMsg( 'eauthentsent', $wgUser->getName() );
312 $error = wfMsg( 'invalidemailaddress' );
315 if( $wgEmailConfirmToEdit && empty( $newadr ) ) {
316 $this->mainPrefsForm( 'error', wfMsg( 'noemailtitle' ) );
319 $wgUser->setEmail( $this->mUserEmail
);
321 if( $oldadr != $newadr ) {
322 wfRunHooks( 'PrefsEmailAudit', array( $wgUser, $oldadr, $newadr ) );
326 if( !$wgAuth->updateExternalDB( $wgUser ) ){
327 $this->mainPrefsForm( 'error', wfMsg( 'externaldberror' ) );
332 if ( !wfRunHooks( 'SavePreferences', array( $this, $wgUser, &$msg, $oldOptions ) ) ) {
333 $this->mainPrefsForm( 'error', $msg );
337 $wgUser->setCookies();
338 $wgUser->saveSettings();
340 if( $needRedirect && $error === false ) {
341 $title = SpecialPage
::getTitleFor( 'Preferences' );
342 $wgOut->redirect( $title->getFullURL( 'success' ) );
346 $wgOut->parserOptions( ParserOptions
::newFromUser( $wgUser ) );
347 $this->mainPrefsForm( $error === false ?
'success' : 'error', $error);
353 function resetPrefs() {
354 global $wgUser, $wgLang, $wgContLang, $wgContLanguageCode, $wgAllowRealName, $wgLocalTZoffset;
356 $this->mUserEmail
= $wgUser->getEmail();
357 $this->mUserEmailAuthenticationtimestamp
= $wgUser->getEmailAuthenticationtimestamp();
358 $this->mRealName
= ($wgAllowRealName) ?
$wgUser->getRealName() : '';
360 # language value might be blank, default to content language
361 $this->mUserLanguage
= $wgUser->getOption( 'language', $wgContLanguageCode );
363 $this->mUserVariant
= $wgUser->getOption( 'variant');
364 $this->mEmailFlag
= $wgUser->getOption( 'disablemail' ) == 1 ?
1 : 0;
365 $this->mNick
= $wgUser->getOption( 'nickname' );
367 $this->mQuickbar
= $wgUser->getOption( 'quickbar' );
368 $this->mSkin
= Skin
::normalizeKey( $wgUser->getOption( 'skin' ) );
369 $this->mMath
= $wgUser->getOption( 'math' );
370 $this->mDate
= $wgUser->getDatePreference();
371 $this->mRows
= $wgUser->getOption( 'rows' );
372 $this->mCols
= $wgUser->getOption( 'cols' );
373 $this->mStubs
= $wgUser->getOption( 'stubthreshold' );
375 $tz = $wgUser->getOption( 'timecorrection' );
376 $data = explode( '|', $tz, 3 );
378 switch ( $data[0] ) {
380 $this->mTimeZone
= $tz;
381 # Check if the specified TZ exists, and change to 'Offset' if
383 if ( !function_exists('timezone_open') || @timezone_open
( $data[2] ) === false ) {
384 $this->mTimeZone
= 'Offset';
385 $minDiff = intval( $data[1] );
390 $this->mTimeZone
= 'System|'.$wgLocalTZoffset;
393 $this->mTimeZone
= 'Offset';
394 $minDiff = intval( $data[1] );
397 $this->mTimeZone
= 'Offset';
398 $data = explode( ':', $tz, 2 );
399 if( count( $data ) == 2 ) {
400 $data[0] = intval( $data[0] );
401 $data[1] = intval( $data[1] );
402 $minDiff = abs( $data[0] ) * 60 +
$data[1];
403 if ( $data[0] < 0 ) $minDiff = -$minDiff;
405 $minDiff = intval( $data[0] ) * 60;
409 if ( is_null( $minDiff ) ) {
410 $this->mHourDiff
= '';
412 $this->mHourDiff
= sprintf( '%+03d:%02d', floor($minDiff/60), abs($minDiff)%60
);
415 $this->mSearch
= $wgUser->getOption( 'searchlimit' );
416 $this->mSearchLines
= $wgUser->getOption( 'contextlines' );
417 $this->mSearchChars
= $wgUser->getOption( 'contextchars' );
418 $this->mImageSize
= $wgUser->getOption( 'imagesize' );
419 $this->mThumbSize
= $wgUser->getOption( 'thumbsize' );
420 $this->mRecent
= $wgUser->getOption( 'rclimit' );
421 $this->mRecentDays
= $wgUser->getOption( 'rcdays' );
422 $this->mWatchlistEdits
= $wgUser->getOption( 'wllimit' );
423 $this->mUnderline
= $wgUser->getOption( 'underline' );
424 $this->mWatchlistDays
= $wgUser->getOption( 'watchlistdays' );
425 $this->mDisableMWSuggest
= $wgUser->getBoolOption( 'disablesuggest' );
427 $togs = User
::getToggles();
428 foreach ( $togs as $tname ) {
429 $this->mToggles
[$tname] = $wgUser->getOption( $tname );
432 $namespaces = $wgContLang->getNamespaces();
433 foreach ( $namespaces as $i => $namespace ) {
434 if ( $i >= NS_MAIN
) {
435 $this->mSearchNs
[$i] = $wgUser->getOption( 'searchNs'.$i );
439 wfRunHooks( 'ResetPreferences', array( $this, $wgUser ) );
445 function restorePreferences() {
447 $wgUser->restoreOptions();
448 $wgUser->setCookies();
449 $wgUser->saveSettings();
450 $this->mainPrefsForm( 'success' );
456 function namespacesCheckboxes() {
459 # Determine namespace checkboxes
460 $namespaces = $wgContLang->getNamespaces();
463 foreach ( $namespaces as $i => $name ) {
466 $checked = $this->mSearchNs
[$i] ?
"checked='checked'" : '';
467 $name = str_replace( '_', ' ', $namespaces[$i] );
470 $name = wfMsg( 'blanknamespace' );
472 $r1 .= "<input type='checkbox' value='1' name='wpNs$i' id='wpNs$i' {$checked}/> <label for='wpNs$i'>{$name}</label><br />\n";
478 function getToggle( $tname, $trailer = false, $disabled = false ) {
479 global $wgUser, $wgLang;
481 $this->mUsedToggles
[$tname] = true;
482 $ttext = $wgLang->getUserToggle( $tname );
484 $checked = $wgUser->getOption( $tname ) == 1 ?
' checked="checked"' : '';
485 $disabled = $disabled ?
' disabled="disabled"' : '';
486 $trailer = $trailer ?
$trailer : '';
487 return "<div class='toggle'><input type='checkbox' value='1' id=\"$tname\" name=\"wpOp$tname\"$checked$disabled />" .
488 " <span class='toggletext'><label for=\"$tname\">$ttext</label>$trailer</span></div>\n";
491 function getToggles( $items ) {
493 foreach( $items as $item ) {
494 if( $item === false )
496 if( is_array( $item ) ) {
497 list( $key, $trailer ) = $item;
502 $out .= $this->getToggle( $key, $trailer );
507 function addRow($td1, $td2) {
508 return "<tr><td class='mw-label'>$td1</td><td class='mw-input'>$td2</td></tr>";
512 * Helper function for user information panel
513 * @param $td1 label for an item
514 * @param $td2 item or null
515 * @param $td3 optional help or null
516 * @return xhtml block
518 function tableRow( $td1, $td2 = null, $td3 = null ) {
520 if ( is_null( $td3 ) ) {
523 $td3 = Xml
::tags( 'tr', null,
524 Xml
::tags( 'td', array( 'class' => 'pref-label', 'colspan' => '2' ), $td3 )
528 if ( is_null( $td2 ) ) {
529 $td1 = Xml
::tags( 'td', array( 'class' => 'pref-label', 'colspan' => '2' ), $td1 );
532 $td1 = Xml
::tags( 'td', array( 'class' => 'pref-label' ), $td1 );
533 $td2 = Xml
::tags( 'td', array( 'class' => 'pref-input' ), $td2 );
536 return Xml
::tags( 'tr', null, $td1 . $td2 ). $td3 . "\n";
543 function mainPrefsForm( $status , $message = '' ) {
544 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgAuth;
545 global $wgAllowRealName, $wgImageLimits, $wgThumbLimits;
546 global $wgDisableLangConversion, $wgDisableTitleConversion;
547 global $wgEnotifWatchlist, $wgEnotifUserTalk,$wgEnotifMinorEdits;
548 global $wgRCShowWatchingUsers, $wgEnotifRevealEditorAddress;
549 global $wgEnableEmail, $wgEnableUserEmail, $wgEmailAuthentication;
550 global $wgContLanguageCode, $wgDefaultSkin, $wgCookieExpiration;
551 global $wgEmailConfirmToEdit, $wgEnableMWSuggest, $wgLocalTZoffset;
553 $wgOut->setPageTitle( wfMsg( 'preferences' ) );
554 $wgOut->setArticleRelated( false );
555 $wgOut->setRobotPolicy( 'noindex,nofollow' );
556 $wgOut->addScriptFile( 'prefs.js' );
558 $wgOut->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc.
560 if ( $this->mSuccess ||
'success' == $status ) {
561 $wgOut->wrapWikiMsg( '<div class="successbox"><strong>$1</strong></div>', 'savedprefs' );
562 } else if ( 'error' == $status ) {
563 $wgOut->addWikiText( '<div class="errorbox"><strong>' . $message . '</strong></div>' );
564 } else if ( '' != $status ) {
565 $wgOut->addWikiText( $message . "\n----" );
568 $qbs = $wgLang->getQuickbarSettings();
569 $mathopts = $wgLang->getMathNames();
570 $dateopts = $wgLang->getDatePreferences();
571 $togs = User
::getToggles();
573 $titleObj = SpecialPage
::getTitleFor( 'Preferences' );
575 # Pre-expire some toggles so they won't show if disabled
576 $this->mUsedToggles
[ 'shownumberswatching' ] = true;
577 $this->mUsedToggles
[ 'showupdated' ] = true;
578 $this->mUsedToggles
[ 'enotifwatchlistpages' ] = true;
579 $this->mUsedToggles
[ 'enotifusertalkpages' ] = true;
580 $this->mUsedToggles
[ 'enotifminoredits' ] = true;
581 $this->mUsedToggles
[ 'enotifrevealaddr' ] = true;
582 $this->mUsedToggles
[ 'ccmeonemails' ] = true;
583 $this->mUsedToggles
[ 'uselivepreview' ] = true;
584 $this->mUsedToggles
[ 'noconvertlink' ] = true;
587 if ( !$this->mEmailFlag
) { $emfc = 'checked="checked"'; }
591 if ($wgEmailAuthentication && ($this->mUserEmail
!= '') ) {
592 if( $wgUser->getEmailAuthenticationTimestamp() ) {
593 // date and time are separate parameters to facilitate localisation.
594 // $time is kept for backward compat reasons.
595 // 'emailauthenticated' is also used in SpecialConfirmemail.php
596 $time = $wgLang->timeAndDate( $wgUser->getEmailAuthenticationTimestamp(), true );
597 $d = $wgLang->date( $wgUser->getEmailAuthenticationTimestamp(), true );
598 $t = $wgLang->time( $wgUser->getEmailAuthenticationTimestamp(), true );
599 $emailauthenticated = wfMsg('emailauthenticated', $time, $d, $t ).'<br />';
600 $disableEmailPrefs = false;
602 $disableEmailPrefs = true;
603 $skin = $wgUser->getSkin();
604 $emailauthenticated = wfMsg('emailnotauthenticated').'<br />' .
605 $skin->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Confirmemail' ),
606 wfMsg( 'emailconfirmlink' ) ) . '<br />';
609 $emailauthenticated = '';
610 $disableEmailPrefs = false;
613 if ($this->mUserEmail
== '') {
614 $emailauthenticated = wfMsg( 'noemailprefs' ) . '<br />';
617 $ps = $this->namespacesCheckboxes();
619 $enotifwatchlistpages = ($wgEnotifWatchlist) ?
$this->getToggle( 'enotifwatchlistpages', false, $disableEmailPrefs ) : '';
620 $enotifusertalkpages = ($wgEnotifUserTalk) ?
$this->getToggle( 'enotifusertalkpages', false, $disableEmailPrefs ) : '';
621 $enotifminoredits = ($wgEnotifWatchlist && $wgEnotifMinorEdits) ?
$this->getToggle( 'enotifminoredits', false, $disableEmailPrefs ) : '';
622 $enotifrevealaddr = (($wgEnotifWatchlist ||
$wgEnotifUserTalk) && $wgEnotifRevealEditorAddress) ?
$this->getToggle( 'enotifrevealaddr', false, $disableEmailPrefs ) : '';
627 Xml
::openElement( 'form', array(
628 'action' => $titleObj->getLocalUrl(),
630 'id' => 'mw-preferences-form',
632 Xml
::openElement( 'div', array( 'id' => 'preferences' ) )
638 Xml
::fieldset( wfMsg('prefs-personal') ) .
639 Xml
::openElement( 'table' ) .
640 $this->tableRow( Xml
::element( 'h2', null, wfMsg( 'prefs-personal' ) ) )
643 # Get groups to which the user belongs
644 $userEffectiveGroups = $wgUser->getEffectiveGroups();
645 $userEffectiveGroupsArray = array();
646 foreach( $userEffectiveGroups as $ueg ) {
648 // Skip the default * group, seems useless here
651 $userEffectiveGroupsArray[] = User
::makeGroupLinkHTML( $ueg );
653 asort( $userEffectiveGroupsArray );
655 $sk = $wgUser->getSkin();
656 $toolLinks = array();
657 $toolLinks[] = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'ListGroupRights' ), wfMsg( 'listgrouprights' ) );
658 # At the moment one tool link only but be prepared for the future...
659 # FIXME: Add a link to Special:Userrights for users who are allowed to use it.
660 # $wgUser->isAllowed( 'userrights' ) seems to strict in some cases
662 $userInformationHtml =
663 $this->tableRow( wfMsgHtml( 'username' ), htmlspecialchars( $wgUser->getName() ) ) .
664 $this->tableRow( wfMsgHtml( 'uid' ), $wgLang->formatNum( htmlspecialchars( $wgUser->getId() ) ) ).
667 wfMsgExt( 'prefs-memberingroups', array( 'parseinline' ), count( $userEffectiveGroupsArray ) ),
668 $wgLang->commaList( $userEffectiveGroupsArray ) .
669 '<br />(' . implode( ' | ', $toolLinks ) . ')'
673 wfMsgHtml( 'prefs-edits' ),
674 $wgLang->formatNum( $wgUser->getEditCount() )
677 if( wfRunHooks( 'PreferencesUserInformationPanel', array( $this, &$userInformationHtml ) ) ) {
678 $wgOut->addHTML( $userInformationHtml );
681 if ( $wgAllowRealName ) {
684 Xml
::label( wfMsg('yourrealname'), 'wpRealName' ),
685 Xml
::input( 'wpRealName', 25, $this->mRealName
, array( 'id' => 'wpRealName' ) ),
686 Xml
::tags('div', array( 'class' => 'prefsectiontip' ),
687 wfMsgExt( 'prefs-help-realname', 'parseinline' )
692 if ( $wgEnableEmail ) {
695 Xml
::label( wfMsg('youremail'), 'wpUserEmail' ),
696 Xml
::input( 'wpUserEmail', 25, $this->mUserEmail
, array( 'id' => 'wpUserEmail' ) ),
697 Xml
::tags('div', array( 'class' => 'prefsectiontip' ),
698 wfMsgExt( $wgEmailConfirmToEdit ?
'prefs-help-email-required' : 'prefs-help-email', 'parseinline' )
704 global $wgParser, $wgMaxSigChars;
705 if( mb_strlen( $this->mNick
) > $wgMaxSigChars ) {
706 $invalidSig = $this->tableRow(
708 Xml
::element( 'span', array( 'class' => 'error' ),
709 wfMsgExt( 'badsiglength', 'parsemag', $wgLang->formatNum( $wgMaxSigChars ) ) )
711 } elseif( !empty( $this->mToggles
['fancysig'] ) &&
712 false === $wgParser->validateSig( $this->mNick
) ) {
713 $invalidSig = $this->tableRow(
715 Xml
::element( 'span', array( 'class' => 'error' ), wfMsg( 'badsig' ) )
723 Xml
::label( wfMsg( 'yournick' ), 'wpNick' ),
724 Xml
::input( 'wpNick', 25, $this->mNick
,
727 // Note: $wgMaxSigChars is enforced in Unicode characters,
728 // both on the backend and now in the browser.
729 // Badly-behaved requests may still try to submit
730 // an overlong string, however.
731 'maxlength' => $wgMaxSigChars ) )
734 $this->tableRow( ' ', $this->getToggle( 'fancysig' ) )
737 list( $lsLabel, $lsSelect) = Xml
::languageSelector( $this->mUserLanguage
);
739 $this->tableRow( $lsLabel, $lsSelect )
742 /* see if there are multiple language variants to choose from*/
743 if(!$wgDisableLangConversion) {
744 $variants = $wgContLang->getVariants();
745 $variantArray = array();
747 $languages = Language
::getLanguageNames( true );
748 foreach($variants as $v) {
749 $v = str_replace( '_', '-', strtolower($v));
750 if( array_key_exists( $v, $languages ) ) {
751 // If it doesn't have a name, we'll pretend it doesn't exist
752 $variantArray[$v] = $languages[$v];
757 foreach( $variantArray as $code => $name ) {
758 $selected = ($code == $this->mUserVariant
);
759 $options .= Xml
::option( "$code - $name", $code, $selected ) . "\n";
762 if(count($variantArray) > 1) {
765 Xml
::label( wfMsg( 'yourvariant' ), 'wpUserVariant' ),
767 array( 'name' => 'wpUserVariant', 'id' => 'wpUserVariant' ),
774 if(count($variantArray) > 1 && !$wgDisableLangConversion && !$wgDisableTitleConversion) {
776 Xml
::tags( 'tr', null,
777 Xml
::tags( 'td', array( 'colspan' => '2' ),
778 $this->getToggle( "noconvertlink" )
786 if( $wgAuth->allowPasswordChange() ) {
787 $link = $wgUser->getSkin()->link( SpecialPage
::getTitleFor( 'ResetPass' ), wfMsgHtml( 'prefs-resetpass' ),
788 array() , array('returnto' => SpecialPage
::getTitleFor( 'Preferences') ) );
790 $this->tableRow( Xml
::element( 'h2', null, wfMsg( 'changepassword' ) ) ) .
791 $this->tableRow( '<ul><li>' . $link . '</li></ul>' ) );
796 if ( $wgEnableEmail ) {
799 if ($wgEnableUserEmail) {
800 // fixme -- the "allowemail" pseudotoggle is a hacked-together
801 // inversion for the "disableemail" preference.
802 $emf = wfMsg( 'allowemail' );
803 $disabled = $disableEmailPrefs ?
' disabled="disabled"' : '';
805 "<input type='checkbox' $emfc $disabled value='1' name='wpEmailFlag' id='wpEmailFlag' /> <label for='wpEmailFlag'>$emf</label>" .
806 $this->getToggle( 'ccmeonemails', '', $disableEmailPrefs );
811 $this->tableRow( Xml
::element( 'h2', null, wfMsg( 'email' ) ) ) .
815 $enotifwatchlistpages.
816 $enotifusertalkpages.
825 Xml
::closeElement( 'table' ) .
826 Xml
::closeElement( 'fieldset' )
832 if ($this->mSkin
== 'cologneblue' ||
$this->mSkin
== 'standard') {
833 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'qbsettings' ) . "</legend>\n" );
834 for ( $i = 0; $i < count( $qbs ); ++
$i ) {
835 if ( $i == $this->mQuickbar
) { $checked = ' checked="checked"'; }
836 else { $checked = ""; }
837 $wgOut->addHTML( "<div><label><input type='radio' name='wpQuickbar' value=\"$i\"$checked />{$qbs[$i]}</label></div>\n" );
839 $wgOut->addHTML( "</fieldset>\n\n" );
841 # Need to output a hidden option even if the relevant skin is not in use,
842 # otherwise the preference will get reset to 0 on submit
843 $wgOut->addHTML( Xml
::hidden( 'wpQuickbar', $this->mQuickbar
) );
848 global $wgAllowUserSkin;
849 if( $wgAllowUserSkin ) {
850 $wgOut->addHTML( "<fieldset>\n<legend>\n" . wfMsg( 'skin' ) . "</legend>\n" );
851 $mptitle = Title
::newMainPage();
852 $previewtext = wfMsg( 'skin-preview' );
853 # Only show members of Skin::getSkinNames() rather than
854 # $skinNames (skins is all skin names from Language.php)
855 $validSkinNames = Skin
::getUsableSkins();
856 # Sort by UI skin name. First though need to update validSkinNames as sometimes
857 # the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI).
858 foreach ( $validSkinNames as $skinkey => &$skinname ) {
859 $msgName = "skinname-{$skinkey}";
860 $localisedSkinName = wfMsg( $msgName );
861 if ( !wfEmptyMsg( $msgName, $localisedSkinName ) ) {
862 $skinname = $localisedSkinName;
865 asort($validSkinNames);
866 foreach ($validSkinNames as $skinkey => $sn ) {
867 $checked = $skinkey == $this->mSkin ?
' checked="checked"' : '';
868 $mplink = htmlspecialchars( $mptitle->getLocalURL( "useskin=$skinkey" ) );
869 $previewlink = "(<a target='_blank' href=\"$mplink\">$previewtext</a>)";
870 if( $skinkey == $wgDefaultSkin )
871 $sn .= ' (' . wfMsg( 'default' ) . ')';
872 $wgOut->addHTML( "<input type='radio' name='wpSkin' id=\"wpSkin$skinkey\" value=\"$skinkey\"$checked /> <label for=\"wpSkin$skinkey\">{$sn}</label> $previewlink<br />\n" );
874 $wgOut->addHTML( "</fieldset>\n\n" );
881 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg('math') . '</legend>' );
882 foreach ( $mathopts as $k => $v ) {
883 $checked = ($k == $this->mMath
);
885 Xml
::openElement( 'div' ) .
886 Xml
::radioLabel( wfMsg( $v ), 'wpMath', $k, "mw-sp-math-$k", $checked ) .
887 Xml
::closeElement( 'div' ) . "\n"
890 $wgOut->addHTML( "</fieldset>\n\n" );
895 $imageLimitOptions = null;
896 foreach ( $wgImageLimits as $index => $limits ) {
897 $selected = ($index == $this->mImageSize
);
898 $imageLimitOptions .= Xml
::option( "{$limits[0]}×{$limits[1]}" .
899 wfMsg('unit-pixel'), $index, $selected );
902 $imageThumbOptions = null;
903 foreach ( $wgThumbLimits as $index => $size ) {
904 $selected = ($index == $this->mThumbSize
);
905 $imageThumbOptions .= Xml
::option($size . wfMsg('unit-pixel'), $index,
909 $imageSizeId = 'wpImageSize';
910 $thumbSizeId = 'wpThumbSize';
912 Xml
::fieldset( wfMsg( 'files' ) ) . "\n" .
913 Xml
::openElement( 'table' ) .
915 <td class="mw-label">' .
916 Xml
::label( wfMsg( 'imagemaxsize' ), $imageSizeId ) .
918 <td class="mw-input">' .
919 Xml
::openElement( 'select', array( 'name' => $imageSizeId, 'id' => $imageSizeId ) ) .
921 Xml
::closeElement( 'select' ) .
924 <td class="mw-label">' .
925 Xml
::label( wfMsg( 'thumbsize' ), $thumbSizeId ) .
927 <td class="mw-input">' .
928 Xml
::openElement( 'select', array( 'name' => $thumbSizeId, 'id' => $thumbSizeId ) ) .
930 Xml
::closeElement( 'select' ) .
933 Xml
::closeElement( 'table' ) .
934 Xml
::closeElement( 'fieldset' )
943 Xml
::openElement( 'fieldset' ) .
944 Xml
::element( 'legend', null, wfMsg( 'datetime' ) ) . "\n"
949 Xml
::openElement( 'fieldset' ) .
950 Xml
::element( 'legend', null, wfMsg( 'dateformat' ) ) . "\n"
953 $epoch = '20010115161234'; # Wikipedia day
954 foreach( $dateopts as $key ) {
955 if( $key == 'default' ) {
956 $formatted = wfMsg( 'datedefault' );
958 $formatted = $wgLang->timeanddate( $epoch, false, $key );
961 Xml
::tags( 'div', null,
962 Xml
::radioLabel( $formatted, 'wpDate', $key, "wpDate$idCnt", $key == $this->mDate
)
967 $wgOut->addHTML( Xml
::closeElement( 'fieldset' ) . "\n" );
970 $nowlocal = Xml
::openElement( 'span', array( 'id' => 'wpLocalTime' ) ) .
971 $wgLang->time( $now = wfTimestampNow(), true ) .
972 Xml
::closeElement( 'span' );
973 $nowserver = $wgLang->time( $now, false ) .
974 Xml
::hidden( 'wpServerTime', substr( $now, 8, 2 ) * 60 +
substr( $now, 10, 2 ) );
977 Xml
::openElement( 'fieldset' ) .
978 Xml
::element( 'legend', null, wfMsg( 'timezonelegend' ) ) .
979 Xml
::openElement( 'table' ) .
980 $this->addRow( wfMsg( 'servertime' ), $nowserver ) .
981 $this->addRow( wfMsg( 'localtime' ), $nowlocal )
983 $opt = Xml
::openElement( 'select', array(
984 'name' => 'wpTimeZone',
985 'id' => 'wpTimeZone',
986 'onchange' => 'javascript:updateTimezoneSelection(false)' ) );
987 $opt .= Xml
::option( wfMsg( 'timezoneuseserverdefault' ), "System|$wgLocalTZoffset", $this->mTimeZone
=== "System|$wgLocalTZoffset" );
988 $opt .= Xml
::option( wfMsg( 'timezoneuseoffset' ), 'Offset', $this->mTimeZone
=== 'Offset' );
989 if ( function_exists( 'timezone_identifiers_list' ) ) {
991 $tzs = timezone_identifiers_list();
993 $selZone = explode( '|', $this->mTimeZone
, 3);
994 $selZone = ( $selZone[0] == 'ZoneInfo' ) ?
$selZone[2] : null;
995 $now = date_create( 'now' );
996 foreach ( $tzs as $tz ) {
997 $z = explode( '/', $tz, 2 );
998 # timezone_identifiers_list() returns a number of
999 # backwards-compatibility entries. This filters them out of the
1000 # list presented to the user.
1001 if ( count( $z ) != 2 ||
!in_array( $z[0], array( 'Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific' ) ) ) continue;
1002 if ( $optgroup != $z[0] ) {
1003 if ( $optgroup !== '' ) $opt .= Xml
::closeElement( 'optgroup' );
1005 $opt .= Xml
::openElement( 'optgroup', array( 'label' => $z[0] ) );
1007 $minDiff = floor( timezone_offset_get( timezone_open( $tz ), $now ) / 60 );
1008 $opt .= Xml
::option( str_replace( '_', ' ', $tz ), "ZoneInfo|$minDiff|$tz", $selZone === $tz, array( 'label' => $z[1] ) );
1010 if ( $optgroup !== '' ) $opt .= Xml
::closeElement( 'optgroup' );
1012 $opt .= Xml
::closeElement( 'select' );
1015 Xml
::label( wfMsg( 'timezoneselect' ), 'wpTimeZone' ),
1020 Xml
::label( wfMsg( 'timezoneoffset' ), 'wpHourDiff' ),
1021 Xml
::input( 'wpHourDiff', 6, $this->mHourDiff
, array(
1022 'id' => 'wpHourDiff',
1023 'onfocus' => 'javascript:updateTimezoneSelection(true)',
1024 'onblur' => 'javascript:updateTimezoneSelection(false)' ) ) ) .
1027 <td class='mw-submit'>" .
1028 Xml
::element( 'input',
1029 array( 'type' => 'button',
1030 'value' => wfMsg( 'guesstimezone' ),
1031 'onclick' => 'javascript:guessTimezone()',
1032 'id' => 'guesstimezonebutton',
1033 'style' => 'display:none;' ) ) .
1036 Xml
::closeElement( 'table' ) .
1037 Xml
::tags( 'div', array( 'class' => 'prefsectiontip' ), wfMsgExt( 'timezonetext', 'parseinline' ) ).
1038 Xml
::closeElement( 'fieldset' ) .
1039 Xml
::closeElement( 'fieldset' ) . "\n\n"
1044 global $wgLivePreview;
1046 Xml
::fieldset( wfMsg( 'textboxsize' ) ) .
1047 wfMsgHTML( 'prefs-edit-boxsize' ) . ' ' .
1048 Xml
::inputLabel( wfMsg( 'rows' ), 'wpRows', 'wpRows', 3, $this->mRows
) . ' ' .
1049 Xml
::inputLabel( wfMsg( 'columns' ), 'wpCols', 'wpCols', 3, $this->mCols
) .
1050 $this->getToggles( array(
1052 'editsectiononrightclick',
1061 $wgLivePreview ?
'uselivepreview' : false,
1066 $wgOut->addHTML( Xml
::closeElement( 'fieldset' ) );
1071 Xml
::fieldset( wfMsg( 'prefs-rc' ) ) .
1072 Xml
::openElement( 'table' ) .
1074 <td class="mw-label">' .
1075 Xml
::label( wfMsg( 'recentchangesdays' ), 'wpRecentDays' ) .
1077 <td class="mw-input">' .
1078 Xml
::input( 'wpRecentDays', 3, $this->mRecentDays
, array( 'id' => 'wpRecentDays' ) ) . ' ' .
1079 wfMsgExt( 'recentchangesdays-max', 'parsemag',
1080 $wgLang->formatNum( ceil( $wgRCMaxAge / ( 3600 * 24 ) ) ) ) .
1083 <td class="mw-label">' .
1084 Xml
::label( wfMsg( 'recentchangescount' ), 'wpRecent' ) .
1086 <td class="mw-input">' .
1087 Xml
::input( 'wpRecent', 3, $this->mRecent
, array( 'id' => 'wpRecent' ) ) .
1090 Xml
::closeElement( 'table' ) .
1094 $toggles[] = 'hideminor';
1095 if( $wgRCShowWatchingUsers )
1096 $toggles[] = 'shownumberswatching';
1097 $toggles[] = 'usenewrc';
1100 $this->getToggles( $toggles ) .
1101 Xml
::closeElement( 'fieldset' )
1106 Xml
::fieldset( wfMsg( 'prefs-watchlist' ) ) .
1107 Xml
::inputLabel( wfMsg( 'prefs-watchlist-days' ), 'wpWatchlistDays', 'wpWatchlistDays', 3, $this->mWatchlistDays
) . ' ' .
1108 wfMsgHTML( 'prefs-watchlist-days-max' ) .
1110 $this->getToggle( 'extendwatchlist' ) .
1111 Xml
::inputLabel( wfMsg( 'prefs-watchlist-edits' ), 'wpWatchlistEdits', 'wpWatchlistEdits', 3, $this->mWatchlistEdits
) . ' ' .
1112 wfMsgHTML( 'prefs-watchlist-edits-max' ) .
1114 $this->getToggles( array( 'watchlisthideminor', 'watchlisthidebots', 'watchlisthideown', 'watchlisthideanons', 'watchlisthideliu' ) )
1117 if( $wgUser->isAllowed( 'createpage' ) ||
$wgUser->isAllowed( 'createtalk' ) ) {
1118 $wgOut->addHTML( $this->getToggle( 'watchcreations' ) );
1121 foreach( array( 'edit' => 'watchdefault', 'move' => 'watchmoves', 'delete' => 'watchdeletion' ) as $action => $toggle ) {
1122 if( $wgUser->isAllowed( $action ) )
1123 $wgOut->addHTML( $this->getToggle( $toggle ) );
1125 $this->mUsedToggles
['watchcreations'] = true;
1126 $this->mUsedToggles
['watchdefault'] = true;
1127 $this->mUsedToggles
['watchmoves'] = true;
1128 $this->mUsedToggles
['watchdeletion'] = true;
1130 $wgOut->addHTML( Xml
::closeElement( 'fieldset' ) );
1133 $mwsuggest = $wgEnableMWSuggest ?
1135 Xml
::label( wfMsg( 'mwsuggest-disable' ), 'wpDisableMWSuggest' ),
1136 Xml
::check( 'wpDisableMWSuggest', $this->mDisableMWSuggest
, array( 'id' => 'wpDisableMWSuggest' ) )
1139 // Elements for the search tab itself
1140 Xml
::openElement( 'fieldset' ) .
1141 Xml
::element( 'legend', null, wfMsg( 'searchresultshead' ) ) .
1142 // Elements for the search options in the search tab
1143 Xml
::openElement( 'fieldset' ) .
1144 Xml
::element( 'legend', null, wfMsg( 'prefs-searchoptions' ) ) .
1145 Xml
::openElement( 'table' ) .
1147 Xml
::label( wfMsg( 'resultsperpage' ), 'wpSearch' ),
1148 Xml
::input( 'wpSearch', 4, $this->mSearch
, array( 'id' => 'wpSearch' ) )
1151 Xml
::label( wfMsg( 'contextlines' ), 'wpSearchLines' ),
1152 Xml
::input( 'wpSearchLines', 4, $this->mSearchLines
, array( 'id' => 'wpSearchLines' ) )
1155 Xml
::label( wfMsg( 'contextchars' ), 'wpSearchChars' ),
1156 Xml
::input( 'wpSearchChars', 4, $this->mSearchChars
, array( 'id' => 'wpSearchChars' ) )
1159 Xml
::closeElement( 'table' ) .
1160 Xml
::closeElement( 'fieldset' ) .
1161 // Elements for the namespace options in the search tab
1162 Xml
::openElement( 'fieldset' ) .
1163 Xml
::element( 'legend', null, wfMsg( 'prefs-namespaces' ) ) .
1164 wfMsgExt( 'defaultns', array( 'parse' ) ) .
1166 Xml
::closeElement( 'fieldset' ) .
1167 // End of the search tab
1168 Xml
::closeElement( 'fieldset' )
1173 $wgOut->addHTML('<fieldset><legend>' . wfMsg('prefs-misc') . '</legend>');
1174 $wgOut->addHTML( '<label for="wpStubs">' . wfMsg( 'stub-threshold' ) . '</label> ' );
1175 $wgOut->addHTML( Xml
::input( 'wpStubs', 6, $this->mStubs
, array( 'id' => 'wpStubs' ) ) );
1176 $msgUnderline = htmlspecialchars( wfMsg ( 'tog-underline' ) );
1177 $msgUnderlinenever = htmlspecialchars( wfMsg ( 'underline-never' ) );
1178 $msgUnderlinealways = htmlspecialchars( wfMsg ( 'underline-always' ) );
1179 $msgUnderlinedefault = htmlspecialchars( wfMsg ( 'underline-default' ) );
1180 $uopt = $wgUser->getOption("underline");
1181 $s0 = $uopt == 0 ?
' selected="selected"' : '';
1182 $s1 = $uopt == 1 ?
' selected="selected"' : '';
1183 $s2 = $uopt == 2 ?
' selected="selected"' : '';
1185 <div class='toggle'><p><label for='wpOpunderline'>$msgUnderline</label>
1186 <select name='wpOpunderline' id='wpOpunderline'>
1187 <option value=\"0\"$s0>$msgUnderlinenever</option>
1188 <option value=\"1\"$s1>$msgUnderlinealways</option>
1189 <option value=\"2\"$s2>$msgUnderlinedefault</option>
1190 </select></p></div>");
1192 foreach ( $togs as $tname ) {
1193 if( !array_key_exists( $tname, $this->mUsedToggles
) ) {
1194 if( $tname == 'norollbackdiff' && $wgUser->isAllowed( 'rollback' ) )
1195 $wgOut->addHTML( $this->getToggle( $tname ) );
1197 $wgOut->addHTML( $this->getToggle( $tname ) );
1201 $wgOut->addHTML( '</fieldset>' );
1203 wfRunHooks( 'RenderPreferencesForm', array( $this, $wgOut ) );
1205 $token = htmlspecialchars( $wgUser->editToken() );
1206 $skin = $wgUser->getSkin();
1208 <div id='prefsubmit'>
1209 <input type='submit' name='wpSaveprefs' class='btnSavePrefs' value=\"" . wfMsgHtml( 'saveprefs' ) .
1210 '"'.$skin->tooltipAndAccesskey('save')." />
1211 <input type='submit' name='wpReset' value=\"" . wfMsgHtml( 'resetprefs' ) . "\" />
1212 <input type='submit' name='wpRestore' class='btnSavePrefs' style='float:right;' value=\"" .
1213 wfMsgHtml( 'restoreprefs' ) . "\" />
1216 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1219 $wgOut->addHTML( Xml
::tags( 'div', array( 'class' => "prefcache" ),
1220 wfMsgExt( 'clearyourcache', 'parseinline' ) )