6a81ef9c85d72f6af6b8ec123754489439c0ac99
4 static $defaultPreferences = null;
7 'timecorrection' => array( 'Preferences', 'filterTimezoneInput' ),
10 static function getPreferences( $user ) {
11 if (self
::$defaultPreferences)
12 return self
::$defaultPreferences;
14 global $wgLang, $wgRCMaxAge;
16 $defaultPreferences = array();
18 self
::profilePreferences( $user, $defaultPreferences );
19 self
::skinPreferences( $user, $defaultPreferences );
20 self
::mathPreferences( $user, $defaultPreferences );
21 self
::filesPreferences( $user, $defaultPreferences );
22 self
::datetimePreferences( $user, $defaultPreferences );
23 self
::renderingPreferences( $user, $defaultPreferences );
24 self
::editingPreferences( $user, $defaultPreferences );
25 self
::rcPreferences( $user, $defaultPreferences );
26 self
::watchlistPreferences( $user, $defaultPreferences );
27 self
::searchPreferences( $user, $defaultPreferences );
28 self
::miscPreferences( $user, $defaultPreferences );
30 wfRunHooks( 'GetPreferences', array( $user, &$defaultPreferences ) );
32 ## Prod in defaults from the user
33 global $wgDefaultUserOptions;
34 foreach( $defaultPreferences as $name => &$info ) {
35 $prefFromUser = self
::getOptionFromUser( $name, $info, $user );
36 $field = HTMLForm
::loadInputFromParameters( $info ); // For validation
37 $globalDefault = isset($wgDefaultUserOptions[$name])
38 ?
$wgDefaultUserOptions[$name]
41 // If it validates, set it as the default
42 if ( isset($info['default']) ) {
43 // Already set, no problem
45 } elseif ( !is_null( $prefFromUser ) && // Make sure we're not just pulling nothing
46 $field->validate( $prefFromUser, $user->mOptions
) ) {
47 $info['default'] = $prefFromUser;
48 } elseif( $field->validate( $globalDefault, $user->mOptions
) ) {
49 $info['default'] = $globalDefault;
53 self
::$defaultPreferences = $defaultPreferences;
55 return $defaultPreferences;
58 // Pull option from a user account. Handles stuff like array-type preferences.
59 static function getOptionFromUser( $name, $info, $user ) {
60 $val = $user->getOption( $name );
62 // Handling for array-type preferences
63 if ( ( isset($info['type']) && $info['type'] == 'multiselect' ) ||
64 ( isset($info['class']) && $info['class'] == 'HTMLMultiSelectField' ) ) {
66 $options = HTMLFormField
::flattenOptions($info['options']);
67 $prefix = isset($info['prefix']) ?
$info['prefix'] : $name;
70 foreach( $options as $label => $value ) {
71 if ($user->getOption( "$prefix$value" ) ) {
80 static function profilePreferences( $user, &$defaultPreferences ) {
82 ## User info #####################################
84 $defaultPreferences['username'] =
87 'label-message' => 'username',
88 'default' => $user->getName(),
89 'section' => 'personal/info',
92 $defaultPreferences['userid'] =
95 'label-message' => 'uid',
96 'default' => $user->getId(),
97 'section' => 'personal/info',
100 # Get groups to which the user belongs
101 $userEffectiveGroups = $user->getEffectiveGroups();
102 $userEffectiveGroupsArray = array();
103 foreach( $userEffectiveGroups as $ueg ) {
105 // Skip the default * group, seems useless here
108 $userEffectiveGroupsArray[] = User
::makeGroupLinkHTML( $ueg );
110 asort( $userEffectiveGroupsArray );
112 $defaultPreferences['usergroups'] =
115 'label' => wfMsgExt( 'prefs-memberingroups', 'parseinline',
116 count($userEffectiveGroupsArray) ),
117 'default' => $wgLang->commaList( $userEffectiveGroupsArray ),
119 'section' => 'personal/info',
122 $defaultPreferences['editcount'] =
125 'label-message' => 'prefs-edits',
126 'default' => $user->getEditCount(),
127 'section' => 'personal/info',
130 if ($user->getRegistration()) {
131 $defaultPreferences['registrationdate'] =
134 'label-message' => 'prefs-registration',
135 'default' => $wgLang->timeanddate( $user->getRegistration() ),
136 'section' => 'personal/info',
140 // Actually changeable stuff
141 global $wgAllowRealName;
142 if ($wgAllowRealName) {
143 $defaultPreferences['realname'] =
146 'default' => $user->getRealName(),
147 'section' => 'personal/info',
148 'label-message' => 'yourrealname',
149 'help-message' => 'prefs-help-realname',
154 $defaultPreferences['gender'] =
157 'section' => 'personal/info',
159 wfMsg('gender-male') => 'male',
160 wfMsg('gender-female') => 'female',
161 wfMsg('gender-unknown') => 'unknown',
163 'label-message' => 'yourgender',
164 'help-message' => 'prefs-help-gender',
168 if ($wgAuth->allowPasswordChange()) {
169 global $wgUser; // For skin.
170 $link = $wgUser->getSkin()->link( SpecialPage
::getTitleFor( 'ResetPass' ),
171 wfMsgHtml( 'prefs-resetpass' ), array() ,
172 array('returnto' => SpecialPage
::getTitleFor( 'Preferences') ) );
174 $defaultPreferences['password'] =
179 'label-message' => 'yourpassword',
180 'section' => 'personal/info',
184 $defaultPreferences['rememberpassword'] =
187 'label-message' => 'tog-rememberpassword',
188 'section' => 'personal/info',
192 global $wgContLanguageCode;
193 $languages = array_reverse( Language
::getLanguageNames( false ) );
194 if( !array_key_exists( $wgContLanguageCode, $languages ) ) {
195 $languages[$wgContLanguageCode] = $wgContLanguageCode;
200 foreach( $languages as $code => $name ) {
201 $display = "$code - $name";
202 $options[$display] = $code;
204 $defaultPreferences['language'] =
207 'section' => 'personal/i18n',
208 'options' => $options,
209 'label-message' => 'yourlanguage',
212 global $wgContLang, $wgDisableLangConversion;
213 /* see if there are multiple language variants to choose from*/
214 $variantArray = array();
215 if(!$wgDisableLangConversion) {
216 $variants = $wgContLang->getVariants();
218 $languages = Language
::getLanguageNames( true );
219 foreach($variants as $v) {
220 $v = str_replace( '_', '-', strtolower($v));
221 if( array_key_exists( $v, $languages ) ) {
222 // If it doesn't have a name, we'll pretend it doesn't exist
223 $variantArray[$v] = $languages[$v];
228 foreach( $variantArray as $code => $name ) {
229 $display = "$code - $name";
230 $options[$display] = $code;
233 if(count($variantArray) > 1) {
234 $defaultPreferences['variant'] =
236 'label-message' => 'yourvariant',
238 'options' => $options,
239 'section' => 'personal/i18n',
244 if( count($variantArray) > 1 && !$wgDisableLangConversion && !$wgDisableTitleConversion ) {
245 $defaultPreferences['noconvertlink'] =
248 'section' => 'personal/i18n',
249 'label-message' => 'tog-noconvertlink',
253 global $wgMaxSigChars;
254 $defaultPreferences['nickname'] =
257 'maxlength' => $wgMaxSigChars,
258 'label-message' => 'yournick',
259 'validation-callback' =>
260 array( 'Preferences', 'validateSignature' ),
261 'section' => 'personal/signature',
262 'filter-callback' => array( 'Preferences', 'cleanSignature' ),
264 $defaultPreferences['fancysig'] =
267 'label-message' => 'tog-fancysig',
268 'section' => 'personal/signature'
273 global $wgEmailConfirmToEdit;
275 $defaultPreferences['emailaddress'] =
278 'default' => $user->getEmail(),
279 'section' => 'personal/email',
280 'label-message' => 'youremail',
281 'help-message' => $wgEmailConfirmToEdit
282 ?
'prefs-help-email-required'
283 : 'prefs-help-email',
284 'validation-callback' => array( 'Preferences', 'validateEmail' ),
287 global $wgEnableEmail, $wgEnableUserEmail, $wgEmailAuthentication;
289 if ( $wgEmailAuthentication ) {
290 if ( $user->getEmail() ) {
291 if( $user->getEmailAuthenticationTimestamp() ) {
292 // date and time are separate parameters to facilitate localisation.
293 // $time is kept for backward compat reasons.
294 // 'emailauthenticated' is also used in SpecialConfirmemail.php
295 $time = $wgLang->timeAndDate( $user->getEmailAuthenticationTimestamp(), true );
296 $d = $wgLang->date( $user->getEmailAuthenticationTimestamp(), true );
297 $t = $wgLang->time( $user->getEmailAuthenticationTimestamp(), true );
298 $emailauthenticated = wfMsg('emailauthenticated', $time, $d, $t ).'<br />';
299 $disableEmailPrefs = false;
301 $disableEmailPrefs = true;
302 global $wgUser; // wgUser is okay here, it's for display
303 $skin = $wgUser->getSkin();
304 $emailauthenticated = wfMsg('emailnotauthenticated').'<br />' .
305 $skin->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Confirmemail' ),
306 wfMsg( 'emailconfirmlink' ) ) . '<br />';
309 $emailauthenticated = wfMsg( 'noemailprefs' );
312 $defaultPreferences['emailauthentication'] =
316 'section' => 'personal/email',
317 'label-message' => 'prefs-emailconfirm-label',
318 'default' => $emailauthenticated,
323 if ($wgEnableEmail) {
324 if ($wgEnableUserEmail) {
325 $defaultPreferences['disablemail'] =
329 'section' => 'personal/email',
330 'label-message' => 'allowemail',
332 $defaultPreferences['ccmeonemails'] =
335 'section' => 'personal/email',
336 'label-message' => 'tog-ccmeonemails',
340 $defaultPreferences['enotifwatchlistpages'] =
343 'section' => 'personal/email',
344 'label-message' => 'tog-enotifwatchlistpages',
346 $defaultPreferences['enotifusertalkpages'] =
349 'section' => 'personal/email',
350 'label-message' => 'tog-enotifusertalkpages',
352 $defaultPreferences['enotifminoredits'] =
355 'section' => 'personal/email',
356 'label-message' => 'tog-enotifminoredits',
358 $defaultPreferences['enotifrevealaddr'] =
361 'section' => 'personal/email',
362 'label-message' => 'tog-enotifrevealaddr'
367 static function skinPreferences( $user, &$defaultPreferences ) {
368 ## Skin #####################################
369 global $wgAllowUserSkin, $wgLang;
371 if ($wgAllowUserSkin) {
372 $defaultPreferences['skin'] =
375 'options' => self
::generateSkinOptions( $user ),
381 $selectedSkin = $user->getOption( 'skin' );
382 if ( in_array( $selectedSkin, array( 'cologneblue', 'standard' ) ) ) {
383 $settings = array_flip($wgLang->getQuickbarSettings());
385 $defaultPreferences['quickbar'] =
388 'options' => $settings,
390 'label-message' => 'qbsettings',
395 static function mathPreferences( $user, &$defaultPreferences ) {
396 ## Math #####################################
397 global $wgUseTeX, $wgLang;
399 $defaultPreferences['math'] =
403 array_flip( array_map( 'wfMsg', $wgLang->getMathNames() ) ),
405 'section' => 'rendering/math',
410 static function filesPreferences( $user, &$defaultPreferences ) {
411 ## Files #####################################
412 $defaultPreferences['imagesize'] =
415 'options' => self
::getImageSizes(),
416 'label-message' => 'imagemaxsize',
417 'section' => 'rendering/files',
419 $defaultPreferences['thumbsize'] =
422 'options' => self
::getThumbSizes(),
423 'label-message' => 'thumbsize',
424 'section' => 'rendering/files',
428 static function datetimePreferences( $user, &$defaultPreferences ) {
431 ## Date and time #####################################
432 $dateOptions = self
::getDateOptions();
434 $defaultPreferences['date'] =
437 'options' => $dateOptions,
438 'label-message' => 'dateformat',
439 'section' => 'datetime',
444 $nowlocal = Xml
::element( 'span', array( 'id' => 'wpLocalTime' ),
445 $wgLang->time( $now = wfTimestampNow(), true ) );
446 $nowserver = $wgLang->time( $now, false ) .
447 Xml
::hidden( 'wpServerTime', substr( $now, 8, 2 ) * 60 +
substr( $now, 10, 2 ) );
449 $defaultPreferences['nowserver'] =
453 'label-message' => 'servertime',
454 'default' => $nowserver,
455 'section' => 'datetime',
458 $defaultPreferences['nowlocal'] =
462 'label-message' => 'localtime',
463 'default' => $nowlocal,
464 'section' => 'datetime',
467 // Grab existing pref.
468 $tzOffset = $user->getOption( 'timecorrection' );
469 $tz = explode( '|', $tzOffset, 2 );
471 $tzSetting = $tzOffset;
472 if (count($tz) > 1 && $tz[0] == 'Offset') {
474 $tzSetting = sprintf( '%+03d:%02d', floor($minDiff/60), abs($minDiff)%60
);;
477 $defaultPreferences['timecorrection'] =
479 'class' => 'HTMLSelectOrOtherField',
480 'label-message' => 'timezonelegend',
481 'options' => self
::getTimezoneOptions(),
482 'default' => $tzSetting,
483 'section' => 'datetime',
487 static function renderingPreferences( $user, &$defaultPreferences ) {
488 ## Page Rendering ##############################
489 $defaultPreferences['underline'] =
493 wfMsg( 'underline-never' ) => 0,
494 wfMsg( 'underline-always' ) => 1,
495 wfMsg( 'underline-default' ) => 2,
497 'label-message' => 'tog-underline',
498 'section' => 'rendering',
501 $stubThresholdValues = array( 0, 50, 100, 500, 1000, 2000, 5000, 10000 );
502 $stubThresholdOptions = array();
503 foreach( $stubThresholdValues as $value ) {
504 $stubThresholdOptions[wfMsg( 'size-bytes', $value )] = $value;
507 $defaultPreferences['stubthreshold'] =
509 'type' => 'selectorother',
510 'section' => 'rendering',
511 'options' => $stubThresholdOptions,
512 'label' => wfMsg('stub-threshold'), // Raw HTML message. Yay?
514 $defaultPreferences['highlightbroken'] =
517 'section' => 'rendering',
518 'label' => wfMsg('tog-highlightbroken'), // Raw HTML
520 $defaultPreferences['showtoc'] =
523 'section' => 'rendering',
524 'label-message' => 'tog-showtoc',
526 $defaultPreferences['nocache'] =
529 'label-message' => 'tog-nocache',
530 'section' => 'rendering',
532 $defaultPreferences['showhiddencats'] =
535 'section' => 'rendering',
536 'label-message' => 'tog-showhiddencats'
538 $defaultPreferences['showjumplinks'] =
541 'section' => 'rendering',
542 'label-message' => 'tog-showjumplinks',
544 $defaultPreferences['justify'] =
547 'section' => 'rendering',
548 'label-message' => 'tog-justify',
550 $defaultPreferences['numberheadings'] =
553 'section' => 'rendering',
554 'label-message' => 'tog-numberheadings',
558 static function editingPreferences( $user, &$defaultPreferences ) {
559 ## Editing #####################################
560 $defaultPreferences['cols'] =
563 'label-message' => 'columns',
564 'section' => 'editing/textboxsize',
568 $defaultPreferences['rows'] =
571 'label-message' => 'rows',
572 'section' => 'editing/textboxsize',
576 $defaultPreferences['previewontop'] =
579 'section' => 'editing',
580 'label-message' => 'tog-previewontop',
582 $defaultPreferences['previewonfirst'] =
585 'section' => 'editing',
586 'label-message' => 'tog-previewonfirst',
588 $defaultPreferences['editsection'] =
591 'section' => 'editing',
592 'label-message' => 'tog-editsection',
594 $defaultPreferences['editsectiononrightclick'] =
597 'section' => 'editing',
598 'label-message' => 'tog-editsectiononrightclick',
600 $defaultPreferences['editondblclick'] =
603 'section' => 'editing',
604 'label-message' => 'tog-editondblclick',
606 $defaultPreferences['editwidth'] =
609 'section' => 'editing',
610 'label-message' => 'tog-editwidth',
612 $defaultPreferences['showtoolbar'] =
615 'section' => 'editing',
616 'label-message' => 'tog-showtoolbar',
618 $defaultPreferences['minordefault'] =
621 'section' => 'editing',
622 'label-message' => 'tog-minordefault',
624 $defaultPreferences['externaleditor'] =
627 'section' => 'editing',
628 'label-message' => 'tog-externaleditor',
630 $defaultPreferences['externaldiff'] =
633 'section' => 'editing',
634 'label-message' => 'tog-externaldiff',
636 $defaultPreferences['forceeditsummary'] =
639 'section' => 'editing',
640 'label-message' => 'tog-forceeditsummary',
642 $defaultPreferences['uselivepreview'] =
645 'section' => 'editing',
646 'label-message' => 'tog-uselivepreview',
650 static function rcPreferences( $user, &$defaultPreferences ) {
651 global $wgRCMaxAge, $wgUseRCPatrol;
652 ## RecentChanges #####################################
653 $defaultPreferences['rcdays'] =
656 'label-message' => 'recentchangesdays',
659 'max' => ceil($wgRCMaxAge / (3600*24)),
661 $defaultPreferences['rclimit'] =
664 'label-message' => 'recentchangescount',
667 $defaultPreferences['usenewrc'] =
670 'label-message' => 'tog-usenewrc',
673 $defaultPreferences['hideminor'] =
676 'label-message' => 'tog-hideminor',
680 global $wgUseRCPatrol;
681 if ($wgUseRCPatrol) {
682 $defaultPreferences['hidepatrolled'] =
686 'label-message' => 'tog-hidepatrolled',
688 $defaultPreferences['newpageshidepatrolled'] =
692 'label-message' => 'tog-newpageshidepatrolled',
696 global $wgRCShowWatchingUsers;
697 if ($wgRCShowWatchingUsers) {
698 $defaultPreferences['shownumberswatching'] =
702 'label-message' => 'tog-shownumberswatching',
707 static function watchlistPreferences( $user, &$defaultPreferences ) {
708 global $wgUseRCPatrol;
709 ## Watchlist #####################################
710 $defaultPreferences['wllimit'] =
715 'label-message' => 'prefs-watchlist-edits',
716 'section' => 'watchlist'
718 $defaultPreferences['watchlistdays'] =
723 'section' => 'watchlist',
724 'label-message' => 'prefs-watchlist-days',
726 $defaultPreferences['extendwatchlist'] =
729 'section' => 'watchlist',
730 'label-message' => 'tog-extendwatchlist',
732 $defaultPreferences['watchlisthideminor'] =
735 'section' => 'watchlist',
736 'label-message' => 'tog-watchlisthideminor',
738 $defaultPreferences['watchlisthidebots'] =
741 'section' => 'watchlist',
742 'label-message' => 'tog-watchlisthidebots',
744 $defaultPreferences['watchlisthideown'] =
747 'section' => 'watchlist',
748 'label-message' => 'tog-watchlisthideown',
750 $defaultPreferences['watchlisthideanons'] =
753 'section' => 'watchlist',
754 'label-message' => 'tog-watchlisthideanons',
756 $defaultPreferences['watchlisthideliu'] =
759 'section' => 'watchlist',
760 'label-message' => 'tog-watchlisthideliu',
763 if ( $wgUseRCPatrol ) {
764 $defaultPreferences['watchlisthidepatrolled'] =
767 'section' => 'watchlist',
768 'label-message' => 'tog-watchlisthidepatrolled',
772 $watchTypes = array( 'edit' => 'watchdefault',
773 'move' => 'watchmoves',
774 'delete' => 'watchdeletion' );
777 if( $user->isAllowed( 'createpage' ) ||
$user->isAllowed( 'createtalk' ) ) {
778 $watchTypes['read'] = 'watchcreations';
781 foreach( $watchTypes as $action => $pref ) {
782 if ( $user->isAllowed( $action ) ) {
783 $defaultPreferences[$pref] = array(
785 'section' => 'watchlist',
786 'label-message' => "tog-$pref",
792 static function searchPreferences( $user, &$defaultPreferences ) {
795 ## Search #####################################
796 $defaultPreferences['searchlimit'] =
799 'label-message' => 'resultsperpage',
800 'section' => 'searchoptions',
803 $defaultPreferences['contextlines'] =
806 'label-message' => 'contextlines',
807 'section' => 'searchoptions',
810 $defaultPreferences['contextchars'] =
813 'label-message' => 'contextchars',
814 'section' => 'searchoptions',
818 // Searchable namespaces back-compat with old format
819 $searchableNamespaces = SearchEngine
::searchableNamespaces();
821 $nsOptions = array();
822 foreach( $wgContLang->getNamespaces() as $ns => $name ) {
823 if ($ns < 0) continue;
824 $displayNs = str_replace( '_', ' ', $name );
826 if (!$displayNs) $displayNs = wfMsg( 'blanknamespace' );
828 $nsOptions[$displayNs] = $ns;
831 $defaultPreferences['searchnamespaces'] =
833 'type' => 'multiselect',
834 'label-message' => 'defaultns',
835 'options' => $nsOptions,
836 'section' => 'searchoptions',
837 'prefix' => 'searchNs',
840 global $wgEnableMWSuggest;
841 if ($wgEnableMWSuggest) {
842 $defaultPreferences['disablesuggest'] =
845 'label-message' => 'mwsuggest-disable',
846 'section' => 'searchoptions',
851 static function miscPreferences( $user, &$defaultPreferences ) {
852 ## Misc #####################################
853 $defaultPreferences['diffonly'] =
857 'label-message' => 'tog-diffonly',
859 $defaultPreferences['norollbackdiff'] =
863 'label-message' => 'tog-norollbackdiff',
867 static function generateSkinOptions( $user ) {
868 global $wgDefaultSkin;
871 $mptitle = Title
::newMainPage();
872 $previewtext = wfMsg( 'skin-preview' );
873 # Only show members of Skin::getSkinNames() rather than
874 # $skinNames (skins is all skin names from Language.php)
875 $validSkinNames = Skin
::getUsableSkins();
876 # Sort by UI skin name. First though need to update validSkinNames as sometimes
877 # the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI).
878 foreach ( $validSkinNames as $skinkey => &$skinname ) {
879 $msgName = "skinname-{$skinkey}";
880 $localisedSkinName = wfMsg( $msgName );
881 if ( !wfEmptyMsg( $msgName, $localisedSkinName ) ) {
882 $skinname = $localisedSkinName;
885 asort($validSkinNames);
886 $sk = $user->getSkin();
888 foreach( $validSkinNames as $skinkey => $sn ) {
889 $mplink = htmlspecialchars( $mptitle->getLocalURL( "useskin=$skinkey" ) );
890 $previewlink = "(<a target='_blank' href=\"$mplink\">$previewtext</a>)";
892 global $wgAllowUserCss, $wgAllowUserJs;
893 if( $wgAllowUserCss ) {
894 $cssPage = Title
::makeTitleSafe( NS_USER
, $user->getName().'/'.$skinkey.'.css' );
895 $customCSS = $sk->makeLinkObj( $cssPage, wfMsgExt('prefs-custom-css', array() ) );
896 $extraLinks .= " ($customCSS)";
898 if( $wgAllowUserJs ) {
899 $jsPage = Title
::makeTitleSafe( NS_USER
, $user->getName().'/'.$skinkey.'.js' );
900 $customJS = $sk->makeLinkObj( $jsPage, wfMsgHtml('prefs-custom-js') );
901 $extraLinks .= " ($customJS)";
903 if( $skinkey == $wgDefaultSkin )
904 $sn .= ' (' . wfMsg( 'default' ) . ')';
905 $display = "$sn $previewlink{$extraLinks}";
906 $ret[$display] = $skinkey;
912 static function getDateOptions() {
914 $dateopts = $wgLang->getDatePreferences();
920 $epoch = '20010115161234'; # Wikipedia day
921 foreach( $dateopts as $key ) {
922 if( $key == 'default' ) {
923 $formatted = wfMsg( 'datedefault' );
925 $formatted = $wgLang->timeanddate( $epoch, false, $key );
927 $ret[$formatted] = $key;
933 static function getImageSizes() {
934 global $wgImageLimits;
938 foreach ( $wgImageLimits as $index => $limits ) {
939 $display = "{$limits[0]}×{$limits[1]}" . wfMsg('unit-pixel');
940 $ret[$display] = $index;
946 static function getThumbSizes() {
947 global $wgThumbLimits;
951 foreach ( $wgThumbLimits as $index => $size ) {
952 $display = $size . wfMsg('unit-pixel');
953 $ret[$display] = $index;
959 static function validateSignature( $signature, $alldata ) {
960 global $wgParser, $wgMaxSigChars, $wgLang;
961 if( mb_strlen( $signature ) > $wgMaxSigChars ) {
963 Xml
::element( 'span', array( 'class' => 'error' ),
964 wfMsgExt( 'badsiglength', 'parsemag',
965 $wgLang->formatNum( $wgMaxSigChars )
968 } elseif( !empty( $alldata['fancysig'] ) &&
969 false === $wgParser->validateSig( $signature ) ) {
970 return Xml
::element( 'span', array( 'class' => 'error' ), wfMsg( 'badsig' ) );
976 static function cleanSignature( $signature, $alldata ) {
978 if( $alldata['fancysig'] ) {
979 $signature = $wgParser->cleanSig( $signature );
981 // When no fancy sig used, make sure ~{3,5} get removed.
982 $signature = $wgParser->cleanSigInSig( $signature );
988 static function validateEmail( $email, $alldata ) {
989 global $wgUser; // To check
991 if ( $email && !$wgUser->isValidEmailAddr( $email ) ) {
992 return wfMsgExt( 'invalidemailaddress', 'parseinline' );
995 global $wgEmailConfirmToEdit;
996 if( $wgEmailConfirmToEdit && !$email ) {
997 return wfMsgExt( 'noemailtitle', 'parseinline' );
1002 static function getFormObject( $user ) {
1003 $formDescriptor = Preferences
::getPreferences( $user );
1004 $htmlForm = new PreferencesForm( $formDescriptor, 'prefs' );
1006 $htmlForm->setSubmitText( wfMsg('saveprefs') );
1007 $htmlForm->setTitle( SpecialPage
::getTitleFor( 'Preferences' ) );
1008 $htmlForm->setSubmitID( 'prefsubmit' );
1009 $htmlForm->setSubmitCallback( array( 'Preferences', 'tryFormSubmit' ) );
1014 static function getTimezoneOptions() {
1017 global $wgLocalTZoffset;
1019 $opt[wfMsg( 'timezoneuseserverdefault' )] = "System|$wgLocalTZoffset";
1020 $opt[wfMsg( 'timezoneuseoffset' )] = 'other';
1021 $opt[wfMsg( 'guesstimezone' )] = 'guess';
1023 if ( function_exists( 'timezone_identifiers_list' ) ) {
1024 # Read timezone list
1025 $tzs = timezone_identifiers_list();
1028 $tzRegions = array();
1029 $tzRegions['Africa'] = wfMsg( 'timezoneregion-africa' );
1030 $tzRegions['America'] = wfMsg( 'timezoneregion-america' );
1031 $tzRegions['Antarctica'] = wfMsg( 'timezoneregion-antarctica' );
1032 $tzRegions['Arctic'] = wfMsg( 'timezoneregion-arctic' );
1033 $tzRegions['Asia'] = wfMsg( 'timezoneregion-asia' );
1034 $tzRegions['Atlantic'] = wfMsg( 'timezoneregion-atlantic' );
1035 $tzRegions['Australia'] = wfMsg( 'timezoneregion-australia' );
1036 $tzRegions['Europe'] = wfMsg( 'timezoneregion-europe' );
1037 $tzRegions['Indian'] = wfMsg( 'timezoneregion-indian' );
1038 $tzRegions['Pacific'] = wfMsg( 'timezoneregion-pacific' );
1039 asort( $tzRegions );
1041 $prefill = array_fill_keys( array_values($tzRegions), array() );
1042 $opt = array_merge( $opt, $prefill );
1044 $now = date_create( 'now' );
1046 foreach ( $tzs as $tz ) {
1047 $z = explode( '/', $tz, 2 );
1049 # timezone_identifiers_list() returns a number of
1050 # backwards-compatibility entries. This filters them out of the
1051 # list presented to the user.
1052 if ( count( $z ) != 2 ||
!array_key_exists( $z[0], $tzRegions ) )
1056 $z[0] = $tzRegions[$z[0]];
1058 $minDiff = floor( timezone_offset_get( timezone_open( $tz ), $now ) / 60 );
1060 $display = str_replace( '_', ' ', $z[0] . '/' . $z[1] );
1061 $value = "ZoneInfo|$minDiff|$tz";
1063 $opt[$z[0]][$display] = $value;
1069 static function filterTimezoneInput( $tz, $alldata ) {
1070 $data = explode( '|', $tz, 3 );
1071 switch ( $data[0] ) {
1076 $data = explode( ':', $tz, 2 );
1078 if( count( $data ) == 2 ) {
1079 $data[0] = intval( $data[0] );
1080 $data[1] = intval( $data[1] );
1081 $minDiff = abs( $data[0] ) * 60 +
$data[1];
1082 if ( $data[0] < 0 ) $minDiff = -$minDiff;
1084 $minDiff = intval( $data[0] ) * 60;
1087 # Max is +14:00 and min is -12:00, see:
1088 # http://en.wikipedia.org/wiki/Timezone
1089 $minDiff = min( $minDiff, 840 ); # 14:00
1090 $minDiff = max( $minDiff, -720 ); # -12:00
1091 return 'Offset|'.$minDiff;
1095 static function tryFormSubmit( $formData, $entryPoint = 'internal' ) {
1096 global $wgUser, $wgEmailAuthentication, $wgEnableEmail;
1101 foreach( array_keys($formData) as $name ) {
1102 if ( isset(self
::$saveFilters[$name]) ) {
1104 call_user_func( self
::$saveFilters[$name], $formData[$name], $formData );
1108 // Stuff that shouldn't be saved as a preference.
1109 $saveBlacklist = array(
1114 if( $wgEnableEmail ) {
1115 $newadr = $formData['emailaddress'];
1116 $oldadr = $wgUser->getEmail();
1117 if( ($newadr != '') && ($newadr != $oldadr) ) {
1118 # the user has supplied a new email address on the login page
1119 # new behaviour: set this new emailaddr from login-page into user database record
1120 $wgUser->setEmail( $newadr );
1121 # but flag as "dirty" = unauthenticated
1122 $wgUser->invalidateEmail();
1123 if ($wgEmailAuthentication) {
1124 # Mail a temporary password to the dirty address.
1125 # User can come back through the confirmation URL to re-enable email.
1126 $result = $wgUser->sendConfirmationMail();
1127 if( WikiError
::isError( $result ) ) {
1128 return wfMsg( 'mailerror', htmlspecialchars( $result->getMessage() ) );
1129 } elseif ($entryPoint == 'ui') {
1134 $wgUser->setEmail( $newadr );
1136 if( $oldadr != $newadr ) {
1137 wfRunHooks( 'PrefsEmailAudit', array( $wgUser, $oldadr, $newadr ) );
1141 // Fortunately, the realname field is MUCH simpler
1142 global $wgAllowRealName;
1143 if ($wgAllowRealName) {
1144 $realName = $formData['realname'];
1145 $wgUser->setRealName( $realName );
1148 foreach( $saveBlacklist as $b )
1149 unset( $formData[$b] );
1151 // Keeps old preferences from interfering due to back-compat
1153 $wgUser->resetOptions();
1155 foreach( $formData as $key => $value ) {
1156 $wgUser->setOption( $key, $value );
1159 $wgUser->saveSettings();
1164 public static function tryUISubmit( $formData ) {
1165 $res = self
::tryFormSubmit( $formData, 'ui' );
1168 $urlOptions = array( 'success' );
1169 if ($res === 'eauth')
1170 $urlOptions[] = 'eauth';
1172 $queryString = implode( '&', $urlOptions );
1174 $url = SpecialPage
::getTitleFor( 'Preferences' )->getFullURL( $queryString );
1176 $wgOut->redirect( $url );
1182 public static function loadOldSearchNs( $user ) {
1183 $searchableNamespaces = SearchEngine
::searchableNamespaces();
1184 // Back compat with old format
1187 foreach( $searchableNamespaces as $ns => $name ) {
1188 if( $user->getOption( 'searchNs' . $ns ) ) {
1197 /** Some tweaks to allow js prefs to work */
1198 class PreferencesForm
extends HTMLForm
{
1200 function wrapForm( $html ) {
1201 $html = Xml
::tags( 'div', array( 'id' => 'preferences' ), $html );
1203 return parent
::wrapForm( $html );
1206 function getButtons() {
1207 $html = parent
::getButtons();
1211 $sk = $wgUser->getSkin();
1212 $t = SpecialPage
::getTitleFor( 'Preferences', 'reset' );
1214 $html .= "\n" . $sk->link( $t, wfMsg( 'restoreprefs' ) );
1219 function filterDataForSubmit( $data ) {
1220 // Support for separating MultiSelect preferences into multiple preferences
1221 // Due to lack of array support.
1222 foreach( $this->mFlatFields
as $fieldname => $field ) {
1223 $info = $field->mParams
;
1224 if ($field instanceof HTMLMultiSelectField
) {
1225 $options = HTMLFormField
::flattenOptions( $info['options'] );
1226 $prefix = isset($info['prefix']) ?
$info['prefix'] : $fieldname;
1228 foreach( $options as $opt ) {
1229 $data["$prefix$opt"] = in_array( $opt, $data[$fieldname] );
1232 unset( $data[$fieldname] );