2013-11-19 12:55:50 +00:00
|
|
|
<?php
|
2013-11-19 13:08:16 +00:00
|
|
|
|
2013-11-19 12:55:50 +00:00
|
|
|
/**
|
|
|
|
|
* Adds a generic button inline to the form. Does not do anything, you must add
|
|
|
|
|
* click handling code in JavaScript. Use a HTMLSubmitField if you merely
|
|
|
|
|
* wish to add a submit button to a form.
|
|
|
|
|
*
|
|
|
|
|
* @since 1.22
|
|
|
|
|
*/
|
|
|
|
|
class HTMLButtonField extends HTMLFormField {
|
|
|
|
|
protected $buttonType = 'button';
|
|
|
|
|
|
2015-06-25 12:56:05 +00:00
|
|
|
/** @var array $mFlags Flags to add to OOUI Button widget */
|
|
|
|
|
protected $mFlags = array();
|
|
|
|
|
|
2013-11-19 12:55:50 +00:00
|
|
|
public function __construct( $info ) {
|
2013-11-19 13:08:16 +00:00
|
|
|
$info['nodata'] = true;
|
2015-06-25 12:56:05 +00:00
|
|
|
if ( isset( $info['flags'] ) )
|
|
|
|
|
$this->mFlags = $info['flags'];
|
2013-11-19 12:55:50 +00:00
|
|
|
parent::__construct( $info );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getInputHTML( $value ) {
|
2015-07-09 17:08:21 +00:00
|
|
|
$flags = '';
|
|
|
|
|
$prefix = 'mw-htmlform-';
|
|
|
|
|
if ( $this->mParent instanceof VFormHTMLForm ||
|
|
|
|
|
$this->mParent->getConfig()->get( 'UseMediaWikiUIEverywhere' )
|
|
|
|
|
) {
|
|
|
|
|
$prefix = 'mw-ui-';
|
|
|
|
|
// add mw-ui-button separately, so the descriptor doesn't need to set it
|
2015-08-27 14:19:20 +00:00
|
|
|
$flags .= ' ' . $prefix.'button';
|
2015-07-09 17:08:21 +00:00
|
|
|
}
|
|
|
|
|
foreach ( $this->mFlags as $flag ) {
|
|
|
|
|
$flags .= ' ' . $prefix . $flag;
|
|
|
|
|
}
|
2013-11-19 12:55:50 +00:00
|
|
|
$attr = array(
|
2015-07-09 17:08:21 +00:00
|
|
|
'class' => 'mw-htmlform-submit ' . $this->mClass . $flags,
|
2013-11-19 12:55:50 +00:00
|
|
|
'id' => $this->mID,
|
2013-05-02 18:27:44 +00:00
|
|
|
) + $this->getAttributes( array( 'disabled', 'tabindex' ) );
|
2013-11-19 12:55:50 +00:00
|
|
|
|
|
|
|
|
return Html::input( $this->mName, $value, $this->buttonType, $attr );
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-21 21:03:49 +00:00
|
|
|
/**
|
|
|
|
|
* Get the OOUI widget for this field.
|
|
|
|
|
* @param string $value
|
2015-07-20 16:27:36 +00:00
|
|
|
* @return OOUI\\ButtonInputWidget
|
2015-04-21 21:03:49 +00:00
|
|
|
*/
|
|
|
|
|
public function getInputOOUI( $value ) {
|
|
|
|
|
return new OOUI\ButtonInputWidget( array(
|
|
|
|
|
'name' => $this->mName,
|
|
|
|
|
'value' => $value,
|
2015-06-25 12:56:05 +00:00
|
|
|
'label' => $value,
|
2015-04-21 21:03:49 +00:00
|
|
|
'type' => $this->buttonType,
|
|
|
|
|
'classes' => array( 'mw-htmlform-submit', $this->mClass ),
|
|
|
|
|
'id' => $this->mID,
|
2015-06-25 12:56:05 +00:00
|
|
|
'flags' => $this->mFlags,
|
2015-04-21 21:03:49 +00:00
|
|
|
) + $this->getAttributes( array( 'disabled', 'tabindex' ), array( 'tabindex' => 'tabIndex' ) ) );
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-19 12:55:50 +00:00
|
|
|
protected function needsLabel() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Button cannot be invalid
|
|
|
|
|
*
|
2014-04-20 21:33:05 +00:00
|
|
|
* @param string $value
|
|
|
|
|
* @param array $alldata
|
2013-11-19 12:55:50 +00:00
|
|
|
*
|
2014-04-20 21:33:05 +00:00
|
|
|
* @return bool
|
2013-11-19 12:55:50 +00:00
|
|
|
*/
|
|
|
|
|
public function validate( $value, $alldata ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2013-11-19 13:08:16 +00:00
|
|
|
}
|