MediaWiki  1.27.4
HTMLFormField Class Reference

The parent class to generate form fields. More...

Inheritance diagram for HTMLFormField:
Collaboration diagram for HTMLFormField:

Public Member Functions

 __construct ($params)
 Initialise the object. More...
 
 cancelSubmit ($value, $alldata)
 Override this function if the control can somehow trigger a form submission that shouldn't actually submit the HTMLForm. More...
 
 canDisplayErrors ()
 True if this field type is able to display errors; false if validation errors need to be displayed in the main HTMLForm error area. More...
 
 filter ($value, $alldata)
 
 getAttributes (array $list)
 Returns the given attributes from the parameters. More...
 
 getDefault ()
 
 getDiv ($value)
 Get the complete div for the input, including help text, labels, and whatever. More...
 
 getErrorsAndErrorClass ($value)
 Determine form errors to display and their classes. More...
 
 getErrorsRaw ($value)
 Determine form errors to display, returning them in an array. More...
 
 getHelpText ()
 Determine the help text to display. More...
 
 getHelpTextHtmlDiv ($helptext)
 Generate help text HTML in div format. More...
 
 getHelpTextHtmlRaw ($helptext)
 Generate help text HTML formatted for raw output. More...
 
 getHelpTextHtmlTable ($helptext)
 Generate help text HTML in table format. More...
 
 getInline ($value)
 Get the complete field as an inline element. More...
 
 getInputHTML ($value)
 This function must be implemented to return the HTML to generate the input object itself. More...
 
 getInputOOUI ($value)
 Same as getInputHTML, but returns an OOUI object. More...
 
 getLabel ()
 
 getLabelHtml ($cellAttributes=[])
 
 getOOUI ($value)
 Get the OOUI version of the div. More...
 
 getOptions ()
 Fetch the array of options from the field's parameters. More...
 
 getOptionsOOUI ()
 Get options and make them into arrays suitable for OOUI. More...
 
 getRaw ($value)
 Get the complete raw fields for the input, including help text, labels, and whatever. More...
 
 getTableRow ($value)
 Get the complete table row for the input, including help text, labels, and whatever. More...
 
 getTooltipAndAccessKey ()
 Returns the attributes required for the tooltip and accesskey. More...
 
 getVForm ($value)
 Get the complete field for the input, including help text, labels, and whatever. More...
 
 hasVisibleOutput ()
 If this field has a user-visible output or not. More...
 
 isHidden ($alldata)
 Test whether this field is supposed to be hidden, based on the values of the other form fields. More...
 
 loadDataFromRequest ($request)
 Get the value that this input has been set to from a posted form, or the input's default value if it has not been set. More...
 
 msg ()
 Get a translated interface message. More...
 
 setShowEmptyLabel ($show)
 Tell the field whether to generate a separate label element if its label is blank. More...
 
 skipLoadData ($request)
 Skip this field when collecting data. More...
 
 validate ($value, $alldata)
 Override this function to add specific validation checks on the field input. More...
 

Static Public Member Functions

static flattenOptions ($options)
 flatten an array of options to a single array, for instance, a set of "<options>" inside "<optgroups>". More...
 
static forceToStringRecursive ($array)
 Recursively forces values in an array to strings, because issues arise with integer 0 as a value. More...
 

Public Attributes

 $mParams
 
HTMLForm null $mParent
 

Protected Member Functions

 getFieldLayoutOOUI ($inputField, $config)
 Get a FieldLayout (or subclass thereof) to wrap this field in when using OOUI output. More...
 
 getLabelAlignOOUI ()
 Get label alignment when generating field for OOUI. More...
 
 getMessage ($value)
 Turns a *-message parameter (which could be a MessageSpecifier, or a message name, or a name + parameters array) into a Message. More...
 
 getNearestFieldByName ($alldata, $name)
 Fetch a field value from $alldata for the closest field matching a given name. More...
 
 isHiddenRecurse (array $alldata, array $params)
 Helper function for isHidden to handle recursive data structures. More...
 
 needsLabel ()
 Should this field have a label, or is there no input element with the appropriate id for the label to point to? More...
 

