r99346 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99345‎ | r99346 | r99347 >
Date:11:43, 9 October 2011
Author:ialex
Status:ok
Tags:
Comment:
* Use the context when building the preferences form descriptor
* Pass the HTMLForm object to the submit callback so that it can have a context and also access to the form itself (see below). This makes Preferences::tryUISubmit() and Prefrences::tryFormSubmit() signatures incompatible. The only extension calling these is EditUser and I will fix in my next commit.
* Added two extension possibilites (for EditUser): PreferencesForm::getExtraSuccessRedirectParameters() to modify the URL parameters when redirecting after successful save and the fourthparameter to Prefrences::getFormObject() to be able to remove some items from the descriptor
* Pass the user being modified to the HTMLForm to use it to save the preferences instead of doing this unconditionally on $wgUser (to remove one hack in EditUser preferences)
Modified paths:
  • /trunk/phase3/includes/HTMLForm.php (modified) (history)
  • /trunk/phase3/includes/Preferences.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/HTMLForm.php
@@ -277,7 +277,7 @@
278278
279279 $data = $this->filterDataForSubmit( $this->mFieldData );
280280
281 - $res = call_user_func( $callback, $data );
 281+ $res = call_user_func( $callback, $data, $this );
282282
283283 return $res;
284284 }
Index: trunk/phase3/includes/Preferences.php
@@ -39,25 +39,26 @@
4040 /**
4141 * @throws MWException
4242 * @param $user User
 43+ * @param $context IContextSource
4344 * @return array|null
4445 */
45 - static function getPreferences( $user ) {
 46+ static function getPreferences( $user, IContextSource $context ) {
4647 if ( self::$defaultPreferences ) {
4748 return self::$defaultPreferences;
4849 }
4950
5051 $defaultPreferences = array();
5152
52 - self::profilePreferences( $user, $defaultPreferences );
53 - self::skinPreferences( $user, $defaultPreferences );
54 - self::filesPreferences( $user, $defaultPreferences );
55 - self::datetimePreferences( $user, $defaultPreferences );
56 - self::renderingPreferences( $user, $defaultPreferences );
57 - self::editingPreferences( $user, $defaultPreferences );
58 - self::rcPreferences( $user, $defaultPreferences );
59 - self::watchlistPreferences( $user, $defaultPreferences );
60 - self::searchPreferences( $user, $defaultPreferences );
61 - self::miscPreferences( $user, $defaultPreferences );
 53+ self::profilePreferences( $user, $context, $defaultPreferences );
 54+ self::skinPreferences( $user, $context, $defaultPreferences );
 55+ self::filesPreferences( $user, $context, $defaultPreferences );
 56+ self::datetimePreferences( $user, $context, $defaultPreferences );
 57+ self::renderingPreferences( $user, $context, $defaultPreferences );
 58+ self::editingPreferences( $user, $context, $defaultPreferences );
 59+ self::rcPreferences( $user, $context, $defaultPreferences );
 60+ self::watchlistPreferences( $user, $context, $defaultPreferences );
 61+ self::searchPreferences( $user, $context, $defaultPreferences );
 62+ self::miscPreferences( $user, $context, $defaultPreferences );
6263
6364 wfRunHooks( 'GetPreferences', array( $user, &$defaultPreferences ) );
6465
@@ -127,11 +128,16 @@
128129
129130 /**
130131 * @param $user User
 132+ * @param $context IContextSource
131133 * @param $defaultPreferences
132134 * @return void
133135 */
134 - static function profilePreferences( $user, &$defaultPreferences ) {
135 - global $wgLang;
 136+ static function profilePreferences( $user, IContextSource $context, &$defaultPreferences ) {
 137+ global $wgAuth, $wgContLang, $wgParser, $wgCookieExpiration, $wgLanguageCode,
 138+ $wgDisableTitleConversion, $wgDisableLangConversion, $wgMaxSigChars,
 139+ $wgEnableEmail, $wgEmailConfirmToEdit, $wgEnableUserEmail, $wgEmailAuthentication,
 140+ $wgEnotifWatchlist, $wgEnotifUserTalk, $wgEnotifRevealEditorAddress;
 141+
136142 ## User info #####################################
137143 // Information panel
138144 $defaultPreferences['username'] = array(
@@ -165,17 +171,16 @@
166172 asort( $userGroups );
167173 asort( $userMembers );
168174
 175+ $lang = $context->getLang();
 176+
169177 $defaultPreferences['usergroups'] = array(
170178 'type' => 'info',
171 - 'label' => wfMsgExt(
172 - 'prefs-memberingroups', 'parseinline',
173 - $wgLang->formatNum( count( $userGroups ) )
174 - ),
175 - 'default' => wfMsgExt(
176 - 'prefs-memberingroups-type', array(),
177 - $wgLang->commaList( $userGroups ),
178 - $wgLang->commaList( $userMembers )
179 - ),
 179+ 'label' => $context->msg( 'prefs-memberingroups' )->numParams(
 180+ count( $userGroups ) )->parse(),
 181+ 'default' => $context->msg( 'prefs-memberingroups-type',
 182+ $lang->commaList( $userGroups ),
 183+ $lang->commaList( $userMembers )
 184+ )->plain(),
180185 'raw' => true,
181186 'section' => 'personal/info',
182187 );
@@ -183,7 +188,7 @@
184189 $defaultPreferences['editcount'] = array(
185190 'type' => 'info',
186191 'label-message' => 'prefs-edits',
187 - 'default' => $wgLang->formatNum( $user->getEditCount() ),
 192+ 'default' => $lang->formatNum( $user->getEditCount() ),
188193 'section' => 'personal/info',
189194 );
190195
@@ -191,18 +196,17 @@
192197 $defaultPreferences['registrationdate'] = array(
193198 'type' => 'info',
194199 'label-message' => 'prefs-registration',
195 - 'default' => wfMsgExt(
196 - 'prefs-registration-date-time', 'parsemag',
197 - $wgLang->timeanddate( $user->getRegistration(), true ),
198 - $wgLang->date( $user->getRegistration(), true ),
199 - $wgLang->time( $user->getRegistration(), true )
200 - ),
 200+ 'default' => $context->msg(
 201+ 'prefs-registration-date-time',
 202+ $lang->timeanddate( $user->getRegistration(), true ),
 203+ $lang->date( $user->getRegistration(), true ),
 204+ $lang->time( $user->getRegistration(), true )
 205+ )->parse(),
201206 'section' => 'personal/info',
202207 );
203208 }
204209
205210 // Actually changeable stuff
206 - global $wgAuth;
207211 $defaultPreferences['realname'] = array(
208212 'type' => $wgAuth->allowPropChange( 'realname' ) ? 'text' : 'info',
209213 'default' => $user->getRealName(),
@@ -215,9 +219,9 @@
216220 'type' => 'select',
217221 'section' => 'personal/info',
218222 'options' => array(
219 - wfMsg( 'gender-male' ) => 'male',
220 - wfMsg( 'gender-female' ) => 'female',
221 - wfMsg( 'gender-unknown' ) => 'unknown',
 223+ $context->msg( 'gender-male' )->text() => 'male',
 224+ $context->msg( 'gender-female' )->text() => 'female',
 225+ $context->msg( 'gender-unknown' )->text() => 'unknown',
222226 ),
223227 'label-message' => 'yourgender',
224228 'help-message' => 'prefs-help-gender',
@@ -225,7 +229,7 @@
226230
227231 if ( $wgAuth->allowPasswordChange() ) {
228232 $link = Linker::link( SpecialPage::getTitleFor( 'ChangePassword' ),
229 - wfMsgHtml( 'prefs-resetpass' ), array(),
 233+ $context->msg( 'prefs-resetpass' )->escaped(), array(),
230234 array( 'returnto' => SpecialPage::getTitleFor( 'Preferences' ) ) );
231235
232236 $defaultPreferences['password'] = array(
@@ -236,21 +240,16 @@
237241 'section' => 'personal/info',
238242 );
239243 }
240 - global $wgCookieExpiration;
241244 if ( $wgCookieExpiration > 0 ) {
242245 $defaultPreferences['rememberpassword'] = array(
243246 'type' => 'toggle',
244 - 'label' => wfMsgExt(
245 - 'tog-rememberpassword',
246 - array( 'parsemag' ),
247 - $wgLang->formatNum( ceil( $wgCookieExpiration / ( 3600 * 24 ) ) )
248 - ),
 247+ 'label' => $context->msg( 'tog-rememberpassword' )->numParams(
 248+ ceil( $wgCookieExpiration / ( 3600 * 24 ) ) )->text(),
249249 'section' => 'personal/info',
250250 );
251251 }
252252
253253 // Language
254 - global $wgLanguageCode;
255254 $languages = Language::getLanguageNames( false );
256255 if ( !array_key_exists( $wgLanguageCode, $languages ) ) {
257256 $languages[$wgLanguageCode] = $wgLanguageCode;
@@ -269,8 +268,6 @@
270269 'label-message' => 'yourlanguage',
271270 );
272271
273 - global $wgContLang, $wgDisableLangConversion;
274 - global $wgDisableTitleConversion;
275272 /* see if there are multiple language variants to choose from*/
276273 $variantArray = array();
277274 if ( !$wgDisableLangConversion ) {
@@ -300,18 +297,16 @@
301298
302299 if ( count( $variantArray ) > 1 && !$wgDisableLangConversion && !$wgDisableTitleConversion ) {
303300 $defaultPreferences['noconvertlink'] =
304 - array(
 301+ array(
305302 'type' => 'toggle',
306303 'section' => 'personal/i18n',
307304 'label-message' => 'tog-noconvertlink',
308305 );
309306 }
310307
311 - global $wgMaxSigChars, $wgOut, $wgParser;
312 -
313308 // show a preview of the old signature first
314 - $oldsigWikiText = $wgParser->preSaveTransform( "~~~", new Title, $user, new ParserOptions );
315 - $oldsigHTML = $wgOut->parseInline( $oldsigWikiText, true, true );
 309+ $oldsigWikiText = $wgParser->preSaveTransform( "~~~", $context->getTitle(), $user, new ParserOptions );
 310+ $oldsigHTML = $context->getOutput()->parseInline( $oldsigWikiText, true, true );
316311 $defaultPreferences['oldsig'] = array(
317312 'type' => 'info',
318313 'raw' => true,
@@ -336,11 +331,7 @@
337332
338333 ## Email stuff
339334
340 - global $wgEnableEmail;
341335 if ( $wgEnableEmail ) {
342 - global $wgEmailConfirmToEdit;
343 - global $wgEnableUserEmail;
344 -
345336 $helpMessages[] = $wgEmailConfirmToEdit
346337 ? 'prefs-help-email-required'
347338 : 'prefs-help-email' ;
@@ -352,7 +343,7 @@
353344
354345 $link = Linker::link(
355346 SpecialPage::getTitleFor( 'ChangeEmail' ),
356 - wfMsgHtml( $user->getEmail() ? 'prefs-changeemail' : 'prefs-setemail' ),
 347+ $context->msg( $user->getEmail() ? 'prefs-changeemail' : 'prefs-setemail' )->escaped(),
357348 array(),
358349 array( 'returnto' => SpecialPage::getTitleFor( 'Preferences' ) ) );
359350
@@ -369,8 +360,6 @@
370361 'section' => 'personal/email',
371362 );
372363
373 - global $wgEmailAuthentication;
374 -
375364 $disableEmailPrefs = false;
376365
377366 if ( $wgEmailAuthentication ) {
@@ -379,25 +368,23 @@
380369 // date and time are separate parameters to facilitate localisation.
381370 // $time is kept for backward compat reasons.
382371 // 'emailauthenticated' is also used in SpecialConfirmemail.php
383 - $time = $wgLang->timeAndDate( $user->getEmailAuthenticationTimestamp(), true );
384 - $d = $wgLang->date( $user->getEmailAuthenticationTimestamp(), true );
385 - $t = $wgLang->time( $user->getEmailAuthenticationTimestamp(), true );
386 - $emailauthenticated = wfMsgExt(
387 - 'emailauthenticated', 'parseinline',
388 - array( $time, $d, $t )
389 - ) . '<br />';
 372+ $time = $lang->timeAndDate( $user->getEmailAuthenticationTimestamp(), true );
 373+ $d = $lang->date( $user->getEmailAuthenticationTimestamp(), true );
 374+ $t = $lang->time( $user->getEmailAuthenticationTimestamp(), true );
 375+ $emailauthenticated = $context->msg( 'emailauthenticated',
 376+ $time, $d, $t )->parse() . '<br />';
390377 $disableEmailPrefs = false;
391378 } else {
392379 $disableEmailPrefs = true;
393 - $emailauthenticated = wfMsgExt( 'emailnotauthenticated', 'parseinline' ) . '<br />' .
 380+ $emailauthenticated = $context->msg( 'emailnotauthenticated' )->parse() . '<br />' .
394381 Linker::linkKnown(
395382 SpecialPage::getTitleFor( 'Confirmemail' ),
396 - wfMsg( 'emailconfirmlink' )
 383+ $context->msg( 'emailconfirmlink' )->escaped()
397384 ) . '<br />';
398385 }
399386 } else {
400387 $disableEmailPrefs = true;
401 - $emailauthenticated = wfMsgHtml( 'noemailprefs' );
 388+ $emailauthenticated = $context->msg( 'noemailprefs' )->escaped();
402389 }
403390
404391 $defaultPreferences['emailauthentication'] = array(
@@ -426,7 +413,6 @@
427414 );
428415 }
429416
430 - global $wgEnotifWatchlist;
431417 if ( $wgEnotifWatchlist ) {
432418 $defaultPreferences['enotifwatchlistpages'] = array(
433419 'type' => 'toggle',
@@ -435,7 +421,6 @@
436422 'disabled' => $disableEmailPrefs,
437423 );
438424 }
439 - global $wgEnotifUserTalk;
440425 if ( $wgEnotifUserTalk ) {
441426 $defaultPreferences['enotifusertalkpages'] = array(
442427 'type' => 'toggle',
@@ -452,7 +437,6 @@
453438 'disabled' => $disableEmailPrefs,
454439 );
455440
456 - global $wgEnotifRevealEditorAddress;
457441 if ( $wgEnotifRevealEditorAddress ) {
458442 $defaultPreferences['enotifrevealaddr'] = array(
459443 'type' => 'toggle',
@@ -467,16 +451,17 @@
468452
469453 /**
470454 * @param $user User
 455+ * @param $context IContextSource
471456 * @param $defaultPreferences
472457 * @return void
473458 */
474 - static function skinPreferences( $user, &$defaultPreferences ) {
 459+ static function skinPreferences( $user, IContextSource $context, &$defaultPreferences ) {
475460 ## Skin #####################################
476 - global $wgLang, $wgAllowUserCss, $wgAllowUserJs;
 461+ global $wgAllowUserCss, $wgAllowUserJs;
477462
478463 $defaultPreferences['skin'] = array(
479464 'type' => 'radio',
480 - 'options' => self::generateSkinOptions( $user ),
 465+ 'options' => self::generateSkinOptions( $user, $context ),
481466 'label' => '&#160;',
482467 'section' => 'rendering/skin',
483468 );
@@ -489,18 +474,18 @@
490475
491476 if ( $wgAllowUserCss ) {
492477 $cssPage = Title::makeTitleSafe( NS_USER, $user->getName() . '/common.css' );
493 - $linkTools[] = Linker::link( $cssPage, wfMsgHtml( 'prefs-custom-css' ) );
 478+ $linkTools[] = Linker::link( $cssPage, $context->msg( 'prefs-custom-css' )->escaped() );
494479 }
495480
496481 if ( $wgAllowUserJs ) {
497482 $jsPage = Title::makeTitleSafe( NS_USER, $user->getName() . '/common.js' );
498 - $linkTools[] = Linker::link( $jsPage, wfMsgHtml( 'prefs-custom-js' ) );
 483+ $linkTools[] = Linker::link( $jsPage, $context->msg( 'prefs-custom-js' )->escaped() );
499484 }
500485
501486 $defaultPreferences['commoncssjs'] = array(
502487 'type' => 'info',
503488 'raw' => true,
504 - 'default' => $wgLang->pipeList( $linkTools ),
 489+ 'default' => $context->getLang()->pipeList( $linkTools ),
505490 'label-message' => 'prefs-common-css-js',
506491 'section' => 'rendering/skin',
507492 );
@@ -508,7 +493,7 @@
509494
510495 $selectedSkin = $user->getOption( 'skin' );
511496 if ( in_array( $selectedSkin, array( 'cologneblue', 'standard' ) ) ) {
512 - $settings = array_flip( $wgLang->getQuickbarSettings() );
 497+ $settings = array_flip( $context->getLang()->getQuickbarSettings() );
513498
514499 $defaultPreferences['quickbar'] = array(
515500 'type' => 'radio',
@@ -521,19 +506,20 @@
522507
523508 /**
524509 * @param $user User
 510+ * @param $context IContextSource
525511 * @param $defaultPreferences Array
526512 */
527 - static function filesPreferences( $user, &$defaultPreferences ) {
 513+ static function filesPreferences( $user, IContextSource $context, &$defaultPreferences ) {
528514 ## Files #####################################
529515 $defaultPreferences['imagesize'] = array(
530516 'type' => 'select',
531 - 'options' => self::getImageSizes(),
 517+ 'options' => self::getImageSizes( $context ),
532518 'label-message' => 'imagemaxsize',
533519 'section' => 'rendering/files',
534520 );
535521 $defaultPreferences['thumbsize'] = array(
536522 'type' => 'select',
537 - 'options' => self::getThumbSizes(),
 523+ 'options' => self::getThumbSizes( $context ),
538524 'label-message' => 'thumbsize',
539525 'section' => 'rendering/files',
540526 );
@@ -541,14 +527,13 @@
542528
543529 /**
544530 * @param $user User
 531+ * @param $context IContextSource
545532 * @param $defaultPreferences
546533 * @return void
547534 */
548 - static function datetimePreferences( $user, &$defaultPreferences ) {
549 - global $wgLang;
550 -
 535+ static function datetimePreferences( $user, IContextSource $context, &$defaultPreferences ) {
551536 ## Date and time #####################################
552 - $dateOptions = self::getDateOptions();
 537+ $dateOptions = self::getDateOptions( $context );
553538 if ( $dateOptions ) {
554539 $defaultPreferences['date'] = array(
555540 'type' => 'radio',
@@ -560,9 +545,10 @@
561546
562547 // Info
563548 $now = wfTimestampNow();
 549+ $lang = $context->getLang();
564550 $nowlocal = Xml::element( 'span', array( 'id' => 'wpLocalTime' ),
565 - $wgLang->time( $now, true ) );
566 - $nowserver = $wgLang->time( $now, false ) .
 551+ $lang->time( $now, true ) );
 552+ $nowserver = $lang->time( $now, false ) .
567553 Html::hidden( 'wpServerTime', (int)substr( $now, 8, 2 ) * 60 + (int)substr( $now, 10, 2 ) );
568554
569555 $defaultPreferences['nowserver'] = array(
@@ -594,7 +580,7 @@
595581 $defaultPreferences['timecorrection'] = array(
596582 'class' => 'HTMLSelectOrOtherField',
597583 'label-message' => 'timezonelegend',
598 - 'options' => self::getTimezoneOptions(),
 584+ 'options' => self::getTimezoneOptions( $context ),
599585 'default' => $tzSetting,
600586 'size' => 20,
601587 'section' => 'datetime/timeoffset',
@@ -603,18 +589,19 @@
604590
605591 /**
606592 * @param $user User
 593+ * @param $context IContextSource
607594 * @param $defaultPreferences Array
608595 */
609 - static function renderingPreferences( $user, &$defaultPreferences ) {
 596+ static function renderingPreferences( $user, IContextSource $context, &$defaultPreferences ) {
610597 ## Page Rendering ##############################
611598 global $wgAllowUserCssPrefs;
612599 if ( $wgAllowUserCssPrefs ) {
613600 $defaultPreferences['underline'] = array(
614601 'type' => 'select',
615602 'options' => array(
616 - wfMsg( 'underline-never' ) => 0,
617 - wfMsg( 'underline-always' ) => 1,
618 - wfMsg( 'underline-default' ) => 2,
 603+ $context->msg( 'underline-never' )->text() => 0,
 604+ $context->msg( 'underline-always' )->text() => 1,
 605+ $context->msg( 'underline-default' )->text() => 2,
619606 ),
620607 'label-message' => 'tog-underline',
621608 'section' => 'rendering/advancedrendering',
@@ -622,9 +609,9 @@
623610 }
624611
625612 $stubThresholdValues = array( 50, 100, 500, 1000, 2000, 5000, 10000 );
626 - $stubThresholdOptions = array( wfMsg( 'stub-threshold-disabled' ) => 0 );
 613+ $stubThresholdOptions = array( $context->msg( 'stub-threshold-disabled' )->text() => 0 );
627614 foreach ( $stubThresholdValues as $value ) {
628 - $stubThresholdOptions[wfMsg( 'size-bytes', $value )] = $value;
 615+ $stubThresholdOptions[$context->msg( 'size-bytes', $value )->text()] = $value;
629616 }
630617
631618 $defaultPreferences['stubthreshold'] = array(
@@ -632,14 +619,14 @@
633620 'section' => 'rendering/advancedrendering',
634621 'options' => $stubThresholdOptions,
635622 'size' => 20,
636 - 'label' => wfMsg( 'stub-threshold' ), // Raw HTML message. Yay?
 623+ 'label' => $context->msg( 'stub-threshold' )->text(), // Raw HTML message. Yay?
637624 );
638625
639626 if ( $wgAllowUserCssPrefs ) {
640627 $defaultPreferences['highlightbroken'] = array(
641628 'type' => 'toggle',
642629 'section' => 'rendering/advancedrendering',
643 - 'label' => wfMsg( 'tog-highlightbroken' ), // Raw HTML
 630+ 'label' => $context->msg( 'tog-highlightbroken' )->text(), // Raw HTML
644631 );
645632 $defaultPreferences['showtoc'] = array(
646633 'type' => 'toggle',
@@ -680,9 +667,10 @@
681668
682669 /**
683670 * @param $user User
 671+ * @param $context IContextSource
684672 * @param $defaultPreferences Array
685673 */
686 - static function editingPreferences( $user, &$defaultPreferences ) {
 674+ static function editingPreferences( $user, IContextSource $context, &$defaultPreferences ) {
687675 global $wgUseExternalEditor, $wgAllowUserCssPrefs;
688676
689677 ## Editing #####################################
@@ -707,10 +695,10 @@
708696 'section' => 'editing/advancedediting',
709697 'label-message' => 'editfont-style',
710698 'options' => array(
711 - wfMsg( 'editfont-default' ) => 'default',
712 - wfMsg( 'editfont-monospace' ) => 'monospace',
713 - wfMsg( 'editfont-sansserif' ) => 'sans-serif',
714 - wfMsg( 'editfont-serif' ) => 'serif',
 699+ $context->msg( 'editfont-default' )->text() => 'default',
 700+ $context->msg( 'editfont-monospace' )->text() => 'monospace',
 701+ $context->msg( 'editfont-sansserif' )->text() => 'sans-serif',
 702+ $context->msg( 'editfont-serif' )->text() => 'serif',
715703 )
716704 );
717705 }
@@ -785,10 +773,11 @@
786774
787775 /**
788776 * @param $user User
 777+ * @param $context IContextSource
789778 * @param $defaultPreferences Array
790779 */
791 - static function rcPreferences( $user, &$defaultPreferences ) {
792 - global $wgRCMaxAge, $wgLang;
 780+ static function rcPreferences( $user, IContextSource $context, &$defaultPreferences ) {
 781+ global $wgRCMaxAge, $wgRCShowWatchingUsers;
793782
794783 ## RecentChanges #####################################
795784 $defaultPreferences['rcdays'] = array(
@@ -797,11 +786,8 @@
798787 'section' => 'rc/displayrc',
799788 'min' => 1,
800789 'max' => ceil( $wgRCMaxAge / ( 3600 * 24 ) ),
801 - 'help' => wfMsgExt(
802 - 'recentchangesdays-max',
803 - array( 'parsemag' ),
804 - $wgLang->formatNum( ceil( $wgRCMaxAge / ( 3600 * 24 ) ) )
805 - )
 790+ 'help' => $context->msg( 'recentchangesdays-max' )->numParams(
 791+ ceil( $wgRCMaxAge / ( 3600 * 24 ) ) )->text()
806792 );
807793 $defaultPreferences['rclimit'] = array(
808794 'type' => 'int',
@@ -833,7 +819,6 @@
834820 );
835821 }
836822
837 - global $wgRCShowWatchingUsers;
838823 if ( $wgRCShowWatchingUsers ) {
839824 $defaultPreferences['shownumberswatching'] = array(
840825 'type' => 'toggle',
@@ -845,9 +830,10 @@
846831
847832 /**
848833 * @param $user User
 834+ * @param $context IContextSource
849835 * @param $defaultPreferences
850836 */
851 - static function watchlistPreferences( $user, &$defaultPreferences ) {
 837+ static function watchlistPreferences( $user, IContextSource $context, &$defaultPreferences ) {
852838 global $wgUseRCPatrol, $wgEnableAPI;
853839
854840 ## Watchlist #####################################
@@ -856,7 +842,7 @@
857843 'min' => 0,
858844 'max' => 7,
859845 'section' => 'watchlist/displaywatchlist',
860 - 'help' => wfMsgHtml( 'prefs-watchlist-days-max' ),
 846+ 'help' => $context->msg( 'prefs-watchlist-days-max' )->escaped(),
861847 'label-message' => 'prefs-watchlist-days',
862848 );
863849 $defaultPreferences['wllimit'] = array(
@@ -864,7 +850,7 @@
865851 'min' => 0,
866852 'max' => 1000,
867853 'label-message' => 'prefs-watchlist-edits',
868 - 'help' => wfMsgHtml( 'prefs-watchlist-edits-max' ),
 854+ 'help' => $context->msg( 'prefs-watchlist-edits-max' )->escaped(),
869855 'section' => 'watchlist/displaywatchlist',
870856 );
871857 $defaultPreferences['extendwatchlist'] = array(
@@ -914,7 +900,7 @@
915901 'type' => 'text',
916902 'section' => 'watchlist/advancedwatchlist',
917903 'label-message' => 'prefs-watchlist-token',
918 - 'help' => wfMsgHtml( 'prefs-help-watchlist-token', $hash )
 904+ 'help' => $context->msg( 'prefs-help-watchlist-token', $hash )->escaped()
919905 );
920906 }
921907
@@ -942,10 +928,11 @@
943929
944930 /**
945931 * @param $user User
 932+ * @param $context IContextSource
946933 * @param $defaultPreferences Array
947934 */
948 - static function searchPreferences( $user, &$defaultPreferences ) {
949 - global $wgContLang;
 935+ static function searchPreferences( $user, IContextSource $context, &$defaultPreferences ) {
 936+ global $wgContLang, $wgEnableMWSuggest, $wgVectorUseSimpleSearch;
950937
951938 ## Search #####################################
952939 $defaultPreferences['searchlimit'] = array(
@@ -955,7 +942,6 @@
956943 'min' => 0,
957944 );
958945
959 - global $wgEnableMWSuggest;
960946 if ( $wgEnableMWSuggest ) {
961947 $defaultPreferences['disablesuggest'] = array(
962948 'type' => 'toggle',
@@ -964,7 +950,6 @@
965951 );
966952 }
967953
968 - global $wgVectorUseSimpleSearch;
969954 if ( $wgVectorUseSimpleSearch ) {
970955 $defaultPreferences['vector-simplesearch'] = array(
971956 'type' => 'toggle',
@@ -989,7 +974,7 @@
990975 $displayNs = str_replace( '_', ' ', $name );
991976
992977 if ( !$displayNs ) {
993 - $displayNs = wfMsg( 'blanknamespace' );
 978+ $displayNs = $context->msg( 'blanknamespace' )->text();
994979 }
995980
996981 $displayNs = htmlspecialchars( $displayNs );
@@ -1007,9 +992,12 @@
1008993
1009994 /**
1010995 * @param $user User
 996+ * @param $context IContextSource
1011997 * @param $defaultPreferences Array
1012998 */
1013 - static function miscPreferences( $user, &$defaultPreferences ) {
 999+ static function miscPreferences( $user, IContextSource $context, &$defaultPreferences ) {
 1000+ global $wgContLang;
 1001+
10141002 ## Misc #####################################
10151003 $defaultPreferences['diffonly'] = array(
10161004 'type' => 'toggle',
@@ -1023,8 +1011,6 @@
10241012 );
10251013
10261014 // Stuff from Language::getExtraUserToggles()
1027 - global $wgContLang;
1028 -
10291015 $toggles = $wgContLang->getExtraUserToggles();
10301016
10311017 foreach ( $toggles as $toggle ) {
@@ -1038,14 +1024,15 @@
10391025
10401026 /**
10411027 * @param $user User The User object
 1028+ * @param $context IContextSource
10421029 * @return Array: text/links to display as key; $skinkey as value
10431030 */
1044 - static function generateSkinOptions( $user ) {
1045 - global $wgDefaultSkin, $wgLang, $wgAllowUserCss, $wgAllowUserJs;
 1031+ static function generateSkinOptions( $user, IContextSource $context ) {
 1032+ global $wgDefaultSkin, $wgAllowUserCss, $wgAllowUserJs;
10461033 $ret = array();
10471034
10481035 $mptitle = Title::newMainPage();
1049 - $previewtext = wfMsgHtml( 'skin-preview' );
 1036+ $previewtext = $context->msg( 'skin-preview' )->text();
10501037
10511038 # Only show members of Skin::getSkinNames() rather than
10521039 # $skinNames (skins is all skin names from Language.php)
@@ -1054,7 +1041,7 @@
10551042 # Sort by UI skin name. First though need to update validSkinNames as sometimes
10561043 # the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI).
10571044 foreach ( $validSkinNames as $skinkey => &$skinname ) {
1058 - $msg = wfMessage( "skinname-{$skinkey}" );
 1045+ $msg = $context->msg( "skinname-{$skinkey}" );
10591046 if ( $msg->exists() ) {
10601047 $skinname = htmlspecialchars( $msg->text() );
10611048 }
@@ -1066,7 +1053,7 @@
10671054
10681055 # Mark the default skin
10691056 if ( $skinkey == $wgDefaultSkin ) {
1070 - $linkTools[] = wfMsgHtml( 'default' );
 1057+ $linkTools[] = $context->msg( 'default' )->escaped();
10711058 }
10721059
10731060 # Create preview link
@@ -1076,15 +1063,15 @@
10771064 # Create links to user CSS/JS pages
10781065 if ( $wgAllowUserCss ) {
10791066 $cssPage = Title::makeTitleSafe( NS_USER, $user->getName() . '/' . $skinkey . '.css' );
1080 - $linkTools[] = Linker::link( $cssPage, wfMsgHtml( 'prefs-custom-css' ) );
 1067+ $linkTools[] = Linker::link( $cssPage, $context->msg( 'prefs-custom-css' )->escaped() );
10811068 }
10821069
10831070 if ( $wgAllowUserJs ) {
10841071 $jsPage = Title::makeTitleSafe( NS_USER, $user->getName() . '/' . $skinkey . '.js' );
1085 - $linkTools[] = Linker::link( $jsPage, wfMsgHtml( 'prefs-custom-js' ) );
 1072+ $linkTools[] = Linker::link( $jsPage, $context->msg( 'prefs-custom-js' )->escaped() );
10861073 }
10871074
1088 - $display = $sn . ' ' . wfMsg( 'parentheses', $wgLang->pipeList( $linkTools ) );
 1075+ $display = $sn . ' ' . $context->msg( 'parentheses', $context->getLang()->pipeList( $linkTools ) )->text();
10891076 $ret[$display] = $skinkey;
10901077 }
10911078
@@ -1092,11 +1079,11 @@
10931080 }
10941081
10951082 /**
 1083+ * @param $context IContextSource
10961084 * @return array
10971085 */
1098 - static function getDateOptions() {
1099 - global $wgLang;
1100 - $dateopts = $wgLang->getDatePreferences();
 1086+ static function getDateOptions( IContextSource $context ) {
 1087+ $dateopts = $context->getLang()->getDatePreferences();
11011088
11021089 $ret = array();
11031090
@@ -1115,9 +1102,9 @@
11161103 $epoch = wfTimestampNow();
11171104 foreach ( $dateopts as $key ) {
11181105 if ( $key == 'default' ) {
1119 - $formatted = wfMsgHtml( 'datedefault' );
 1106+ $formatted = $context->msg( 'datedefault' )->escaped();
11201107 } else {
1121 - $formatted = htmlspecialchars( $wgLang->timeanddate( $epoch, false, $key ) );
 1108+ $formatted = htmlspecialchars( $context->getLang()->timeanddate( $epoch, false, $key ) );
11221109 }
11231110 $ret[$formatted] = $key;
11241111 }
@@ -1126,15 +1113,17 @@
11271114 }
11281115
11291116 /**
 1117+ * @param $context IContextSource
11301118 * @return array
11311119 */
1132 - static function getImageSizes() {
 1120+ static function getImageSizes( IContextSource $context ) {
11331121 global $wgImageLimits;
11341122
11351123 $ret = array();
 1124+ $pixels = $context->msg( 'unit-pixel' )->text();
11361125
11371126 foreach ( $wgImageLimits as $index => $limits ) {
1138 - $display = "{$limits[0]}×{$limits[1]}" . wfMsg( 'unit-pixel' );
 1127+ $display = "{$limits[0]}×{$limits[1]}" . $pixels;
11391128 $ret[$display] = $index;
11401129 }
11411130
@@ -1142,15 +1131,17 @@
11431132 }
11441133
11451134 /**
 1135+ * @param $context IContextSource
11461136 * @return array
11471137 */
1148 - static function getThumbSizes() {
 1138+ static function getThumbSizes( IContextSource $context ) {
11491139 global $wgThumbLimits;
11501140
11511141 $ret = array();
 1142+ $pixels = $context->msg( 'unit-pixel' )->text();
11521143
11531144 foreach ( $wgThumbLimits as $index => $size ) {
1154 - $display = $size . wfMsg( 'unit-pixel' );
 1145+ $display = $size . $pixels;
11551146 $ret[$display] = $index;
11561147 }
11571148
@@ -1163,13 +1154,10 @@
11641155 * @return bool|string
11651156 */
11661157 static function validateSignature( $signature, $alldata ) {
1167 - global $wgParser, $wgMaxSigChars, $wgLang;
 1158+ global $wgParser, $wgMaxSigChars;
11681159 if ( mb_strlen( $signature ) > $wgMaxSigChars ) {
11691160 return Xml::element( 'span', array( 'class' => 'error' ),
1170 - wfMsgExt( 'badsiglength', 'parsemag',
1171 - $wgLang->formatNum( $wgMaxSigChars )
1172 - )
1173 - );
 1161+ wfMessage( 'badsiglength' )->numParams( $wgMaxSigChars )->text() );
11741162 } elseif ( isset( $alldata['fancysig'] ) &&
11751163 $alldata['fancysig'] &&
11761164 false === $wgParser->validateSig( $signature ) ) {
@@ -1217,17 +1205,22 @@
12181206 * @param $user User
12191207 * @param $context IContextSource
12201208 * @param $formClass string
 1209+ * @param $remove Array: array of items to remove
12211210 * @return HtmlForm
12221211 */
1223 - static function getFormObject( $user, IContextSource $context, $formClass = 'PreferencesForm' ) {
1224 - $formDescriptor = Preferences::getPreferences( $user );
 1212+ static function getFormObject( $user, IContextSource $context, $formClass = 'PreferencesForm', array $remove = array() ) {
 1213+ $formDescriptor = Preferences::getPreferences( $user, $context );
 1214+ if ( count( $remove ) ) {
 1215+ $removeKeys = array_flip( $remove );
 1216+ $formDescriptor = array_diff_key( $formDescriptor, $removeKeys );
 1217+ }
12251218 $htmlForm = new $formClass( $formDescriptor, $context, 'prefs' );
12261219
 1220+ $htmlForm->setModifiedUser( $user );
12271221 $htmlForm->setId( 'mw-prefs-form' );
12281222 $htmlForm->setSubmitText( wfMsg( 'saveprefs' ) );
12291223 # Used message keys: 'accesskey-preferences-save', 'tooltip-preferences-save'
12301224 $htmlForm->setSubmitTooltip( 'preferences-save' );
1231 - $htmlForm->setTitle( SpecialPage::getTitleFor( 'Preferences' ) );
12321225 $htmlForm->setSubmitID( 'prefsubmit' );
12331226 $htmlForm->setSubmitCallback( array( 'Preferences', 'tryFormSubmit' ) );
12341227
@@ -1237,20 +1230,20 @@
12381231 /**
12391232 * @return array
12401233 */
1241 - static function getTimezoneOptions() {
 1234+ static function getTimezoneOptions( IContextSource $context ) {
12421235 $opt = array();
12431236
12441237 global $wgLocalTZoffset, $wgLocaltimezone;
12451238 // Check that $wgLocalTZoffset is the same as $wgLocaltimezone
12461239 if ( $wgLocalTZoffset == date( 'Z' ) / 60 ) {
1247 - $server_tz_msg = wfMsg( 'timezoneuseserverdefault', $wgLocaltimezone );
 1240+ $server_tz_msg = $context->msg( 'timezoneuseserverdefault', $wgLocaltimezone )->text();
12481241 } else {
12491242 $tzstring = sprintf( '%+03d:%02d', floor( $wgLocalTZoffset / 60 ), abs( $wgLocalTZoffset ) % 60 );
1250 - $server_tz_msg = wfMsg( 'timezoneuseserverdefault', $tzstring );
 1243+ $server_tz_msg = $context->msg( 'timezoneuseserverdefault', $tzstring )->text();
12511244 }
12521245 $opt[$server_tz_msg] = "System|$wgLocalTZoffset";
1253 - $opt[wfMsg( 'timezoneuseoffset' )] = 'other';
1254 - $opt[wfMsg( 'guesstimezone' )] = 'guess';
 1246+ $opt[$context->msg( 'timezoneuseoffset' )->text()] = 'other';
 1247+ $opt[$context->msg( 'guesstimezone' )->text()] = 'guess';
12551248
12561249 if ( function_exists( 'timezone_identifiers_list' ) ) {
12571250 # Read timezone list
@@ -1258,16 +1251,16 @@
12591252 sort( $tzs );
12601253
12611254 $tzRegions = array();
1262 - $tzRegions['Africa'] = wfMsg( 'timezoneregion-africa' );
1263 - $tzRegions['America'] = wfMsg( 'timezoneregion-america' );
1264 - $tzRegions['Antarctica'] = wfMsg( 'timezoneregion-antarctica' );
1265 - $tzRegions['Arctic'] = wfMsg( 'timezoneregion-arctic' );
1266 - $tzRegions['Asia'] = wfMsg( 'timezoneregion-asia' );
1267 - $tzRegions['Atlantic'] = wfMsg( 'timezoneregion-atlantic' );
1268 - $tzRegions['Australia'] = wfMsg( 'timezoneregion-australia' );
1269 - $tzRegions['Europe'] = wfMsg( 'timezoneregion-europe' );
1270 - $tzRegions['Indian'] = wfMsg( 'timezoneregion-indian' );
1271 - $tzRegions['Pacific'] = wfMsg( 'timezoneregion-pacific' );
 1255+ $tzRegions['Africa'] = $context->msg( 'timezoneregion-africa' )->text();
 1256+ $tzRegions['America'] = $context->msg( 'timezoneregion-america' )->text();
 1257+ $tzRegions['Antarctica'] = $context->msg( 'timezoneregion-antarctica' )->text();
 1258+ $tzRegions['Arctic'] = $context->msg( 'timezoneregion-arctic' )->text();
 1259+ $tzRegions['Asia'] = $context->msg( 'timezoneregion-asia' )->text();
 1260+ $tzRegions['Atlantic'] = $context->msg( 'timezoneregion-atlantic' )->text();
 1261+ $tzRegions['Australia'] = $context->msg( 'timezoneregion-australia' )->text();
 1262+ $tzRegions['Europe'] = $context->msg( 'timezoneregion-europe' )->text();
 1263+ $tzRegions['Indian'] = $context->msg( 'timezoneregion-indian' )->text();
 1264+ $tzRegions['Pacific'] = $context->msg( 'timezoneregion-pacific' )->text();
12721265 asort( $tzRegions );
12731266
12741267 $prefill = array_fill_keys( array_values( $tzRegions ), array() );
@@ -1340,12 +1333,14 @@
13411334
13421335 /**
13431336 * @param $formData
 1337+ * @param $form HTMLForm
13441338 * @param $entryPoint string
13451339 * @return bool|Status|string
13461340 */
1347 - static function tryFormSubmit( $formData, $entryPoint = 'internal' ) {
1348 - global $wgUser;
 1341+ static function tryFormSubmit( $formData, $form, $entryPoint = 'internal' ) {
 1342+ global $wgHiddenPrefs;
13491343
 1344+ $user = $form->getModifiedUser();
13501345 $result = true;
13511346
13521347 // Filter input
@@ -1363,10 +1358,9 @@
13641359 );
13651360
13661361 // Fortunately, the realname field is MUCH simpler
1367 - global $wgHiddenPrefs;
13681362 if ( !in_array( 'realname', $wgHiddenPrefs ) ) {
13691363 $realName = $formData['realname'];
1370 - $wgUser->setRealName( $realName );
 1364+ $user->setRealName( $realName );
13711365 }
13721366
13731367 foreach ( $saveBlacklist as $b ) {
@@ -1380,18 +1374,18 @@
13811375 foreach( $wgHiddenPrefs as $pref ){
13821376 # If the user has not set a non-default value here, the default will be returned
13831377 # and subsequently discarded
1384 - $formData[$pref] = $wgUser->getOption( $pref, null, true );
 1378+ $formData[$pref] = $user->getOption( $pref, null, true );
13851379 }
13861380
13871381 // Keeps old preferences from interfering due to back-compat
13881382 // code, etc.
1389 - $wgUser->resetOptions();
 1383+ $user->resetOptions();
13901384
13911385 foreach ( $formData as $key => $value ) {
1392 - $wgUser->setOption( $key, $value );
 1386+ $user->setOption( $key, $value );
13931387 }
13941388
1395 - $wgUser->saveSettings();
 1389+ $user->saveSettings();
13961390
13971391 return $result;
13981392 }
@@ -1400,22 +1394,21 @@
14011395 * @param $formData
14021396 * @return Status
14031397 */
1404 - public static function tryUISubmit( $formData ) {
1405 - $res = self::tryFormSubmit( $formData, 'ui' );
 1398+ public static function tryUISubmit( $formData, $form ) {
 1399+ $res = self::tryFormSubmit( $formData, $form, 'ui' );
14061400
14071401 if ( $res ) {
1408 - $urlOptions = array( 'success' );
 1402+ $urlOptions = array( 'success' => 1 );
14091403
14101404 if ( $res === 'eauth' ) {
1411 - $urlOptions[] = 'eauth';
 1405+ $urlOptions['eauth'] = 1;
14121406 }
14131407
1414 - $queryString = implode( '&', $urlOptions );
 1408+ $urlOptions += $form->getExtraSuccessRedirectParameters();
14151409
1416 - $url = SpecialPage::getTitleFor( 'Preferences' )->getFullURL( $queryString );
 1410+ $url = $form->getTitle()->getFullURL( $urlOptions );
14171411
1418 - global $wgOut;
1419 - $wgOut->redirect( $url );
 1412+ $form->getContext()->getOutput()->redirect( $url );
14201413 }
14211414
14221415 return Status::newGood();
@@ -1483,8 +1476,31 @@
14841477
14851478 /** Some tweaks to allow js prefs to work */
14861479 class PreferencesForm extends HTMLForm {
 1480+ private $modifiedUser;
14871481
 1482+ public function setModifiedUser( $user ) {
 1483+ $this->modifiedUser = $user;
 1484+ }
 1485+
 1486+ public function getModifiedUser() {
 1487+ if ( $this->modifiedUser === null ) {
 1488+ return $this->getUser();
 1489+ } else {
 1490+ return $this->modifiedUser;
 1491+ }
 1492+ }
 1493+
14881494 /**
 1495+ * Get extra parameters for the query string when redirecting after
 1496+ * successful save.
 1497+ *
 1498+ * @return array()
 1499+ */
 1500+ public function getExtraSuccessRedirectParameters() {
 1501+ return array();
 1502+ }
 1503+
 1504+ /**
14891505 * @param $html string
14901506 * @return String
14911507 */

Follow-up revisions

RevisionCommit summaryAuthorDate
r99347Follow-up r99346: updates to EditUser extension to make it compatible, also g...ialex11:46, 9 October 2011

Status & tagging log