Removal of unused globals
[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 global $wgLang;
475
476 $settings = array_flip( $wgLang->getQuickbarSettings() );
477
478 $defaultPreferences['quickbar'] = array(
479 'type' => 'radio',
480 'options' => $settings,
481 'section' => 'rendering/skin',
482 'label-message' => 'qbsettings',
483 );
484 }
485 }
486
487 static function mathPreferences( $user, &$defaultPreferences ) {
488 ## Math #####################################
489 global $wgUseTeX, $wgLang;
490 if ( $wgUseTeX ) {
491 $defaultPreferences['math'] = array(
492 'type' => 'radio',
493 'options' => array_flip( array_map( 'wfMsgHtml', $wgLang->getMathNames() ) ),
494 'label' => '&#160;',
495 'section' => 'rendering/math',
496 );
497 }
498 }
499
500 static function filesPreferences( $user, &$defaultPreferences ) {
501 ## Files #####################################
502 $defaultPreferences['imagesize'] = array(
503 'type' => 'select',
504 'options' => self::getImageSizes(),
505 'label-message' => 'imagemaxsize',
506 'section' => 'rendering/files',
507 );
508 $defaultPreferences['thumbsize'] = array(
509 'type' => 'select',
510 'options' => self::getThumbSizes(),
511 'label-message' => 'thumbsize',
512 'section' => 'rendering/files',
513 );
514 }
515
516 static function datetimePreferences( $user, &$defaultPreferences ) {
517 global $wgLang;
518
519 ## Date and time #####################################
520 $dateOptions = self::getDateOptions();
521 if ( $dateOptions ) {
522 $defaultPreferences['date'] = array(
523 'type' => 'radio',
524 'options' => $dateOptions,
525 'label' => '&#160;',
526 'section' => 'datetime/dateformat',
527 );
528 }
529
530 // Info
531 $nowlocal = Xml::element( 'span', array( 'id' => 'wpLocalTime' ),
532 $wgLang->time( $now = wfTimestampNow(), true ) );
533 $nowserver = $wgLang->time( $now, false ) .
534 Xml::hidden( 'wpServerTime', substr( $now, 8, 2 ) * 60 + substr( $now, 10, 2 ) );
535
536 $defaultPreferences['nowserver'] = array(
537 'type' => 'info',
538 'raw' => 1,
539 'label-message' => 'servertime',
540 'default' => $nowserver,
541 'section' => 'datetime/timeoffset',
542 );
543
544 $defaultPreferences['nowlocal'] = array(
545 'type' => 'info',
546 'raw' => 1,
547 'label-message' => 'localtime',
548 'default' => $nowlocal,
549 'section' => 'datetime/timeoffset',
550 );
551
552 // Grab existing pref.
553 $tzOffset = $user->getOption( 'timecorrection' );
554 $tz = explode( '|', $tzOffset, 2 );
555
556 $tzSetting = $tzOffset;
557 if ( count( $tz ) > 1 && $tz[0] == 'Offset' ) {
558 $minDiff = $tz[1];
559 $tzSetting = sprintf( '%+03d:%02d', floor( $minDiff / 60 ), abs( $minDiff ) % 60 );
560 }
561
562 $defaultPreferences['timecorrection'] = array(
563 'class' => 'HTMLSelectOrOtherField',
564 'label-message' => 'timezonelegend',
565 'options' => self::getTimezoneOptions(),
566 'default' => $tzSetting,
567 'size' => 20,
568 'section' => 'datetime/timeoffset',
569 );
570 }
571
572 static function renderingPreferences( $user, &$defaultPreferences ) {
573 ## Page Rendering ##############################
574 global $wgAllowUserCssPrefs;
575 if ( $wgAllowUserCssPrefs ) {
576 $defaultPreferences['underline'] = array(
577 'type' => 'select',
578 'options' => array(
579 wfMsg( 'underline-never' ) => 0,
580 wfMsg( 'underline-always' ) => 1,
581 wfMsg( 'underline-default' ) => 2,
582 ),
583 'label-message' => 'tog-underline',
584 'section' => 'rendering/advancedrendering',
585 );
586 }
587
588 $stubThresholdValues = array( 0, 50, 100, 500, 1000, 2000, 5000, 10000 );
589 $stubThresholdOptions = array();
590 foreach ( $stubThresholdValues as $value ) {
591 $stubThresholdOptions[wfMsg( 'size-bytes', $value )] = $value;
592 }
593
594 $defaultPreferences['stubthreshold'] = array(
595 'type' => 'selectorother',
596 'section' => 'rendering/advancedrendering',
597 'options' => $stubThresholdOptions,
598 'size' => 20,
599 'label' => wfMsg( 'stub-threshold' ), // Raw HTML message. Yay?
600 );
601
602 if ( $wgAllowUserCssPrefs ) {
603 $defaultPreferences['highlightbroken'] = array(
604 'type' => 'toggle',
605 'section' => 'rendering/advancedrendering',
606 'label' => wfMsg( 'tog-highlightbroken' ), // Raw HTML
607 );
608 $defaultPreferences['showtoc'] = array(
609 'type' => 'toggle',
610 'section' => 'rendering/advancedrendering',
611 'label-message' => 'tog-showtoc',
612 );
613 }
614 $defaultPreferences['nocache'] = array(
615 'type' => 'toggle',
616 'label-message' => 'tog-nocache',
617 'section' => 'rendering/advancedrendering',
618 );
619 $defaultPreferences['showhiddencats'] = array(
620 'type' => 'toggle',
621 'section' => 'rendering/advancedrendering',
622 'label-message' => 'tog-showhiddencats'
623 );
624 $defaultPreferences['showjumplinks'] = array(
625 'type' => 'toggle',
626 'section' => 'rendering/advancedrendering',
627 'label-message' => 'tog-showjumplinks',
628 );
629
630 if ( $wgAllowUserCssPrefs ) {
631 $defaultPreferences['justify'] = array(
632 'type' => 'toggle',
633 'section' => 'rendering/advancedrendering',
634 'label-message' => 'tog-justify',
635 );
636 }
637
638 $defaultPreferences['numberheadings'] = array(
639 'type' => 'toggle',
640 'section' => 'rendering/advancedrendering',
641 'label-message' => 'tog-numberheadings',
642 );
643 }
644
645 static function editingPreferences( $user, &$defaultPreferences ) {
646 global $wgUseExternalEditor, $wgAllowUserCssPrefs;
647
648 ## Editing #####################################
649 $defaultPreferences['cols'] = array(
650 'type' => 'int',
651 'label-message' => 'columns',
652 'section' => 'editing/textboxsize',
653 'min' => 4,
654 'max' => 1000,
655 );
656 $defaultPreferences['rows'] = array(
657 'type' => 'int',
658 'label-message' => 'rows',
659 'section' => 'editing/textboxsize',
660 'min' => 4,
661 'max' => 1000,
662 );
663
664 if ( $wgAllowUserCssPrefs ) {
665 $defaultPreferences['editfont'] = array(
666 'type' => 'select',
667 'section' => 'editing/advancedediting',
668 'label-message' => 'editfont-style',
669 'options' => array(
670 wfMsg( 'editfont-default' ) => 'default',
671 wfMsg( 'editfont-monospace' ) => 'monospace',
672 wfMsg( 'editfont-sansserif' ) => 'sans-serif',
673 wfMsg( 'editfont-serif' ) => 'serif',
674 )
675 );
676 }
677 $defaultPreferences['previewontop'] = array(
678 'type' => 'toggle',
679 'section' => 'editing/advancedediting',
680 'label-message' => 'tog-previewontop',
681 );
682 $defaultPreferences['previewonfirst'] = array(
683 'type' => 'toggle',
684 'section' => 'editing/advancedediting',
685 'label-message' => 'tog-previewonfirst',
686 );
687
688 if ( $wgAllowUserCssPrefs ) {
689 $defaultPreferences['editsection'] = array(
690 'type' => 'toggle',
691 'section' => 'editing/advancedediting',
692 'label-message' => 'tog-editsection',
693 );
694 }
695 $defaultPreferences['editsectiononrightclick'] = array(
696 'type' => 'toggle',
697 'section' => 'editing/advancedediting',
698 'label-message' => 'tog-editsectiononrightclick',
699 );
700 $defaultPreferences['editondblclick'] = array(
701 'type' => 'toggle',
702 'section' => 'editing/advancedediting',
703 'label-message' => 'tog-editondblclick',
704 );
705 $defaultPreferences['showtoolbar'] = array(
706 'type' => 'toggle',
707 'section' => 'editing/advancedediting',
708 'label-message' => 'tog-showtoolbar',
709 );
710
711 if ( $wgUseExternalEditor ) {
712 $defaultPreferences['externaleditor'] = array(
713 'type' => 'toggle',
714 'section' => 'editing/advancedediting',
715 'label-message' => 'tog-externaleditor',
716 );
717 $defaultPreferences['externaldiff'] = array(
718 'type' => 'toggle',
719 'section' => 'editing/advancedediting',
720 'label-message' => 'tog-externaldiff',
721 );
722 }
723
724 $defaultPreferences['forceeditsummary'] = array(
725 'type' => 'toggle',
726 'section' => 'editing/advancedediting',
727 'label-message' => 'tog-forceeditsummary',
728 );
729
730
731 $defaultPreferences['uselivepreview'] = array(
732 'type' => 'toggle',
733 'section' => 'editing/advancedediting',
734 'label-message' => 'tog-uselivepreview',
735 );
736 }
737
738 static function rcPreferences( $user, &$defaultPreferences ) {
739 global $wgRCMaxAge, $wgUseRCPatrol, $wgLang;
740
741 ## RecentChanges #####################################
742 $defaultPreferences['rcdays'] = array(
743 'type' => 'float',
744 'label-message' => 'recentchangesdays',
745 'section' => 'rc/displayrc',
746 'min' => 1,
747 'max' => ceil( $wgRCMaxAge / ( 3600 * 24 ) ),
748 'help' => wfMsgExt(
749 'recentchangesdays-max',
750 array( 'parsemag' ),
751 $wgLang->formatNum( ceil( $wgRCMaxAge / ( 3600 * 24 ) ) )
752 )
753 );
754 $defaultPreferences['rclimit'] = array(
755 'type' => 'int',
756 'label-message' => 'recentchangescount',
757 'help-message' => 'prefs-help-recentchangescount',
758 'section' => 'rc/displayrc',
759 );
760 $defaultPreferences['usenewrc'] = array(
761 'type' => 'toggle',
762 'label-message' => 'tog-usenewrc',
763 'section' => 'rc/advancedrc',
764 );
765 $defaultPreferences['hideminor'] = array(
766 'type' => 'toggle',
767 'label-message' => 'tog-hideminor',
768 'section' => 'rc/advancedrc',
769 );
770
771 if ( $wgUseRCPatrol ) {
772 $defaultPreferences['hidepatrolled'] = array(
773 'type' => 'toggle',
774 'section' => 'rc/advancedrc',
775 'label-message' => 'tog-hidepatrolled',
776 );
777 $defaultPreferences['newpageshidepatrolled'] = array(
778 'type' => 'toggle',
779 'section' => 'rc/advancedrc',
780 'label-message' => 'tog-newpageshidepatrolled',
781 );
782 }
783
784 global $wgRCShowWatchingUsers;
785 if ( $wgRCShowWatchingUsers ) {
786 $defaultPreferences['shownumberswatching'] = array(
787 'type' => 'toggle',
788 'section' => 'rc/advancedrc',
789 'label-message' => 'tog-shownumberswatching',
790 );
791 }
792 }
793
794 static function watchlistPreferences( $user, &$defaultPreferences ) {
795 global $wgUseRCPatrol, $wgEnableAPI;
796
797 ## Watchlist #####################################
798 $defaultPreferences['watchlistdays'] = array(
799 'type' => 'float',
800 'min' => 0,
801 'max' => 7,
802 'section' => 'watchlist/displaywatchlist',
803 'help' => wfMsgHtml( 'prefs-watchlist-days-max' ),
804 'label-message' => 'prefs-watchlist-days',
805 );
806 $defaultPreferences['wllimit'] = array(
807 'type' => 'int',
808 'min' => 0,
809 'max' => 1000,
810 'label-message' => 'prefs-watchlist-edits',
811 'help' => wfMsgHtml( 'prefs-watchlist-edits-max' ),
812 'section' => 'watchlist/displaywatchlist',
813 );
814 $defaultPreferences['extendwatchlist'] = array(
815 'type' => 'toggle',
816 'section' => 'watchlist/advancedwatchlist',
817 'label-message' => 'tog-extendwatchlist',
818 );
819 $defaultPreferences['watchlisthideminor'] = array(
820 'type' => 'toggle',
821 'section' => 'watchlist/advancedwatchlist',
822 'label-message' => 'tog-watchlisthideminor',
823 );
824 $defaultPreferences['watchlisthidebots'] = array(
825 'type' => 'toggle',
826 'section' => 'watchlist/advancedwatchlist',
827 'label-message' => 'tog-watchlisthidebots',
828 );
829 $defaultPreferences['watchlisthideown'] = array(
830 'type' => 'toggle',
831 'section' => 'watchlist/advancedwatchlist',
832 'label-message' => 'tog-watchlisthideown',
833 );
834 $defaultPreferences['watchlisthideanons'] = array(
835 'type' => 'toggle',
836 'section' => 'watchlist/advancedwatchlist',
837 'label-message' => 'tog-watchlisthideanons',
838 );
839 $defaultPreferences['watchlisthideliu'] = array(
840 'type' => 'toggle',
841 'section' => 'watchlist/advancedwatchlist',
842 'label-message' => 'tog-watchlisthideliu',
843 );
844
845 if ( $wgUseRCPatrol ) {
846 $defaultPreferences['watchlisthidepatrolled'] = array(
847 'type' => 'toggle',
848 'section' => 'watchlist/advancedwatchlist',
849 'label-message' => 'tog-watchlisthidepatrolled',
850 );
851 }
852
853 if ( $wgEnableAPI ) {
854 # Some random gibberish as a proposed default
855 $hash = sha1( mt_rand() . microtime( true ) );
856
857 $defaultPreferences['watchlisttoken'] = array(
858 'type' => 'text',
859 'section' => 'watchlist/advancedwatchlist',
860 'label-message' => 'prefs-watchlist-token',
861 'help' => wfMsgHtml( 'prefs-help-watchlist-token', $hash )
862 );
863 }
864
865 $watchTypes = array(
866 'edit' => 'watchdefault',
867 'move' => 'watchmoves',
868 'delete' => 'watchdeletion'
869 );
870
871 // Kinda hacky
872 if ( $user->isAllowed( 'createpage' ) || $user->isAllowed( 'createtalk' ) ) {
873 $watchTypes['read'] = 'watchcreations';
874 }
875
876 foreach ( $watchTypes as $action => $pref ) {
877 if ( $user->isAllowed( $action ) ) {
878 $defaultPreferences[$pref] = array(
879 'type' => 'toggle',
880 'section' => 'watchlist/advancedwatchlist',
881 'label-message' => "tog-$pref",
882 );
883 }
884 }
885 }
886
887 static function searchPreferences( $user, &$defaultPreferences ) {
888 global $wgContLang;
889
890 ## Search #####################################
891 $defaultPreferences['searchlimit'] = array(
892 'type' => 'int',
893 'label-message' => 'resultsperpage',
894 'section' => 'searchoptions/displaysearchoptions',
895 'min' => 0,
896 );
897 $defaultPreferences['contextlines'] = array(
898 'type' => 'int',
899 'label-message' => 'contextlines',
900 'section' => 'searchoptions/displaysearchoptions',
901 'min' => 0,
902 );
903 $defaultPreferences['contextchars'] = array(
904 'type' => 'int',
905 'label-message' => 'contextchars',
906 'section' => 'searchoptions/displaysearchoptions',
907 'min' => 0,
908 );
909
910 global $wgEnableMWSuggest;
911 if ( $wgEnableMWSuggest ) {
912 $defaultPreferences['disablesuggest'] = array(
913 'type' => 'toggle',
914 'label-message' => 'mwsuggest-disable',
915 'section' => 'searchoptions/displaysearchoptions',
916 );
917 }
918
919 global $wgVectorUseSimpleSearch;
920 if ( $wgVectorUseSimpleSearch ) {
921 $defaultPreferences['vector-simplesearch'] = array(
922 'type' => 'toggle',
923 'label-message' => 'vector-simplesearch-preference',
924 'section' => 'searchoptions/displaysearchoptions'
925 );
926 }
927
928 $defaultPreferences['searcheverything'] = array(
929 'type' => 'toggle',
930 'label-message' => 'searcheverything-enable',
931 'section' => 'searchoptions/advancedsearchoptions',
932 );
933
934 // Searchable namespaces back-compat with old format
935 $searchableNamespaces = SearchEngine::searchableNamespaces();
936
937 $nsOptions = array();
938
939 foreach ( $wgContLang->getNamespaces() as $ns => $name ) {
940 if ( $ns < 0 ) {
941 continue;
942 }
943
944 $displayNs = str_replace( '_', ' ', $name );
945
946 if ( !$displayNs ) {
947 $displayNs = wfMsg( 'blanknamespace' );
948 }
949
950 $displayNs = htmlspecialchars( $displayNs );
951 $nsOptions[$displayNs] = $ns;
952 }
953
954 $defaultPreferences['searchnamespaces'] = array(
955 'type' => 'multiselect',
956 'label-message' => 'defaultns',
957 'options' => $nsOptions,
958 'section' => 'searchoptions/advancedsearchoptions',
959 'prefix' => 'searchNs',
960 );
961 }
962
963 static function miscPreferences( $user, &$defaultPreferences ) {
964 ## Misc #####################################
965 $defaultPreferences['diffonly'] = array(
966 'type' => 'toggle',
967 'section' => 'misc/diffs',
968 'label-message' => 'tog-diffonly',
969 );
970 $defaultPreferences['norollbackdiff'] = array(
971 'type' => 'toggle',
972 'section' => 'misc/diffs',
973 'label-message' => 'tog-norollbackdiff',
974 );
975
976 // Stuff from Language::getExtraUserToggles()
977 global $wgContLang;
978
979 $toggles = $wgContLang->getExtraUserToggles();
980
981 foreach ( $toggles as $toggle ) {
982 $defaultPreferences[$toggle] = array(
983 'type' => 'toggle',
984 'section' => 'personal/i18n',
985 'label-message' => "tog-$toggle",
986 );
987 }
988 }
989
990 /**
991 * @param $user The User object
992 * @return Array: text/links to display as key; $skinkey as value
993 */
994 static function generateSkinOptions( $user ) {
995 global $wgDefaultSkin, $wgLang, $wgAllowUserCss, $wgAllowUserJs;
996 $ret = array();
997
998 $mptitle = Title::newMainPage();
999 $previewtext = wfMsgHtml( 'skin-preview' );
1000
1001 # Only show members of Skin::getSkinNames() rather than
1002 # $skinNames (skins is all skin names from Language.php)
1003 $validSkinNames = Skin::getUsableSkins();
1004
1005 # Sort by UI skin name. First though need to update validSkinNames as sometimes
1006 # the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI).
1007 foreach ( $validSkinNames as $skinkey => &$skinname ) {
1008 $msgName = "skinname-{$skinkey}";
1009 $localisedSkinName = wfMsg( $msgName );
1010 if ( !wfEmptyMsg( $msgName, $localisedSkinName ) ) {
1011 $skinname = htmlspecialchars( $localisedSkinName );
1012 }
1013 }
1014 asort( $validSkinNames );
1015 $sk = $user->getSkin();
1016
1017 foreach ( $validSkinNames as $skinkey => $sn ) {
1018 $linkTools = array();
1019
1020 # Mark the default skin
1021 if ( $skinkey == $wgDefaultSkin ) {
1022 $linkTools[] = wfMsgHtml( 'default' );
1023 }
1024
1025 # Create preview link
1026 $mplink = htmlspecialchars( $mptitle->getLocalURL( "useskin=$skinkey" ) );
1027 $linkTools[] = "<a target='_blank' href=\"$mplink\">$previewtext</a>";
1028
1029 # Create links to user CSS/JS pages
1030 if ( $wgAllowUserCss ) {
1031 $cssPage = Title::makeTitleSafe( NS_USER, $user->getName() . '/' . $skinkey . '.css' );
1032 $linkTools[] = $sk->link( $cssPage, wfMsgHtml( 'prefs-custom-css' ) );
1033 }
1034
1035 if ( $wgAllowUserJs ) {
1036 $jsPage = Title::makeTitleSafe( NS_USER, $user->getName() . '/' . $skinkey . '.js' );
1037 $linkTools[] = $sk->link( $jsPage, wfMsgHtml( 'prefs-custom-js' ) );
1038 }
1039
1040 $display = $sn . ' ' . wfMsg( 'parentheses', $wgLang->pipeList( $linkTools ) );
1041 $ret[$display] = $skinkey;
1042 }
1043
1044 return $ret;
1045 }
1046
1047 static function getDateOptions() {
1048 global $wgLang;
1049 $dateopts = $wgLang->getDatePreferences();
1050
1051 $ret = array();
1052
1053 if ( $dateopts ) {
1054 if ( !in_array( 'default', $dateopts ) ) {
1055 $dateopts[] = 'default'; // Make sure default is always valid
1056 // Bug 19237
1057 }
1058
1059 // KLUGE: site default might not be valid for user language
1060 global $wgDefaultUserOptions;
1061 if ( !in_array( $wgDefaultUserOptions['date'], $dateopts ) ) {
1062 $wgDefaultUserOptions['date'] = 'default';
1063 }
1064
1065 $idCnt = 0;
1066 $epoch = wfTimestampNow();
1067 foreach ( $dateopts as $key ) {
1068 if ( $key == 'default' ) {
1069 $formatted = wfMsgHtml( 'datedefault' );
1070 } else {
1071 $formatted = htmlspecialchars( $wgLang->timeanddate( $epoch, false, $key ) );
1072 }
1073 $ret[$formatted] = $key;
1074 }
1075 }
1076 return $ret;
1077 }
1078
1079 static function getImageSizes() {
1080 global $wgImageLimits;
1081
1082 $ret = array();
1083
1084 foreach ( $wgImageLimits as $index => $limits ) {
1085 $display = "{$limits[0]}×{$limits[1]}" . wfMsg( 'unit-pixel' );
1086 $ret[$display] = $index;
1087 }
1088
1089 return $ret;
1090 }
1091
1092 static function getThumbSizes() {
1093 global $wgThumbLimits;
1094
1095 $ret = array();
1096
1097 foreach ( $wgThumbLimits as $index => $size ) {
1098 $display = $size . wfMsg( 'unit-pixel' );
1099 $ret[$display] = $index;
1100 }
1101
1102 return $ret;
1103 }
1104
1105 static function validateSignature( $signature, $alldata ) {
1106 global $wgParser, $wgMaxSigChars, $wgLang;
1107 if ( mb_strlen( $signature ) > $wgMaxSigChars ) {
1108 return Xml::element( 'span', array( 'class' => 'error' ),
1109 wfMsgExt( 'badsiglength', 'parsemag',
1110 $wgLang->formatNum( $wgMaxSigChars )
1111 )
1112 );
1113 } elseif ( !empty( $alldata['fancysig'] ) &&
1114 false === $wgParser->validateSig( $signature ) ) {
1115 return Xml::element( 'span', array( 'class' => 'error' ), wfMsg( 'badsig' ) );
1116 } else {
1117 return true;
1118 }
1119 }
1120
1121 static function cleanSignature( $signature, $alldata ) {
1122 global $wgParser;
1123 if ( $alldata['fancysig'] ) {
1124 $signature = $wgParser->cleanSig( $signature );
1125 } else {
1126 // When no fancy sig used, make sure ~{3,5} get removed.
1127 $signature = $wgParser->cleanSigInSig( $signature );
1128 }
1129
1130 return $signature;
1131 }
1132
1133 static function validateEmail( $email, $alldata ) {
1134 if ( $email && !User::isValidEmailAddr( $email ) ) {
1135 return wfMsgExt( 'invalidemailaddress', 'parseinline' );
1136 }
1137
1138 global $wgEmailConfirmToEdit;
1139 if ( $wgEmailConfirmToEdit && !$email ) {
1140 return wfMsgExt( 'noemailtitle', 'parseinline' );
1141 }
1142 return true;
1143 }
1144
1145 static function getFormObject( $user, $formClass = 'PreferencesForm' ) {
1146 $formDescriptor = Preferences::getPreferences( $user );
1147 $htmlForm = new $formClass( $formDescriptor, 'prefs' );
1148
1149 $htmlForm->setSubmitText( wfMsg( 'saveprefs' ) );
1150 # Used message keys: 'accesskey-preferences-save', 'tooltip-preferences-save'
1151 $htmlForm->setSubmitTooltip( 'preferences-save' );
1152 $htmlForm->setTitle( SpecialPage::getTitleFor( 'Preferences' ) );
1153 $htmlForm->setSubmitID( 'prefsubmit' );
1154 $htmlForm->setSubmitCallback( array( 'Preferences', 'tryFormSubmit' ) );
1155
1156 return $htmlForm;
1157 }
1158
1159 static function getTimezoneOptions() {
1160 $opt = array();
1161
1162 global $wgLocalTZoffset;
1163
1164 $opt[wfMsg( 'timezoneuseserverdefault' )] = "System|$wgLocalTZoffset";
1165 $opt[wfMsg( 'timezoneuseoffset' )] = 'other';
1166 $opt[wfMsg( 'guesstimezone' )] = 'guess';
1167
1168 if ( function_exists( 'timezone_identifiers_list' ) ) {
1169 # Read timezone list
1170 $tzs = timezone_identifiers_list();
1171 sort( $tzs );
1172
1173 $tzRegions = array();
1174 $tzRegions['Africa'] = wfMsg( 'timezoneregion-africa' );
1175 $tzRegions['America'] = wfMsg( 'timezoneregion-america' );
1176 $tzRegions['Antarctica'] = wfMsg( 'timezoneregion-antarctica' );
1177 $tzRegions['Arctic'] = wfMsg( 'timezoneregion-arctic' );
1178 $tzRegions['Asia'] = wfMsg( 'timezoneregion-asia' );
1179 $tzRegions['Atlantic'] = wfMsg( 'timezoneregion-atlantic' );
1180 $tzRegions['Australia'] = wfMsg( 'timezoneregion-australia' );
1181 $tzRegions['Europe'] = wfMsg( 'timezoneregion-europe' );
1182 $tzRegions['Indian'] = wfMsg( 'timezoneregion-indian' );
1183 $tzRegions['Pacific'] = wfMsg( 'timezoneregion-pacific' );
1184 asort( $tzRegions );
1185
1186 $prefill = array_fill_keys( array_values( $tzRegions ), array() );
1187 $opt = array_merge( $opt, $prefill );
1188
1189 $now = date_create( 'now' );
1190
1191 foreach ( $tzs as $tz ) {
1192 $z = explode( '/', $tz, 2 );
1193
1194 # timezone_identifiers_list() returns a number of
1195 # backwards-compatibility entries. This filters them out of the
1196 # list presented to the user.
1197 if ( count( $z ) != 2 || !array_key_exists( $z[0], $tzRegions ) ) {
1198 continue;
1199 }
1200
1201 # Localize region
1202 $z[0] = $tzRegions[$z[0]];
1203
1204 $minDiff = floor( timezone_offset_get( timezone_open( $tz ), $now ) / 60 );
1205
1206 $display = str_replace( '_', ' ', $z[0] . '/' . $z[1] );
1207 $value = "ZoneInfo|$minDiff|$tz";
1208
1209 $opt[$z[0]][$display] = $value;
1210 }
1211 }
1212 return $opt;
1213 }
1214
1215 static function filterTimezoneInput( $tz, $alldata ) {
1216 $data = explode( '|', $tz, 3 );
1217 switch ( $data[0] ) {
1218 case 'ZoneInfo':
1219 case 'System':
1220 return $tz;
1221 default:
1222 $data = explode( ':', $tz, 2 );
1223 $minDiff = 0;
1224 if ( count( $data ) == 2 ) {
1225 $data[0] = intval( $data[0] );
1226 $data[1] = intval( $data[1] );
1227 $minDiff = abs( $data[0] ) * 60 + $data[1];
1228 if ( $data[0] < 0 ) $minDiff = - $minDiff;
1229 } else {
1230 $minDiff = intval( $data[0] ) * 60;
1231 }
1232
1233 # Max is +14:00 and min is -12:00, see:
1234 # http://en.wikipedia.org/wiki/Timezone
1235 $minDiff = min( $minDiff, 840 ); # 14:00
1236 $minDiff = max( $minDiff, - 720 ); # -12:00
1237 return 'Offset|' . $minDiff;
1238 }
1239 }
1240
1241 static function tryFormSubmit( $formData, $entryPoint = 'internal' ) {
1242 global $wgUser, $wgEmailAuthentication, $wgEnableEmail;
1243
1244 $result = true;
1245
1246 // Filter input
1247 foreach ( array_keys( $formData ) as $name ) {
1248 if ( isset( self::$saveFilters[$name] ) ) {
1249 $formData[$name] =
1250 call_user_func( self::$saveFilters[$name], $formData[$name], $formData );
1251 }
1252 }
1253
1254 // Stuff that shouldn't be saved as a preference.
1255 $saveBlacklist = array(
1256 'realname',
1257 'emailaddress',
1258 );
1259
1260 if ( $wgEnableEmail ) {
1261 $newaddr = $formData['emailaddress'];
1262 $oldaddr = $wgUser->getEmail();
1263 if ( ( $newaddr != '' ) && ( $newaddr != $oldaddr ) ) {
1264 # the user has supplied a new email address on the login page
1265 # new behaviour: set this new emailaddr from login-page into user database record
1266 $wgUser->setEmail( $newaddr );
1267 # but flag as "dirty" = unauthenticated
1268 $wgUser->invalidateEmail();
1269 if ( $wgEmailAuthentication ) {
1270 # Mail a temporary password to the dirty address.
1271 # User can come back through the confirmation URL to re-enable email.
1272 $result = $wgUser->sendConfirmationMail( $oldaddr != '' );
1273 if ( WikiError::isError( $result ) ) {
1274 return wfMsg( 'mailerror', htmlspecialchars( $result->getMessage() ) );
1275 } elseif ( $entryPoint == 'ui' ) {
1276 $result = 'eauth';
1277 }
1278 }
1279 } else {
1280 $wgUser->setEmail( $newaddr );
1281 }
1282 if ( $oldaddr != $newaddr ) {
1283 wfRunHooks( 'PrefsEmailAudit', array( $wgUser, $oldaddr, $newaddr ) );
1284 }
1285 }
1286
1287 // Fortunately, the realname field is MUCH simpler
1288 global $wgHiddenPrefs;
1289 if ( !in_array( 'realname', $wgHiddenPrefs ) ) {
1290 $realName = $formData['realname'];
1291 $wgUser->setRealName( $realName );
1292 }
1293
1294 foreach ( $saveBlacklist as $b ) {
1295 unset( $formData[$b] );
1296 }
1297
1298 // Keeps old preferences from interfering due to back-compat
1299 // code, etc.
1300 $wgUser->resetOptions();
1301
1302 foreach ( $formData as $key => $value ) {
1303 $wgUser->setOption( $key, $value );
1304 }
1305
1306 $wgUser->saveSettings();
1307
1308 return $result;
1309 }
1310
1311 public static function tryUISubmit( $formData ) {
1312 $res = self::tryFormSubmit( $formData, 'ui' );
1313
1314 if ( $res ) {
1315 $urlOptions = array( 'success' );
1316
1317 if ( $res === 'eauth' ) {
1318 $urlOptions[] = 'eauth';
1319 }
1320
1321 $queryString = implode( '&', $urlOptions );
1322
1323 $url = SpecialPage::getTitleFor( 'Preferences' )->getFullURL( $queryString );
1324
1325 global $wgOut;
1326 $wgOut->redirect( $url );
1327 }
1328
1329 return true;
1330 }
1331
1332 public static function loadOldSearchNs( $user ) {
1333 $searchableNamespaces = SearchEngine::searchableNamespaces();
1334 // Back compat with old format
1335 $arr = array();
1336
1337 foreach ( $searchableNamespaces as $ns => $name ) {
1338 if ( $user->getOption( 'searchNs' . $ns ) ) {
1339 $arr[] = $ns;
1340 }
1341 }
1342
1343 return $arr;
1344 }
1345 }
1346
1347 /** Some tweaks to allow js prefs to work */
1348 class PreferencesForm extends HTMLForm {
1349 function wrapForm( $html ) {
1350 $html = Xml::tags( 'div', array( 'id' => 'preferences' ), $html );
1351
1352 return parent::wrapForm( $html );
1353 }
1354
1355 function getButtons() {
1356 $html = parent::getButtons();
1357
1358 global $wgUser;
1359
1360 $sk = $wgUser->getSkin();
1361 $t = SpecialPage::getTitleFor( 'Preferences', 'reset' );
1362
1363 $html .= "\n" . $sk->link( $t, wfMsgHtml( 'restoreprefs' ) );
1364
1365 $html = Xml::tags( 'div', array( 'class' => 'mw-prefs-buttons' ), $html );
1366
1367 return $html;
1368 }
1369
1370 function filterDataForSubmit( $data ) {
1371 // Support for separating MultiSelect preferences into multiple preferences
1372 // Due to lack of array support.
1373 foreach ( $this->mFlatFields as $fieldname => $field ) {
1374 $info = $field->mParams;
1375 if ( $field instanceof HTMLMultiSelectField ) {
1376 $options = HTMLFormField::flattenOptions( $info['options'] );
1377 $prefix = isset( $info['prefix'] ) ? $info['prefix'] : $fieldname;
1378
1379 foreach ( $options as $opt ) {
1380 $data["$prefix$opt"] = in_array( $opt, $data[$fieldname] );
1381 }
1382
1383 unset( $data[$fieldname] );
1384 }
1385 }
1386
1387 return $data;
1388 }
1389 }