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';
103 global $wgUser, $wgOut;
105 if ( $wgUser->isAnon() ) {
106 $wgOut->showErrorPage( 'prefsnologin', 'prefsnologintext' );
109 if ( wfReadOnly() ) {
110 $wgOut->readOnlyPage();
113 if ( $this->mReset
) {
115 $this->mainPrefsForm( 'reset', wfMsg( 'prefsreset' ) );
116 } else if ( $this->mSaveprefs
) {
117 $this->savePreferences();
120 $this->mainPrefsForm( '' );
126 function validateInt( &$val, $min=0, $max=0x7fffffff ) {
128 $val = min($val, $max);
129 $val = max($val, $min);
136 function validateFloat( &$val, $min, $max=0x7fffffff ) {
137 $val = floatval( $val );
138 $val = min( $val, $max );
139 $val = max( $val, $min );
146 function validateIntOrNull( &$val, $min=0, $max=0x7fffffff ) {
151 return $this->validateInt( $val, $min, $max );
158 function validateDate( $val ) {
159 global $wgLang, $wgContLang;
160 if ( $val !== false && (
161 in_array( $val, (array)$wgLang->getDatePreferences() ) ||
162 in_array( $val, (array)$wgContLang->getDatePreferences() ) ) )
166 return $wgLang->getDefaultDateFormat();
171 * Used to validate the user inputed timezone before saving it as
172 * 'timecorrection', will return '00:00' if fed bogus data.
173 * Note: It's not a 100% correct implementation timezone-wise, it will
174 * accept stuff like '14:30',
176 * @param string $s the user input
179 function validateTimeZone( $s ) {
181 if ( strpos( $s, ':' ) ) {
183 $array = explode( ':' , $s );
184 $hour = intval( $array[0] );
185 $minute = intval( $array[1] );
187 $minute = intval( $s * 60 );
188 $hour = intval( $minute / 60 );
189 $minute = abs( $minute ) %
60;
191 # Max is +14:00 and min is -12:00, see:
192 # http://en.wikipedia.org/wiki/Timezone
193 $hour = min( $hour, 14 );
194 $hour = max( $hour, -12 );
195 $minute = min( $minute, 59 );
196 $minute = max( $minute, 0 );
197 $s = sprintf( "%02d:%02d", $hour, $minute );
205 function savePreferences() {
206 global $wgUser, $wgOut, $wgParser;
207 global $wgEnableUserEmail, $wgEnableEmail;
208 global $wgEmailAuthentication;
212 if ( '' != $this->mNewpass
&& $wgAuth->allowPasswordChange() ) {
213 if ( $this->mNewpass
!= $this->mRetypePass
) {
214 wfRunHooks( "PrefsPasswordAudit", array( $wgUser, $this->mNewpass
, 'badretype' ) );
215 $this->mainPrefsForm( 'error', wfMsg( 'badretype' ) );
219 if (!$wgUser->checkPassword( $this->mOldpass
)) {
220 wfRunHooks( "PrefsPasswordAudit", array( $wgUser, $this->mNewpass
, 'wrongpassword' ) );
221 $this->mainPrefsForm( 'error', wfMsg( 'wrongpassword' ) );
226 $wgUser->setPassword( $this->mNewpass
);
227 wfRunHooks( "PrefsPasswordAudit", array( $wgUser, $this->mNewpass
, 'success' ) );
228 $this->mNewpass
= $this->mOldpass
= $this->mRetypePass
= '';
229 } catch( PasswordError
$e ) {
230 wfRunHooks( "PrefsPasswordAudit", array( $wgUser, $this->mNewpass
, 'error' ) );
231 $this->mainPrefsForm( 'error', $e->getMessage() );
235 $wgUser->setRealName( $this->mRealName
);
237 if( $wgUser->getOption( 'language' ) !== $this->mUserLanguage
) {
238 $needRedirect = true;
240 $needRedirect = false;
243 # Validate the signature and clean it up as needed
244 if( $this->mToggles
['fancysig'] ) {
245 if( Parser
::validateSig( $this->mNick
) !== false ) {
246 $this->mNick
= $wgParser->cleanSig( $this->mNick
);
248 $this->mainPrefsForm( 'error', wfMsg( 'badsig' ) );
251 // When no fancy sig used, make sure ~{3,5} get removed.
252 $this->mNick
= $wgParser->cleanSigInSig( $this->mNick
);
255 $wgUser->setOption( 'language', $this->mUserLanguage
);
256 $wgUser->setOption( 'variant', $this->mUserVariant
);
257 $wgUser->setOption( 'nickname', $this->mNick
);
258 $wgUser->setOption( 'quickbar', $this->mQuickbar
);
259 $wgUser->setOption( 'skin', $this->mSkin
);
262 $wgUser->setOption( 'math', $this->mMath
);
264 $wgUser->setOption( 'date', $this->validateDate( $this->mDate
) );
265 $wgUser->setOption( 'searchlimit', $this->validateIntOrNull( $this->mSearch
) );
266 $wgUser->setOption( 'contextlines', $this->validateIntOrNull( $this->mSearchLines
) );
267 $wgUser->setOption( 'contextchars', $this->validateIntOrNull( $this->mSearchChars
) );
268 $wgUser->setOption( 'rclimit', $this->validateIntOrNull( $this->mRecent
) );
269 $wgUser->setOption( 'rcdays', $this->validateInt( $this->mRecentDays
, 1, 7 ) );
270 $wgUser->setOption( 'wllimit', $this->validateIntOrNull( $this->mWatchlistEdits
, 0, 1000 ) );
271 $wgUser->setOption( 'rows', $this->validateInt( $this->mRows
, 4, 1000 ) );
272 $wgUser->setOption( 'cols', $this->validateInt( $this->mCols
, 4, 1000 ) );
273 $wgUser->setOption( 'stubthreshold', $this->validateIntOrNull( $this->mStubs
) );
274 $wgUser->setOption( 'timecorrection', $this->validateTimeZone( $this->mHourDiff
, -12, 14 ) );
275 $wgUser->setOption( 'imagesize', $this->mImageSize
);
276 $wgUser->setOption( 'thumbsize', $this->mThumbSize
);
277 $wgUser->setOption( 'underline', $this->validateInt($this->mUnderline
, 0, 2) );
278 $wgUser->setOption( 'watchlistdays', $this->validateFloat( $this->mWatchlistDays
, 0, 7 ) );
280 # Set search namespace options
281 foreach( $this->mSearchNs
as $i => $value ) {
282 $wgUser->setOption( "searchNs{$i}", $value );
285 if( $wgEnableEmail && $wgEnableUserEmail ) {
286 $wgUser->setOption( 'disablemail', $this->mEmailFlag
);
290 foreach ( $this->mToggles
as $tname => $tvalue ) {
291 $wgUser->setOption( $tname, $tvalue );
293 if (!$wgAuth->updateExternalDB($wgUser)) {
294 $this->mainPrefsForm( wfMsg( 'externaldberror' ) );
297 $wgUser->setCookies();
298 $wgUser->saveSettings();
301 if( $wgEnableEmail ) {
302 $newadr = $this->mUserEmail
;
303 $oldadr = $wgUser->getEmail();
304 if( ($newadr != '') && ($newadr != $oldadr) ) {
305 # the user has supplied a new email address on the login page
306 if( $wgUser->isValidEmailAddr( $newadr ) ) {
307 $wgUser->mEmail
= $newadr; # new behaviour: set this new emailaddr from login-page into user database record
308 $wgUser->mEmailAuthenticated
= null; # but flag as "dirty" = unauthenticated
309 $wgUser->saveSettings();
310 if ($wgEmailAuthentication) {
311 # Mail a temporary password to the dirty address.
312 # User can come back through the confirmation URL to re-enable email.
313 $result = $wgUser->sendConfirmationMail();
314 if( WikiError
::isError( $result ) ) {
315 $error = wfMsg( 'mailerror', htmlspecialchars( $result->getMessage() ) );
317 $error = wfMsg( 'eauthentsent', $wgUser->getName() );
321 $error = wfMsg( 'invalidemailaddress' );
324 $wgUser->setEmail( $this->mUserEmail
);
325 $wgUser->setCookies();
326 $wgUser->saveSettings();
328 if( $oldadr != $newadr ) {
329 wfRunHooks( "PrefsEmailAudit", array( $wgUser, $oldadr, $newadr ) );
333 if( $needRedirect && $error === false ) {
334 $title =& SpecialPage
::getTitleFor( "Preferences" );
335 $wgOut->redirect($title->getFullURL('success'));
339 $wgOut->setParserOptions( ParserOptions
::newFromUser( $wgUser ) );
340 $this->mainPrefsForm( $error === false ?
'success' : 'error', $error);
346 function resetPrefs() {
347 global $wgUser, $wgLang, $wgContLang, $wgContLanguageCode, $wgAllowRealName;
349 $this->mOldpass
= $this->mNewpass
= $this->mRetypePass
= '';
350 $this->mUserEmail
= $wgUser->getEmail();
351 $this->mUserEmailAuthenticationtimestamp
= $wgUser->getEmailAuthenticationtimestamp();
352 $this->mRealName
= ($wgAllowRealName) ?
$wgUser->getRealName() : '';
354 # language value might be blank, default to content language
355 $this->mUserLanguage
= $wgUser->getOption( 'language', $wgContLanguageCode );
357 $this->mUserVariant
= $wgUser->getOption( 'variant');
358 $this->mEmailFlag
= $wgUser->getOption( 'disablemail' ) == 1 ?
1 : 0;
359 $this->mNick
= $wgUser->getOption( 'nickname' );
361 $this->mQuickbar
= $wgUser->getOption( 'quickbar' );
362 $this->mSkin
= Skin
::normalizeKey( $wgUser->getOption( 'skin' ) );
363 $this->mMath
= $wgUser->getOption( 'math' );
364 $this->mDate
= $wgUser->getDatePreference();
365 $this->mRows
= $wgUser->getOption( 'rows' );
366 $this->mCols
= $wgUser->getOption( 'cols' );
367 $this->mStubs
= $wgUser->getOption( 'stubthreshold' );
368 $this->mHourDiff
= $wgUser->getOption( 'timecorrection' );
369 $this->mSearch
= $wgUser->getOption( 'searchlimit' );
370 $this->mSearchLines
= $wgUser->getOption( 'contextlines' );
371 $this->mSearchChars
= $wgUser->getOption( 'contextchars' );
372 $this->mImageSize
= $wgUser->getOption( 'imagesize' );
373 $this->mThumbSize
= $wgUser->getOption( 'thumbsize' );
374 $this->mRecent
= $wgUser->getOption( 'rclimit' );
375 $this->mRecentDays
= $wgUser->getOption( 'rcdays' );
376 $this->mWatchlistEdits
= $wgUser->getOption( 'wllimit' );
377 $this->mUnderline
= $wgUser->getOption( 'underline' );
378 $this->mWatchlistDays
= $wgUser->getOption( 'watchlistdays' );
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 );
396 function namespacesCheckboxes() {
399 # Determine namespace checkboxes
400 $namespaces = $wgContLang->getNamespaces();
403 foreach ( $namespaces as $i => $name ) {
406 $checked = $this->mSearchNs
[$i] ?
"checked='checked'" : '';
407 $name = str_replace( '_', ' ', $namespaces[$i] );
410 $name = wfMsg( 'blanknamespace' );
412 $r1 .= "<input type='checkbox' value='1' name='wpNs$i' id='wpNs$i' {$checked}/> <label for='wpNs$i'>{$name}</label><br />\n";
418 function getToggle( $tname, $trailer = false, $disabled = false ) {
419 global $wgUser, $wgLang;
421 $this->mUsedToggles
[$tname] = true;
422 $ttext = $wgLang->getUserToggle( $tname );
424 $checked = $wgUser->getOption( $tname ) == 1 ?
' checked="checked"' : '';
425 $disabled = $disabled ?
' disabled="disabled"' : '';
426 $trailer = $trailer ?
$trailer : '';
427 return "<div class='toggle'><input type='checkbox' value='1' id=\"$tname\" name=\"wpOp$tname\"$checked$disabled />" .
428 " <span class='toggletext'><label for=\"$tname\">$ttext</label>$trailer</span></div>\n";
431 function getToggles( $items ) {
433 foreach( $items as $item ) {
434 if( $item === false )
436 if( is_array( $item ) ) {
437 list( $key, $trailer ) = $item;
442 $out .= $this->getToggle( $key, $trailer );
447 function addRow($td1, $td2) {
448 return "<tr><td align='right'>$td1</td><td align='left'>$td2</td></tr>";
452 * Helper function for user information panel
453 * @param $td1 label for an item
454 * @param $td2 item or null
455 * @param $td3 optional help or null
456 * @return xhtml block
458 function tableRow( $td1, $td2 = null, $td3 = null ) {
461 $align['align'] = $wgContLang->isRtl() ?
'right' : 'left';
463 if ( is_null( $td3 ) ) {
466 $td3 = Xml
::tags( 'tr', null,
467 Xml
::tags( 'td', array( 'colspan' => '2' ), $td3 )
471 if ( is_null( $td2 ) ) {
472 $td1 = Xml
::tags( 'td', $align +
array( 'colspan' => '2' ), $td1 );
475 $td1 = Xml
::tags( 'td', $align, $td1 );
476 $td2 = Xml
::tags( 'td', $align, $td2 );
479 return Xml
::tags( 'tr', null, $td1 . $td2 ). $td3 . "\n";
486 function mainPrefsForm( $status , $message = '' ) {
487 global $wgUser, $wgOut, $wgLang, $wgContLang;
488 global $wgAllowRealName, $wgImageLimits, $wgThumbLimits;
489 global $wgDisableLangConversion;
490 global $wgEnotifWatchlist, $wgEnotifUserTalk,$wgEnotifMinorEdits;
491 global $wgRCShowWatchingUsers, $wgEnotifRevealEditorAddress;
492 global $wgEnableEmail, $wgEnableUserEmail, $wgEmailAuthentication;
493 global $wgContLanguageCode, $wgDefaultSkin, $wgSkipSkins, $wgAuth;
495 $wgOut->setPageTitle( wfMsg( 'preferences' ) );
496 $wgOut->setArticleRelated( false );
497 $wgOut->setRobotpolicy( 'noindex,nofollow' );
499 $wgOut->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc.
501 if ( $this->mSuccess ||
'success' == $status ) {
502 $wgOut->addWikitext( '<div class="successbox"><strong>'. wfMsg( 'savedprefs' ) . '</strong></div>' );
503 } else if ( 'error' == $status ) {
504 $wgOut->addWikitext( '<div class="errorbox"><strong>' . $message . '</strong></div>' );
505 } else if ( '' != $status ) {
506 $wgOut->addWikitext( $message . "\n----" );
509 $qbs = $wgLang->getQuickbarSettings();
510 $skinNames = $wgLang->getSkinNames();
511 $mathopts = $wgLang->getMathNames();
512 $dateopts = $wgLang->getDatePreferences();
513 $togs = User
::getToggles();
515 $titleObj = SpecialPage
::getTitleFor( 'Preferences' );
516 $action = $titleObj->escapeLocalURL();
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;
529 if ( !$this->mEmailFlag
) { $emfc = 'checked="checked"'; }
533 if ($wgEmailAuthentication && ($this->mUserEmail
!= '') ) {
534 if( $wgUser->getEmailAuthenticationTimestamp() ) {
535 $emailauthenticated = wfMsg('emailauthenticated',$wgLang->timeanddate($wgUser->getEmailAuthenticationTimestamp(), true ) ).'<br />';
536 $disableEmailPrefs = false;
538 $disableEmailPrefs = true;
539 $skin = $wgUser->getSkin();
540 $emailauthenticated = wfMsg('emailnotauthenticated').'<br />' .
541 $skin->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Confirmemail' ),
542 wfMsg( 'emailconfirmlink' ) );
545 $emailauthenticated = '';
546 $disableEmailPrefs = false;
549 if ($this->mUserEmail
== '') {
550 $emailauthenticated = wfMsg( 'noemailprefs' );
553 $ps = $this->namespacesCheckboxes();
555 $enotifwatchlistpages = ($wgEnotifWatchlist) ?
$this->getToggle( 'enotifwatchlistpages', false, $disableEmailPrefs ) : '';
556 $enotifusertalkpages = ($wgEnotifUserTalk) ?
$this->getToggle( 'enotifusertalkpages', false, $disableEmailPrefs ) : '';
557 $enotifminoredits = ($wgEnotifWatchlist && $wgEnotifMinorEdits) ?
$this->getToggle( 'enotifminoredits', false, $disableEmailPrefs ) : '';
558 $enotifrevealaddr = (($wgEnotifWatchlist ||
$wgEnotifUserTalk) && $wgEnotifRevealEditorAddress) ?
$this->getToggle( 'enotifrevealaddr', false, $disableEmailPrefs ) : '';
562 $wgOut->addHTML( "<form action=\"$action\" method='post'>" );
563 $wgOut->addHTML( "<div id='preferences'>" );
568 Xml
::openElement( 'fieldset ' ) .
569 Xml
::element( 'legend', null, wfMsg('prefs-personal') ) .
570 Xml
::openElement( 'table' ) .
571 $this->tableRow( Xml
::element( 'h2', null, wfMsg( 'prefs-personal' ) ) )
574 $userInformationHtml =
575 $this->tableRow( wfMsgHtml( 'username' ), htmlspecialchars( $wgUser->getName() ) ) .
576 $this->tableRow( wfMsgHtml( 'uid' ), htmlspecialchars( $wgUser->getID() ) );
578 if( wfRunHooks( 'PreferencesUserInformationPanel', array( $this, &$userInformationHtml ) ) ) {
579 $wgOut->addHtml( $userInformationHtml );
582 if ( $wgAllowRealName ) {
585 Xml
::label( wfMsg('yourrealname'), 'wpRealName' ),
586 Xml
::input( 'wpRealName', 25, $this->mRealName
, array( 'id' => 'wpRealName' ) ),
587 Xml
::tags('div', array( 'class' => 'prefsectiontip' ),
588 wfMsgExt( 'prefs-help-realname', 'parseinline' )
593 if ( $wgEnableEmail ) {
596 Xml
::label( wfMsg('youremail'), 'wpUserEmail' ),
597 Xml
::input( 'wpUserEmail', 25, $this->mUserEmail
, array( 'id' => 'wpUserEmail' ) ),
598 Xml
::tags('div', array( 'class' => 'prefsectiontip' ),
599 wfMsgExt( 'prefs-help-email', 'parseinline' )
606 if( !empty( $this->mToggles
['fancysig'] ) &&
607 false === $wgParser->validateSig( $this->mNick
) ) {
608 $invalidSig = $this->tableRow(
610 Xml
::element( 'span', array( 'class' => 'error' ), wfMsg( 'badsig' ) )
618 Xml
::label( wfMsg( 'yournick' ), 'wpNick' ),
619 Xml
::input( 'wpNick', 25, $this->mNick
, array( 'id' => 'wpNick' ) )
622 $this->tableRow( ' ', $this->getToggle( 'fancysig' ) )
625 list( $lsLabel, $lsSelect) = Xml
::languageSelector( $this->mUserLanguage
);
627 $this->tableRow( $lsLabel, $lsSelect )
630 /* see if there are multiple language variants to choose from*/
631 if(!$wgDisableLangConversion) {
632 $variants = $wgContLang->getVariants();
633 $variantArray = array();
635 $languages = Language
::getLanguageNames( true );
636 foreach($variants as $v) {
637 $v = str_replace( '_', '-', strtolower($v));
638 if( array_key_exists( $v, $languages ) ) {
639 // If it doesn't have a name, we'll pretend it doesn't exist
640 $variantArray[$v] = $languages[$v];
645 foreach( $variantArray as $code => $name ) {
646 $selected = ($code == $this->mUserVariant
);
647 $options .= Xml
::option( "$code - $name", $code, $selected ) . "\n";
650 if(count($variantArray) > 1) {
653 Xml
::label( wfMsg( 'yourvariant' ), 'wpUserVariant' ),
655 array( 'name' => 'wpUserVariant', 'id' => 'wpUserVariant' ),
664 if( $wgAuth->allowPasswordChange() ) {
666 $this->tableRow( Xml
::element( 'h2', null, wfMsg( 'changepassword' ) ) ) .
668 Xml
::label( wfMsg( 'oldpassword' ), 'wpOldpass' ),
669 Xml
::password( 'wpOldpass', 25, $this->mOldpass
, array( 'id' => 'wpOldpass' ) )
672 Xml
::label( wfMsg( 'newpassword' ), 'wpNewpass' ),
673 Xml
::password( 'wpNewpass', 25, $this->mNewpass
, array( 'id' => 'wpNewpass' ) )
676 Xml
::label( wfMsg( 'retypenew' ), 'wpRetypePass' ),
677 Xml
::password( 'wpRetypePass', 25, $this->mRetypePass
, array( 'id' => 'wpRetypePass' ) )
679 Xml
::tags( 'tr', null,
680 Xml
::tags( 'td', array( 'colspan' => '2' ),
681 $this->getToggle( "rememberpassword" )
689 if ( $wgEnableEmail ) {
692 if ($wgEnableUserEmail) {
693 $emf = wfMsg( 'allowemail' );
694 $disabled = $disableEmailPrefs ?
' disabled="disabled"' : '';
696 "<input type='checkbox' $emfc $disabled value='1' name='wpEmailFlag' id='wpEmailFlag' /> <label for='wpEmailFlag'>$emf</label>";
701 $this->tableRow( Xml
::element( 'h2', null, wfMsg( 'email' ) ) ) .
705 $enotifwatchlistpages.
706 $enotifusertalkpages.
709 $this->getToggle( 'ccmeonemails' )
716 Xml
::closeElement( 'table' ) .
717 Xml
::closeElement( 'fieldset' )
723 if ($this->mSkin
== 'cologneblue' ||
$this->mSkin
== 'standard') {
724 $wgOut->addHtml( "<fieldset>\n<legend>" . wfMsg( 'qbsettings' ) . "</legend>\n" );
725 for ( $i = 0; $i < count( $qbs ); ++
$i ) {
726 if ( $i == $this->mQuickbar
) { $checked = ' checked="checked"'; }
727 else { $checked = ""; }
728 $wgOut->addHTML( "<div><label><input type='radio' name='wpQuickbar' value=\"$i\"$checked />{$qbs[$i]}</label></div>\n" );
730 $wgOut->addHtml( "</fieldset>\n\n" );
732 # Need to output a hidden option even if the relevant skin is not in use,
733 # otherwise the preference will get reset to 0 on submit
734 $wgOut->addHtml( wfHidden( 'wpQuickbar', $this->mQuickbar
) );
739 $wgOut->addHTML( "<fieldset>\n<legend>\n" . wfMsg('skin') . "</legend>\n" );
740 $mptitle = Title
::newMainPage();
741 $previewtext = wfMsg('skinpreview');
742 # Only show members of Skin::getSkinNames() rather than
743 # $skinNames (skins is all skin names from Language.php)
744 $validSkinNames = Skin
::getSkinNames();
745 # Sort by UI skin name. First though need to update validSkinNames as sometimes
746 # the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI).
747 foreach ($validSkinNames as $skinkey => & $skinname ) {
748 if ( isset( $skinNames[$skinkey] ) ) {
749 $skinname = $skinNames[$skinkey];
752 asort($validSkinNames);
753 foreach ($validSkinNames as $skinkey => $sn ) {
754 if ( in_array( $skinkey, $wgSkipSkins ) ) {
757 $checked = $skinkey == $this->mSkin ?
' checked="checked"' : '';
759 $mplink = htmlspecialchars($mptitle->getLocalURL("useskin=$skinkey"));
760 $previewlink = "<a target='_blank' href=\"$mplink\">$previewtext</a>";
761 if( $skinkey == $wgDefaultSkin )
762 $sn .= ' (' . wfMsg( 'default' ) . ')';
763 $wgOut->addHTML( "<input type='radio' name='wpSkin' id=\"wpSkin$skinkey\" value=\"$skinkey\"$checked /> <label for=\"wpSkin$skinkey\">{$sn}</label> $previewlink<br />\n" );
765 $wgOut->addHTML( "</fieldset>\n\n" );
771 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg('math') . '</legend>' );
772 foreach ( $mathopts as $k => $v ) {
773 $checked = ($k == $this->mMath
);
775 Xml
::openElement( 'div' ) .
776 Xml
::radioLabel( wfMsg( $v ), 'wpMath', $k, "mw-sp-math-$k", $checked ) .
777 Xml
::closeElement( 'div' ) . "\n"
780 $wgOut->addHTML( "</fieldset>\n\n" );
786 "<fieldset>\n" . Xml
::element( 'legend', null, wfMsg( 'files' ) ) . "\n"
789 $imageLimitOptions = null;
790 foreach ( $wgImageLimits as $index => $limits ) {
791 $selected = ($index == $this->mImageSize
);
792 $imageLimitOptions .= Xml
::option( "{$limits[0]}ร{$limits[1]}" .
793 wfMsg('unit-pixel'), $index, $selected );
796 $imageSizeId = 'wpImageSize';
798 "<div>" . Xml
::label( wfMsg('imagemaxsize'), $imageSizeId ) . " " .
799 Xml
::openElement( 'select', array( 'name' => $imageSizeId, 'id' => $imageSizeId ) ) .
801 Xml
::closeElement( 'select' ) . "</div>\n"
804 $imageThumbOptions = null;
805 foreach ( $wgThumbLimits as $index => $size ) {
806 $selected = ($index == $this->mThumbSize
);
807 $imageThumbOptions .= Xml
::option($size . wfMsg('unit-pixel'), $index,
811 $thumbSizeId = 'wpThumbSize';
813 "<div>" . Xml
::label( wfMsg('thumbsize'), $thumbSizeId ) . " " .
814 Xml
::openElement( 'select', array( 'name' => $thumbSizeId, 'id' => $thumbSizeId ) ) .
816 Xml
::closeElement( 'select' ) . "</div>\n"
819 $wgOut->addHTML( "</fieldset>\n\n" );
826 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'datetime' ) . "</legend>\n" );
829 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'dateformat' ) . "</legend>\n" );
831 $epoch = '20010115161234'; # Wikipedia day
832 foreach( $dateopts as $key ) {
833 if( $key == 'default' ) {
834 $formatted = wfMsgHtml( 'datedefault' );
836 $formatted = htmlspecialchars( $wgLang->timeanddate( $epoch, false, $key ) );
838 ($key == $this->mDate
) ?
$checked = ' checked="checked"' : $checked = '';
839 $wgOut->addHTML( "<div><input type='radio' name=\"wpDate\" id=\"wpDate$idCnt\" ".
840 "value=\"$key\"$checked /> <label for=\"wpDate$idCnt\">$formatted</label></div>\n" );
843 $wgOut->addHTML( "</fieldset>\n" );
846 $nowlocal = $wgLang->time( $now = wfTimestampNow(), true );
847 $nowserver = $wgLang->time( $now, false );
849 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'timezonelegend' ). '</legend><table>' .
850 $this->addRow( wfMsg( 'servertime' ), $nowserver ) .
851 $this->addRow( wfMsg( 'localtime' ), $nowlocal ) .
853 '<label for="wpHourDiff">' . wfMsg( 'timezoneoffset' ) . '</label>',
854 "<input type='text' name='wpHourDiff' id='wpHourDiff' value=\"" . htmlspecialchars( $this->mHourDiff
) . "\" size='6' />"
855 ) . "<tr><td colspan='2'>
856 <input type='button' value=\"" . wfMsg( 'guesstimezone' ) ."\"
857 onclick='javascript:guessTimezone()' id='guesstimezonebutton' style='display:none;' />
858 </td></tr></table><div class='prefsectiontip'>ยน" . wfMsg( 'timezonetext' ) . "</div></fieldset>
863 global $wgLivePreview;
864 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'textboxsize' ) . '</legend>
866 wfInputLabel( wfMsg( 'rows' ), 'wpRows', 'wpRows', 3, $this->mRows
) .
868 wfInputLabel( wfMsg( 'columns' ), 'wpCols', 'wpCols', 3, $this->mCols
) .
870 $this->getToggles( array(
872 'editsectiononrightclick',
881 $wgLivePreview ?
'uselivepreview' : false,
887 $wgOut->addHtml( '<fieldset><legend>' . wfMsgHtml( 'prefs-rc' ) . '</legend>' );
890 $rc .= '<td>' . Xml
::label( wfMsg( 'recentchangesdays' ), 'wpRecentDays' ) . '</td>';
891 $rc .= '<td>' . Xml
::input( 'wpRecentDays', 3, $this->mRecentDays
, array( 'id' => 'wpRecentDays' ) ) . '</td>';
893 $rc .= '<td>' . Xml
::label( wfMsg( 'recentchangescount' ), 'wpRecent' ) . '</td>';
894 $rc .= '<td>' . Xml
::input( 'wpRecent', 3, $this->mRecent
, array( 'id' => 'wpRecent' ) ) . '</td>';
895 $rc .= '</tr></table>';
896 $wgOut->addHtml( $rc );
898 $wgOut->addHtml( '<br />' );
900 $toggles[] = 'hideminor';
901 if( $wgRCShowWatchingUsers )
902 $toggles[] = 'shownumberswatching';
903 $toggles[] = 'usenewrc';
904 $wgOut->addHtml( $this->getToggles( $toggles ) );
906 $wgOut->addHtml( '</fieldset>' );
909 $wgOut->addHtml( '<fieldset><legend>' . wfMsgHtml( 'prefs-watchlist' ) . '</legend>' );
911 $wgOut->addHtml( wfInputLabel( wfMsg( 'prefs-watchlist-days' ), 'wpWatchlistDays', 'wpWatchlistDays', 3, $this->mWatchlistDays
) );
912 $wgOut->addHtml( '<br /><br />' );
914 $wgOut->addHtml( $this->getToggle( 'extendwatchlist' ) );
915 $wgOut->addHtml( wfInputLabel( wfMsg( 'prefs-watchlist-edits' ), 'wpWatchlistEdits', 'wpWatchlistEdits', 3, $this->mWatchlistEdits
) );
916 $wgOut->addHtml( '<br /><br />' );
918 $wgOut->addHtml( $this->getToggles( array( 'watchlisthideown', 'watchlisthidebots', 'watchlisthideminor' ) ) );
920 if( $wgUser->isAllowed( 'createpage' ) ||
$wgUser->isAllowed( 'createtalk' ) )
921 $wgOut->addHtml( $this->getToggle( 'watchcreations' ) );
922 foreach( array( 'edit' => 'watchdefault', 'move' => 'watchmoves', 'delete' => 'watchdeletion' ) as $action => $toggle ) {
923 if( $wgUser->isAllowed( $action ) )
924 $wgOut->addHtml( $this->getToggle( $toggle ) );
926 $this->mUsedToggles
['watchcreations'] = true;
927 $this->mUsedToggles
['watchdefault'] = true;
928 $this->mUsedToggles
['watchmoves'] = true;
929 $this->mUsedToggles
['watchdeletion'] = true;
931 $wgOut->addHtml( '</fieldset>' );
934 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'searchresultshead' ) . '</legend><table>' .
936 wfLabel( wfMsg( 'resultsperpage' ), 'wpSearch' ),
937 wfInput( 'wpSearch', 4, $this->mSearch
, array( 'id' => 'wpSearch' ) )
940 wfLabel( wfMsg( 'contextlines' ), 'wpSearchLines' ),
941 wfInput( 'wpSearchLines', 4, $this->mSearchLines
, array( 'id' => 'wpSearchLines' ) )
944 wfLabel( wfMsg( 'contextchars' ), 'wpSearchChars' ),
945 wfInput( 'wpSearchChars', 4, $this->mSearchChars
, array( 'id' => 'wpSearchChars' ) )
947 "</table><fieldset><legend>" . wfMsg( 'defaultns' ) . "</legend>$ps</fieldset></fieldset>" );
951 $wgOut->addHTML('<fieldset><legend>' . wfMsg('prefs-misc') . '</legend>');
952 $wgOut->addHTML( wfInputLabel( wfMsg( 'stubthreshold' ),
953 'wpStubs', 'wpStubs', 6, $this->mStubs
) );
954 $msgUnderline = htmlspecialchars( wfMsg ( 'tog-underline' ) );
955 $msgUnderlinenever = htmlspecialchars( wfMsg ( 'underline-never' ) );
956 $msgUnderlinealways = htmlspecialchars( wfMsg ( 'underline-always' ) );
957 $msgUnderlinedefault = htmlspecialchars( wfMsg ( 'underline-default' ) );
958 $uopt = $wgUser->getOption("underline");
959 $s0 = $uopt == 0 ?
' selected="selected"' : '';
960 $s1 = $uopt == 1 ?
' selected="selected"' : '';
961 $s2 = $uopt == 2 ?
' selected="selected"' : '';
963 <div class='toggle'><p><label for='wpOpunderline'>$msgUnderline</label>
964 <select name='wpOpunderline' id='wpOpunderline'>
965 <option value=\"0\"$s0>$msgUnderlinenever</option>
966 <option value=\"1\"$s1>$msgUnderlinealways</option>
967 <option value=\"2\"$s2>$msgUnderlinedefault</option>
968 </select></p></div>");
970 foreach ( $togs as $tname ) {
971 if( !array_key_exists( $tname, $this->mUsedToggles
) ) {
972 $wgOut->addHTML( $this->getToggle( $tname ) );
975 $wgOut->addHTML( '</fieldset>' );
977 $token = $wgUser->editToken();
978 $skin = $wgUser->getSkin();
980 <div id='prefsubmit'>
982 <input type='submit' name='wpSaveprefs' class='btnSavePrefs' value=\"" . wfMsgHtml( 'saveprefs' ) . '"'.$skin->tooltipAndAccesskey('save')." />
983 <input type='submit' name='wpReset' value=\"" . wfMsgHtml( 'resetprefs' ) . "\" />
988 <input type='hidden' name='wpEditToken' value='{$token}' />
991 $wgOut->addHtml( Xml
::tags( 'div', array( 'class' => "prefcache" ),
992 wfMsgExt( 'clearyourcache', 'parseinline' ) )