MediaWiki  1.23.2
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...
 
 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...
 
 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...
 
 getInputHTML ( $value)
 This function must be implemented to return the HTML to generate the input object itself. More...
 
 getLabel ()
 
 getLabelHtml ( $cellAttributes=array())
 
 getOptions ()
 Fetch the array of options from the field's parameters. 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...
 
 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...
 
 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 $mParent
 

Protected Member Functions

 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
 
 $mFilterCallback
 
 $mID
 
 $mLabel
 
 $mName
 
 $mOptions = false
 
 $mOptionsLabelsNotFromMessage = false
 
bool $mShowEmptyLabels = true
 If true will generate an empty div element with no label. More...
 
 $mValidationCallback
 

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

◆ __construct()

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

Reimplemented in Licenses, HTMLCheckMatrix, HTMLSelectAndOtherField, HTMLSelectOrOtherField, HTMLHiddenField, HTMLButtonField, and HTMLInfoField.

Definition at line 142 of file HTMLFormField.php.

References $params, array(), Sanitizer\escapeId(), and wfMessage().

Member Function Documentation

◆ filter()

HTMLFormField::filter (   $value,
  $alldata 
)

Definition at line 88 of file HTMLFormField.php.

References $value.

◆ flattenOptions()

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 601 of file HTMLFormField.php.

References $options, $value, array(), and as.

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

◆ forceToStringRecursive()

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 536 of file HTMLFormField.php.

References array().

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

◆ formatErrors()

static HTMLFormField::formatErrors (   $errors)
staticprotected

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

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

Definition at line 622 of file HTMLFormField.php.

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

Referenced by getErrorsAndErrorClass().

◆ getAttributes()

HTMLFormField::getAttributes ( array  $list)

Returns the given attributes from the parameters.

Parameters
array$listList of attributes to get
Returns
array Attributes

Definition at line 493 of file HTMLFormField.php.

References $ret, array(), and as.

Referenced by HTMLMultiSelectField\formatOptions(), HTMLRadioField\formatOptions(), HTMLCheckField\getInputHTML(), HTMLTextField\getInputHTML(), HTMLTextAreaField\getInputHTML(), HTMLButtonField\getInputHTML(), HTMLSelectAndOtherField\getInputHTML(), and HTMLCheckMatrix\getInputHTML().

◆ getDefault()

◆ getDiv()

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.

Reimplemented in HTMLInfoField, HTMLHiddenField, HTMLEditTools, and HTMLApiField.

Definition at line 270 of file HTMLFormField.php.

References $html, $value, array(), getErrorsAndErrorClass(), getHelpText(), getHelpTextHtmlDiv(), getInputHTML(), getLabelHtml(), list, and Html\rawElement().

◆ getErrorsAndErrorClass()

HTMLFormField::getErrorsAndErrorClass (   $value)

Determine form errors to display and their classes.

Since
1.20
Parameters
string$valueThe value of the input
Returns
array

Definition at line 409 of file HTMLFormField.php.

References $value, array(), formatErrors(), and validate().

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

◆ getHelpText()

HTMLFormField::getHelpText ( )

Determine the help text to display.

Since
1.20
Returns
string

Definition at line 374 of file HTMLFormField.php.

References $name, array(), as, and msg().

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

◆ getHelpTextHtmlDiv()

HTMLFormField::getHelpTextHtmlDiv (   $helptext)

Generate help text HTML in div format.

Since
1.20
Parameters
string | null$helptext
Returns
String

Definition at line 348 of file HTMLFormField.php.

References array(), and Html\rawElement().

Referenced by getDiv(), and getHelpTextHtmlRaw().

◆ getHelpTextHtmlRaw()

HTMLFormField::getHelpTextHtmlRaw (   $helptext)

Generate help text HTML formatted for raw output.

Since
1.20
Parameters
string | null$helptext
Returns
String

Definition at line 365 of file HTMLFormField.php.

References getHelpTextHtmlDiv().

Referenced by getRaw().

◆ getHelpTextHtmlTable()

HTMLFormField::getHelpTextHtmlTable (   $helptext)

Generate help text HTML in table format.

Since
1.20
Parameters
string | null$helptext
Returns
string

Definition at line 329 of file HTMLFormField.php.

References array(), and Html\rawElement().

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

◆ getInputHTML()

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.