Static Protected Member Functions

static formatErrors ($errors)
 Formats one or more errors as accepted by field validation-callback. More...
 

Protected Attributes

 $mClass = ''
 
 $mDefault
 
 $mDir
 
 $mFilterCallback
 
 $mHelpClass = false
 
 $mHideIf = null
 
 $mID
 
 $mLabel
 
 $mName
 
 $mOptions = false
 
 $mOptionsLabelsNotFromMessage = false
 
bool $mShowEmptyLabels = true
 If true will generate an empty div element with no label. More...
 
 $mValidationCallback
 
 $mVFormClass = ''
 

Private Member Functions

 lookupOptionsKeys ($options)
 Given an array of msg-key => value mappings, returns an array with keys being the message texts. More...
 

Detailed Description

The parent class to generate form fields.

Any field type should be a subclass of this.

Definition at line 7 of file HTMLFormField.php.

Constructor & Destructor Documentation

HTMLFormField::__construct (   $params)

Initialise the object.

Parameters
array$paramsAssociative Array. See HTMLForm doc for syntax.
Since
1.22 The 'label' attribute no longer accepts raw HTML, use 'label-raw' instead
Exceptions
MWException

Definition at line 375 of file HTMLFormField.php.

References $params, Sanitizer\escapeId(), and getMessage().

Member Function Documentation

HTMLFormField::cancelSubmit (   $value,
  $alldata 
)

Override this function if the control can somehow trigger a form submission that shouldn't actually submit the HTMLForm.

Since
1.23
Parameters
string | array$valueThe value the field was submitted with
array$alldataThe data collected from the form
Returns
bool True to cancel the submission

Definition at line 287 of file HTMLFormField.php.

HTMLFormField::canDisplayErrors ( )

True if this field type is able to display errors; false if validation errors need to be displayed in the main HTMLForm error area.

Returns
bool

Definition at line 63 of file HTMLFormField.php.

HTMLFormField::filter (   $value,
  $alldata 
)

Definition at line 321 of file HTMLFormField.php.

References $value.

static HTMLFormField::flattenOptions (   $options)
static

flatten an array of options to a single array, for instance, a set of "<options>" inside "<optgroups>".

Parameters
array$optionsAssociative Array with values either Strings or Arrays
Returns
array Flattened input

Definition at line 1045 of file HTMLFormField.php.

References $options, $value, and as.

Referenced by Preferences\datetimePreferences(), HTMLMultiSelectField\filterDataForSubmit(), HTMLCheckMatrix\filterDataForSubmit(), HTMLSelectOrOtherField\getInputHTML(), HTMLAutoCompleteSelectField\getInputHTML(), Preferences\getOptionFromUser(), User\getOptionKinds(), HTMLSelectField\validate(), HTMLMultiSelectField\validate(), HTMLRadioField\validate(), and HTMLAutoCompleteSelectField\validate().

static HTMLFormField::forceToStringRecursive (   $array)
static

Recursively forces values in an array to strings, because issues arise with integer 0 as a value.

Parameters
array$array
Returns
array

Definition at line 958 of file HTMLFormField.php.

Referenced by HTMLMultiSelectField\filterDataForSubmit(), and HTMLMultiSelectField\getInputHTML().

static HTMLFormField::formatErrors (   $errors)
staticprotected

Formats one or more errors as accepted by field validation-callback.

Parameters
string | Message | array$errorsArray of strings or Message instances
Returns
string HTML
Since
1.18

Definition at line 1066 of file HTMLFormField.php.

References $lines, as, and Html\rawElement().

HTMLFormField::getDiv (   $value)

Get the complete div for the input, including help text, labels, and whatever.

Since
1.20
Parameters
string$valueThe value to set the input to.
Returns
string Complete HTML table row.

Definition at line 523 of file HTMLFormField.php.

