* @file
*/
+use Wikimedia\ObjectFactory;
+
/**
* Object handling generic submission, CSRF protection, layout and
* other logic for UI forms. in a reusable manner.
class HTMLForm extends ContextSource {
// A mapping of 'type' inputs onto standard HTMLFormField subclasses
public static $typeMappings = [
- 'api' => 'HTMLApiField',
- 'text' => 'HTMLTextField',
- 'textwithbutton' => 'HTMLTextFieldWithButton',
- 'textarea' => 'HTMLTextAreaField',
- 'select' => 'HTMLSelectField',
- 'combobox' => 'HTMLComboboxField',
- 'radio' => 'HTMLRadioField',
- 'multiselect' => 'HTMLMultiSelectField',
- 'limitselect' => 'HTMLSelectLimitField',
- 'check' => 'HTMLCheckField',
- 'toggle' => 'HTMLCheckField',
- 'int' => 'HTMLIntField',
- 'float' => 'HTMLFloatField',
- 'info' => 'HTMLInfoField',
- 'selectorother' => 'HTMLSelectOrOtherField',
- 'selectandother' => 'HTMLSelectAndOtherField',
- 'namespaceselect' => 'HTMLSelectNamespace',
- 'namespaceselectwithbutton' => 'HTMLSelectNamespaceWithButton',
- 'tagfilter' => 'HTMLTagFilter',
- 'sizefilter' => 'HTMLSizeFilterField',
- 'submit' => 'HTMLSubmitField',
- 'hidden' => 'HTMLHiddenField',
- 'edittools' => 'HTMLEditTools',
- 'checkmatrix' => 'HTMLCheckMatrix',
- 'cloner' => 'HTMLFormFieldCloner',
- 'autocompleteselect' => 'HTMLAutoCompleteSelectField',
- 'date' => 'HTMLDateTimeField',
- 'time' => 'HTMLDateTimeField',
- 'datetime' => 'HTMLDateTimeField',
+ 'api' => HTMLApiField::class,
+ 'text' => HTMLTextField::class,
+ 'textwithbutton' => HTMLTextFieldWithButton::class,
+ 'textarea' => HTMLTextAreaField::class,
+ 'select' => HTMLSelectField::class,
+ 'combobox' => HTMLComboboxField::class,
+ 'radio' => HTMLRadioField::class,
+ 'multiselect' => HTMLMultiSelectField::class,
+ 'limitselect' => HTMLSelectLimitField::class,
+ 'check' => HTMLCheckField::class,
+ 'toggle' => HTMLCheckField::class,
+ 'int' => HTMLIntField::class,
+ 'float' => HTMLFloatField::class,
+ 'info' => HTMLInfoField::class,
+ 'selectorother' => HTMLSelectOrOtherField::class,
+ 'selectandother' => HTMLSelectAndOtherField::class,
+ 'namespaceselect' => HTMLSelectNamespace::class,
+ 'namespaceselectwithbutton' => HTMLSelectNamespaceWithButton::class,
+ 'tagfilter' => HTMLTagFilter::class,
+ 'sizefilter' => HTMLSizeFilterField::class,
+ 'submit' => HTMLSubmitField::class,
+ 'hidden' => HTMLHiddenField::class,
+ 'edittools' => HTMLEditTools::class,
+ 'checkmatrix' => HTMLCheckMatrix::class,
+ 'cloner' => HTMLFormFieldCloner::class,
+ 'autocompleteselect' => HTMLAutoCompleteSelectField::class,
+ 'date' => HTMLDateTimeField::class,
+ 'time' => HTMLDateTimeField::class,
+ 'datetime' => HTMLDateTimeField::class,
// HTMLTextField will output the correct type="" attribute automagically.
// There are about four zillion other HTML5 input types, like range, but
// we don't use those at the moment, so no point in adding all of them.
- 'email' => 'HTMLTextField',
- 'password' => 'HTMLTextField',
- 'url' => 'HTMLTextField',
- 'title' => 'HTMLTitleTextField',
- 'user' => 'HTMLUserTextField',
- 'usersmultiselect' => 'HTMLUsersMultiselectField',
+ 'email' => HTMLTextField::class,
+ 'password' => HTMLTextField::class,
+ 'url' => HTMLTextField::class,
+ 'title' => HTMLTitleTextField::class,
+ 'user' => HTMLUserTextField::class,
+ 'usersmultiselect' => HTMLUsersMultiselectField::class,
];
public $mFieldData;
protected $mAction = false;
/**
- * Form attribute autocomplete. false does not set the attribute
+ * Form attribute autocomplete. A typical value is "off". null does not set the attribute
* @since 1.27
- * @var bool|string
+ * @var string|null
*/
- protected $mAutocomplete = false;
+ protected $mAutocomplete = null;
protected $mUseMultipart = false;
protected $mHiddenFields = [];
if ( $this->mId ) {
$attribs['id'] = $this->mId;
}
- if ( $this->mAutocomplete ) {
+ if ( is_string( $this->mAutocomplete ) ) {
$attribs['autocomplete'] = $this->mAutocomplete;
}
if ( $this->mName ) {
}
/**
- * Set the value for the autocomplete attribute of the form.
- * When set to false (which is the default state), the attribute get not set.
+ * Set the value for the autocomplete attribute of the form. A typical value is "off".
+ * When set to null (which is the default state), the attribute get not set.
*
* @since 1.27
*
- * @param string|bool $autocomplete
+ * @param string|null $autocomplete
*
* @return HTMLForm $this for chaining calls
*/