Oops, forgot to change this in r71426
[lhc/web/wiklou.git] / includes / Preferences.php
1 <?php
2 /**
3 * We're now using the HTMLForm object with some customisation to generate the
4 * Preferences form. This object handles generic submission, CSRF protection,
5 * layout and other logic in a reusable manner. We subclass it as a PreferencesForm
6 * to make some minor customisations.
7 *
8 * In order to generate the form, the HTMLForm object needs an array structure
9 * detailing the form fields available, and that's what this class is for. Each
10 * element of the array is a basic property-list, including the type of field,
11 * the label it is to be given in the form, callbacks for validation and
12 * 'filtering', and other pertinent information. Note that the 'default' field
13 * is named for generic forms, and does not represent the preference's default
14 * (which is stored in $wgDefaultUserOptions), but the default for the form
15 * field, which should be whatever the user has set for that preference. There
16 * is no need to override it unless you have some special storage logic (for
17 * instance, those not presently stored as options, but which are best set from
18 * the user preferences view).
19 *
20 * Field types are implemented as subclasses of the generic HTMLFormField
21 * object, and typically implement at least getInputHTML, which generates the
22 * HTML for the input field to be placed in the table.
23 *
24 * Once fields have been retrieved and validated, submission logic is handed
25 * over to the tryUISubmit static method of this class.
26 */
27
28 class Preferences {
29 static $defaultPreferences = null;
30 static $saveFilters = array(
31 'timecorrection' => array( 'Preferences', 'filterTimezoneInput' ),
32 );
33
34 static function getPreferences( $user ) {
35 if ( self::$defaultPreferences )
36 return self::$defaultPreferences;
37
38 $defaultPreferences = array();
39
40 self::profilePreferences( $user, $defaultPreferences );
41 self::skinPreferences( $user, $defaultPreferences );
42 self::filesPreferences( $user, $defaultPreferences );
43 self::mathPreferences( $user, $defaultPreferences );
44 self::datetimePreferences( $user, $defaultPreferences );
45 self::renderingPreferences( $user, $defaultPreferences );
46 self::editingPreferences( $user, $defaultPreferences );
47 self::rcPreferences( $user, $defaultPreferences );
48 self::watchlistPreferences( $user, $defaultPreferences );
49 self::searchPreferences( $user, $defaultPreferences );
50 self::miscPreferences( $user, $defaultPreferences );
51
52 wfRunHooks( 'GetPreferences', array( $user, &$defaultPreferences ) );
53
54 ## Remove preferences that wikis don't want to use
55 global $wgHiddenPrefs;
56 foreach ( $wgHiddenPrefs as $pref ) {
57 if ( isset( $defaultPreferences[$pref] ) ) {
58 unset( $defaultPreferences[$pref] );
59 }
60 }
61
62 ## Prod in defaults from the user
63 foreach ( $defaultPreferences as $name => &$info ) {
64 $prefFromUser = self::getOptionFromUser( $name, $info, $user );
65 $field = HTMLForm::loadInputFromParameters( $info ); // For validation
66 $defaultOptions = User::getDefaultOptions();
67 $globalDefault = isset( $defaultOptions[$name] )
68 ? $defaultOptions[$name]
69 : null;
70
71 // If it validates, set it as the default
72 if ( isset( $info['default'] ) ) {
73 // Already set, no problem
74 continue;
75 } elseif ( !is_null( $prefFromUser ) && // Make sure we're not just pulling nothing
76 $field->validate( $prefFromUser, $user->mOptions ) === true ) {
77 $info['default'] = $prefFromUser;
78 } elseif ( $field->validate( $globalDefault, $user->mOptions ) === true ) {
79 $info['default'] = $globalDefault;
80 } else {
81 throw new MWException( "Global default '$globalDefault' is invalid for field $name" );
82 }
83 }
84
85 self::$defaultPreferences = $defaultPreferences;
86
87 return $defaultPreferences;
88 }
89
90 // Pull option from a user account. Handles stuff like array-type preferences.
91 static function getOptionFromUser( $name, $info, $user ) {
92 $val = $user->getOption( $name );
93
94 // Handling for array-type preferences
95 if ( ( isset( $info['type'] ) && $info['type'] == 'multiselect' ) ||
96 ( isset( $info['class'] ) && $info['class'] == 'HTMLMultiSelectField' ) ) {
97 $options = HTMLFormField::flattenOptions( $info['options'] );
98 $prefix = isset( $info['prefix'] ) ? $info['prefix'] : $name;
99 $val = array();
100
101 foreach ( $options as $label => $value ) {
102 if ( $user->getOption( "$prefix$value" ) ) {
103 $val[] = $value;
104 }
105 }
106 }
107
108 return $val;
109 }
110
111 static function profilePreferences( $user, &$defaultPreferences ) {
112 global $wgLang, $wgUser;
113 ## User info #####################################
114 // Information panel
115 $defaultPreferences['username'] = array(
116 'type' => 'info',
117 'label-message' => 'username',
118 'default' => $user->getName(),
119 'section' => 'personal/info',
120 );
121
122 $defaultPreferences['userid'] = array(
123 'type' => 'info',
124 'label-message' => 'uid',
125 'default' => $user->getId(),
126 'section' => 'personal/info',
127 );
128
129 # Get groups to which the user belongs
130 $userEffectiveGroups = $user->getEffectiveGroups();
131 $userGroups = $userMembers = array();
132 foreach ( $userEffectiveGroups as $ueg ) {
133 if ( $ueg == '*' ) {
134 // Skip the default * group, seems useless here
135 continue;
136 }
137 $groupName = User::getGroupName( $ueg );
138 $userGroups[] = User::makeGroupLinkHTML( $ueg, $groupName );
139
140 $memberName = User::getGroupMember( $ueg );
141 $userMembers[] = User::makeGroupLinkHTML( $ueg, $memberName );
142 }
143 asort( $userGroups );
144 asort( $userMembers );
145
146 $defaultPreferences['usergroups'] = array(
147 'type' => 'info',
148 'label' => wfMsgExt(
149 'prefs-memberingroups', 'parseinline',
150 $wgLang->formatNum( count( $userGroups ) )
151 ),
152 'default' => wfMsgExt(
153 'prefs-memberingroups-type', array(),
154 $wgLang->commaList( $userGroups ),
155 $wgLang->commaList( $userMembers )
156 ),
157 'raw' => true,
158 'section' => 'personal/info',
159 );
160
161 $defaultPreferences['editcount'] = array(
162 'type' => 'info',
163 'label-message' => 'prefs-edits',
164 'default' => $wgLang->formatNum( $user->getEditCount() ),
165 'section' => 'personal/info',
166 );
167
168 if ( $user->getRegistration() ) {
169 $defaultPreferences['registrationdate'] = array(
170 'type' => 'info',
171 'label-message' => 'prefs-registration',
172 'default' => wfMsgExt(
173 'prefs-registration-date-time', 'parsemag',
174 $wgLang->timeanddate( $user->getRegistration(), true ),
175 $wgLang->date( $user->getRegistration(), true ),
176 $wgLang->time( $user->getRegistration(), true )
177 ),
178 'section' => 'personal/info',
179 );
180 }
181
182 // Actually changeable stuff
183 global $wgAuth;
184 $defaultPreferences['realname'] = array(
185 'type' => $wgAuth->allowPropChange( 'realname' ) ? 'text' : 'info',
186 'default' => $user->getRealName(),
187 'section' => 'personal/info',
188 'label-message' => 'yourrealname',
189 'help-message' => 'prefs-help-realname',
190 );
191
192 $defaultPreferences['gender'] = array(
193 'type' => 'select',
194 'section' => 'personal/info',
195 'options' => array(
196 wfMsg( 'gender-male' ) => 'male',
197 wfMsg( 'gender-female' ) => 'female',
198 wfMsg( 'gender-unknown' ) => 'unknown',
199 ),
200 'label-message' => 'yourgender',
201 'help-message' => 'prefs-help-gender',
202 );
203
204 if ( $wgAuth->allowPasswordChange() ) {
205 $link = $wgUser->getSkin()->link( SpecialPage::getTitleFor( 'Resetpass' ),
206 wfMsgHtml( 'prefs-resetpass' ), array(),
207 array( 'returnto' => SpecialPage::getTitleFor( 'Preferences' ) ) );
208
209 $defaultPreferences['password'] = array(
210 'type' => 'info',
211 'raw' => true,
212 'default' => $link,
213 'label-message' => 'yourpassword',
214 'section' => 'personal/info',
215 );
216 }
217 global $wgCookieExpiration;
218 if ( $wgCookieExpiration > 0 ) {
219 $defaultPreferences['rememberpassword'] = array(
220 'type' => 'toggle',
221 'label' => wfMsgExt(
222 'tog-rememberpassword',
223 array( 'parsemag' ),
224 $wgLang->formatNum( ceil( $wgCookieExpiration / ( 3600 * 24 ) ) )
225 ),
226 'section' => 'personal/info',
227 );
228 }
229
230 // Language
231 global $wgContLanguageCode;
232 $languages = Language::getLanguageNames( false );
233 if ( !array_key_exists( $wgContLanguageCode, $languages ) ) {
234 $languages[$wgContLanguageCode] = $wgContLanguageCode;
235 }
236 ksort( $languages );
237
238 $options = array();
239 foreach ( $languages as $code => $name ) {
240 $display = wfBCP47( $code ) . ' - ' . $name;
241 $options[$display] = $code;
242 }
243 $defaultPreferences['language'] = array(
244 'type' => 'select',
245 'section' => 'personal/i18n',
246 'options' => $options,
247 'label-message' => 'yourlanguage',
248 );
249
250 global $wgContLang, $wgDisableLangConversion;
251 global $wgDisableTitleConversion;
252 /* see if there are multiple language variants to choose from*/
253 $variantArray = array();
254 if ( !$wgDisableLangConversion ) {
255 $variants = $wgContLang->getVariants();
256
257 $languages = Language::getLanguageNames( true );
258 foreach ( $variants as $v ) {
259 $v = str_replace( '_', '-', strtolower( $v ) );
260 if ( array_key_exists( $v, $languages ) ) {
261 // If it doesn't have a name, we'll pretend it doesn't exist
262 $variantArray[$v] = $languages[$v];
263 }
264 }
265
266 $options = array();
267 foreach ( $variantArray as $code => $name ) {
268 $display = wfBCP47( $code ) . ' - ' . $name;
269 $options[$display] = $code;
270 }
271
272 if ( count( $variantArray ) > 1 ) {
273 $defaultPreferences['variant'] = array(
274 'label-message' => 'yourvariant',
275 'type' => 'select',
276 'options' => $options,
277 'section' => 'personal/i18n',
278 );
279 }
280 }
281
282 if ( count( $variantArray ) > 1 && !$wgDisableLangConversion && !$wgDisableTitleConversion ) {
283 $defaultPreferences['noconvertlink'] =
284 array(
285 'type' => 'toggle',
286 'section' => 'personal/i18n',
287 'label-message' => 'tog-noconvertlink',
288 );
289 }
290
291 global $wgMaxSigChars, $wgOut, $wgParser;
292
293 // show a preview of the old signature first
294 $oldsigWikiText = $wgParser->preSaveTransform( "~~~", new Title , $user, new ParserOptions );
295 $oldsigHTML = $wgOut->parseInline( $oldsigWikiText );
296 $defaultPreferences['oldsig'] = array(
297 'type' => 'info',
298 'raw' => true,
299 'label-message' => 'tog-oldsig',
300 'default' => $oldsigHTML,
301 'section' => 'personal/signature',
302 );
303 $defaultPreferences['nickname'] = array(
304 'type' => $wgAuth->allowPropChange( 'nickname' ) ? 'text' : 'info',
305 'maxlength' => $wgMaxSigChars,
306 'label-message' => 'yournick',
307 'validation-callback' => array( 'Preferences', 'validateSignature' ),
308 'section' => 'personal/signature',
309 'filter-callback' => array( 'Preferences', 'cleanSignature' ),
310 );
311 $defaultPreferences['fancysig'] = array(
312 'type' => 'toggle',
313 'label-message' => 'tog-fancysig',
314 'help-message' => 'prefs-help-signature', // show general help about signature at the bottom of the section
315 'section' => 'personal/signature'
316 );
317
318 ## Email stuff
319
320 global $wgEnableEmail;
321 if ( $wgEnableEmail ) {
322 global $wgEmailConfirmToEdit;
323
324 $defaultPreferences['emailaddress'] = array(
325 'type' => $wgAuth->allowPropChange( 'emailaddress' ) ? 'email' : 'info',
326 'default' => $user->getEmail(),
327 'section' => 'personal/email',
328 'label-message' => 'youremail',
329 'help-message' => $wgEmailConfirmToEdit
330 ? 'prefs-help-email-required'
331 : 'prefs-help-email',
332 'validation-callback' => array( 'Preferences', 'validateEmail' ),
333 );
334
335 global $wgEnableUserEmail, $wgEmailAuthentication;
336
337 $disableEmailPrefs = false;
338
339 if ( $wgEmailAuthentication ) {
340 if ( $user->getEmail() ) {
341 if ( $user->getEmailAuthenticationTimestamp() ) {
342 // date and time are separate parameters to facilitate localisation.
343 // $time is kept for backward compat reasons.
344 // 'emailauthenticated' is also used in SpecialConfirmemail.php
345 $time = $wgLang->timeAndDate( $user->getEmailAuthenticationTimestamp(), true );
346 $d = $wgLang->date( $user->getEmailAuthenticationTimestamp(), true );
347 $t = $wgLang->time( $user->getEmailAuthenticationTimestamp(), true );
348 $emailauthenticated = wfMsgExt(
349 'emailauthenticated', 'parseinline',
350 array( $time, $d, $t )
351 ) . '<br />';
352 $disableEmailPrefs = false;
353 } else {
354 $disableEmailPrefs = true;
355 $skin = $wgUser->getSkin();
356 $emailauthenticated = wfMsgExt( 'emailnotauthenticated', 'parseinline' ) . '<br />' .
357 $skin->link(
358 SpecialPage::getTitleFor( 'Confirmemail' ),
359 wfMsg( 'emailconfirmlink' ),
360 array(),
361 array(),
362 array( 'known', 'noclasses' )
363 ) . '<br />';
364 }
365 } else {
366 $disableEmailPrefs = true;
367 $emailauthenticated = wfMsgHtml( 'noemailprefs' );
368 }
369
370 $defaultPreferences['emailauthentication'] = array(
371 'type' => 'info',
372 'raw' => true,
373 'section' => 'personal/email',
374 'label-message' => 'prefs-emailconfirm-label',
375 'default' => $emailauthenticated,
376 );
377
378 }
379
380 if ( $wgEnableUserEmail && $user->isAllowed( 'sendemail' ) ) {
381 $defaultPreferences['disablemail'] = array(
382 'type' => 'toggle',
383 'invert' => true,
384 'section' => 'personal/email',
385 'label-message' => 'allowemail',
386 'disabled' => $disableEmailPrefs,
387 );
388 $defaultPreferences['ccmeonemails'] = array(
389 'type' => 'toggle',
390 'section' => 'personal/email',
391 'label-message' => 'tog-ccmeonemails',
392 'disabled' => $disableEmailPrefs,
393 );
394 }
395
396 global $wgEnotifWatchlist;
397 if ( $wgEnotifWatchlist ) {
398 $defaultPreferences['enotifwatchlistpages'] = array(
399 'type' => 'toggle',
400 'section' => 'personal/email',
401 'label-message' => 'tog-enotifwatchlistpages',
402 'disabled' => $disableEmailPrefs,
403 );
404 }
405 global $wgEnotifUserTalk;
406 if ( $wgEnotifUserTalk ) {
407 $defaultPreferences['enotifusertalkpages'] = array(
408 'type' => 'toggle',
409 'section' => 'personal/email',
410 'label-message' => 'tog-enotifusertalkpages',
411 'disabled' => $disableEmailPrefs,
412 );
413 }
414 if ( $wgEnotifUserTalk || $wgEnotifWatchlist ) {
415 $defaultPreferences['enotifminoredits'] = array(
416 'type' => 'toggle',
417 'section' => 'personal/email',
418 'label-message' => 'tog-enotifminoredits',
419 'disabled' => $disableEmailPrefs,
420 );
421
422 global $wgEnotifRevealEditorAddress;
423 if ( $wgEnotifRevealEditorAddress ) {
424 $defaultPreferences['enotifrevealaddr'] = array(
425 'type' => 'toggle',
426 'section' => 'personal/email',
427 'label-message' => 'tog-enotifrevealaddr',
428 'disabled' => $disableEmailPrefs,
429 );
430 }
431 }
432 }
433 }
434
435 static function skinPreferences( $user, &$defaultPreferences ) {
436 ## Skin #####################################
437 global $wgLang, $wgAllowUserCss, $wgAllowUserJs;
438
439 $defaultPreferences['skin'] = array(
440 'type' => 'radio',
441 'options' => self::generateSkinOptions( $user ),
442 'label' => '&#160;',
443 'section' => 'rendering/skin',
444 );
445
446 # Create links to user CSS/JS pages for all skins
447 # This code is basically copied from generateSkinOptions(). It'd
448 # be nice to somehow merge this back in there to avoid redundancy.
449 if ( $wgAllowUserCss || $wgAllowUserJs ) {
450 $sk = $user->getSkin();
451 $linkTools = array();
452
453 if ( $wgAllowUserCss ) {
454 $cssPage = Title::makeTitleSafe( NS_USER, $user->getName() . '/common.css' );
455 $linkTools[] = $sk->link( $cssPage, wfMsgHtml( 'prefs-custom-css' ) );
456 }
457
458 if ( $wgAllowUserJs ) {
459 $jsPage = Title::makeTitleSafe( NS_USER, $user->getName() . '/common.js' );
460 $linkTools[] = $sk->link( $jsPage, wfMsgHtml( 'prefs-custom-js' ) );
461 }
462
463 $defaultPreferences['commoncssjs'] = array(
464 'type' => 'info',
465 'raw' => true,
466 'default' => $wgLang->pipeList( $linkTools ),
467 'label-message' => 'prefs-common-css-js',
468 'section' => 'rendering/skin',
469 );
470 }
471
472 $selectedSkin = $user->getOption( 'skin' );
473 if ( in_array( $selectedSkin, array( 'cologneblue', 'standard' ) ) ) {
474 $settings = array_flip( $wgLang->getQuickbarSettings() );
475
476 $defaultPreferences['quickbar'] = array(
477 'type' => 'radio',
478 'options' => $settings,
479 'section' => 'rendering/skin',
480 'label-message' => 'qbsettings',
481 );
482 }
483 }
484
485 static function mathPreferences( $user, &$defaultPreferences ) {
486 ## Math #####################################
487 global $wgUseTeX, $wgLang;
488 if ( $wgUseTeX ) {
489 $defaultPreferences['math'] = array(
490 'type' => 'radio',
491 'options' => array_flip( array_map( 'wfMsgHtml', $wgLang->getMathNames() ) ),
492 'label' => '&#160;',
493 'section' => 'rendering/math',
494 );
495 }
496 }
497
498 static function filesPreferences( $user, &$defaultPreferences ) {
499 ## Files #####################################
500 $defaultPreferences['imagesize'] = array(
501 'type' => 'select',
502 'options' => self::getImageSizes(),
503 'label-message' => 'imagemaxsize',
504 'section' => 'rendering/files',
505 );
506 $defaultPreferences['thumbsize'] = array(
507 'type' => 'select',
508 'options' => self::getThumbSizes(),
509 'label-message' => 'thumbsize',
510 'section' => 'rendering/files',
511 );
512 }
513
514 static function datetimePreferences( $user, &$defaultPreferences ) {
515 global $wgLang;
516
517 ## Date and time #####################################
518 $dateOptions = self::getDateOptions();
519 if ( $dateOptions ) {
520 $defaultPreferences['date'] = array(
521 'type' => 'radio',
522 'options' => $dateOptions,
523 'label' => '&#160;',
524 'section' => 'datetime/dateformat',
525 );
526 }
527
528 // Info
529 $nowlocal = Xml::element( 'span', array( 'id' => 'wpLocalTime' ),
530 $wgLang->time( $now = wfTimestampNow(), true ) );
531 $nowserver = $wgLang->time( $now, false ) .
532 Xml::hidden( 'wpServerTime', substr( $now, 8, 2 ) * 60 + substr( $now, 10, 2 ) );
533
534 $defaultPreferences['nowserver'] = array(
535 'type' => 'info',
536 'raw' => 1,
537 'label-message' => 'servertime',
538 'default' => $nowserver,
539 'section' => 'datetime/timeoffset',
540 );
541
542 $defaultPreferences['nowlocal'] = array(
543 'type' => 'info',
544 'raw' => 1,
545 'label-message' => 'localtime',
546 'default' => $nowlocal,
547 'section' => 'datetime/timeoffset',
548 );
549
550 // Grab existing pref.
551 $tzOffset = $user->getOption( 'timecorrection' );
552 $tz = explode( '|', $tzOffset, 2 );
553
554 $tzSetting = $tzOffset;
555 if ( count( $tz ) > 1 && $tz[0] == 'Offset' ) {
556 $minDiff = $tz[1];
557 $tzSetting = sprintf( '%+03d:%02d', floor( $minDiff / 60 ), abs( $minDiff ) % 60 );
558 }
559
560 $defaultPreferences['timecorrection'] = array(
561 'class' => 'HTMLSelectOrOtherField',
562 'label-message' => 'timezonelegend',
563 'options' => self::getTimezoneOptions(),
564 'default' => $tzSetting,
565 'size' => 20,
566 'section' => 'datetime/timeoffset',
567 );
568 }
569
570 static function renderingPreferences( $user, &$defaultPreferences ) {
571 ## Page Rendering ##############################
572 global $wgAllowUserCssPrefs;
573 if ( $wgAllowUserCssPrefs ) {
574 $defaultPreferences['underline'] = array(
575 'type' => 'select',
576 'options' => array(
577 wfMsg( 'underline-never' ) => 0,
578 wfMsg( 'underline-always' ) => 1,
579 wfMsg( 'underline-default' ) => 2,
580 ),
581 'label-message' => 'tog-underline',
582 'section' => 'rendering/advancedrendering',
583 );
584 }
585
586 $stubThresholdValues = array( 50, 100, 500, 1000, 2000, 5000, 10000 );
587 $stubThresholdOptions = array( wfMsg( 'stub-threshold-disabled' ) => 0 );
588 foreach ( $stubThresholdValues as $value ) {
589 $stubThresholdOptions[wfMsg( 'size-bytes', $value )] = $value;
590 }
591
592 $defaultPreferences['stubthreshold'] = array(
593 'type' => 'selectorother',
594 'section' => 'rendering/advancedrendering',
595 'options' => $stubThresholdOptions,
596 'size' => 20,
597 'label' => wfMsg( 'stub-threshold' ), // Raw HTML message. Yay?
598 );
599
600 if ( $wgAllowUserCssPrefs ) {
601 $defaultPreferences['highlightbroken'] = array(
602 'type' => 'toggle',
603 'section' => 'rendering/advancedrendering',
604 'label' => wfMsg( 'tog-highlightbroken' ), // Raw HTML
605 );
606 $defaultPreferences['showtoc'] = array(
607 'type' => 'toggle',
608 'section' => 'rendering/advancedrendering',
609 'label-message' => 'tog-showtoc',
610 );
611 }
612 $defaultPreferences['nocache'] = array(
613 'type' => 'toggle',
614 'label-message' => 'tog-nocache',
615 'section' => 'rendering/advancedrendering',
616 );
617 $defaultPreferences['showhiddencats'] = array(
618 'type' => 'toggle',
619 'section' => 'rendering/advancedrendering',
620 'label-message' => 'tog-showhiddencats'
621 );
622 $defaultPreferences['showjumplinks'] = array(
623 'type' => 'toggle',
624 'section' => 'rendering/advancedrendering',
625 'label-message' => 'tog-showjumplinks',
626 );
627
628 if ( $wgAllowUserCssPrefs ) {
629 $defaultPreferences['justify'] = array(
630 'type' => 'toggle',
631 'section' => 'rendering/advancedrendering',
632 'label-message' => 'tog-justify',
633 );
634 }
635
636 $defaultPreferences['numberheadings'] = array(
637 'type' => 'toggle',
638 'section' => 'rendering/advancedrendering',
639 'label-message' => 'tog-numberheadings',
640 );
641 }
642
643 static function editingPreferences( $user, &$defaultPreferences ) {
644 global $wgUseExternalEditor, $wgAllowUserCssPrefs;
645
646 ## Editing #####################################
647 $defaultPreferences['cols'] = array(
648 'type' => 'int',
649 'label-message' => 'columns',
650 'section' => 'editing/textboxsize',
651 'min' => 4,
652 'max' => 1000,
653 );
654 $defaultPreferences['rows'] = array(
655 'type' => 'int',
656 'label-message' => 'rows',
657 'section' => 'editing/textboxsize',
658 'min' => 4,
659 'max' => 1000,
660 );
661
662 if ( $wgAllowUserCssPrefs ) {
663 $defaultPreferences['editfont'] = array(
664 'type' => 'select',
665 'section' => 'editing/advancedediting',
666 'label-message' => 'editfont-style',
667 'options' => array(
668 wfMsg( 'editfont-default' ) => 'default',
669 wfMsg( 'editfont-monospace' ) => 'monospace',
670 wfMsg( 'editfont-sansserif' ) => 'sans-serif',
671 wfMsg( 'editfont-serif' ) => 'serif',
672 )
673 );
674 }
675 $defaultPreferences['previewontop'] = array(
676 'type' => 'toggle',
677 'section' => 'editing/advancedediting',
678 'label-message' => 'tog-previewontop',
679 );
680 $defaultPreferences['previewonfirst'] = array(
681 'type' => 'toggle',
682 'section' => 'editing/advancedediting',
683 'label-message' => 'tog-previewonfirst',
684 );
685
686 if ( $wgAllowUserCssPrefs ) {
687 $defaultPreferences['editsection'] = array(
688 'type' => 'toggle',
689 'section' => 'editing/advancedediting',
690 'label-message' => 'tog-editsection',
691 );
692 }
693 $defaultPreferences['editsectiononrightclick'] = array(
694 'type' => 'toggle',
695 'section' => 'editing/advancedediting',
696 'label-message' => 'tog-editsectiononrightclick',
697 );
698 $defaultPreferences['editondblclick'] = array(
699 'type' => 'toggle',
700 'section' => 'editing/advancedediting',
701 'label-message' => 'tog-editondblclick',
702 );
703 $defaultPreferences['showtoolbar'] = array(
704 'type' => 'toggle',
705 'section' => 'editing/advancedediting',
706 'label-message' => 'tog-showtoolbar',
707 );
708
709 if ( $wgUseExternalEditor ) {
710 $defaultPreferences['externaleditor'] = array(
711 'type' => 'toggle',
712 'section' => 'editing/advancedediting',
713 'label-message' => 'tog-externaleditor',
714 );
715 $defaultPreferences['externaldiff'] = array(
716 'type' => 'toggle',
717 'section' => 'editing/advancedediting',
718 'label-message' => 'tog-externaldiff',
719 );
720 }
721
722 $defaultPreferences['forceeditsummary'] = array(
723 'type' => 'toggle',
724 'section' => 'editing/advancedediting',
725 'label-message' => 'tog-forceeditsummary',
726 );
727
728
729 $defaultPreferences['uselivepreview'] = array(
730 'type' => 'toggle',
731 'section' => 'editing/advancedediting',
732 'label-message' => 'tog-uselivepreview',
733 );
734 }
735
736 static function rcPreferences( $user, &$defaultPreferences ) {
737 global $wgRCMaxAge, $wgUseRCPatrol, $wgLang;
738
739 ## RecentChanges #####################################
740 $defaultPreferences['rcdays'] = array(
741 'type' => 'float',
742 'label-message' => 'recentchangesdays',
743 'section' => 'rc/displayrc',
744 'min' => 1,
745 'max' => ceil( $wgRCMaxAge / ( 3600 * 24 ) ),
746 'help' => wfMsgExt(
747 'recentchangesdays-max',
748 array( 'parsemag' ),
749 $wgLang->formatNum( ceil( $wgRCMaxAge / ( 3600 * 24 ) ) )
750 )
751 );
752 $defaultPreferences['rclimit'] = array(
753 'type' => 'int',
754 'label-message' => 'recentchangescount',
755 'help-message' => 'prefs-help-recentchangescount',
756 'section' => 'rc/displayrc',
757 );
758 $defaultPreferences['usenewrc'] = array(
759 'type' => 'toggle',
760 'label-message' => 'tog-usenewrc',
761 'section' => 'rc/advancedrc',
762 );
763 $defaultPreferences['hideminor'] = array(
764 'type' => 'toggle',
765 'label-message' => 'tog-hideminor',
766 'section' => 'rc/advancedrc',
767 );
768
769 if ( $wgUseRCPatrol ) {
770 $defaultPreferences['hidepatrolled'] = array(
771 'type' => 'toggle',
772 'section' => 'rc/advancedrc',
773 'label-message' => 'tog-hidepatrolled',
774 );
775 $defaultPreferences['newpageshidepatrolled'] = array(
776 'type' => 'toggle',
777 'section' => 'rc/advancedrc',
778 'label-message' => 'tog-newpageshidepatrolled',
779 );
780 }
781
782 global $wgRCShowWatchingUsers;
783 if ( $wgRCShowWatchingUsers ) {
784 $defaultPreferences['shownumberswatching'] = array(
785 'type' => 'toggle',
786 'section' => 'rc/advancedrc',
787 'label-message' => 'tog-shownumberswatching',
788 );
789 }
790 }
791
792 static function watchlistPreferences( $user, &$defaultPreferences ) {
793 global $wgUseRCPatrol, $wgEnableAPI;
794
795 ## Watchlist #####################################
796 $defaultPreferences['watchlistdays'] = array(
797 'type' => 'float',
798 'min' => 0,
799 'max' => 7,
800 'section' => 'watchlist/displaywatchlist',
801 'help' => wfMsgHtml( 'prefs-watchlist-days-max' ),
802 'label-message' => 'prefs-watchlist-days',
803 );
804 $defaultPreferences['wllimit'] = array(
805 'type' => 'int',
806 'min' => 0,
807 'max' => 1000,
808 'label-message' => 'prefs-watchlist-edits',
809 'help' => wfMsgHtml( 'prefs-watchlist-edits-max' ),
810 'section' => 'watchlist/displaywatchlist',
811 );
812 $defaultPreferences['extendwatchlist'] = array(
813 'type' => 'toggle',
814 'section' => 'watchlist/advancedwatchlist',
815 'label-message' => 'tog-extendwatchlist',
816 );
817 $defaultPreferences['watchlisthideminor'] = array(
818 'type' => 'toggle',
819 'section' => 'watchlist/advancedwatchlist',
820 'label-message' => 'tog-watchlisthideminor',
821 );
822 $defaultPreferences['watchlisthidebots'] = array(
823 'type' => 'toggle',
824 'section' => 'watchlist/advancedwatchlist',
825 'label-message' => 'tog-watchlisthidebots',
826 );
827 $defaultPreferences['watchlisthideown'] = array(
828 'type' => 'toggle',
829 'section' => 'watchlist/advancedwatchlist',
830 'label-message' => 'tog-watchlisthideown',
831 );
832 $defaultPreferences['watchlisthideanons'] = array(
833 'type' => 'toggle',
834 'section' => 'watchlist/advancedwatchlist',
835 'label-message' => 'tog-watchlisthideanons',
836 );
837 $defaultPreferences['watchlisthideliu'] = array(
838 'type' => 'toggle',
839 'section' => 'watchlist/advancedwatchlist',
840 'label-message' => 'tog-watchlisthideliu',
841 );
842
843 if ( $wgUseRCPatrol ) {
844 $defaultPreferences['watchlisthidepatrolled'] = array(
845 'type' => 'toggle',
846 'section' => 'watchlist/advancedwatchlist',
847 'label-message' => 'tog-watchlisthidepatrolled',
848 );
849 }
850
851 if ( $wgEnableAPI ) {
852 # Some random gibberish as a proposed default
853 $hash = sha1( mt_rand() . microtime( true ) );
854
855 $defaultPreferences['watchlisttoken'] = array(
856 'type' => 'text',
857 'section' => 'watchlist/advancedwatchlist',
858 'label-message' => 'prefs-watchlist-token',
859 'help' => wfMsgHtml( 'prefs-help-watchlist-token', $hash )
860 );
861 }
862
863 $watchTypes = array(
864 'edit' => 'watchdefault',
865 'move' => 'watchmoves',
866 'delete' => 'watchdeletion'
867 );
868
869 // Kinda hacky
870 if ( $user->isAllowed( 'createpage' ) || $user->isAllowed( 'createtalk' ) ) {
871 $watchTypes['read'] = 'watchcreations';
872 }
873
874 foreach ( $watchTypes as $action => $pref ) {
875 if ( $user->isAllowed( $action ) ) {
876 $defaultPreferences[$pref] = array(
877 'type' => 'toggle',
878 'section' => 'watchlist/advancedwatchlist',
879 'label-message' => "tog-$pref",
880 );
881 }
882 }
883 }
884
885 static function searchPreferences( $user, &$defaultPreferences ) {
886 global $wgContLang;
887
888 ## Search #####################################
889 $defaultPreferences['searchlimit'] = array(
890 'type' => 'int',
891 'label-message' => 'resultsperpage',
892 'section' => 'searchoptions/displaysearchoptions',
893 'min' => 0,
894 );
895 $defaultPreferences['contextlines'] = array(
896 'type' => 'int',
897 'label-message' => 'contextlines',
898 'section' => 'searchoptions/displaysearchoptions',
899 'min' => 0,
900 );
901 $defaultPreferences['contextchars'] = array(
902 'type' => 'int',
903 'label-message' => 'contextchars',
904 'section' => 'searchoptions/displaysearchoptions',
905 'min' => 0,
906 );
907
908 global $wgEnableMWSuggest;
909 if ( $wgEnableMWSuggest ) {
910 $defaultPreferences['disablesuggest'] = array(
911 'type' => 'toggle',
912 'label-message' => 'mwsuggest-disable',
913 'section' => 'searchoptions/displaysearchoptions',
914 );
915 }
916
917 global $wgVectorUseSimpleSearch;
918 if ( $wgVectorUseSimpleSearch ) {
919 $defaultPreferences['vector-simplesearch'] = array(
920 'type' => 'toggle',
921 'label-message' => 'vector-simplesearch-preference',
922 'section' => 'searchoptions/displaysearchoptions'
923 );
924 }
925
926 $defaultPreferences['searcheverything'] = array(
927 'type' => 'toggle',
928 'label-message' => 'searcheverything-enable',
929 'section' => 'searchoptions/advancedsearchoptions',
930 );
931
932 // Searchable namespaces back-compat with old format
933 $searchableNamespaces = SearchEngine::searchableNamespaces();
934
935 $nsOptions = array();
936
937 foreach ( $wgContLang->getNamespaces() as $ns => $name ) {
938 if ( $ns < 0 ) {
939 continue;
940 }
941
942 $displayNs = str_replace( '_', ' ', $name );
943
944 if ( !$displayNs ) {
945 $displayNs = wfMsg( 'blanknamespace' );
946 }
947
948 $displayNs = htmlspecialchars( $displayNs );
949 $nsOptions[$displayNs] = $ns;
950 }
951
952 $defaultPreferences['searchnamespaces'] = array(
953 'type' => 'multiselect',
954 'label-message' => 'defaultns',
955 'options' => $nsOptions,
956 'section' => 'searchoptions/advancedsearchoptions',
957 'prefix' => 'searchNs',
958 );
959 }
960
961 static function miscPreferences( $user, &$defaultPreferences ) {
962 ## Misc #####################################
963 $defaultPreferences['diffonly'] = array(
964 'type' => 'toggle',
965 'section' => 'misc/diffs',
966 'label-message' => 'tog-diffonly',
967 );
968 $defaultPreferences['norollbackdiff'] = array(
969 'type' => 'toggle',
970 'section' => 'misc/diffs',
971 'label-message' => 'tog-norollbackdiff',
972 );
973
974 // Stuff from Language::getExtraUserToggles()
975 global $wgContLang;
976
977 $toggles = $wgContLang->getExtraUserToggles();
978
979 foreach ( $toggles as $toggle ) {
980 $defaultPreferences[$toggle] = array(
981 'type' => 'toggle',
982 'section' => 'personal/i18n',
983 'label-message' => "tog-$toggle",
984 );
985 }
986 }
987
988 /**
989 * @param $user The User object
990 * @return Array: text/links to display as key; $skinkey as value
991 */
992 static function generateSkinOptions( $user ) {
993 global $wgDefaultSkin, $wgLang, $wgAllowUserCss, $wgAllowUserJs;
994 $ret = array();
995
996 $mptitle = Title::newMainPage();
997 $previewtext = wfMsgHtml( 'skin-preview' );
998
999 # Only show members of Skin::getSkinNames() rather than
1000 # $skinNames (skins is all skin names from Language.php)
1001 $validSkinNames = Skin::getUsableSkins();
1002
1003 # Sort by UI skin name. First though need to update validSkinNames as sometimes
1004 # the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI).
1005 foreach ( $validSkinNames as $skinkey => &$skinname ) {
1006 $msgName = "skinname-{$skinkey}";
1007 $localisedSkinName = wfMsg( $msgName );
1008 if ( !wfEmptyMsg( $msgName, $localisedSkinName ) ) {
1009 $skinname = htmlspecialchars( $localisedSkinName );
1010 }
1011 }
1012 asort( $validSkinNames );
1013 $sk = $user->getSkin();
1014
1015 foreach ( $validSkinNames as $skinkey => $sn ) {
1016 $linkTools = array();
1017
1018 # Mark the default skin
1019 if ( $skinkey == $wgDefaultSkin ) {
1020 $linkTools[] = wfMsgHtml( 'default' );
1021 }
1022
1023 # Create preview link
1024 $mplink = htmlspecialchars( $mptitle->getLocalURL( "useskin=$skinkey" ) );
1025 $linkTools[] = "<a target='_blank' href=\"$mplink\">$previewtext</a>";
1026
1027 # Create links to user CSS/JS pages
1028 if ( $wgAllowUserCss ) {
1029 $cssPage = Title::makeTitleSafe( NS_USER, $user->getName() . '/' . $skinkey . '.css' );
1030 $linkTools[] = $sk->link( $cssPage, wfMsgHtml( 'prefs-custom-css' ) );
1031 }
1032
1033 if ( $wgAllowUserJs ) {
1034 $jsPage = Title::makeTitleSafe( NS_USER, $user->getName() . '/' . $skinkey . '.js' );
1035 $linkTools[] = $sk->link( $jsPage, wfMsgHtml( 'prefs-custom-js' ) );
1036 }
1037
1038 $display = $sn . ' ' . wfMsg( 'parentheses', $wgLang->pipeList( $linkTools ) );
1039 $ret[$display] = $skinkey;
1040 }
1041
1042 return $ret;
1043 }
1044
1045 static function getDateOptions() {
1046 global $wgLang;
1047 $dateopts = $wgLang->getDatePreferences();
1048
1049 $ret = array();
1050
1051 if ( $dateopts ) {
1052 if ( !in_array( 'default', $dateopts ) ) {
1053 $dateopts[] = 'default'; // Make sure default is always valid
1054 // Bug 19237
1055 }
1056
1057 // KLUGE: site default might not be valid for user language
1058 global $wgDefaultUserOptions;
1059 if ( !in_array( $wgDefaultUserOptions['date'], $dateopts ) ) {
1060 $wgDefaultUserOptions['date'] = 'default';
1061 }
1062
1063 $epoch = wfTimestampNow();
1064 foreach ( $dateopts as $key ) {
1065 if ( $key == 'default' ) {
1066 $formatted = wfMsgHtml( 'datedefault' );
1067 } else {
1068 $formatted = htmlspecialchars( $wgLang->timeanddate( $epoch, false, $key ) );
1069 }
1070 $ret[$formatted] = $key;
1071 }
1072 }
1073 return $ret;
1074 }
1075
1076 static function getImageSizes() {
1077 global $wgImageLimits;
1078
1079 $ret = array();
1080
1081 foreach ( $wgImageLimits as $index => $limits ) {
1082 $display = "{$limits[0]}×{$limits[1]}" . wfMsg( 'unit-pixel' );
1083 $ret[$display] = $index;
1084 }
1085
1086 return $ret;
1087 }
1088
1089 static function getThumbSizes() {
1090 global $wgThumbLimits;
1091
1092 $ret = array();
1093
1094 foreach ( $wgThumbLimits as $index => $size ) {
1095 $display = $size . wfMsg( 'unit-pixel' );
1096 $ret[$display] = $index;
1097 }
1098
1099 return $ret;
1100 }
1101
1102 static function validateSignature( $signature, $alldata ) {
1103 global $wgParser, $wgMaxSigChars, $wgLang;
1104 if ( mb_strlen( $signature ) > $wgMaxSigChars ) {
1105 return Xml::element( 'span', array( 'class' => 'error' ),
1106 wfMsgExt( 'badsiglength', 'parsemag',
1107 $wgLang->formatNum( $wgMaxSigChars )
1108 )
1109 );
1110 } elseif ( !empty( $alldata['fancysig'] ) &&
1111 false === $wgParser->validateSig( $signature ) ) {
1112 return Xml::element( 'span', array( 'class' => 'error' ), wfMsg( 'badsig' ) );
1113 } else {
1114 return true;
1115 }
1116 }
1117
1118 static function cleanSignature( $signature, $alldata ) {
1119 global $wgParser;
1120 if ( $alldata['fancysig'] ) {
1121 $signature = $wgParser->cleanSig( $signature );
1122 } else {
1123 // When no fancy sig used, make sure ~{3,5} get removed.
1124 $signature = $wgParser->cleanSigInSig( $signature );
1125 }
1126
1127 return $signature;
1128 }
1129
1130 static function validateEmail( $email, $alldata ) {
1131 if ( $email && !User::isValidEmailAddr( $email ) ) {
1132 return wfMsgExt( 'invalidemailaddress', 'parseinline' );
1133 }
1134
1135 global $wgEmailConfirmToEdit;
1136 if ( $wgEmailConfirmToEdit && !$email ) {
1137 return wfMsgExt( 'noemailtitle', 'parseinline' );
1138 }
1139 return true;
1140 }
1141
1142 static function getFormObject( $user, $formClass = 'PreferencesForm' ) {
1143 $formDescriptor = Preferences::getPreferences( $user );
1144 $htmlForm = new $formClass( $formDescriptor, 'prefs' );
1145
1146 $htmlForm->setSubmitText( wfMsg( 'saveprefs' ) );
1147 # Used message keys: 'accesskey-preferences-save', 'tooltip-preferences-save'
1148 $htmlForm->setSubmitTooltip( 'preferences-save' );
1149 $htmlForm->setTitle( SpecialPage::getTitleFor( 'Preferences' ) );
1150 $htmlForm->setSubmitID( 'prefsubmit' );
1151 $htmlForm->setSubmitCallback( array( 'Preferences', 'tryFormSubmit' ) );
1152
1153 return $htmlForm;
1154 }
1155
1156 static function getTimezoneOptions() {
1157 $opt = array();
1158
1159 global $wgLocalTZoffset;
1160
1161 $opt[wfMsg( 'timezoneuseserverdefault' )] = "System|$wgLocalTZoffset";
1162 $opt[wfMsg( 'timezoneuseoffset' )] = 'other';
1163 $opt[wfMsg( 'guesstimezone' )] = 'guess';
1164
1165 if ( function_exists( 'timezone_identifiers_list' ) ) {
1166 # Read timezone list
1167 $tzs = timezone_identifiers_list();
1168 sort( $tzs );
1169
1170 $tzRegions = array();
1171 $tzRegions['Africa'] = wfMsg( 'timezoneregion-africa' );
1172 $tzRegions['America'] = wfMsg( 'timezoneregion-america' );
1173 $tzRegions['Antarctica'] = wfMsg( 'timezoneregion-antarctica' );
1174 $tzRegions['Arctic'] = wfMsg( 'timezoneregion-arctic' );
1175 $tzRegions['Asia'] = wfMsg( 'timezoneregion-asia' );
1176 $tzRegions['Atlantic'] = wfMsg( 'timezoneregion-atlantic' );
1177 $tzRegions['Australia'] = wfMsg( 'timezoneregion-australia' );
1178 $tzRegions['Europe'] = wfMsg( 'timezoneregion-europe' );
1179 $tzRegions['Indian'] = wfMsg( 'timezoneregion-indian' );
1180 $tzRegions['Pacific'] = wfMsg( 'timezoneregion-pacific' );
1181 asort( $tzRegions );
1182
1183 $prefill = array_fill_keys( array_values( $tzRegions ), array() );
1184 $opt = array_merge( $opt, $prefill );
1185
1186 $now = date_create( 'now' );
1187
1188 foreach ( $tzs as $tz ) {
1189 $z = explode( '/', $tz, 2 );
1190
1191 # timezone_identifiers_list() returns a number of
1192 # backwards-compatibility entries. This filters them out of the
1193 # list presented to the user.
1194 if ( count( $z ) != 2 || !array_key_exists( $z[0], $tzRegions ) ) {
1195 continue;
1196 }
1197
1198 # Localize region
1199 $z[0] = $tzRegions[$z[0]];
1200
1201 $minDiff = floor( timezone_offset_get( timezone_open( $tz ), $now ) / 60 );
1202
1203 $display = str_replace( '_', ' ', $z[0] . '/' . $z[1] );
1204 $value = "ZoneInfo|$minDiff|$tz";
1205
1206 $opt[$z[0]][$display] = $value;
1207 }
1208 }
1209 return $opt;
1210 }
1211
1212 static function filterTimezoneInput( $tz, $alldata ) {
1213 $data = explode( '|', $tz, 3 );
1214 switch ( $data[0] ) {
1215 case 'ZoneInfo':
1216 case 'System':
1217 return $tz;
1218 default:
1219 $data = explode( ':', $tz, 2 );
1220 $minDiff = 0;
1221 if ( count( $data ) == 2 ) {
1222 $data[0] = intval( $data[0] );
1223 $data[1] = intval( $data[1] );
1224 $minDiff = abs( $data[0] ) * 60 + $data[1];
1225 if ( $data[0] < 0 ) $minDiff = - $minDiff;
1226 } else {
1227 $minDiff = intval( $data[0] ) * 60;
1228 }
1229
1230 # Max is +14:00 and min is -12:00, see:
1231 # http://en.wikipedia.org/wiki/Timezone
1232 $minDiff = min( $minDiff, 840 ); # 14:00
1233 $minDiff = max( $minDiff, - 720 ); # -12:00
1234 return 'Offset|' . $minDiff;
1235 }
1236 }
1237
1238 static function tryFormSubmit( $formData, $entryPoint = 'internal' ) {
1239 global $wgUser, $wgEmailAuthentication, $wgEnableEmail;
1240
1241 $result = true;
1242
1243 // Filter input
1244 foreach ( array_keys( $formData ) as $name ) {
1245 if ( isset( self::$saveFilters[$name] ) ) {
1246 $formData[$name] =
1247 call_user_func( self::$saveFilters[$name], $formData[$name], $formData );
1248 }
1249 }
1250
1251 // Stuff that shouldn't be saved as a preference.
1252 $saveBlacklist = array(
1253 'realname',
1254 'emailaddress',
1255 );
1256
1257 if ( $wgEnableEmail ) {
1258 $newaddr = $formData['emailaddress'];
1259 $oldaddr = $wgUser->getEmail();
1260 if ( ( $newaddr != '' ) && ( $newaddr != $oldaddr ) ) {
1261 # the user has supplied a new email address on the login page
1262 # new behaviour: set this new emailaddr from login-page into user database record
1263 $wgUser->setEmail( $newaddr );
1264 # but flag as "dirty" = unauthenticated
1265 $wgUser->invalidateEmail();
1266 if ( $wgEmailAuthentication ) {
1267 # Mail a temporary password to the dirty address.
1268 # User can come back through the confirmation URL to re-enable email.
1269 $result = $wgUser->sendConfirmationMail( $oldaddr != '' );
1270 if ( WikiError::isError( $result ) ) {
1271 return wfMsg( 'mailerror', htmlspecialchars( $result->getMessage() ) );
1272 } elseif ( $entryPoint == 'ui' ) {
1273 $result = 'eauth';
1274 }
1275 }
1276 } else {
1277 $wgUser->setEmail( $newaddr );
1278 }
1279 if ( $oldaddr != $newaddr ) {
1280 wfRunHooks( 'PrefsEmailAudit', array( $wgUser, $oldaddr, $newaddr ) );
1281 }
1282 }
1283
1284 // Fortunately, the realname field is MUCH simpler
1285 global $wgHiddenPrefs;
1286 if ( !in_array( 'realname', $wgHiddenPrefs ) ) {
1287 $realName = $formData['realname'];
1288 $wgUser->setRealName( $realName );
1289 }
1290
1291 foreach ( $saveBlacklist as $b ) {
1292 unset( $formData[$b] );
1293 }
1294
1295 // Keeps old preferences from interfering due to back-compat
1296 // code, etc.
1297 $wgUser->resetOptions();
1298
1299 foreach ( $formData as $key => $value ) {
1300 $wgUser->setOption( $key, $value );
1301 }
1302
1303 $wgUser->saveSettings();
1304
1305 return $result;
1306 }
1307
1308 public static function tryUISubmit( $formData ) {
1309 $res = self::tryFormSubmit( $formData, 'ui' );
1310
1311 if ( $res ) {
1312 $urlOptions = array( 'success' );
1313
1314 if ( $res === 'eauth' ) {
1315 $urlOptions[] = 'eauth';
1316 }
1317
1318 $queryString = implode( '&', $urlOptions );
1319
1320 $url = SpecialPage::getTitleFor( 'Preferences' )->getFullURL( $queryString );
1321
1322 global $wgOut;
1323 $wgOut->redirect( $url );
1324 }
1325
1326 return true;
1327 }
1328
1329 public static function loadOldSearchNs( $user ) {
1330 $searchableNamespaces = SearchEngine::searchableNamespaces();
1331 // Back compat with old format
1332 $arr = array();
1333
1334 foreach ( $searchableNamespaces as $ns => $name ) {
1335 if ( $user->getOption( 'searchNs' . $ns ) ) {
1336 $arr[] = $ns;
1337 }
1338 }
1339
1340 return $arr;
1341 }
1342 }
1343
1344 /** Some tweaks to allow js prefs to work */
1345 class PreferencesForm extends HTMLForm {
1346 function wrapForm( $html ) {
1347 $html = Xml::tags( 'div', array( 'id' => 'preferences' ), $html );
1348
1349 return parent::wrapForm( $html );
1350 }
1351
1352 function getButtons() {
1353 $html = parent::getButtons();
1354
1355 global $wgUser;
1356
1357 $sk = $wgUser->getSkin();
1358 $t = SpecialPage::getTitleFor( 'Preferences', 'reset' );
1359
1360 $html .= "\n" . $sk->link( $t, wfMsgHtml( 'restoreprefs' ) );
1361
1362 $html = Xml::tags( 'div', array( 'class' => 'mw-prefs-buttons' ), $html );
1363
1364 return $html;
1365 }
1366
1367 function filterDataForSubmit( $data ) {
1368 // Support for separating MultiSelect preferences into multiple preferences
1369 // Due to lack of array support.
1370 foreach ( $this->mFlatFields as $fieldname => $field ) {
1371 $info = $field->mParams;
1372 if ( $field instanceof HTMLMultiSelectField ) {
1373 $options = HTMLFormField::flattenOptions( $info['options'] );
1374 $prefix = isset( $info['prefix'] ) ? $info['prefix'] : $fieldname;
1375
1376 foreach ( $options as $opt ) {
1377 $data["$prefix$opt"] = in_array( $opt, $data[$fieldname] );
1378 }
1379
1380 unset( $data[$fieldname] );
1381 }
1382 }
1383
1384 return $data;
1385 }
1386 }