Revert "preferences: Use a faster and simpler form descriptor when validating"

This reverts commit 07b4daf85d.

Due to the new method being used in both the API, and in the
loadPreferenceValues method (which is used by the main pref UI), this
change is not easy to reason about and is much wider in impact than
I had thought. More research and understanding is needed.

Bug: T302643
Change-Id: Ic420bc16ac5de8ce90343926e9c73815f3ff7479
This commit is contained in:
Krinkle 2022-03-01 19:33:30 +00:00
parent 07b4daf85d
commit 8763d8e911
2 changed files with 2 additions and 42 deletions

View file

@ -22,7 +22,6 @@
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MediaWikiServices;
use MediaWiki\Preferences\DefaultPreferencesFactory;
use MediaWiki\Preferences\PreferencesFactory;
use MediaWiki\User\UserOptionsManager;
@ -115,7 +114,7 @@ class ApiOptions extends ApiBase {
$prefs = $this->getPreferences();
$prefsKinds = $this->userOptionsManager->getOptionKinds( $user, $this->getContext(), $changes );
$htmlForm = new HTMLForm( DefaultPreferencesFactory::simplifyFormDescriptor( $prefs ), $this );
$htmlForm = new HTMLForm( $prefs, $this );
foreach ( $changes as $key => $value ) {
switch ( $prefsKinds[$key] ) {
case 'registered':

View file

@ -253,45 +253,6 @@ class DefaultPreferencesFactory implements PreferencesFactory {
return $preferences;
}
/**
* Simplify form descriptor for vaidation or something similar.
*
* @param array $descriptor HTML form descriptor.
* @return array
*/
public static function simplifyFormDescriptor( array $descriptor ) {
foreach ( $descriptor as $name => &$params ) {
// Info fields are useless and can use complicated closure to provide
// text, skip all of them.
if ( ( isset( $params['type'] ) && $params['type'] === 'info' ) ||
( isset( $params['class'] ) && $params['class'] === \HTMLInfoField::class )
) {
unset( $descriptor[$name] );
continue;
}
// Message parsing is the heaviest load when constructing the field,
// but we just want to validate data.
foreach ( $params as $key => $value ) {
switch ( $key ) {
// Special case, should be kept.
case 'options-message':
break;
// Special case, should be transfered.
case 'options-messages':
unset( $params[$key] );
$params['options'] = $value;
break;
default:
if ( preg_match( '/-messages?$/', $key ) ) {
// Unwanted.
unset( $params[$key] );
}
}
}
}
return $descriptor;
}
/**
* Loads existing values for a given array of preferences
* @throws MWException
@ -307,7 +268,7 @@ class DefaultPreferencesFactory implements PreferencesFactory {
}
// For validation.
$form = new HTMLForm( self::simplifyFormDescriptor( $defaultPreferences ), $context );
$form = new HTMLForm( $defaultPreferences, $context );
$disable = !$user->isAllowed( 'editmyoptions' );