API: Set HTMLForm when validating field in ApiOptions
authorBrad Jorsch <bjorsch@wikimedia.org>
Mon, 20 Apr 2015 19:57:42 +0000 (15:57 -0400)
committerBrad Jorsch <bjorsch@wikimedia.org>
Mon, 20 Apr 2015 19:57:42 +0000 (15:57 -0400)
Bug: T96583
Change-Id: I09507990827581b587c14b0f7283cdf0dc21436a

includes/api/ApiOptions.php

index 8ef0629..436f22a 100644 (file)
@@ -75,11 +75,17 @@ class ApiOptions extends ApiBase {
                $prefs = Preferences::getPreferences( $user, $this->getContext() );
                $prefsKinds = $user->getOptionKinds( $this->getContext(), $changes );
 
+               $htmlForm = null;
                foreach ( $changes as $key => $value ) {
                        switch ( $prefsKinds[$key] ) {
                                case 'registered':
                                        // Regular option.
+                                       if ( $htmlForm === null ) {
+                                               // We need a dummy HTMLForm for the validate callback...
+                                               $htmlForm = new HTMLForm( array(), $this );
+                                       }
                                        $field = HTMLForm::loadInputFromParameters( $key, $prefs[$key] );
+                                       $field->mParent = $htmlForm;
                                        $validation = $field->validate( $value, $user->getOptions() );
                                        break;
                                case 'registered-multiselect':