3 * Form to edit user preferences.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 * We're now using the HTMLForm object with some customisation to generate the
25 * Preferences form. This object handles generic submission, CSRF protection,
26 * layout and other logic in a reusable manner. We subclass it as a PreferencesForm
27 * to make some minor customisations.
29 * In order to generate the form, the HTMLForm object needs an array structure
30 * detailing the form fields available, and that's what this class is for. Each
31 * element of the array is a basic property-list, including the type of field,
32 * the label it is to be given in the form, callbacks for validation and
33 * 'filtering', and other pertinent information. Note that the 'default' field
34 * is named for generic forms, and does not represent the preference's default
35 * (which is stored in $wgDefaultUserOptions), but the default for the form
36 * field, which should be whatever the user has set for that preference. There
37 * is no need to override it unless you have some special storage logic (for
38 * instance, those not presently stored as options, but which are best set from
39 * the user preferences view).
41 * Field types are implemented as subclasses of the generic HTMLFormField
42 * object, and typically implement at least getInputHTML, which generates the
43 * HTML for the input field to be placed in the table.
45 * Once fields have been retrieved and validated, submission logic is handed
46 * over to the tryUISubmit static method of this class.
49 static $defaultPreferences = null;
50 static $saveFilters = array(
51 'timecorrection' => array( 'Preferences', 'filterTimezoneInput' ),
52 'cols' => array( 'Preferences', 'filterIntval' ),
53 'rows' => array( 'Preferences', 'filterIntval' ),
54 'rclimit' => array( 'Preferences', 'filterIntval' ),
55 'wllimit' => array( 'Preferences', 'filterIntval' ),
56 'searchlimit' => array( 'Preferences', 'filterIntval' ),
59 // Stuff that shouldn't be saved as a preference.
60 private static $saveBlacklist = array(
68 * @param $context IContextSource
71 static function getPreferences( $user, IContextSource
$context ) {
72 if ( self
::$defaultPreferences ) {
73 return self
::$defaultPreferences;
76 $defaultPreferences = array();
78 self
::profilePreferences( $user, $context, $defaultPreferences );
79 self
::skinPreferences( $user, $context, $defaultPreferences );
80 self
::filesPreferences( $user, $context, $defaultPreferences );
81 self
::datetimePreferences( $user, $context, $defaultPreferences );
82 self
::renderingPreferences( $user, $context, $defaultPreferences );
83 self
::editingPreferences( $user, $context, $defaultPreferences );
84 self
::rcPreferences( $user, $context, $defaultPreferences );
85 self
::watchlistPreferences( $user, $context, $defaultPreferences );
86 self
::searchPreferences( $user, $context, $defaultPreferences );
87 self
::miscPreferences( $user, $context, $defaultPreferences );
89 wfRunHooks( 'GetPreferences', array( $user, &$defaultPreferences ) );
91 ## Remove preferences that wikis don't want to use
92 global $wgHiddenPrefs;
93 foreach ( $wgHiddenPrefs as $pref ) {
94 if ( isset( $defaultPreferences[$pref] ) ) {
95 unset( $defaultPreferences[$pref] );
99 ## Make sure that form fields have their parent set. See bug 41337.
100 $dummyForm = new HTMLForm( array(), $context );
102 $disable = !$user->isAllowed( 'editmyoptions' );
104 ## Prod in defaults from the user
105 foreach ( $defaultPreferences as $name => &$info ) {
106 $prefFromUser = self
::getOptionFromUser( $name, $info, $user );
107 if ( $disable && !in_array( $name, self
::$saveBlacklist ) ) {
108 $info['disabled'] = 'disabled';
110 $field = HTMLForm
::loadInputFromParameters( $name, $info ); // For validation
111 $field->mParent
= $dummyForm;
112 $defaultOptions = User
::getDefaultOptions();
113 $globalDefault = isset( $defaultOptions[$name] )
114 ?
$defaultOptions[$name]
117 // If it validates, set it as the default
118 if ( isset( $info['default'] ) ) {
119 // Already set, no problem
121 } elseif ( !is_null( $prefFromUser ) && // Make sure we're not just pulling nothing
122 $field->validate( $prefFromUser, $user->getOptions() ) === true ) {
123 $info['default'] = $prefFromUser;
124 } elseif ( $field->validate( $globalDefault, $user->getOptions() ) === true ) {
125 $info['default'] = $globalDefault;
127 throw new MWException( "Global default '$globalDefault' is invalid for field $name" );
131 self
::$defaultPreferences = $defaultPreferences;
133 return $defaultPreferences;
137 * Pull option from a user account. Handles stuff like array-type preferences.
142 * @return array|String
144 static function getOptionFromUser( $name, $info, $user ) {
145 $val = $user->getOption( $name );
147 // Handling for multiselect preferences
148 if ( ( isset( $info['type'] ) && $info['type'] == 'multiselect' ) ||
149 ( isset( $info['class'] ) && $info['class'] == 'HTMLMultiSelectField' ) ) {
150 $options = HTMLFormField
::flattenOptions( $info['options'] );
151 $prefix = isset( $info['prefix'] ) ?
$info['prefix'] : $name;
154 foreach ( $options as $value ) {
155 if ( $user->getOption( "$prefix$value" ) ) {
161 // Handling for checkmatrix preferences
162 if ( ( isset( $info['type'] ) && $info['type'] == 'checkmatrix' ) ||
163 ( isset( $info['class'] ) && $info['class'] == 'HTMLCheckMatrix' ) ) {
164 $columns = HTMLFormField
::flattenOptions( $info['columns'] );
165 $rows = HTMLFormField
::flattenOptions( $info['rows'] );
166 $prefix = isset( $info['prefix'] ) ?
$info['prefix'] : $name;
169 foreach ( $columns as $column ) {
170 foreach ( $rows as $row ) {
171 if ( $user->getOption( "$prefix$column-$row" ) ) {
172 $val[] = "$column-$row";
183 * @param $context IContextSource
184 * @param $defaultPreferences
187 static function profilePreferences( $user, IContextSource
$context, &$defaultPreferences ) {
188 global $wgAuth, $wgContLang, $wgParser, $wgCookieExpiration, $wgLanguageCode,
189 $wgDisableTitleConversion, $wgDisableLangConversion, $wgMaxSigChars,
190 $wgEnableEmail, $wgEmailConfirmToEdit, $wgEnableUserEmail, $wgEmailAuthentication,
191 $wgEnotifWatchlist, $wgEnotifUserTalk, $wgEnotifRevealEditorAddress,
194 // retrieving user name for GENDER and misc.
195 $userName = $user->getName();
197 ## User info #####################################
199 $defaultPreferences['username'] = array(
201 'label-message' => array( 'username', $userName ),
202 'default' => $userName,
203 'section' => 'personal/info',
206 $defaultPreferences['userid'] = array(
208 'label-message' => array( 'uid', $userName ),
209 'default' => $user->getId(),
210 'section' => 'personal/info',
213 # Get groups to which the user belongs
214 $userEffectiveGroups = $user->getEffectiveGroups();
215 $userGroups = $userMembers = array();
216 foreach ( $userEffectiveGroups as $ueg ) {
218 // Skip the default * group, seems useless here
221 $groupName = User
::getGroupName( $ueg );
222 $userGroups[] = User
::makeGroupLinkHTML( $ueg, $groupName );
224 $memberName = User
::getGroupMember( $ueg, $userName );
225 $userMembers[] = User
::makeGroupLinkHTML( $ueg, $memberName );
227 asort( $userGroups );
228 asort( $userMembers );
230 $lang = $context->getLanguage();
232 $defaultPreferences['usergroups'] = array(
234 'label' => $context->msg( 'prefs-memberingroups' )->numParams(
235 count( $userGroups ) )->params( $userName )->parse(),
236 'default' => $context->msg( 'prefs-memberingroups-type',
237 $lang->commaList( $userGroups ),
238 $lang->commaList( $userMembers )
241 'section' => 'personal/info',
244 $editCount = Linker
::link( SpecialPage
::getTitleFor( "Contributions", $userName ),
245 $lang->formatNum( $user->getEditCount() ) );
247 $defaultPreferences['editcount'] = array(
250 'label-message' => 'prefs-edits',
251 'default' => $editCount,
252 'section' => 'personal/info',
255 if ( $user->getRegistration() ) {
256 $displayUser = $context->getUser();
257 $userRegistration = $user->getRegistration();
258 $defaultPreferences['registrationdate'] = array(
260 'label-message' => 'prefs-registration',
261 'default' => $context->msg(
262 'prefs-registration-date-time',
263 $lang->userTimeAndDate( $userRegistration, $displayUser ),
264 $lang->userDate( $userRegistration, $displayUser ),
265 $lang->userTime( $userRegistration, $displayUser )
267 'section' => 'personal/info',
271 $canViewPrivateInfo = $user->isAllowed( 'viewmyprivateinfo' );
272 $canEditPrivateInfo = $user->isAllowed( 'editmyprivateinfo' );
274 // Actually changeable stuff
275 $defaultPreferences['realname'] = array(
276 // (not really "private", but still shouldn't be edited without permission)
277 'type' => $canEditPrivateInfo && $wgAuth->allowPropChange( 'realname' ) ?
'text' : 'info',
278 'default' => $user->getRealName(),
279 'section' => 'personal/info',
280 'label-message' => 'yourrealname',
281 'help-message' => 'prefs-help-realname',
284 if ( $canEditPrivateInfo && $wgAuth->allowPasswordChange() ) {
285 $link = Linker
::link( SpecialPage
::getTitleFor( 'ChangePassword' ),
286 $context->msg( 'prefs-resetpass' )->escaped(), array(),
287 array( 'returnto' => SpecialPage
::getTitleFor( 'Preferences' )->getPrefixedText() ) );
289 $defaultPreferences['password'] = array(
293 'label-message' => 'yourpassword',
294 'section' => 'personal/info',
297 if ( $wgCookieExpiration > 0 ) {
298 $defaultPreferences['rememberpassword'] = array(
300 'label' => $context->msg( 'tog-rememberpassword' )->numParams(
301 ceil( $wgCookieExpiration / ( 3600 * 24 ) ) )->text(),
302 'section' => 'personal/info',
305 // Only show preferhttps if secure login is turned on
306 if ( $wgSecureLogin && wfCanIPUseHTTPS( $context->getRequest()->getIP() ) ) {
307 $defaultPreferences['prefershttps'] = array(
309 'label-message' => 'tog-prefershttps',
310 'help-message' => 'prefs-help-prefershttps',
311 'section' => 'personal/info'
316 $languages = Language
::fetchLanguageNames( null, 'mw' );
317 if ( !array_key_exists( $wgLanguageCode, $languages ) ) {
318 $languages[$wgLanguageCode] = $wgLanguageCode;
323 foreach ( $languages as $code => $name ) {
324 $display = wfBCP47( $code ) . ' - ' . $name;
325 $options[$display] = $code;
327 $defaultPreferences['language'] = array(
329 'section' => 'personal/i18n',
330 'options' => $options,
331 'label-message' => 'yourlanguage',
334 $defaultPreferences['gender'] = array(
336 'section' => 'personal/i18n',
338 $context->msg( 'parentheses',
339 $context->msg( 'gender-unknown' )->text()
340 )->text() => 'unknown',
341 $context->msg( 'gender-female' )->text() => 'female',
342 $context->msg( 'gender-male' )->text() => 'male',
344 'label-message' => 'yourgender',
345 'help-message' => 'prefs-help-gender',
348 // see if there are multiple language variants to choose from
349 if ( !$wgDisableLangConversion ) {
350 foreach ( LanguageConverter
::$languagesWithVariants as $langCode ) {
351 if ( $langCode == $wgContLang->getCode() ) {
352 $variants = $wgContLang->getVariants();
354 if ( count( $variants ) <= 1 ) {
358 $variantArray = array();
359 foreach ( $variants as $v ) {
360 $v = str_replace( '_', '-', strtolower( $v ) );
361 $variantArray[$v] = $lang->getVariantname( $v, false );
365 foreach ( $variantArray as $code => $name ) {
366 $display = wfBCP47( $code ) . ' - ' . $name;
367 $options[$display] = $code;
370 $defaultPreferences['variant'] = array(
371 'label-message' => 'yourvariant',
373 'options' => $options,
374 'section' => 'personal/i18n',
375 'help-message' => 'prefs-help-variant',
378 if ( !$wgDisableTitleConversion ) {
379 $defaultPreferences['noconvertlink'] = array(
381 'section' => 'personal/i18n',
382 'label-message' => 'tog-noconvertlink',
386 $defaultPreferences["variant-$langCode"] = array(
393 // show a preview of the old signature first
394 $oldsigWikiText = $wgParser->preSaveTransform( "~~~", $context->getTitle(), $user, ParserOptions
::newFromContext( $context ) );
395 $oldsigHTML = $context->getOutput()->parseInline( $oldsigWikiText, true, true );
396 $defaultPreferences['oldsig'] = array(
399 'label-message' => 'tog-oldsig',
400 'default' => $oldsigHTML,
401 'section' => 'personal/signature',
403 $defaultPreferences['nickname'] = array(
404 'type' => $wgAuth->allowPropChange( 'nickname' ) ?
'text' : 'info',
405 'maxlength' => $wgMaxSigChars,
406 'label-message' => 'yournick',
407 'validation-callback' => array( 'Preferences', 'validateSignature' ),
408 'section' => 'personal/signature',
409 'filter-callback' => array( 'Preferences', 'cleanSignature' ),
411 $defaultPreferences['fancysig'] = array(
413 'label-message' => 'tog-fancysig',
414 'help-message' => 'prefs-help-signature', // show general help about signature at the bottom of the section
415 'section' => 'personal/signature'
420 if ( $wgEnableEmail ) {
421 if ( $canViewPrivateInfo ) {
422 $helpMessages[] = $wgEmailConfirmToEdit
423 ?
'prefs-help-email-required'
424 : 'prefs-help-email';
426 if ( $wgEnableUserEmail ) {
427 // additional messages when users can send email to each other
428 $helpMessages[] = 'prefs-help-email-others';
431 $emailAddress = $user->getEmail() ?
htmlspecialchars( $user->getEmail() ) : '';
432 if ( $canEditPrivateInfo && $wgAuth->allowPropChange( 'emailaddress' ) ) {
433 $link = Linker
::link(
434 SpecialPage
::getTitleFor( 'ChangeEmail' ),
435 $context->msg( $user->getEmail() ?
'prefs-changeemail' : 'prefs-setemail' )->escaped(),
437 array( 'returnto' => SpecialPage
::getTitleFor( 'Preferences' )->getPrefixedText() ) );
439 $emailAddress .= $emailAddress == '' ?
$link : (
440 $context->msg( 'word-separator' )->plain()
441 . $context->msg( 'parentheses' )->rawParams( $link )->plain()
445 $defaultPreferences['emailaddress'] = array(
448 'default' => $emailAddress,
449 'label-message' => 'youremail',
450 'section' => 'personal/email',
451 'help-messages' => $helpMessages,
452 # 'cssclass' chosen below
456 $disableEmailPrefs = false;
458 if ( $wgEmailAuthentication ) {
459 $emailauthenticationclass = 'mw-email-not-authenticated';
460 if ( $user->getEmail() ) {
461 if ( $user->getEmailAuthenticationTimestamp() ) {
462 // date and time are separate parameters to facilitate localisation.
463 // $time is kept for backward compat reasons.
464 // 'emailauthenticated' is also used in SpecialConfirmemail.php
465 $displayUser = $context->getUser();
466 $emailTimestamp = $user->getEmailAuthenticationTimestamp();
467 $time = $lang->userTimeAndDate( $emailTimestamp, $displayUser );
468 $d = $lang->userDate( $emailTimestamp, $displayUser );
469 $t = $lang->userTime( $emailTimestamp, $displayUser );
470 $emailauthenticated = $context->msg( 'emailauthenticated',
471 $time, $d, $t )->parse() . '<br />';
472 $disableEmailPrefs = false;
473 $emailauthenticationclass = 'mw-email-authenticated';
475 $disableEmailPrefs = true;
476 $emailauthenticated = $context->msg( 'emailnotauthenticated' )->parse() . '<br />' .
478 SpecialPage
::getTitleFor( 'Confirmemail' ),
479 $context->msg( 'emailconfirmlink' )->escaped()
481 $emailauthenticationclass = "mw-email-not-authenticated";
484 $disableEmailPrefs = true;
485 $emailauthenticated = $context->msg( 'noemailprefs' )->escaped();
486 $emailauthenticationclass = 'mw-email-none';
489 if ( $canViewPrivateInfo ) {
490 $defaultPreferences['emailauthentication'] = array(
493 'section' => 'personal/email',
494 'label-message' => 'prefs-emailconfirm-label',
495 'default' => $emailauthenticated,
496 # Apply the same CSS class used on the input to the message:
497 'cssclass' => $emailauthenticationclass,
499 $defaultPreferences['emailaddress']['cssclass'] = $emailauthenticationclass;
503 if ( $wgEnableUserEmail && $user->isAllowed( 'sendemail' ) ) {
504 $defaultPreferences['disablemail'] = array(
507 'section' => 'personal/email',
508 'label-message' => 'allowemail',
509 'disabled' => $disableEmailPrefs,
511 $defaultPreferences['ccmeonemails'] = array(
513 'section' => 'personal/email',
514 'label-message' => 'tog-ccmeonemails',
515 'disabled' => $disableEmailPrefs,
519 if ( $wgEnotifWatchlist ) {
520 $defaultPreferences['enotifwatchlistpages'] = array(
522 'section' => 'personal/email',
523 'label-message' => 'tog-enotifwatchlistpages',
524 'disabled' => $disableEmailPrefs,
527 if ( $wgEnotifUserTalk ) {
528 $defaultPreferences['enotifusertalkpages'] = array(
530 'section' => 'personal/email',
531 'label-message' => 'tog-enotifusertalkpages',
532 'disabled' => $disableEmailPrefs,
535 if ( $wgEnotifUserTalk ||
$wgEnotifWatchlist ) {
536 $defaultPreferences['enotifminoredits'] = array(
538 'section' => 'personal/email',
539 'label-message' => 'tog-enotifminoredits',
540 'disabled' => $disableEmailPrefs,
543 if ( $wgEnotifRevealEditorAddress ) {
544 $defaultPreferences['enotifrevealaddr'] = array(
546 'section' => 'personal/email',
547 'label-message' => 'tog-enotifrevealaddr',
548 'disabled' => $disableEmailPrefs,
557 * @param $context IContextSource
558 * @param $defaultPreferences
561 static function skinPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
562 ## Skin #####################################
563 global $wgAllowUserCss, $wgAllowUserJs;
565 $defaultPreferences['skin'] = array(
567 'options' => self
::generateSkinOptions( $user, $context ),
569 'section' => 'rendering/skin',
572 # Create links to user CSS/JS pages for all skins
573 # This code is basically copied from generateSkinOptions(). It'd
574 # be nice to somehow merge this back in there to avoid redundancy.
575 if ( $wgAllowUserCss ||
$wgAllowUserJs ) {
576 $linkTools = array();
577 $userName = $user->getName();
579 if ( $wgAllowUserCss ) {
580 $cssPage = Title
::makeTitleSafe( NS_USER
, $userName . '/common.css' );
581 $linkTools[] = Linker
::link( $cssPage, $context->msg( 'prefs-custom-css' )->escaped() );
584 if ( $wgAllowUserJs ) {
585 $jsPage = Title
::makeTitleSafe( NS_USER
, $userName . '/common.js' );
586 $linkTools[] = Linker
::link( $jsPage, $context->msg( 'prefs-custom-js' )->escaped() );
589 $defaultPreferences['commoncssjs'] = array(
592 'default' => $context->getLanguage()->pipeList( $linkTools ),
593 'label-message' => 'prefs-common-css-js',
594 'section' => 'rendering/skin',
601 * @param $context IContextSource
602 * @param $defaultPreferences Array
604 static function filesPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
605 ## Files #####################################
606 $defaultPreferences['imagesize'] = array(
608 'options' => self
::getImageSizes( $context ),
609 'label-message' => 'imagemaxsize',
610 'section' => 'rendering/files',
612 $defaultPreferences['thumbsize'] = array(
614 'options' => self
::getThumbSizes( $context ),
615 'label-message' => 'thumbsize',
616 'section' => 'rendering/files',
622 * @param $context IContextSource
623 * @param $defaultPreferences
626 static function datetimePreferences( $user, IContextSource
$context, &$defaultPreferences ) {
627 ## Date and time #####################################
628 $dateOptions = self
::getDateOptions( $context );
629 if ( $dateOptions ) {
630 $defaultPreferences['date'] = array(
632 'options' => $dateOptions,
634 'section' => 'datetime/dateformat',
639 $now = wfTimestampNow();
640 $lang = $context->getLanguage();
641 $nowlocal = Xml
::element( 'span', array( 'id' => 'wpLocalTime' ),
642 $lang->time( $now, true ) );
643 $nowserver = $lang->time( $now, false ) .
644 Html
::hidden( 'wpServerTime', (int)substr( $now, 8, 2 ) * 60 +
(int)substr( $now, 10, 2 ) );
646 $defaultPreferences['nowserver'] = array(
649 'label-message' => 'servertime',
650 'default' => $nowserver,
651 'section' => 'datetime/timeoffset',
654 $defaultPreferences['nowlocal'] = array(
657 'label-message' => 'localtime',
658 'default' => $nowlocal,
659 'section' => 'datetime/timeoffset',
662 // Grab existing pref.
663 $tzOffset = $user->getOption( 'timecorrection' );
664 $tz = explode( '|', $tzOffset, 3 );
666 $tzOptions = self
::getTimezoneOptions( $context );
668 $tzSetting = $tzOffset;
669 if ( count( $tz ) > 1 && $tz[0] == 'Offset' ) {
671 $tzSetting = sprintf( '%+03d:%02d', floor( $minDiff / 60 ), abs( $minDiff ) %
60 );
672 } elseif ( count( $tz ) > 1 && $tz[0] == 'ZoneInfo' &&
673 !in_array( $tzOffset, HTMLFormField
::flattenOptions( $tzOptions ) ) )
675 # Timezone offset can vary with DST
676 $userTZ = timezone_open( $tz[2] );
677 if ( $userTZ !== false ) {
678 $minDiff = floor( timezone_offset_get( $userTZ, date_create( 'now' ) ) / 60 );
679 $tzSetting = "ZoneInfo|$minDiff|{$tz[2]}";
683 $defaultPreferences['timecorrection'] = array(
684 'class' => 'HTMLSelectOrOtherField',
685 'label-message' => 'timezonelegend',
686 'options' => $tzOptions,
687 'default' => $tzSetting,
689 'section' => 'datetime/timeoffset',
695 * @param $context IContextSource
696 * @param $defaultPreferences Array
698 static function renderingPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
699 ## Page Rendering ##############################
700 global $wgAllowUserCssPrefs;
701 if ( $wgAllowUserCssPrefs ) {
702 $defaultPreferences['underline'] = array(
705 $context->msg( 'underline-never' )->text() => 0,
706 $context->msg( 'underline-always' )->text() => 1,
707 $context->msg( 'underline-default' )->text() => 2,
709 'label-message' => 'tog-underline',
710 'section' => 'rendering/advancedrendering',
714 $stubThresholdValues = array( 50, 100, 500, 1000, 2000, 5000, 10000 );
715 $stubThresholdOptions = array( $context->msg( 'stub-threshold-disabled' )->text() => 0 );
716 foreach ( $stubThresholdValues as $value ) {
717 $stubThresholdOptions[$context->msg( 'size-bytes', $value )->text()] = $value;
720 $defaultPreferences['stubthreshold'] = array(
721 'type' => 'selectorother',
722 'section' => 'rendering/advancedrendering',
723 'options' => $stubThresholdOptions,
725 'label-raw' => $context->msg( 'stub-threshold' )->text(), // Raw HTML message. Yay?
728 if ( $wgAllowUserCssPrefs ) {
729 $defaultPreferences['showtoc'] = array(
731 'section' => 'rendering/advancedrendering',
732 'label-message' => 'tog-showtoc',
735 $defaultPreferences['nocache'] = array(
737 'label-message' => 'tog-nocache',
738 'section' => 'rendering/advancedrendering',
740 $defaultPreferences['showhiddencats'] = array(
742 'section' => 'rendering/advancedrendering',
743 'label-message' => 'tog-showhiddencats'
746 if ( $wgAllowUserCssPrefs ) {
747 $defaultPreferences['justify'] = array(
749 'section' => 'rendering/advancedrendering',
750 'label-message' => 'tog-justify',
754 $defaultPreferences['numberheadings'] = array(
756 'section' => 'rendering/advancedrendering',
757 'label-message' => 'tog-numberheadings',
763 * @param $context IContextSource
764 * @param $defaultPreferences Array
766 static function editingPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
767 global $wgAllowUserCssPrefs;
769 ## Editing #####################################
770 if ( $wgAllowUserCssPrefs ) {
771 $defaultPreferences['editsection'] = array(
773 'section' => 'editing/advancedediting',
774 'label-message' => 'tog-editsection',
777 $defaultPreferences['editsectiononrightclick'] = array(
779 'section' => 'editing/advancedediting',
780 'label-message' => 'tog-editsectiononrightclick',
782 $defaultPreferences['editondblclick'] = array(
784 'section' => 'editing/advancedediting',
785 'label-message' => 'tog-editondblclick',
788 if ( $wgAllowUserCssPrefs ) {
789 $defaultPreferences['editfont'] = array(
791 'section' => 'editing/editor',
792 'label-message' => 'editfont-style',
794 $context->msg( 'editfont-default' )->text() => 'default',
795 $context->msg( 'editfont-monospace' )->text() => 'monospace',
796 $context->msg( 'editfont-sansserif' )->text() => 'sans-serif',
797 $context->msg( 'editfont-serif' )->text() => 'serif',
801 $defaultPreferences['cols'] = array(
803 'label-message' => 'columns',
804 'section' => 'editing/editor',
808 $defaultPreferences['rows'] = array(
810 'label-message' => 'rows',
811 'section' => 'editing/editor',
815 if ( $user->isAllowed( 'minoredit' ) ) {
816 $defaultPreferences['minordefault'] = array(
818 'section' => 'editing/editor',
819 'label-message' => 'tog-minordefault',
822 $defaultPreferences['forceeditsummary'] = array(
824 'section' => 'editing/editor',
825 'label-message' => 'tog-forceeditsummary',
827 $defaultPreferences['useeditwarning'] = array(
829 'section' => 'editing/editor',
830 'label-message' => 'tog-useeditwarning',
832 $defaultPreferences['showtoolbar'] = array(
834 'section' => 'editing/editor',
835 'label-message' => 'tog-showtoolbar',
838 $defaultPreferences['previewonfirst'] = array(
840 'section' => 'editing/preview',
841 'label-message' => 'tog-previewonfirst',
843 $defaultPreferences['previewontop'] = array(
845 'section' => 'editing/preview',
846 'label-message' => 'tog-previewontop',
848 $defaultPreferences['uselivepreview'] = array(
850 'section' => 'editing/preview',
851 'label-message' => 'tog-uselivepreview',
858 * @param $context IContextSource
859 * @param $defaultPreferences Array
861 static function rcPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
862 global $wgRCMaxAge, $wgRCShowWatchingUsers;
864 ## RecentChanges #####################################
865 $defaultPreferences['rcdays'] = array(
867 'label-message' => 'recentchangesdays',
868 'section' => 'rc/displayrc',
870 'max' => ceil( $wgRCMaxAge / ( 3600 * 24 ) ),
871 'help' => $context->msg( 'recentchangesdays-max' )->numParams(
872 ceil( $wgRCMaxAge / ( 3600 * 24 ) ) )->text()
874 $defaultPreferences['rclimit'] = array(
876 'label-message' => 'recentchangescount',
877 'help-message' => 'prefs-help-recentchangescount',
878 'section' => 'rc/displayrc',
880 $defaultPreferences['usenewrc'] = array(
882 'label-message' => 'tog-usenewrc',
883 'section' => 'rc/advancedrc',
885 $defaultPreferences['hideminor'] = array(
887 'label-message' => 'tog-hideminor',
888 'section' => 'rc/advancedrc',
891 if ( $user->useRCPatrol() ) {
892 $defaultPreferences['hidepatrolled'] = array(
894 'section' => 'rc/advancedrc',
895 'label-message' => 'tog-hidepatrolled',
897 $defaultPreferences['newpageshidepatrolled'] = array(
899 'section' => 'rc/advancedrc',
900 'label-message' => 'tog-newpageshidepatrolled',
904 if ( $wgRCShowWatchingUsers ) {
905 $defaultPreferences['shownumberswatching'] = array(
907 'section' => 'rc/advancedrc',
908 'label-message' => 'tog-shownumberswatching',
915 * @param $context IContextSource
916 * @param $defaultPreferences
918 static function watchlistPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
919 global $wgUseRCPatrol, $wgEnableAPI, $wgRCMaxAge;
921 $watchlistdaysMax = ceil( $wgRCMaxAge / ( 3600 * 24 ) );
923 ## Watchlist #####################################
924 $defaultPreferences['watchlistdays'] = array(
927 'max' => $watchlistdaysMax,
928 'section' => 'watchlist/displaywatchlist',
929 'help' => $context->msg( 'prefs-watchlist-days-max' )->numParams(
930 $watchlistdaysMax )->text(),
931 'label-message' => 'prefs-watchlist-days',
933 $defaultPreferences['wllimit'] = array(
937 'label-message' => 'prefs-watchlist-edits',
938 'help' => $context->msg( 'prefs-watchlist-edits-max' )->escaped(),
939 'section' => 'watchlist/displaywatchlist',
941 $defaultPreferences['extendwatchlist'] = array(
943 'section' => 'watchlist/advancedwatchlist',
944 'label-message' => 'tog-extendwatchlist',
946 $defaultPreferences['watchlisthideminor'] = array(
948 'section' => 'watchlist/advancedwatchlist',
949 'label-message' => 'tog-watchlisthideminor',
951 $defaultPreferences['watchlisthidebots'] = array(
953 'section' => 'watchlist/advancedwatchlist',
954 'label-message' => 'tog-watchlisthidebots',
956 $defaultPreferences['watchlisthideown'] = array(
958 'section' => 'watchlist/advancedwatchlist',
959 'label-message' => 'tog-watchlisthideown',
961 $defaultPreferences['watchlisthideanons'] = array(
963 'section' => 'watchlist/advancedwatchlist',
964 'label-message' => 'tog-watchlisthideanons',
966 $defaultPreferences['watchlisthideliu'] = array(
968 'section' => 'watchlist/advancedwatchlist',
969 'label-message' => 'tog-watchlisthideliu',
972 if ( $wgUseRCPatrol ) {
973 $defaultPreferences['watchlisthidepatrolled'] = array(
975 'section' => 'watchlist/advancedwatchlist',
976 'label-message' => 'tog-watchlisthidepatrolled',
981 'edit' => 'watchdefault',
982 'move' => 'watchmoves',
983 'delete' => 'watchdeletion'
987 if ( $user->isAllowed( 'createpage' ) ||
$user->isAllowed( 'createtalk' ) ) {
988 $watchTypes['read'] = 'watchcreations';
991 foreach ( $watchTypes as $action => $pref ) {
992 if ( $user->isAllowed( $action ) ) {
994 // tog-watchdefault, tog-watchmoves, tog-watchdeletion, tog-watchcreations
995 $defaultPreferences[$pref] = array(
997 'section' => 'watchlist/advancedwatchlist',
998 'label-message' => "tog-$pref",
1003 if ( $wgEnableAPI ) {
1004 $defaultPreferences['watchlisttoken'] = array(
1007 $defaultPreferences['watchlisttoken-info'] = array(
1009 'section' => 'watchlist/tokenwatchlist',
1010 'label-message' => 'prefs-watchlist-token',
1011 'default' => $user->getTokenFromOption( 'watchlisttoken' ),
1012 'help-message' => 'prefs-help-watchlist-token2',
1019 * @param $context IContextSource
1020 * @param $defaultPreferences Array
1022 static function searchPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
1023 global $wgContLang, $wgVectorUseSimpleSearch;
1025 ## Search #####################################
1026 $defaultPreferences['searchlimit'] = array(
1028 'label-message' => 'resultsperpage',
1029 'section' => 'searchoptions/displaysearchoptions',
1033 if ( $wgVectorUseSimpleSearch ) {
1034 $defaultPreferences['vector-simplesearch'] = array(
1036 'label-message' => 'vector-simplesearch-preference',
1037 'section' => 'searchoptions/displaysearchoptions',
1041 $defaultPreferences['disablesuggest'] = array(
1043 'label-message' => 'mwsuggest-disable',
1044 'section' => 'searchoptions/displaysearchoptions',
1047 $defaultPreferences['searcheverything'] = array(
1049 'label-message' => 'searcheverything-enable',
1050 'section' => 'searchoptions/advancedsearchoptions',
1053 $nsOptions = $wgContLang->getFormattedNamespaces();
1054 $nsOptions[0] = $context->msg( 'blanknamespace' )->text();
1055 foreach ( $nsOptions as $ns => $name ) {
1057 unset( $nsOptions[$ns] );
1061 $defaultPreferences['searchnamespaces'] = array(
1062 'type' => 'multiselect',
1063 'label-message' => 'defaultns',
1064 'options' => array_flip( $nsOptions ),
1065 'section' => 'searchoptions/advancedsearchoptions',
1066 'prefix' => 'searchNs',
1072 * @param $context IContextSource
1073 * @param $defaultPreferences Array
1075 static function miscPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
1078 ## Misc #####################################
1079 $defaultPreferences['diffonly'] = array(
1081 'section' => 'misc/diffs',
1082 'label-message' => 'tog-diffonly',
1084 $defaultPreferences['norollbackdiff'] = array(
1086 'section' => 'misc/diffs',
1087 'label-message' => 'tog-norollbackdiff',
1090 // Stuff from Language::getExtraUserToggles()
1091 $toggles = $wgContLang->getExtraUserToggles();
1093 foreach ( $toggles as $toggle ) {
1094 $defaultPreferences[$toggle] = array(
1096 'section' => 'personal/i18n',
1097 'label-message' => "tog-$toggle",
1103 * @param $user User The User object
1104 * @param $context IContextSource
1105 * @return Array: text/links to display as key; $skinkey as value
1107 static function generateSkinOptions( $user, IContextSource
$context ) {
1108 global $wgDefaultSkin, $wgAllowUserCss, $wgAllowUserJs;
1111 $mptitle = Title
::newMainPage();
1112 $previewtext = $context->msg( 'skin-preview' )->text();
1114 # Only show members of Skin::getSkinNames() rather than
1115 # $skinNames (skins is all skin names from Language.php)
1116 $validSkinNames = Skin
::getUsableSkins();
1118 # Sort by UI skin name. First though need to update validSkinNames as sometimes
1119 # the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI).
1120 foreach ( $validSkinNames as $skinkey => &$skinname ) {
1121 $msg = $context->msg( "skinname-{$skinkey}" );
1122 if ( $msg->exists() ) {
1123 $skinname = htmlspecialchars( $msg->text() );
1126 asort( $validSkinNames );
1128 foreach ( $validSkinNames as $skinkey => $sn ) {
1129 $linkTools = array();
1131 # Mark the default skin
1132 if ( $skinkey == $wgDefaultSkin ) {
1133 $linkTools[] = $context->msg( 'default' )->escaped();
1136 # Create preview link
1137 $mplink = htmlspecialchars( $mptitle->getLocalURL( array( 'useskin' => $skinkey ) ) );
1138 $linkTools[] = "<a target='_blank' href=\"$mplink\">$previewtext</a>";
1140 # Create links to user CSS/JS pages
1141 if ( $wgAllowUserCss ) {
1142 $cssPage = Title
::makeTitleSafe( NS_USER
, $user->getName() . '/' . $skinkey . '.css' );
1143 $linkTools[] = Linker
::link( $cssPage, $context->msg( 'prefs-custom-css' )->escaped() );
1146 if ( $wgAllowUserJs ) {
1147 $jsPage = Title
::makeTitleSafe( NS_USER
, $user->getName() . '/' . $skinkey . '.js' );
1148 $linkTools[] = Linker
::link( $jsPage, $context->msg( 'prefs-custom-js' )->escaped() );
1151 $display = $sn . ' ' . $context->msg( 'parentheses', $context->getLanguage()->pipeList( $linkTools ) )->text();
1152 $ret[$display] = $skinkey;
1159 * @param $context IContextSource
1162 static function getDateOptions( IContextSource
$context ) {
1163 $lang = $context->getLanguage();
1164 $dateopts = $lang->getDatePreferences();
1169 if ( !in_array( 'default', $dateopts ) ) {
1170 $dateopts[] = 'default'; // Make sure default is always valid
1174 // KLUGE: site default might not be valid for user language
1175 global $wgDefaultUserOptions;
1176 if ( !in_array( $wgDefaultUserOptions['date'], $dateopts ) ) {
1177 $wgDefaultUserOptions['date'] = 'default';
1180 $epoch = wfTimestampNow();
1181 foreach ( $dateopts as $key ) {
1182 if ( $key == 'default' ) {
1183 $formatted = $context->msg( 'datedefault' )->escaped();
1185 $formatted = htmlspecialchars( $lang->timeanddate( $epoch, false, $key ) );
1187 $ret[$formatted] = $key;
1194 * @param $context IContextSource
1197 static function getImageSizes( IContextSource
$context ) {
1198 global $wgImageLimits;
1201 $pixels = $context->msg( 'unit-pixel' )->text();
1203 foreach ( $wgImageLimits as $index => $limits ) {
1204 $display = "{$limits[0]}×{$limits[1]}" . $pixels;
1205 $ret[$display] = $index;
1212 * @param $context IContextSource
1215 static function getThumbSizes( IContextSource
$context ) {
1216 global $wgThumbLimits;
1219 $pixels = $context->msg( 'unit-pixel' )->text();
1221 foreach ( $wgThumbLimits as $index => $size ) {
1222 $display = $size . $pixels;
1223 $ret[$display] = $index;
1230 * @param $signature string
1231 * @param $alldata array
1232 * @param $form HTMLForm
1233 * @return bool|string
1235 static function validateSignature( $signature, $alldata, $form ) {
1236 global $wgParser, $wgMaxSigChars;
1237 if ( mb_strlen( $signature ) > $wgMaxSigChars ) {
1238 return Xml
::element( 'span', array( 'class' => 'error' ),
1239 $form->msg( 'badsiglength' )->numParams( $wgMaxSigChars )->text() );
1240 } elseif ( isset( $alldata['fancysig'] ) &&
1241 $alldata['fancysig'] &&
1242 false === $wgParser->validateSig( $signature ) ) {
1243 return Xml
::element( 'span', array( 'class' => 'error' ), $form->msg( 'badsig' )->text() );
1250 * @param $signature string
1251 * @param $alldata array
1252 * @param $form HTMLForm
1255 static function cleanSignature( $signature, $alldata, $form ) {
1256 if ( isset( $alldata['fancysig'] ) && $alldata['fancysig'] ) {
1258 $signature = $wgParser->cleanSig( $signature );
1260 // When no fancy sig used, make sure ~{3,5} get removed.
1261 $signature = Parser
::cleanSigInSig( $signature );
1269 * @param $context IContextSource
1270 * @param $formClass string
1271 * @param array $remove array of items to remove
1274 static function getFormObject( $user, IContextSource
$context, $formClass = 'PreferencesForm', array $remove = array() ) {
1275 $formDescriptor = Preferences
::getPreferences( $user, $context );
1276 if ( count( $remove ) ) {
1277 $removeKeys = array_flip( $remove );
1278 $formDescriptor = array_diff_key( $formDescriptor, $removeKeys );
1281 // Remove type=api preferences. They are not intended for rendering in the form.
1282 foreach ( $formDescriptor as $name => $info ) {
1283 if ( isset( $info['type'] ) && $info['type'] === 'api' ) {
1284 unset( $formDescriptor[$name] );
1289 * @var $htmlForm PreferencesForm
1291 $htmlForm = new $formClass( $formDescriptor, $context, 'prefs' );
1293 $htmlForm->setModifiedUser( $user );
1294 $htmlForm->setId( 'mw-prefs-form' );
1295 $htmlForm->setSubmitText( $context->msg( 'saveprefs' )->text() );
1296 # Used message keys: 'accesskey-preferences-save', 'tooltip-preferences-save'
1297 $htmlForm->setSubmitTooltip( 'preferences-save' );
1298 $htmlForm->setSubmitID( 'prefsubmit' );
1299 $htmlForm->setSubmitCallback( array( 'Preferences', 'tryFormSubmit' ) );
1305 * @param $context IContextSource
1308 static function getTimezoneOptions( IContextSource
$context ) {
1311 global $wgLocalTZoffset;
1312 $timestamp = MWTimestamp
::getLocalInstance();
1313 // Check that $wgLocalTZoffset is the same as the local time zone offset
1314 if ( $wgLocalTZoffset == $timestamp->format( 'Z' ) / 60 ) {
1315 $server_tz_msg = $context->msg( 'timezoneuseserverdefault', $timestamp->getTimezone()->getName() )->text();
1317 $tzstring = sprintf( '%+03d:%02d', floor( $wgLocalTZoffset / 60 ), abs( $wgLocalTZoffset ) %
60 );
1318 $server_tz_msg = $context->msg( 'timezoneuseserverdefault', $tzstring )->text();
1320 $opt[$server_tz_msg] = "System|$wgLocalTZoffset";
1321 $opt[$context->msg( 'timezoneuseoffset' )->text()] = 'other';
1322 $opt[$context->msg( 'guesstimezone' )->text()] = 'guess';
1324 if ( function_exists( 'timezone_identifiers_list' ) ) {
1325 # Read timezone list
1326 $tzs = timezone_identifiers_list();
1329 $tzRegions = array();
1330 $tzRegions['Africa'] = $context->msg( 'timezoneregion-africa' )->text();
1331 $tzRegions['America'] = $context->msg( 'timezoneregion-america' )->text();
1332 $tzRegions['Antarctica'] = $context->msg( 'timezoneregion-antarctica' )->text();
1333 $tzRegions['Arctic'] = $context->msg( 'timezoneregion-arctic' )->text();
1334 $tzRegions['Asia'] = $context->msg( 'timezoneregion-asia' )->text();
1335 $tzRegions['Atlantic'] = $context->msg( 'timezoneregion-atlantic' )->text();
1336 $tzRegions['Australia'] = $context->msg( 'timezoneregion-australia' )->text();
1337 $tzRegions['Europe'] = $context->msg( 'timezoneregion-europe' )->text();
1338 $tzRegions['Indian'] = $context->msg( 'timezoneregion-indian' )->text();
1339 $tzRegions['Pacific'] = $context->msg( 'timezoneregion-pacific' )->text();
1340 asort( $tzRegions );
1342 $prefill = array_fill_keys( array_values( $tzRegions ), array() );
1343 $opt = array_merge( $opt, $prefill );
1345 $now = date_create( 'now' );
1347 foreach ( $tzs as $tz ) {
1348 $z = explode( '/', $tz, 2 );
1350 # timezone_identifiers_list() returns a number of
1351 # backwards-compatibility entries. This filters them out of the
1352 # list presented to the user.
1353 if ( count( $z ) != 2 ||
!array_key_exists( $z[0], $tzRegions ) ) {
1358 $z[0] = $tzRegions[$z[0]];
1360 $minDiff = floor( timezone_offset_get( timezone_open( $tz ), $now ) / 60 );
1362 $display = str_replace( '_', ' ', $z[0] . '/' . $z[1] );
1363 $value = "ZoneInfo|$minDiff|$tz";
1365 $opt[$z[0]][$display] = $value;
1376 static function filterIntval( $value, $alldata ) {
1377 return intval( $value );
1385 static function filterTimezoneInput( $tz, $alldata ) {
1386 $data = explode( '|', $tz, 3 );
1387 switch ( $data[0] ) {
1392 $data = explode( ':', $tz, 2 );
1393 if ( count( $data ) == 2 ) {
1394 $data[0] = intval( $data[0] );
1395 $data[1] = intval( $data[1] );
1396 $minDiff = abs( $data[0] ) * 60 +
$data[1];
1397 if ( $data[0] < 0 ) {
1398 $minDiff = - $minDiff;
1401 $minDiff = intval( $data[0] ) * 60;
1404 # Max is +14:00 and min is -12:00, see:
1405 # http://en.wikipedia.org/wiki/Timezone
1406 $minDiff = min( $minDiff, 840 ); # 14:00
1407 $minDiff = max( $minDiff, - 720 ); # -12:00
1408 return 'Offset|' . $minDiff;
1413 * Handle the form submission if everything validated properly
1416 * @param $form PreferencesForm
1417 * @param $entryPoint string
1418 * @return bool|Status|string
1420 static function tryFormSubmit( $formData, $form, $entryPoint = 'internal' ) {
1421 global $wgHiddenPrefs, $wgAuth;
1423 $user = $form->getModifiedUser();
1426 if ( !$user->isAllowedAny( 'editmyprivateinfo', 'editmyoptions' ) ) {
1427 return Status
::newFatal( 'mypreferencesprotected' );
1431 foreach ( array_keys( $formData ) as $name ) {
1432 if ( isset( self
::$saveFilters[$name] ) ) {
1434 call_user_func( self
::$saveFilters[$name], $formData[$name], $formData );
1438 // Fortunately, the realname field is MUCH simpler
1439 // (not really "private", but still shouldn't be edited without permission)
1440 if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->isAllowed( 'editmyprivateinfo' ) ) {
1441 $realName = $formData['realname'];
1442 $user->setRealName( $realName );
1445 if ( $user->isAllowed( 'editmyoptions' ) ) {
1446 foreach ( self
::$saveBlacklist as $b ) {
1447 unset( $formData[$b] );
1450 # If users have saved a value for a preference which has subsequently been disabled
1451 # via $wgHiddenPrefs, we don't want to destroy that setting in case the preference
1452 # is subsequently re-enabled
1453 # TODO: maintenance script to actually delete these
1454 foreach ( $wgHiddenPrefs as $pref ) {
1455 # If the user has not set a non-default value here, the default will be returned
1456 # and subsequently discarded
1457 $formData[$pref] = $user->getOption( $pref, null, true );
1460 // Keep old preferences from interfering due to back-compat code, etc.
1461 $user->resetOptions( 'unused', $form->getContext() );
1463 foreach ( $formData as $key => $value ) {
1464 $user->setOption( $key, $value );
1467 $user->saveSettings();
1470 $wgAuth->updateExternalDB( $user );
1477 * @param $form PreferencesForm
1480 public static function tryUISubmit( $formData, $form ) {
1481 $res = self
::tryFormSubmit( $formData, $form, 'ui' );
1484 $urlOptions = array( 'success' => 1 );
1486 if ( $res === 'eauth' ) {
1487 $urlOptions['eauth'] = 1;
1490 $urlOptions +
= $form->getExtraSuccessRedirectParameters();
1492 $url = $form->getTitle()->getFullURL( $urlOptions );
1494 $form->getContext()->getOutput()->redirect( $url );
1497 return Status
::newGood();
1501 * Try to set a user's email address.
1502 * This does *not* try to validate the address.
1503 * Caller is responsible for checking $wgAuth and 'editmyprivateinfo'
1506 * @deprecated in 1.20; use User::setEmailWithConfirmation() instead.
1508 * @param string $newaddr New email address
1509 * @return Array (true on success or Status on failure, info string)
1511 public static function trySetUserEmail( User
$user, $newaddr ) {
1512 wfDeprecated( __METHOD__
, '1.20' );
1514 $result = $user->setEmailWithConfirmation( $newaddr );
1515 if ( $result->isGood() ) {
1516 return array( true, $result->value
);
1518 return array( $result, 'mailerror' );
1523 * @deprecated in 1.19
1527 public static function loadOldSearchNs( $user ) {
1528 wfDeprecated( __METHOD__
, '1.19' );
1530 $searchableNamespaces = SearchEngine
::searchableNamespaces();
1531 // Back compat with old format
1534 foreach ( $searchableNamespaces as $ns => $name ) {
1535 if ( $user->getOption( 'searchNs' . $ns ) ) {
1544 /** Some tweaks to allow js prefs to work */
1545 class PreferencesForm
extends HTMLForm
{
1546 // Override default value from HTMLForm
1547 protected $mSubSectionBeforeFields = false;
1549 private $modifiedUser;
1554 public function setModifiedUser( $user ) {
1555 $this->modifiedUser
= $user;
1561 public function getModifiedUser() {
1562 if ( $this->modifiedUser
=== null ) {
1563 return $this->getUser();
1565 return $this->modifiedUser
;
1570 * Get extra parameters for the query string when redirecting after
1575 public function getExtraSuccessRedirectParameters() {
1580 * @param $html string
1583 function wrapForm( $html ) {
1584 $html = Xml
::tags( 'div', array( 'id' => 'preferences' ), $html );
1586 return parent
::wrapForm( $html );
1592 function getButtons() {
1593 if ( !$this->getModifiedUser()->isAllowedAny( 'editmyprivateinfo', 'editmyoptions' ) ) {
1597 $html = parent
::getButtons();
1599 if ( $this->getModifiedUser()->isAllowed( 'editmyoptions' ) ) {
1600 $t = SpecialPage
::getTitleFor( 'Preferences', 'reset' );
1602 $html .= "\n" . Linker
::link( $t, $this->msg( 'restoreprefs' )->escaped() );
1604 $html = Xml
::tags( 'div', array( 'class' => 'mw-prefs-buttons' ), $html );
1611 * Separate multi-option preferences into multiple preferences, since we
1612 * have to store them separately
1613 * @param $data array
1616 function filterDataForSubmit( $data ) {
1617 foreach ( $this->mFlatFields
as $fieldname => $field ) {
1618 if ( $field instanceof HTMLNestedFilterable
) {
1619 $info = $field->mParams
;
1620 $prefix = isset( $info['prefix'] ) ?
$info['prefix'] : $fieldname;
1621 foreach ( $field->filterDataForSubmit( $data[$fieldname] ) as $key => $value ) {
1622 $data["$prefix$key"] = $value;
1624 unset( $data[$fieldname] );
1632 * Get the whole body of the form.
1635 function getBody() {
1636 return $this->displaySection( $this->mFieldTree
, '', 'mw-prefsection-' );
1640 * Get the "<legend>" for a given section key. Normally this is the
1641 * prefs-$key message but we'll allow extensions to override it.
1642 * @param $key string
1645 function getLegend( $key ) {
1646 $legend = parent
::getLegend( $key );
1647 wfRunHooks( 'PreferencesGetLegend', array( $this, $key, &$legend ) );