+ /**
+ * Load the user from the master to reduce CAS errors on double post (T95839)
+ *
+ * @return null|User
+ */
+ protected function getUserForUpdates() {
+ if ( !$this->userForUpdates ) {
+ $this->userForUpdates = $this->getUser()->getInstanceForUpdate();
+ }
+
+ return $this->userForUpdates;
+ }
+
+ /**
+ * Returns preferences form descriptor
+ * @return mixed[][]
+ */
+ protected function getPreferences() {
+ $preferencesFactory = MediaWikiServices::getInstance()->getPreferencesFactory();
+ return $preferencesFactory->getFormDescriptor( $this->getUserForUpdates(),
+ $this->getContext() );
+ }
+
+ /**
+ * @param string[] $kinds One or more types returned by User::listOptionKinds() or 'all'
+ */
+ protected function resetPreferences( array $kinds ) {
+ $this->getUserForUpdates()->resetOptions( $kinds, $this->getContext() );
+ }
+
+ /**
+ * Sets one user preference to be applied by commitChanges()
+ *
+ * @param string $preference
+ * @param mixed $value
+ */
+ protected function setPreference( $preference, $value ) {
+ $this->getUserForUpdates()->setOption( $preference, $value );
+ }
+
+ /**
+ * Applies changes to user preferences
+ */
+ protected function commitChanges() {
+ $this->getUserForUpdates()->saveSettings();
+ }
+