*/
class HTMLForm extends ContextSource {
- # A mapping of 'type' inputs onto standard HTMLFormField subclasses
+ // A mapping of 'type' inputs onto standard HTMLFormField subclasses
static $typeMappings = array(
'text' => 'HTMLTextField',
'textarea' => 'HTMLTextAreaField',
'submit' => 'HTMLSubmitField',
'hidden' => 'HTMLHiddenField',
'edittools' => 'HTMLEditTools',
- 'namespaces' => 'HTMLNamespacesField',
- 'restrictionlevels' => 'HTMLRestrictionLevelsField',
- # HTMLTextField will output the correct type="" attribute automagically.
- # There are about four zillion other HTML5 input types, like url, but
- # we don't use those at the moment, so no point in adding all of them.
+ // HTMLTextField will output the correct type="" attribute automagically.
+ // There are about four zillion other HTML5 input types, like url, but
+ // we don't use those at the moment, so no point in adding all of them.
'email' => 'HTMLTextField',
'password' => 'HTMLTextField',
);
protected $mTitle;
protected $mMethod = 'post';
+
+ /**
+ * @since 1.19
+ * @var false|string
+ */
+ protected $mAction = false;
protected $mUseMultipart = false;
protected $mHiddenFields = array();
* done already.
* @deprecated since 1.18 load modules with ResourceLoader instead
*/
- static function addJS() { }
+ static function addJS() { wfDeprecated( __METHOD__, '1.18' ); }
/**
* Initialise a new Object for the field
/**
* Add header text, inside the form.
* @param $msg String complete text of message to display
- * @param $section The section to add the header to
+ * @param $section string The section to add the header to
*/
function addHeaderText( $msg, $section = null ) {
if ( is_null( $section ) ) {
}
/**
- * Display the form (sending to wgOut), with an appropriate error
+ * Display the form (sending to $wgOut), with an appropriate error
* message or stack of messages, and any validation errors, etc.
* @param $submitResult Mixed output from HTMLForm::trySubmit()
*/
: 'application/x-www-form-urlencoded';
# Attributes
$attribs = array(
- 'action' => $this->getTitle()->getFullURL(),
+ 'action' => $this->mAction === false ? $this->getTitle()->getFullURL() : $this->mAction,
'method' => $this->mMethod,
'class' => 'visualClear',
'enctype' => $encType,
public function getLegend( $key ) {
return wfMsg( "{$this->mMessagePrefix}-$key" );
}
-
- /**
- * Returns an array of fields in the form
- *
- * @return HTMLFormField[]
- */
- public function getFlatFields() {
- return $this->mFlatFields;
- }
-
+
/**
- * Returns a value of a field
- *
- * @param $field string Field name
- * @return mixed
+ * Set the value for the action attribute of the form.
+ * When set to false (which is the default state), the set title is used.
+ *
+ * @since 1.19
+ *
+ * @param string|false $action
*/
- public function getVal( $field ) {
- return $this->mFieldData[$field];
+ public function setAction( $action ) {
+ $this->mAction = $action;
}
+
}
/**
if ( isset( $params['filter-callback'] ) ) {
$this->mFilterCallback = $params['filter-callback'];
}
+
+ if ( isset( $params['flatlist'] ) ){
+ $this->mClass .= ' mw-htmlform-flatlist';
+ }
}
/**
return $html;
}
- /**
- * Returns the HTML name of the Field
- *
- * @return string
- */
- public function getName() {
- return $this->mName;
- }
-
function getLabel() {
return $this->mLabel;
}
/**
* flatten an array of options to a single array, for instance,
* a set of <options> inside <optgroups>.
- * @param $options Associative Array with values either Strings
+ * @param $options array Associative Array with values either Strings
* or Arrays
* @return Array flattened input
*/
'value' => $value,
) + $this->getTooltipAndAccessKey();
+ if ( $this->mClass !== '' ) {
+ $attribs['class'] = $this->mClass;
+ }
+
if ( isset( $this->mParams['maxlength'] ) ) {
$attribs['maxlength'] = $this->mParams['maxlength'];
}
'rows' => $this->getRows(),
) + $this->getTooltipAndAccessKey();
-
+ if ( $this->mClass !== '' ) {
+ $attribs['class'] = $this->mClass;
+ }
+
if ( !empty( $this->mParams['disabled'] ) ) {
$attribs['disabled'] = 'disabled';
}
if ( !empty( $this->mParams['disabled'] ) ) {
$attr['disabled'] = 'disabled';
}
+
+ if ( $this->mClass !== '' ) {
+ $attr['class'] = $this->mClass;
+ }
return Xml::check( $this->mName, $value, $attr ) . ' ' .
Html::rawElement( 'label', array( 'for' => $this->mID ), $this->mLabel );
if ( !empty( $this->mParams['disabled'] ) ) {
$select->setAttribute( 'disabled', 'disabled' );
}
+
+ if ( $this->mClass !== '' ) {
+ $select->setAttribute( 'class', $this->mClass );
+ }
$select->addOptions( $this->mParams['options'] );
if ( isset( $this->mParams['maxlength'] ) ) {
$tbAttribs['maxlength'] = $this->mParams['maxlength'];
}
+
+ if ( $this->mClass !== '' ) {
+ $tbAttribs['class'] = $this->mClass;
+ }
$textbox = Html::input(
$this->mName . '-other',
*/
class HTMLMultiSelectField extends HTMLFormField {
- public function __construct( $params ){
- parent::__construct( $params );
- if( isset( $params['flatlist'] ) ){
- $this->mClass .= ' mw-htmlform-multiselect-flatlist';
- }
- }
-
function validate( $value, $alldata ) {
$p = parent::validate( $value, $alldata );
$attribs + $thisAttribs );
$checkbox .= ' ' . Html::rawElement( 'label', array( 'for' => "{$this->mID}-$info" ), $label );
- $html .= ' ' . Html::rawElement( 'div', array( 'class' => 'mw-htmlform-multiselect-item' ), $checkbox );
+ $html .= ' ' . Html::rawElement( 'div', array( 'class' => 'mw-htmlform-flatlist-item' ), $checkbox );
}
}
'id' => $this->mID . '-other',
'size' => $this->getSize(),
);
+
+ if ( $this->mClass !== '' ) {
+ $textAttribs['class'] = $this->mClass;
+ }
foreach ( array( 'required', 'autofocus', 'multiple', 'disabled' ) as $param ) {
if ( isset( $this->mParams[$param] ) ) {
* Radio checkbox fields.
*/
class HTMLRadioField extends HTMLFormField {
- function __construct( $params ) {
- parent::__construct( $params );
- if ( isset( $params['flatlist'] ) ) {
- $this->mClass .= ' mw-htmlform-radio-flatlist';
- }
- }
function validate( $value, $alldata ) {
$radio .= ' ' .
Html::rawElement( 'label', array( 'for' => $id ), $label );
- $html .= ' ' . Html::rawElement( 'div', array( 'class' => 'mw-htmlform-radio-item' ), $radio );
+ $html .= ' ' . Html::rawElement( 'div', array( 'class' => 'mw-htmlform-flatlist-item' ), $radio );
}
}
return Xml::submitButton(
$value,
array(
- 'class' => 'mw-htmlform-submit',
+ 'class' => 'mw-htmlform-submit ' . $this->mClass,
'name' => $this->mName,
'id' => $this->mID,
)
. "</div></td></tr>\n";
}
}
-
-/**
- * Dropdown for namespaces
- */
-class HTMLNamespacesField extends HTMLSelectField {
- function __construct( $params ) {
- global $wgContLang;
- parent::__construct( $params );
-
- $namespaces = $wgContLang->getFormattedNamespaces();
-
- $options = array();
- $options[ wfMessage( 'namespacesall' )->escaped() ] = ''; // TODO: Make an option
-
- foreach ( $namespaces as $index => $name ) {
- // Don't include things like SpecialPages
- if ( $index < NS_MAIN ) {
- continue;
- }
-
- if ( $index === 0 ) {
- $name = wfMessage( 'blanknamespace' )->escaped();
- }
-
- $options[$name] = $index;
- }
-
- $this->mParams['options'] = $options;
- }
-}
-
-/**
- * Dropdown for protection levels
- */
-class HTMLRestrictionLevelsField extends HTMLSelectField {
-
- /**
- * Should this field be displayed? If it hits a condition where it should
- * be hidden, set this to false.
- *
- * @var bool
- */
- protected $enabled = true;
-
- function __construct( $params ) {
- global $wgRestrictionLevels;
- parent::__construct( $params );
-
- $options = array( wfMsg('restriction-level-all') => 0 ); // Temporary array
-
- // First pass to load the level names
- foreach( $wgRestrictionLevels as $type ) {
- if ( $type != '' && $type != '*' ) {
- $text = wfMsg("restriction-level-$type");
- $options[$text] = $type;
- }
- }
-
- // Is there only one level (aside from "all")?
- if( count($options) <= 2 ) {
- $this->enabled = false;
- return;
- }
-
- $this->mParams['options'] = $options;
- }
-
- /**
- * Returns false where
- *
- * @param $value
- * @return String
- */
- function getTableRow( $value ) {
- if ( $this->enabled ) {
- return parent::getTableRow( $value );
- }
-
- return '';
- }
-}
\ No newline at end of file