PHPSessionHandler: Implement SessionHandlerInterface
[mediawiki.git] / includes / htmlform / HTMLButtonField.php
blobb4849e551863c018ea482ae0566ef47d9a12b258
1 <?php
3 /**
4 * Adds a generic button inline to the form. Does not do anything, you must add
5 * click handling code in JavaScript. Use a HTMLSubmitField if you merely
6 * wish to add a submit button to a form.
8 * Additional recognized configuration parameters include:
9 * - flags: OOUI flags for the button, see OOUI\\FlaggedElement
10 * - buttonlabel-message: Message to use for the button display text, instead
11 * of the value from 'default'. Overrides 'buttonlabel' and 'buttonlabel-raw'.
12 * - buttonlabel: Text to display for the button display text, instead
13 * of the value from 'default'. Overrides 'buttonlabel-raw'.
14 * - buttonlabel-raw: HTMLto display for the button display text, instead
15 * of the value from 'default'.
17 * Note that the buttonlabel parameters are not supported on IE6 and IE7 due to
18 * bugs in those browsers. If detected, they will be served buttons using the
19 * value of 'default' as the button label.
21 * @since 1.22
23 class HTMLButtonField extends HTMLFormField {
24 protected $buttonType = 'button';
25 protected $buttonLabel = null;
27 /** @var array $mFlags Flags to add to OOUI Button widget */
28 protected $mFlags = array();
30 public function __construct( $info ) {
31 $info['nodata'] = true;
32 if ( isset( $info['flags'] ) ) {
33 $this->mFlags = $info['flags'];
36 # Generate the label from a message, if possible
37 if ( isset( $info['buttonlabel-message'] ) ) {
38 $msgInfo = $info['buttonlabel-message'];
40 if ( is_array( $msgInfo ) ) {
41 $msg = array_shift( $msgInfo );
42 } else {
43 $msg = $msgInfo;
44 $msgInfo = array();
47 $this->buttonLabel = $this->msg( $msg, $msgInfo )->parse();
48 } elseif ( isset( $info['buttonlabel'] ) ) {
49 if ( $info['buttonlabel'] === '&#160;' ) {
50 // Apparently some things set &nbsp directly and in an odd format
51 $this->buttonLabel = '&#160;';
52 } else {
53 $this->buttonLabel = htmlspecialchars( $info['buttonlabel'] );
55 } elseif ( isset( $info['buttonlabel-raw'] ) ) {
56 $this->buttonLabel = $info['buttonlabel-raw'];
59 parent::__construct( $info );
62 public function getInputHTML( $value ) {
63 $flags = '';
64 $prefix = 'mw-htmlform-';
65 if ( $this->mParent instanceof VFormHTMLForm ||
66 $this->mParent->getConfig()->get( 'UseMediaWikiUIEverywhere' )
67 ) {
68 $prefix = 'mw-ui-';
69 // add mw-ui-button separately, so the descriptor doesn't need to set it
70 $flags .= ' ' . $prefix . 'button';
72 foreach ( $this->mFlags as $flag ) {
73 $flags .= ' ' . $prefix . $flag;
75 $attr = array(
76 'class' => 'mw-htmlform-submit ' . $this->mClass . $flags,
77 'id' => $this->mID,
78 'type' => $this->buttonType,
79 'name' => $this->mName,
80 'value' => $value,
81 ) + $this->getAttributes( array( 'disabled', 'tabindex' ) );
83 if ( $this->isBadIE() ) {
84 return Html::element( 'input', $attr );
85 } else {
86 return Html::rawElement( 'button', $attr, $this->buttonLabel ?: htmlspecialchars( $value ) );
90 /**
91 * Get the OOUI widget for this field.
92 * @param string $value
93 * @return OOUI\ButtonInputWidget
95 public function getInputOOUI( $value ) {
96 return new OOUI\ButtonInputWidget( array(
97 'name' => $this->mName,
98 'value' => $value,
99 'label' => !$this->isBadIE() && $this->buttonLabel
100 ? new OOUI\HtmlSnippet( $this->buttonLabel )
101 : $value,
102 'type' => $this->buttonType,
103 'classes' => array( 'mw-htmlform-submit', $this->mClass ),
104 'id' => $this->mID,
105 'flags' => $this->mFlags,
106 'useInputTag' => $this->isBadIE(),
107 ) + $this->getAttributes( array( 'disabled', 'tabindex' ), array( 'tabindex' => 'tabIndex' ) ) );
110 protected function needsLabel() {
111 return false;
115 * Button cannot be invalid
117 * @param string $value
118 * @param array $alldata
120 * @return bool
122 public function validate( $value, $alldata ) {
123 return true;
127 * IE<8 has bugs with <button>, so we'll need to avoid them.
128 * @return bool Whether the request is from a bad version of IE
130 private function isBadIE() {
131 $request = $this->mParent
132 ? $this->mParent->getRequest()
133 : RequestContext::getMain()->getRequest();
134 return preg_match( '/MSIE [1-7]\./i', $request->getHeader( 'User-Agent' ) );