MediaWiki  1.23.3
Preferences.php
Go to the documentation of this file.
1 <?php
48 class Preferences {
49  static $defaultPreferences = null;
50  static $saveFilters = array(
51  'timecorrection' => array( 'Preferences', 'filterTimezoneInput' ),
52  'cols' => array( 'Preferences', 'filterIntval' ),
53  'rows' => array( 'Preferences', 'filterIntval' ),
54  'rclimit' => array( 'Preferences', 'filterIntval' ),
55  'wllimit' => array( 'Preferences', 'filterIntval' ),
56  'searchlimit' => array( 'Preferences', 'filterIntval' ),
57  );
58 
59  // Stuff that shouldn't be saved as a preference.
60  private static $saveBlacklist = array(
61  'realname',
62  'emailaddress',
63  );
64 
68  static function getSaveBlacklist() {
69  return self::$saveBlacklist;
70  }
71 
78  static function getPreferences( $user, IContextSource $context ) {
79  if ( self::$defaultPreferences ) {
81  }
82 
84 
95 
96  wfRunHooks( 'GetPreferences', array( $user, &$defaultPreferences ) );
97 
98  ## Remove preferences that wikis don't want to use
99  global $wgHiddenPrefs;
100  foreach ( $wgHiddenPrefs as $pref ) {
101  if ( isset( $defaultPreferences[$pref] ) ) {
102  unset( $defaultPreferences[$pref] );
103  }
104  }
105 
106  ## Make sure that form fields have their parent set. See bug 41337.
107  $dummyForm = new HTMLForm( array(), $context );
108 
109  $disable = !$user->isAllowed( 'editmyoptions' );
110 
111  ## Prod in defaults from the user
112  foreach ( $defaultPreferences as $name => &$info ) {
113  $prefFromUser = self::getOptionFromUser( $name, $info, $user );
114  if ( $disable && !in_array( $name, self::$saveBlacklist ) ) {
115  $info['disabled'] = 'disabled';
116  }
117  $field = HTMLForm::loadInputFromParameters( $name, $info ); // For validation
118  $field->mParent = $dummyForm;
120  $globalDefault = isset( $defaultOptions[$name] )
122  : null;
123 
124  // If it validates, set it as the default
125  if ( isset( $info['default'] ) ) {
126  // Already set, no problem
127  continue;
128  } elseif ( !is_null( $prefFromUser ) && // Make sure we're not just pulling nothing
129  $field->validate( $prefFromUser, $user->getOptions() ) === true ) {
130  $info['default'] = $prefFromUser;
131  } elseif ( $field->validate( $globalDefault, $user->getOptions() ) === true ) {
132  $info['default'] = $globalDefault;
133  } else {
134  throw new MWException( "Global default '$globalDefault' is invalid for field $name" );
135  }
136  }
137 
138  self::$defaultPreferences = $defaultPreferences;
139 
140  return $defaultPreferences;
141  }
142 
151  static function getOptionFromUser( $name, $info, $user ) {
152  $val = $user->getOption( $name );
153 
154  // Handling for multiselect preferences
155  if ( ( isset( $info['type'] ) && $info['type'] == 'multiselect' ) ||
156  ( isset( $info['class'] ) && $info['class'] == 'HTMLMultiSelectField' ) ) {
157  $options = HTMLFormField::flattenOptions( $info['options'] );
158  $prefix = isset( $info['prefix'] ) ? $info['prefix'] : $name;
159  $val = array();
160 
161  foreach ( $options as $value ) {
162  if ( $user->getOption( "$prefix$value" ) ) {
163  $val[] = $value;
164  }
165  }
166  }
167 
168  // Handling for checkmatrix preferences
169  if ( ( isset( $info['type'] ) && $info['type'] == 'checkmatrix' ) ||
170  ( isset( $info['class'] ) && $info['class'] == 'HTMLCheckMatrix' ) ) {
171  $columns = HTMLFormField::flattenOptions( $info['columns'] );
172  $rows = HTMLFormField::flattenOptions( $info['rows'] );
173  $prefix = isset( $info['prefix'] ) ? $info['prefix'] : $name;
174  $val = array();
175 
176  foreach ( $columns as $column ) {
177  foreach ( $rows as $row ) {
178  if ( $user->getOption( "$prefix$column-$row" ) ) {
179  $val[] = "$column-$row";
180  }
181  }
182  }
183  }
184 
185  return $val;
186  }
187 
195  global $wgAuth, $wgContLang, $wgParser, $wgCookieExpiration, $wgLanguageCode,
196  $wgDisableLangConversion, $wgMaxSigChars,
197  $wgEnableEmail, $wgEmailConfirmToEdit, $wgEnableUserEmail, $wgEmailAuthentication,
198  $wgEnotifWatchlist, $wgEnotifUserTalk, $wgEnotifRevealEditorAddress,
199  $wgSecureLogin;
200 
201  // retrieving user name for GENDER and misc.
202  $userName = $user->getName();
203 
204  ## User info #####################################
205  // Information panel
206  $defaultPreferences['username'] = array(
207  'type' => 'info',
208  'label-message' => array( 'username', $userName ),
209  'default' => $userName,
210  'section' => 'personal/info',
211  );
212 
213  $defaultPreferences['userid'] = array(
214  'type' => 'info',
215  'label-message' => array( 'uid', $userName ),
216  'default' => $user->getId(),
217  'section' => 'personal/info',
218  );
219 
220  # Get groups to which the user belongs
221  $userEffectiveGroups = $user->getEffectiveGroups();
222  $userGroups = $userMembers = array();
223  foreach ( $userEffectiveGroups as $ueg ) {
224  if ( $ueg == '*' ) {
225  // Skip the default * group, seems useless here
226  continue;
227  }
228  $groupName = User::getGroupName( $ueg );
229  $userGroups[] = User::makeGroupLinkHTML( $ueg, $groupName );
230 
231  $memberName = User::getGroupMember( $ueg, $userName );
232  $userMembers[] = User::makeGroupLinkHTML( $ueg, $memberName );
233  }
234  asort( $userGroups );
235  asort( $userMembers );
236 
237  $lang = $context->getLanguage();
238 
239  $defaultPreferences['usergroups'] = array(
240  'type' => 'info',
241  'label' => $context->msg( 'prefs-memberingroups' )->numParams(
242  count( $userGroups ) )->params( $userName )->parse(),
243  'default' => $context->msg( 'prefs-memberingroups-type',
244  $lang->commaList( $userGroups ),
245  $lang->commaList( $userMembers )
246  )->plain(),
247  'raw' => true,
248  'section' => 'personal/info',
249  );
250 
251  $editCount = Linker::link( SpecialPage::getTitleFor( "Contributions", $userName ),
252  $lang->formatNum( $user->getEditCount() ) );
253 
254  $defaultPreferences['editcount'] = array(
255  'type' => 'info',
256  'raw' => true,
257  'label-message' => 'prefs-edits',
258  'default' => $editCount,
259  'section' => 'personal/info',
260  );
261 
262  if ( $user->getRegistration() ) {
263  $displayUser = $context->getUser();
264  $userRegistration = $user->getRegistration();
265  $defaultPreferences['registrationdate'] = array(
266  'type' => 'info',
267  'label-message' => 'prefs-registration',
268  'default' => $context->msg(
269  'prefs-registration-date-time',
270  $lang->userTimeAndDate( $userRegistration, $displayUser ),
271  $lang->userDate( $userRegistration, $displayUser ),
272  $lang->userTime( $userRegistration, $displayUser )
273  )->parse(),
274  'section' => 'personal/info',
275  );
276  }
277 
278  $canViewPrivateInfo = $user->isAllowed( 'viewmyprivateinfo' );
279  $canEditPrivateInfo = $user->isAllowed( 'editmyprivateinfo' );
280 
281  // Actually changeable stuff
282  $defaultPreferences['realname'] = array(
283  // (not really "private", but still shouldn't be edited without permission)
284  'type' => $canEditPrivateInfo && $wgAuth->allowPropChange( 'realname' ) ? 'text' : 'info',
285  'default' => $user->getRealName(),
286  'section' => 'personal/info',
287  'label-message' => 'yourrealname',
288  'help-message' => 'prefs-help-realname',
289  );
290 
291  if ( $canEditPrivateInfo && $wgAuth->allowPasswordChange() ) {
292  $link = Linker::link( SpecialPage::getTitleFor( 'ChangePassword' ),
293  $context->msg( 'prefs-resetpass' )->escaped(), array(),
294  array( 'returnto' => SpecialPage::getTitleFor( 'Preferences' )->getPrefixedText() ) );
295 
296  $defaultPreferences['password'] = array(
297  'type' => 'info',
298  'raw' => true,
299  'default' => $link,
300  'label-message' => 'yourpassword',
301  'section' => 'personal/info',
302  );
303  }
304  // Only show prefershttps if secure login is turned on
305  if ( $wgSecureLogin && wfCanIPUseHTTPS( $context->getRequest()->getIP() ) ) {
306  $defaultPreferences['prefershttps'] = array(
307  'type' => 'toggle',
308  'label-message' => 'tog-prefershttps',
309  'help-message' => 'prefs-help-prefershttps',
310  'section' => 'personal/info'
311  );
312  }
313 
314  // Language
316  if ( !array_key_exists( $wgLanguageCode, $languages ) ) {
317  $languages[$wgLanguageCode] = $wgLanguageCode;
318  }
319  ksort( $languages );
320 
321  $options = array();
322  foreach ( $languages as $code => $name ) {
323  $display = wfBCP47( $code ) . ' - ' . $name;
324  $options[$display] = $code;
325  }
326  $defaultPreferences['language'] = array(
327  'type' => 'select',
328  'section' => 'personal/i18n',
329  'options' => $options,
330  'label-message' => 'yourlanguage',
331  );
332 
333  $defaultPreferences['gender'] = array(
334  'type' => 'radio',
335  'section' => 'personal/i18n',
336  'options' => array(
337  $context->msg( 'parentheses',
338  $context->msg( 'gender-unknown' )->text()
339  )->text() => 'unknown',
340  $context->msg( 'gender-female' )->text() => 'female',
341  $context->msg( 'gender-male' )->text() => 'male',
342  ),
343  'label-message' => 'yourgender',
344  'help-message' => 'prefs-help-gender',
345  );
346 
347  // see if there are multiple language variants to choose from
348  if ( !$wgDisableLangConversion ) {
349  foreach ( LanguageConverter::$languagesWithVariants as $langCode ) {
350  if ( $langCode == $wgContLang->getCode() ) {
351  $variants = $wgContLang->getVariants();
352 
353  if ( count( $variants ) <= 1 ) {
354  continue;
355  }
356 
357  $variantArray = array();
358  foreach ( $variants as $v ) {
359  $v = str_replace( '_', '-', strtolower( $v ) );
360  $variantArray[$v] = $lang->getVariantname( $v, false );
361  }
362 
363  $options = array();
364  foreach ( $variantArray as $code => $name ) {
365  $display = wfBCP47( $code ) . ' - ' . $name;
366  $options[$display] = $code;
367  }
368 
369  $defaultPreferences['variant'] = array(
370  'label-message' => 'yourvariant',
371  'type' => 'select',
372  'options' => $options,
373  'section' => 'personal/i18n',
374  'help-message' => 'prefs-help-variant',
375  );
376  } else {
377  $defaultPreferences["variant-$langCode"] = array(
378  'type' => 'api',
379  );
380  }
381  }
382  }
383 
384  // Stuff from Language::getExtraUserToggles()
385  // FIXME is this dead code? $extraUserToggles doesn't seem to be defined for any language
386  $toggles = $wgContLang->getExtraUserToggles();
387 
388  foreach ( $toggles as $toggle ) {
389  $defaultPreferences[$toggle] = array(
390  'type' => 'toggle',
391  'section' => 'personal/i18n',
392  'label-message' => "tog-$toggle",
393  );
394  }
395 
396  // show a preview of the old signature first
397  $oldsigWikiText = $wgParser->preSaveTransform(
398  '~~~',
399  $context->getTitle(),
400  $user,
402  );
403  $oldsigHTML = $context->getOutput()->parseInline( $oldsigWikiText, true, true );
404  $defaultPreferences['oldsig'] = array(
405  'type' => 'info',
406  'raw' => true,
407  'label-message' => 'tog-oldsig',
408  'default' => $oldsigHTML,
409  'section' => 'personal/signature',
410  );
411  $defaultPreferences['nickname'] = array(
412  'type' => $wgAuth->allowPropChange( 'nickname' ) ? 'text' : 'info',
413  'maxlength' => $wgMaxSigChars,
414  'label-message' => 'yournick',
415  'validation-callback' => array( 'Preferences', 'validateSignature' ),
416  'section' => 'personal/signature',
417  'filter-callback' => array( 'Preferences', 'cleanSignature' ),
418  );
419  $defaultPreferences['fancysig'] = array(
420  'type' => 'toggle',
421  'label-message' => 'tog-fancysig',
422  // show general help about signature at the bottom of the section
423  'help-message' => 'prefs-help-signature',
424  'section' => 'personal/signature'
425  );
426 
427  ## Email stuff
428 
429  if ( $wgEnableEmail ) {
430  if ( $canViewPrivateInfo ) {
431  $helpMessages[] = $wgEmailConfirmToEdit
432  ? 'prefs-help-email-required'
433  : 'prefs-help-email';
434 
435  if ( $wgEnableUserEmail ) {
436  // additional messages when users can send email to each other
437  $helpMessages[] = 'prefs-help-email-others';
438  }
439 
440  $emailAddress = $user->getEmail() ? htmlspecialchars( $user->getEmail() ) : '';
441  if ( $canEditPrivateInfo && $wgAuth->allowPropChange( 'emailaddress' ) ) {
443  SpecialPage::getTitleFor( 'ChangeEmail' ),
444  $context->msg( $user->getEmail() ? 'prefs-changeemail' : 'prefs-setemail' )->escaped(),
445  array(),
446  array( 'returnto' => SpecialPage::getTitleFor( 'Preferences' )->getPrefixedText() ) );
447 
448  $emailAddress .= $emailAddress == '' ? $link : (
449  $context->msg( 'word-separator' )->plain()
450  . $context->msg( 'parentheses' )->rawParams( $link )->plain()
451  );
452  }
453 
454  $defaultPreferences['emailaddress'] = array(
455  'type' => 'info',
456  'raw' => true,
457  'default' => $emailAddress,
458  'label-message' => 'youremail',
459  'section' => 'personal/email',
460  'help-messages' => $helpMessages,
461  # 'cssclass' chosen below
462  );
463  }
464 
465  $disableEmailPrefs = false;
466 
467  if ( $wgEmailAuthentication ) {
468  $emailauthenticationclass = 'mw-email-not-authenticated';
469  if ( $user->getEmail() ) {
470  if ( $user->getEmailAuthenticationTimestamp() ) {
471  // date and time are separate parameters to facilitate localisation.
472  // $time is kept for backward compat reasons.
473  // 'emailauthenticated' is also used in SpecialConfirmemail.php
474  $displayUser = $context->getUser();
475  $emailTimestamp = $user->getEmailAuthenticationTimestamp();
476  $time = $lang->userTimeAndDate( $emailTimestamp, $displayUser );
477  $d = $lang->userDate( $emailTimestamp, $displayUser );
478  $t = $lang->userTime( $emailTimestamp, $displayUser );
479  $emailauthenticated = $context->msg( 'emailauthenticated',
480  $time, $d, $t )->parse() . '<br />';
481  $disableEmailPrefs = false;
482  $emailauthenticationclass = 'mw-email-authenticated';
483  } else {
484  $disableEmailPrefs = true;
485  $emailauthenticated = $context->msg( 'emailnotauthenticated' )->parse() . '<br />' .
487  SpecialPage::getTitleFor( 'Confirmemail' ),
488  $context->msg( 'emailconfirmlink' )->escaped()
489  ) . '<br />';
490  $emailauthenticationclass = "mw-email-not-authenticated";
491  }
492  } else {
493  $disableEmailPrefs = true;
494  $emailauthenticated = $context->msg( 'noemailprefs' )->escaped();
495  $emailauthenticationclass = 'mw-email-none';
496  }
497 
498  if ( $canViewPrivateInfo ) {
499  $defaultPreferences['emailauthentication'] = array(
500  'type' => 'info',
501  'raw' => true,
502  'section' => 'personal/email',
503  'label-message' => 'prefs-emailconfirm-label',
504  'default' => $emailauthenticated,
505  # Apply the same CSS class used on the input to the message:
506  'cssclass' => $emailauthenticationclass,
507  );
508  $defaultPreferences['emailaddress']['cssclass'] = $emailauthenticationclass;
509  }
510  }
511 
512  if ( $wgEnableUserEmail && $user->isAllowed( 'sendemail' ) ) {
513  $defaultPreferences['disablemail'] = array(
514  'type' => 'toggle',
515  'invert' => true,
516  'section' => 'personal/email',
517  'label-message' => 'allowemail',
518  'disabled' => $disableEmailPrefs,
519  );
520  $defaultPreferences['ccmeonemails'] = array(
521  'type' => 'toggle',
522  'section' => 'personal/email',
523  'label-message' => 'tog-ccmeonemails',
524  'disabled' => $disableEmailPrefs,
525  );
526  }
527 
528  if ( $wgEnotifWatchlist ) {
529  $defaultPreferences['enotifwatchlistpages'] = array(
530  'type' => 'toggle',
531  'section' => 'personal/email',
532  'label-message' => 'tog-enotifwatchlistpages',
533  'disabled' => $disableEmailPrefs,
534  );
535  }
536  if ( $wgEnotifUserTalk ) {
537  $defaultPreferences['enotifusertalkpages'] = array(
538  'type' => 'toggle',
539  'section' => 'personal/email',
540  'label-message' => 'tog-enotifusertalkpages',
541  'disabled' => $disableEmailPrefs,
542  );
543  }
544  if ( $wgEnotifUserTalk || $wgEnotifWatchlist ) {
545  $defaultPreferences['enotifminoredits'] = array(
546  'type' => 'toggle',
547  'section' => 'personal/email',
548  'label-message' => 'tog-enotifminoredits',
549  'disabled' => $disableEmailPrefs,
550  );
551 
552  if ( $wgEnotifRevealEditorAddress ) {
553  $defaultPreferences['enotifrevealaddr'] = array(
554  'type' => 'toggle',
555  'section' => 'personal/email',
556  'label-message' => 'tog-enotifrevealaddr',
557  'disabled' => $disableEmailPrefs,
558  );
559  }
560  }
561  }
562  }
563 
570  static function skinPreferences( $user, IContextSource $context, &$defaultPreferences ) {
571  ## Skin #####################################
572  global $wgAllowUserCss, $wgAllowUserJs;
573 
574  $defaultPreferences['skin'] = array(
575  'type' => 'radio',
576  'options' => self::generateSkinOptions( $user, $context ),
577  'label' => '&#160;',
578  'section' => 'rendering/skin',
579  );
580 
581  # Create links to user CSS/JS pages for all skins
582  # This code is basically copied from generateSkinOptions(). It'd
583  # be nice to somehow merge this back in there to avoid redundancy.
584  if ( $wgAllowUserCss || $wgAllowUserJs ) {
585  $linkTools = array();
586  $userName = $user->getName();
587 
588  if ( $wgAllowUserCss ) {
589  $cssPage = Title::makeTitleSafe( NS_USER, $userName . '/common.css' );
590  $linkTools[] = Linker::link( $cssPage, $context->msg( 'prefs-custom-css' )->escaped() );
591  }
592 
593  if ( $wgAllowUserJs ) {
594  $jsPage = Title::makeTitleSafe( NS_USER, $userName . '/common.js' );
595  $linkTools[] = Linker::link( $jsPage, $context->msg( 'prefs-custom-js' )->escaped() );
596  }
597 
598  $defaultPreferences['commoncssjs'] = array(
599  'type' => 'info',
600  'raw' => true,
601  'default' => $context->getLanguage()->pipeList( $linkTools ),
602  'label-message' => 'prefs-common-css-js',
603  'section' => 'rendering/skin',
604  );
605  }
606  }
607 
613  static function filesPreferences( $user, IContextSource $context, &$defaultPreferences ) {
614  ## Files #####################################
615  $defaultPreferences['imagesize'] = array(
616  'type' => 'select',
617  'options' => self::getImageSizes( $context ),
618  'label-message' => 'imagemaxsize',
619  'section' => 'rendering/files',
620  );
621  $defaultPreferences['thumbsize'] = array(
622  'type' => 'select',
623  'options' => self::getThumbSizes( $context ),
624  'label-message' => 'thumbsize',
625  'section' => 'rendering/files',
626  );
627  }
628 
636  ## Date and time #####################################
637  $dateOptions = self::getDateOptions( $context );
638  if ( $dateOptions ) {
639  $defaultPreferences['date'] = array(
640  'type' => 'radio',
641  'options' => $dateOptions,
642  'label' => '&#160;',
643  'section' => 'rendering/dateformat',
644  );
645  }
646 
647  // Info
648  $now = wfTimestampNow();
649  $lang = $context->getLanguage();
650  $nowlocal = Xml::element( 'span', array( 'id' => 'wpLocalTime' ),
651  $lang->time( $now, true ) );
652  $nowserver = $lang->time( $now, false ) .
653  Html::hidden( 'wpServerTime', (int)substr( $now, 8, 2 ) * 60 + (int)substr( $now, 10, 2 ) );
654 
655  $defaultPreferences['nowserver'] = array(
656  'type' => 'info',
657  'raw' => 1,
658  'label-message' => 'servertime',
659  'default' => $nowserver,
660  'section' => 'rendering/timeoffset',
661  );
662 
663  $defaultPreferences['nowlocal'] = array(
664  'type' => 'info',
665  'raw' => 1,
666  'label-message' => 'localtime',
667  'default' => $nowlocal,
668  'section' => 'rendering/timeoffset',
669  );
670 
671  // Grab existing pref.
672  $tzOffset = $user->getOption( 'timecorrection' );
673  $tz = explode( '|', $tzOffset, 3 );
674 
675  $tzOptions = self::getTimezoneOptions( $context );
676 
677  $tzSetting = $tzOffset;
678  if ( count( $tz ) > 1 && $tz[0] == 'Offset' ) {
679  $minDiff = $tz[1];
680  $tzSetting = sprintf( '%+03d:%02d', floor( $minDiff / 60 ), abs( $minDiff ) % 60 );
681  } elseif ( count( $tz ) > 1 && $tz[0] == 'ZoneInfo' &&
682  !in_array( $tzOffset, HTMLFormField::flattenOptions( $tzOptions ) )
683  ) {
684  # Timezone offset can vary with DST
685  $userTZ = timezone_open( $tz[2] );
686  if ( $userTZ !== false ) {
687  $minDiff = floor( timezone_offset_get( $userTZ, date_create( 'now' ) ) / 60 );
688  $tzSetting = "ZoneInfo|$minDiff|{$tz[2]}";
689  }
690  }
691 
692  $defaultPreferences['timecorrection'] = array(
693  'class' => 'HTMLSelectOrOtherField',
694  'label-message' => 'timezonelegend',
695  'options' => $tzOptions,
696  'default' => $tzSetting,
697  'size' => 20,
698  'section' => 'rendering/timeoffset',
699  );
700  }
701 
708  ## Diffs ####################################
709  $defaultPreferences['diffonly'] = array(
710  'type' => 'toggle',
711  'section' => 'rendering/diffs',
712  'label-message' => 'tog-diffonly',
713  );
714  $defaultPreferences['norollbackdiff'] = array(
715  'type' => 'toggle',
716  'section' => 'rendering/diffs',
717  'label-message' => 'tog-norollbackdiff',
718  );
719 
720  ## Page Rendering ##############################
721  global $wgAllowUserCssPrefs;
722  if ( $wgAllowUserCssPrefs ) {
723  $defaultPreferences['underline'] = array(
724  'type' => 'select',
725  'options' => array(
726  $context->msg( 'underline-never' )->text() => 0,
727  $context->msg( 'underline-always' )->text() => 1,
728  $context->msg( 'underline-default' )->text() => 2,
729  ),
730  'label-message' => 'tog-underline',
731  'section' => 'rendering/advancedrendering',
732  );
733  }
734 
735  $stubThresholdValues = array( 50, 100, 500, 1000, 2000, 5000, 10000 );
736  $stubThresholdOptions = array( $context->msg( 'stub-threshold-disabled' )->text() => 0 );
737  foreach ( $stubThresholdValues as $value ) {
738  $stubThresholdOptions[$context->msg( 'size-bytes', $value )->text()] = $value;
739  }
740 
741  $defaultPreferences['stubthreshold'] = array(
742  'type' => 'select',
743  'section' => 'rendering/advancedrendering',
744  'options' => $stubThresholdOptions,
745  'label-raw' => $context->msg( 'stub-threshold' )->text(), // Raw HTML message. Yay?
746  );
747 
748  $defaultPreferences['showhiddencats'] = array(
749  'type' => 'toggle',
750  'section' => 'rendering/advancedrendering',
751  'label-message' => 'tog-showhiddencats'
752  );
753 
754  $defaultPreferences['numberheadings'] = array(
755  'type' => 'toggle',
756  'section' => 'rendering/advancedrendering',
757  'label-message' => 'tog-numberheadings',
758  );
759  }
760 
767  global $wgAllowUserCssPrefs;
768 
769  ## Editing #####################################
770  $defaultPreferences['editsectiononrightclick'] = array(
771  'type' => 'toggle',
772  'section' => 'editing/advancedediting',
773  'label-message' => 'tog-editsectiononrightclick',
774  );
775  $defaultPreferences['editondblclick'] = array(
776  'type' => 'toggle',
777  'section' => 'editing/advancedediting',
778  'label-message' => 'tog-editondblclick',
779  );
780 
781  if ( $wgAllowUserCssPrefs ) {
782  $defaultPreferences['editfont'] = array(
783  'type' => 'select',
784  'section' => 'editing/editor',
785  'label-message' => 'editfont-style',
786  'options' => array(
787  $context->msg( 'editfont-default' )->text() => 'default',
788  $context->msg( 'editfont-monospace' )->text() => 'monospace',
789  $context->msg( 'editfont-sansserif' )->text() => 'sans-serif',
790  $context->msg( 'editfont-serif' )->text() => 'serif',
791  )
792  );
793  }
794  $defaultPreferences['cols'] = array(
795  'type' => 'int',
796  'label-message' => 'columns',
797  'section' => 'editing/editor',
798  'min' => 4,
799  'max' => 1000,
800  );
801  $defaultPreferences['rows'] = array(
802  'type' => 'int',
803  'label-message' => 'rows',
804  'section' => 'editing/editor',
805  'min' => 4,
806  'max' => 1000,
807  );
808  if ( $user->isAllowed( 'minoredit' ) ) {
809  $defaultPreferences['minordefault'] = array(
810  'type' => 'toggle',
811  'section' => 'editing/editor',
812  'label-message' => 'tog-minordefault',
813  );
814  }
815  $defaultPreferences['forceeditsummary'] = array(
816  'type' => 'toggle',
817  'section' => 'editing/editor',
818  'label-message' => 'tog-forceeditsummary',
819  );
820  $defaultPreferences['useeditwarning'] = array(
821  'type' => 'toggle',
822  'section' => 'editing/editor',
823  'label-message' => 'tog-useeditwarning',
824  );
825  $defaultPreferences['showtoolbar'] = array(
826  'type' => 'toggle',
827  'section' => 'editing/editor',
828  'label-message' => 'tog-showtoolbar',
829  );
830 
831  $defaultPreferences['previewonfirst'] = array(
832  'type' => 'toggle',
833  'section' => 'editing/preview',
834  'label-message' => 'tog-previewonfirst',
835  );
836  $defaultPreferences['previewontop'] = array(
837  'type' => 'toggle',
838  'section' => 'editing/preview',
839  'label-message' => 'tog-previewontop',
840  );
841  $defaultPreferences['uselivepreview'] = array(
842  'type' => 'toggle',
843  'section' => 'editing/preview',
844  'label-message' => 'tog-uselivepreview',
845  );
846 
847  }
848 
854  static function rcPreferences( $user, IContextSource $context, &$defaultPreferences ) {
855  global $wgRCMaxAge, $wgRCShowWatchingUsers;
856 
857  ## RecentChanges #####################################
858  $defaultPreferences['rcdays'] = array(
859  'type' => 'float',
860  'label-message' => 'recentchangesdays',
861  'section' => 'rc/displayrc',
862  'min' => 1,
863  'max' => ceil( $wgRCMaxAge / ( 3600 * 24 ) ),
864  'help' => $context->msg( 'recentchangesdays-max' )->numParams(
865  ceil( $wgRCMaxAge / ( 3600 * 24 ) ) )->text()
866  );
867  $defaultPreferences['rclimit'] = array(
868  'type' => 'int',
869  'label-message' => 'recentchangescount',
870  'help-message' => 'prefs-help-recentchangescount',
871  'section' => 'rc/displayrc',
872  );
873  $defaultPreferences['usenewrc'] = array(
874  'type' => 'toggle',
875  'label-message' => 'tog-usenewrc',
876  'section' => 'rc/advancedrc',
877  );
878  $defaultPreferences['hideminor'] = array(
879  'type' => 'toggle',
880  'label-message' => 'tog-hideminor',
881  'section' => 'rc/advancedrc',
882  );
883 
884  if ( $user->useRCPatrol() ) {
885  $defaultPreferences['hidepatrolled'] = array(
886  'type' => 'toggle',
887  'section' => 'rc/advancedrc',
888  'label-message' => 'tog-hidepatrolled',
889  );
890  $defaultPreferences['newpageshidepatrolled'] = array(
891  'type' => 'toggle',
892  'section' => 'rc/advancedrc',
893  'label-message' => 'tog-newpageshidepatrolled',
894  );
895  }
896 
897  if ( $wgRCShowWatchingUsers ) {
898  $defaultPreferences['shownumberswatching'] = array(
899  'type' => 'toggle',
900  'section' => 'rc/advancedrc',
901  'label-message' => 'tog-shownumberswatching',
902  );
903  }
904  }
905 
912  global $wgUseRCPatrol, $wgEnableAPI, $wgRCMaxAge;
913 
914  $watchlistdaysMax = ceil( $wgRCMaxAge / ( 3600 * 24 ) );
915 
916  ## Watchlist #####################################
917  $defaultPreferences['watchlistdays'] = array(
918  'type' => 'float',
919  'min' => 0,
920  'max' => $watchlistdaysMax,
921  'section' => 'watchlist/displaywatchlist',
922  'help' => $context->msg( 'prefs-watchlist-days-max' )->numParams(
923  $watchlistdaysMax )->text(),
924  'label-message' => 'prefs-watchlist-days',
925  );
926  $defaultPreferences['wllimit'] = array(
927  'type' => 'int',
928  'min' => 0,
929  'max' => 1000,
930  'label-message' => 'prefs-watchlist-edits',
931  'help' => $context->msg( 'prefs-watchlist-edits-max' )->escaped(),
932  'section' => 'watchlist/displaywatchlist',
933  );
934  $defaultPreferences['extendwatchlist'] = array(
935  'type' => 'toggle',
936  'section' => 'watchlist/advancedwatchlist',
937  'label-message' => 'tog-extendwatchlist',
938  );
939  $defaultPreferences['watchlisthideminor'] = array(
940  'type' => 'toggle',
941  'section' => 'watchlist/advancedwatchlist',
942  'label-message' => 'tog-watchlisthideminor',
943  );
944  $defaultPreferences['watchlisthidebots'] = array(
945  'type' => 'toggle',
946  'section' => 'watchlist/advancedwatchlist',
947  'label-message' => 'tog-watchlisthidebots',
948  );
949  $defaultPreferences['watchlisthideown'] = array(
950  'type' => 'toggle',
951  'section' => 'watchlist/advancedwatchlist',
952  'label-message' => 'tog-watchlisthideown',
953  );
954  $defaultPreferences['watchlisthideanons'] = array(
955  'type' => 'toggle',
956  'section' => 'watchlist/advancedwatchlist',
957  'label-message' => 'tog-watchlisthideanons',
958  );
959  $defaultPreferences['watchlisthideliu'] = array(
960  'type' => 'toggle',
961  'section' => 'watchlist/advancedwatchlist',
962  'label-message' => 'tog-watchlisthideliu',
963  );
964 
965  if ( $wgUseRCPatrol ) {
966  $defaultPreferences['watchlisthidepatrolled'] = array(
967  'type' => 'toggle',
968  'section' => 'watchlist/advancedwatchlist',
969  'label-message' => 'tog-watchlisthidepatrolled',
970  );
971  }
972 
973  $watchTypes = array(
974  'edit' => 'watchdefault',
975  'move' => 'watchmoves',
976  'delete' => 'watchdeletion'
977  );
978 
979  // Kinda hacky
980  if ( $user->isAllowed( 'createpage' ) || $user->isAllowed( 'createtalk' ) ) {
981  $watchTypes['read'] = 'watchcreations';
982  }
983 
984  foreach ( $watchTypes as $action => $pref ) {
985  if ( $user->isAllowed( $action ) ) {
986  // Messages:
987  // tog-watchdefault, tog-watchmoves, tog-watchdeletion, tog-watchcreations
988  $defaultPreferences[$pref] = array(
989  'type' => 'toggle',
990  'section' => 'watchlist/advancedwatchlist',
991  'label-message' => "tog-$pref",
992  );
993  }
994  }
995 
996  if ( $wgEnableAPI ) {
997  $defaultPreferences['watchlisttoken'] = array(
998  'type' => 'api',
999  );
1000  $defaultPreferences['watchlisttoken-info'] = array(
1001  'type' => 'info',
1002  'section' => 'watchlist/tokenwatchlist',
1003  'label-message' => 'prefs-watchlist-token',
1004  'default' => $user->getTokenFromOption( 'watchlisttoken' ),
1005  'help-message' => 'prefs-help-watchlist-token2',
1006  );
1007  }
1008  }
1009 
1017 
1018  $defaultPreferences['searcheverything'] = array(
1019  'type' => 'toggle',
1020  'label-message' => 'searcheverything-enable',
1021  'section' => 'searchoptions/advancedsearchoptions',
1022  );
1023 
1024  $nsOptions = $wgContLang->getFormattedNamespaces();
1025  $nsOptions[0] = $context->msg( 'blanknamespace' )->text();
1026  foreach ( $nsOptions as $ns => $name ) {
1027  if ( $ns < 0 ) {
1028  unset( $nsOptions[$ns] );
1029  }
1030  }
1031 
1032  $defaultPreferences['searchnamespaces'] = array(
1033  'type' => 'multiselect',
1034  'label-message' => 'defaultns',
1035  'options' => array_flip( $nsOptions ),
1036  'section' => 'searchoptions/advancedsearchoptions',
1037  'prefix' => 'searchNs',
1038  );
1039  }
1040 
1044  static function miscPreferences( $user, IContextSource $context, &$defaultPreferences ) {
1045  }
1046 
1052  static function generateSkinOptions( $user, IContextSource $context ) {
1053  global $wgDefaultSkin, $wgAllowUserCss, $wgAllowUserJs;
1054  $ret = array();
1055 
1056  $mptitle = Title::newMainPage();
1057  $previewtext = $context->msg( 'skin-preview' )->text();
1058 
1059  # Only show skins that aren't disabled in $wgSkipSkins
1060  $validSkinNames = Skin::getAllowedSkins();
1061 
1062  # Sort by UI skin name. First though need to update validSkinNames as sometimes
1063  # the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI).
1064  foreach ( $validSkinNames as $skinkey => &$skinname ) {
1065  $msg = $context->msg( "skinname-{$skinkey}" );
1066  if ( $msg->exists() ) {
1067  $skinname = htmlspecialchars( $msg->text() );
1068  }
1069  }
1070  asort( $validSkinNames );
1071 
1072  foreach ( $validSkinNames as $skinkey => $sn ) {
1073  $linkTools = array();
1074 
1075  # Mark the default skin
1076  if ( $skinkey == $wgDefaultSkin ) {
1077  $linkTools[] = $context->msg( 'default' )->escaped();
1078  }
1079 
1080  # Create preview link
1081  $mplink = htmlspecialchars( $mptitle->getLocalURL( array( 'useskin' => $skinkey ) ) );
1082  $linkTools[] = "<a target='_blank' href=\"$mplink\">$previewtext</a>";
1083 
1084  # Create links to user CSS/JS pages
1085  if ( $wgAllowUserCss ) {
1086  $cssPage = Title::makeTitleSafe( NS_USER, $user->getName() . '/' . $skinkey . '.css' );
1087  $linkTools[] = Linker::link( $cssPage, $context->msg( 'prefs-custom-css' )->escaped() );
1088  }
1089 
1090  if ( $wgAllowUserJs ) {
1091  $jsPage = Title::makeTitleSafe( NS_USER, $user->getName() . '/' . $skinkey . '.js' );
1092  $linkTools[] = Linker::link( $jsPage, $context->msg( 'prefs-custom-js' )->escaped() );
1093  }
1094 
1095  $display = $sn . ' ' . $context->msg(
1096  'parentheses',
1097  $context->getLanguage()->pipeList( $linkTools )
1098  )->text();
1099  $ret[$display] = $skinkey;
1100  }
1101 
1102  return $ret;
1103  }
1104 
1109  static function getDateOptions( IContextSource $context ) {
1110  $lang = $context->getLanguage();
1111  $dateopts = $lang->getDatePreferences();
1112 
1113  $ret = array();
1114 
1115  if ( $dateopts ) {
1116  if ( !in_array( 'default', $dateopts ) ) {
1117  $dateopts[] = 'default'; // Make sure default is always valid
1118  // Bug 19237
1119  }
1120 
1121  // KLUGE: site default might not be valid for user language
1122  global $wgDefaultUserOptions;
1123  if ( !in_array( $wgDefaultUserOptions['date'], $dateopts ) ) {
1124  $wgDefaultUserOptions['date'] = 'default';
1125  }
1126 
1127  $epoch = wfTimestampNow();
1128  foreach ( $dateopts as $key ) {
1129  if ( $key == 'default' ) {
1130  $formatted = $context->msg( 'datedefault' )->escaped();
1131  } else {
1132  $formatted = htmlspecialchars( $lang->timeanddate( $epoch, false, $key ) );
1133  }
1134  $ret[$formatted] = $key;
1135  }
1136  }
1137  return $ret;
1138  }
1139 
1144  static function getImageSizes( IContextSource $context ) {
1145  global $wgImageLimits;
1146 
1147  $ret = array();
1148  $pixels = $context->msg( 'unit-pixel' )->text();
1149 
1150  foreach ( $wgImageLimits as $index => $limits ) {
1151  $display = "{$limits[0]}×{$limits[1]}" . $pixels;
1152  $ret[$display] = $index;
1153  }
1154 
1155  return $ret;
1156  }
1157 
1162  static function getThumbSizes( IContextSource $context ) {
1163  global $wgThumbLimits;
1164 
1165  $ret = array();
1166  $pixels = $context->msg( 'unit-pixel' )->text();
1167 
1168  foreach ( $wgThumbLimits as $index => $size ) {
1169  $display = $size . $pixels;
1170  $ret[$display] = $index;
1171  }
1172 
1173  return $ret;
1174  }
1175 
1182  static function validateSignature( $signature, $alldata, $form ) {
1183  global $wgParser, $wgMaxSigChars;
1184  if ( mb_strlen( $signature ) > $wgMaxSigChars ) {
1185  return Xml::element( 'span', array( 'class' => 'error' ),
1186  $form->msg( 'badsiglength' )->numParams( $wgMaxSigChars )->text() );
1187  } elseif ( isset( $alldata['fancysig'] ) &&
1188  $alldata['fancysig'] &&
1189  $wgParser->validateSig( $signature ) === false
1190  ) {
1191  return Xml::element(
1192  'span',
1193  array( 'class' => 'error' ),
1194  $form->msg( 'badsig' )->text()
1195  );
1196  } else {
1197  return true;
1198  }
1199  }
1200 
1207  static function cleanSignature( $signature, $alldata, $form ) {
1208  if ( isset( $alldata['fancysig'] ) && $alldata['fancysig'] ) {
1209  global $wgParser;
1210  $signature = $wgParser->cleanSig( $signature );
1211  } else {
1212  // When no fancy sig used, make sure ~{3,5} get removed.
1213  $signature = Parser::cleanSigInSig( $signature );
1214  }
1215 
1216  return $signature;
1217  }
1218 
1226  static function getFormObject(
1227  $user,
1228  IContextSource $context,
1229  $formClass = 'PreferencesForm',
1230  array $remove = array()
1231  ) {
1232  $formDescriptor = Preferences::getPreferences( $user, $context );
1233  if ( count( $remove ) ) {
1234  $removeKeys = array_flip( $remove );
1235  $formDescriptor = array_diff_key( $formDescriptor, $removeKeys );
1236  }
1237 
1238  // Remove type=api preferences. They are not intended for rendering in the form.
1239  foreach ( $formDescriptor as $name => $info ) {
1240  if ( isset( $info['type'] ) && $info['type'] === 'api' ) {
1241  unset( $formDescriptor[$name] );
1242  }
1243  }
1244 
1248  $htmlForm = new $formClass( $formDescriptor, $context, 'prefs' );
1249 
1250  $htmlForm->setModifiedUser( $user );
1251  $htmlForm->setId( 'mw-prefs-form' );
1252  $htmlForm->setSubmitText( $context->msg( 'saveprefs' )->text() );
1253  # Used message keys: 'accesskey-preferences-save', 'tooltip-preferences-save'
1254  $htmlForm->setSubmitTooltip( 'preferences-save' );
1255  $htmlForm->setSubmitID( 'prefsubmit' );
1256  $htmlForm->setSubmitCallback( array( 'Preferences', 'tryFormSubmit' ) );
1257 
1258  return $htmlForm;
1259  }
1260 
1265  static function getTimezoneOptions( IContextSource $context ) {
1266  $opt = array();
1267 
1268  global $wgLocalTZoffset;
1270  // Check that $wgLocalTZoffset is the same as the local time zone offset
1271  if ( $wgLocalTZoffset == $timestamp->format( 'Z' ) / 60 ) {
1272  $server_tz_msg = $context->msg(
1273  'timezoneuseserverdefault',
1274  $timestamp->getTimezone()->getName()
1275  )->text();
1276  } else {
1277  $tzstring = sprintf(
1278  '%+03d:%02d',
1279  floor( $wgLocalTZoffset / 60 ),
1280  abs( $wgLocalTZoffset ) % 60
1281  );
1282  $server_tz_msg = $context->msg( 'timezoneuseserverdefault', $tzstring )->text();
1283  }
1284  $opt[$server_tz_msg] = "System|$wgLocalTZoffset";
1285  $opt[$context->msg( 'timezoneuseoffset' )->text()] = 'other';
1286  $opt[$context->msg( 'guesstimezone' )->text()] = 'guess';
1287 
1288  if ( function_exists( 'timezone_identifiers_list' ) ) {
1289  # Read timezone list
1290  $tzs = timezone_identifiers_list();
1291  sort( $tzs );
1292 
1293  $tzRegions = array();
1294  $tzRegions['Africa'] = $context->msg( 'timezoneregion-africa' )->text();
1295  $tzRegions['America'] = $context->msg( 'timezoneregion-america' )->text();
1296  $tzRegions['Antarctica'] = $context->msg( 'timezoneregion-antarctica' )->text();
1297  $tzRegions['Arctic'] = $context->msg( 'timezoneregion-arctic' )->text();
1298  $tzRegions['Asia'] = $context->msg( 'timezoneregion-asia' )->text();
1299  $tzRegions['Atlantic'] = $context->msg( 'timezoneregion-atlantic' )->text();
1300  $tzRegions['Australia'] = $context->msg( 'timezoneregion-australia' )->text();
1301  $tzRegions['Europe'] = $context->msg( 'timezoneregion-europe' )->text();
1302  $tzRegions['Indian'] = $context->msg( 'timezoneregion-indian' )->text();
1303  $tzRegions['Pacific'] = $context->msg( 'timezoneregion-pacific' )->text();
1304  asort( $tzRegions );
1305 
1306  $prefill = array_fill_keys( array_values( $tzRegions ), array() );
1307  $opt = array_merge( $opt, $prefill );
1308 
1309  $now = date_create( 'now' );
1310 
1311  foreach ( $tzs as $tz ) {
1312  $z = explode( '/', $tz, 2 );
1313 
1314  # timezone_identifiers_list() returns a number of
1315  # backwards-compatibility entries. This filters them out of the
1316  # list presented to the user.
1317  if ( count( $z ) != 2 || !array_key_exists( $z[0], $tzRegions ) ) {
1318  continue;
1319  }
1320 
1321  # Localize region
1322  $z[0] = $tzRegions[$z[0]];
1323 
1324  $minDiff = floor( timezone_offset_get( timezone_open( $tz ), $now ) / 60 );
1325 
1326  $display = str_replace( '_', ' ', $z[0] . '/' . $z[1] );
1327  $value = "ZoneInfo|$minDiff|$tz";
1328 
1329  $opt[$z[0]][$display] = $value;
1330  }
1331  }
1332  return $opt;
1333  }
1334 
1340  static function filterIntval( $value, $alldata ) {
1341  return intval( $value );
1342  }
1343 
1349  static function filterTimezoneInput( $tz, $alldata ) {
1350  $data = explode( '|', $tz, 3 );
1351  switch ( $data[0] ) {
1352  case 'ZoneInfo':
1353  case 'System':
1354  return $tz;
1355  default:
1356  $data = explode( ':', $tz, 2 );
1357  if ( count( $data ) == 2 ) {
1358  $data[0] = intval( $data[0] );
1359  $data[1] = intval( $data[1] );
1360  $minDiff = abs( $data[0] ) * 60 + $data[1];
1361  if ( $data[0] < 0 ) {
1362  $minDiff = - $minDiff;
1363  }
1364  } else {
1365  $minDiff = intval( $data[0] ) * 60;
1366  }
1367 
1368  # Max is +14:00 and min is -12:00, see:
1369  # http://en.wikipedia.org/wiki/Timezone
1370  $minDiff = min( $minDiff, 840 ); # 14:00
1371  $minDiff = max( $minDiff, - 720 ); # -12:00
1372  return 'Offset|' . $minDiff;
1373  }
1374  }
1375 
1383  static function tryFormSubmit( $formData, $form ) {
1384  global $wgHiddenPrefs, $wgAuth;
1385 
1386  $user = $form->getModifiedUser();
1387  $result = true;
1388 
1389  if ( !$user->isAllowedAny( 'editmyprivateinfo', 'editmyoptions' ) ) {
1390  return Status::newFatal( 'mypreferencesprotected' );
1391  }
1392 
1393  // Filter input
1394  foreach ( array_keys( $formData ) as $name ) {
1395  if ( isset( self::$saveFilters[$name] ) ) {
1396  $formData[$name] =
1397  call_user_func( self::$saveFilters[$name], $formData[$name], $formData );
1398  }
1399  }
1400 
1401  // Fortunately, the realname field is MUCH simpler
1402  // (not really "private", but still shouldn't be edited without permission)
1403  if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->isAllowed( 'editmyprivateinfo' ) && array_key_exists( 'realname', $formData ) ) {
1404  $realName = $formData['realname'];
1405  $user->setRealName( $realName );
1406  }
1407 
1408  if ( $user->isAllowed( 'editmyoptions' ) ) {
1409  foreach ( self::$saveBlacklist as $b ) {
1410  unset( $formData[$b] );
1411  }
1412 
1413  # If users have saved a value for a preference which has subsequently been disabled
1414  # via $wgHiddenPrefs, we don't want to destroy that setting in case the preference
1415  # is subsequently re-enabled
1416  foreach ( $wgHiddenPrefs as $pref ) {
1417  # If the user has not set a non-default value here, the default will be returned
1418  # and subsequently discarded
1419  $formData[$pref] = $user->getOption( $pref, null, true );
1420  }
1421 
1422  // Keep old preferences from interfering due to back-compat code, etc.
1423  $user->resetOptions( 'unused', $form->getContext() );
1424 
1425  foreach ( $formData as $key => $value ) {
1426  $user->setOption( $key, $value );
1427  }
1428 
1429  wfRunHooks( 'PreferencesFormPreSave', array( $formData, $form, $user, &$result ) );
1430  $user->saveSettings();
1431  }
1432 
1433  $wgAuth->updateExternalDB( $user );
1434 
1435  return $result;
1436  }
1437 
1443  public static function tryUISubmit( $formData, $form ) {
1444  $res = self::tryFormSubmit( $formData, $form );
1445 
1446  if ( $res ) {
1447  $urlOptions = array( 'success' => 1 );
1448 
1449  if ( $res === 'eauth' ) {
1450  $urlOptions['eauth'] = 1;
1451  }
1452 
1453  $urlOptions += $form->getExtraSuccessRedirectParameters();
1454 
1455  $url = $form->getTitle()->getFullURL( $urlOptions );
1456 
1457  $form->getContext()->getOutput()->redirect( $url );
1458  }
1459 
1460  return Status::newGood();
1461  }
1462 
1474  public static function trySetUserEmail( User $user, $newaddr ) {
1475  wfDeprecated( __METHOD__, '1.20' );
1476 
1477  $result = $user->setEmailWithConfirmation( $newaddr );
1478  if ( $result->isGood() ) {
1479  return array( true, $result->value );
1480  } else {
1481  return array( $result, 'mailerror' );
1482  }
1483  }
1484 
1490  public static function loadOldSearchNs( $user ) {
1491  wfDeprecated( __METHOD__, '1.19' );
1492 
1493  $searchableNamespaces = SearchEngine::searchableNamespaces();
1494  // Back compat with old format
1495  $arr = array();
1496 
1497  foreach ( $searchableNamespaces as $ns => $name ) {
1498  if ( $user->getOption( 'searchNs' . $ns ) ) {
1499  $arr[] = $ns;
1500  }
1501  }
1502 
1503  return $arr;
1504  }
1505 }
1506 
1508 class PreferencesForm extends HTMLForm {
1509  // Override default value from HTMLForm
1510  protected $mSubSectionBeforeFields = false;
1511 
1512  private $modifiedUser;
1513 
1517  public function setModifiedUser( $user ) {
1518  $this->modifiedUser = $user;
1519  }
1520 
1524  public function getModifiedUser() {
1525  if ( $this->modifiedUser === null ) {
1526  return $this->getUser();
1527  } else {
1528  return $this->modifiedUser;
1529  }
1530  }
1531 
1539  return array();
1540  }
1541 
1546  function wrapForm( $html ) {
1547  $html = Xml::tags( 'div', array( 'id' => 'preferences' ), $html );
1548 
1549  return parent::wrapForm( $html );
1550  }
1551 
1555  function getButtons() {
1556  if ( !$this->getModifiedUser()->isAllowedAny( 'editmyprivateinfo', 'editmyoptions' ) ) {
1557  return '';
1558  }
1559 
1560  $html = parent::getButtons();
1561 
1562  if ( $this->getModifiedUser()->isAllowed( 'editmyoptions' ) ) {
1563  $t = SpecialPage::getTitleFor( 'Preferences', 'reset' );
1564 
1565  $html .= "\n" . Linker::link( $t, $this->msg( 'restoreprefs' )->escaped() );
1566 
1567  $html = Xml::tags( 'div', array( 'class' => 'mw-prefs-buttons' ), $html );
1568  }
1569 
1570  return $html;
1571  }
1572 
1579  function filterDataForSubmit( $data ) {
1580  foreach ( $this->mFlatFields as $fieldname => $field ) {
1581  if ( $field instanceof HTMLNestedFilterable ) {
1582  $info = $field->mParams;
1583  $prefix = isset( $info['prefix'] ) ? $info['prefix'] : $fieldname;
1584  foreach ( $field->filterDataForSubmit( $data[$fieldname] ) as $key => $value ) {
1585  $data["$prefix$key"] = $value;
1586  }
1587  unset( $data[$fieldname] );
1588  }
1589  }
1590 
1591  return $data;
1592  }
1593 
1598  function getBody() {
1599  return $this->displaySection( $this->mFieldTree, '', 'mw-prefsection-' );
1600  }
1601 
1608  function getLegend( $key ) {
1609  $legend = parent::getLegend( $key );
1610  wfRunHooks( 'PreferencesGetLegend', array( $this, $key, &$legend ) );
1611  return $legend;
1612  }
1613 }
Preferences\getPreferences
static getPreferences( $user, IContextSource $context)
Definition: Preferences.php:78
Preferences\getThumbSizes
static getThumbSizes(IContextSource $context)
Definition: Preferences.php:1162
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. $reader:XMLReader object $logInfo:Array of information Return false to stop further processing of the tag 'ImportHandlePageXMLTag':When parsing a XML tag in a page. $reader:XMLReader object $pageInfo:Array of information Return false to stop further processing of the tag 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information Return false to stop further processing of the tag 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. $reader:XMLReader object Return false to stop further processing of the tag 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. $reader:XMLReader object $revisionInfo:Array of information Return false to stop further processing of the tag 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. $title:Title object for the current page $request:WebRequest $ignoreRedirect:boolean to skip redirect check $target:Title/string of redirect target $article:Article object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) $article:article(object) being checked 'IsTrustedProxy':Override the result of wfIsTrustedProxy() $ip:IP being check $result:Change this value to override the result of wfIsTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of User::isValidEmailAddr(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetMagic':DEPRECATED, use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetSpecialPageAliases':DEPRECATED, use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Associative array mapping language codes to prefixed links of the form "language:title". & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LinkBegin':Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1528
$time
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition: hooks.txt:1358
Preferences\filterTimezoneInput
static filterTimezoneInput( $tz, $alldata)
Definition: Preferences.php:1349
wfBCP47
wfBCP47( $code)
Get the normalised IETF language tag See unit test for examples.
Definition: GlobalFunctions.php:3929
wfCanIPUseHTTPS
wfCanIPUseHTTPS( $ip)
Determine whether the client at a given source IP is likely to be able to access the wiki via HTTPS.
Definition: GlobalFunctions.php:4138
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
Preferences\rcPreferences
static rcPreferences( $user, IContextSource $context, &$defaultPreferences)
Definition: Preferences.php:854
$html
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition: hooks.txt:1530
ContextSource\msg
msg()
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:175
Preferences\trySetUserEmail
static trySetUserEmail(User $user, $newaddr)
Try to set a user's email address.
Definition: Preferences.php:1474
Xml\tags
static tags( $element, $attribs=null, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:131
Preferences\editingPreferences
static editingPreferences( $user, IContextSource $context, &$defaultPreferences)
Definition: Preferences.php:766
PreferencesForm\filterDataForSubmit
filterDataForSubmit( $data)
Separate multi-option preferences into multiple preferences, since we have to store them separately.
Definition: Preferences.php:1579
PreferencesForm\getExtraSuccessRedirectParameters
getExtraSuccessRedirectParameters()
Get extra parameters for the query string when redirecting after successful save.
Definition: Preferences.php:1538
Preferences\$defaultPreferences
static $defaultPreferences
Definition: Preferences.php:49
text
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition: design.txt:12
$timestamp
if( $limit) $timestamp
Definition: importImages.php:104
Preferences\$saveFilters
static $saveFilters
Definition: Preferences.php:50
Title\newMainPage
static newMainPage()
Create a new Title for the Main Page.
Definition: Title.php:441
$form
usually copyright or history_copyright This message must be in HTML not wikitext $subpages will be ignored and the rest of subPageSubtitle() will run. 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink' whether MediaWiki currently thinks this is a CSS JS page Hooks may change this value to override the return value of Title::isCssOrJsPage(). 'TitleIsAlwaysKnown' whether MediaWiki currently thinks this page is known isMovable() always returns false. $title whether MediaWiki currently thinks this page is movable Hooks may change this value to override the return value of Title::isMovable(). 'TitleIsWikitextPage' whether MediaWiki currently thinks this is a wikitext page Hooks may change this value to override the return value of Title::isWikitextPage() 'TitleMove' use UploadVerification and UploadVerifyFile instead $form
Definition: hooks.txt:2573
SearchEngine\searchableNamespaces
static searchableNamespaces()
Make a list of searchable namespaces and their canonical names.
Definition: SearchEngine.php:334
MediaWiki\getTitle
getTitle()
Get the Title object that we'll be acting on, as specified in the WebRequest.
Definition: Wiki.php:134
$defaultOptions
return false to override stock group addition can be modified try getUserPermissionsErrors userCan checks are continued by internal code can override on output return false to not delete it return false to override the default password checks this Boolean value will be checked to determine if the password was valid return false to implement your own hashing method this String will be used as the hash which may be added to this hook is run right before returning the options to the caller which means it s potentially called dozens or hundreds of times You may want to cache the results of non trivial operations in your hook function for this reason & $defaultOptions
Definition: hooks.txt:2697
User\makeGroupLinkHTML
static makeGroupLinkHTML( $group, $text='')
Create a link to the group in HTML, if available; else return the group name.
Definition: User.php:4282
$ret
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition: hooks.txt:1530
PreferencesForm\wrapForm
wrapForm( $html)
Definition: Preferences.php:1546
Status\newGood
static newGood( $value=null)
Factory function for good results.
Definition: Status.php:77
PreferencesForm\getLegend
getLegend( $key)
Get the "<legend>" for a given section key.
Definition: Preferences.php:1608
PreferencesForm\getBody
getBody()
Get the whole body of the form.
Definition: Preferences.php:1598
Preferences\searchPreferences
static searchPreferences( $user, IContextSource $context, &$defaultPreferences)
Definition: Preferences.php:1015
IContextSource\msg
msg()
Get a Message object with context set.
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name.
Definition: SpecialPage.php:74
Preferences\filterIntval
static filterIntval( $value, $alldata)
Definition: Preferences.php:1340
Html\hidden
static hidden( $name, $value, $attribs=array())
Convenience function to produce an input element with type=hidden.
Definition: Html.php:662
$wgContLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the content language as $wgContLang
Definition: design.txt:56
Preferences\getDateOptions
static getDateOptions(IContextSource $context)
Definition: Preferences.php:1109
Preferences\tryUISubmit
static tryUISubmit( $formData, $form)
Definition: Preferences.php:1443
ContextSource\getUser
getUser()
Get the User object.
Definition: ContextSource.php:132
$link
set to $title object and return false for a match for latest after cache objects are set use the ContentHandler facility to handle CSS and JavaScript for highlighting & $link
Definition: hooks.txt:2149
PreferencesForm\$modifiedUser
$modifiedUser
Definition: Preferences.php:1512
PreferencesForm\getButtons
getButtons()
Definition: Preferences.php:1555
Linker\linkKnown
static linkKnown( $target, $html=null, $customAttribs=array(), $query=array(), $options=array( 'known', 'noclasses'))
Identical to link(), except $options defaults to 'known'.
Definition: Linker.php:264
Preferences\getSaveBlacklist
static getSaveBlacklist()
Definition: Preferences.php:68
User\getDefaultOptions
static getDefaultOptions()
Combine the language default options with any site-specific options and add the default language vari...
Definition: User.php:1350
Linker\link
static link( $target, $html=null, $customAttribs=array(), $query=array(), $options=array())
This function returns an HTML link to the given target.
Definition: Linker.php:192
below
controlled by $wgMainCacheType controlled by $wgParserCacheType controlled by $wgMessageCacheType If you set CACHE_NONE to one of the three control default value for MediaWiki still create a but requests to it are no ops and we always fall through to the database If the cache daemon can t be it should also disable itself fairly smoothly By $wgMemc is used but when it is $parserMemc or $messageMemc this is mentioned below
Definition: memcached.txt:96
Preferences
We're now using the HTMLForm object with some customisation to generate the Preferences form.
Definition: Preferences.php:48
Preferences\getFormObject
static getFormObject( $user, IContextSource $context, $formClass='PreferencesForm', array $remove=array())
Definition: Preferences.php:1226
MWException
MediaWiki exception.
Definition: MWException.php:26
PreferencesForm\getModifiedUser
getModifiedUser()
Definition: Preferences.php:1524
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1127
Language\fetchLanguageNames
static fetchLanguageNames( $inLanguage=null, $include='mw')
Get an array of language names, indexed by code.
Definition: Language.php:875
Preferences\generateSkinOptions
static generateSkinOptions( $user, IContextSource $context)
Definition: Preferences.php:1052
Xml\element
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
Definition: Xml.php:39
wfRunHooks
wfRunHooks( $event, array $args=array(), $deprecatedVersion=null)
Call hook functions defined in $wgHooks.
Definition: GlobalFunctions.php:4010
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
PreferencesForm
Some tweaks to allow js prefs to work.
Definition: Preferences.php:1508
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:2514
$columns
if(! $in) $columns
Definition: Utf8Test.php:50
Preferences\validateSignature
static validateSignature( $signature, $alldata, $form)
Definition: Preferences.php:1182
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:188
Preferences\miscPreferences
static miscPreferences( $user, IContextSource $context, &$defaultPreferences)
Dummy, kept for backwards-compatibility.
Definition: Preferences.php:1044
$options
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition: hooks.txt:1530
Preferences\watchlistPreferences
static watchlistPreferences( $user, IContextSource $context, &$defaultPreferences)
Definition: Preferences.php:911
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:422
$languages
$languages
Definition: rebuildLanguage.php:129
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
Preferences\tryFormSubmit
static tryFormSubmit( $formData, $form)
Handle the form submission if everything validated properly.
Definition: Preferences.php:1383
Preferences\skinPreferences
static skinPreferences( $user, IContextSource $context, &$defaultPreferences)
Definition: Preferences.php:570
$size
$size
Definition: RandomTest.php:75
$value
$value
Definition: styleTest.css.php:45
ParserOptions\newFromContext
static newFromContext(IContextSource $context)
Get a ParserOptions object from a IContextSource object.
Definition: ParserOptions.php:396
Preferences\$saveBlacklist
static $saveBlacklist
Definition: Preferences.php:60
HTMLForm\displaySection
displaySection( $fields, $sectionName='', $fieldsetIDPrefix='', &$hasUserVisibleFields=false)
Definition: HTMLForm.php:1169
IContextSource\getUser
getUser()
Get the User object.
PreferencesForm\setModifiedUser
setModifiedUser( $user)
Definition: Preferences.php:1517
IContextSource\getTitle
getTitle()
Get the Title object.
HTMLForm\loadInputFromParameters
static loadInputFromParameters( $fieldname, $descriptor)
Initialise a new Object for the field.
Definition: HTMLForm.php:351
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:237
User\getGroupMember
static getGroupMember( $group, $username='#')
Get the localized descriptive name for a member of a group, if it exists.
Definition: User.php:4210
IContextSource
Interface for objects which can provide a context on request.
Definition: IContextSource.php:29
User\getGroupName
static getGroupName( $group)
Get the localized descriptive name for a group, if it exists.
Definition: User.php:4198
$wgParser
$wgParser
Definition: Setup.php:567
Preferences\profilePreferences
static profilePreferences( $user, IContextSource $context, &$defaultPreferences)
Definition: Preferences.php:194
Preferences\getTimezoneOptions
static getTimezoneOptions(IContextSource $context)
Definition: Preferences.php:1265
on
We ve cleaned up the code here by removing clumps of infrequently used code and moving them off somewhere else It s much easier for someone working with this code to see what s _really_ going on
Definition: hooks.txt:86
PreferencesForm\$mSubSectionBeforeFields
$mSubSectionBeforeFields
Definition: Preferences.php:1510
HTMLNestedFilterable
Definition: HTMLNestedFilterable.php:3
used
you don t have to do a grep find to see where the $wgReverseTitle variable is used
Definition: hooks.txt:117
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
NS_USER
const NS_USER
Definition: Defines.php:81
IContextSource\getRequest
getRequest()
Get the WebRequest object.
HTMLFormField\flattenOptions
static flattenOptions( $options)
flatten an array of options to a single array, for instance, a set of "<options>" inside "<optgroups>...
Definition: HTMLFormField.php:601
$t
$t
Definition: testCompression.php:65
Skin\getAllowedSkins
static getAllowedSkins()
Fetch the list of user-selectable skins in regards to $wgSkipSkins.
Definition: Skin.php:108
Preferences\loadOldSearchNs
static loadOldSearchNs( $user)
Definition: Preferences.php:1490
Preferences\getImageSizes
static getImageSizes(IContextSource $context)
Definition: Preferences.php:1144
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:59
message
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form externallinks including delete and has completed for all link tables default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a message
Definition: hooks.txt:1624
IContextSource\getOutput
getOutput()
Get the OutputPage object.
$res
$res
Definition: database.txt:21
MWTimestamp\getLocalInstance
static getLocalInstance( $ts=false)
Get a timestamp instance in the server local timezone ($wgLocaltimezone)
Definition: MWTimestamp.php:373
Preferences\filesPreferences
static filesPreferences( $user, IContextSource $context, &$defaultPreferences)
Definition: Preferences.php:613
Preferences\getOptionFromUser
static getOptionFromUser( $name, $info, $user)
Pull option from a user account.
Definition: Preferences.php:151
Preferences\renderingPreferences
static renderingPreferences( $user, IContextSource $context, &$defaultPreferences)
Definition: Preferences.php:707
IContextSource\getLanguage
getLanguage()
Get the Language object.
Status\newFatal
static newFatal( $message)
Factory function for fatal errors.
Definition: Status.php:63
Preferences\cleanSignature
static cleanSignature( $signature, $alldata, $form)
Definition: Preferences.php:1207
HTMLForm
Object handling generic submission, CSRF protection, layout and other logic for UI forms.
Definition: HTMLForm.php:100
Preferences\datetimePreferences
static datetimePreferences( $user, IContextSource $context, &$defaultPreferences)
Definition: Preferences.php:635