wiki.techinc.nl/includes/htmlform/HTMLButtonField.php
Florian 88d616ba7b Fix doc-blocks for some HTMLForm elements
The @return doxygen parameter can take a class with a namespace, but
the \ needs to be escaped with an additional \. "\value" is usually interpreted
as a special command.

Actually with "@return OOUI\Widget", e.g., you'll get this output in your docs:
return OOUI

and an error message in the doxygen generation with something like "unknown command \Widget".

With "@return OOUI\\Widget" you'll get the expected output:
return OOUI\Widget

without any error message.

Change-Id: I14c4d7521f81ddd8c7b56facc1f0ae34f86b2299
2015-07-20 17:01:04 +00:00

76 lines
1.9 KiB
PHP

<?php
/**
* 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';
/** @var array $mFlags Flags to add to OOUI Button widget */
protected $mFlags = array();
public function __construct( $info ) {
$info['nodata'] = true;
if ( isset( $info['flags'] ) )
$this->mFlags = $info['flags'];
parent::__construct( $info );
}
public function getInputHTML( $value ) {
$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
$flags .= $prefix.'button';
}
foreach ( $this->mFlags as $flag ) {
$flags .= ' ' . $prefix . $flag;
}
$attr = array(
'class' => 'mw-htmlform-submit ' . $this->mClass . $flags,
'id' => $this->mID,
) + $this->getAttributes( array( 'disabled', 'tabindex' ) );
return Html::input( $this->mName, $value, $this->buttonType, $attr );
}
/**
* Get the OOUI widget for this field.
* @param string $value
* @return OOUI\\ButtonInputWidget
*/
public function getInputOOUI( $value ) {
return new OOUI\ButtonInputWidget( array(
'name' => $this->mName,
'value' => $value,
'label' => $value,
'type' => $this->buttonType,
'classes' => array( 'mw-htmlform-submit', $this->mClass ),
'id' => $this->mID,
'flags' => $this->mFlags,
) + $this->getAttributes( array( 'disabled', 'tabindex' ), array( 'tabindex' => 'tabIndex' ) ) );
}
protected function needsLabel() {
return false;
}
/**
* Button cannot be invalid
*
* @param string $value
* @param array $alldata
*
* @return bool
*/
public function validate( $value, $alldata ) {
return true;
}
}