* the HTML for the input field to be placed in the table.
*
* You can find extensive documentation on the www.mediawiki.org wiki:
- * - http://www.mediawiki.org/wiki/HTMLForm
- * - http://www.mediawiki.org/wiki/HTMLForm/tutorial
+ * - https://www.mediawiki.org/wiki/HTMLForm
+ * - https://www.mediawiki.org/wiki/HTMLForm/tutorial
*
* The constructor input is an associative array of $fieldname => $info,
* where $info is an Associative Array with any of the following:
* 'default' -- default value when the form is displayed
* 'id' -- HTML id attribute
* 'cssclass' -- CSS class
- * 'options' -- varies according to the specific object.
+ * 'options' -- associative array mapping labels to values.
+ * Some field types support multi-level arrays.
+ * 'options-messages' -- associative array mapping message keys to values.
+ * Some field types support multi-level arrays.
+ * 'options-message' -- message key to be parsed to extract the list of
+ * options (like 'ipbreason-dropdown').
* 'label-message' -- message key for a message to use as the label.
* can be an array of msg key and then parameters to
* the message.
'edittools' => 'HTMLEditTools',
'checkmatrix' => 'HTMLCheckMatrix',
// HTMLTextField will output the correct type="" attribute automagically.
- // There are about four zillion other HTML5 input types, like url, but
+ // 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',
);
public $mFieldData;
}
/**
- * Initialise a new Object for the field
+ * Get the HTMLFormField subclass for this descriptor.
+ *
+ * The descriptor can be passed either 'class' which is the name of
+ * a HTMLFormField subclass, or a shorter 'type' which is an alias.
+ * This makes sure the 'class' is always set, and also is returned by
+ * this function for ease.
*
- * @param $fieldname string
- * @param string $descriptor input Descriptor, as described above
+ * @since 1.23
+ *
+ * @param string $fieldname Name of the field
+ * @param array $descriptor Input Descriptor, as described above
*
* @throws MWException
- * @return HTMLFormField subclass
+ * @return string Name of a HTMLFormField subclass
*/
- static function loadInputFromParameters( $fieldname, $descriptor ) {
+ public static function getClassFromDescriptor( $fieldname, &$descriptor ) {
if ( isset( $descriptor['class'] ) ) {
$class = $descriptor['class'];
} elseif ( isset( $descriptor['type'] ) ) {
}
if ( !$class ) {
- throw new MWException( "Descriptor with no class: " . print_r( $descriptor, true ) );
+ throw new MWException( "Descriptor with no class for $fieldname: " . print_r( $descriptor, true ) );
}
+ return $class;
+ }
+
+ /**
+ * Initialise a new Object for the field
+ *
+ * @param string $fieldname Name of the field
+ * @param array $descriptor Input Descriptor, as described above
+ *
+ * @throws MWException
+ * @return HTMLFormField subclass
+ */
+ public static function loadInputFromParameters( $fieldname, $descriptor ) {
+ $class = self::getClassFromDescriptor( $fieldname, $descriptor );
$descriptor['fieldname'] = $fieldname;