References $html, $mClass, $mVFormClass, $value, FormatJson\encode(), getErrorsAndErrorClass(), getHelpText(), getHelpTextHtmlDiv(), getInputHTML(), getLabelHtml(), list, and Html\rawElement().

Referenced by getOOUI(), and getVForm().

HTMLFormField::getErrorsAndErrorClass (   $value)

Determine form errors to display and their classes.

Since
1.20
Parameters
string$valueThe value of the input
Returns
array array( $errors, $errorClass )

Definition at line 803 of file HTMLFormField.php.

References $value, and validate().

Referenced by getDiv(), getInline(), getRaw(), HTMLCheckMatrix\getTableRow(), and getTableRow().

HTMLFormField::getErrorsRaw (   $value)

Determine form errors to display, returning them in an array.

Since
1.26
Parameters
string$valueThe value of the input
Returns
string[] Array of error HTML strings

Definition at line 824 of file HTMLFormField.php.

References $value, as, and validate().

Referenced by getOOUI().

HTMLFormField::getFieldLayoutOOUI (   $inputField,
  $config 
)
protected

Get a FieldLayout (or subclass thereof) to wrap this field in when using OOUI output.

Returns
OOUI\FieldLayout|OOUI\ActionFieldLayout

Definition at line 630 of file HTMLFormField.php.

Referenced by getOOUI().

HTMLFormField::getHelpText ( )

Determine the help text to display.

Since
1.20
Returns
string HTML

Definition at line 769 of file HTMLFormField.php.

References as, getMessage(), and msg().

Referenced by getDiv(), getInline(), getOOUI(), getRaw(), HTMLCheckMatrix\getTableRow(), and getTableRow().

HTMLFormField::getHelpTextHtmlDiv (   $helptext)

Generate help text HTML in div format.

Since
1.20
Parameters
string | null$helptext
Returns
string

Definition at line 733 of file HTMLFormField.php.

References FormatJson\encode(), and Html\rawElement().

Referenced by getDiv(), getHelpTextHtmlRaw(), and getInline().

HTMLFormField::getHelpTextHtmlRaw (   $helptext)

Generate help text HTML formatted for raw output.

Since
1.20
Parameters
string | null$helptext
Returns
string

Definition at line 760 of file HTMLFormField.php.

References getHelpTextHtmlDiv().

Referenced by getRaw().

HTMLFormField::getHelpTextHtmlTable (   $helptext)

Generate help text HTML in table format.

Since
1.20
Parameters
string | null$helptext
Returns
string

Definition at line 704 of file HTMLFormField.php.

References $mHelpClass, FormatJson\encode(), and Html\rawElement().

Referenced by HTMLCheckMatrix\getTableRow(), and getTableRow().

HTMLFormField::getInline (   $value)

Get the complete field as an inline element.

Since
1.25
Parameters
string$valueThe value to set the input to.
Returns
string Complete HTML inline element

Definition at line 682 of file HTMLFormField.php.

References $html, $value, getErrorsAndErrorClass(), getHelpText(), getHelpTextHtmlDiv(), getInputHTML(), getLabelHtml(), and list.

HTMLFormField::getInputHTML (   $value)
abstract

This function must be implemented to return the HTML to generate the input object itself.

It should not implement the surrounding table cells/rows, or labels/help messages.

Parameters
string$valueThe value to set the input to; eg a default text for a text input.
Returns
string Valid HTML.

Referenced by getDiv(), getInline(), getRaw(), and getTableRow().

HTMLFormField::getInputOOUI (   $value)

Same as getInputHTML, but returns an OOUI object.

Defaults to false, which getOOUI will interpret as "use the HTML version"

Parameters
string$value
Returns
OOUI\Widget|false

Definition at line 54 of file HTMLFormField.php.

Referenced by getOOUI().

HTMLFormField::getLabel ( )
Returns
string HTML

Definition at line 846 of file HTMLFormField.php.

References $mLabel.

Referenced by getLabelHtml(), and getOOUI().

