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, $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->mHourDiff
= $request->getVal( 'wpHourDiff' );
55 $this->mSearchLines
= $request->getVal( 'wpSearchLines' );
56 $this->mSearchChars
= $request->getVal( 'wpSearchChars' );
57 $this->mImageSize
= $request->getVal( 'wpImageSize' );
58 $this->mThumbSize
= $request->getInt( 'wpThumbSize' );
59 $this->mUnderline
= $request->getInt( 'wpOpunderline' );
60 $this->mAction
= $request->getVal( 'action' );
61 $this->mReset
= $request->getCheck( 'wpReset' );
62 $this->mPosted
= $request->wasPosted();
63 $this->mSuccess
= $request->getCheck( 'success' );
64 $this->mWatchlistDays
= $request->getVal( 'wpWatchlistDays' );
65 $this->mWatchlistEdits
= $request->getVal( 'wpWatchlistEdits' );
66 $this->mDisableMWSuggest
= $request->getCheck( 'wpDisableMWSuggest' );
68 $this->mSaveprefs
= $request->getCheck( 'wpSaveprefs' ) &&
70 $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
72 # User toggles (the big ugly unsorted list of checkboxes)
73 $this->mToggles
= array();
74 if ( $this->mPosted
) {
75 $togs = User
::getToggles();
76 foreach ( $togs as $tname ) {
77 $this->mToggles
[$tname] = $request->getCheck( "wpOp$tname" ) ?
1 : 0;
81 $this->mUsedToggles
= array();
83 # Search namespace options
84 # Note: namespaces don't necessarily have consecutive keys
85 $this->mSearchNs
= array();
86 if ( $this->mPosted
) {
87 $namespaces = $wgContLang->getNamespaces();
88 foreach ( $namespaces as $i => $namespace ) {
90 $this->mSearchNs
[$i] = $request->getCheck( "wpNs$i" ) ?
1 : 0;
96 if ( !preg_match( '/^[a-z\-]*$/', $this->mUserLanguage
) ) {
97 $this->mUserLanguage
= 'nolanguage';
100 wfRunHooks( 'InitPreferencesForm', array( $this, $request ) );
104 global $wgUser, $wgOut, $wgTitle;
106 if ( $wgUser->isAnon() ) {
107 $wgOut->showErrorPage( 'prefsnologin', 'prefsnologintext', array($wgTitle->getPrefixedDBkey()) );
110 if ( wfReadOnly() ) {
111 $wgOut->readOnlyPage();
114 if ( $this->mReset
) {
116 $this->mainPrefsForm( 'reset', wfMsg( 'prefsreset' ) );
117 } else if ( $this->mSaveprefs
) {
118 $this->savePreferences();
121 $this->mainPrefsForm( '' );
127 function validateInt( &$val, $min=0, $max=0x7fffffff ) {
129 $val = min($val, $max);
130 $val = max($val, $min);
137 function validateFloat( &$val, $min, $max=0x7fffffff ) {
138 $val = floatval( $val );
139 $val = min( $val, $max );
140 $val = max( $val, $min );
147 function validateIntOrNull( &$val, $min=0, $max=0x7fffffff ) {
152 return $this->validateInt( $val, $min, $max );
159 function validateDate( $val ) {
160 global $wgLang, $wgContLang;
161 if ( $val !== false && (
162 in_array( $val, (array)$wgLang->getDatePreferences() ) ||
163 in_array( $val, (array)$wgContLang->getDatePreferences() ) ) )
167 return $wgLang->getDefaultDateFormat();
172 * Used to validate the user inputed timezone before saving it as
173 * 'timecorrection', will return '00:00' if fed bogus data.
174 * Note: It's not a 100% correct implementation timezone-wise, it will
175 * accept stuff like '14:30',
177 * @param string $s the user input
180 function validateTimeZone( $s ) {
182 if ( strpos( $s, ':' ) ) {
184 $array = explode( ':' , $s );
185 $hour = intval( $array[0] );
186 $minute = intval( $array[1] );
188 $minute = intval( $s * 60 );
189 $hour = intval( $minute / 60 );
190 $minute = abs( $minute ) %
60;
192 # Max is +14:00 and min is -12:00, see:
193 # http://en.wikipedia.org/wiki/Timezone
194 $hour = min( $hour, 14 );
195 $hour = max( $hour, -12 );
196 $minute = min( $minute, 59 );
197 $minute = max( $minute, 0 );
198 $s = sprintf( "%02d:%02d", $hour, $minute );
206 function savePreferences() {
207 global $wgUser, $wgOut, $wgParser;
208 global $wgEnableUserEmail, $wgEnableEmail;
209 global $wgEmailAuthentication, $wgRCMaxAge;
210 global $wgAuth, $wgEmailConfirmToEdit;
212 $wgUser->setRealName( $this->mRealName
);
213 $oldOptions = $wgUser->mOptions
;
215 if( $wgUser->getOption( 'language' ) !== $this->mUserLanguage
) {
216 $needRedirect = true;
218 $needRedirect = false;
221 # Validate the signature and clean it up as needed
222 global $wgMaxSigChars;
223 if( mb_strlen( $this->mNick
) > $wgMaxSigChars ) {
225 $this->mainPrefsForm( 'error',
226 wfMsgExt( 'badsiglength', 'parsemag', $wgLang->formatNum( $wgMaxSigChars ) ) );
228 } elseif( $this->mToggles
['fancysig'] ) {
229 if( $wgParser->validateSig( $this->mNick
) !== false ) {
230 $this->mNick
= $wgParser->cleanSig( $this->mNick
);
232 $this->mainPrefsForm( 'error', wfMsg( 'badsig' ) );
236 // When no fancy sig used, make sure ~{3,5} get removed.
237 $this->mNick
= $wgParser->cleanSigInSig( $this->mNick
);
240 $wgUser->setOption( 'language', $this->mUserLanguage
);
241 $wgUser->setOption( 'variant', $this->mUserVariant
);
242 $wgUser->setOption( 'nickname', $this->mNick
);
243 $wgUser->setOption( 'quickbar', $this->mQuickbar
);
244 global $wgAllowUserSkin;
245 if( $wgAllowUserSkin ) {
246 $wgUser->setOption( 'skin', $this->mSkin
);
250 $wgUser->setOption( 'math', $this->mMath
);
252 $wgUser->setOption( 'date', $this->validateDate( $this->mDate
) );
253 $wgUser->setOption( 'searchlimit', $this->validateIntOrNull( $this->mSearch
) );
254 $wgUser->setOption( 'contextlines', $this->validateIntOrNull( $this->mSearchLines
) );
255 $wgUser->setOption( 'contextchars', $this->validateIntOrNull( $this->mSearchChars
) );
256 $wgUser->setOption( 'rclimit', $this->validateIntOrNull( $this->mRecent
) );
257 $wgUser->setOption( 'rcdays', $this->validateInt($this->mRecentDays
, 1, ceil($wgRCMaxAge / (3600*24))));
258 $wgUser->setOption( 'wllimit', $this->validateIntOrNull( $this->mWatchlistEdits
, 0, 1000 ) );
259 $wgUser->setOption( 'rows', $this->validateInt( $this->mRows
, 4, 1000 ) );
260 $wgUser->setOption( 'cols', $this->validateInt( $this->mCols
, 4, 1000 ) );
261 $wgUser->setOption( 'stubthreshold', $this->validateIntOrNull( $this->mStubs
) );
262 $wgUser->setOption( 'timecorrection', $this->validateTimeZone( $this->mHourDiff
, -12, 14 ) );
263 $wgUser->setOption( 'imagesize', $this->mImageSize
);
264 $wgUser->setOption( 'thumbsize', $this->mThumbSize
);
265 $wgUser->setOption( 'underline', $this->validateInt($this->mUnderline
, 0, 2) );
266 $wgUser->setOption( 'watchlistdays', $this->validateFloat( $this->mWatchlistDays
, 0, 7 ) );
267 $wgUser->setOption( 'disablesuggest', $this->mDisableMWSuggest
);
269 # Set search namespace options
270 foreach( $this->mSearchNs
as $i => $value ) {
271 $wgUser->setOption( "searchNs{$i}", $value );
274 if( $wgEnableEmail && $wgEnableUserEmail ) {
275 $wgUser->setOption( 'disablemail', $this->mEmailFlag
);
279 foreach ( $this->mToggles
as $tname => $tvalue ) {
280 $wgUser->setOption( $tname, $tvalue );
284 if( $wgEnableEmail ) {
285 $newadr = $this->mUserEmail
;
286 $oldadr = $wgUser->getEmail();
287 if( ($newadr != '') && ($newadr != $oldadr) ) {
288 # the user has supplied a new email address on the login page
289 if( $wgUser->isValidEmailAddr( $newadr ) ) {
290 # new behaviour: set this new emailaddr from login-page into user database record
291 $wgUser->setEmail( $newadr );
292 # but flag as "dirty" = unauthenticated
293 $wgUser->invalidateEmail();
294 if ($wgEmailAuthentication) {
295 # Mail a temporary password to the dirty address.
296 # User can come back through the confirmation URL to re-enable email.
297 $result = $wgUser->sendConfirmationMail();
298 if( WikiError
::isError( $result ) ) {
299 $error = wfMsg( 'mailerror', htmlspecialchars( $result->getMessage() ) );
301 $error = wfMsg( 'eauthentsent', $wgUser->getName() );
305 $error = wfMsg( 'invalidemailaddress' );
308 if( $wgEmailConfirmToEdit && empty( $newadr ) ) {
309 $this->mainPrefsForm( 'error', wfMsg( 'noemailtitle' ) );
312 $wgUser->setEmail( $this->mUserEmail
);
314 if( $oldadr != $newadr ) {
315 wfRunHooks( 'PrefsEmailAudit', array( $wgUser, $oldadr, $newadr ) );
319 if( !$wgAuth->updateExternalDB( $wgUser ) ){
320 $this->mainPrefsForm( 'error', wfMsg( 'externaldberror' ) );
325 if ( !wfRunHooks( 'SavePreferences', array( $this, $wgUser, &$msg, $oldOptions ) ) ) {
326 $this->mainPrefsForm( 'error', $msg );
330 $wgUser->setCookies();
331 $wgUser->saveSettings();
333 if( $needRedirect && $error === false ) {
334 $title = SpecialPage
::getTitleFor( 'Preferences' );
335 $wgOut->redirect( $title->getFullURL( 'success' ) );
339 $wgOut->parserOptions( ParserOptions
::newFromUser( $wgUser ) );
340 $this->mainPrefsForm( $error === false ?
'success' : 'error', $error);
346 function resetPrefs() {
347 global $wgUser, $wgLang, $wgContLang, $wgContLanguageCode, $wgAllowRealName;
349 $this->mUserEmail
= $wgUser->getEmail();
350 $this->mUserEmailAuthenticationtimestamp
= $wgUser->getEmailAuthenticationtimestamp();
351 $this->mRealName
= ($wgAllowRealName) ?
$wgUser->getRealName() : '';
353 # language value might be blank, default to content language
354 $this->mUserLanguage
= $wgUser->getOption( 'language', $wgContLanguageCode );
356 $this->mUserVariant
= $wgUser->getOption( 'variant');
357 $this->mEmailFlag
= $wgUser->getOption( 'disablemail' ) == 1 ?
1 : 0;
358 $this->mNick
= $wgUser->getOption( 'nickname' );
360 $this->mQuickbar
= $wgUser->getOption( 'quickbar' );
361 $this->mSkin
= Skin
::normalizeKey( $wgUser->getOption( 'skin' ) );
362 $this->mMath
= $wgUser->getOption( 'math' );
363 $this->mDate
= $wgUser->getDatePreference();
364 $this->mRows
= $wgUser->getOption( 'rows' );
365 $this->mCols
= $wgUser->getOption( 'cols' );
366 $this->mStubs
= $wgUser->getOption( 'stubthreshold' );
367 $this->mHourDiff
= $wgUser->getOption( 'timecorrection' );
368 $this->mSearch
= $wgUser->getOption( 'searchlimit' );
369 $this->mSearchLines
= $wgUser->getOption( 'contextlines' );
370 $this->mSearchChars
= $wgUser->getOption( 'contextchars' );
371 $this->mImageSize
= $wgUser->getOption( 'imagesize' );
372 $this->mThumbSize
= $wgUser->getOption( 'thumbsize' );
373 $this->mRecent
= $wgUser->getOption( 'rclimit' );
374 $this->mRecentDays
= $wgUser->getOption( 'rcdays' );
375 $this->mWatchlistEdits
= $wgUser->getOption( 'wllimit' );
376 $this->mUnderline
= $wgUser->getOption( 'underline' );
377 $this->mWatchlistDays
= $wgUser->getOption( 'watchlistdays' );
378 $this->mDisableMWSuggest
= $wgUser->getBoolOption( 'disablesuggest' );
380 $togs = User
::getToggles();
381 foreach ( $togs as $tname ) {
382 $this->mToggles
[$tname] = $wgUser->getOption( $tname );
385 $namespaces = $wgContLang->getNamespaces();
386 foreach ( $namespaces as $i => $namespace ) {
387 if ( $i >= NS_MAIN
) {
388 $this->mSearchNs
[$i] = $wgUser->getOption( 'searchNs'.$i );
392 wfRunHooks( 'ResetPreferences', array( $this, $wgUser ) );
398 function namespacesCheckboxes() {
401 # Determine namespace checkboxes
402 $namespaces = $wgContLang->getNamespaces();
405 foreach ( $namespaces as $i => $name ) {
408 $checked = $this->mSearchNs
[$i] ?
"checked='checked'" : '';
409 $name = str_replace( '_', ' ', $namespaces[$i] );
412 $name = wfMsg( 'blanknamespace' );
414 $r1 .= "<input type='checkbox' value='1' name='wpNs$i' id='wpNs$i' {$checked}/> <label for='wpNs$i'>{$name}</label><br />\n";
420 function getToggle( $tname, $trailer = false, $disabled = false ) {
421 global $wgUser, $wgLang;
423 $this->mUsedToggles
[$tname] = true;
424 $ttext = $wgLang->getUserToggle( $tname );
426 $checked = $wgUser->getOption( $tname ) == 1 ?
' checked="checked"' : '';
427 $disabled = $disabled ?
' disabled="disabled"' : '';
428 $trailer = $trailer ?
$trailer : '';
429 return "<div class='toggle'><input type='checkbox' value='1' id=\"$tname\" name=\"wpOp$tname\"$checked$disabled />" .
430 " <span class='toggletext'><label for=\"$tname\">$ttext</label>$trailer</span></div>\n";
433 function getToggles( $items ) {
435 foreach( $items as $item ) {
436 if( $item === false )
438 if( is_array( $item ) ) {
439 list( $key, $trailer ) = $item;
444 $out .= $this->getToggle( $key, $trailer );
449 function addRow($td1, $td2) {
450 return "<tr><td class='mw-label'>$td1</td><td class='mw-input'>$td2</td></tr>";
454 * Helper function for user information panel
455 * @param $td1 label for an item
456 * @param $td2 item or null
457 * @param $td3 optional help or null
458 * @return xhtml block
460 function tableRow( $td1, $td2 = null, $td3 = null ) {
462 if ( is_null( $td3 ) ) {
465 $td3 = Xml
::tags( 'tr', null,
466 Xml
::tags( 'td', array( 'class' => 'pref-label', 'colspan' => '2' ), $td3 )
470 if ( is_null( $td2 ) ) {
471 $td1 = Xml
::tags( 'td', array( 'class' => 'pref-label', 'colspan' => '2' ), $td1 );
474 $td1 = Xml
::tags( 'td', array( 'class' => 'pref-label' ), $td1 );
475 $td2 = Xml
::tags( 'td', array( 'class' => 'pref-input' ), $td2 );
478 return Xml
::tags( 'tr', null, $td1 . $td2 ). $td3 . "\n";
485 function mainPrefsForm( $status , $message = '' ) {
486 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgAuth;
487 global $wgAllowRealName, $wgImageLimits, $wgThumbLimits;
488 global $wgDisableLangConversion, $wgDisableTitleConversion;
489 global $wgEnotifWatchlist, $wgEnotifUserTalk,$wgEnotifMinorEdits;
490 global $wgRCShowWatchingUsers, $wgEnotifRevealEditorAddress;
491 global $wgEnableEmail, $wgEnableUserEmail, $wgEmailAuthentication;
492 global $wgContLanguageCode, $wgDefaultSkin, $wgCookieExpiration;
493 global $wgEmailConfirmToEdit, $wgEnableMWSuggest;
495 $wgOut->setPageTitle( wfMsg( 'preferences' ) );
496 $wgOut->setArticleRelated( false );
497 $wgOut->setRobotPolicy( 'noindex,nofollow' );
498 $wgOut->addScriptFile( 'prefs.js' );
500 $wgOut->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc.
502 if ( $this->mSuccess ||
'success' == $status ) {
503 $wgOut->wrapWikiMsg( '<div class="successbox"><strong>$1</strong></div>', 'savedprefs' );
504 } else if ( 'error' == $status ) {
505 $wgOut->addWikiText( '<div class="errorbox"><strong>' . $message . '</strong></div>' );
506 } else if ( '' != $status ) {
507 $wgOut->addWikiText( $message . "\n----" );
510 $qbs = $wgLang->getQuickbarSettings();
511 $skinNames = $wgLang->getSkinNames();
512 $mathopts = $wgLang->getMathNames();
513 $dateopts = $wgLang->getDatePreferences();
514 $togs = User
::getToggles();
516 $titleObj = SpecialPage
::getTitleFor( 'Preferences' );
518 # Pre-expire some toggles so they won't show if disabled
519 $this->mUsedToggles
[ 'shownumberswatching' ] = true;
520 $this->mUsedToggles
[ 'showupdated' ] = true;
521 $this->mUsedToggles
[ 'enotifwatchlistpages' ] = true;
522 $this->mUsedToggles
[ 'enotifusertalkpages' ] = true;
523 $this->mUsedToggles
[ 'enotifminoredits' ] = true;
524 $this->mUsedToggles
[ 'enotifrevealaddr' ] = true;
525 $this->mUsedToggles
[ 'ccmeonemails' ] = true;
526 $this->mUsedToggles
[ 'uselivepreview' ] = true;
527 $this->mUsedToggles
[ 'noconvertlink' ] = true;
530 if ( !$this->mEmailFlag
) { $emfc = 'checked="checked"'; }
534 if ($wgEmailAuthentication && ($this->mUserEmail
!= '') ) {
535 if( $wgUser->getEmailAuthenticationTimestamp() ) {
536 // date and time are separate parameters to facilitate localisation.
537 // $time is kept for backward compat reasons.
538 // 'emailauthenticated' is also used in SpecialConfirmemail.php
539 $time = $wgLang->timeAndDate( $wgUser->getEmailAuthenticationTimestamp(), true );
540 $d = $wgLang->date( $wgUser->getEmailAuthenticationTimestamp(), true );
541 $t = $wgLang->time( $wgUser->getEmailAuthenticationTimestamp(), true );
542 $emailauthenticated = wfMsg('emailauthenticated', $time, $d, $t ).'<br />';
543 $disableEmailPrefs = false;
545 $disableEmailPrefs = true;
546 $skin = $wgUser->getSkin();
547 $emailauthenticated = wfMsg('emailnotauthenticated').'<br />' .
548 $skin->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Confirmemail' ),
549 wfMsg( 'emailconfirmlink' ) ) . '<br />';
552 $emailauthenticated = '';
553 $disableEmailPrefs = false;
556 if ($this->mUserEmail
== '') {
557 $emailauthenticated = wfMsg( 'noemailprefs' ) . '<br />';
560 $ps = $this->namespacesCheckboxes();
562 $enotifwatchlistpages = ($wgEnotifWatchlist) ?
$this->getToggle( 'enotifwatchlistpages', false, $disableEmailPrefs ) : '';
563 $enotifusertalkpages = ($wgEnotifUserTalk) ?
$this->getToggle( 'enotifusertalkpages', false, $disableEmailPrefs ) : '';
564 $enotifminoredits = ($wgEnotifWatchlist && $wgEnotifMinorEdits) ?
$this->getToggle( 'enotifminoredits', false, $disableEmailPrefs ) : '';
565 $enotifrevealaddr = (($wgEnotifWatchlist ||
$wgEnotifUserTalk) && $wgEnotifRevealEditorAddress) ?
$this->getToggle( 'enotifrevealaddr', false, $disableEmailPrefs ) : '';
570 Xml
::openElement( 'form', array(
571 'action' => $titleObj->getLocalUrl(),
573 'id' => 'mw-preferences-form',
575 Xml
::openElement( 'div', array( 'id' => 'preferences' ) )
581 Xml
::fieldset( wfMsg('prefs-personal') ) .
582 Xml
::openElement( 'table' ) .
583 $this->tableRow( Xml
::element( 'h2', null, wfMsg( 'prefs-personal' ) ) )
586 # Get groups to which the user belongs
587 $userEffectiveGroups = $wgUser->getEffectiveGroups();
588 $userEffectiveGroupsArray = array();
589 foreach( $userEffectiveGroups as $ueg ) {
591 // Skip the default * group, seems useless here
594 $userEffectiveGroupsArray[] = User
::makeGroupLinkHTML( $ueg );
596 asort( $userEffectiveGroupsArray );
598 $sk = $wgUser->getSkin();
599 $toolLinks = array();
600 $toolLinks[] = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'ListGroupRights' ), wfMsg( 'listgrouprights' ) );
601 # At the moment one tool link only but be prepared for the future...
602 # FIXME: Add a link to Special:Userrights for users who are allowed to use it.
603 # $wgUser->isAllowed( 'userrights' ) seems to strict in some cases
605 $userInformationHtml =
606 $this->tableRow( wfMsgHtml( 'username' ), htmlspecialchars( $wgUser->getName() ) ) .
607 $this->tableRow( wfMsgHtml( 'uid' ), $wgLang->formatNum( htmlspecialchars( $wgUser->getId() ) ) ).
610 wfMsgExt( 'prefs-memberingroups', array( 'parseinline' ), count( $userEffectiveGroupsArray ) ),
611 $wgLang->commaList( $userEffectiveGroupsArray ) .
612 '<br />(' . implode( ' | ', $toolLinks ) . ')'
616 wfMsgHtml( 'prefs-edits' ),
617 $wgLang->formatNum( $wgUser->getEditCount() )
620 if( wfRunHooks( 'PreferencesUserInformationPanel', array( $this, &$userInformationHtml ) ) ) {
621 $wgOut->addHTML( $userInformationHtml );
624 if ( $wgAllowRealName ) {
627 Xml
::label( wfMsg('yourrealname'), 'wpRealName' ),
628 Xml
::input( 'wpRealName', 25, $this->mRealName
, array( 'id' => 'wpRealName' ) ),
629 Xml
::tags('div', array( 'class' => 'prefsectiontip' ),
630 wfMsgExt( 'prefs-help-realname', 'parseinline' )
635 if ( $wgEnableEmail ) {
638 Xml
::label( wfMsg('youremail'), 'wpUserEmail' ),
639 Xml
::input( 'wpUserEmail', 25, $this->mUserEmail
, array( 'id' => 'wpUserEmail' ) ),
640 Xml
::tags('div', array( 'class' => 'prefsectiontip' ),
641 wfMsgExt( $wgEmailConfirmToEdit ?
'prefs-help-email-required' : 'prefs-help-email', 'parseinline' )
647 global $wgParser, $wgMaxSigChars;
648 if( mb_strlen( $this->mNick
) > $wgMaxSigChars ) {
649 $invalidSig = $this->tableRow(
651 Xml
::element( 'span', array( 'class' => 'error' ),
652 wfMsgExt( 'badsiglength', 'parsemag', $wgLang->formatNum( $wgMaxSigChars ) ) )
654 } elseif( !empty( $this->mToggles
['fancysig'] ) &&
655 false === $wgParser->validateSig( $this->mNick
) ) {
656 $invalidSig = $this->tableRow(
658 Xml
::element( 'span', array( 'class' => 'error' ), wfMsg( 'badsig' ) )
666 Xml
::label( wfMsg( 'yournick' ), 'wpNick' ),
667 Xml
::input( 'wpNick', 25, $this->mNick
,
670 // Note: $wgMaxSigChars is enforced in Unicode characters,
671 // both on the backend and now in the browser.
672 // Badly-behaved requests may still try to submit
673 // an overlong string, however.
674 'maxlength' => $wgMaxSigChars ) )
677 $this->tableRow( ' ', $this->getToggle( 'fancysig' ) )
680 list( $lsLabel, $lsSelect) = Xml
::languageSelector( $this->mUserLanguage
);
682 $this->tableRow( $lsLabel, $lsSelect )
685 /* see if there are multiple language variants to choose from*/
686 if(!$wgDisableLangConversion) {
687 $variants = $wgContLang->getVariants();
688 $variantArray = array();
690 $languages = Language
::getLanguageNames( true );
691 foreach($variants as $v) {
692 $v = str_replace( '_', '-', strtolower($v));
693 if( array_key_exists( $v, $languages ) ) {
694 // If it doesn't have a name, we'll pretend it doesn't exist
695 $variantArray[$v] = $languages[$v];
700 foreach( $variantArray as $code => $name ) {
701 $selected = ($code == $this->mUserVariant
);
702 $options .= Xml
::option( "$code - $name", $code, $selected ) . "\n";
705 if(count($variantArray) > 1) {
708 Xml
::label( wfMsg( 'yourvariant' ), 'wpUserVariant' ),
710 array( 'name' => 'wpUserVariant', 'id' => 'wpUserVariant' ),
717 if(count($variantArray) > 1 && !$wgDisableLangConversion && !$wgDisableTitleConversion) {
719 Xml
::tags( 'tr', null,
720 Xml
::tags( 'td', array( 'colspan' => '2' ),
721 $this->getToggle( "noconvertlink" )
729 if( $wgAuth->allowPasswordChange() ) {
730 $link = $wgUser->getSkin()->link( SpecialPage
::getTitleFor( 'ResetPass' ), wfMsgHtml( 'prefs-resetpass' ),
731 array() , array('returnto' => SpecialPage
::getTitleFor( 'Preferences') ) );
733 $this->tableRow( Xml
::element( 'h2', null, wfMsg( 'changepassword' ) ) ) .
734 $this->tableRow( '<ul><li>' . $link . '</li></ul>' ) );
739 if ( $wgEnableEmail ) {
742 if ($wgEnableUserEmail) {
743 // fixme -- the "allowemail" pseudotoggle is a hacked-together
744 // inversion for the "disableemail" preference.
745 $emf = wfMsg( 'allowemail' );
746 $disabled = $disableEmailPrefs ?
' disabled="disabled"' : '';
748 "<input type='checkbox' $emfc $disabled value='1' name='wpEmailFlag' id='wpEmailFlag' /> <label for='wpEmailFlag'>$emf</label>" .
749 $this->getToggle( 'ccmeonemails', '', $disableEmailPrefs );
754 $this->tableRow( Xml
::element( 'h2', null, wfMsg( 'email' ) ) ) .
758 $enotifwatchlistpages.
759 $enotifusertalkpages.
768 Xml
::closeElement( 'table' ) .
769 Xml
::closeElement( 'fieldset' )
775 if ($this->mSkin
== 'cologneblue' ||
$this->mSkin
== 'standard') {
776 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'qbsettings' ) . "</legend>\n" );
777 for ( $i = 0; $i < count( $qbs ); ++
$i ) {
778 if ( $i == $this->mQuickbar
) { $checked = ' checked="checked"'; }
779 else { $checked = ""; }
780 $wgOut->addHTML( "<div><label><input type='radio' name='wpQuickbar' value=\"$i\"$checked />{$qbs[$i]}</label></div>\n" );
782 $wgOut->addHTML( "</fieldset>\n\n" );
784 # Need to output a hidden option even if the relevant skin is not in use,
785 # otherwise the preference will get reset to 0 on submit
786 $wgOut->addHTML( Xml
::hidden( 'wpQuickbar', $this->mQuickbar
) );
791 global $wgAllowUserSkin;
792 if( $wgAllowUserSkin ) {
793 $wgOut->addHTML( "<fieldset>\n<legend>\n" . wfMsg('skin') . "</legend>\n" );
794 $mptitle = Title
::newMainPage();
795 $previewtext = wfMsg('skin-preview');
796 # Only show members of Skin::getSkinNames() rather than
797 # $skinNames (skins is all skin names from Language.php)
798 $validSkinNames = Skin
::getUsableSkins();
799 # Sort by UI skin name. First though need to update validSkinNames as sometimes
800 # the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI).
801 foreach ($validSkinNames as $skinkey => & $skinname ) {
802 if ( isset( $skinNames[$skinkey] ) ) {
803 $skinname = $skinNames[$skinkey];
806 asort($validSkinNames);
807 foreach ($validSkinNames as $skinkey => $sn ) {
808 $checked = $skinkey == $this->mSkin ?
' checked="checked"' : '';
809 $mplink = htmlspecialchars($mptitle->getLocalURL("useskin=$skinkey"));
810 $previewlink = "(<a target='_blank' href=\"$mplink\">$previewtext</a>)";
811 if( $skinkey == $wgDefaultSkin )
812 $sn .= ' (' . wfMsg( 'default' ) . ')';
813 $wgOut->addHTML( "<input type='radio' name='wpSkin' id=\"wpSkin$skinkey\" value=\"$skinkey\"$checked /> <label for=\"wpSkin$skinkey\">{$sn}</label> $previewlink<br />\n" );
815 $wgOut->addHTML( "</fieldset>\n\n" );
822 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg('math') . '</legend>' );
823 foreach ( $mathopts as $k => $v ) {
824 $checked = ($k == $this->mMath
);
826 Xml
::openElement( 'div' ) .
827 Xml
::radioLabel( wfMsg( $v ), 'wpMath', $k, "mw-sp-math-$k", $checked ) .
828 Xml
::closeElement( 'div' ) . "\n"
831 $wgOut->addHTML( "</fieldset>\n\n" );
836 $imageLimitOptions = null;
837 foreach ( $wgImageLimits as $index => $limits ) {
838 $selected = ($index == $this->mImageSize
);
839 $imageLimitOptions .= Xml
::option( "{$limits[0]}×{$limits[1]}" .
840 wfMsg('unit-pixel'), $index, $selected );
843 $imageThumbOptions = null;
844 foreach ( $wgThumbLimits as $index => $size ) {
845 $selected = ($index == $this->mThumbSize
);
846 $imageThumbOptions .= Xml
::option($size . wfMsg('unit-pixel'), $index,
850 $imageSizeId = 'wpImageSize';
851 $thumbSizeId = 'wpThumbSize';
853 Xml
::fieldset( wfMsg( 'files' ) ) . "\n" .
854 Xml
::openElement( 'table' ) .
856 <td class="mw-label">' .
857 Xml
::label( wfMsg( 'imagemaxsize' ), $imageSizeId ) .
859 <td class="mw-input">' .
860 Xml
::openElement( 'select', array( 'name' => $imageSizeId, 'id' => $imageSizeId ) ) .
862 Xml
::closeElement( 'select' ) .
865 <td class="mw-label">' .
866 Xml
::label( wfMsg( 'thumbsize' ), $thumbSizeId ) .
868 <td class="mw-input">' .
869 Xml
::openElement( 'select', array( 'name' => $thumbSizeId, 'id' => $thumbSizeId ) ) .
871 Xml
::closeElement( 'select' ) .
874 Xml
::closeElement( 'table' ) .
875 Xml
::closeElement( 'fieldset' )
884 Xml
::openElement( 'fieldset' ) .
885 Xml
::element( 'legend', null, wfMsg( 'datetime' ) ) . "\n"
890 Xml
::openElement( 'fieldset' ) .
891 Xml
::element( 'legend', null, wfMsg( 'dateformat' ) ) . "\n"
894 $epoch = '20010115161234'; # Wikipedia day
895 foreach( $dateopts as $key ) {
896 if( $key == 'default' ) {
897 $formatted = wfMsg( 'datedefault' );
899 $formatted = $wgLang->timeanddate( $epoch, false, $key );
902 Xml
::tags( 'div', null,
903 Xml
::radioLabel( $formatted, 'wpDate', $key, "wpDate$idCnt", $key == $this->mDate
)
908 $wgOut->addHTML( Xml
::closeElement( 'fieldset' ) . "\n" );
911 $nowlocal = $wgLang->time( $now = wfTimestampNow(), true );
912 $nowserver = $wgLang->time( $now, false );
915 Xml
::openElement( 'fieldset' ) .
916 Xml
::element( 'legend', null, wfMsg( 'timezonelegend' ) ) .
917 Xml
::openElement( 'table' ) .
918 $this->addRow( wfMsg( 'servertime' ), $nowserver ) .
919 $this->addRow( wfMsg( 'localtime' ), $nowlocal ) .
921 Xml
::label( wfMsg( 'timezoneoffset' ), 'wpHourDiff' ),
922 Xml
::input( 'wpHourDiff', 6, $this->mHourDiff
, array( 'id' => 'wpHourDiff' ) ) ) .
925 <td class='mw-submit'>" .
926 Xml
::element( 'input',
927 array( 'type' => 'button',
928 'value' => wfMsg( 'guesstimezone' ),
929 'onclick' => 'javascript:guessTimezone()',
930 'id' => 'guesstimezonebutton',
931 'style' => 'display:none;' ) ) .
934 Xml
::closeElement( 'table' ) .
935 Xml
::tags( 'div', array( 'class' => 'prefsectiontip' ), wfMsgExt( 'timezonetext', 'parseinline' ) ).
936 Xml
::closeElement( 'fieldset' ) .
937 Xml
::closeElement( 'fieldset' ) . "\n\n"
942 global $wgLivePreview;
944 Xml
::fieldset( wfMsg( 'textboxsize' ) ) .
945 wfMsgHTML( 'prefs-edit-boxsize' ) . ' ' .
946 Xml
::inputLabel( wfMsg( 'rows' ), 'wpRows', 'wpRows', 3, $this->mRows
) . ' ' .
947 Xml
::inputLabel( wfMsg( 'columns' ), 'wpCols', 'wpCols', 3, $this->mCols
) .
948 $this->getToggles( array(
950 'editsectiononrightclick',
959 $wgLivePreview ?
'uselivepreview' : false,
964 $wgOut->addHTML( Xml
::closeElement( 'fieldset' ) );
969 Xml
::fieldset( wfMsg( 'prefs-rc' ) ) .
970 Xml
::openElement( 'table' ) .
972 <td class="mw-label">' .
973 Xml
::label( wfMsg( 'recentchangesdays' ), 'wpRecentDays' ) .
975 <td class="mw-input">' .
976 Xml
::input( 'wpRecentDays', 3, $this->mRecentDays
, array( 'id' => 'wpRecentDays' ) ) . ' ' .
977 wfMsgExt( 'recentchangesdays-max', 'parsemag',
978 $wgLang->formatNum( ceil( $wgRCMaxAge / ( 3600 * 24 ) ) ) ) .
981 <td class="mw-label">' .
982 Xml
::label( wfMsg( 'recentchangescount' ), 'wpRecent' ) .
984 <td class="mw-input">' .
985 Xml
::input( 'wpRecent', 3, $this->mRecent
, array( 'id' => 'wpRecent' ) ) .
988 Xml
::closeElement( 'table' ) .
992 $toggles[] = 'hideminor';
993 if( $wgRCShowWatchingUsers )
994 $toggles[] = 'shownumberswatching';
995 $toggles[] = 'usenewrc';
998 $this->getToggles( $toggles ) .
999 Xml
::closeElement( 'fieldset' )
1004 Xml
::fieldset( wfMsg( 'prefs-watchlist' ) ) .
1005 Xml
::inputLabel( wfMsg( 'prefs-watchlist-days' ), 'wpWatchlistDays', 'wpWatchlistDays', 3, $this->mWatchlistDays
) . ' ' .
1006 wfMsgHTML( 'prefs-watchlist-days-max' ) .
1008 $this->getToggle( 'extendwatchlist' ) .
1009 Xml
::inputLabel( wfMsg( 'prefs-watchlist-edits' ), 'wpWatchlistEdits', 'wpWatchlistEdits', 3, $this->mWatchlistEdits
) . ' ' .
1010 wfMsgHTML( 'prefs-watchlist-edits-max' ) .
1012 $this->getToggles( array( 'watchlisthideminor', 'watchlisthidebots', 'watchlisthideown', 'watchlisthideanons', 'watchlisthideliu' ) )
1015 if( $wgUser->isAllowed( 'createpage' ) ||
$wgUser->isAllowed( 'createtalk' ) ) {
1016 $wgOut->addHTML( $this->getToggle( 'watchcreations' ) );
1019 foreach( array( 'edit' => 'watchdefault', 'move' => 'watchmoves', 'delete' => 'watchdeletion' ) as $action => $toggle ) {
1020 if( $wgUser->isAllowed( $action ) )
1021 $wgOut->addHTML( $this->getToggle( $toggle ) );
1023 $this->mUsedToggles
['watchcreations'] = true;
1024 $this->mUsedToggles
['watchdefault'] = true;
1025 $this->mUsedToggles
['watchmoves'] = true;
1026 $this->mUsedToggles
['watchdeletion'] = true;
1028 $wgOut->addHTML( Xml
::closeElement( 'fieldset' ) );
1031 $mwsuggest = $wgEnableMWSuggest ?
1033 Xml
::label( wfMsg( 'mwsuggest-disable' ), 'wpDisableMWSuggest' ),
1034 Xml
::check( 'wpDisableMWSuggest', $this->mDisableMWSuggest
, array( 'id' => 'wpDisableMWSuggest' ) )
1037 // Elements for the search tab itself
1038 Xml
::openElement( 'fieldset' ) .
1039 Xml
::element( 'legend', null, wfMsg( 'searchresultshead' ) ) .
1040 // Elements for the search options in the search tab
1041 Xml
::openElement( 'fieldset' ) .
1042 Xml
::element( 'legend', null, wfMsg( 'prefs-searchoptions' ) ) .
1043 Xml
::openElement( 'table' ) .
1045 Xml
::label( wfMsg( 'resultsperpage' ), 'wpSearch' ),
1046 Xml
::input( 'wpSearch', 4, $this->mSearch
, array( 'id' => 'wpSearch' ) )
1049 Xml
::label( wfMsg( 'contextlines' ), 'wpSearchLines' ),
1050 Xml
::input( 'wpSearchLines', 4, $this->mSearchLines
, array( 'id' => 'wpSearchLines' ) )
1053 Xml
::label( wfMsg( 'contextchars' ), 'wpSearchChars' ),
1054 Xml
::input( 'wpSearchChars', 4, $this->mSearchChars
, array( 'id' => 'wpSearchChars' ) )
1057 Xml
::closeElement( 'table' ) .
1058 Xml
::closeElement( 'fieldset' ) .
1059 // Elements for the namespace options in the search tab
1060 Xml
::openElement( 'fieldset' ) .
1061 Xml
::element( 'legend', null, wfMsg( 'prefs-namespaces' ) ) .
1062 wfMsgExt( 'defaultns', array( 'parse' ) ) .
1064 Xml
::closeElement( 'fieldset' ) .
1065 // End of the search tab
1066 Xml
::closeElement( 'fieldset' )
1071 $wgOut->addHTML('<fieldset><legend>' . wfMsg('prefs-misc') . '</legend>');
1072 $wgOut->addHTML( '<label for="wpStubs">' . wfMsg( 'stub-threshold' ) . '</label> ' );
1073 $wgOut->addHTML( Xml
::input( 'wpStubs', 6, $this->mStubs
, array( 'id' => 'wpStubs' ) ) );
1074 $msgUnderline = htmlspecialchars( wfMsg ( 'tog-underline' ) );
1075 $msgUnderlinenever = htmlspecialchars( wfMsg ( 'underline-never' ) );
1076 $msgUnderlinealways = htmlspecialchars( wfMsg ( 'underline-always' ) );
1077 $msgUnderlinedefault = htmlspecialchars( wfMsg ( 'underline-default' ) );
1078 $uopt = $wgUser->getOption("underline");
1079 $s0 = $uopt == 0 ?
' selected="selected"' : '';
1080 $s1 = $uopt == 1 ?
' selected="selected"' : '';
1081 $s2 = $uopt == 2 ?
' selected="selected"' : '';
1083 <div class='toggle'><p><label for='wpOpunderline'>$msgUnderline</label>
1084 <select name='wpOpunderline' id='wpOpunderline'>
1085 <option value=\"0\"$s0>$msgUnderlinenever</option>
1086 <option value=\"1\"$s1>$msgUnderlinealways</option>
1087 <option value=\"2\"$s2>$msgUnderlinedefault</option>
1088 </select></p></div>");
1090 foreach ( $togs as $tname ) {
1091 if( !array_key_exists( $tname, $this->mUsedToggles
) ) {
1092 if( $tname == 'norollbackdiff' && $wgUser->isAllowed( 'rollback' ) )
1093 $wgOut->addHTML( $this->getToggle( $tname ) );
1095 $wgOut->addHTML( $this->getToggle( $tname ) );
1099 $wgOut->addHTML( '</fieldset>' );
1101 wfRunHooks( 'RenderPreferencesForm', array( $this, $wgOut ) );
1103 $token = htmlspecialchars( $wgUser->editToken() );
1104 $skin = $wgUser->getSkin();
1106 <div id='prefsubmit'>
1108 <input type='submit' name='wpSaveprefs' class='btnSavePrefs' value=\"" . wfMsgHtml( 'saveprefs' ) . '"'.$skin->tooltipAndAccesskey('save')." />
1109 <input type='submit' name='wpReset' value=\"" . wfMsgHtml( 'resetprefs' ) . "\" />
1114 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1117 $wgOut->addHTML( Xml
::tags( 'div', array( 'class' => "prefcache" ),
1118 wfMsgExt( 'clearyourcache', 'parseinline' ) )