X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fhtmlform%2FHTMLForm.php;h=f5be83fc1af055e787d6763cc296cb92c32f1051;hb=04d1aa3033f40a38d721f7f0e88b5bac440d2869;hp=aeeb934f930cecb4422390a04f142a321ba76602;hpb=3353ced6cd3148de1549568ee9633a913fd5faab;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/htmlform/HTMLForm.php b/includes/htmlform/HTMLForm.php index aeeb934f93..a7cef3cbe6 100644 --- a/includes/htmlform/HTMLForm.php +++ b/includes/htmlform/HTMLForm.php @@ -21,8 +21,6 @@ * @file */ -use Wikimedia\ObjectFactory; - /** * Object handling generic submission, CSRF protection, layout and * other logic for UI forms. in a reusable manner. @@ -182,11 +180,11 @@ class HTMLForm extends ContextSource { protected $mMessagePrefix; /** @var HTMLFormField[] */ - protected $mFlatFields; - - protected $mFieldTree; + protected $mFlatFields = []; + protected $mFieldTree = []; protected $mShowReset = false; protected $mShowSubmit = true; + /** @var string[] */ protected $mSubmitFlags = [ 'primary', 'progressive' ]; protected $mShowCancel = false; protected $mCancelTarget; @@ -222,15 +220,15 @@ class HTMLForm extends ContextSource { protected $mAction = false; /** - * Whether the HTML form can be collapsed - * @since 1.33 + * Whether the form can be collapsed + * @since 1.34 * @var bool */ protected $mCollapsible = false; /** - * Whether the HTML form IS collapsed by default - * @since 1.33 + * Whether the form is collapsed by default + * @since 1.34 * @var bool */ protected $mCollapsed = false; @@ -304,12 +302,11 @@ class HTMLForm extends ContextSource { switch ( $displayFormat ) { case 'vform': - return ObjectFactory::constructClassInstance( VFormHTMLForm::class, $arguments ); + return new VFormHTMLForm( ...$arguments ); case 'ooui': - return ObjectFactory::constructClassInstance( OOUIHTMLForm::class, $arguments ); + return new OOUIHTMLForm( ...$arguments ); default: - /** @var HTMLForm $form */ - $form = ObjectFactory::constructClassInstance( self::class, $arguments ); + $form = new self( ...$arguments ); $form->setDisplayFormat( $displayFormat ); return $form; } @@ -318,7 +315,8 @@ class HTMLForm extends ContextSource { /** * Build a new HTMLForm from an array of field attributes * - * @param array $descriptor Array of Field constructs, as described above + * @param array $descriptor Array of Field constructs, as described + * in the class documentation * @param IContextSource|null $context Available since 1.18, will become compulsory in 1.18. * Obviates the need to call $form->setTitle() * @param string $messagePrefix A prefix to go in front of default messages @@ -346,11 +344,23 @@ class HTMLForm extends ContextSource { $this->displayFormat = 'div'; } - // Expand out into a tree. + $this->addFields( $descriptor ); + } + + /** + * Add fields to the form + * + * @since 1.34 + * + * @param array $descriptor Array of Field constructs, as described + * in the class documentation + * @return HTMLForm + */ + public function addFields( $descriptor ) { $loadedDescriptor = []; - $this->mFlatFields = []; foreach ( $descriptor as $fieldname => $info ) { + $section = $info['section'] ?? ''; if ( isset( $info['type'] ) && $info['type'] === 'file' ) { @@ -374,7 +384,9 @@ class HTMLForm extends ContextSource { $this->mFlatFields[$fieldname] = $field; } - $this->mFieldTree = $loadedDescriptor; + $this->mFieldTree = array_merge( $this->mFieldTree, $loadedDescriptor ); + + return $this; } /** @@ -457,7 +469,8 @@ class HTMLForm extends ContextSource { * @since 1.23 * * @param string $fieldname Name of the field - * @param array &$descriptor Input Descriptor, as described above + * @param array &$descriptor Input Descriptor, as described + * in the class documentation * * @throws MWException * @return string Name of a HTMLFormField subclass @@ -484,7 +497,8 @@ class HTMLForm extends ContextSource { * Initialise a new Object for the field * * @param string $fieldname Name of the field - * @param array $descriptor Input Descriptor, as described above + * @param array $descriptor Input Descriptor, as described + * in the class documentation * @param HTMLForm|null $parent Parent instance of HTMLForm * * @throws MWException @@ -1062,14 +1076,15 @@ class HTMLForm extends ContextSource { } /** - * Make the form collapsible - * @since 1.33 - * @param bool $collapsed whether it should be by default - * @return HTMLForm $this for chaining calls (since 1.20) + * Enable collapsible mode, and set whether the form is collapsed by default. + * + * @since 1.34 + * @param bool $collapsedByDefault Whether the form is collapsed by default (optional). + * @return HTMLForm $this for chaining calls */ - public function setCollapsible( $collapsed = false ) { + public function setCollapsibleOptions( $collapsedByDefault = false ) { $this->mCollapsible = true; - $this->mCollapsed = $collapsed; + $this->mCollapsed = $collapsedByDefault; return $this; } @@ -1276,20 +1291,6 @@ class HTMLForm extends ContextSource { return $this->displaySection( $this->mFieldTree, $this->mTableId ); } - /** - * Format and display an error message stack. - * - * @param string|array|Status $errors - * - * @deprecated since 1.28, use getErrorsOrWarnings() instead - * - * @return string - */ - public function getErrors( $errors ) { - wfDeprecated( __METHOD__ ); - return $this->getErrorsOrWarnings( $errors, 'error' ); - } - /** * Returns a formatted list of errors or warnings from the given elements. * @@ -1372,21 +1373,6 @@ class HTMLForm extends ContextSource { return $this; } - /** - * Identify that the submit button in the form has a progressive action - * @since 1.25 - * @deprecated since 1.32, No need to call. Submit button already - * has a progressive action form. - * - * @return HTMLForm $this for chaining calls (since 1.28) - */ - public function setSubmitProgressive() { - wfDeprecated( __METHOD__, '1.32' ); - $this->mSubmitFlags = [ 'progressive', 'primary' ]; - - return $this; - } - /** * Set the text for the submit button to a message * @since 1.19