HTMLFormField::getLabelAlignOOUI ( )
protected

Get label alignment when generating field for OOUI.

Returns
string 'left', 'right', 'top' or 'inline'

Definition at line 622 of file HTMLFormField.php.

Referenced by getOOUI().

HTMLFormField::getLabelHtml (   $cellAttributes = [])
HTMLFormField::getMessage (   $value)
protected
HTMLFormField::getNearestFieldByName (   $alldata,
  $name 
)
protected

Fetch a field value from $alldata for the closest field matching a given name.

This is complex because it needs to handle array fields like the user would expect. The general algorithm is to look for $name as a sibling of $this, then a sibling of $this's parent, and so on. Keeping in mind that $name itself might be referencing an array.

Parameters
array$alldata
string$name
Returns
string

Definition at line 112 of file HTMLFormField.php.

References $key, $keys, $mName, $name, and string.

Referenced by isHiddenRecurse().

HTMLFormField::getOOUI (   $value)

Get the OOUI version of the div.

Falls back to getDiv by default.

Since
1.26
Parameters
string$valueThe value to set the input to.
Returns
OOUI\FieldLayout|OOUI\ActionFieldLayout

Definition at line 572 of file HTMLFormField.php.

References $mClass, $value, as, getDiv(), getErrorsRaw(), getFieldLayoutOOUI(), getHelpText(), getInputOOUI(), getLabel(), and getLabelAlignOOUI().

HTMLFormField::getOptionsOOUI ( )

Get options and make them into arrays suitable for OOUI.

Returns
array Options for inclusion in a select or whatever.

Definition at line 1019 of file HTMLFormField.php.

References $options, as, getOptions(), and string.

Referenced by HTMLComboboxField\getInputOOUI(), and HTMLSelectField\getInputOOUI().

HTMLFormField::getRaw (   $value)

Get the complete raw fields for the input, including help text, labels, and whatever.

Since
1.20
Parameters
string$valueThe value to set the input to.
Returns
string Complete HTML table row.

Definition at line 647 of file HTMLFormField.php.

References $html, $value, getErrorsAndErrorClass(), getHelpText(), getHelpTextHtmlRaw(), getInputHTML(), getLabelHtml(), and list.

HTMLFormField::getTableRow (   $value)

Get the complete table row for the input, including help text, labels, and whatever.

Parameters
string$valueThe value to set the input to.
Returns
string Complete HTML table row.

Definition at line 465 of file HTMLFormField.php.

References $html, $value, FormatJson\encode(), getErrorsAndErrorClass(), getHelpText(), getHelpTextHtmlTable(), getInputHTML(), getLabelHtml(), list, and Html\rawElement().

HTMLFormField::getTooltipAndAccessKey ( )

Returns the attributes required for the tooltip and accesskey.

Returns
array Attributes

Definition at line 902 of file HTMLFormField.php.

References Linker\tooltipAndAccesskeyAttribs().

Referenced by HTMLCheckField\getInputHTML(), HTMLTextAreaField\getInputHTML(), HTMLTextField\getInputHTML(), HTMLCheckField\getInputOOUI(), HTMLTextAreaField\getInputOOUI(), and HTMLTextField\getInputOOUI().

HTMLFormField::getVForm (   $value)

Get the complete field for the input, including help text, labels, and whatever.

Fall back from 'vform' to 'div' when not overridden.

Since
1.25
Parameters
string$valueThe value to set the input to.
Returns
string Complete HTML field.

Definition at line 670 of file HTMLFormField.php.

References $value, and getDiv().

HTMLFormField::hasVisibleOutput ( )

If this field has a user-visible output or not.

If not, it will not be rendered

Returns
bool

Definition at line 95 of file HTMLFormField.php.

HTMLFormField::isHidden (   $alldata)

Test whether this field is supposed to be hidden, based on the values of the other form fields.

Since
1.23
Parameters
array$alldataThe data collected from the form
Returns
bool

Definition at line 269 of file HTMLFormField.php.

References isHiddenRecurse().

