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 PreferencesForm( &$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->mPosted = $request->wasPosted();
64 $this->mSuccess = $request->getCheck( 'success' );
65 $this->mWatchlistDays = $request->getVal( 'wpWatchlistDays' );
66 $this->mWatchlistEdits = $request->getVal( 'wpWatchlistEdits' );
67 $this->mDisableMWSuggest = $request->getCheck( 'wpDisableMWSuggest' );
69 $this->mSaveprefs = $request->getCheck( 'wpSaveprefs' ) &&
71 $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
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;
82 $this->mUsedToggles = array();
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 ) {
91 $this->mSearchNs[$i] = $request->getCheck( "wpNs$i" ) ? 1 : 0;
97 if ( !preg_match( '/^[a-z\-]*$/', $this->mUserLanguage ) ) {
98 $this->mUserLanguage = 'nolanguage';
101 wfRunHooks( 'InitPreferencesForm', array( $this, $request ) );
105 global $wgUser, $wgOut, $wgTitle;
107 if ( $wgUser->isAnon() ) {
108 $wgOut->showErrorPage( 'prefsnologin', 'prefsnologintext', array($wgTitle->getPrefixedDBkey()) );
111 if ( wfReadOnly() ) {
112 $wgOut->readOnlyPage();
115 if ( $this->mReset ) {
117 $this->mainPrefsForm( 'reset', wfMsg( 'prefsreset' ) );
118 } else if ( $this->mSaveprefs ) {
119 $this->savePreferences();
122 $this->mainPrefsForm( '' );
128 function validateInt( &$val, $min=0, $max=0x7fffffff ) {
130 $val = min($val, $max);
131 $val = max($val, $min);
138 function validateFloat( &$val, $min, $max=0x7fffffff ) {
139 $val = floatval( $val );
140 $val = min( $val, $max );
141 $val = max( $val, $min );
148 function validateIntOrNull( &$val, $min=0, $max=0x7fffffff ) {
153 return $this->validateInt( $val, $min, $max );
160 function validateDate( $val ) {
161 global $wgLang, $wgContLang;
162 if ( $val !== false && (
163 in_array( $val, (array)$wgLang->getDatePreferences() ) ||
164 in_array( $val, (array)$wgContLang->getDatePreferences() ) ) )
168 return $wgLang->getDefaultDateFormat();
173 * Used to validate the user inputed timezone before saving it as
174 * 'timecorrection', will return 'System' if fed bogus data.
176 * @param string $tz the user input Zoneinfo timezone
177 * @param string $s the user input offset string
180 function validateTimeZone( $tz, $s ) {
181 $data = explode( '|', $tz, 3 );
182 switch ( $data[0] ) {
188 $data = explode( ':', $s, 2 );
190 if( count( $data ) == 2 ) {
191 $data[0] = intval( $data[0] );
192 $data[1] = intval( $data[1] );
193 $minDiff = abs( $data[0] ) * 60 + $data[1];
194 if ( $data[0] < 0 ) $minDiff = -$minDiff;
196 $minDiff = intval( $data[0] ) * 60;
199 # Max is +14:00 and min is -12:00, see:
200 # http://en.wikipedia.org/wiki/Timezone
201 $minDiff = min( $minDiff, 840 ); # 14:00
202 $minDiff = max( $minDiff, -720 ); # -12:00
203 return 'Offset|'.$minDiff;
210 function savePreferences() {
211 global $wgUser, $wgOut, $wgParser;
212 global $wgEnableUserEmail, $wgEnableEmail;
213 global $wgEmailAuthentication, $wgRCMaxAge;
214 global $wgAuth, $wgEmailConfirmToEdit;
216 $wgUser->setRealName( $this->mRealName );
217 $oldOptions = $wgUser->mOptions;
219 if( $wgUser->getOption( 'language' ) !== $this->mUserLanguage ) {
220 $needRedirect = true;
222 $needRedirect = false;
225 # Validate the signature and clean it up as needed
226 global $wgMaxSigChars;
227 if( mb_strlen( $this->mNick ) > $wgMaxSigChars ) {
229 $this->mainPrefsForm( 'error',
230 wfMsgExt( 'badsiglength', 'parsemag', $wgLang->formatNum( $wgMaxSigChars ) ) );
232 } elseif( $this->mToggles['fancysig'] ) {
233 if( $wgParser->validateSig( $this->mNick ) !== false ) {
234 $this->mNick = $wgParser->cleanSig( $this->mNick );
236 $this->mainPrefsForm( 'error', wfMsg( 'badsig' ) );
240 // When no fancy sig used, make sure ~{3,5} get removed.
241 $this->mNick = $wgParser->cleanSigInSig( $this->mNick );
244 $wgUser->setOption( 'language', $this->mUserLanguage );
245 $wgUser->setOption( 'variant', $this->mUserVariant );
246 $wgUser->setOption( 'nickname', $this->mNick );
247 $wgUser->setOption( 'quickbar', $this->mQuickbar );
248 global $wgAllowUserSkin;
249 if( $wgAllowUserSkin ) {
250 $wgUser->setOption( 'skin', $this->mSkin );
254 $wgUser->setOption( 'math', $this->mMath );
256 $wgUser->setOption( 'date', $this->validateDate( $this->mDate ) );
257 $wgUser->setOption( 'searchlimit', $this->validateIntOrNull( $this->mSearch ) );
258 $wgUser->setOption( 'contextlines', $this->validateIntOrNull( $this->mSearchLines ) );
259 $wgUser->setOption( 'contextchars', $this->validateIntOrNull( $this->mSearchChars ) );
260 $wgUser->setOption( 'rclimit', $this->validateIntOrNull( $this->mRecent ) );
261 $wgUser->setOption( 'rcdays', $this->validateInt($this->mRecentDays, 1, ceil($wgRCMaxAge / (3600*24))));
262 $wgUser->setOption( 'wllimit', $this->validateIntOrNull( $this->mWatchlistEdits, 0, 1000 ) );
263 $wgUser->setOption( 'rows', $this->validateInt( $this->mRows, 4, 1000 ) );
264 $wgUser->setOption( 'cols', $this->validateInt( $this->mCols, 4, 1000 ) );
265 $wgUser->setOption( 'stubthreshold', $this->validateIntOrNull( $this->mStubs ) );
266 $wgUser->setOption( 'timecorrection', $this->validateTimeZone( $this->mTimeZone, $this->mHourDiff ) );
267 $wgUser->setOption( 'imagesize', $this->mImageSize );
268 $wgUser->setOption( 'thumbsize', $this->mThumbSize );
269 $wgUser->setOption( 'underline', $this->validateInt($this->mUnderline, 0, 2) );
270 $wgUser->setOption( 'watchlistdays', $this->validateFloat( $this->mWatchlistDays, 0, 7 ) );
271 $wgUser->setOption( 'disablesuggest', $this->mDisableMWSuggest );
273 # Set search namespace options
274 foreach( $this->mSearchNs as $i => $value ) {
275 $wgUser->setOption( "searchNs{$i}", $value );
278 if( $wgEnableEmail && $wgEnableUserEmail ) {
279 $wgUser->setOption( 'disablemail', $this->mEmailFlag );
283 foreach ( $this->mToggles as $tname => $tvalue ) {
284 $wgUser->setOption( $tname, $tvalue );
288 if( $wgEnableEmail ) {
289 $newadr = $this->mUserEmail;
290 $oldadr = $wgUser->getEmail();
291 if( ($newadr != '') && ($newadr != $oldadr) ) {
292 # the user has supplied a new email address on the login page
293 if( $wgUser->isValidEmailAddr( $newadr ) ) {
294 # new behaviour: set this new emailaddr from login-page into user database record
295 $wgUser->setEmail( $newadr );
296 # but flag as "dirty" = unauthenticated
297 $wgUser->invalidateEmail();
298 if ($wgEmailAuthentication) {
299 # Mail a temporary password to the dirty address.
300 # User can come back through the confirmation URL to re-enable email.
301 $result = $wgUser->sendConfirmationMail();
302 if( WikiError::isError( $result ) ) {
303 $error = wfMsg( 'mailerror', htmlspecialchars( $result->getMessage() ) );
305 $error = wfMsg( 'eauthentsent', $wgUser->getName() );
309 $error = wfMsg( 'invalidemailaddress' );
312 if( $wgEmailConfirmToEdit && empty( $newadr ) ) {
313 $this->mainPrefsForm( 'error', wfMsg( 'noemailtitle' ) );
316 $wgUser->setEmail( $this->mUserEmail );
318 if( $oldadr != $newadr ) {
319 wfRunHooks( 'PrefsEmailAudit', array( $wgUser, $oldadr, $newadr ) );
323 if( !$wgAuth->updateExternalDB( $wgUser ) ){
324 $this->mainPrefsForm( 'error', wfMsg( 'externaldberror' ) );
329 if ( !wfRunHooks( 'SavePreferences', array( $this, $wgUser, &$msg, $oldOptions ) ) ) {
330 $this->mainPrefsForm( 'error', $msg );
334 $wgUser->setCookies();
335 $wgUser->saveSettings();
337 if( $needRedirect && $error === false ) {
338 $title = SpecialPage::getTitleFor( 'Preferences' );
339 $wgOut->redirect( $title->getFullURL( 'success' ) );
343 $wgOut->parserOptions( ParserOptions::newFromUser( $wgUser ) );
344 $this->mainPrefsForm( $error === false ? 'success' : 'error', $error);
350 function resetPrefs() {
351 global $wgUser, $wgLang, $wgContLang, $wgContLanguageCode, $wgAllowRealName, $wgLocalTZoffset;
353 $this->mUserEmail = $wgUser->getEmail();
354 $this->mUserEmailAuthenticationtimestamp = $wgUser->getEmailAuthenticationtimestamp();
355 $this->mRealName = ($wgAllowRealName) ? $wgUser->getRealName() : '';
357 # language value might be blank, default to content language
358 $this->mUserLanguage = $wgUser->getOption( 'language', $wgContLanguageCode );
360 $this->mUserVariant = $wgUser->getOption( 'variant');
361 $this->mEmailFlag = $wgUser->getOption( 'disablemail' ) == 1 ? 1 : 0;
362 $this->mNick = $wgUser->getOption( 'nickname' );
364 $this->mQuickbar = $wgUser->getOption( 'quickbar' );
365 $this->mSkin = Skin::normalizeKey( $wgUser->getOption( 'skin' ) );
366 $this->mMath = $wgUser->getOption( 'math' );
367 $this->mDate = $wgUser->getDatePreference();
368 $this->mRows = $wgUser->getOption( 'rows' );
369 $this->mCols = $wgUser->getOption( 'cols' );
370 $this->mStubs = $wgUser->getOption( 'stubthreshold' );
372 $tz = $wgUser->getOption( 'timecorrection' );
373 $data = explode( '|', $tz, 3 );
375 switch ( $data[0] ) {
377 $this->mTimeZone = $tz;
378 # Check if the specified TZ exists, and change to 'Offset' if
380 if ( !function_exists('timezone_open') || @timezone_open( $data[2] ) === false ) {
381 $this->mTimeZone = 'Offset';
382 $minDiff = intval( $data[1] );
387 $this->mTimeZone = 'System|'.$wgLocalTZoffset;
390 $this->mTimeZone = 'Offset';
391 $minDiff = intval( $data[1] );
394 $this->mTimeZone = 'Offset';
395 $data = explode( ':', $tz, 2 );
396 if( count( $data ) == 2 ) {
397 $data[0] = intval( $data[0] );
398 $data[1] = intval( $data[1] );
399 $minDiff = abs( $data[0] ) * 60 + $data[1];
400 if ( $data[0] < 0 ) $minDiff = -$minDiff;
402 $minDiff = intval( $data[0] ) * 60;
406 if ( is_null( $minDiff ) ) {
407 $this->mHourDiff = '';
409 $this->mHourDiff = sprintf( '%+03d:%02d', floor($minDiff/60), abs($minDiff)%60 );
412 $this->mSearch = $wgUser->getOption( 'searchlimit' );
413 $this->mSearchLines = $wgUser->getOption( 'contextlines' );
414 $this->mSearchChars = $wgUser->getOption( 'contextchars' );
415 $this->mImageSize = $wgUser->getOption( 'imagesize' );
416 $this->mThumbSize = $wgUser->getOption( 'thumbsize' );
417 $this->mRecent = $wgUser->getOption( 'rclimit' );
418 $this->mRecentDays = $wgUser->getOption( 'rcdays' );
419 $this->mWatchlistEdits = $wgUser->getOption( 'wllimit' );
420 $this->mUnderline = $wgUser->getOption( 'underline' );
421 $this->mWatchlistDays = $wgUser->getOption( 'watchlistdays' );
422 $this->mDisableMWSuggest = $wgUser->getBoolOption( 'disablesuggest' );
424 $togs = User::getToggles();
425 foreach ( $togs as $tname ) {
426 $this->mToggles[$tname] = $wgUser->getOption( $tname );
429 $namespaces = $wgContLang->getNamespaces();
430 foreach ( $namespaces as $i => $namespace ) {
431 if ( $i >= NS_MAIN ) {
432 $this->mSearchNs[$i] = $wgUser->getOption( 'searchNs'.$i );
436 wfRunHooks( 'ResetPreferences', array( $this, $wgUser ) );
442 function namespacesCheckboxes() {
445 # Determine namespace checkboxes
446 $namespaces = $wgContLang->getNamespaces();
449 foreach ( $namespaces as $i => $name ) {
452 $checked = $this->mSearchNs[$i] ? "checked='checked'" : '';
453 $name = str_replace( '_', ' ', $namespaces[$i] );
456 $name = wfMsg( 'blanknamespace' );
458 $r1 .= "<input type='checkbox' value='1' name='wpNs$i' id='wpNs$i' {$checked}/> <label for='wpNs$i'>{$name}</label><br />\n";
464 function getToggle( $tname, $trailer = false, $disabled = false ) {
465 global $wgUser, $wgLang;
467 $this->mUsedToggles[$tname] = true;
468 $ttext = $wgLang->getUserToggle( $tname );
470 $checked = $wgUser->getOption( $tname ) == 1 ? ' checked="checked"' : '';
471 $disabled = $disabled ? ' disabled="disabled"' : '';
472 $trailer = $trailer ? $trailer : '';
473 return "<div class='toggle'><input type='checkbox' value='1' id=\"$tname\" name=\"wpOp$tname\"$checked$disabled />" .
474 " <span class='toggletext'><label for=\"$tname\">$ttext</label>$trailer</span></div>\n";
477 function getToggles( $items ) {
479 foreach( $items as $item ) {
480 if( $item === false )
482 if( is_array( $item ) ) {
483 list( $key, $trailer ) = $item;
488 $out .= $this->getToggle( $key, $trailer );
493 function addRow($td1, $td2) {
494 return "<tr><td class='mw-label'>$td1</td><td class='mw-input'>$td2</td></tr>";
498 * Helper function for user information panel
499 * @param $td1 label for an item
500 * @param $td2 item or null
501 * @param $td3 optional help or null
502 * @return xhtml block
504 function tableRow( $td1, $td2 = null, $td3 = null ) {
506 if ( is_null( $td3 ) ) {
509 $td3 = Xml::tags( 'tr', null,
510 Xml::tags( 'td', array( 'class' => 'pref-label', 'colspan' => '2' ), $td3 )
514 if ( is_null( $td2 ) ) {
515 $td1 = Xml::tags( 'td', array( 'class' => 'pref-label', 'colspan' => '2' ), $td1 );
518 $td1 = Xml::tags( 'td', array( 'class' => 'pref-label' ), $td1 );
519 $td2 = Xml::tags( 'td', array( 'class' => 'pref-input' ), $td2 );
522 return Xml::tags( 'tr', null, $td1 . $td2 ). $td3 . "\n";
529 function mainPrefsForm( $status , $message = '' ) {
530 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgAuth;
531 global $wgAllowRealName, $wgImageLimits, $wgThumbLimits;
532 global $wgDisableLangConversion, $wgDisableTitleConversion;
533 global $wgEnotifWatchlist, $wgEnotifUserTalk,$wgEnotifMinorEdits;
534 global $wgRCShowWatchingUsers, $wgEnotifRevealEditorAddress;
535 global $wgEnableEmail, $wgEnableUserEmail, $wgEmailAuthentication;
536 global $wgContLanguageCode, $wgDefaultSkin, $wgCookieExpiration;
537 global $wgEmailConfirmToEdit, $wgEnableMWSuggest, $wgLocalTZoffset;
539 $wgOut->setPageTitle( wfMsg( 'preferences' ) );
540 $wgOut->setArticleRelated( false );
541 $wgOut->setRobotPolicy( 'noindex,nofollow' );
542 $wgOut->addScriptFile( 'prefs.js' );
544 $wgOut->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc.
546 if ( $this->mSuccess || 'success' == $status ) {
547 $wgOut->wrapWikiMsg( '<div class="successbox"><strong>$1</strong></div>', 'savedprefs' );
548 } else if ( 'error' == $status ) {
549 $wgOut->addWikiText( '<div class="errorbox"><strong>' . $message . '</strong></div>' );
550 } else if ( '' != $status ) {
551 $wgOut->addWikiText( $message . "\n----" );
554 $qbs = $wgLang->getQuickbarSettings();
555 $mathopts = $wgLang->getMathNames();
556 $dateopts = $wgLang->getDatePreferences();
557 $togs = User::getToggles();
559 $titleObj = SpecialPage::getTitleFor( 'Preferences' );
561 # Pre-expire some toggles so they won't show if disabled
562 $this->mUsedToggles[ 'shownumberswatching' ] = true;
563 $this->mUsedToggles[ 'showupdated' ] = true;
564 $this->mUsedToggles[ 'enotifwatchlistpages' ] = true;
565 $this->mUsedToggles[ 'enotifusertalkpages' ] = true;
566 $this->mUsedToggles[ 'enotifminoredits' ] = true;
567 $this->mUsedToggles[ 'enotifrevealaddr' ] = true;
568 $this->mUsedToggles[ 'ccmeonemails' ] = true;
569 $this->mUsedToggles[ 'uselivepreview' ] = true;
570 $this->mUsedToggles[ 'noconvertlink' ] = true;
573 if ( !$this->mEmailFlag ) { $emfc = 'checked="checked"'; }
577 if ($wgEmailAuthentication && ($this->mUserEmail != '') ) {
578 if( $wgUser->getEmailAuthenticationTimestamp() ) {
579 // date and time are separate parameters to facilitate localisation.
580 // $time is kept for backward compat reasons.
581 // 'emailauthenticated' is also used in SpecialConfirmemail.php
582 $time = $wgLang->timeAndDate( $wgUser->getEmailAuthenticationTimestamp(), true );
583 $d = $wgLang->date( $wgUser->getEmailAuthenticationTimestamp(), true );
584 $t = $wgLang->time( $wgUser->getEmailAuthenticationTimestamp(), true );
585 $emailauthenticated = wfMsg('emailauthenticated', $time, $d, $t ).'<br />';
586 $disableEmailPrefs = false;
588 $disableEmailPrefs = true;
589 $skin = $wgUser->getSkin();
590 $emailauthenticated = wfMsg('emailnotauthenticated').'<br />' .
591 $skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Confirmemail' ),
592 wfMsg( 'emailconfirmlink' ) ) . '<br />';
595 $emailauthenticated = '';
596 $disableEmailPrefs = false;
599 if ($this->mUserEmail == '') {
600 $emailauthenticated = wfMsg( 'noemailprefs' ) . '<br />';
603 $ps = $this->namespacesCheckboxes();
605 $enotifwatchlistpages = ($wgEnotifWatchlist) ? $this->getToggle( 'enotifwatchlistpages', false, $disableEmailPrefs ) : '';
606 $enotifusertalkpages = ($wgEnotifUserTalk) ? $this->getToggle( 'enotifusertalkpages', false, $disableEmailPrefs ) : '';
607 $enotifminoredits = ($wgEnotifWatchlist && $wgEnotifMinorEdits) ? $this->getToggle( 'enotifminoredits', false, $disableEmailPrefs ) : '';
608 $enotifrevealaddr = (($wgEnotifWatchlist || $wgEnotifUserTalk) && $wgEnotifRevealEditorAddress) ? $this->getToggle( 'enotifrevealaddr', false, $disableEmailPrefs ) : '';
613 Xml::openElement( 'form', array(
614 'action' => $titleObj->getLocalUrl(),
616 'id' => 'mw-preferences-form',
618 Xml::openElement( 'div', array( 'id' => 'preferences' ) )
624 Xml::fieldset( wfMsg('prefs-personal') ) .
625 Xml::openElement( 'table' ) .
626 $this->tableRow( Xml::element( 'h2', null, wfMsg( 'prefs-personal' ) ) )
629 # Get groups to which the user belongs
630 $userEffectiveGroups = $wgUser->getEffectiveGroups();
631 $userEffectiveGroupsArray = array();
632 foreach( $userEffectiveGroups as $ueg ) {
634 // Skip the default * group, seems useless here
637 $userEffectiveGroupsArray[] = User::makeGroupLinkHTML( $ueg );
639 asort( $userEffectiveGroupsArray );
641 $sk = $wgUser->getSkin();
642 $toolLinks = array();
643 $toolLinks[] = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'ListGroupRights' ), wfMsg( 'listgrouprights' ) );
644 # At the moment one tool link only but be prepared for the future...
645 # FIXME: Add a link to Special:Userrights for users who are allowed to use it.
646 # $wgUser->isAllowed( 'userrights' ) seems to strict in some cases
648 $userInformationHtml =
649 $this->tableRow( wfMsgHtml( 'username' ), htmlspecialchars( $wgUser->getName() ) ) .
650 $this->tableRow( wfMsgHtml( 'uid' ), $wgLang->formatNum( htmlspecialchars( $wgUser->getId() ) ) ).
653 wfMsgExt( 'prefs-memberingroups', array( 'parseinline' ), count( $userEffectiveGroupsArray ) ),
654 $wgLang->commaList( $userEffectiveGroupsArray ) .
655 '<br />(' . implode( ' | ', $toolLinks ) . ')'
659 wfMsgHtml( 'prefs-edits' ),
660 $wgLang->formatNum( $wgUser->getEditCount() )
663 if( wfRunHooks( 'PreferencesUserInformationPanel', array( $this, &$userInformationHtml ) ) ) {
664 $wgOut->addHTML( $userInformationHtml );
667 if ( $wgAllowRealName ) {
670 Xml::label( wfMsg('yourrealname'), 'wpRealName' ),
671 Xml::input( 'wpRealName', 25, $this->mRealName, array( 'id' => 'wpRealName' ) ),
672 Xml::tags('div', array( 'class' => 'prefsectiontip' ),
673 wfMsgExt( 'prefs-help-realname', 'parseinline' )
678 if ( $wgEnableEmail ) {
681 Xml::label( wfMsg('youremail'), 'wpUserEmail' ),
682 Xml::input( 'wpUserEmail', 25, $this->mUserEmail, array( 'id' => 'wpUserEmail' ) ),
683 Xml::tags('div', array( 'class' => 'prefsectiontip' ),
684 wfMsgExt( $wgEmailConfirmToEdit ? 'prefs-help-email-required' : 'prefs-help-email', 'parseinline' )
690 global $wgParser, $wgMaxSigChars;
691 if( mb_strlen( $this->mNick ) > $wgMaxSigChars ) {
692 $invalidSig = $this->tableRow(
694 Xml::element( 'span', array( 'class' => 'error' ),
695 wfMsgExt( 'badsiglength', 'parsemag', $wgLang->formatNum( $wgMaxSigChars ) ) )
697 } elseif( !empty( $this->mToggles['fancysig'] ) &&
698 false === $wgParser->validateSig( $this->mNick ) ) {
699 $invalidSig = $this->tableRow(
701 Xml::element( 'span', array( 'class' => 'error' ), wfMsg( 'badsig' ) )
709 Xml::label( wfMsg( 'yournick' ), 'wpNick' ),
710 Xml::input( 'wpNick', 25, $this->mNick,
713 // Note: $wgMaxSigChars is enforced in Unicode characters,
714 // both on the backend and now in the browser.
715 // Badly-behaved requests may still try to submit
716 // an overlong string, however.
717 'maxlength' => $wgMaxSigChars ) )
720 $this->tableRow( ' ', $this->getToggle( 'fancysig' ) )
723 list( $lsLabel, $lsSelect) = Xml::languageSelector( $this->mUserLanguage );
725 $this->tableRow( $lsLabel, $lsSelect )
728 /* see if there are multiple language variants to choose from*/
729 if(!$wgDisableLangConversion) {
730 $variants = $wgContLang->getVariants();
731 $variantArray = array();
733 $languages = Language::getLanguageNames( true );
734 foreach($variants as $v) {
735 $v = str_replace( '_', '-', strtolower($v));
736 if( array_key_exists( $v, $languages ) ) {
737 // If it doesn't have a name, we'll pretend it doesn't exist
738 $variantArray[$v] = $languages[$v];
743 foreach( $variantArray as $code => $name ) {
744 $selected = ($code == $this->mUserVariant);
745 $options .= Xml::option( "$code - $name", $code, $selected ) . "\n";
748 if(count($variantArray) > 1) {
751 Xml::label( wfMsg( 'yourvariant' ), 'wpUserVariant' ),
753 array( 'name' => 'wpUserVariant', 'id' => 'wpUserVariant' ),
760 if(count($variantArray) > 1 && !$wgDisableLangConversion && !$wgDisableTitleConversion) {
762 Xml::tags( 'tr', null,
763 Xml::tags( 'td', array( 'colspan' => '2' ),
764 $this->getToggle( "noconvertlink" )
772 if( $wgAuth->allowPasswordChange() ) {
773 $link = $wgUser->getSkin()->link( SpecialPage::getTitleFor( 'ResetPass' ), wfMsgHtml( 'prefs-resetpass' ),
774 array() , array('returnto' => SpecialPage::getTitleFor( 'Preferences') ) );
776 $this->tableRow( Xml::element( 'h2', null, wfMsg( 'changepassword' ) ) ) .
777 $this->tableRow( '<ul><li>' . $link . '</li></ul>' ) );
782 if ( $wgEnableEmail ) {
785 if ($wgEnableUserEmail) {
786 // fixme -- the "allowemail" pseudotoggle is a hacked-together
787 // inversion for the "disableemail" preference.
788 $emf = wfMsg( 'allowemail' );
789 $disabled = $disableEmailPrefs ? ' disabled="disabled"' : '';
791 "<input type='checkbox' $emfc $disabled value='1' name='wpEmailFlag' id='wpEmailFlag' /> <label for='wpEmailFlag'>$emf</label>" .
792 $this->getToggle( 'ccmeonemails', '', $disableEmailPrefs );
797 $this->tableRow( Xml::element( 'h2', null, wfMsg( 'email' ) ) ) .
801 $enotifwatchlistpages.
802 $enotifusertalkpages.
811 Xml::closeElement( 'table' ) .
812 Xml::closeElement( 'fieldset' )
818 if ($this->mSkin == 'cologneblue' || $this->mSkin == 'standard') {
819 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'qbsettings' ) . "</legend>\n" );
820 for ( $i = 0; $i < count( $qbs ); ++$i ) {
821 if ( $i == $this->mQuickbar ) { $checked = ' checked="checked"'; }
822 else { $checked = ""; }
823 $wgOut->addHTML( "<div><label><input type='radio' name='wpQuickbar' value=\"$i\"$checked />{$qbs[$i]}</label></div>\n" );
825 $wgOut->addHTML( "</fieldset>\n\n" );
827 # Need to output a hidden option even if the relevant skin is not in use,
828 # otherwise the preference will get reset to 0 on submit
829 $wgOut->addHTML( Xml::hidden( 'wpQuickbar', $this->mQuickbar ) );
834 global $wgAllowUserSkin;
835 if( $wgAllowUserSkin ) {
836 $wgOut->addHTML( "<fieldset>\n<legend>\n" . wfMsg( 'skin' ) . "</legend>\n" );
837 $mptitle = Title::newMainPage();
838 $previewtext = wfMsg( 'skin-preview' );
839 # Only show members of Skin::getSkinNames() rather than
840 # $skinNames (skins is all skin names from Language.php)
841 $validSkinNames = Skin::getUsableSkins();
842 # Sort by UI skin name. First though need to update validSkinNames as sometimes
843 # the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI).
844 foreach ( $validSkinNames as $skinkey => &$skinname ) {
845 $msgName = "skinname-{$skinkey}";
846 $localisedSkinName = wfMsg( $msgName );
847 if ( !wfEmptyMsg( $msgName, $localisedSkinName ) ) {
848 $skinname = $localisedSkinName;
851 asort($validSkinNames);
852 foreach ($validSkinNames as $skinkey => $sn ) {
853 $checked = $skinkey == $this->mSkin ? ' checked="checked"' : '';
854 $mplink = htmlspecialchars( $mptitle->getLocalURL( "useskin=$skinkey" ) );
855 $previewlink = "(<a target='_blank' href=\"$mplink\">$previewtext</a>)";
856 if( $skinkey == $wgDefaultSkin )
857 $sn .= ' (' . wfMsg( 'default' ) . ')';
858 $wgOut->addHTML( "<input type='radio' name='wpSkin' id=\"wpSkin$skinkey\" value=\"$skinkey\"$checked /> <label for=\"wpSkin$skinkey\">{$sn}</label> $previewlink<br />\n" );
860 $wgOut->addHTML( "</fieldset>\n\n" );
867 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg('math') . '</legend>' );
868 foreach ( $mathopts as $k => $v ) {
869 $checked = ($k == $this->mMath);
871 Xml::openElement( 'div' ) .
872 Xml::radioLabel( wfMsg( $v ), 'wpMath', $k, "mw-sp-math-$k", $checked ) .
873 Xml::closeElement( 'div' ) . "\n"
876 $wgOut->addHTML( "</fieldset>\n\n" );
881 $imageLimitOptions = null;
882 foreach ( $wgImageLimits as $index => $limits ) {
883 $selected = ($index == $this->mImageSize);
884 $imageLimitOptions .= Xml::option( "{$limits[0]}×{$limits[1]}" .
885 wfMsg('unit-pixel'), $index, $selected );
888 $imageThumbOptions = null;
889 foreach ( $wgThumbLimits as $index => $size ) {
890 $selected = ($index == $this->mThumbSize);
891 $imageThumbOptions .= Xml::option($size . wfMsg('unit-pixel'), $index,
895 $imageSizeId = 'wpImageSize';
896 $thumbSizeId = 'wpThumbSize';
898 Xml::fieldset( wfMsg( 'files' ) ) . "\n" .
899 Xml::openElement( 'table' ) .
901 <td class="mw-label">' .
902 Xml::label( wfMsg( 'imagemaxsize' ), $imageSizeId ) .
904 <td class="mw-input">' .
905 Xml::openElement( 'select', array( 'name' => $imageSizeId, 'id' => $imageSizeId ) ) .
907 Xml::closeElement( 'select' ) .
910 <td class="mw-label">' .
911 Xml::label( wfMsg( 'thumbsize' ), $thumbSizeId ) .
913 <td class="mw-input">' .
914 Xml::openElement( 'select', array( 'name' => $thumbSizeId, 'id' => $thumbSizeId ) ) .
916 Xml::closeElement( 'select' ) .
919 Xml::closeElement( 'table' ) .
920 Xml::closeElement( 'fieldset' )
929 Xml::openElement( 'fieldset' ) .
930 Xml::element( 'legend', null, wfMsg( 'datetime' ) ) . "\n"
935 Xml::openElement( 'fieldset' ) .
936 Xml::element( 'legend', null, wfMsg( 'dateformat' ) ) . "\n"
939 $epoch = '20010115161234'; # Wikipedia day
940 foreach( $dateopts as $key ) {
941 if( $key == 'default' ) {
942 $formatted = wfMsg( 'datedefault' );
944 $formatted = $wgLang->timeanddate( $epoch, false, $key );
947 Xml::tags( 'div', null,
948 Xml::radioLabel( $formatted, 'wpDate', $key, "wpDate$idCnt", $key == $this->mDate )
953 $wgOut->addHTML( Xml::closeElement( 'fieldset' ) . "\n" );
956 $nowlocal = Xml::openElement( 'span', array( 'id' => 'wpLocalTime' ) ) .
957 $wgLang->time( $now = wfTimestampNow(), true ) .
958 Xml::closeElement( 'span' );
959 $nowserver = $wgLang->time( $now, false ) .
960 Xml::hidden( 'wpServerTime', substr( $now, 8, 2 ) * 60 + substr( $now, 10, 2 ) );
963 Xml::openElement( 'fieldset' ) .
964 Xml::element( 'legend', null, wfMsg( 'timezonelegend' ) ) .
965 Xml::openElement( 'table' ) .
966 $this->addRow( wfMsg( 'servertime' ), $nowserver ) .
967 $this->addRow( wfMsg( 'localtime' ), $nowlocal )
969 $opt = Xml::openElement( 'select', array(
970 'name' => 'wpTimeZone',
971 'id' => 'wpTimeZone',
972 'onchange' => 'javascript:updateTimezoneSelection(false)' ) );
973 $opt .= Xml::option( wfMsg( 'timezoneuseserverdefault' ), "System|$wgLocalTZoffset", $this->mTimeZone === "System|$wgLocalTZoffset" );
974 $opt .= Xml::option( wfMsg( 'timezoneuseoffset' ), 'Offset', $this->mTimeZone === 'Offset' );
975 if ( function_exists( 'timezone_identifiers_list' ) ) {
977 $tzs = timezone_identifiers_list();
979 $selZone = explode( '|', $this->mTimeZone, 3);
980 $selZone = ( $selZone[0] == 'ZoneInfo' ) ? $selZone[2] : null;
981 $now = date_create( 'now' );
982 foreach ( $tzs as $tz ) {
983 $z = explode( '/', $tz, 2 );
984 # timezone_identifiers_list() returns a number of
985 # backwards-compatibility entries. This filters them out of the
986 # list presented to the user.
987 if ( count( $z ) != 2 || !in_array( $z[0], array( 'Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific' ) ) ) continue;
988 if ( $optgroup != $z[0] ) {
989 if ( $optgroup !== '' ) $opt .= Xml::closeElement( 'optgroup' );
991 $opt .= Xml::openElement( 'optgroup', array( 'label' => $z[0] ) );
993 $minDiff = floor( timezone_offset_get( timezone_open( $tz ), $now ) / 60 );
994 $opt .= Xml::option( str_replace( '_', ' ', $tz ), "ZoneInfo|$minDiff|$tz", $selZone === $tz, array( 'label' => $z[1] ) );
996 if ( $optgroup !== '' ) $opt .= Xml::closeElement( 'optgroup' );
998 $opt .= Xml::closeElement( 'select' );
1001 Xml::label( wfMsg( 'timezoneselect' ), 'wpTimeZone' ),
1006 Xml::label( wfMsg( 'timezoneoffset' ), 'wpHourDiff' ),
1007 Xml::input( 'wpHourDiff', 6, $this->mHourDiff, array(
1008 'id' => 'wpHourDiff',
1009 'onfocus' => 'javascript:updateTimezoneSelection(true)',
1010 'onblur' => 'javascript:updateTimezoneSelection(false)' ) ) ) .
1013 <td class='mw-submit'>" .
1014 Xml::element( 'input',
1015 array( 'type' => 'button',
1016 'value' => wfMsg( 'guesstimezone' ),
1017 'onclick' => 'javascript:guessTimezone()',
1018 'id' => 'guesstimezonebutton',
1019 'style' => 'display:none;' ) ) .
1022 Xml::closeElement( 'table' ) .
1023 Xml::tags( 'div', array( 'class' => 'prefsectiontip' ), wfMsgExt( 'timezonetext', 'parseinline' ) ).
1024 Xml::closeElement( 'fieldset' ) .
1025 Xml::closeElement( 'fieldset' ) . "\n\n"
1030 global $wgLivePreview;
1032 Xml::fieldset( wfMsg( 'textboxsize' ) ) .
1033 wfMsgHTML( 'prefs-edit-boxsize' ) . ' ' .
1034 Xml::inputLabel( wfMsg( 'rows' ), 'wpRows', 'wpRows', 3, $this->mRows ) . ' ' .
1035 Xml::inputLabel( wfMsg( 'columns' ), 'wpCols', 'wpCols', 3, $this->mCols ) .
1036 $this->getToggles( array(
1038 'editsectiononrightclick',
1047 $wgLivePreview ? 'uselivepreview' : false,
1052 $wgOut->addHTML( Xml::closeElement( 'fieldset' ) );
1057 Xml::fieldset( wfMsg( 'prefs-rc' ) ) .
1058 Xml::openElement( 'table' ) .
1060 <td class="mw-label">' .
1061 Xml::label( wfMsg( 'recentchangesdays' ), 'wpRecentDays' ) .
1063 <td class="mw-input">' .
1064 Xml::input( 'wpRecentDays', 3, $this->mRecentDays, array( 'id' => 'wpRecentDays' ) ) . ' ' .
1065 wfMsgExt( 'recentchangesdays-max', 'parsemag',
1066 $wgLang->formatNum( ceil( $wgRCMaxAge / ( 3600 * 24 ) ) ) ) .
1069 <td class="mw-label">' .
1070 Xml::label( wfMsg( 'recentchangescount' ), 'wpRecent' ) .
1072 <td class="mw-input">' .
1073 Xml::input( 'wpRecent', 3, $this->mRecent, array( 'id' => 'wpRecent' ) ) .
1076 Xml::closeElement( 'table' ) .
1080 $toggles[] = 'hideminor';
1081 if( $wgRCShowWatchingUsers )
1082 $toggles[] = 'shownumberswatching';
1083 $toggles[] = 'usenewrc';
1086 $this->getToggles( $toggles ) .
1087 Xml::closeElement( 'fieldset' )
1092 Xml::fieldset( wfMsg( 'prefs-watchlist' ) ) .
1093 Xml::inputLabel( wfMsg( 'prefs-watchlist-days' ), 'wpWatchlistDays', 'wpWatchlistDays', 3, $this->mWatchlistDays ) . ' ' .
1094 wfMsgHTML( 'prefs-watchlist-days-max' ) .
1096 $this->getToggle( 'extendwatchlist' ) .
1097 Xml::inputLabel( wfMsg( 'prefs-watchlist-edits' ), 'wpWatchlistEdits', 'wpWatchlistEdits', 3, $this->mWatchlistEdits ) . ' ' .
1098 wfMsgHTML( 'prefs-watchlist-edits-max' ) .
1100 $this->getToggles( array( 'watchlisthideminor', 'watchlisthidebots', 'watchlisthideown', 'watchlisthideanons', 'watchlisthideliu' ) )
1103 if( $wgUser->isAllowed( 'createpage' ) || $wgUser->isAllowed( 'createtalk' ) ) {
1104 $wgOut->addHTML( $this->getToggle( 'watchcreations' ) );
1107 foreach( array( 'edit' => 'watchdefault', 'move' => 'watchmoves', 'delete' => 'watchdeletion' ) as $action => $toggle ) {
1108 if( $wgUser->isAllowed( $action ) )
1109 $wgOut->addHTML( $this->getToggle( $toggle ) );
1111 $this->mUsedToggles['watchcreations'] = true;
1112 $this->mUsedToggles['watchdefault'] = true;
1113 $this->mUsedToggles['watchmoves'] = true;
1114 $this->mUsedToggles['watchdeletion'] = true;
1116 $wgOut->addHTML( Xml::closeElement( 'fieldset' ) );
1119 $mwsuggest = $wgEnableMWSuggest ?
1121 Xml::label( wfMsg( 'mwsuggest-disable' ), 'wpDisableMWSuggest' ),
1122 Xml::check( 'wpDisableMWSuggest', $this->mDisableMWSuggest, array( 'id' => 'wpDisableMWSuggest' ) )
1125 // Elements for the search tab itself
1126 Xml::openElement( 'fieldset' ) .
1127 Xml::element( 'legend', null, wfMsg( 'searchresultshead' ) ) .
1128 // Elements for the search options in the search tab
1129 Xml::openElement( 'fieldset' ) .
1130 Xml::element( 'legend', null, wfMsg( 'prefs-searchoptions' ) ) .
1131 Xml::openElement( 'table' ) .
1133 Xml::label( wfMsg( 'resultsperpage' ), 'wpSearch' ),
1134 Xml::input( 'wpSearch', 4, $this->mSearch, array( 'id' => 'wpSearch' ) )
1137 Xml::label( wfMsg( 'contextlines' ), 'wpSearchLines' ),
1138 Xml::input( 'wpSearchLines', 4, $this->mSearchLines, array( 'id' => 'wpSearchLines' ) )
1141 Xml::label( wfMsg( 'contextchars' ), 'wpSearchChars' ),
1142 Xml::input( 'wpSearchChars', 4, $this->mSearchChars, array( 'id' => 'wpSearchChars' ) )
1145 Xml::closeElement( 'table' ) .
1146 Xml::closeElement( 'fieldset' ) .
1147 // Elements for the namespace options in the search tab
1148 Xml::openElement( 'fieldset' ) .
1149 Xml::element( 'legend', null, wfMsg( 'prefs-namespaces' ) ) .
1150 wfMsgExt( 'defaultns', array( 'parse' ) ) .
1152 Xml::closeElement( 'fieldset' ) .
1153 // End of the search tab
1154 Xml::closeElement( 'fieldset' )
1159 $wgOut->addHTML('<fieldset><legend>' . wfMsg('prefs-misc') . '</legend>');
1160 $wgOut->addHTML( '<label for="wpStubs">' . wfMsg( 'stub-threshold' ) . '</label> ' );
1161 $wgOut->addHTML( Xml::input( 'wpStubs', 6, $this->mStubs, array( 'id' => 'wpStubs' ) ) );
1162 $msgUnderline = htmlspecialchars( wfMsg ( 'tog-underline' ) );
1163 $msgUnderlinenever = htmlspecialchars( wfMsg ( 'underline-never' ) );
1164 $msgUnderlinealways = htmlspecialchars( wfMsg ( 'underline-always' ) );
1165 $msgUnderlinedefault = htmlspecialchars( wfMsg ( 'underline-default' ) );
1166 $uopt = $wgUser->getOption("underline");
1167 $s0 = $uopt == 0 ? ' selected="selected"' : '';
1168 $s1 = $uopt == 1 ? ' selected="selected"' : '';
1169 $s2 = $uopt == 2 ? ' selected="selected"' : '';
1171 <div class='toggle'><p><label for='wpOpunderline'>$msgUnderline</label>
1172 <select name='wpOpunderline' id='wpOpunderline'>
1173 <option value=\"0\"$s0>$msgUnderlinenever</option>
1174 <option value=\"1\"$s1>$msgUnderlinealways</option>
1175 <option value=\"2\"$s2>$msgUnderlinedefault</option>
1176 </select></p></div>");
1178 foreach ( $togs as $tname ) {
1179 if( !array_key_exists( $tname, $this->mUsedToggles ) ) {
1180 if( $tname == 'norollbackdiff' && $wgUser->isAllowed( 'rollback' ) )
1181 $wgOut->addHTML( $this->getToggle( $tname ) );
1183 $wgOut->addHTML( $this->getToggle( $tname ) );
1187 $wgOut->addHTML( '</fieldset>' );
1189 wfRunHooks( 'RenderPreferencesForm', array( $this, $wgOut ) );
1191 $token = htmlspecialchars( $wgUser->editToken() );
1192 $skin = $wgUser->getSkin();
1194 <div id='prefsubmit'>
1196 <input type='submit' name='wpSaveprefs' class='btnSavePrefs' value=\"" . wfMsgHtml( 'saveprefs' ) . '"'.$skin->tooltipAndAccesskey('save')." />
1197 <input type='submit' name='wpReset' value=\"" . wfMsgHtml( 'resetprefs' ) . "\" />
1202 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1205 $wgOut->addHTML( Xml::tags( 'div', array( 'class' => "prefcache" ),
1206 wfMsgExt( 'clearyourcache', 'parseinline' ) )