4 * We're now using the HTMLForm object with some customisation to generate the
5 * Preferences form. This object handles generic submission, CSRF protection,
6 * layout and other logic in a reusable manner. We subclass it as a PreferencesForm
7 * to make some minor customisations.
9 * In order to generate the form, the HTMLForm object needs an array structure
10 * detailing the form fields available, and that's what this class is for. Each
11 * element of the array is a basic property-list, including the type of field,
12 * the label it is to be given in the form, callbacks for validation and
13 * 'filtering', and other pertinent information. Note that the 'default' field
14 * is named for generic forms, and does not represent the preference's default
15 * (which is stored in $wgDefaultUserOptions), but the default for the form
16 * field, which should be whatever the user has set for that preference. There
17 * is no need to override it unless you have some special storage logic (for
18 * instance, those not presently stored as options, but which are best set from
19 * the user preferences view).
21 * Field types are implemented as subclasses of the generic HTMLFormField
22 * object, and typically implement at least getInputHTML, which generates the
23 * HTML for the input field to be placed in the table.
25 * Once fields have been retrieved and validated, submission logic is handed
26 * over to the tryUISubmit static method of this class.
29 static $defaultPreferences = null;
32 'timecorrection' => array( 'Preferences', 'filterTimezoneInput' ),
35 static function getPreferences( $user ) {
36 if ( self
::$defaultPreferences )
37 return self
::$defaultPreferences;
41 $defaultPreferences = array();
43 self
::profilePreferences( $user, $defaultPreferences );
44 self
::skinPreferences( $user, $defaultPreferences );
45 self
::filesPreferences( $user, $defaultPreferences );
46 self
::mathPreferences( $user, $defaultPreferences );
47 self
::datetimePreferences( $user, $defaultPreferences );
48 self
::renderingPreferences( $user, $defaultPreferences );
49 self
::editingPreferences( $user, $defaultPreferences );
50 self
::rcPreferences( $user, $defaultPreferences );
51 self
::watchlistPreferences( $user, $defaultPreferences );
52 self
::searchPreferences( $user, $defaultPreferences );
53 self
::miscPreferences( $user, $defaultPreferences );
55 wfRunHooks( 'GetPreferences', array( $user, &$defaultPreferences ) );
57 ## Remove preferences that wikis don't want to use
58 global $wgHiddenPrefs;
59 foreach ( $wgHiddenPrefs as $pref ) {
60 if ( isset( $defaultPreferences[$pref] ) ) {
61 unset( $defaultPreferences[$pref] );
65 ## Prod in defaults from the user
66 global $wgDefaultUserOptions;
67 foreach( $defaultPreferences as $name => &$info ) {
68 $prefFromUser = self
::getOptionFromUser( $name, $info, $user );
69 $field = HTMLForm
::loadInputFromParameters( $info ); // For validation
70 $defaultOptions = User
::getDefaultOptions();
71 $globalDefault = isset( $defaultOptions[$name] )
72 ?
$defaultOptions[$name]
75 // If it validates, set it as the default
76 if ( isset( $info['default'] ) ) {
77 // Already set, no problem
79 } elseif ( !is_null( $prefFromUser ) && // Make sure we're not just pulling nothing
80 $field->validate( $prefFromUser, $user->mOptions
) === true ) {
81 $info['default'] = $prefFromUser;
82 } elseif( $field->validate( $globalDefault, $user->mOptions
) === true ) {
83 $info['default'] = $globalDefault;
85 throw new MWException( "Global default '$globalDefault' is invalid for field $name" );
89 self
::$defaultPreferences = $defaultPreferences;
91 return $defaultPreferences;
94 // Pull option from a user account. Handles stuff like array-type preferences.
95 static function getOptionFromUser( $name, $info, $user ) {
96 $val = $user->getOption( $name );
98 // Handling for array-type preferences
99 if ( ( isset( $info['type'] ) && $info['type'] == 'multiselect' ) ||
100 ( isset( $info['class'] ) && $info['class'] == 'HTMLMultiSelectField' ) ) {
102 $options = HTMLFormField
::flattenOptions( $info['options'] );
103 $prefix = isset( $info['prefix'] ) ?
$info['prefix'] : $name;
106 foreach( $options as $label => $value ) {
107 if( $user->getOption( "$prefix$value" ) ) {
116 static function profilePreferences( $user, &$defaultPreferences ) {
117 global $wgLang, $wgUser;
118 ## User info #####################################
120 $defaultPreferences['username'] =
123 'label-message' => 'username',
124 'default' => $user->getName(),
125 'section' => 'personal/info',
128 $defaultPreferences['userid'] =
131 'label-message' => 'uid',
132 'default' => $user->getId(),
133 'section' => 'personal/info',
136 # Get groups to which the user belongs
137 $userEffectiveGroups = $user->getEffectiveGroups();
138 $userGroups = $userMembers = array();
139 foreach( $userEffectiveGroups as $ueg ) {
141 // Skip the default * group, seems useless here
144 $groupName = User
::getGroupName( $ueg );
145 $userGroups[] = User
::makeGroupLinkHTML( $ueg, $groupName );
147 $memberName = User
::getGroupMember( $ueg );
148 $userMembers[] = User
::makeGroupLinkHTML( $ueg, $memberName );
150 asort( $userGroups );
151 asort( $userMembers );
153 $defaultPreferences['usergroups'] =
156 'label' => wfMsgExt( 'prefs-memberingroups', 'parseinline',
157 $wgLang->formatNum( count($userGroups) ) ),
158 'default' => wfMsgExt( 'prefs-memberingroups-type', array(),
159 $wgLang->commaList( $userGroups ),
160 $wgLang->commaList( $userMembers )
163 'section' => 'personal/info',
166 $defaultPreferences['editcount'] =
169 'label-message' => 'prefs-edits',
170 'default' => $wgLang->formatNum( $user->getEditCount() ),
171 'section' => 'personal/info',
174 if( $user->getRegistration() ) {
175 $defaultPreferences['registrationdate'] =
178 'label-message' => 'prefs-registration',
179 'default' => wfMsgExt( 'prefs-registration-date-time', 'parsemag',
180 $wgLang->timeanddate( $user->getRegistration(), true ),
181 $wgLang->date( $user->getRegistration(), true ),
182 $wgLang->time( $user->getRegistration(), true ) ),
183 'section' => 'personal/info',
187 // Actually changeable stuff
189 $defaultPreferences['realname'] =
191 'type' => $wgAuth->allowPropChange( 'realname' ) ?
'text' : 'info',
192 'default' => $user->getRealName(),
193 'section' => 'personal/info',
194 'label-message' => 'yourrealname',
195 'help-message' => 'prefs-help-realname',
198 $defaultPreferences['gender'] =
201 'section' => 'personal/info',
203 wfMsg( 'gender-male' ) => 'male',
204 wfMsg( 'gender-female' ) => 'female',
205 wfMsg( 'gender-unknown' ) => 'unknown',
207 'label-message' => 'yourgender',
208 'help-message' => 'prefs-help-gender',
211 if( $wgAuth->allowPasswordChange() ) {
212 $link = $wgUser->getSkin()->link( SpecialPage
::getTitleFor( 'Resetpass' ),
213 wfMsgHtml( 'prefs-resetpass' ), array(),
214 array( 'returnto' => SpecialPage
::getTitleFor( 'Preferences' ) ) );
216 $defaultPreferences['password'] =
221 'label-message' => 'yourpassword',
222 'section' => 'personal/info',
226 $defaultPreferences['rememberpassword'] =
229 'label-message' => 'tog-rememberpassword',
230 'section' => 'personal/info',
234 global $wgContLanguageCode;
235 $languages = array_reverse( Language
::getLanguageNames( false ) );
236 if( !array_key_exists( $wgContLanguageCode, $languages ) ) {
237 $languages[$wgContLanguageCode] = $wgContLanguageCode;
242 foreach( $languages as $code => $name ) {
243 $display = wfBCP47( $code ) . ' - ' . $name;
244 $options[$display] = $code;
246 $defaultPreferences['language'] =
249 'section' => 'personal/i18n',
250 'options' => $options,
251 'label-message' => 'yourlanguage',
254 global $wgContLang, $wgDisableLangConversion;
255 global $wgDisableTitleConversion;
256 /* see if there are multiple language variants to choose from*/
257 $variantArray = array();
258 if( !$wgDisableLangConversion ) {
259 $variants = $wgContLang->getVariants();
261 $languages = Language
::getLanguageNames( true );
262 foreach( $variants as $v ) {
263 $v = str_replace( '_', '-', strtolower( $v ) );
264 if( array_key_exists( $v, $languages ) ) {
265 // If it doesn't have a name, we'll pretend it doesn't exist
266 $variantArray[$v] = $languages[$v];
271 foreach( $variantArray as $code => $name ) {
272 $display = wfBCP47( $code ) . ' - ' . $name;
273 $options[$display] = $code;
276 if( count( $variantArray ) > 1 ) {
277 $defaultPreferences['variant'] =
279 'label-message' => 'yourvariant',
281 'options' => $options,
282 'section' => 'personal/i18n',
287 if( count( $variantArray ) > 1 && !$wgDisableLangConversion && !$wgDisableTitleConversion ) {
288 $defaultPreferences['noconvertlink'] =
291 'section' => 'personal/i18n',
292 'label-message' => 'tog-noconvertlink',
296 global $wgMaxSigChars, $wgOut, $wgParser;
298 // show a preview of the old signature first
299 $oldsigWikiText = $wgParser->preSaveTransform( "~~~", new Title
, $user, new ParserOptions
);
300 $oldsigHTML = $wgOut->parseInline( $oldsigWikiText );
301 $defaultPreferences['oldsig'] =
305 'label-message' => 'tog-oldsig',
306 'default' => $oldsigHTML,
307 'section' => 'personal/signature',
309 $defaultPreferences['nickname'] =
311 'type' => $wgAuth->allowPropChange( 'nickname' ) ?
'text' : 'info',
312 'maxlength' => $wgMaxSigChars,
313 'label-message' => 'yournick',
314 'validation-callback' =>
315 array( 'Preferences', 'validateSignature' ),
316 'section' => 'personal/signature',
317 'filter-callback' => array( 'Preferences', 'cleanSignature' ),
319 $defaultPreferences['fancysig'] =
322 'label-message' => 'tog-fancysig',
323 'help-message' => 'prefs-help-signature', // show general help about signature at the bottom of the section
324 'section' => 'personal/signature'
329 global $wgEnableEmail;
330 if ($wgEnableEmail) {
332 global $wgEmailConfirmToEdit;
334 $defaultPreferences['emailaddress'] =
336 'type' => $wgAuth->allowPropChange( 'emailaddress' ) ?
'email' : 'info',
337 'default' => $user->getEmail(),
338 'section' => 'personal/email',
339 'label-message' => 'youremail',
340 'help-message' => $wgEmailConfirmToEdit
341 ?
'prefs-help-email-required'
342 : 'prefs-help-email',
343 'validation-callback' => array( 'Preferences', 'validateEmail' ),
346 global $wgEnableUserEmail, $wgEmailAuthentication;
348 $disableEmailPrefs = false;
350 if ( $wgEmailAuthentication ) {
351 if ( $user->getEmail() ) {
352 if( $user->getEmailAuthenticationTimestamp() ) {
353 // date and time are separate parameters to facilitate localisation.
354 // $time is kept for backward compat reasons.
355 // 'emailauthenticated' is also used in SpecialConfirmemail.php
356 $time = $wgLang->timeAndDate( $user->getEmailAuthenticationTimestamp(), true );
357 $d = $wgLang->date( $user->getEmailAuthenticationTimestamp(), true );
358 $t = $wgLang->time( $user->getEmailAuthenticationTimestamp(), true );
359 $emailauthenticated = wfMsgExt( 'emailauthenticated', 'parseinline',
360 array($time, $d, $t ) ) . '<br />';
361 $disableEmailPrefs = false;
363 $disableEmailPrefs = true;
364 $skin = $wgUser->getSkin();
365 $emailauthenticated = wfMsgExt( 'emailnotauthenticated', 'parseinline' ) . '<br />' .
367 SpecialPage
::getTitleFor( 'Confirmemail' ),
368 wfMsg( 'emailconfirmlink' ),
371 array( 'known', 'noclasses' )
375 $disableEmailPrefs = true;
376 $emailauthenticated = wfMsgHtml( 'noemailprefs' );
379 $defaultPreferences['emailauthentication'] =
383 'section' => 'personal/email',
384 'label-message' => 'prefs-emailconfirm-label',
385 'default' => $emailauthenticated,
390 if( $wgEnableUserEmail && $user->isAllowed( 'sendemail' ) ) {
391 $defaultPreferences['disablemail'] =
395 'section' => 'personal/email',
396 'label-message' => 'allowemail',
397 'disabled' => $disableEmailPrefs,
399 $defaultPreferences['ccmeonemails'] =
402 'section' => 'personal/email',
403 'label-message' => 'tog-ccmeonemails',
404 'disabled' => $disableEmailPrefs,
408 global $wgEnotifWatchlist;
409 if ( $wgEnotifWatchlist ) {
410 $defaultPreferences['enotifwatchlistpages'] =
413 'section' => 'personal/email',
414 'label-message' => 'tog-enotifwatchlistpages',
415 'disabled' => $disableEmailPrefs,
418 global $wgEnotifUserTalk;
419 if( $wgEnotifUserTalk ) {
420 $defaultPreferences['enotifusertalkpages'] =
423 'section' => 'personal/email',
424 'label-message' => 'tog-enotifusertalkpages',
425 'disabled' => $disableEmailPrefs,
428 if( $wgEnotifUserTalk ||
$wgEnotifWatchlist ) {
429 $defaultPreferences['enotifminoredits'] =
432 'section' => 'personal/email',
433 'label-message' => 'tog-enotifminoredits',
434 'disabled' => $disableEmailPrefs,
436 global $wgEnotifRevealEditorAddress;
437 if ( $wgEnotifRevealEditorAddress ) {
438 $defaultPreferences['enotifrevealaddr'] =
441 'section' => 'personal/email',
442 'label-message' => 'tog-enotifrevealaddr',
443 'disabled' => $disableEmailPrefs,
450 static function skinPreferences( $user, &$defaultPreferences ) {
451 ## Skin #####################################
452 global $wgLang, $wgAllowUserCss, $wgAllowUserJs;
454 $defaultPreferences['skin'] =
457 'options' => self
::generateSkinOptions( $user ),
459 'section' => 'rendering/skin',
462 # Create links to user CSS/JS pages for all skins
463 # This code is basically copied from generateSkinOptions(). It'd
464 # be nice to somehow merge this back in there to avoid redundancy.
465 if( $wgAllowUserCss ||
$wgAllowUserJs ) {
466 $sk = $user->getSkin();
467 $linkTools = array();
468 if( $wgAllowUserCss ) {
469 $cssPage = Title
::makeTitleSafe( NS_USER
, $user->getName() . '/common.css' );
470 $linkTools[] = $sk->link( $cssPage, wfMsgHtml( 'prefs-custom-css' ) );
472 if( $wgAllowUserJs ) {
473 $jsPage = Title
::makeTitleSafe( NS_USER
, $user->getName() . '/common.js' );
474 $linkTools[] = $sk->link( $jsPage, wfMsgHtml( 'prefs-custom-js' ) );
476 $defaultPreferences['commoncssjs'] =
480 'default' => $wgLang->pipeList( $linkTools ),
481 'label-message' => 'prefs-common-css-js',
482 'section' => 'rendering/skin',
486 $selectedSkin = $user->getOption( 'skin' );
487 if ( in_array( $selectedSkin, array( 'cologneblue', 'standard' ) ) ) {
489 $settings = array_flip( $wgLang->getQuickbarSettings() );
491 $defaultPreferences['quickbar'] =
494 'options' => $settings,
495 'section' => 'rendering/skin',
496 'label-message' => 'qbsettings',
501 static function mathPreferences( $user, &$defaultPreferences ) {
502 ## Math #####################################
503 global $wgUseTeX, $wgLang;
505 $defaultPreferences['math'] =
509 array_flip( array_map( 'wfMsgHtml', $wgLang->getMathNames() ) ),
511 'section' => 'rendering/math',
516 static function filesPreferences( $user, &$defaultPreferences ) {
517 ## Files #####################################
518 $defaultPreferences['imagesize'] =
521 'options' => self
::getImageSizes(),
522 'label-message' => 'imagemaxsize',
523 'section' => 'rendering/files',
525 $defaultPreferences['thumbsize'] =
528 'options' => self
::getThumbSizes(),
529 'label-message' => 'thumbsize',
530 'section' => 'rendering/files',
534 static function datetimePreferences( $user, &$defaultPreferences ) {
537 ## Date and time #####################################
538 $dateOptions = self
::getDateOptions();
540 $defaultPreferences['date'] =
543 'options' => $dateOptions,
545 'section' => 'datetime/dateformat',
550 $nowlocal = Xml
::element( 'span', array( 'id' => 'wpLocalTime' ),
551 $wgLang->time( $now = wfTimestampNow(), true ) );
552 $nowserver = $wgLang->time( $now, false ) .
553 Xml
::hidden( 'wpServerTime', substr( $now, 8, 2 ) * 60 +
substr( $now, 10, 2 ) );
555 $defaultPreferences['nowserver'] =
559 'label-message' => 'servertime',
560 'default' => $nowserver,
561 'section' => 'datetime/timeoffset',
564 $defaultPreferences['nowlocal'] =
568 'label-message' => 'localtime',
569 'default' => $nowlocal,
570 'section' => 'datetime/timeoffset',
573 // Grab existing pref.
574 $tzOffset = $user->getOption( 'timecorrection' );
575 $tz = explode( '|', $tzOffset, 2 );
577 $tzSetting = $tzOffset;
578 if( count( $tz ) > 1 && $tz[0] == 'Offset' ) {
580 $tzSetting = sprintf( '%+03d:%02d', floor( $minDiff/60 ), abs( $minDiff )%60
);
583 $defaultPreferences['timecorrection'] =
585 'class' => 'HTMLSelectOrOtherField',
586 'label-message' => 'timezonelegend',
587 'options' => self
::getTimezoneOptions(),
588 'default' => $tzSetting,
590 'section' => 'datetime/timeoffset',
594 static function renderingPreferences( $user, &$defaultPreferences ) {
595 ## Page Rendering ##############################
596 $defaultPreferences['underline'] =
600 wfMsg( 'underline-never' ) => 0,
601 wfMsg( 'underline-always' ) => 1,
602 wfMsg( 'underline-default' ) => 2,
604 'label-message' => 'tog-underline',
605 'section' => 'rendering/advancedrendering',
608 $stubThresholdValues = array( 0, 50, 100, 500, 1000, 2000, 5000, 10000 );
609 $stubThresholdOptions = array();
610 foreach( $stubThresholdValues as $value ) {
611 $stubThresholdOptions[wfMsg( 'size-bytes', $value )] = $value;
614 $defaultPreferences['stubthreshold'] =
616 'type' => 'selectorother',
617 'section' => 'rendering/advancedrendering',
618 'options' => $stubThresholdOptions,
620 'label' => wfMsg( 'stub-threshold' ), // Raw HTML message. Yay?
622 $defaultPreferences['highlightbroken'] =
625 'section' => 'rendering/advancedrendering',
626 'label' => wfMsg( 'tog-highlightbroken' ), // Raw HTML
628 $defaultPreferences['showtoc'] =
631 'section' => 'rendering/advancedrendering',
632 'label-message' => 'tog-showtoc',
634 $defaultPreferences['nocache'] =
637 'label-message' => 'tog-nocache',
638 'section' => 'rendering/advancedrendering',
640 $defaultPreferences['showhiddencats'] =
643 'section' => 'rendering/advancedrendering',
644 'label-message' => 'tog-showhiddencats'
646 $defaultPreferences['showjumplinks'] =
649 'section' => 'rendering/advancedrendering',
650 'label-message' => 'tog-showjumplinks',
652 $defaultPreferences['justify'] =
655 'section' => 'rendering/advancedrendering',
656 'label-message' => 'tog-justify',
658 $defaultPreferences['numberheadings'] =
661 'section' => 'rendering/advancedrendering',
662 'label-message' => 'tog-numberheadings',
666 static function editingPreferences( $user, &$defaultPreferences ) {
667 global $wgUseExternalEditor, $wgLivePreview;
669 ## Editing #####################################
670 $defaultPreferences['cols'] =
673 'label-message' => 'columns',
674 'section' => 'editing/textboxsize',
678 $defaultPreferences['rows'] =
681 'label-message' => 'rows',
682 'section' => 'editing/textboxsize',
687 $defaultPreferences['editfont'] =
690 'section' => 'editing/advancedediting',
691 'label-message' => 'editfont-style',
693 wfMsg( 'editfont-default' ) => 'default',
694 wfMsg( 'editfont-monospace' ) => 'monospace',
695 wfMsg( 'editfont-sansserif' ) => 'sans-serif',
696 wfMsg( 'editfont-serif' ) => 'serif',
699 $defaultPreferences['previewontop'] =
702 'section' => 'editing/advancedediting',
703 'label-message' => 'tog-previewontop',
705 $defaultPreferences['previewonfirst'] =
708 'section' => 'editing/advancedediting',
709 'label-message' => 'tog-previewonfirst',
711 $defaultPreferences['editsection'] =
714 'section' => 'editing/advancedediting',
715 'label-message' => 'tog-editsection',
717 $defaultPreferences['editsectiononrightclick'] =
720 'section' => 'editing/advancedediting',
721 'label-message' => 'tog-editsectiononrightclick',
723 $defaultPreferences['editondblclick'] =
726 'section' => 'editing/advancedediting',
727 'label-message' => 'tog-editondblclick',
729 $defaultPreferences['editwidth'] =
732 'section' => 'editing/advancedediting',
733 'label-message' => 'tog-editwidth',
735 $defaultPreferences['showtoolbar'] =
738 'section' => 'editing/advancedediting',
739 'label-message' => 'tog-showtoolbar',
741 $defaultPreferences['minordefault'] =
744 'section' => 'editing/advancedediting',
745 'label-message' => 'tog-minordefault',
748 if ( $wgUseExternalEditor ) {
749 $defaultPreferences['externaleditor'] =
752 'section' => 'editing/advancedediting',
753 'label-message' => 'tog-externaleditor',
755 $defaultPreferences['externaldiff'] =
758 'section' => 'editing/advancedediting',
759 'label-message' => 'tog-externaldiff',
763 $defaultPreferences['forceeditsummary'] =
766 'section' => 'editing/advancedediting',
767 'label-message' => 'tog-forceeditsummary',
769 if ( $wgLivePreview ) {
770 $defaultPreferences['uselivepreview'] =
773 'section' => 'editing/advancedediting',
774 'label-message' => 'tog-uselivepreview',
779 static function rcPreferences( $user, &$defaultPreferences ) {
780 global $wgRCMaxAge, $wgUseRCPatrol, $wgLang;
781 ## RecentChanges #####################################
782 $defaultPreferences['rcdays'] =
785 'label-message' => 'recentchangesdays',
786 'section' => 'rc/display',
788 'max' => ceil( $wgRCMaxAge / ( 3600*24 ) ),
789 'help' => wfMsgExt( 'recentchangesdays-max', array( 'parsemag' ), $wgLang->formatNum( ceil( $wgRCMaxAge / ( 3600*24 ) ) ) ),
791 $defaultPreferences['rclimit'] =
794 'label-message' => 'recentchangescount',
795 'help-message' => 'prefs-help-recentchangescount',
796 'section' => 'rc/display',
798 $defaultPreferences['usenewrc'] =
801 'label-message' => 'tog-usenewrc',
802 'section' => 'rc/advancedrc',
804 $defaultPreferences['hideminor'] =
807 'label-message' => 'tog-hideminor',
808 'section' => 'rc/advancedrc',
811 if( $wgUseRCPatrol ) {
812 $defaultPreferences['hidepatrolled'] =
815 'section' => 'rc/advancedrc',
816 'label-message' => 'tog-hidepatrolled',
818 $defaultPreferences['newpageshidepatrolled'] =
821 'section' => 'rc/advancedrc',
822 'label-message' => 'tog-newpageshidepatrolled',
826 global $wgRCShowWatchingUsers;
827 if( $wgRCShowWatchingUsers ) {
828 $defaultPreferences['shownumberswatching'] =
831 'section' => 'rc/advancedrc',
832 'label-message' => 'tog-shownumberswatching',
837 static function watchlistPreferences( $user, &$defaultPreferences ) {
838 global $wgUseRCPatrol, $wgEnableAPI;
839 ## Watchlist #####################################
840 $defaultPreferences['watchlistdays'] =
845 'section' => 'watchlist/display',
846 'help' => wfMsgHtml( 'prefs-watchlist-days-max' ),
847 'label-message' => 'prefs-watchlist-days',
849 $defaultPreferences['wllimit'] =
854 'label-message' => 'prefs-watchlist-edits',
855 'help' => wfMsgHtml( 'prefs-watchlist-edits-max' ),
856 'section' => 'watchlist/display',
858 $defaultPreferences['extendwatchlist'] =
861 'section' => 'watchlist/advancedwatchlist',
862 'label-message' => 'tog-extendwatchlist',
864 $defaultPreferences['watchlisthideminor'] =
867 'section' => 'watchlist/advancedwatchlist',
868 'label-message' => 'tog-watchlisthideminor',
870 $defaultPreferences['watchlisthidebots'] =
873 'section' => 'watchlist/advancedwatchlist',
874 'label-message' => 'tog-watchlisthidebots',
876 $defaultPreferences['watchlisthideown'] =
879 'section' => 'watchlist/advancedwatchlist',
880 'label-message' => 'tog-watchlisthideown',
882 $defaultPreferences['watchlisthideanons'] =
885 'section' => 'watchlist/advancedwatchlist',
886 'label-message' => 'tog-watchlisthideanons',
888 $defaultPreferences['watchlisthideliu'] =
891 'section' => 'watchlist/advancedwatchlist',
892 'label-message' => 'tog-watchlisthideliu',
894 if ( $wgEnableAPI ) {
895 # Some random gibberish as a proposed default
896 $hash = sha1( mt_rand() . microtime( true ) );
897 $defaultPreferences['watchlisttoken'] =
900 'section' => 'watchlist/advancedwatchlist',
901 'label-message' => 'prefs-watchlist-token',
902 'help' => wfMsgHtml( 'prefs-help-watchlist-token', $hash )
906 if ( $wgUseRCPatrol ) {
907 $defaultPreferences['watchlisthidepatrolled'] =
910 'section' => 'watchlist/advancedwatchlist',
911 'label-message' => 'tog-watchlisthidepatrolled',
916 'edit' => 'watchdefault',
917 'move' => 'watchmoves',
918 'delete' => 'watchdeletion'
922 if( $user->isAllowed( 'createpage' ) ||
$user->isAllowed( 'createtalk' ) ) {
923 $watchTypes['read'] = 'watchcreations';
926 foreach( $watchTypes as $action => $pref ) {
927 if ( $user->isAllowed( $action ) ) {
928 $defaultPreferences[$pref] = array(
930 'section' => 'watchlist/advancedwatchlist',
931 'label-message' => "tog-$pref",
937 static function searchPreferences( $user, &$defaultPreferences ) {
940 ## Search #####################################
941 $defaultPreferences['searchlimit'] =
944 'label-message' => 'resultsperpage',
945 'section' => 'searchoptions/display',
948 $defaultPreferences['contextlines'] =
951 'label-message' => 'contextlines',
952 'section' => 'searchoptions/display',
955 $defaultPreferences['contextchars'] =
958 'label-message' => 'contextchars',
959 'section' => 'searchoptions/display',
962 global $wgEnableMWSuggest;
963 if( $wgEnableMWSuggest ) {
964 $defaultPreferences['disablesuggest'] =
967 'label-message' => 'mwsuggest-disable',
968 'section' => 'searchoptions/display',
972 $defaultPreferences['searcheverything'] =
975 'label-message' => 'searcheverything-enable',
976 'section' => 'searchoptions/advancedsearchoptions',
979 // Searchable namespaces back-compat with old format
980 $searchableNamespaces = SearchEngine
::searchableNamespaces();
982 $nsOptions = array();
983 foreach( $wgContLang->getNamespaces() as $ns => $name ) {
984 if( $ns < 0 ) continue;
985 $displayNs = str_replace( '_', ' ', $name );
987 if( !$displayNs ) $displayNs = wfMsg( 'blanknamespace' );
989 $displayNs = htmlspecialchars( $displayNs );
990 $nsOptions[$displayNs] = $ns;
993 $defaultPreferences['searchnamespaces'] =
995 'type' => 'multiselect',
996 'label-message' => 'defaultns',
997 'options' => $nsOptions,
998 'section' => 'searchoptions/advancedsearchoptions',
999 'prefix' => 'searchNs',
1003 static function miscPreferences( $user, &$defaultPreferences ) {
1004 ## Misc #####################################
1005 $defaultPreferences['diffonly'] =
1008 'section' => 'misc/diffs',
1009 'label-message' => 'tog-diffonly',
1011 $defaultPreferences['norollbackdiff'] =
1014 'section' => 'misc/diffs',
1015 'label-message' => 'tog-norollbackdiff',
1018 // Stuff from Language::getExtraUserToggles()
1021 $toggles = $wgContLang->getExtraUserToggles();
1023 foreach( $toggles as $toggle ) {
1024 $defaultPreferences[$toggle] =
1027 'section' => 'personal/i18n',
1028 'label-message' => "tog-$toggle",
1034 * @param object $user The user object
1035 * @return array Text/links to display as key; $skinkey as value
1037 static function generateSkinOptions( $user ) {
1038 global $wgDefaultSkin, $wgLang, $wgAllowUserCss, $wgAllowUserJs;
1041 $mptitle = Title
::newMainPage();
1042 $previewtext = wfMsgHtml( 'skin-preview' );
1043 # Only show members of Skin::getSkinNames() rather than
1044 # $skinNames (skins is all skin names from Language.php)
1045 $validSkinNames = Skin
::getUsableSkins();
1046 # Sort by UI skin name. First though need to update validSkinNames as sometimes
1047 # the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI).
1048 foreach ( $validSkinNames as $skinkey => &$skinname ) {
1049 $msgName = "skinname-{$skinkey}";
1050 $localisedSkinName = wfMsg( $msgName );
1051 if ( !wfEmptyMsg( $msgName, $localisedSkinName ) ) {
1052 $skinname = htmlspecialchars( $localisedSkinName );
1055 asort( $validSkinNames );
1056 $sk = $user->getSkin();
1058 foreach( $validSkinNames as $skinkey => $sn ) {
1059 $linkTools = array();
1061 # Mark the default skin
1062 if( $skinkey == $wgDefaultSkin ) {
1063 $linkTools[] = wfMsgHtml( 'default' );
1066 # Create preview link
1067 $mplink = htmlspecialchars( $mptitle->getLocalURL( "useskin=$skinkey" ) );
1068 $linkTools[] = "<a target='_blank' href=\"$mplink\">$previewtext</a>";
1070 # Create links to user CSS/JS pages
1071 if( $wgAllowUserCss ) {
1072 $cssPage = Title
::makeTitleSafe( NS_USER
, $user->getName() . '/' . $skinkey . '.css' );
1073 $linkTools[] = $sk->link( $cssPage, wfMsgHtml( 'prefs-custom-css' ) );
1075 if( $wgAllowUserJs ) {
1076 $jsPage = Title
::makeTitleSafe( NS_USER
, $user->getName() . '/' . $skinkey . '.js' );
1077 $linkTools[] = $sk->link( $jsPage, wfMsgHtml( 'prefs-custom-js' ) );
1080 $display = $sn . ' ' . wfMsg( 'parentheses', $wgLang->pipeList( $linkTools ) );
1081 $ret[$display] = $skinkey;
1087 static function getDateOptions() {
1089 $dateopts = $wgLang->getDatePreferences();
1094 if ( !in_array( 'default', $dateopts ) ) {
1095 $dateopts[] = 'default'; // Make sure default is always valid
1100 $epoch = wfTimestampNow();
1101 foreach( $dateopts as $key ) {
1102 if( $key == 'default' ) {
1103 $formatted = wfMsgHtml( 'datedefault' );
1105 $formatted = htmlspecialchars( $wgLang->timeanddate( $epoch, false, $key ) );
1107 $ret[$formatted] = $key;
1113 static function getImageSizes() {
1114 global $wgImageLimits;
1118 foreach ( $wgImageLimits as $index => $limits ) {
1119 $display = "{$limits[0]}×{$limits[1]}" . wfMsg( 'unit-pixel' );
1120 $ret[$display] = $index;
1126 static function getThumbSizes() {
1127 global $wgThumbLimits;
1131 foreach ( $wgThumbLimits as $index => $size ) {
1132 $display = $size . wfMsg( 'unit-pixel' );
1133 $ret[$display] = $index;
1139 static function validateSignature( $signature, $alldata ) {
1140 global $wgParser, $wgMaxSigChars, $wgLang;
1141 if( mb_strlen( $signature ) > $wgMaxSigChars ) {
1143 Xml
::element( 'span', array( 'class' => 'error' ),
1144 wfMsgExt( 'badsiglength', 'parsemag',
1145 $wgLang->formatNum( $wgMaxSigChars )
1148 } elseif( !empty( $alldata['fancysig'] ) &&
1149 false === $wgParser->validateSig( $signature ) ) {
1150 return Xml
::element( 'span', array( 'class' => 'error' ), wfMsg( 'badsig' ) );
1156 static function cleanSignature( $signature, $alldata ) {
1158 if( $alldata['fancysig'] ) {
1159 $signature = $wgParser->cleanSig( $signature );
1161 // When no fancy sig used, make sure ~{3,5} get removed.
1162 $signature = $wgParser->cleanSigInSig( $signature );
1168 static function validateEmail( $email, $alldata ) {
1169 if ( $email && !User
::isValidEmailAddr( $email ) ) {
1170 return wfMsgExt( 'invalidemailaddress', 'parseinline' );
1173 global $wgEmailConfirmToEdit;
1174 if( $wgEmailConfirmToEdit && !$email ) {
1175 return wfMsgExt( 'noemailtitle', 'parseinline' );
1180 static function getFormObject( $user ) {
1181 $formDescriptor = Preferences
::getPreferences( $user );
1182 $htmlForm = new PreferencesForm( $formDescriptor, 'prefs' );
1184 $htmlForm->setSubmitText( wfMsg( 'saveprefs' ) );
1185 $htmlForm->setTitle( SpecialPage
::getTitleFor( 'Preferences' ) );
1186 $htmlForm->setSubmitID( 'prefsubmit' );
1187 $htmlForm->setSubmitCallback( array( 'Preferences', 'tryFormSubmit' ) );
1192 static function getTimezoneOptions() {
1195 global $wgLocalTZoffset;
1197 $opt[wfMsg( 'timezoneuseserverdefault' )] = "System|$wgLocalTZoffset";
1198 $opt[wfMsg( 'timezoneuseoffset' )] = 'other';
1199 $opt[wfMsg( 'guesstimezone' )] = 'guess';
1201 if ( function_exists( 'timezone_identifiers_list' ) ) {
1202 # Read timezone list
1203 $tzs = timezone_identifiers_list();
1206 $tzRegions = array();
1207 $tzRegions['Africa'] = wfMsg( 'timezoneregion-africa' );
1208 $tzRegions['America'] = wfMsg( 'timezoneregion-america' );
1209 $tzRegions['Antarctica'] = wfMsg( 'timezoneregion-antarctica' );
1210 $tzRegions['Arctic'] = wfMsg( 'timezoneregion-arctic' );
1211 $tzRegions['Asia'] = wfMsg( 'timezoneregion-asia' );
1212 $tzRegions['Atlantic'] = wfMsg( 'timezoneregion-atlantic' );
1213 $tzRegions['Australia'] = wfMsg( 'timezoneregion-australia' );
1214 $tzRegions['Europe'] = wfMsg( 'timezoneregion-europe' );
1215 $tzRegions['Indian'] = wfMsg( 'timezoneregion-indian' );
1216 $tzRegions['Pacific'] = wfMsg( 'timezoneregion-pacific' );
1217 asort( $tzRegions );
1219 $prefill = array_fill_keys( array_values( $tzRegions ), array() );
1220 $opt = array_merge( $opt, $prefill );
1222 $now = date_create( 'now' );
1224 foreach ( $tzs as $tz ) {
1225 $z = explode( '/', $tz, 2 );
1227 # timezone_identifiers_list() returns a number of
1228 # backwards-compatibility entries. This filters them out of the
1229 # list presented to the user.
1230 if ( count( $z ) != 2 ||
!array_key_exists( $z[0], $tzRegions ) )
1234 $z[0] = $tzRegions[$z[0]];
1236 $minDiff = floor( timezone_offset_get( timezone_open( $tz ), $now ) / 60 );
1238 $display = str_replace( '_', ' ', $z[0] . '/' . $z[1] );
1239 $value = "ZoneInfo|$minDiff|$tz";
1241 $opt[$z[0]][$display] = $value;
1247 static function filterTimezoneInput( $tz, $alldata ) {
1248 $data = explode( '|', $tz, 3 );
1249 switch ( $data[0] ) {
1254 $data = explode( ':', $tz, 2 );
1256 if( count( $data ) == 2 ) {
1257 $data[0] = intval( $data[0] );
1258 $data[1] = intval( $data[1] );
1259 $minDiff = abs( $data[0] ) * 60 +
$data[1];
1260 if ( $data[0] < 0 ) $minDiff = -$minDiff;
1262 $minDiff = intval( $data[0] ) * 60;
1265 # Max is +14:00 and min is -12:00, see:
1266 # http://en.wikipedia.org/wiki/Timezone
1267 $minDiff = min( $minDiff, 840 ); # 14:00
1268 $minDiff = max( $minDiff, -720 ); # -12:00
1269 return 'Offset|'.$minDiff;
1273 static function tryFormSubmit( $formData, $entryPoint = 'internal' ) {
1274 global $wgUser, $wgEmailAuthentication, $wgEnableEmail;
1279 foreach( array_keys( $formData ) as $name ) {
1280 if ( isset( self
::$saveFilters[$name] ) ) {
1282 call_user_func( self
::$saveFilters[$name], $formData[$name], $formData );
1286 // Stuff that shouldn't be saved as a preference.
1287 $saveBlacklist = array(
1292 if( $wgEnableEmail ) {
1293 $newaddr = $formData['emailaddress'];
1294 $oldaddr = $wgUser->getEmail();
1295 if( ( $newaddr != '' ) && ( $newaddr != $oldaddr ) ) {
1296 # the user has supplied a new email address on the login page
1297 # new behaviour: set this new emailaddr from login-page into user database record
1298 $wgUser->setEmail( $newaddr );
1299 # but flag as "dirty" = unauthenticated
1300 $wgUser->invalidateEmail();
1301 if( $wgEmailAuthentication ) {
1302 # Mail a temporary password to the dirty address.
1303 # User can come back through the confirmation URL to re-enable email.
1304 $result = $wgUser->sendConfirmationMail( $oldaddr != '' );
1305 if( WikiError
::isError( $result ) ) {
1306 return wfMsg( 'mailerror', htmlspecialchars( $result->getMessage() ) );
1307 } elseif( $entryPoint == 'ui' ) {
1312 $wgUser->setEmail( $newaddr );
1314 if( $oldaddr != $newaddr ) {
1315 wfRunHooks( 'PrefsEmailAudit', array( $wgUser, $oldaddr, $newaddr ) );
1319 // Fortunately, the realname field is MUCH simpler
1320 global $wgHiddenPrefs;
1321 if ( !in_array( 'realname', $wgHiddenPrefs ) ) {
1322 $realName = $formData['realname'];
1323 $wgUser->setRealName( $realName );
1326 foreach( $saveBlacklist as $b )
1327 unset( $formData[$b] );
1329 // Keeps old preferences from interfering due to back-compat
1331 $wgUser->resetOptions();
1333 foreach( $formData as $key => $value ) {
1334 $wgUser->setOption( $key, $value );
1337 $wgUser->saveSettings();
1342 public static function tryUISubmit( $formData ) {
1343 $res = self
::tryFormSubmit( $formData, 'ui' );
1346 $urlOptions = array( 'success' );
1347 if( $res === 'eauth' )
1348 $urlOptions[] = 'eauth';
1350 $queryString = implode( '&', $urlOptions );
1352 $url = SpecialPage
::getTitleFor( 'Preferences' )->getFullURL( $queryString );
1354 $wgOut->redirect( $url );
1360 public static function loadOldSearchNs( $user ) {
1361 $searchableNamespaces = SearchEngine
::searchableNamespaces();
1362 // Back compat with old format
1365 foreach( $searchableNamespaces as $ns => $name ) {
1366 if( $user->getOption( 'searchNs' . $ns ) ) {
1375 /** Some tweaks to allow js prefs to work */
1376 class PreferencesForm
extends HTMLForm
{
1378 function wrapForm( $html ) {
1379 $html = Xml
::tags( 'div', array( 'id' => 'preferences' ), $html );
1381 return parent
::wrapForm( $html );
1384 function getButtons() {
1385 $html = parent
::getButtons();
1389 $sk = $wgUser->getSkin();
1390 $t = SpecialPage
::getTitleFor( 'Preferences', 'reset' );
1392 $html .= "\n" . $sk->link( $t, wfMsgHtml( 'restoreprefs' ) );
1394 $html = Xml
::tags( 'div', array( 'class' => 'mw-prefs-buttons' ), $html );
1399 function filterDataForSubmit( $data ) {
1400 // Support for separating MultiSelect preferences into multiple preferences
1401 // Due to lack of array support.
1402 foreach( $this->mFlatFields
as $fieldname => $field ) {
1403 $info = $field->mParams
;
1404 if( $field instanceof HTMLMultiSelectField
) {
1405 $options = HTMLFormField
::flattenOptions( $info['options'] );
1406 $prefix = isset( $info['prefix'] ) ?
$info['prefix'] : $fieldname;
1408 foreach( $options as $opt ) {
1409 $data["$prefix$opt"] = in_array( $opt, $data[$fieldname] );
1412 unset( $data[$fieldname] );