* (bug 23276) Add hook to Special:NewPages to modify query
[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, $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
733 $defaultPreferences['uselivepreview'] = array(
734 'type' => 'toggle',
735 'section' => 'editing/advancedediting',
736 'label-message' => 'tog-uselivepreview',
737 );
738 }
739
740 static function rcPreferences( $user, &$defaultPreferences ) {
741 global $wgRCMaxAge, $wgUseRCPatrol, $wgLang;
742
743 ## RecentChanges #####################################
744 $defaultPreferences['rcdays'] = array(
745 'type' => 'float',
746 'label-message' => 'recentchangesdays',
747 'section' => 'rc/display',
748 'min' => 1,
749 'max' => ceil( $wgRCMaxAge / ( 3600 * 24 ) ),
750 'help' => wfMsgExt(
751 'recentchangesdays-max',
752 array( 'parsemag' ),
753 $wgLang->formatNum( ceil( $wgRCMaxAge / ( 3600 * 24 ) ) )
754 )
755 );
756 $defaultPreferences['rclimit'] = array(
757 'type' => 'int',
758 'label-message' => 'recentchangescount',
759 'help-message' => 'prefs-help-recentchangescount',
760 'section' => 'rc/display',
761 );
762 $defaultPreferences['usenewrc'] = array(
763 'type' => 'toggle',
764 'label-message' => 'tog-usenewrc',
765 'section' => 'rc/advancedrc',
766 );
767 $defaultPreferences['hideminor'] = array(
768 'type' => 'toggle',
769 'label-message' => 'tog-hideminor',
770 'section' => 'rc/advancedrc',
771 );
772
773 if ( $wgUseRCPatrol ) {
774 $defaultPreferences['hidepatrolled'] = array(
775 'type' => 'toggle',
776 'section' => 'rc/advancedrc',
777 'label-message' => 'tog-hidepatrolled',
778 );
779 $defaultPreferences['newpageshidepatrolled'] = array(
780 'type' => 'toggle',
781 'section' => 'rc/advancedrc',
782 'label-message' => 'tog-newpageshidepatrolled',
783 );
784 }
785
786 global $wgRCShowWatchingUsers;
787 if ( $wgRCShowWatchingUsers ) {
788 $defaultPreferences['shownumberswatching'] = array(
789 'type' => 'toggle',
790 'section' => 'rc/advancedrc',
791 'label-message' => 'tog-shownumberswatching',
792 );
793 }
794 }
795
796 static function watchlistPreferences( $user, &$defaultPreferences ) {
797 global $wgUseRCPatrol, $wgEnableAPI;
798
799 ## Watchlist #####################################
800 $defaultPreferences['watchlistdays'] = array(
801 'type' => 'float',
802 'min' => 0,
803 'max' => 7,
804 'section' => 'watchlist/display',
805 'help' => wfMsgHtml( 'prefs-watchlist-days-max' ),
806 'label-message' => 'prefs-watchlist-days',
807 );
808 $defaultPreferences['wllimit'] = array(
809 'type' => 'int',
810 'min' => 0,
811 'max' => 1000,
812 'label-message' => 'prefs-watchlist-edits',
813 'help' => wfMsgHtml( 'prefs-watchlist-edits-max' ),
814 'section' => 'watchlist/display',
815 );
816 $defaultPreferences['extendwatchlist'] = array(
817 'type' => 'toggle',
818 'section' => 'watchlist/advancedwatchlist',
819 'label-message' => 'tog-extendwatchlist',
820 );
821 $defaultPreferences['watchlisthideminor'] = array(
822 'type' => 'toggle',
823 'section' => 'watchlist/advancedwatchlist',
824 'label-message' => 'tog-watchlisthideminor',
825 );
826 $defaultPreferences['watchlisthidebots'] = array(
827 'type' => 'toggle',
828 'section' => 'watchlist/advancedwatchlist',
829 'label-message' => 'tog-watchlisthidebots',
830 );
831 $defaultPreferences['watchlisthideown'] = array(
832 'type' => 'toggle',
833 'section' => 'watchlist/advancedwatchlist',
834 'label-message' => 'tog-watchlisthideown',
835 );
836 $defaultPreferences['watchlisthideanons'] = array(
837 'type' => 'toggle',
838 'section' => 'watchlist/advancedwatchlist',
839 'label-message' => 'tog-watchlisthideanons',
840 );
841 $defaultPreferences['watchlisthideliu'] = array(
842 'type' => 'toggle',
843 'section' => 'watchlist/advancedwatchlist',
844 'label-message' => 'tog-watchlisthideliu',
845 );
846
847 if ( $wgEnableAPI ) {
848 # Some random gibberish as a proposed default
849 $hash = sha1( mt_rand() . microtime( true ) );
850
851 $defaultPreferences['watchlisttoken'] = array(
852 'type' => 'text',
853 'section' => 'watchlist/advancedwatchlist',
854 'label-message' => 'prefs-watchlist-token',
855 'help' => wfMsgHtml( 'prefs-help-watchlist-token', $hash )
856 );
857 }
858
859 if ( $wgUseRCPatrol ) {
860 $defaultPreferences['watchlisthidepatrolled'] = array(
861 'type' => 'toggle',
862 'section' => 'watchlist/advancedwatchlist',
863 'label-message' => 'tog-watchlisthidepatrolled',
864 );
865 }
866
867 $watchTypes = array(
868 'edit' => 'watchdefault',
869 'move' => 'watchmoves',
870 'delete' => 'watchdeletion'
871 );
872
873 // Kinda hacky
874 if ( $user->isAllowed( 'createpage' ) || $user->isAllowed( 'createtalk' ) ) {
875 $watchTypes['read'] = 'watchcreations';
876 }
877
878 foreach ( $watchTypes as $action => $pref ) {
879 if ( $user->isAllowed( $action ) ) {
880 $defaultPreferences[$pref] = array(
881 'type' => 'toggle',
882 'section' => 'watchlist/advancedwatchlist',
883 'label-message' => "tog-$pref",
884 );
885 }
886 }
887 }
888
889 static function searchPreferences( $user, &$defaultPreferences ) {
890 global $wgContLang;
891
892 ## Search #####################################
893 $defaultPreferences['searchlimit'] = array(
894 'type' => 'int',
895 'label-message' => 'resultsperpage',
896 'section' => 'searchoptions/display',
897 'min' => 0,
898 );
899 $defaultPreferences['contextlines'] = array(
900 'type' => 'int',
901 'label-message' => 'contextlines',
902 'section' => 'searchoptions/display',
903 'min' => 0,
904 );
905 $defaultPreferences['contextchars'] = array(
906 'type' => 'int',
907 'label-message' => 'contextchars',
908 'section' => 'searchoptions/display',
909 'min' => 0,
910 );
911
912 global $wgEnableMWSuggest;
913 if ( $wgEnableMWSuggest ) {
914 $defaultPreferences['disablesuggest'] = array(
915 'type' => 'toggle',
916 'label-message' => 'mwsuggest-disable',
917 'section' => 'searchoptions/display',
918 );
919 }
920
921 $defaultPreferences['searcheverything'] = array(
922 'type' => 'toggle',
923 'label-message' => 'searcheverything-enable',
924 'section' => 'searchoptions/advancedsearchoptions',
925 );
926
927 // Searchable namespaces back-compat with old format
928 $searchableNamespaces = SearchEngine::searchableNamespaces();
929
930 $nsOptions = array();
931
932 foreach ( $wgContLang->getNamespaces() as $ns => $name ) {
933 if ( $ns < 0 ) {
934 continue;
935 }
936
937 $displayNs = str_replace( '_', ' ', $name );
938
939 if ( !$displayNs ) {
940 $displayNs = wfMsg( 'blanknamespace' );
941 }
942
943 $displayNs = htmlspecialchars( $displayNs );
944 $nsOptions[$displayNs] = $ns;
945 }
946
947 $defaultPreferences['searchnamespaces'] = array(
948 'type' => 'multiselect',
949 'label-message' => 'defaultns',
950 'options' => $nsOptions,
951 'section' => 'searchoptions/advancedsearchoptions',
952 'prefix' => 'searchNs',
953 );
954 }
955
956 static function miscPreferences( $user, &$defaultPreferences ) {
957 ## Misc #####################################
958 $defaultPreferences['diffonly'] = array(
959 'type' => 'toggle',
960 'section' => 'misc/diffs',
961 'label-message' => 'tog-diffonly',
962 );
963 $defaultPreferences['norollbackdiff'] = array(
964 'type' => 'toggle',
965 'section' => 'misc/diffs',
966 'label-message' => 'tog-norollbackdiff',
967 );
968
969 // Stuff from Language::getExtraUserToggles()
970 global $wgContLang;
971
972 $toggles = $wgContLang->getExtraUserToggles();
973
974 foreach ( $toggles as $toggle ) {
975 $defaultPreferences[$toggle] = array(
976 'type' => 'toggle',
977 'section' => 'personal/i18n',
978 'label-message' => "tog-$toggle",
979 );
980 }
981 }
982
983 /**
984 * @param object $user The user object
985 * @return array Text/links to display as key; $skinkey as value
986 */
987 static function generateSkinOptions( $user ) {
988 global $wgDefaultSkin, $wgLang, $wgAllowUserCss, $wgAllowUserJs;
989 $ret = array();
990
991 $mptitle = Title::newMainPage();
992 $previewtext = wfMsgHtml( 'skin-preview' );
993
994 # Only show members of Skin::getSkinNames() rather than
995 # $skinNames (skins is all skin names from Language.php)
996 $validSkinNames = Skin::getUsableSkins();
997
998 # Sort by UI skin name. First though need to update validSkinNames as sometimes
999 # the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI).
1000 foreach ( $validSkinNames as $skinkey => &$skinname ) {
1001 $msgName = "skinname-{$skinkey}";
1002 $localisedSkinName = wfMsg( $msgName );
1003 if ( !wfEmptyMsg( $msgName, $localisedSkinName ) ) {
1004 $skinname = htmlspecialchars( $localisedSkinName );
1005 }
1006 }
1007 asort( $validSkinNames );
1008 $sk = $user->getSkin();
1009
1010 foreach ( $validSkinNames as $skinkey => $sn ) {
1011 $linkTools = array();
1012
1013 # Mark the default skin
1014 if ( $skinkey == $wgDefaultSkin ) {
1015 $linkTools[] = wfMsgHtml( 'default' );
1016 }
1017
1018 # Create preview link
1019 $mplink = htmlspecialchars( $mptitle->getLocalURL( "useskin=$skinkey" ) );
1020 $linkTools[] = "<a target='_blank' href=\"$mplink\">$previewtext</a>";
1021
1022 # Create links to user CSS/JS pages
1023 if ( $wgAllowUserCss ) {
1024 $cssPage = Title::makeTitleSafe( NS_USER, $user->getName() . '/' . $skinkey . '.css' );
1025 $linkTools[] = $sk->link( $cssPage, wfMsgHtml( 'prefs-custom-css' ) );
1026 }
1027
1028 if ( $wgAllowUserJs ) {
1029 $jsPage = Title::makeTitleSafe( NS_USER, $user->getName() . '/' . $skinkey . '.js' );
1030 $linkTools[] = $sk->link( $jsPage, wfMsgHtml( 'prefs-custom-js' ) );
1031 }
1032
1033 $display = $sn . ' ' . wfMsg( 'parentheses', $wgLang->pipeList( $linkTools ) );
1034 $ret[$display] = $skinkey;
1035 }
1036
1037 return $ret;
1038 }
1039
1040 static function getDateOptions() {
1041 global $wgLang;
1042 $dateopts = $wgLang->getDatePreferences();
1043
1044 $ret = array();
1045
1046 if ( $dateopts ) {
1047 if ( !in_array( 'default', $dateopts ) ) {
1048 $dateopts[] = 'default'; // Make sure default is always valid
1049 // Bug 19237
1050 }
1051
1052 // KLUGE: site default might not be valid for user language
1053 global $wgDefaultUserOptions;
1054 if ( !in_array( $wgDefaultUserOptions['date'], $dateopts ) ) {
1055 $wgDefaultUserOptions['date'] = 'default';
1056 }
1057
1058 $idCnt = 0;
1059 $epoch = wfTimestampNow();
1060 foreach ( $dateopts as $key ) {
1061 if ( $key == 'default' ) {
1062 $formatted = wfMsgHtml( 'datedefault' );
1063 } else {
1064 $formatted = htmlspecialchars( $wgLang->timeanddate( $epoch, false, $key ) );
1065 }
1066 $ret[$formatted] = $key;
1067 }
1068 }
1069 return $ret;
1070 }
1071
1072 static function getImageSizes() {
1073 global $wgImageLimits;
1074
1075 $ret = array();
1076
1077 foreach ( $wgImageLimits as $index => $limits ) {
1078 $display = "{$limits[0]}×{$limits[1]}" . wfMsg( 'unit-pixel' );
1079 $ret[$display] = $index;
1080 }
1081
1082 return $ret;
1083 }
1084
1085 static function getThumbSizes() {
1086 global $wgThumbLimits;
1087
1088 $ret = array();
1089
1090 foreach ( $wgThumbLimits as $index => $size ) {
1091 $display = $size . wfMsg( 'unit-pixel' );
1092 $ret[$display] = $index;
1093 }
1094
1095 return $ret;
1096 }
1097
1098 static function validateSignature( $signature, $alldata ) {
1099 global $wgParser, $wgMaxSigChars, $wgLang;
1100 if ( mb_strlen( $signature ) > $wgMaxSigChars ) {
1101 return Xml::element( 'span', array( 'class' => 'error' ),
1102 wfMsgExt( 'badsiglength', 'parsemag',
1103 $wgLang->formatNum( $wgMaxSigChars )
1104 )
1105 );
1106 } elseif ( !empty( $alldata['fancysig'] ) &&
1107 false === $wgParser->validateSig( $signature ) ) {
1108 return Xml::element( 'span', array( 'class' => 'error' ), wfMsg( 'badsig' ) );
1109 } else {
1110 return true;
1111 }
1112 }
1113
1114 static function cleanSignature( $signature, $alldata ) {
1115 global $wgParser;
1116 if ( $alldata['fancysig'] ) {
1117 $signature = $wgParser->cleanSig( $signature );
1118 } else {
1119 // When no fancy sig used, make sure ~{3,5} get removed.
1120 $signature = $wgParser->cleanSigInSig( $signature );
1121 }
1122
1123 return $signature;
1124 }
1125
1126 static function validateEmail( $email, $alldata ) {
1127 if ( $email && !User::isValidEmailAddr( $email ) ) {
1128 return wfMsgExt( 'invalidemailaddress', 'parseinline' );
1129 }
1130
1131 global $wgEmailConfirmToEdit;
1132 if ( $wgEmailConfirmToEdit && !$email ) {
1133 return wfMsgExt( 'noemailtitle', 'parseinline' );
1134 }
1135 return true;
1136 }
1137
1138 static function getFormObject( $user ) {
1139 $formDescriptor = Preferences::getPreferences( $user );
1140 $htmlForm = new PreferencesForm( $formDescriptor, 'prefs' );
1141
1142 $htmlForm->setSubmitText( wfMsg( 'saveprefs' ) );
1143 $htmlForm->setTitle( SpecialPage::getTitleFor( 'Preferences' ) );
1144 $htmlForm->setSubmitID( 'prefsubmit' );
1145 $htmlForm->setSubmitCallback( array( 'Preferences', 'tryFormSubmit' ) );
1146
1147 return $htmlForm;
1148 }
1149
1150 static function getTimezoneOptions() {
1151 $opt = array();
1152
1153 global $wgLocalTZoffset;
1154
1155 $opt[wfMsg( 'timezoneuseserverdefault' )] = "System|$wgLocalTZoffset";
1156 $opt[wfMsg( 'timezoneuseoffset' )] = 'other';
1157 $opt[wfMsg( 'guesstimezone' )] = 'guess';
1158
1159 if ( function_exists( 'timezone_identifiers_list' ) ) {
1160 # Read timezone list
1161 $tzs = timezone_identifiers_list();
1162 sort( $tzs );
1163
1164 $tzRegions = array();
1165 $tzRegions['Africa'] = wfMsg( 'timezoneregion-africa' );
1166 $tzRegions['America'] = wfMsg( 'timezoneregion-america' );
1167 $tzRegions['Antarctica'] = wfMsg( 'timezoneregion-antarctica' );
1168 $tzRegions['Arctic'] = wfMsg( 'timezoneregion-arctic' );
1169 $tzRegions['Asia'] = wfMsg( 'timezoneregion-asia' );
1170 $tzRegions['Atlantic'] = wfMsg( 'timezoneregion-atlantic' );
1171 $tzRegions['Australia'] = wfMsg( 'timezoneregion-australia' );
1172 $tzRegions['Europe'] = wfMsg( 'timezoneregion-europe' );
1173 $tzRegions['Indian'] = wfMsg( 'timezoneregion-indian' );
1174 $tzRegions['Pacific'] = wfMsg( 'timezoneregion-pacific' );
1175 asort( $tzRegions );
1176
1177 $prefill = array_fill_keys( array_values( $tzRegions ), array() );
1178 $opt = array_merge( $opt, $prefill );
1179
1180 $now = date_create( 'now' );
1181
1182 foreach ( $tzs as $tz ) {
1183 $z = explode( '/', $tz, 2 );
1184
1185 # timezone_identifiers_list() returns a number of
1186 # backwards-compatibility entries. This filters them out of the
1187 # list presented to the user.
1188 if ( count( $z ) != 2 || !array_key_exists( $z[0], $tzRegions ) ) {
1189 continue;
1190 }
1191
1192 # Localize region
1193 $z[0] = $tzRegions[$z[0]];
1194
1195 $minDiff = floor( timezone_offset_get( timezone_open( $tz ), $now ) / 60 );
1196
1197 $display = str_replace( '_', ' ', $z[0] . '/' . $z[1] );
1198 $value = "ZoneInfo|$minDiff|$tz";
1199
1200 $opt[$z[0]][$display] = $value;
1201 }
1202 }
1203 return $opt;
1204 }
1205
1206 static function filterTimezoneInput( $tz, $alldata ) {
1207 $data = explode( '|', $tz, 3 );
1208 switch ( $data[0] ) {
1209 case 'ZoneInfo':
1210 case 'System':
1211 return $tz;
1212 default:
1213 $data = explode( ':', $tz, 2 );
1214 $minDiff = 0;
1215 if ( count( $data ) == 2 ) {
1216 $data[0] = intval( $data[0] );
1217 $data[1] = intval( $data[1] );
1218 $minDiff = abs( $data[0] ) * 60 + $data[1];
1219 if ( $data[0] < 0 ) $minDiff = - $minDiff;
1220 } else {
1221 $minDiff = intval( $data[0] ) * 60;
1222 }
1223
1224 # Max is +14:00 and min is -12:00, see:
1225 # http://en.wikipedia.org/wiki/Timezone
1226 $minDiff = min( $minDiff, 840 ); # 14:00
1227 $minDiff = max( $minDiff, - 720 ); # -12:00
1228 return 'Offset|' . $minDiff;
1229 }
1230 }
1231
1232 static function tryFormSubmit( $formData, $entryPoint = 'internal' ) {
1233 global $wgUser, $wgEmailAuthentication, $wgEnableEmail;
1234
1235 $result = true;
1236
1237 // Filter input
1238 foreach ( array_keys( $formData ) as $name ) {
1239 if ( isset( self::$saveFilters[$name] ) ) {
1240 $formData[$name] =
1241 call_user_func( self::$saveFilters[$name], $formData[$name], $formData );
1242 }
1243 }
1244
1245 // Stuff that shouldn't be saved as a preference.
1246 $saveBlacklist = array(
1247 'realname',
1248 'emailaddress',
1249 );
1250
1251 if ( $wgEnableEmail ) {
1252 $newaddr = $formData['emailaddress'];
1253 $oldaddr = $wgUser->getEmail();
1254 if ( ( $newaddr != '' ) && ( $newaddr != $oldaddr ) ) {
1255 # the user has supplied a new email address on the login page
1256 # new behaviour: set this new emailaddr from login-page into user database record
1257 $wgUser->setEmail( $newaddr );
1258 # but flag as "dirty" = unauthenticated
1259 $wgUser->invalidateEmail();
1260 if ( $wgEmailAuthentication ) {
1261 # Mail a temporary password to the dirty address.
1262 # User can come back through the confirmation URL to re-enable email.
1263 $result = $wgUser->sendConfirmationMail( $oldaddr != '' );
1264 if ( WikiError::isError( $result ) ) {
1265 return wfMsg( 'mailerror', htmlspecialchars( $result->getMessage() ) );
1266 } elseif ( $entryPoint == 'ui' ) {
1267 $result = 'eauth';
1268 }
1269 }
1270 } else {
1271 $wgUser->setEmail( $newaddr );
1272 }
1273 if ( $oldaddr != $newaddr ) {
1274 wfRunHooks( 'PrefsEmailAudit', array( $wgUser, $oldaddr, $newaddr ) );
1275 }
1276 }
1277
1278 // Fortunately, the realname field is MUCH simpler
1279 global $wgHiddenPrefs;
1280 if ( !in_array( 'realname', $wgHiddenPrefs ) ) {
1281 $realName = $formData['realname'];
1282 $wgUser->setRealName( $realName );
1283 }
1284
1285 foreach ( $saveBlacklist as $b ) {
1286 unset( $formData[$b] );
1287 }
1288
1289 // Keeps old preferences from interfering due to back-compat
1290 // code, etc.
1291 $wgUser->resetOptions();
1292
1293 foreach ( $formData as $key => $value ) {
1294 $wgUser->setOption( $key, $value );
1295 }
1296
1297 $wgUser->saveSettings();
1298
1299 return $result;
1300 }
1301
1302 public static function tryUISubmit( $formData ) {
1303 $res = self::tryFormSubmit( $formData, 'ui' );
1304
1305 if ( $res ) {
1306 $urlOptions = array( 'success' );
1307
1308 if ( $res === 'eauth' ) {
1309 $urlOptions[] = 'eauth';
1310 }
1311
1312 $queryString = implode( '&', $urlOptions );
1313
1314 $url = SpecialPage::getTitleFor( 'Preferences' )->getFullURL( $queryString );
1315
1316 global $wgOut;
1317 $wgOut->redirect( $url );
1318 }
1319
1320 return true;
1321 }
1322
1323 public static function loadOldSearchNs( $user ) {
1324 $searchableNamespaces = SearchEngine::searchableNamespaces();
1325 // Back compat with old format
1326 $arr = array();
1327
1328 foreach ( $searchableNamespaces as $ns => $name ) {
1329 if ( $user->getOption( 'searchNs' . $ns ) ) {
1330 $arr[] = $ns;
1331 }
1332 }
1333
1334 return $arr;
1335 }
1336 }
1337
1338 /** Some tweaks to allow js prefs to work */
1339 class PreferencesForm extends HTMLForm {
1340 function wrapForm( $html ) {
1341 $html = Xml::tags( 'div', array( 'id' => 'preferences' ), $html );
1342
1343 return parent::wrapForm( $html );
1344 }
1345
1346 function getButtons() {
1347 $html = parent::getButtons();
1348
1349 global $wgUser;
1350
1351 $sk = $wgUser->getSkin();
1352 $t = SpecialPage::getTitleFor( 'Preferences', 'reset' );
1353
1354 $html .= "\n" . $sk->link( $t, wfMsgHtml( 'restoreprefs' ) );
1355
1356 $html = Xml::tags( 'div', array( 'class' => 'mw-prefs-buttons' ), $html );
1357
1358 return $html;
1359 }
1360
1361 function filterDataForSubmit( $data ) {
1362 // Support for separating MultiSelect preferences into multiple preferences
1363 // Due to lack of array support.
1364 foreach ( $this->mFlatFields as $fieldname => $field ) {
1365 $info = $field->mParams;
1366 if ( $field instanceof HTMLMultiSelectField ) {
1367 $options = HTMLFormField::flattenOptions( $info['options'] );
1368 $prefix = isset( $info['prefix'] ) ? $info['prefix'] : $fieldname;
1369
1370 foreach ( $options as $opt ) {
1371 $data["$prefix$opt"] = in_array( $opt, $data[$fieldname] );
1372 }
1373
1374 unset( $data[$fieldname] );
1375 }
1376 }
1377
1378 return $data;
1379 }
1380 }