Referenced by validate().

HTMLFormField::isHiddenRecurse ( array  $alldata,
array  $params 
)
protected

Helper function for isHidden to handle recursive data structures.

Parameters
array$alldata
array$params
Returns
bool
Exceptions
MWException

Definition at line 162 of file HTMLFormField.php.

References $params, $value, as, getNearestFieldByName(), and list.

Referenced by isHidden().

HTMLFormField::loadDataFromRequest (   $request)

Get the value that this input has been set to from a posted form, or the input's default value if it has not been set.

Parameters
WebRequest$request
Returns
string The value

Definition at line 359 of file HTMLFormField.php.

References $request, and getDefault().

HTMLFormField::lookupOptionsKeys (   $options)
private

Given an array of msg-key => value mappings, returns an array with keys being the message texts.

It also forces values to strings.

Parameters
array$options
Returns
array

Definition at line 940 of file HTMLFormField.php.

References $key, $options, $ret, $value, as, and msg().

Referenced by getOptions().

HTMLFormField::needsLabel ( )
protected

Should this field have a label, or is there no input element with the appropriate id for the label to point to?

Returns
bool True to output a label, false to suppress

Definition at line 335 of file HTMLFormField.php.

Referenced by getLabelHtml().

HTMLFormField::setShowEmptyLabel (   $show)

Tell the field whether to generate a separate label element if its label is blank.

Since
1.22
Parameters
bool$showSet to false to not generate a label.
Returns
void

Definition at line 348 of file HTMLFormField.php.

Referenced by HTMLButtonField\__construct().

HTMLFormField::skipLoadData (   $request)

Skip this field when collecting data.

Parameters
WebRequest$request
Returns
bool
Since
1.27

Definition at line 1113 of file HTMLFormField.php.

HTMLFormField::validate (   $value,
  $alldata 
)

Override this function to add specific validation checks on the field input.

Don't forget to call parent::validate() to ensure that the user-defined callback mValidationCallback is still run

Parameters
string | array$valueThe value the field was submitted with
array$alldataThe data collected from the form
Returns
bool|string True on success, or String error to display, or false to fail validation without displaying an error.

Definition at line 302 of file HTMLFormField.php.

References $value, isHidden(), and msg().

Referenced by getErrorsAndErrorClass(), getErrorsRaw(), HtmlCheckMatrixTest\validate(), and EditWatchlistCheckboxSeriesField\validate().

Member Data Documentation

HTMLFormField::$mDefault
protected
HTMLFormField::$mDir
protected

Definition at line 13 of file HTMLFormField.php.

Referenced by HTMLTextField\getInputHTML().

HTMLFormField::$mFilterCallback
protected

Definition at line 11 of file HTMLFormField.php.

HTMLFormField::$mHelpClass = false
protected

Definition at line 18 of file HTMLFormField.php.

Referenced by getHelpTextHtmlTable().

HTMLFormField::$mHideIf = null
protected

Definition at line 22 of file HTMLFormField.php.

HTMLFormField::$mLabel
protected

Definition at line 14 of file HTMLFormField.php.

Referenced by HTMLCheckField\getLabel(), and getLabel().

HTMLFormField::$mOptions = false
protected
HTMLFormField::$mOptionsLabelsNotFromMessage = false
protected

Definition at line 21 of file HTMLFormField.php.

HTMLFormField::$mParams

Definition at line 8 of file HTMLFormField.php.

HTMLForm null HTMLFormField::$mParent

Definition at line 33 of file HTMLFormField.php.

Referenced by msg().

bool HTMLFormField::$mShowEmptyLabels = true
protected

If true will generate an empty div element with no label.

Since
1.22

Definition at line 28 of file HTMLFormField.php.

HTMLFormField::$mValidationCallback
protected

Definition at line 10 of file HTMLFormField.php.

HTMLFormField::$mVFormClass = ''
protected

Definition at line 17 of file HTMLFormField.php.

Referenced by getDiv().


The documentation for this class was generated from the following file: