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