Samwilson has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/374451 )
Change subject: Make it possible to inject a different Preferences object ...................................................................... Make it possible to inject a different Preferences object This makes some changes relating to subclassing Preferences and PreferencesForm. Add a new hook 'PreferencesFactory' that is run in the Preferences::factory() method, to allow extensions to change the returned Preferences object however they want. See docs/hooks.txt for details. Fix the constructor of SpecialPreferences to match that of its parent, so subclasses can do the same. Fix the help link of SpecialPreferences to not be hard-coded to 'Help:Preferences' but instead use the title of the special page. Move the setting of the submit callback for the PreferencesForm into SpecialPreferences::getFormObject() so that implementors of this method can provide their own callback. Bug: T173476 Change-Id: I3f7e9067c2faa915c2b05a2ae01312c3f2fee2ea --- M includes/Preferences.php M includes/specials/SpecialPreferences.php 2 files changed, 28 insertions(+), 6 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/51/374451/1 diff --git a/includes/Preferences.php b/includes/Preferences.php index c64e8a8..7b8d526 100644 --- a/includes/Preferences.php +++ b/includes/Preferences.php @@ -67,6 +67,18 @@ ]; /** + * Get a new Preferences object. + * @param User $user The user who owns the preferences. + * @param IContextSource $contextSource The context in which the preferences are being used. + * @return static + */ + public static function factory( User $user, IContextSource $contextSource ) { + $preferences = new static(); + Hooks::run( 'PreferencesFactory', [ $user, $contextSource, &$preferences ] ); + return $preferences; + } + + /** * @return array */ static function getSaveBlacklist() { @@ -1332,7 +1344,7 @@ $formClass = 'PreferencesForm', array $remove = [] ) { - $formDescriptor = self::getPreferences( $user, $context ); + $formDescriptor = static::getPreferences( $user, $context ); if ( count( $remove ) ) { $removeKeys = array_flip( $remove ); $formDescriptor = array_diff_key( $formDescriptor, $removeKeys ); diff --git a/includes/specials/SpecialPreferences.php b/includes/specials/SpecialPreferences.php index ba5a57e..233615b 100644 --- a/includes/specials/SpecialPreferences.php +++ b/includes/specials/SpecialPreferences.php @@ -27,8 +27,16 @@ * @ingroup SpecialPage */ class SpecialPreferences extends SpecialPage { - function __construct() { - parent::__construct( 'Preferences' ); + + public function __construct( + $name = 'Preferences', + $restriction = '', + $listed = true, + $function = false, + $file = '', + $includable = false + ) { + parent::__construct( $name, $restriction, $listed, $function, $file, $includable ); } public function doesWrites() { @@ -72,7 +80,7 @@ ); } - $this->addHelpLink( 'Help:Preferences' ); + $this->addHelpLink( 'Help:' . $this->getPageTitle()->getText() ); // Load the user from the master to reduce CAS errors on double post (T95839) if ( $this->getRequest()->wasPosted() ) { @@ -82,7 +90,6 @@ } $htmlForm = $this->getFormObject( $user, $this->getContext() ); - $htmlForm->setSubmitCallback( [ 'Preferences', 'tryUISubmit' ] ); $sectionTitles = $htmlForm->getPreferenceSections(); $prefTabs = ''; @@ -124,7 +131,10 @@ * @return PreferencesForm|HtmlForm */ protected function getFormObject( $user, IContextSource $context ) { - return Preferences::getFormObject( $user, $context ); + $preferences = Preferences::factory( $user, $context ); + $form = $preferences::getFormObject( $user, $context ); + $form->setSubmitCallback( [ $preferences, 'tryUISubmit' ] ); + return $form; } private function showResetForm() { -- To view, visit https://gerrit.wikimedia.org/r/374451 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I3f7e9067c2faa915c2b05a2ae01312c3f2fee2ea Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Samwilson <s...@samwilson.id.au> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits