3 * Hold things related to displaying and saving user preferences.
4 * @addtogroup SpecialPage
8 * Entry point that create the "Preferences" object
10 function wfSpecialPreferences() {
13 $form = new PreferencesForm( $wgRequest );
18 * Preferences form handling
19 * This object will show the preferences form and can save it as well.
20 * @addtogroup SpecialPage
22 class PreferencesForm
{
23 var $mQuickbar, $mOldpass, $mNewpass, $mRetypePass, $mStubs;
24 var $mRows, $mCols, $mSkin, $mMath, $mDate, $mUserEmail, $mEmailFlag, $mNick;
25 var $mUserLanguage, $mUserVariant;
26 var $mSearch, $mRecent, $mRecentDays, $mHourDiff, $mSearchLines, $mSearchChars, $mAction;
27 var $mReset, $mPosted, $mToggles, $mUseAjaxSearch, $mSearchNs, $mRealName, $mImageSize;
28 var $mUnderline, $mWatchlistEdits;
34 function PreferencesForm( &$request ) {
35 global $wgContLang, $wgUser, $wgAllowRealName;
37 $this->mQuickbar
= $request->getVal( 'wpQuickbar' );
38 $this->mOldpass
= $request->getVal( 'wpOldpass' );
39 $this->mNewpass
= $request->getVal( 'wpNewpass' );
40 $this->mRetypePass
=$request->getVal( 'wpRetypePass' );
41 $this->mStubs
= $request->getVal( 'wpStubs' );
42 $this->mRows
= $request->getVal( 'wpRows' );
43 $this->mCols
= $request->getVal( 'wpCols' );
44 $this->mSkin
= $request->getVal( 'wpSkin' );
45 $this->mMath
= $request->getVal( 'wpMath' );
46 $this->mDate
= $request->getVal( 'wpDate' );
47 $this->mUserEmail
= $request->getVal( 'wpUserEmail' );
48 $this->mRealName
= $wgAllowRealName ?
$request->getVal( 'wpRealName' ) : '';
49 $this->mEmailFlag
= $request->getCheck( 'wpEmailFlag' ) ?
0 : 1;
50 $this->mNick
= $request->getVal( 'wpNick' );
51 $this->mUserLanguage
= $request->getVal( 'wpUserLanguage' );
52 $this->mUserVariant
= $request->getVal( 'wpUserVariant' );
53 $this->mSearch
= $request->getVal( 'wpSearch' );
54 $this->mRecent
= $request->getVal( 'wpRecent' );
55 $this->mRecentDays
= $request->getVal( 'wpRecentDays' );
56 $this->mHourDiff
= $request->getVal( 'wpHourDiff' );
57 $this->mSearchLines
= $request->getVal( 'wpSearchLines' );
58 $this->mSearchChars
= $request->getVal( 'wpSearchChars' );
59 $this->mImageSize
= $request->getVal( 'wpImageSize' );
60 $this->mThumbSize
= $request->getInt( 'wpThumbSize' );
61 $this->mUnderline
= $request->getInt( 'wpOpunderline' );
62 $this->mAction
= $request->getVal( 'action' );
63 $this->mReset
= $request->getCheck( 'wpReset' );
64 $this->mPosted
= $request->wasPosted();
65 $this->mSuccess
= $request->getCheck( 'success' );
66 $this->mWatchlistDays
= $request->getVal( 'wpWatchlistDays' );
67 $this->mWatchlistEdits
= $request->getVal( 'wpWatchlistEdits' );
68 $this->mUseAjaxSearch
= $request->getCheck( 'wpUseAjaxSearch' );
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;
108 if ( $wgUser->isAnon() ) {
109 $wgOut->showErrorPage( 'prefsnologin', 'prefsnologintext' );
112 if ( wfReadOnly() ) {
113 $wgOut->readOnlyPage();
116 if ( $this->mReset
) {
118 $this->mainPrefsForm( 'reset', wfMsg( 'prefsreset' ) );
119 } else if ( $this->mSaveprefs
) {
120 $this->savePreferences();
123 $this->mainPrefsForm( '' );
129 function validateInt( &$val, $min=0, $max=0x7fffffff ) {
131 $val = min($val, $max);
132 $val = max($val, $min);
139 function validateFloat( &$val, $min, $max=0x7fffffff ) {
140 $val = floatval( $val );
141 $val = min( $val, $max );
142 $val = max( $val, $min );
149 function validateIntOrNull( &$val, $min=0, $max=0x7fffffff ) {
154 return $this->validateInt( $val, $min, $max );
161 function validateDate( $val ) {
162 global $wgLang, $wgContLang;
163 if ( $val !== false && (
164 in_array( $val, (array)$wgLang->getDatePreferences() ) ||
165 in_array( $val, (array)$wgContLang->getDatePreferences() ) ) )
169 return $wgLang->getDefaultDateFormat();
174 * Used to validate the user inputed timezone before saving it as
175 * 'timecorrection', will return '00:00' if fed bogus data.
176 * Note: It's not a 100% correct implementation timezone-wise, it will
177 * accept stuff like '14:30',
179 * @param string $s the user input
182 function validateTimeZone( $s ) {
184 if ( strpos( $s, ':' ) ) {
186 $array = explode( ':' , $s );
187 $hour = intval( $array[0] );
188 $minute = intval( $array[1] );
190 $minute = intval( $s * 60 );
191 $hour = intval( $minute / 60 );
192 $minute = abs( $minute ) %
60;
194 # Max is +14:00 and min is -12:00, see:
195 # http://en.wikipedia.org/wiki/Timezone
196 $hour = min( $hour, 14 );
197 $hour = max( $hour, -12 );
198 $minute = min( $minute, 59 );
199 $minute = max( $minute, 0 );
200 $s = sprintf( "%02d:%02d", $hour, $minute );
208 function savePreferences() {
209 global $wgUser, $wgOut, $wgParser;
210 global $wgEnableUserEmail, $wgEnableEmail;
211 global $wgEmailAuthentication, $wgRCMaxAge;
212 global $wgAuth, $wgEmailConfirmToEdit;
215 if ( '' != $this->mNewpass
&& $wgAuth->allowPasswordChange() ) {
216 if ( $this->mNewpass
!= $this->mRetypePass
) {
217 wfRunHooks( 'PrefsPasswordAudit', array( $wgUser, $this->mNewpass
, 'badretype' ) );
218 $this->mainPrefsForm( 'error', wfMsg( 'badretype' ) );
222 if (!$wgUser->checkPassword( $this->mOldpass
)) {
223 wfRunHooks( 'PrefsPasswordAudit', array( $wgUser, $this->mNewpass
, 'wrongpassword' ) );
224 $this->mainPrefsForm( 'error', wfMsg( 'wrongpassword' ) );
229 $wgUser->setPassword( $this->mNewpass
);
230 wfRunHooks( 'PrefsPasswordAudit', array( $wgUser, $this->mNewpass
, 'success' ) );
231 $this->mNewpass
= $this->mOldpass
= $this->mRetypePass
= '';
232 } catch( PasswordError
$e ) {
233 wfRunHooks( 'PrefsPasswordAudit', array( $wgUser, $this->mNewpass
, 'error' ) );
234 $this->mainPrefsForm( 'error', $e->getMessage() );
238 $wgUser->setRealName( $this->mRealName
);
239 $oldOptions = $wgUser->mOptions
;
241 if( $wgUser->getOption( 'language' ) !== $this->mUserLanguage
) {
242 $needRedirect = true;
244 $needRedirect = false;
247 # Validate the signature and clean it up as needed
248 global $wgMaxSigChars;
249 if( mb_strlen( $this->mNick
) > $wgMaxSigChars ) {
251 $this->mainPrefsForm( 'error',
252 wfMsg( 'badsiglength', $wgLang->formatNum( $wgMaxSigChars ) ) );
254 } elseif( $this->mToggles
['fancysig'] ) {
255 if( $wgParser->validateSig( $this->mNick
) !== false ) {
256 $this->mNick
= $wgParser->cleanSig( $this->mNick
);
258 $this->mainPrefsForm( 'error', wfMsg( 'badsig' ) );
262 // When no fancy sig used, make sure ~{3,5} get removed.
263 $this->mNick
= $wgParser->cleanSigInSig( $this->mNick
);
266 $wgUser->setOption( 'language', $this->mUserLanguage
);
267 $wgUser->setOption( 'variant', $this->mUserVariant
);
268 $wgUser->setOption( 'nickname', $this->mNick
);
269 $wgUser->setOption( 'quickbar', $this->mQuickbar
);
270 $wgUser->setOption( 'skin', $this->mSkin
);
273 $wgUser->setOption( 'math', $this->mMath
);
275 $wgUser->setOption( 'date', $this->validateDate( $this->mDate
) );
276 $wgUser->setOption( 'searchlimit', $this->validateIntOrNull( $this->mSearch
) );
277 $wgUser->setOption( 'contextlines', $this->validateIntOrNull( $this->mSearchLines
) );
278 $wgUser->setOption( 'contextchars', $this->validateIntOrNull( $this->mSearchChars
) );
279 $wgUser->setOption( 'rclimit', $this->validateIntOrNull( $this->mRecent
) );
280 $wgUser->setOption( 'rcdays', $this->validateInt($this->mRecentDays
, 1, ceil($wgRCMaxAge / (3600*24))));
281 $wgUser->setOption( 'wllimit', $this->validateIntOrNull( $this->mWatchlistEdits
, 0, 1000 ) );
282 $wgUser->setOption( 'rows', $this->validateInt( $this->mRows
, 4, 1000 ) );
283 $wgUser->setOption( 'cols', $this->validateInt( $this->mCols
, 4, 1000 ) );
284 $wgUser->setOption( 'stubthreshold', $this->validateIntOrNull( $this->mStubs
) );
285 $wgUser->setOption( 'timecorrection', $this->validateTimeZone( $this->mHourDiff
, -12, 14 ) );
286 $wgUser->setOption( 'imagesize', $this->mImageSize
);
287 $wgUser->setOption( 'thumbsize', $this->mThumbSize
);
288 $wgUser->setOption( 'underline', $this->validateInt($this->mUnderline
, 0, 2) );
289 $wgUser->setOption( 'watchlistdays', $this->validateFloat( $this->mWatchlistDays
, 0, 7 ) );
290 $wgUser->setOption( 'ajaxsearch', $this->mUseAjaxSearch
);
292 # Set search namespace options
293 foreach( $this->mSearchNs
as $i => $value ) {
294 $wgUser->setOption( "searchNs{$i}", $value );
297 if( $wgEnableEmail && $wgEnableUserEmail ) {
298 $wgUser->setOption( 'disablemail', $this->mEmailFlag
);
302 foreach ( $this->mToggles
as $tname => $tvalue ) {
303 $wgUser->setOption( $tname, $tvalue );
307 if( $wgEnableEmail ) {
308 $newadr = $this->mUserEmail
;
309 $oldadr = $wgUser->getEmail();
310 if( ($newadr != '') && ($newadr != $oldadr) ) {
311 # the user has supplied a new email address on the login page
312 if( $wgUser->isValidEmailAddr( $newadr ) ) {
313 # new behaviour: set this new emailaddr from login-page into user database record
314 $wgUser->setEmail( $newadr );
315 # but flag as "dirty" = unauthenticated
316 $wgUser->invalidateEmail();
317 if ($wgEmailAuthentication) {
318 # Mail a temporary password to the dirty address.
319 # User can come back through the confirmation URL to re-enable email.
320 $result = $wgUser->sendConfirmationMail();
321 if( WikiError
::isError( $result ) ) {
322 $error = wfMsg( 'mailerror', htmlspecialchars( $result->getMessage() ) );
324 $error = wfMsg( 'eauthentsent', $wgUser->getName() );
328 $error = wfMsg( 'invalidemailaddress' );
331 if( $wgEmailConfirmToEdit && empty( $newadr ) ) {
332 $this->mainPrefsForm( 'error', wfMsg( 'noemailtitle' ) );
335 $wgUser->setEmail( $this->mUserEmail
);
337 if( $oldadr != $newadr ) {
338 wfRunHooks( 'PrefsEmailAudit', array( $wgUser, $oldadr, $newadr ) );
342 if( !$wgAuth->updateExternalDB( $wgUser ) ){
343 $this->mainPrefsForm( 'error', wfMsg( 'externaldberror' ) );
348 if ( !wfRunHooks( 'SavePreferences', array( $this, $wgUser, &$msg, $oldOptions ) ) ) {
349 $this->mainPrefsForm( 'error', $msg );
353 $wgUser->setCookies();
354 $wgUser->saveSettings();
356 if( $needRedirect && $error === false ) {
357 $title = SpecialPage
::getTitleFor( 'Preferences' );
358 $wgOut->redirect( $title->getFullURL( 'success' ) );
362 $wgOut->parserOptions( ParserOptions
::newFromUser( $wgUser ) );
363 $this->mainPrefsForm( $error === false ?
'success' : 'error', $error);
369 function resetPrefs() {
370 global $wgUser, $wgLang, $wgContLang, $wgContLanguageCode, $wgAllowRealName;
372 $this->mOldpass
= $this->mNewpass
= $this->mRetypePass
= '';
373 $this->mUserEmail
= $wgUser->getEmail();
374 $this->mUserEmailAuthenticationtimestamp
= $wgUser->getEmailAuthenticationtimestamp();
375 $this->mRealName
= ($wgAllowRealName) ?
$wgUser->getRealName() : '';
377 # language value might be blank, default to content language
378 $this->mUserLanguage
= $wgUser->getOption( 'language', $wgContLanguageCode );
380 $this->mUserVariant
= $wgUser->getOption( 'variant');
381 $this->mEmailFlag
= $wgUser->getOption( 'disablemail' ) == 1 ?
1 : 0;
382 $this->mNick
= $wgUser->getOption( 'nickname' );
384 $this->mQuickbar
= $wgUser->getOption( 'quickbar' );
385 $this->mSkin
= Skin
::normalizeKey( $wgUser->getOption( 'skin' ) );
386 $this->mMath
= $wgUser->getOption( 'math' );
387 $this->mDate
= $wgUser->getDatePreference();
388 $this->mRows
= $wgUser->getOption( 'rows' );
389 $this->mCols
= $wgUser->getOption( 'cols' );
390 $this->mStubs
= $wgUser->getOption( 'stubthreshold' );
391 $this->mHourDiff
= $wgUser->getOption( 'timecorrection' );
392 $this->mSearch
= $wgUser->getOption( 'searchlimit' );
393 $this->mSearchLines
= $wgUser->getOption( 'contextlines' );
394 $this->mSearchChars
= $wgUser->getOption( 'contextchars' );
395 $this->mImageSize
= $wgUser->getOption( 'imagesize' );
396 $this->mThumbSize
= $wgUser->getOption( 'thumbsize' );
397 $this->mRecent
= $wgUser->getOption( 'rclimit' );
398 $this->mRecentDays
= $wgUser->getOption( 'rcdays' );
399 $this->mWatchlistEdits
= $wgUser->getOption( 'wllimit' );
400 $this->mUnderline
= $wgUser->getOption( 'underline' );
401 $this->mWatchlistDays
= $wgUser->getOption( 'watchlistdays' );
402 $this->mUseAjaxSearch
= $wgUser->getBoolOption( 'ajaxsearch' );
404 $togs = User
::getToggles();
405 foreach ( $togs as $tname ) {
406 $this->mToggles
[$tname] = $wgUser->getOption( $tname );
409 $namespaces = $wgContLang->getNamespaces();
410 foreach ( $namespaces as $i => $namespace ) {
411 if ( $i >= NS_MAIN
) {
412 $this->mSearchNs
[$i] = $wgUser->getOption( 'searchNs'.$i );
416 wfRunHooks( 'ResetPreferences', array( $this, $wgUser ) );
422 function namespacesCheckboxes() {
425 # Determine namespace checkboxes
426 $namespaces = $wgContLang->getNamespaces();
429 foreach ( $namespaces as $i => $name ) {
432 $checked = $this->mSearchNs
[$i] ?
"checked='checked'" : '';
433 $name = str_replace( '_', ' ', $namespaces[$i] );
436 $name = wfMsg( 'blanknamespace' );
438 $r1 .= "<input type='checkbox' value='1' name='wpNs$i' id='wpNs$i' {$checked}/> <label for='wpNs$i'>{$name}</label><br />\n";
444 function getToggle( $tname, $trailer = false, $disabled = false ) {
445 global $wgUser, $wgLang;
447 $this->mUsedToggles
[$tname] = true;
448 $ttext = $wgLang->getUserToggle( $tname );
450 $checked = $wgUser->getOption( $tname ) == 1 ?
' checked="checked"' : '';
451 $disabled = $disabled ?
' disabled="disabled"' : '';
452 $trailer = $trailer ?
$trailer : '';
453 return "<div class='toggle'><input type='checkbox' value='1' id=\"$tname\" name=\"wpOp$tname\"$checked$disabled />" .
454 " <span class='toggletext'><label for=\"$tname\">$ttext</label>$trailer</span></div>\n";
457 function getToggles( $items ) {
459 foreach( $items as $item ) {
460 if( $item === false )
462 if( is_array( $item ) ) {
463 list( $key, $trailer ) = $item;
468 $out .= $this->getToggle( $key, $trailer );
473 function addRow($td1, $td2) {
474 return "<tr><td align='right'>$td1</td><td align='left'>$td2</td></tr>";
478 * Helper function for user information panel
479 * @param $td1 label for an item
480 * @param $td2 item or null
481 * @param $td3 optional help or null
482 * @return xhtml block
484 function tableRow( $td1, $td2 = null, $td3 = null ) {
487 $align['align'] = $wgContLang->isRtl() ?
'right' : 'left';
489 if ( is_null( $td3 ) ) {
492 $td3 = Xml
::tags( 'tr', null,
493 Xml
::tags( 'td', array( 'colspan' => '2' ), $td3 )
497 if ( is_null( $td2 ) ) {
498 $td1 = Xml
::tags( 'td', $align +
array( 'colspan' => '2' ), $td1 );
501 $td1 = Xml
::tags( 'td', $align, $td1 );
502 $td2 = Xml
::tags( 'td', $align, $td2 );
505 return Xml
::tags( 'tr', null, $td1 . $td2 ). $td3 . "\n";
512 function mainPrefsForm( $status , $message = '' ) {
513 global $wgUser, $wgOut, $wgLang, $wgContLang;
514 global $wgAllowRealName, $wgImageLimits, $wgThumbLimits;
515 global $wgDisableLangConversion;
516 global $wgEnotifWatchlist, $wgEnotifUserTalk,$wgEnotifMinorEdits;
517 global $wgRCShowWatchingUsers, $wgEnotifRevealEditorAddress;
518 global $wgEnableEmail, $wgEnableUserEmail, $wgEmailAuthentication;
519 global $wgContLanguageCode, $wgDefaultSkin, $wgSkipSkins, $wgAuth;
520 global $wgEmailConfirmToEdit, $wgAjaxSearch;
522 $wgOut->setPageTitle( wfMsg( 'preferences' ) );
523 $wgOut->setArticleRelated( false );
524 $wgOut->setRobotpolicy( 'noindex,nofollow' );
526 $wgOut->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc.
528 if ( $this->mSuccess ||
'success' == $status ) {
529 $wgOut->wrapWikiMsg( '<div class="successbox"><strong>$1</strong></div>', 'savedprefs' );
530 } else if ( 'error' == $status ) {
531 $wgOut->addWikiText( '<div class="errorbox"><strong>' . $message . '</strong></div>' );
532 } else if ( '' != $status ) {
533 $wgOut->addWikiText( $message . "\n----" );
536 $qbs = $wgLang->getQuickbarSettings();
537 $skinNames = $wgLang->getSkinNames();
538 $mathopts = $wgLang->getMathNames();
539 $dateopts = $wgLang->getDatePreferences();
540 $togs = User
::getToggles();
542 $titleObj = SpecialPage
::getTitleFor( 'Preferences' );
543 $action = $titleObj->escapeLocalURL();
545 # Pre-expire some toggles so they won't show if disabled
546 $this->mUsedToggles
[ 'shownumberswatching' ] = true;
547 $this->mUsedToggles
[ 'showupdated' ] = true;
548 $this->mUsedToggles
[ 'enotifwatchlistpages' ] = true;
549 $this->mUsedToggles
[ 'enotifusertalkpages' ] = true;
550 $this->mUsedToggles
[ 'enotifminoredits' ] = true;
551 $this->mUsedToggles
[ 'enotifrevealaddr' ] = true;
552 $this->mUsedToggles
[ 'ccmeonemails' ] = true;
553 $this->mUsedToggles
[ 'uselivepreview' ] = true;
556 if ( !$this->mEmailFlag
) { $emfc = 'checked="checked"'; }
560 if ($wgEmailAuthentication && ($this->mUserEmail
!= '') ) {
561 if( $wgUser->getEmailAuthenticationTimestamp() ) {
562 $emailauthenticated = wfMsg('emailauthenticated',$wgLang->timeanddate($wgUser->getEmailAuthenticationTimestamp(), true ) ).'<br />';
563 $disableEmailPrefs = false;
565 $disableEmailPrefs = true;
566 $skin = $wgUser->getSkin();
567 $emailauthenticated = wfMsg('emailnotauthenticated').'<br />' .
568 $skin->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Confirmemail' ),
569 wfMsg( 'emailconfirmlink' ) ) . '<br />';
572 $emailauthenticated = '';
573 $disableEmailPrefs = false;
576 if ($this->mUserEmail
== '') {
577 $emailauthenticated = wfMsg( 'noemailprefs' ) . '<br />';
580 $ps = $this->namespacesCheckboxes();
582 $enotifwatchlistpages = ($wgEnotifWatchlist) ?
$this->getToggle( 'enotifwatchlistpages', false, $disableEmailPrefs ) : '';
583 $enotifusertalkpages = ($wgEnotifUserTalk) ?
$this->getToggle( 'enotifusertalkpages', false, $disableEmailPrefs ) : '';
584 $enotifminoredits = ($wgEnotifWatchlist && $wgEnotifMinorEdits) ?
$this->getToggle( 'enotifminoredits', false, $disableEmailPrefs ) : '';
585 $enotifrevealaddr = (($wgEnotifWatchlist ||
$wgEnotifUserTalk) && $wgEnotifRevealEditorAddress) ?
$this->getToggle( 'enotifrevealaddr', false, $disableEmailPrefs ) : '';
589 $wgOut->addHTML( "<form action=\"$action\" method='post'>" );
590 $wgOut->addHTML( "<div id='preferences'>" );
595 Xml
::openElement( 'fieldset ' ) .
596 Xml
::element( 'legend', null, wfMsg('prefs-personal') ) .
597 Xml
::openElement( 'table' ) .
598 $this->tableRow( Xml
::element( 'h2', null, wfMsg( 'prefs-personal' ) ) )
601 $userInformationHtml =
602 $this->tableRow( wfMsgHtml( 'username' ), htmlspecialchars( $wgUser->getName() ) ) .
603 $this->tableRow( wfMsgHtml( 'uid' ), htmlspecialchars( $wgUser->getID() ) ) .
605 wfMsgHtml( 'prefs-edits' ),
606 $wgLang->formatNum( User
::edits( $wgUser->getId() ) )
609 if( wfRunHooks( 'PreferencesUserInformationPanel', array( $this, &$userInformationHtml ) ) ) {
610 $wgOut->addHtml( $userInformationHtml );
613 if ( $wgAllowRealName ) {
616 Xml
::label( wfMsg('yourrealname'), 'wpRealName' ),
617 Xml
::input( 'wpRealName', 25, $this->mRealName
, array( 'id' => 'wpRealName' ) ),
618 Xml
::tags('div', array( 'class' => 'prefsectiontip' ),
619 wfMsgExt( 'prefs-help-realname', 'parseinline' )
624 if ( $wgEnableEmail ) {
627 Xml
::label( wfMsg('youremail'), 'wpUserEmail' ),
628 Xml
::input( 'wpUserEmail', 25, $this->mUserEmail
, array( 'id' => 'wpUserEmail' ) ),
629 Xml
::tags('div', array( 'class' => 'prefsectiontip' ),
630 wfMsgExt( $wgEmailConfirmToEdit ?
'prefs-help-email-required' : 'prefs-help-email', 'parseinline' )
636 global $wgParser, $wgMaxSigChars;
637 if( mb_strlen( $this->mNick
) > $wgMaxSigChars ) {
638 $invalidSig = $this->tableRow(
640 Xml
::element( 'span', array( 'class' => 'error' ),
641 wfMsg( 'badsiglength', $wgLang->formatNum( $wgMaxSigChars ) ) )
643 } elseif( !empty( $this->mToggles
['fancysig'] ) &&
644 false === $wgParser->validateSig( $this->mNick
) ) {
645 $invalidSig = $this->tableRow(
647 Xml
::element( 'span', array( 'class' => 'error' ), wfMsg( 'badsig' ) )
655 Xml
::label( wfMsg( 'yournick' ), 'wpNick' ),
656 Xml
::input( 'wpNick', 25, $this->mNick
,
659 // Note: $wgMaxSigChars is enforced in Unicode characters,
660 // both on the backend and now in the browser.
661 // Badly-behaved requests may still try to submit
662 // an overlong string, however.
663 'maxlength' => $wgMaxSigChars ) )
666 $this->tableRow( ' ', $this->getToggle( 'fancysig' ) )
669 list( $lsLabel, $lsSelect) = Xml
::languageSelector( $this->mUserLanguage
);
671 $this->tableRow( $lsLabel, $lsSelect )
674 /* see if there are multiple language variants to choose from*/
675 if(!$wgDisableLangConversion) {
676 $variants = $wgContLang->getVariants();
677 $variantArray = array();
679 $languages = Language
::getLanguageNames( true );
680 foreach($variants as $v) {
681 $v = str_replace( '_', '-', strtolower($v));
682 if( array_key_exists( $v, $languages ) ) {
683 // If it doesn't have a name, we'll pretend it doesn't exist
684 $variantArray[$v] = $languages[$v];
689 foreach( $variantArray as $code => $name ) {
690 $selected = ($code == $this->mUserVariant
);
691 $options .= Xml
::option( "$code - $name", $code, $selected ) . "\n";
694 if(count($variantArray) > 1) {
697 Xml
::label( wfMsg( 'yourvariant' ), 'wpUserVariant' ),
699 array( 'name' => 'wpUserVariant', 'id' => 'wpUserVariant' ),
708 if( $wgAuth->allowPasswordChange() ) {
710 $this->tableRow( Xml
::element( 'h2', null, wfMsg( 'changepassword' ) ) ) .
712 Xml
::label( wfMsg( 'oldpassword' ), 'wpOldpass' ),
713 Xml
::password( 'wpOldpass', 25, $this->mOldpass
, array( 'id' => 'wpOldpass' ) )
716 Xml
::label( wfMsg( 'newpassword' ), 'wpNewpass' ),
717 Xml
::password( 'wpNewpass', 25, $this->mNewpass
, array( 'id' => 'wpNewpass' ) )
720 Xml
::label( wfMsg( 'retypenew' ), 'wpRetypePass' ),
721 Xml
::password( 'wpRetypePass', 25, $this->mRetypePass
, array( 'id' => 'wpRetypePass' ) )
723 Xml
::tags( 'tr', null,
724 Xml
::tags( 'td', array( 'colspan' => '2' ),
725 $this->getToggle( "rememberpassword" )
733 if ( $wgEnableEmail ) {
736 if ($wgEnableUserEmail) {
737 $emf = wfMsg( 'allowemail' );
738 $disabled = $disableEmailPrefs ?
' disabled="disabled"' : '';
740 "<input type='checkbox' $emfc $disabled value='1' name='wpEmailFlag' id='wpEmailFlag' /> <label for='wpEmailFlag'>$emf</label>";
745 $this->tableRow( Xml
::element( 'h2', null, wfMsg( 'email' ) ) ) .
749 $enotifwatchlistpages.
750 $enotifusertalkpages.
753 $this->getToggle( 'ccmeonemails' )
760 Xml
::closeElement( 'table' ) .
761 Xml
::closeElement( 'fieldset' )
767 if ($this->mSkin
== 'cologneblue' ||
$this->mSkin
== 'standard') {
768 $wgOut->addHtml( "<fieldset>\n<legend>" . wfMsg( 'qbsettings' ) . "</legend>\n" );
769 for ( $i = 0; $i < count( $qbs ); ++
$i ) {
770 if ( $i == $this->mQuickbar
) { $checked = ' checked="checked"'; }
771 else { $checked = ""; }
772 $wgOut->addHTML( "<div><label><input type='radio' name='wpQuickbar' value=\"$i\"$checked />{$qbs[$i]}</label></div>\n" );
774 $wgOut->addHtml( "</fieldset>\n\n" );
776 # Need to output a hidden option even if the relevant skin is not in use,
777 # otherwise the preference will get reset to 0 on submit
778 $wgOut->addHtml( wfHidden( 'wpQuickbar', $this->mQuickbar
) );
783 $wgOut->addHTML( "<fieldset>\n<legend>\n" . wfMsg('skin') . "</legend>\n" );
784 $mptitle = Title
::newMainPage();
785 $previewtext = wfMsg('skinpreview');
786 # Only show members of Skin::getSkinNames() rather than
787 # $skinNames (skins is all skin names from Language.php)
788 $validSkinNames = Skin
::getSkinNames();
789 # Sort by UI skin name. First though need to update validSkinNames as sometimes
790 # the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI).
791 foreach ($validSkinNames as $skinkey => & $skinname ) {
792 if ( isset( $skinNames[$skinkey] ) ) {
793 $skinname = $skinNames[$skinkey];
796 asort($validSkinNames);
797 foreach ($validSkinNames as $skinkey => $sn ) {
798 if ( in_array( $skinkey, $wgSkipSkins ) ) {
801 $checked = $skinkey == $this->mSkin ?
' checked="checked"' : '';
803 $mplink = htmlspecialchars($mptitle->getLocalURL("useskin=$skinkey"));
804 $previewlink = "<a target='_blank' href=\"$mplink\">$previewtext</a>";
805 if( $skinkey == $wgDefaultSkin )
806 $sn .= ' (' . wfMsg( 'default' ) . ')';
807 $wgOut->addHTML( "<input type='radio' name='wpSkin' id=\"wpSkin$skinkey\" value=\"$skinkey\"$checked /> <label for=\"wpSkin$skinkey\">{$sn}</label> $previewlink<br />\n" );
809 $wgOut->addHTML( "</fieldset>\n\n" );
815 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg('math') . '</legend>' );
816 foreach ( $mathopts as $k => $v ) {
817 $checked = ($k == $this->mMath
);
819 Xml
::openElement( 'div' ) .
820 Xml
::radioLabel( wfMsg( $v ), 'wpMath', $k, "mw-sp-math-$k", $checked ) .
821 Xml
::closeElement( 'div' ) . "\n"
824 $wgOut->addHTML( "</fieldset>\n\n" );
830 "<fieldset>\n" . Xml
::element( 'legend', null, wfMsg( 'files' ) ) . "\n"
833 $imageLimitOptions = null;
834 foreach ( $wgImageLimits as $index => $limits ) {
835 $selected = ($index == $this->mImageSize
);
836 $imageLimitOptions .= Xml
::option( "{$limits[0]}ร{$limits[1]}" .
837 wfMsg('unit-pixel'), $index, $selected );
840 $imageSizeId = 'wpImageSize';
842 "<div>" . Xml
::label( wfMsg('imagemaxsize'), $imageSizeId ) . " " .
843 Xml
::openElement( 'select', array( 'name' => $imageSizeId, 'id' => $imageSizeId ) ) .
845 Xml
::closeElement( 'select' ) . "</div>\n"
848 $imageThumbOptions = null;
849 foreach ( $wgThumbLimits as $index => $size ) {
850 $selected = ($index == $this->mThumbSize
);
851 $imageThumbOptions .= Xml
::option($size . wfMsg('unit-pixel'), $index,
855 $thumbSizeId = 'wpThumbSize';
857 "<div>" . Xml
::label( wfMsg('thumbsize'), $thumbSizeId ) . " " .
858 Xml
::openElement( 'select', array( 'name' => $thumbSizeId, 'id' => $thumbSizeId ) ) .
860 Xml
::closeElement( 'select' ) . "</div>\n"
863 $wgOut->addHTML( "</fieldset>\n\n" );
870 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'datetime' ) . "</legend>\n" );
873 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'dateformat' ) . "</legend>\n" );
875 $epoch = '20010115161234'; # Wikipedia day
876 foreach( $dateopts as $key ) {
877 if( $key == 'default' ) {
878 $formatted = wfMsgHtml( 'datedefault' );
880 $formatted = htmlspecialchars( $wgLang->timeanddate( $epoch, false, $key ) );
882 ($key == $this->mDate
) ?
$checked = ' checked="checked"' : $checked = '';
883 $wgOut->addHTML( "<div><input type='radio' name=\"wpDate\" id=\"wpDate$idCnt\" ".
884 "value=\"$key\"$checked /> <label for=\"wpDate$idCnt\">$formatted</label></div>\n" );
887 $wgOut->addHTML( "</fieldset>\n" );
890 $nowlocal = $wgLang->time( $now = wfTimestampNow(), true );
891 $nowserver = $wgLang->time( $now, false );
893 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'timezonelegend' ). '</legend><table>' .
894 $this->addRow( wfMsg( 'servertime' ), $nowserver ) .
895 $this->addRow( wfMsg( 'localtime' ), $nowlocal ) .
897 '<label for="wpHourDiff">' . wfMsg( 'timezoneoffset' ) . '</label>',
898 "<input type='text' name='wpHourDiff' id='wpHourDiff' value=\"" . htmlspecialchars( $this->mHourDiff
) . "\" size='6' />"
899 ) . "<tr><td colspan='2'>
900 <input type='button' value=\"" . wfMsg( 'guesstimezone' ) ."\"
901 onclick='javascript:guessTimezone()' id='guesstimezonebutton' style='display:none;' />
902 </td></tr></table><div class='prefsectiontip'>ยน" . wfMsg( 'timezonetext' ) . "</div></fieldset>
907 global $wgLivePreview;
908 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'textboxsize' ) . '</legend>
910 wfInputLabel( wfMsg( 'rows' ), 'wpRows', 'wpRows', 3, $this->mRows
) .
912 wfInputLabel( wfMsg( 'columns' ), 'wpCols', 'wpCols', 3, $this->mCols
) .
914 $this->getToggles( array(
916 'editsectiononrightclick',
925 $wgLivePreview ?
'uselivepreview' : false,
931 $wgOut->addHtml( '<fieldset><legend>' . wfMsgHtml( 'prefs-rc' ) . '</legend>' );
934 $rc .= '<td>' . Xml
::label( wfMsg( 'recentchangesdays' ), 'wpRecentDays' ) . '</td>';
935 $rc .= '<td>' . Xml
::input( 'wpRecentDays', 3, $this->mRecentDays
, array( 'id' => 'wpRecentDays' ) ) . '</td>';
937 $rc .= '<td>' . Xml
::label( wfMsg( 'recentchangescount' ), 'wpRecent' ) . '</td>';
938 $rc .= '<td>' . Xml
::input( 'wpRecent', 3, $this->mRecent
, array( 'id' => 'wpRecent' ) ) . '</td>';
939 $rc .= '</tr></table>';
940 $wgOut->addHtml( $rc );
942 $wgOut->addHtml( '<br />' );
944 $toggles[] = 'hideminor';
945 if( $wgRCShowWatchingUsers )
946 $toggles[] = 'shownumberswatching';
947 $toggles[] = 'usenewrc';
948 $wgOut->addHtml( $this->getToggles( $toggles ) );
950 $wgOut->addHtml( '</fieldset>' );
953 $wgOut->addHtml( '<fieldset><legend>' . wfMsgHtml( 'prefs-watchlist' ) . '</legend>' );
955 $wgOut->addHtml( wfInputLabel( wfMsg( 'prefs-watchlist-days' ), 'wpWatchlistDays', 'wpWatchlistDays', 3, $this->mWatchlistDays
) );
956 $wgOut->addHtml( '<br /><br />' );
958 $wgOut->addHtml( $this->getToggle( 'extendwatchlist' ) );
959 $wgOut->addHtml( wfInputLabel( wfMsg( 'prefs-watchlist-edits' ), 'wpWatchlistEdits', 'wpWatchlistEdits', 3, $this->mWatchlistEdits
) );
960 $wgOut->addHtml( '<br /><br />' );
962 $wgOut->addHtml( $this->getToggles( array( 'watchlisthideown', 'watchlisthidebots', 'watchlisthideminor' ) ) );
964 if( $wgUser->isAllowed( 'createpage' ) ||
$wgUser->isAllowed( 'createtalk' ) )
965 $wgOut->addHtml( $this->getToggle( 'watchcreations' ) );
966 foreach( array( 'edit' => 'watchdefault', 'move' => 'watchmoves', 'delete' => 'watchdeletion' ) as $action => $toggle ) {
967 if( $wgUser->isAllowed( $action ) )
968 $wgOut->addHtml( $this->getToggle( $toggle ) );
970 $this->mUsedToggles
['watchcreations'] = true;
971 $this->mUsedToggles
['watchdefault'] = true;
972 $this->mUsedToggles
['watchmoves'] = true;
973 $this->mUsedToggles
['watchdeletion'] = true;
975 $wgOut->addHtml( '</fieldset>' );
978 $ajaxsearch = $wgAjaxSearch ?
980 wfLabel( wfMsg( 'useajaxsearch' ), 'wpUseAjaxSearch' ),
981 wfCheck( 'wpUseAjaxSearch', $this->mUseAjaxSearch
, array( 'id' => 'wpUseAjaxSearch' ) )
983 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'searchresultshead' ) . '</legend><table>' .
986 wfLabel( wfMsg( 'resultsperpage' ), 'wpSearch' ),
987 wfInput( 'wpSearch', 4, $this->mSearch
, array( 'id' => 'wpSearch' ) )
990 wfLabel( wfMsg( 'contextlines' ), 'wpSearchLines' ),
991 wfInput( 'wpSearchLines', 4, $this->mSearchLines
, array( 'id' => 'wpSearchLines' ) )
994 wfLabel( wfMsg( 'contextchars' ), 'wpSearchChars' ),
995 wfInput( 'wpSearchChars', 4, $this->mSearchChars
, array( 'id' => 'wpSearchChars' ) )
997 "</table><fieldset><legend>" . wfMsg( 'defaultns' ) . "</legend>$ps</fieldset></fieldset>" );
1001 $wgOut->addHTML('<fieldset><legend>' . wfMsg('prefs-misc') . '</legend>');
1002 $wgOut->addHtml( '<label for="wpStubs">' . wfMsg( 'stub-threshold' ) . '</label> ' );
1003 $wgOut->addHtml( Xml
::input( 'wpStubs', 6, $this->mStubs
, array( 'id' => 'wpStubs' ) ) );
1004 $msgUnderline = htmlspecialchars( wfMsg ( 'tog-underline' ) );
1005 $msgUnderlinenever = htmlspecialchars( wfMsg ( 'underline-never' ) );
1006 $msgUnderlinealways = htmlspecialchars( wfMsg ( 'underline-always' ) );
1007 $msgUnderlinedefault = htmlspecialchars( wfMsg ( 'underline-default' ) );
1008 $uopt = $wgUser->getOption("underline");
1009 $s0 = $uopt == 0 ?
' selected="selected"' : '';
1010 $s1 = $uopt == 1 ?
' selected="selected"' : '';
1011 $s2 = $uopt == 2 ?
' selected="selected"' : '';
1013 <div class='toggle'><p><label for='wpOpunderline'>$msgUnderline</label>
1014 <select name='wpOpunderline' id='wpOpunderline'>
1015 <option value=\"0\"$s0>$msgUnderlinenever</option>
1016 <option value=\"1\"$s1>$msgUnderlinealways</option>
1017 <option value=\"2\"$s2>$msgUnderlinedefault</option>
1018 </select></p></div>");
1020 foreach ( $togs as $tname ) {
1021 if( !array_key_exists( $tname, $this->mUsedToggles
) ) {
1022 $wgOut->addHTML( $this->getToggle( $tname ) );
1025 $wgOut->addHTML( '</fieldset>' );
1027 wfRunHooks( 'RenderPreferencesForm', array( $this, $wgOut ) );
1029 $token = htmlspecialchars( $wgUser->editToken() );
1030 $skin = $wgUser->getSkin();
1032 <div id='prefsubmit'>
1034 <input type='submit' name='wpSaveprefs' class='btnSavePrefs' value=\"" . wfMsgHtml( 'saveprefs' ) . '"'.$skin->tooltipAndAccesskey('save')." />
1035 <input type='submit' name='wpReset' value=\"" . wfMsgHtml( 'resetprefs' ) . "\" />
1040 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1043 $wgOut->addHtml( Xml
::tags( 'div', array( 'class' => "prefcache" ),
1044 wfMsgExt( 'clearyourcache', 'parseinline' ) )