Reimplemented in Licenses, HTMLCheckMatrix, HTMLHiddenField, HTMLRadioField, HTMLSelectAndOtherField, HTMLMultiSelectField, HTMLSelectField, HTMLSelectOrOtherField, HTMLButtonField, HTMLApiField, HTMLTextAreaField, HTMLInfoField, HTMLTextField, HTMLCheckField, and HTMLEditTools.

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

◆ getLabel()

HTMLFormField::getLabel ( )

Reimplemented in HTMLCheckField.

Definition at line 425 of file HTMLFormField.php.

References $mLabel.

Referenced by getLabelHtml().

◆ getLabelHtml()

HTMLFormField::getLabelHtml (   $cellAttributes = array())

Reimplemented in UploadSourceField.

Definition at line 429 of file HTMLFormField.php.

References $html, $mID, array(), getLabel(), needsLabel(), and Html\rawElement().

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

◆ getOptions()

HTMLFormField::getOptions ( )

◆ getRaw()

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.

Reimplemented in HTMLInfoField, HTMLHiddenField, HTMLEditTools, and HTMLApiField.

Definition at line 307 of file HTMLFormField.php.

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

◆ getTableRow()

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.

Reimplemented in HTMLCheckMatrix, HTMLInfoField, HTMLHiddenField, HTMLEditTools, and HTMLApiField.

Definition at line 224 of file HTMLFormField.php.

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

◆ getTooltipAndAccessKey()

HTMLFormField::getTooltipAndAccessKey ( )

Returns the attributes required for the tooltip and accesskey.

Returns
array Attributes

Definition at line 479 of file HTMLFormField.php.

References array(), and Linker\tooltipAndAccesskeyAttribs().

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

◆ loadDataFromRequest()

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

Reimplemented in HTMLCheckMatrix, HTMLMultiSelectField, HTMLSelectOrOtherField, HTMLSelectAndOtherField, and HTMLCheckField.

Definition at line 126 of file HTMLFormField.php.

References getDefault().

◆ lookupOptionsKeys()

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 518 of file HTMLFormField.php.

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

Referenced by getOptions().

◆ msg()

◆ needsLabel()

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

Reimplemented in HTMLMultiSelectField, HTMLRadioField, HTMLCheckField, HTMLInfoField, and HTMLButtonField.

Definition at line 102 of file HTMLFormField.php.

Referenced by getLabelHtml().

◆ setShowEmptyLabel()

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 115 of file HTMLFormField.php.

◆ validate()

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$valueThe value the field was submitted with
array$alldataThe data collected from the form
Returns
Mixed Bool true on success, or String error to display.

Reimplemented in EditWatchlistCheckboxSeriesField, HTMLBlockedUsersItemSelect, HTMLSelectAndOtherField, HTMLCheckMatrix, HTMLButtonField, HTMLFloatField, HTMLIntField, HTMLMultiSelectField, HTMLRadioField, and HTMLSelectField.

Definition at line 73 of file HTMLFormField.php.

References $value, and msg().

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

Member Data Documentation

◆ $mClass

◆ $mDefault

HTMLFormField::$mDefault
protected

◆ $mFilterCallback

HTMLFormField::$mFilterCallback
protected

Definition at line 11 of file HTMLFormField.php.

◆ $mID

HTMLFormField::$mID
protected

◆ $mLabel

HTMLFormField::$mLabel
protected

Definition at line 13 of file HTMLFormField.php.

Referenced by getLabel().

◆ $mName

HTMLFormField::$mName
protected

Definition at line 12 of file HTMLFormField.php.

◆ $mOptions

HTMLFormField::$mOptions = false
protected

Definition at line 17 of file HTMLFormField.php.

Referenced by getOptions().

◆ $mOptionsLabelsNotFromMessage

HTMLFormField::$mOptionsLabelsNotFromMessage = false
protected

Definition at line 18 of file HTMLFormField.php.

◆ $mParams

HTMLFormField::$mParams

Definition at line 8 of file HTMLFormField.php.

◆ $mParent

HTMLForm HTMLFormField::$mParent

Definition at line 27 of file HTMLFormField.php.

◆ $mShowEmptyLabels

bool HTMLFormField::$mShowEmptyLabels = true
protected

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

Since
1.22

Definition at line 23 of file HTMLFormField.php.

◆ $mValidationCallback

HTMLFormField::$mValidationCallback
protected

Definition at line 10 of file HTMLFormField.php.


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