3 * Hold things related to displaying and saving user preferences.
9 * Entry point that create the "Preferences" object
11 function wfSpecialPreferences() {
14 $form = new PreferencesForm( $wgRequest );
19 * Preferences form handling
20 * This object will show the preferences form and can save it as well.
21 * @ingroup SpecialPage
23 class PreferencesForm
{
24 var $mQuickbar, $mOldpass, $mNewpass, $mRetypePass, $mStubs;
25 var $mRows, $mCols, $mSkin, $mMath, $mDate, $mUserEmail, $mEmailFlag, $mNick;
26 var $mUserLanguage, $mUserVariant;
27 var $mSearch, $mRecent, $mRecentDays, $mHourDiff, $mSearchLines, $mSearchChars, $mAction;
28 var $mReset, $mPosted, $mToggles, $mUseAjaxSearch, $mSearchNs, $mRealName, $mImageSize;
29 var $mUnderline, $mWatchlistEdits;
35 function PreferencesForm( &$request ) {
36 global $wgContLang, $wgUser, $wgAllowRealName;
38 $this->mQuickbar
= $request->getVal( 'wpQuickbar' );
39 $this->mOldpass
= $request->getVal( 'wpOldpass' );
40 $this->mNewpass
= $request->getVal( 'wpNewpass' );
41 $this->mRetypePass
=$request->getVal( 'wpRetypePass' );
42 $this->mStubs
= $request->getVal( 'wpStubs' );
43 $this->mRows
= $request->getVal( 'wpRows' );
44 $this->mCols
= $request->getVal( 'wpCols' );
45 $this->mSkin
= $request->getVal( 'wpSkin' );
46 $this->mMath
= $request->getVal( 'wpMath' );
47 $this->mDate
= $request->getVal( 'wpDate' );
48 $this->mUserEmail
= $request->getVal( 'wpUserEmail' );
49 $this->mRealName
= $wgAllowRealName ?
$request->getVal( 'wpRealName' ) : '';
50 $this->mEmailFlag
= $request->getCheck( 'wpEmailFlag' ) ?
0 : 1;
51 $this->mNick
= $request->getVal( 'wpNick' );
52 $this->mUserLanguage
= $request->getVal( 'wpUserLanguage' );
53 $this->mUserVariant
= $request->getVal( 'wpUserVariant' );
54 $this->mSearch
= $request->getVal( 'wpSearch' );
55 $this->mRecent
= $request->getVal( 'wpRecent' );
56 $this->mRecentDays
= $request->getVal( 'wpRecentDays' );
57 $this->mHourDiff
= $request->getVal( 'wpHourDiff' );
58 $this->mSearchLines
= $request->getVal( 'wpSearchLines' );
59 $this->mSearchChars
= $request->getVal( 'wpSearchChars' );
60 $this->mImageSize
= $request->getVal( 'wpImageSize' );
61 $this->mThumbSize
= $request->getInt( 'wpThumbSize' );
62 $this->mUnderline
= $request->getInt( 'wpOpunderline' );
63 $this->mAction
= $request->getVal( 'action' );
64 $this->mReset
= $request->getCheck( 'wpReset' );
65 $this->mPosted
= $request->wasPosted();
66 $this->mSuccess
= $request->getCheck( 'success' );
67 $this->mWatchlistDays
= $request->getVal( 'wpWatchlistDays' );
68 $this->mWatchlistEdits
= $request->getVal( 'wpWatchlistEdits' );
69 $this->mUseAjaxSearch
= $request->getCheck( 'wpUseAjaxSearch' );
70 $this->mDisableMWSuggest
= $request->getCheck( 'wpDisableMWSuggest' );
72 $this->mSaveprefs
= $request->getCheck( 'wpSaveprefs' ) &&
74 $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
76 # User toggles (the big ugly unsorted list of checkboxes)
77 $this->mToggles
= array();
78 if ( $this->mPosted
) {
79 $togs = User
::getToggles();
80 foreach ( $togs as $tname ) {
81 $this->mToggles
[$tname] = $request->getCheck( "wpOp$tname" ) ?
1 : 0;
85 $this->mUsedToggles
= array();
87 # Search namespace options
88 # Note: namespaces don't necessarily have consecutive keys
89 $this->mSearchNs
= array();
90 if ( $this->mPosted
) {
91 $namespaces = $wgContLang->getNamespaces();
92 foreach ( $namespaces as $i => $namespace ) {
94 $this->mSearchNs
[$i] = $request->getCheck( "wpNs$i" ) ?
1 : 0;
100 if ( !preg_match( '/^[a-z\-]*$/', $this->mUserLanguage
) ) {
101 $this->mUserLanguage
= 'nolanguage';
104 wfRunHooks( 'InitPreferencesForm', array( $this, $request ) );
108 global $wgUser, $wgOut;
110 if ( $wgUser->isAnon() ) {
111 $wgOut->showErrorPage( 'prefsnologin', 'prefsnologintext' );
114 if ( wfReadOnly() ) {
115 $wgOut->readOnlyPage();
118 if ( $this->mReset
) {
120 $this->mainPrefsForm( 'reset', wfMsg( 'prefsreset' ) );
121 } else if ( $this->mSaveprefs
) {
122 $this->savePreferences();
125 $this->mainPrefsForm( '' );
131 function validateInt( &$val, $min=0, $max=0x7fffffff ) {
133 $val = min($val, $max);
134 $val = max($val, $min);
141 function validateFloat( &$val, $min, $max=0x7fffffff ) {
142 $val = floatval( $val );
143 $val = min( $val, $max );
144 $val = max( $val, $min );
151 function validateIntOrNull( &$val, $min=0, $max=0x7fffffff ) {
156 return $this->validateInt( $val, $min, $max );
163 function validateDate( $val ) {
164 global $wgLang, $wgContLang;
165 if ( $val !== false && (
166 in_array( $val, (array)$wgLang->getDatePreferences() ) ||
167 in_array( $val, (array)$wgContLang->getDatePreferences() ) ) )
171 return $wgLang->getDefaultDateFormat();
176 * Used to validate the user inputed timezone before saving it as
177 * 'timecorrection', will return '00:00' if fed bogus data.
178 * Note: It's not a 100% correct implementation timezone-wise, it will
179 * accept stuff like '14:30',
181 * @param string $s the user input
184 function validateTimeZone( $s ) {
186 if ( strpos( $s, ':' ) ) {
188 $array = explode( ':' , $s );
189 $hour = intval( $array[0] );
190 $minute = intval( $array[1] );
192 $minute = intval( $s * 60 );
193 $hour = intval( $minute / 60 );
194 $minute = abs( $minute ) %
60;
196 # Max is +14:00 and min is -12:00, see:
197 # http://en.wikipedia.org/wiki/Timezone
198 $hour = min( $hour, 14 );
199 $hour = max( $hour, -12 );
200 $minute = min( $minute, 59 );
201 $minute = max( $minute, 0 );
202 $s = sprintf( "%02d:%02d", $hour, $minute );
210 function savePreferences() {
211 global $wgUser, $wgOut, $wgParser;
212 global $wgEnableUserEmail, $wgEnableEmail;
213 global $wgEmailAuthentication, $wgRCMaxAge;
214 global $wgAuth, $wgEmailConfirmToEdit;
217 if ( '' != $this->mNewpass
&& $wgAuth->allowPasswordChange() ) {
218 if ( $this->mNewpass
!= $this->mRetypePass
) {
219 wfRunHooks( 'PrefsPasswordAudit', array( $wgUser, $this->mNewpass
, 'badretype' ) );
220 $this->mainPrefsForm( 'error', wfMsg( 'badretype' ) );
224 if (!$wgUser->checkPassword( $this->mOldpass
)) {
225 wfRunHooks( 'PrefsPasswordAudit', array( $wgUser, $this->mNewpass
, 'wrongpassword' ) );
226 $this->mainPrefsForm( 'error', wfMsg( 'wrongpassword' ) );
231 $wgUser->setPassword( $this->mNewpass
);
232 wfRunHooks( 'PrefsPasswordAudit', array( $wgUser, $this->mNewpass
, 'success' ) );
233 $this->mNewpass
= $this->mOldpass
= $this->mRetypePass
= '';
234 } catch( PasswordError
$e ) {
235 wfRunHooks( 'PrefsPasswordAudit', array( $wgUser, $this->mNewpass
, 'error' ) );
236 $this->mainPrefsForm( 'error', $e->getMessage() );
240 $wgUser->setRealName( $this->mRealName
);
241 $oldOptions = $wgUser->mOptions
;
243 if( $wgUser->getOption( 'language' ) !== $this->mUserLanguage
) {
244 $needRedirect = true;
246 $needRedirect = false;
249 # Validate the signature and clean it up as needed
250 global $wgMaxSigChars;
251 if( mb_strlen( $this->mNick
) > $wgMaxSigChars ) {
253 $this->mainPrefsForm( 'error',
254 wfMsgExt( 'badsiglength', 'parsemag', $wgLang->formatNum( $wgMaxSigChars ) ) );
256 } elseif( $this->mToggles
['fancysig'] ) {
257 if( $wgParser->validateSig( $this->mNick
) !== false ) {
258 $this->mNick
= $wgParser->cleanSig( $this->mNick
);
260 $this->mainPrefsForm( 'error', wfMsg( 'badsig' ) );
264 // When no fancy sig used, make sure ~{3,5} get removed.
265 $this->mNick
= $wgParser->cleanSigInSig( $this->mNick
);
268 $wgUser->setOption( 'language', $this->mUserLanguage
);
269 $wgUser->setOption( 'variant', $this->mUserVariant
);
270 $wgUser->setOption( 'nickname', $this->mNick
);
271 $wgUser->setOption( 'quickbar', $this->mQuickbar
);
272 $wgUser->setOption( 'skin', $this->mSkin
);
275 $wgUser->setOption( 'math', $this->mMath
);
277 $wgUser->setOption( 'date', $this->validateDate( $this->mDate
) );
278 $wgUser->setOption( 'searchlimit', $this->validateIntOrNull( $this->mSearch
) );
279 $wgUser->setOption( 'contextlines', $this->validateIntOrNull( $this->mSearchLines
) );
280 $wgUser->setOption( 'contextchars', $this->validateIntOrNull( $this->mSearchChars
) );
281 $wgUser->setOption( 'rclimit', $this->validateIntOrNull( $this->mRecent
) );
282 $wgUser->setOption( 'rcdays', $this->validateInt($this->mRecentDays
, 1, ceil($wgRCMaxAge / (3600*24))));
283 $wgUser->setOption( 'wllimit', $this->validateIntOrNull( $this->mWatchlistEdits
, 0, 1000 ) );
284 $wgUser->setOption( 'rows', $this->validateInt( $this->mRows
, 4, 1000 ) );
285 $wgUser->setOption( 'cols', $this->validateInt( $this->mCols
, 4, 1000 ) );
286 $wgUser->setOption( 'stubthreshold', $this->validateIntOrNull( $this->mStubs
) );
287 $wgUser->setOption( 'timecorrection', $this->validateTimeZone( $this->mHourDiff
, -12, 14 ) );
288 $wgUser->setOption( 'imagesize', $this->mImageSize
);
289 $wgUser->setOption( 'thumbsize', $this->mThumbSize
);
290 $wgUser->setOption( 'underline', $this->validateInt($this->mUnderline
, 0, 2) );
291 $wgUser->setOption( 'watchlistdays', $this->validateFloat( $this->mWatchlistDays
, 0, 7 ) );
292 $wgUser->setOption( 'ajaxsearch', $this->mUseAjaxSearch
);
293 $wgUser->setOption( 'disablesuggest', $this->mDisableMWSuggest
);
295 # Set search namespace options
296 foreach( $this->mSearchNs
as $i => $value ) {
297 $wgUser->setOption( "searchNs{$i}", $value );
300 if( $wgEnableEmail && $wgEnableUserEmail ) {
301 $wgUser->setOption( 'disablemail', $this->mEmailFlag
);
305 foreach ( $this->mToggles
as $tname => $tvalue ) {
306 $wgUser->setOption( $tname, $tvalue );
310 if( $wgEnableEmail ) {
311 $newadr = $this->mUserEmail
;
312 $oldadr = $wgUser->getEmail();
313 if( ($newadr != '') && ($newadr != $oldadr) ) {
314 # the user has supplied a new email address on the login page
315 if( $wgUser->isValidEmailAddr( $newadr ) ) {
316 # new behaviour: set this new emailaddr from login-page into user database record
317 $wgUser->setEmail( $newadr );
318 # but flag as "dirty" = unauthenticated
319 $wgUser->invalidateEmail();
320 if ($wgEmailAuthentication) {
321 # Mail a temporary password to the dirty address.
322 # User can come back through the confirmation URL to re-enable email.
323 $result = $wgUser->sendConfirmationMail();
324 if( WikiError
::isError( $result ) ) {
325 $error = wfMsg( 'mailerror', htmlspecialchars( $result->getMessage() ) );
327 $error = wfMsg( 'eauthentsent', $wgUser->getName() );
331 $error = wfMsg( 'invalidemailaddress' );
334 if( $wgEmailConfirmToEdit && empty( $newadr ) ) {
335 $this->mainPrefsForm( 'error', wfMsg( 'noemailtitle' ) );
338 $wgUser->setEmail( $this->mUserEmail
);
340 if( $oldadr != $newadr ) {
341 wfRunHooks( 'PrefsEmailAudit', array( $wgUser, $oldadr, $newadr ) );
345 if( !$wgAuth->updateExternalDB( $wgUser ) ){
346 $this->mainPrefsForm( 'error', wfMsg( 'externaldberror' ) );
351 if ( !wfRunHooks( 'SavePreferences', array( $this, $wgUser, &$msg, $oldOptions ) ) ) {
352 $this->mainPrefsForm( 'error', $msg );
356 $wgUser->setCookies();
357 $wgUser->saveSettings();
359 if( $needRedirect && $error === false ) {
360 $title = SpecialPage
::getTitleFor( 'Preferences' );
361 $wgOut->redirect( $title->getFullURL( 'success' ) );
365 $wgOut->parserOptions( ParserOptions
::newFromUser( $wgUser ) );
366 $this->mainPrefsForm( $error === false ?
'success' : 'error', $error);
372 function resetPrefs() {
373 global $wgUser, $wgLang, $wgContLang, $wgContLanguageCode, $wgAllowRealName;
375 $this->mOldpass
= $this->mNewpass
= $this->mRetypePass
= '';
376 $this->mUserEmail
= $wgUser->getEmail();
377 $this->mUserEmailAuthenticationtimestamp
= $wgUser->getEmailAuthenticationtimestamp();
378 $this->mRealName
= ($wgAllowRealName) ?
$wgUser->getRealName() : '';
380 # language value might be blank, default to content language
381 $this->mUserLanguage
= $wgUser->getOption( 'language', $wgContLanguageCode );
383 $this->mUserVariant
= $wgUser->getOption( 'variant');
384 $this->mEmailFlag
= $wgUser->getOption( 'disablemail' ) == 1 ?
1 : 0;
385 $this->mNick
= $wgUser->getOption( 'nickname' );
387 $this->mQuickbar
= $wgUser->getOption( 'quickbar' );
388 $this->mSkin
= Skin
::normalizeKey( $wgUser->getOption( 'skin' ) );
389 $this->mMath
= $wgUser->getOption( 'math' );
390 $this->mDate
= $wgUser->getDatePreference();
391 $this->mRows
= $wgUser->getOption( 'rows' );
392 $this->mCols
= $wgUser->getOption( 'cols' );
393 $this->mStubs
= $wgUser->getOption( 'stubthreshold' );
394 $this->mHourDiff
= $wgUser->getOption( 'timecorrection' );
395 $this->mSearch
= $wgUser->getOption( 'searchlimit' );
396 $this->mSearchLines
= $wgUser->getOption( 'contextlines' );
397 $this->mSearchChars
= $wgUser->getOption( 'contextchars' );
398 $this->mImageSize
= $wgUser->getOption( 'imagesize' );
399 $this->mThumbSize
= $wgUser->getOption( 'thumbsize' );
400 $this->mRecent
= $wgUser->getOption( 'rclimit' );
401 $this->mRecentDays
= $wgUser->getOption( 'rcdays' );
402 $this->mWatchlistEdits
= $wgUser->getOption( 'wllimit' );
403 $this->mUnderline
= $wgUser->getOption( 'underline' );
404 $this->mWatchlistDays
= $wgUser->getOption( 'watchlistdays' );
405 $this->mUseAjaxSearch
= $wgUser->getBoolOption( 'ajaxsearch' );
406 $this->mDisableMWSuggest
= $wgUser->getBoolOption( 'disablesuggest' );
408 $togs = User
::getToggles();
409 foreach ( $togs as $tname ) {
410 $this->mToggles
[$tname] = $wgUser->getOption( $tname );
413 $namespaces = $wgContLang->getNamespaces();
414 foreach ( $namespaces as $i => $namespace ) {
415 if ( $i >= NS_MAIN
) {
416 $this->mSearchNs
[$i] = $wgUser->getOption( 'searchNs'.$i );
420 wfRunHooks( 'ResetPreferences', array( $this, $wgUser ) );
426 function namespacesCheckboxes() {
429 # Determine namespace checkboxes
430 $namespaces = $wgContLang->getNamespaces();
433 foreach ( $namespaces as $i => $name ) {
436 $checked = $this->mSearchNs
[$i] ?
"checked='checked'" : '';
437 $name = str_replace( '_', ' ', $namespaces[$i] );
440 $name = wfMsg( 'blanknamespace' );
442 $r1 .= "<input type='checkbox' value='1' name='wpNs$i' id='wpNs$i' {$checked}/> <label for='wpNs$i'>{$name}</label><br />\n";
448 function getToggle( $tname, $trailer = false, $disabled = false ) {
449 global $wgUser, $wgLang;
451 $this->mUsedToggles
[$tname] = true;
452 $ttext = $wgLang->getUserToggle( $tname );
454 $checked = $wgUser->getOption( $tname ) == 1 ?
' checked="checked"' : '';
455 $disabled = $disabled ?
' disabled="disabled"' : '';
456 $trailer = $trailer ?
$trailer : '';
457 return "<div class='toggle'><input type='checkbox' value='1' id=\"$tname\" name=\"wpOp$tname\"$checked$disabled />" .
458 " <span class='toggletext'><label for=\"$tname\">$ttext</label>$trailer</span></div>\n";
461 function getToggles( $items ) {
463 foreach( $items as $item ) {
464 if( $item === false )
466 if( is_array( $item ) ) {
467 list( $key, $trailer ) = $item;
472 $out .= $this->getToggle( $key, $trailer );
477 function addRow($td1, $td2) {
478 return "<tr><td class='mw-label'>$td1</td><td class='mw-input'>$td2</td></tr>";
482 * Helper function for user information panel
483 * @param $td1 label for an item
484 * @param $td2 item or null
485 * @param $td3 optional help or null
486 * @return xhtml block
488 function tableRow( $td1, $td2 = null, $td3 = null ) {
490 if ( is_null( $td3 ) ) {
493 $td3 = Xml
::tags( 'tr', null,
494 Xml
::tags( 'td', array( 'class' => 'pref-label', 'colspan' => '2' ), $td3 )
498 if ( is_null( $td2 ) ) {
499 $td1 = Xml
::tags( 'td', array( 'class' => 'pref-label', 'colspan' => '2' ), $td1 );
502 $td1 = Xml
::tags( 'td', array( 'class' => 'pref-label' ), $td1 );
503 $td2 = Xml
::tags( 'td', array( 'class' => 'pref-input' ), $td2 );
506 return Xml
::tags( 'tr', null, $td1 . $td2 ). $td3 . "\n";
513 function mainPrefsForm( $status , $message = '' ) {
514 global $wgUser, $wgOut, $wgLang, $wgContLang;
515 global $wgAllowRealName, $wgImageLimits, $wgThumbLimits;
516 global $wgDisableLangConversion, $wgDisableTitleConversion;
517 global $wgEnotifWatchlist, $wgEnotifUserTalk,$wgEnotifMinorEdits;
518 global $wgRCShowWatchingUsers, $wgEnotifRevealEditorAddress;
519 global $wgEnableEmail, $wgEnableUserEmail, $wgEmailAuthentication;
520 global $wgContLanguageCode, $wgDefaultSkin, $wgAuth;
521 global $wgEmailConfirmToEdit, $wgAjaxSearch, $wgEnableMWSuggest;
523 $wgOut->setPageTitle( wfMsg( 'preferences' ) );
524 $wgOut->setArticleRelated( false );
525 $wgOut->setRobotPolicy( 'noindex,nofollow' );
526 $wgOut->addScriptFile( 'prefs.js' );
528 $wgOut->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc.
530 if ( $this->mSuccess ||
'success' == $status ) {
531 $wgOut->wrapWikiMsg( '<div class="successbox"><strong>$1</strong></div>', 'savedprefs' );
532 } else if ( 'error' == $status ) {
533 $wgOut->addWikiText( '<div class="errorbox"><strong>' . $message . '</strong></div>' );
534 } else if ( '' != $status ) {
535 $wgOut->addWikiText( $message . "\n----" );
538 $qbs = $wgLang->getQuickbarSettings();
539 $skinNames = $wgLang->getSkinNames();
540 $mathopts = $wgLang->getMathNames();
541 $dateopts = $wgLang->getDatePreferences();
542 $togs = User
::getToggles();
544 $titleObj = SpecialPage
::getTitleFor( 'Preferences' );
546 # Pre-expire some toggles so they won't show if disabled
547 $this->mUsedToggles
[ 'shownumberswatching' ] = true;
548 $this->mUsedToggles
[ 'showupdated' ] = true;
549 $this->mUsedToggles
[ 'enotifwatchlistpages' ] = true;
550 $this->mUsedToggles
[ 'enotifusertalkpages' ] = true;
551 $this->mUsedToggles
[ 'enotifminoredits' ] = true;
552 $this->mUsedToggles
[ 'enotifrevealaddr' ] = true;
553 $this->mUsedToggles
[ 'ccmeonemails' ] = true;
554 $this->mUsedToggles
[ 'uselivepreview' ] = true;
555 $this->mUsedToggles
[ 'noconvertlink' ] = true;
558 if ( !$this->mEmailFlag
) { $emfc = 'checked="checked"'; }
562 if ($wgEmailAuthentication && ($this->mUserEmail
!= '') ) {
563 if( $wgUser->getEmailAuthenticationTimestamp() ) {
564 $emailauthenticated = wfMsg('emailauthenticated',$wgLang->timeanddate($wgUser->getEmailAuthenticationTimestamp(), true ) ).'<br />';
565 $disableEmailPrefs = false;
567 $disableEmailPrefs = true;
568 $skin = $wgUser->getSkin();
569 $emailauthenticated = wfMsg('emailnotauthenticated').'<br />' .
570 $skin->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Confirmemail' ),
571 wfMsg( 'emailconfirmlink' ) ) . '<br />';
574 $emailauthenticated = '';
575 $disableEmailPrefs = false;
578 if ($this->mUserEmail
== '') {
579 $emailauthenticated = wfMsg( 'noemailprefs' ) . '<br />';
582 $ps = $this->namespacesCheckboxes();
584 $enotifwatchlistpages = ($wgEnotifWatchlist) ?
$this->getToggle( 'enotifwatchlistpages', false, $disableEmailPrefs ) : '';
585 $enotifusertalkpages = ($wgEnotifUserTalk) ?
$this->getToggle( 'enotifusertalkpages', false, $disableEmailPrefs ) : '';
586 $enotifminoredits = ($wgEnotifWatchlist && $wgEnotifMinorEdits) ?
$this->getToggle( 'enotifminoredits', false, $disableEmailPrefs ) : '';
587 $enotifrevealaddr = (($wgEnotifWatchlist ||
$wgEnotifUserTalk) && $wgEnotifRevealEditorAddress) ?
$this->getToggle( 'enotifrevealaddr', false, $disableEmailPrefs ) : '';
592 Xml
::openElement( 'form', array(
593 'action' => $titleObj->getLocalUrl(),
595 'id' => 'mw-preferences-form',
597 Xml
::openElement( 'div', array( 'id' => 'preferences' ) )
603 Xml
::fieldset( wfMsg('prefs-personal') ) .
604 Xml
::openElement( 'table' ) .
605 $this->tableRow( Xml
::element( 'h2', null, wfMsg( 'prefs-personal' ) ) )
608 # Get groups to which the user belongs
609 $userEffectiveGroups = $wgUser->getEffectiveGroups();
610 $userEffectiveGroupsArray = array();
611 foreach( $userEffectiveGroups as $ueg ) {
613 // Skip the default * group, seems useless here
616 $userEffectiveGroupsArray[] = User
::makeGroupLinkHTML( $ueg );
618 asort( $userEffectiveGroupsArray );
620 $sk = $wgUser->getSkin();
621 $toolLinks = array();
622 $toolLinks[] = $sk->makeKnownLinkObj( SpecialPage
::getTitleFor( 'ListGroupRights' ), wfMsg( 'listgrouprights' ) );
623 # At the moment one tool link only but be prepared for the future...
624 # FIXME: Add a link to Special:Userrights for users who are allowed to use it.
625 # $wgUser->isAllowed( 'userrights' ) seems to strict in some cases
627 $userInformationHtml =
628 $this->tableRow( wfMsgHtml( 'username' ), htmlspecialchars( $wgUser->getName() ) ) .
629 $this->tableRow( wfMsgHtml( 'uid' ), $wgLang->formatNum( htmlspecialchars( $wgUser->getId() ) ) ).
632 wfMsgExt( 'prefs-memberingroups', array( 'parseinline' ), count( $userEffectiveGroupsArray ) ),
633 implode( wfMsg( 'comma-separator' ), $userEffectiveGroupsArray ) .
634 '<br />(' . implode( ' | ', $toolLinks ) . ')'
638 wfMsgHtml( 'prefs-edits' ),
639 $wgLang->formatNum( $wgUser->getEditCount() )
642 if( wfRunHooks( 'PreferencesUserInformationPanel', array( $this, &$userInformationHtml ) ) ) {
643 $wgOut->addHtml( $userInformationHtml );
646 if ( $wgAllowRealName ) {
649 Xml
::label( wfMsg('yourrealname'), 'wpRealName' ),
650 Xml
::input( 'wpRealName', 25, $this->mRealName
, array( 'id' => 'wpRealName' ) ),
651 Xml
::tags('div', array( 'class' => 'prefsectiontip' ),
652 wfMsgExt( 'prefs-help-realname', 'parseinline' )
657 if ( $wgEnableEmail ) {
660 Xml
::label( wfMsg('youremail'), 'wpUserEmail' ),
661 Xml
::input( 'wpUserEmail', 25, $this->mUserEmail
, array( 'id' => 'wpUserEmail' ) ),
662 Xml
::tags('div', array( 'class' => 'prefsectiontip' ),
663 wfMsgExt( $wgEmailConfirmToEdit ?
'prefs-help-email-required' : 'prefs-help-email', 'parseinline' )
669 global $wgParser, $wgMaxSigChars;
670 if( mb_strlen( $this->mNick
) > $wgMaxSigChars ) {
671 $invalidSig = $this->tableRow(
673 Xml
::element( 'span', array( 'class' => 'error' ),
674 wfMsgExt( 'badsiglength', 'parsemag', $wgLang->formatNum( $wgMaxSigChars ) ) )
676 } elseif( !empty( $this->mToggles
['fancysig'] ) &&
677 false === $wgParser->validateSig( $this->mNick
) ) {
678 $invalidSig = $this->tableRow(
680 Xml
::element( 'span', array( 'class' => 'error' ), wfMsg( 'badsig' ) )
688 Xml
::label( wfMsg( 'yournick' ), 'wpNick' ),
689 Xml
::input( 'wpNick', 25, $this->mNick
,
692 // Note: $wgMaxSigChars is enforced in Unicode characters,
693 // both on the backend and now in the browser.
694 // Badly-behaved requests may still try to submit
695 // an overlong string, however.
696 'maxlength' => $wgMaxSigChars ) )
699 $this->tableRow( ' ', $this->getToggle( 'fancysig' ) )
702 list( $lsLabel, $lsSelect) = Xml
::languageSelector( $this->mUserLanguage
);
704 $this->tableRow( $lsLabel, $lsSelect )
707 /* see if there are multiple language variants to choose from*/
708 if(!$wgDisableLangConversion) {
709 $variants = $wgContLang->getVariants();
710 $variantArray = array();
712 $languages = Language
::getLanguageNames( true );
713 foreach($variants as $v) {
714 $v = str_replace( '_', '-', strtolower($v));
715 if( array_key_exists( $v, $languages ) ) {
716 // If it doesn't have a name, we'll pretend it doesn't exist
717 $variantArray[$v] = $languages[$v];
722 foreach( $variantArray as $code => $name ) {
723 $selected = ($code == $this->mUserVariant
);
724 $options .= Xml
::option( "$code - $name", $code, $selected ) . "\n";
727 if(count($variantArray) > 1) {
730 Xml
::label( wfMsg( 'yourvariant' ), 'wpUserVariant' ),
732 array( 'name' => 'wpUserVariant', 'id' => 'wpUserVariant' ),
739 if(count($variantArray) > 1 && !$wgDisableLangConversion && !$wgDisableTitleConversion) {
741 Xml
::tags( 'tr', null,
742 Xml
::tags( 'td', array( 'colspan' => '2' ),
743 $this->getToggle( "noconvertlink" )
751 if( $wgAuth->allowPasswordChange() ) {
753 $this->tableRow( Xml
::element( 'h2', null, wfMsg( 'changepassword' ) ) ) .
755 Xml
::label( wfMsg( 'oldpassword' ), 'wpOldpass' ),
756 Xml
::password( 'wpOldpass', 25, $this->mOldpass
, array( 'id' => 'wpOldpass' ) )
759 Xml
::label( wfMsg( 'newpassword' ), 'wpNewpass' ),
760 Xml
::password( 'wpNewpass', 25, $this->mNewpass
, array( 'id' => 'wpNewpass' ) )
763 Xml
::label( wfMsg( 'retypenew' ), 'wpRetypePass' ),
764 Xml
::password( 'wpRetypePass', 25, $this->mRetypePass
, array( 'id' => 'wpRetypePass' ) )
766 Xml
::tags( 'tr', null,
767 Xml
::tags( 'td', array( 'colspan' => '2' ),
768 $this->getToggle( "rememberpassword" )
776 if ( $wgEnableEmail ) {
779 if ($wgEnableUserEmail) {
780 // fixme -- the "allowemail" pseudotoggle is a hacked-together
781 // inversion for the "disableemail" preference.
782 $emf = wfMsg( 'allowemail' );
783 $disabled = $disableEmailPrefs ?
' disabled="disabled"' : '';
785 "<input type='checkbox' $emfc $disabled value='1' name='wpEmailFlag' id='wpEmailFlag' /> <label for='wpEmailFlag'>$emf</label>" .
786 $this->getToggle( 'ccmeonemails', '', $disableEmailPrefs );
791 $this->tableRow( Xml
::element( 'h2', null, wfMsg( 'email' ) ) ) .
795 $enotifwatchlistpages.
796 $enotifusertalkpages.
805 Xml
::closeElement( 'table' ) .
806 Xml
::closeElement( 'fieldset' )
812 if ($this->mSkin
== 'cologneblue' ||
$this->mSkin
== 'standard') {
813 $wgOut->addHtml( "<fieldset>\n<legend>" . wfMsg( 'qbsettings' ) . "</legend>\n" );
814 for ( $i = 0; $i < count( $qbs ); ++
$i ) {
815 if ( $i == $this->mQuickbar
) { $checked = ' checked="checked"'; }
816 else { $checked = ""; }
817 $wgOut->addHTML( "<div><label><input type='radio' name='wpQuickbar' value=\"$i\"$checked />{$qbs[$i]}</label></div>\n" );
819 $wgOut->addHtml( "</fieldset>\n\n" );
821 # Need to output a hidden option even if the relevant skin is not in use,
822 # otherwise the preference will get reset to 0 on submit
823 $wgOut->addHtml( wfHidden( 'wpQuickbar', $this->mQuickbar
) );
828 $wgOut->addHTML( "<fieldset>\n<legend>\n" . wfMsg('skin') . "</legend>\n" );
829 $mptitle = Title
::newMainPage();
830 $previewtext = wfMsg('skin-preview');
831 # Only show members of Skin::getSkinNames() rather than
832 # $skinNames (skins is all skin names from Language.php)
833 $validSkinNames = Skin
::getUsableSkins();
834 # Sort by UI skin name. First though need to update validSkinNames as sometimes
835 # the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI).
836 foreach ($validSkinNames as $skinkey => & $skinname ) {
837 if ( isset( $skinNames[$skinkey] ) ) {
838 $skinname = $skinNames[$skinkey];
841 asort($validSkinNames);
842 foreach ($validSkinNames as $skinkey => $sn ) {
843 $checked = $skinkey == $this->mSkin ?
' checked="checked"' : '';
845 $mplink = htmlspecialchars($mptitle->getLocalURL("useskin=$skinkey"));
846 $previewlink = "(<a target='_blank' href=\"$mplink\">$previewtext</a>)";
847 if( $skinkey == $wgDefaultSkin )
848 $sn .= ' (' . wfMsg( 'default' ) . ')';
849 $wgOut->addHTML( "<input type='radio' name='wpSkin' id=\"wpSkin$skinkey\" value=\"$skinkey\"$checked /> <label for=\"wpSkin$skinkey\">{$sn}</label> $previewlink<br />\n" );
851 $wgOut->addHTML( "</fieldset>\n\n" );
857 $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg('math') . '</legend>' );
858 foreach ( $mathopts as $k => $v ) {
859 $checked = ($k == $this->mMath
);
861 Xml
::openElement( 'div' ) .
862 Xml
::radioLabel( wfMsg( $v ), 'wpMath', $k, "mw-sp-math-$k", $checked ) .
863 Xml
::closeElement( 'div' ) . "\n"
866 $wgOut->addHTML( "</fieldset>\n\n" );
872 "<fieldset>\n" . Xml
::element( 'legend', null, wfMsg( 'files' ) ) . "\n"
875 $imageLimitOptions = null;
876 foreach ( $wgImageLimits as $index => $limits ) {
877 $selected = ($index == $this->mImageSize
);
878 $imageLimitOptions .= Xml
::option( "{$limits[0]}×{$limits[1]}" .
879 wfMsg('unit-pixel'), $index, $selected );
882 $imageSizeId = 'wpImageSize';
884 "<div>" . Xml
::label( wfMsg('imagemaxsize'), $imageSizeId ) . " " .
885 Xml
::openElement( 'select', array( 'name' => $imageSizeId, 'id' => $imageSizeId ) ) .
887 Xml
::closeElement( 'select' ) . "</div>\n"
890 $imageThumbOptions = null;
891 foreach ( $wgThumbLimits as $index => $size ) {
892 $selected = ($index == $this->mThumbSize
);
893 $imageThumbOptions .= Xml
::option($size . wfMsg('unit-pixel'), $index,
897 $thumbSizeId = 'wpThumbSize';
899 "<div>" . Xml
::label( wfMsg('thumbsize'), $thumbSizeId ) . " " .
900 Xml
::openElement( 'select', array( 'name' => $thumbSizeId, 'id' => $thumbSizeId ) ) .
902 Xml
::closeElement( 'select' ) . "</div>\n"
905 $wgOut->addHTML( "</fieldset>\n\n" );
913 Xml
::openElement( 'fieldset' ) .
914 Xml
::element( 'legend', null, wfMsg( 'datetime' ) ) . "\n"
919 Xml
::openElement( 'fieldset' ) .
920 Xml
::element( 'legend', null, wfMsg( 'dateformat' ) ) . "\n"
923 $epoch = '20010115161234'; # Wikipedia day
924 foreach( $dateopts as $key ) {
925 if( $key == 'default' ) {
926 $formatted = wfMsg( 'datedefault' );
928 $formatted = $wgLang->timeanddate( $epoch, false, $key );
931 Xml
::tags( 'div', null,
932 Xml
::radioLabel( $formatted, 'wpDate', $key, "wpDate$idCnt", $key == $this->mDate
)
937 $wgOut->addHTML( Xml
::closeElement( 'fieldset' ) . "\n" );
940 $nowlocal = $wgLang->time( $now = wfTimestampNow(), true );
941 $nowserver = $wgLang->time( $now, false );
944 Xml
::openElement( 'fieldset' ) .
945 Xml
::element( 'legend', null, wfMsg( 'timezonelegend' ) ) .
946 Xml
::openElement( 'table' ) .
947 $this->addRow( wfMsg( 'servertime' ), $nowserver ) .
948 $this->addRow( wfMsg( 'localtime' ), $nowlocal ) .
950 Xml
::label( wfMsg( 'timezoneoffset' ), 'wpHourDiff' ),
951 Xml
::input( 'wpHourDiff', 6, $this->mHourDiff
, array( 'id' => 'wpHourDiff' ) ) ) .
954 <td class='mw-submit'>" .
955 Xml
::element( 'input',
956 array( 'type' => 'button',
957 'value' => wfMsg( 'guesstimezone' ),
958 'onclick' => 'javascript:guessTimezone()',
959 'id' => 'guesstimezonebutton',
960 'style' => 'display:none;' ) ) .
963 Xml
::closeElement( 'table' ) .
964 Xml
::tags( 'div', array( 'class' => 'prefsectiontip' ), wfMsgExt( 'timezonetext', 'parseinline' ) ).
965 Xml
::closeElement( 'fieldset' ) .
966 Xml
::closeElement( 'fieldset' ) . "\n\n"
971 global $wgLivePreview;
972 $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'textboxsize' ) . '</legend>
974 wfInputLabel( wfMsg( 'rows' ), 'wpRows', 'wpRows', 3, $this->mRows
) .
976 wfInputLabel( wfMsg( 'columns' ), 'wpCols', 'wpCols', 3, $this->mCols
) .
978 $this->getToggles( array(
980 'editsectiononrightclick',
989 $wgLivePreview ?
'uselivepreview' : false,
995 $wgOut->addHtml( '<fieldset><legend>' . wfMsgHtml( 'prefs-rc' ) . '</legend>' );
998 $rc .= '<td>' . Xml
::label( wfMsg( 'recentchangesdays' ), 'wpRecentDays' ) . '</td>';
999 $rc .= '<td>' . Xml
::input( 'wpRecentDays', 3, $this->mRecentDays
, array( 'id' => 'wpRecentDays' ) ) . '</td>';
1001 $rc .= '<td>' . Xml
::label( wfMsg( 'recentchangescount' ), 'wpRecent' ) . '</td>';
1002 $rc .= '<td>' . Xml
::input( 'wpRecent', 3, $this->mRecent
, array( 'id' => 'wpRecent' ) ) . '</td>';
1003 $rc .= '</tr></table>';
1004 $wgOut->addHtml( $rc );
1006 $wgOut->addHtml( '<br />' );
1008 $toggles[] = 'hideminor';
1009 if( $wgRCShowWatchingUsers )
1010 $toggles[] = 'shownumberswatching';
1011 $toggles[] = 'usenewrc';
1012 $wgOut->addHtml( $this->getToggles( $toggles ) );
1014 $wgOut->addHtml( '</fieldset>' );
1017 $wgOut->addHtml( '<fieldset><legend>' . wfMsgHtml( 'prefs-watchlist' ) . '</legend>' );
1019 $wgOut->addHtml( wfInputLabel( wfMsg( 'prefs-watchlist-days' ), 'wpWatchlistDays', 'wpWatchlistDays', 3, $this->mWatchlistDays
) );
1020 $wgOut->addHtml( '<br /><br />' );
1022 $wgOut->addHtml( $this->getToggle( 'extendwatchlist' ) );
1023 $wgOut->addHtml( wfInputLabel( wfMsg( 'prefs-watchlist-edits' ), 'wpWatchlistEdits', 'wpWatchlistEdits', 3, $this->mWatchlistEdits
) );
1024 $wgOut->addHtml( '<br /><br />' );
1026 $wgOut->addHtml( $this->getToggles( array( 'watchlisthideminor', 'watchlisthidebots', 'watchlisthideown', 'watchlisthideanons', 'watchlisthideliu' ) ) );
1028 if( $wgUser->isAllowed( 'createpage' ) ||
$wgUser->isAllowed( 'createtalk' ) )
1029 $wgOut->addHtml( $this->getToggle( 'watchcreations' ) );
1030 foreach( array( 'edit' => 'watchdefault', 'move' => 'watchmoves', 'delete' => 'watchdeletion' ) as $action => $toggle ) {
1031 if( $wgUser->isAllowed( $action ) )
1032 $wgOut->addHtml( $this->getToggle( $toggle ) );
1034 $this->mUsedToggles
['watchcreations'] = true;
1035 $this->mUsedToggles
['watchdefault'] = true;
1036 $this->mUsedToggles
['watchmoves'] = true;
1037 $this->mUsedToggles
['watchdeletion'] = true;
1039 $wgOut->addHtml( '</fieldset>' );
1042 $ajaxsearch = $wgAjaxSearch ?
1044 Xml
::label( wfMsg( 'useajaxsearch' ), 'wpUseAjaxSearch' ),
1045 Xml
::check( 'wpUseAjaxSearch', $this->mUseAjaxSearch
, array( 'id' => 'wpUseAjaxSearch' ) )
1047 $mwsuggest = $wgEnableMWSuggest ?
1049 Xml
::label( wfMsg( 'mwsuggest-disable' ), 'wpDisableMWSuggest' ),
1050 Xml
::check( 'wpDisableMWSuggest', $this->mDisableMWSuggest
, array( 'id' => 'wpDisableMWSuggest' ) )
1053 // Elements for the search tab itself
1054 Xml
::openElement( 'fieldset' ) .
1055 Xml
::element( 'legend', null, wfMsg( 'searchresultshead' ) ) .
1056 // Elements for the search options in the search tab
1057 Xml
::openElement( 'fieldset' ) .
1058 Xml
::element( 'legend', null, wfMsg( 'prefs-searchoptions' ) ) .
1059 Xml
::openElement( 'table' ) .
1062 Xml
::label( wfMsg( 'resultsperpage' ), 'wpSearch' ),
1063 Xml
::input( 'wpSearch', 4, $this->mSearch
, array( 'id' => 'wpSearch' ) )
1066 Xml
::label( wfMsg( 'contextlines' ), 'wpSearchLines' ),
1067 Xml
::input( 'wpSearchLines', 4, $this->mSearchLines
, array( 'id' => 'wpSearchLines' ) )
1070 Xml
::label( wfMsg( 'contextchars' ), 'wpSearchChars' ),
1071 Xml
::input( 'wpSearchChars', 4, $this->mSearchChars
, array( 'id' => 'wpSearchChars' ) )
1074 Xml
::closeElement( 'table' ) .
1075 Xml
::closeElement( 'fieldset' ) .
1076 // Elements for the namespace options in the search tab
1077 Xml
::openElement( 'fieldset' ) .
1078 Xml
::element( 'legend', null, wfMsg( 'prefs-namespaces' ) ) .
1079 wfMsgExt( 'defaultns', array( 'parse' ) ) .
1081 Xml
::closeElement( 'fieldset' ) .
1082 // End of the search tab
1083 Xml
::closeElement( 'fieldset' )
1088 $wgOut->addHTML('<fieldset><legend>' . wfMsg('prefs-misc') . '</legend>');
1089 $wgOut->addHtml( '<label for="wpStubs">' . wfMsg( 'stub-threshold' ) . '</label> ' );
1090 $wgOut->addHtml( Xml
::input( 'wpStubs', 6, $this->mStubs
, array( 'id' => 'wpStubs' ) ) );
1091 $msgUnderline = htmlspecialchars( wfMsg ( 'tog-underline' ) );
1092 $msgUnderlinenever = htmlspecialchars( wfMsg ( 'underline-never' ) );
1093 $msgUnderlinealways = htmlspecialchars( wfMsg ( 'underline-always' ) );
1094 $msgUnderlinedefault = htmlspecialchars( wfMsg ( 'underline-default' ) );
1095 $uopt = $wgUser->getOption("underline");
1096 $s0 = $uopt == 0 ?
' selected="selected"' : '';
1097 $s1 = $uopt == 1 ?
' selected="selected"' : '';
1098 $s2 = $uopt == 2 ?
' selected="selected"' : '';
1100 <div class='toggle'><p><label for='wpOpunderline'>$msgUnderline</label>
1101 <select name='wpOpunderline' id='wpOpunderline'>
1102 <option value=\"0\"$s0>$msgUnderlinenever</option>
1103 <option value=\"1\"$s1>$msgUnderlinealways</option>
1104 <option value=\"2\"$s2>$msgUnderlinedefault</option>
1105 </select></p></div>");
1107 foreach ( $togs as $tname ) {
1108 if( !array_key_exists( $tname, $this->mUsedToggles
) ) {
1109 $wgOut->addHTML( $this->getToggle( $tname ) );
1112 $wgOut->addHTML( '</fieldset>' );
1114 wfRunHooks( 'RenderPreferencesForm', array( $this, $wgOut ) );
1116 $token = htmlspecialchars( $wgUser->editToken() );
1117 $skin = $wgUser->getSkin();
1119 <div id='prefsubmit'>
1121 <input type='submit' name='wpSaveprefs' class='btnSavePrefs' value=\"" . wfMsgHtml( 'saveprefs' ) . '"'.$skin->tooltipAndAccesskey('save')." />
1122 <input type='submit' name='wpReset' value=\"" . wfMsgHtml( 'resetprefs' ) . "\" />
1127 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1130 $wgOut->addHtml( Xml
::tags( 'div', array( 'class' => "prefcache" ),
1131 wfMsgExt( 'clearyourcache', 'parseinline' ) )