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, $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' );
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;
107 if ( $wgUser->isAnon() ) {
108 $wgOut->showErrorPage( 'prefsnologin', 'prefsnologintext' );
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 '00:00' if fed bogus data.
175 * Note: It's not a 100% correct implementation timezone-wise, it will
176 * accept stuff like '14:30',
178 * @param string $s the user input
181 function validateTimeZone( $s ) {
183 if ( strpos( $s, ':' ) ) {
185 $array = explode( ':' , $s );
186 $hour = intval( $array[0] );
187 $minute = intval( $array[1] );
189 $minute = intval( $s * 60 );
190 $hour = intval( $minute / 60 );
191 $minute = abs( $minute ) %
60;
193 # Max is +14:00 and min is -12:00, see:
194 # http://en.wikipedia.org/wiki/Timezone
195 $hour = min( $hour, 14 );
196 $hour = max( $hour, -12 );
197 $minute = min( $minute, 59 );
198 $minute = max( $minute, 0 );
199 $s = sprintf( "%02d:%02d", $hour, $minute );
207 function savePreferences() {
208 global $wgUser, $wgOut, $wgParser;
209 global $wgEnableUserEmail, $wgEnableEmail;
210 global $wgEmailAuthentication, $wgRCMaxAge;
211 global $wgAuth, $wgEmailConfirmToEdit;
214 if ( '' != $this->mNewpass
&& $wgAuth->allowPasswordChange() ) {
215 if ( $this->mNewpass
!= $this->mRetypePass
) {
216 wfRunHooks( 'PrefsPasswordAudit', array( $wgUser, $this->mNewpass
, 'badretype' ) );
217 $this->mainPrefsForm( 'error', wfMsg( 'badretype' ) );
221 if (!$wgUser->checkPassword( $this->mOldpass
)) {
222 wfRunHooks( 'PrefsPasswordAudit', array( $wgUser, $this->mNewpass
, 'wrongpassword' ) );
223 $this->mainPrefsForm( 'error', wfMsg( 'wrongpassword' ) );
228 $wgUser->setPassword( $this->mNewpass
);
229 wfRunHooks( 'PrefsPasswordAudit', array( $wgUser, $this->mNewpass
, 'success' ) );
230 $this->mNewpass
= $this->mOldpass
= $this->mRetypePass
= '';
231 } catch( PasswordError
$e ) {
232 wfRunHooks( 'PrefsPasswordAudit', array( $wgUser, $this->mNewpass
, 'error' ) );
233 $this->mainPrefsForm( 'error', $e->getMessage() );
237 $wgUser->setRealName( $this->mRealName
);
239 if( $wgUser->getOption( 'language' ) !== $this->mUserLanguage
) {
240 $needRedirect = true;
242 $needRedirect = false;
245 # Validate the signature and clean it up as needed
246 global $wgMaxSigChars;
247 if( mb_strlen( $this->mNick
) > $wgMaxSigChars ) {
249 $this->mainPrefsForm( 'error',
250 wfMsg( 'badsiglength', $wgLang->formatNum( $wgMaxSigChars ) ) );
252 } elseif( $this->mToggles
['fancysig'] ) {
253 if( $wgParser->validateSig( $this->mNick
) !== false ) {
254 $this->mNick
= $wgParser->cleanSig( $this->mNick
);
256 $this->mainPrefsForm( 'error', wfMsg( 'badsig' ) );
260 // When no fancy sig used, make sure ~{3,5} get removed.
261 $this->mNick
= $wgParser->cleanSigInSig( $this->mNick
);
264 $wgUser->setOption( 'language', $this->mUserLanguage
);
265 $wgUser->setOption( 'variant', $this->mUserVariant
);
266 $wgUser->setOption( 'nickname', $this->mNick
);
267 $wgUser->setOption( 'quickbar', $this->mQuickbar
);
268 $wgUser->setOption( 'skin', $this->mSkin
);
271 $wgUser->setOption( 'math', $this->mMath
);
273 $wgUser->setOption( 'date', $this->validateDate( $this->mDate
) );
274 $wgUser->setOption( 'searchlimit', $this->validateIntOrNull( $this->mSearch
) );
275 $wgUser->setOption( 'contextlines', $this->validateIntOrNull( $this->mSearchLines
) );
276 $wgUser->setOption( 'contextchars', $this->validateIntOrNull( $this->mSearchChars
) );
277 $wgUser->setOption( 'rclimit', $this->validateIntOrNull( $this->mRecent
) );
278 $wgUser->setOption( 'rcdays', $this->validateInt($this->mRecentDays
, 1, ceil($wgRCMaxAge / (3600*24))));
279 $wgUser->setOption( 'wllimit', $this->validateIntOrNull( $this->mWatchlistEdits
, 0, 1000 ) );
280 $wgUser->setOption( 'rows', $this->validateInt( $this->mRows
, 4, 1000 ) );
281 $wgUser->setOption( 'cols', $this->validateInt( $this->mCols
, 4, 1000 ) );
282 $wgUser->setOption( 'stubthreshold', $this->validateIntOrNull( $this->mStubs
) );
283 $wgUser->setOption( 'timecorrection', $this->validateTimeZone( $this->mHourDiff
, -12, 14 ) );
284 $wgUser->setOption( 'imagesize', $this->mImageSize
);
285 $wgUser->setOption( 'thumbsize', $this->mThumbSize
);
286 $wgUser->setOption( 'underline', $this->validateInt($this->mUnderline
, 0, 2) );
287 $wgUser->setOption( 'watchlistdays', $this->validateFloat( $this->mWatchlistDays
, 0, 7 ) );
289 # Set search namespace options
290 foreach( $this->mSearchNs
as $i => $value ) {
291 $wgUser->setOption( "searchNs{$i}", $value );
294 if( $wgEnableEmail && $wgEnableUserEmail ) {
295 $wgUser->setOption( 'disablemail', $this->mEmailFlag
);
299 foreach ( $this->mToggles
as $tname => $tvalue ) {
300 $wgUser->setOption( $tname, $tvalue );
304 if( $wgEnableEmail ) {
305 $newadr = $this->mUserEmail
;
306 $oldadr = $wgUser->getEmail();
307 if( ($newadr != '') && ($newadr != $oldadr) ) {
308 # the user has supplied a new email address on the login page
309 if( $wgUser->isValidEmailAddr( $newadr ) ) {
310 $wgUser->mEmail
= $newadr; # new behaviour: set this new emailaddr from login-page into user database record
311 $wgUser->mEmailAuthenticated
= null; # but flag as "dirty" = unauthenticated
312 if ($wgEmailAuthentication) {
313 # Mail a temporary password to the dirty address.
314 # User can come back through the confirmation URL to re-enable email.
315 $result = $wgUser->sendConfirmationMail();
316 if( WikiError
::isError( $result ) ) {
317 $error = wfMsg( 'mailerror', htmlspecialchars( $result->getMessage() ) );
319 $error = wfMsg( 'eauthentsent', $wgUser->getName() );
323 $error = wfMsg( 'invalidemailaddress' );
326 if( $wgEmailConfirmToEdit && empty( $newadr ) ) {
327 $this->mainPrefsForm( 'error', wfMsg( 'noemailtitle' ) );
330 $wgUser->setEmail( $this->mUserEmail
);
332 if( $oldadr != $newadr ) {
333 wfRunHooks( 'PrefsEmailAudit', array( $wgUser, $oldadr, $newadr ) );
337 if (!$wgAuth->updateExternalDB($wgUser)) {
338 $this->mainPrefsForm( 'error', wfMsg( 'externaldberror' ) );
343 if ( !wfRunHooks( 'SavePreferences', array( $this, $wgUser, &$msg ) ) ) {
345 $this->mainPrefsForm( 'error', $msg );
349 $wgUser->setCookies();
350 $wgUser->saveSettings();
352 if( $needRedirect && $error === false ) {
353 $title = SpecialPage
::getTitleFor( 'Preferences' );
354 $wgOut->redirect($title->getFullURL('success'));
358 $wgOut->setParserOptions( ParserOptions
::newFromUser( $wgUser ) );
359 $this->mainPrefsForm( $error === false ?
'success' : 'error', $error);
365 function resetPrefs() {
366 global $wgUser, $wgLang, $wgContLang, $wgContLanguageCode, $wgAllowRealName;
368 $this->mOldpass
= $this->mNewpass
= $this->mRetypePass
= '';
369 $this->mUserEmail
= $wgUser->getEmail();
370 $this->mUserEmailAuthenticationtimestamp
= $wgUser->getEmailAuthenticationtimestamp();
371 $this->mRealName
= ($wgAllowRealName) ?
$wgUser->getRealName() : '';
373 # language value might be blank, default to content language
374 $this->mUserLanguage
= $wgUser->getOption( 'language', $wgContLanguageCode );
376 $this->mUserVariant
= $wgUser->getOption( 'variant');
377 $this->mEmailFlag
= $wgUser->getOption( 'disablemail' ) == 1 ?
1 : 0;
378 $this->mNick
= $wgUser->getOption( 'nickname' );
380 $this->mQuickbar
= $wgUser->getOption( 'quickbar' );
381 $this->mSkin
= Skin
::normalizeKey( $wgUser->getOption( 'skin' ) );
382 $this->mMath
= $wgUser->getOption( 'math' );
383 $this->mDate
= $wgUser->getDatePreference();
384 $this->mRows
= $wgUser->getOption( 'rows' );
385 $this->mCols
= $wgUser->getOption( 'cols' );
386 $this->mStubs
= $wgUser->getOption( 'stubthreshold' );
387 $this->mHourDiff
= $wgUser->getOption( 'timecorrection' );
388 $this->mSearch
= $wgUser->getOption( 'searchlimit' );
389 $this->mSearchLines
= $wgUser->getOption( 'contextlines' );
390 $this->mSearchChars
= $wgUser->getOption( 'contextchars' );
391 $this->mImageSize
= $wgUser->getOption( 'imagesize' );
392 $this->mThumbSize
= $wgUser->getOption( 'thumbsize' );
393 $this->mRecent
= $wgUser->getOption( 'rclimit' );
394 $this->mRecentDays
= $wgUser->getOption( 'rcdays' );
395 $this->mWatchlistEdits
= $wgUser->getOption( 'wllimit' );
396 $this->mUnderline
= $wgUser->getOption( 'underline' );
397 $this->mWatchlistDays
= $wgUser->getOption( 'watchlistdays' );
399 $togs = User
::getToggles();
400 foreach ( $togs as $tname ) {
401 $this->mToggles
[$tname] = $wgUser->getOption( $tname );
404 $namespaces = $wgContLang->getNamespaces();
405 foreach ( $namespaces as $i => $namespace ) {
406 if ( $i >= NS_MAIN
) {
407 $this->mSearchNs
[$i] = $wgUser->getOption( 'searchNs'.$i );
411 wfRunHooks( 'ResetPreferences', array( $this, $wgUser ) );
417 function namespacesCheckboxes() {
420 # Determine namespace checkboxes
421 $namespaces = $wgContLang->getNamespaces();
424 foreach ( $namespaces as $i => $name ) {
427 $checked = $this->mSearchNs
[$i] ?
"checked='checked'" : '';
428 $name = str_replace( '_', ' ', $namespaces[$i] );
431 $name = wfMsg( 'blanknamespace' );
433 $r1 .= "<input type='checkbox' value='1' name='wpNs$i' id='wpNs$i' {$checked}/> <label for='wpNs$i'>{$name}</label><br />\n";
439 function getToggle( $tname, $trailer = false, $disabled = false ) {
440 global $wgUser, $wgLang;
442 $this->mUsedToggles
[$tname] = true;
443 $ttext = $wgLang->getUserToggle( $tname );
445 $checked = $wgUser->getOption( $tname ) == 1 ?
' checked="checked"' : '';
446 $disabled = $disabled ?
' disabled="disabled"' : '';
447 $trailer = $trailer ?
$trailer : '';
448 return "<div class='toggle'><input type='checkbox' value='1' id=\"$tname\" name=\"wpOp$tname\"$checked$disabled />" .
449 " <span class='toggletext'><label for=\"$tname\">$ttext</label>$trailer</span></div>\n";
452 function getToggles( $items ) {
454 foreach( $items as $item ) {
455 if( $item === false )
457 if( is_array( $item ) ) {
458 list( $key, $trailer ) = $item;
463 $out .= $this->getToggle( $key, $trailer );
468 function addRow($td1, $td2) {
469 return "<tr><td align='right'>$td1</td><td align='left'>$td2</td></tr>";
473 * Helper function for user information panel
474 * @param $td1 label for an item
475 * @param $td2 item or null
476 * @param $td3 optional help or null
477 * @return xhtml block
479 function tableRow( $td1, $td2 = null, $td3 = null ) {
482 $align['align'] = $wgContLang->isRtl() ?
'right' : 'left';
484 if ( is_null( $td3 ) ) {
487 $td3 = Xml
::tags( 'tr', null,
488 Xml
::tags( 'td', array( 'colspan' => '2' ), $td3 )
492 if ( is_null( $td2 ) ) {
493 $td1 = Xml
::tags( 'td', $align +
array( 'colspan' => '2' ), $td1 );
496 $td1 = Xml
::tags( 'td', $align, $td1 );
497 $td2 = Xml
::tags( 'td', $align, $td2 );
500 return Xml
::tags( 'tr', null, $td1 . $td2 ). $td3 . "\n";
507 function mainPrefsForm( $status , $message = '' ) {
508 global $wgUser, $wgOut, $wgLang, $wgContLang;
509 global $wgAllowRealName, $wgImageLimits, $wgThumbLimits;
510 global $wgDisableLangConversion;
511 global $wgEnotifWatchlist, $wgEnotifUserTalk,$wgEnotifMinorEdits;
512 global $wgRCShowWatchingUsers, $wgEnotifRevealEditorAddress;
513 global $wgEnableEmail, $wgEnableUserEmail, $wgEmailAuthentication;
514 global $wgContLanguageCode, $wgDefaultSkin, $wgSkipSkins, $wgAuth;
515 global $wgEmailConfirmToEdit;
517 $wgOut->setPageTitle( wfMsg( 'preferences' ) );
518 $wgOut->setArticleRelated( false );
519 $wgOut->setRobotpolicy( 'noindex,nofollow' );
521 $wgOut->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc.
523 if ( $this->mSuccess ||
'success' == $status ) {
524 $wgOut->addWikitext( '<div class="successbox"><strong>'. wfMsg( 'savedprefs' ) . '</strong></div>' );
525 } else if ( 'error' == $status ) {
526 $wgOut->addWikitext( '<div class="errorbox"><strong>' . $message . '</strong></div>' );
527 } else if ( '' != $status ) {
528 $wgOut->addWikitext( $message . "\n----" );
531 $qbs = $wgLang->getQuickbarSettings();
532 $skinNames = $wgLang->getSkinNames();
533 $mathopts = $wgLang->getMathNames();
534 $dateopts = $wgLang->getDatePreferences();
535 $togs = User
::getToggles();
537 $titleObj = SpecialPage
::getTitleFor( 'Preferences' );
538 $action = $titleObj->escapeLocalURL();
540 # Pre-expire some toggles so they won't show if disabled
541 $this->mUsedToggles
[ 'shownumberswatching' ] = true;
542 $this->mUsedToggles
[ 'showupdated' ] = true;
543 $this->mUsedToggles
[ 'enotifwatchlistpages' ] = true;
544 $this->mUsedToggles
[ 'enotifusertalkpages' ] = true;
545 $this->mUsedToggles
[ 'enotifminoredits' ] = true;
546 $this->mUsedToggles
[ 'enotifrevealaddr' ] = true;
547 $this->mUsedToggles
[ 'ccmeonemails' ] = true;
548 $this->mUsedToggles
[ 'uselivepreview' ] = true;
551 if ( !$this->mEmailFlag
) { $emfc = 'checked="checked"'; }
555 if ($wgEmailAuthentication && ($this->mUserEmail
!= '') ) {
556 if( $wgUser->getEmailAuthenticationTimestamp() ) {
557 $emailauthenticated = wfMsg('emailauthenticated',$wgLang->timeanddate($wgUser->getEmailAuthenticationTimestamp(), true ) ).'<br />';
558 $disableEmailPrefs = false;
560 $disableEmailPrefs = true;
561 $skin = $wgUser->getSkin();
562 $emailauthenticated = wfMsg('emailnotauthenticated').'<br />' .
563 $skin->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Confirmemail' ),
564 wfMsg( 'emailconfirmlink' ) ) . '<br />';
567 $emailauthenticated = '';
568 $disableEmailPrefs = false;
571 if ($this->mUserEmail
== '') {
572 $emailauthenticated = wfMsg( 'noemailprefs' ) . '<br />';
575 $ps = $this->namespacesCheckboxes();
577 $enotifwatchlistpages = ($wgEnotifWatchlist) ?
$this->getToggle( 'enotifwatchlistpages', false, $disableEmailPrefs ) : '';
578 $enotifusertalkpages = ($wgEnotifUserTalk) ?
$this->getToggle( 'enotifusertalkpages', false, $disableEmailPrefs ) : '';
579 $enotifminoredits = ($wgEnotifWatchlist && $wgEnotifMinorEdits) ?
$this->getToggle( 'enotifminoredits', false, $disableEmailPrefs ) : '';
580 $enotifrevealaddr = (($wgEnotifWatchlist ||
$wgEnotifUserTalk) && $wgEnotifRevealEditorAddress) ?
$this->getToggle( 'enotifrevealaddr', false, $disableEmailPrefs ) : '';
584 $wgOut->addHTML( "<form action=\"$action\" method='post'>" );
585 $wgOut->addHTML( "<div id='preferences'>" );
590 Xml
::openElement( 'fieldset ' ) .
591 Xml
::element( 'legend', null, wfMsg('prefs-personal') ) .
592 Xml
::openElement( 'table' ) .
593 $this->tableRow( Xml
::element( 'h2', null, wfMsg( 'prefs-personal' ) ) )
596 $userInformationHtml =
597 $this->tableRow( wfMsgHtml( 'username' ), htmlspecialchars( $wgUser->getName() ) ) .
598 $this->tableRow( wfMsgHtml( 'uid' ), htmlspecialchars( $wgUser->getID() ) ) .
600 wfMsgHtml( 'prefs-edits' ),
601 $wgLang->formatNum( User
::edits( $wgUser->getId() ) )
604 if( wfRunHooks( 'PreferencesUserInformationPanel', array( $this, &$userInformationHtml ) ) ) {
605 $wgOut->addHtml( $userInformationHtml );
608 if ( $wgAllowRealName ) {
611 Xml
::label( wfMsg('yourrealname'), 'wpRealName' ),
612 Xml
::input( 'wpRealName', 25, $this->mRealName
, array( 'id' => 'wpRealName' ) ),
613 Xml
::tags('div', array( 'class' => 'prefsectiontip' ),
614 wfMsgExt( 'prefs-help-realname', 'parseinline' )
619 if ( $wgEnableEmail ) {
622 Xml
::label( wfMsg('youremail'), 'wpUserEmail' ),
623 Xml
::input( 'wpUserEmail', 25, $this->mUserEmail
, array( 'id' => 'wpUserEmail' ) ),
624 Xml
::tags('div', array( 'class' => 'prefsectiontip' ),
625 wfMsgExt( $wgEmailConfirmToEdit ?
'prefs-help-email-required' : 'prefs-help-email', 'parseinline' )
631 global $wgParser, $wgMaxSigChars;
632 if( mb_strlen( $this->mNick
) > $wgMaxSigChars ) {
633 $invalidSig = $this->tableRow(
635 Xml
::element( 'span', array( 'class' => 'error' ),
636 wfMsg( 'badsiglength', $wgLang->formatNum( $wgMaxSigChars ) ) )
638 } elseif( !empty( $this->mToggles
['fancysig'] ) &&
639 false === $wgParser->validateSig( $this->mNick
) ) {
640 $invalidSig = $this->tableRow(
642 Xml
::element( 'span', array( 'class' => 'error' ), wfMsg( 'badsig' ) )
650 Xml
::label( wfMsg( 'yournick' ), 'wpNick' ),
651 Xml
::input( 'wpNick', 25, $this->mNick
,
654 // Note: $wgMaxSigChars is enforced in Unicode characters,
655 // both on the backend and now in the browser.
656 // Badly-behaved requests may still try to submit
657 // an overlong string, however.
658 'maxlength' => $wgMaxSigChars ) )
661 $this->tableRow( ' ', $this->getToggle( 'fancysig' ) )
664 list( $lsLabel, $lsSelect) = Xml
::languageSelector( $this->mUserLanguage
);
666 $this->tableRow( $lsLabel, $lsSelect )
669 /* see if there are multiple language variants to choose from*/
670 if(!$wgDisableLangConversion) {
671 $variants = $wgContLang->getVariants();
672 $variantArray = array();
674 $languages = Language
::getLanguageNames( true );
675 foreach($variants as $v) {
676 $v = str_replace( '_', '-', strtolower($v));
677 if( array_key_exists( $v, $languages ) ) {
678 // If it doesn't have a name, we'll pretend it doesn't exist
679 $variantArray[$v] = $languages[$v];
684 foreach( $variantArray as $code => $name ) {
685 $selected = ($code == $this->mUserVariant
);
686 $options .= Xml
::option( "$code - $name", $code, $selected ) . "\n";
689 if(count($variantArray) > 1) {
692 Xml
::label( wfMsg( 'yourvariant' ), 'wpUserVariant' ),
694 array( 'name' => 'wpUserVariant', 'id' => 'wpUserVariant' ),
703 if( $wgAuth->allowPasswordChange() ) {
705 $this->tableRow( Xml
::element( 'h2', null, wfMsg( 'changepassword' ) ) ) .
707 Xml
::label( wfMsg( 'oldpassword' ), 'wpOldpass' ),
708 Xml
::password( 'wpOldpass', 25, $this->mOldpass
, array( 'id' => 'wpOldpass' ) )
711 Xml
::label( wfMsg( 'newpassword' ), 'wpNewpass' ),
712 Xml
::password( 'wpNewpass', 25, $this->mNewpass
, array( 'id' => 'wpNewpass' ) )
715 Xml
::label( wfMsg( 'retypenew' ), 'wpRetypePass' ),
716 Xml
::password( 'wpRetypePass', 25, $this->mRetypePass
, array( 'id' => 'wpRetypePass' ) )
718 Xml
::tags( 'tr', null,
719 Xml
::tags( 'td', array( 'colspan' => '2' ),
720 $this->getToggle( "rememberpassword" )
728 if ( $wgEnableEmail ) {
731 if ($wgEnableUserEmail) {
732 $emf = wfMsg( 'allowemail' );
733 $disabled = $disableEmailPrefs ?
' disabled="disabled"' : '';
735 "<input type='checkbox' $emfc $disabled value='1' name='wpEmailFlag' id='wpEmailFlag' /> <label for='wpEmailFlag'>$emf</label>";
740 $this->tableRow( Xml
::element( 'h2', null, wfMsg( 'email' ) ) ) .
744 $enotifwatchlistpages.
745 $enotifusertalkpages.
748 $this->getToggle( 'ccmeonemails' )
755 Xml
::closeElement( 'table' ) .
756 Xml
::closeElement( 'fieldset' )
762 if ($this->mSkin
== 'cologneblue' ||
$this->mSkin
== 'standard') {
763 $wgOut->addHtml( "<fieldset>\n<legend>" . wfMsg( 'qbsettings' ) . "</legend>\n" );
764 for ( $i = 0; $i < count( $qbs ); ++
$i ) {
765 if ( $i == $this->mQuickbar
) { $checked = ' checked="checked"'; }
766 else { $checked = ""; }
767 $wgOut->addHTML( "<div><label><input type='radio' name='wpQuickbar' value=\"$i\"$checked />{$qbs[$i]}</label></div>\n" );
769 $wgOut->addHtml( "</fieldset>\n\n" );
771 # Need to output a hidden option even if the relevant skin is not in use,
772 # otherwise the preference will get reset to 0 on submit
773 $wgOut->addHtml( wfHidden( 'wpQuickbar', $this->mQuickbar
) );
778 $wgOut->addHTML( "<fieldset>\n<legend>\n" . wfMsg('skin') . "</legend>\n" );
779 $mptitle = Title
::newMainPage();
780 $previewtext = wfMsg('skinpreview');
781 # Only show members of Skin::getSkinNames() rather than
782 # $skinNames (skins is all skin names from Language.php)
783 $validSkinNames = Skin
::getSkinNames();
784 # Sort by UI skin name. First though need to update validSkinNames as sometimes
785 # the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI).
786 foreach ($validSkinNames as $skinkey => & $skinname ) {
787 if ( isset( $skinNames[$skinkey] ) ) {
788 $skinname = $skinNames[$skinkey];
791 asort($validSkinNames);
792 foreach ($validSkinNames as $skinkey => $sn ) {
793 if ( in_array( $skinkey, $wgSkipSkins ) ) {
796 $checked = $skinkey == $this->mSkin ?
' checked="checked"' : '';
798 $mplink = htmlspecialchars($mptitle->getLocalURL("useskin=$skinkey"));
799 $previewlink = "<a target='_blank' href=\"$mplink\">$previewtext</a>";
800 if( $skinkey == $wgDefaultSkin )
801 $sn .= ' (' . wfMsg( 'default' ) . ')';
802 $wgOut->addHTML( "<input type='radio' name='wpSkin' id=\"wpSkin$skinkey\" value=\"$skinkey\"$checked /> <label for=\"wpSkin$skinkey\">{$sn}</label> $previewlink<br />\n" );
804 $wgOut->addHTML( "</fieldset>\n\n" );
810 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg('math') . '</legend>' );
811 foreach ( $mathopts as $k => $v ) {
812 $checked = ($k == $this->mMath
);
814 Xml
::openElement( 'div' ) .
815 Xml
::radioLabel( wfMsg( $v ), 'wpMath', $k, "mw-sp-math-$k", $checked ) .
816 Xml
::closeElement( 'div' ) . "\n"
819 $wgOut->addHTML( "</fieldset>\n\n" );
825 "<fieldset>\n" . Xml
::element( 'legend', null, wfMsg( 'files' ) ) . "\n"
828 $imageLimitOptions = null;
829 foreach ( $wgImageLimits as $index => $limits ) {
830 $selected = ($index == $this->mImageSize
);
831 $imageLimitOptions .= Xml
::option( "{$limits[0]}ร{$limits[1]}" .
832 wfMsg('unit-pixel'), $index, $selected );
835 $imageSizeId = 'wpImageSize';
837 "<div>" . Xml
::label( wfMsg('imagemaxsize'), $imageSizeId ) . " " .
838 Xml
::openElement( 'select', array( 'name' => $imageSizeId, 'id' => $imageSizeId ) ) .
840 Xml
::closeElement( 'select' ) . "</div>\n"
843 $imageThumbOptions = null;
844 foreach ( $wgThumbLimits as $index => $size ) {
845 $selected = ($index == $this->mThumbSize
);
846 $imageThumbOptions .= Xml
::option($size . wfMsg('unit-pixel'), $index,
850 $thumbSizeId = 'wpThumbSize';
852 "<div>" . Xml
::label( wfMsg('thumbsize'), $thumbSizeId ) . " " .
853 Xml
::openElement( 'select', array( 'name' => $thumbSizeId, 'id' => $thumbSizeId ) ) .
855 Xml
::closeElement( 'select' ) . "</div>\n"
858 $wgOut->addHTML( "</fieldset>\n\n" );
865 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'datetime' ) . "</legend>\n" );
868 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'dateformat' ) . "</legend>\n" );
870 $epoch = '20010115161234'; # Wikipedia day
871 foreach( $dateopts as $key ) {
872 if( $key == 'default' ) {
873 $formatted = wfMsgHtml( 'datedefault' );
875 $formatted = htmlspecialchars( $wgLang->timeanddate( $epoch, false, $key ) );
877 ($key == $this->mDate
) ?
$checked = ' checked="checked"' : $checked = '';
878 $wgOut->addHTML( "<div><input type='radio' name=\"wpDate\" id=\"wpDate$idCnt\" ".
879 "value=\"$key\"$checked /> <label for=\"wpDate$idCnt\">$formatted</label></div>\n" );
882 $wgOut->addHTML( "</fieldset>\n" );
885 $nowlocal = $wgLang->time( $now = wfTimestampNow(), true );
886 $nowserver = $wgLang->time( $now, false );
888 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'timezonelegend' ). '</legend><table>' .
889 $this->addRow( wfMsg( 'servertime' ), $nowserver ) .
890 $this->addRow( wfMsg( 'localtime' ), $nowlocal ) .
892 '<label for="wpHourDiff">' . wfMsg( 'timezoneoffset' ) . '</label>',
893 "<input type='text' name='wpHourDiff' id='wpHourDiff' value=\"" . htmlspecialchars( $this->mHourDiff
) . "\" size='6' />"
894 ) . "<tr><td colspan='2'>
895 <input type='button' value=\"" . wfMsg( 'guesstimezone' ) ."\"
896 onclick='javascript:guessTimezone()' id='guesstimezonebutton' style='display:none;' />
897 </td></tr></table><div class='prefsectiontip'>ยน" . wfMsg( 'timezonetext' ) . "</div></fieldset>
902 global $wgLivePreview;
903 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'textboxsize' ) . '</legend>
905 wfInputLabel( wfMsg( 'rows' ), 'wpRows', 'wpRows', 3, $this->mRows
) .
907 wfInputLabel( wfMsg( 'columns' ), 'wpCols', 'wpCols', 3, $this->mCols
) .
909 $this->getToggles( array(
911 'editsectiononrightclick',
920 $wgLivePreview ?
'uselivepreview' : false,
926 $wgOut->addHtml( '<fieldset><legend>' . wfMsgHtml( 'prefs-rc' ) . '</legend>' );
929 $rc .= '<td>' . Xml
::label( wfMsg( 'recentchangesdays' ), 'wpRecentDays' ) . '</td>';
930 $rc .= '<td>' . Xml
::input( 'wpRecentDays', 3, $this->mRecentDays
, array( 'id' => 'wpRecentDays' ) ) . '</td>';
932 $rc .= '<td>' . Xml
::label( wfMsg( 'recentchangescount' ), 'wpRecent' ) . '</td>';
933 $rc .= '<td>' . Xml
::input( 'wpRecent', 3, $this->mRecent
, array( 'id' => 'wpRecent' ) ) . '</td>';
934 $rc .= '</tr></table>';
935 $wgOut->addHtml( $rc );
937 $wgOut->addHtml( '<br />' );
939 $toggles[] = 'hideminor';
940 if( $wgRCShowWatchingUsers )
941 $toggles[] = 'shownumberswatching';
942 $toggles[] = 'usenewrc';
943 $wgOut->addHtml( $this->getToggles( $toggles ) );
945 $wgOut->addHtml( '</fieldset>' );
948 $wgOut->addHtml( '<fieldset><legend>' . wfMsgHtml( 'prefs-watchlist' ) . '</legend>' );
950 $wgOut->addHtml( wfInputLabel( wfMsg( 'prefs-watchlist-days' ), 'wpWatchlistDays', 'wpWatchlistDays', 3, $this->mWatchlistDays
) );
951 $wgOut->addHtml( '<br /><br />' );
953 $wgOut->addHtml( $this->getToggle( 'extendwatchlist' ) );
954 $wgOut->addHtml( wfInputLabel( wfMsg( 'prefs-watchlist-edits' ), 'wpWatchlistEdits', 'wpWatchlistEdits', 3, $this->mWatchlistEdits
) );
955 $wgOut->addHtml( '<br /><br />' );
957 $wgOut->addHtml( $this->getToggles( array( 'watchlisthideown', 'watchlisthidebots', 'watchlisthideminor' ) ) );
959 if( $wgUser->isAllowed( 'createpage' ) ||
$wgUser->isAllowed( 'createtalk' ) )
960 $wgOut->addHtml( $this->getToggle( 'watchcreations' ) );
961 foreach( array( 'edit' => 'watchdefault', 'move' => 'watchmoves', 'delete' => 'watchdeletion' ) as $action => $toggle ) {
962 if( $wgUser->isAllowed( $action ) )
963 $wgOut->addHtml( $this->getToggle( $toggle ) );
965 $this->mUsedToggles
['watchcreations'] = true;
966 $this->mUsedToggles
['watchdefault'] = true;
967 $this->mUsedToggles
['watchmoves'] = true;
968 $this->mUsedToggles
['watchdeletion'] = true;
970 $wgOut->addHtml( '</fieldset>' );
973 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'searchresultshead' ) . '</legend><table>' .
975 wfLabel( wfMsg( 'resultsperpage' ), 'wpSearch' ),
976 wfInput( 'wpSearch', 4, $this->mSearch
, array( 'id' => 'wpSearch' ) )
979 wfLabel( wfMsg( 'contextlines' ), 'wpSearchLines' ),
980 wfInput( 'wpSearchLines', 4, $this->mSearchLines
, array( 'id' => 'wpSearchLines' ) )
983 wfLabel( wfMsg( 'contextchars' ), 'wpSearchChars' ),
984 wfInput( 'wpSearchChars', 4, $this->mSearchChars
, array( 'id' => 'wpSearchChars' ) )
986 "</table><fieldset><legend>" . wfMsg( 'defaultns' ) . "</legend>$ps</fieldset></fieldset>" );
990 $wgOut->addHTML('<fieldset><legend>' . wfMsg('prefs-misc') . '</legend>');
991 $wgOut->addHtml( '<label for="wpStubs">' . wfMsg( 'stub-threshold' ) . '</label> ' );
992 $wgOut->addHtml( Xml
::input( 'wpStubs', 6, $this->mStubs
, array( 'id' => 'wpStubs' ) ) );
993 $msgUnderline = htmlspecialchars( wfMsg ( 'tog-underline' ) );
994 $msgUnderlinenever = htmlspecialchars( wfMsg ( 'underline-never' ) );
995 $msgUnderlinealways = htmlspecialchars( wfMsg ( 'underline-always' ) );
996 $msgUnderlinedefault = htmlspecialchars( wfMsg ( 'underline-default' ) );
997 $uopt = $wgUser->getOption("underline");
998 $s0 = $uopt == 0 ?
' selected="selected"' : '';
999 $s1 = $uopt == 1 ?
' selected="selected"' : '';
1000 $s2 = $uopt == 2 ?
' selected="selected"' : '';
1002 <div class='toggle'><p><label for='wpOpunderline'>$msgUnderline</label>
1003 <select name='wpOpunderline' id='wpOpunderline'>
1004 <option value=\"0\"$s0>$msgUnderlinenever</option>
1005 <option value=\"1\"$s1>$msgUnderlinealways</option>
1006 <option value=\"2\"$s2>$msgUnderlinedefault</option>
1007 </select></p></div>");
1009 foreach ( $togs as $tname ) {
1010 if( !array_key_exists( $tname, $this->mUsedToggles
) ) {
1011 $wgOut->addHTML( $this->getToggle( $tname ) );
1014 $wgOut->addHTML( '</fieldset>' );
1016 wfRunHooks( 'RenderPreferencesForm', array( $this, $wgOut ) );
1018 $token = htmlspecialchars( $wgUser->editToken() );
1019 $skin = $wgUser->getSkin();
1021 <div id='prefsubmit'>
1023 <input type='submit' name='wpSaveprefs' class='btnSavePrefs' value=\"" . wfMsgHtml( 'saveprefs' ) . '"'.$skin->tooltipAndAccesskey('save')." />
1024 <input type='submit' name='wpReset' value=\"" . wfMsgHtml( 'resetprefs' ) . "\" />
1029 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1032 $wgOut->addHtml( Xml
::tags( 'div', array( 'class' => "prefcache" ),
1033 wfMsgExt( 'clearyourcache', 'parseinline' ) )