summaryrefslogtreecommitdiff
path: root/vendor/oojs/oojs-ui/php/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/oojs/oojs-ui/php/widgets')
-rw-r--r--vendor/oojs/oojs-ui/php/widgets/ButtonInputWidget.php14
-rw-r--r--vendor/oojs/oojs-ui/php/widgets/ButtonWidget.php2
-rw-r--r--vendor/oojs/oojs-ui/php/widgets/CheckboxInputWidget.php2
-rw-r--r--vendor/oojs/oojs-ui/php/widgets/DropdownInputWidget.php11
-rw-r--r--vendor/oojs/oojs-ui/php/widgets/IconWidget.php2
-rw-r--r--vendor/oojs/oojs-ui/php/widgets/IndicatorWidget.php2
-rw-r--r--vendor/oojs/oojs-ui/php/widgets/InputWidget.php10
-rw-r--r--vendor/oojs/oojs-ui/php/widgets/LabelWidget.php2
-rw-r--r--vendor/oojs/oojs-ui/php/widgets/RadioInputWidget.php2
-rw-r--r--vendor/oojs/oojs-ui/php/widgets/RadioSelectInputWidget.php127
-rw-r--r--vendor/oojs/oojs-ui/php/widgets/TextInputWidget.php63
11 files changed, 224 insertions, 13 deletions
diff --git a/vendor/oojs/oojs-ui/php/widgets/ButtonInputWidget.php b/vendor/oojs/oojs-ui/php/widgets/ButtonInputWidget.php
index b3bcb63b..00c17912 100644
--- a/vendor/oojs/oojs-ui/php/widgets/ButtonInputWidget.php
+++ b/vendor/oojs/oojs-ui/php/widgets/ButtonInputWidget.php
@@ -6,6 +6,15 @@ namespace OOUI;
* A button that is an input widget. Intended to be used within a FormLayout.
*/
class ButtonInputWidget extends InputWidget {
+
+ /* Static Properties */
+
+ /**
+ * Disable generating `<label>` elements for buttons. One would very rarely need additional label
+ * for a button, and it's already a big clickable target, and it causes unexpected rendering.
+ */
+ public static $supportsSimpleLabel = false;
+
/* Properties */
/**
@@ -60,8 +69,11 @@ class ButtonInputWidget extends InputWidget {
}
protected function getInputElement( $config ) {
+ $type = in_array( $config['type'], array( 'button', 'submit', 'reset' ) ) ?
+ $config['type'] :
+ 'button';
$input = new Tag( $config['useInputTag'] ? 'input' : 'button' );
- $input->setAttributes( array( 'type' => $config['type'] ) );
+ $input->setAttributes( array( 'type' => $type ) );
return $input;
}
diff --git a/vendor/oojs/oojs-ui/php/widgets/ButtonWidget.php b/vendor/oojs/oojs-ui/php/widgets/ButtonWidget.php
index f26608b1..976ac6c2 100644
--- a/vendor/oojs/oojs-ui/php/widgets/ButtonWidget.php
+++ b/vendor/oojs/oojs-ui/php/widgets/ButtonWidget.php
@@ -50,6 +50,8 @@ class ButtonWidget extends Widget {
$this->mixin( new FlaggedElement( $this, $config ) );
$this->mixin( new TabIndexedElement( $this,
array_merge( $config, array( 'tabIndexed' => $this->button ) ) ) );
+ $this->mixin( new AccessKeyedElement( $this,
+ array_merge( $config, array( 'accessKeyed' => $this->button ) ) ) );
// Initialization
$this->button->appendContent( $this->icon, $this->label, $this->indicator );
diff --git a/vendor/oojs/oojs-ui/php/widgets/CheckboxInputWidget.php b/vendor/oojs/oojs-ui/php/widgets/CheckboxInputWidget.php
index bda09c66..5d180d58 100644
--- a/vendor/oojs/oojs-ui/php/widgets/CheckboxInputWidget.php
+++ b/vendor/oojs/oojs-ui/php/widgets/CheckboxInputWidget.php
@@ -27,6 +27,8 @@ class CheckboxInputWidget extends InputWidget {
// Initialization
$this->addClasses( array( 'oo-ui-checkboxInputWidget' ) );
+ // Required for pretty styling in MediaWiki theme
+ $this->appendContent( new Tag( 'span' ) );
$this->setSelected( isset( $config['selected'] ) ? $config['selected'] : false );
}
diff --git a/vendor/oojs/oojs-ui/php/widgets/DropdownInputWidget.php b/vendor/oojs/oojs-ui/php/widgets/DropdownInputWidget.php
index ae541a66..f8ea48a3 100644
--- a/vendor/oojs/oojs-ui/php/widgets/DropdownInputWidget.php
+++ b/vendor/oojs/oojs-ui/php/widgets/DropdownInputWidget.php
@@ -23,6 +23,10 @@ class DropdownInputWidget extends InputWidget {
// Parent constructor
parent::__construct( $config );
+ // Mixins
+ $this->mixin( new TitledElement( $this,
+ array_merge( $config, array( 'titled' => $this->input ) ) ) );
+
// Initialization
$this->setOptions( isset( $config['options'] ) ? $config['options'] : array() );
$this->addClasses( array( 'oo-ui-dropdownInputWidget' ) );
@@ -60,11 +64,12 @@ class DropdownInputWidget extends InputWidget {
// Rebuild the dropdown menu
$this->input->clearContent();
foreach ( $options as $opt ) {
+ $optValue = $this->cleanUpValue( $opt['data'] );
$option = new Tag( 'option' );
- $option->setAttributes( array( 'value' => $opt['data'] ) );
- $option->appendContent( isset( $opt['label'] ) ? $opt['label'] : $opt['data'] );
+ $option->setAttributes( array( 'value' => $optValue ) );
+ $option->appendContent( isset( $opt['label'] ) ? $opt['label'] : $optValue );
- if ( $value === $opt['data'] ) {
+ if ( $value === $optValue ) {
$isValueAvailable = true;
}
diff --git a/vendor/oojs/oojs-ui/php/widgets/IconWidget.php b/vendor/oojs/oojs-ui/php/widgets/IconWidget.php
index f8273f37..d752ddc8 100644
--- a/vendor/oojs/oojs-ui/php/widgets/IconWidget.php
+++ b/vendor/oojs/oojs-ui/php/widgets/IconWidget.php
@@ -9,7 +9,7 @@ namespace OOUI;
*/
class IconWidget extends Widget {
- /* Static properties */
+ /* Static Properties */
public static $tagName = 'span';
diff --git a/vendor/oojs/oojs-ui/php/widgets/IndicatorWidget.php b/vendor/oojs/oojs-ui/php/widgets/IndicatorWidget.php
index 01f2055d..b933a309 100644
--- a/vendor/oojs/oojs-ui/php/widgets/IndicatorWidget.php
+++ b/vendor/oojs/oojs-ui/php/widgets/IndicatorWidget.php
@@ -9,7 +9,7 @@ namespace OOUI;
*/
class IndicatorWidget extends Widget {
- /* Static properties */
+ /* Static Properties */
public static $tagName = 'span';
diff --git a/vendor/oojs/oojs-ui/php/widgets/InputWidget.php b/vendor/oojs/oojs-ui/php/widgets/InputWidget.php
index 234d3145..24f5a51c 100644
--- a/vendor/oojs/oojs-ui/php/widgets/InputWidget.php
+++ b/vendor/oojs/oojs-ui/php/widgets/InputWidget.php
@@ -9,6 +9,10 @@ namespace OOUI;
*/
class InputWidget extends Widget {
+ /* Static Properties */
+
+ public static $supportsSimpleLabel = true;
+
/* Properties */
/**
@@ -42,6 +46,10 @@ class InputWidget extends Widget {
array_merge( $config, array( 'flagged' => $this ) ) ) );
$this->mixin( new TabIndexedElement( $this,
array_merge( $config, array( 'tabIndexed' => $this->input ) ) ) );
+ $this->mixin( new TitledElement( $this,
+ array_merge( $config, array( 'titled' => $this->input ) ) ) );
+ $this->mixin( new AccessKeyedElement( $this,
+ array_merge( $config, array( 'accessKeyed' => $this->input ) ) ) );
// Initialization
if ( isset( $config['name'] ) ) {
@@ -53,7 +61,7 @@ class InputWidget extends Widget {
$this
->addClasses( array( 'oo-ui-inputWidget' ) )
->appendContent( $this->input );
- $this->appendContent( new Tag( 'span' ) );
+ $this->input->addClasses( array( 'oo-ui-inputWidget-input' ) );
$this->setValue( isset( $config['value'] ) ? $config['value'] : null );
}
diff --git a/vendor/oojs/oojs-ui/php/widgets/LabelWidget.php b/vendor/oojs/oojs-ui/php/widgets/LabelWidget.php
index b59a5f25..8945b15f 100644
--- a/vendor/oojs/oojs-ui/php/widgets/LabelWidget.php
+++ b/vendor/oojs/oojs-ui/php/widgets/LabelWidget.php
@@ -7,7 +7,7 @@ namespace OOUI;
*/
class LabelWidget extends Widget {
- /* Static properties */
+ /* Static Properties */
public static $tagName = 'span';
diff --git a/vendor/oojs/oojs-ui/php/widgets/RadioInputWidget.php b/vendor/oojs/oojs-ui/php/widgets/RadioInputWidget.php
index 26da29d0..69fd0a8e 100644
--- a/vendor/oojs/oojs-ui/php/widgets/RadioInputWidget.php
+++ b/vendor/oojs/oojs-ui/php/widgets/RadioInputWidget.php
@@ -18,6 +18,8 @@ class RadioInputWidget extends InputWidget {
// Initialization
$this->addClasses( array( 'oo-ui-radioInputWidget' ) );
+ // Required for pretty styling in MediaWiki theme
+ $this->appendContent( new Tag( 'span' ) );
$this->setSelected( isset( $config['selected'] ) ? $config['selected'] : false );
}
diff --git a/vendor/oojs/oojs-ui/php/widgets/RadioSelectInputWidget.php b/vendor/oojs/oojs-ui/php/widgets/RadioSelectInputWidget.php
new file mode 100644
index 00000000..912c6917
--- /dev/null
+++ b/vendor/oojs/oojs-ui/php/widgets/RadioSelectInputWidget.php
@@ -0,0 +1,127 @@
+<?php
+
+namespace OOUI;
+
+/**
+ * Multiple radio buttons input widget. Intended to be used within a OO.ui.FormLayout.
+ */
+class RadioSelectInputWidget extends InputWidget {
+
+ /* Static Properties */
+
+ public static $supportsSimpleLabel = false;
+
+ /* Properties */
+
+ /**
+ * @var string|null
+ */
+ protected $name = null;
+
+ /**
+ * @var FieldLayout[]
+ */
+ protected $fields = array();
+
+ /**
+ * @param array $config Configuration options
+ * @param array[] $config['options'] Array of menu options in the format
+ * `array( 'data' => …, 'label' => … )`
+ */
+ public function __construct( array $config = array() ) {
+ // Parent constructor
+ parent::__construct( $config );
+
+ if ( isset( $config['name'] ) ) {
+ $this->name = $config['name'];
+ }
+
+ // Initialization
+ $this->setOptions( isset( $config['options'] ) ? $config['options'] : array() );
+ $this->addClasses( array( 'oo-ui-radioSelectInputWidget' ) );
+ }
+
+ protected function getInputElement( $config ) {
+ // Actually unused
+ return new Tag( 'div' );
+ }
+
+ public function setValue( $value ) {
+ $this->value = $this->cleanUpValue( $value );
+ foreach ( $this->fields as &$field ) {
+ $field->getField()->setSelected( $field->getField()->getValue() === $this->value );
+ }
+ return $this;
+ }
+
+ /**
+ * Set the options available for this input.
+ *
+ * @param array[] $options Array of menu options in the format
+ * `array( 'data' => …, 'label' => … )`
+ * @chainable
+ */
+ public function setOptions( $options ) {
+ $value = $this->getValue();
+ $isValueAvailable = false;
+ $this->fields = array();
+
+ // Rebuild the radio buttons
+ $this->clearContent();
+ // Need a unique name, otherwise more than one radio will be selectable
+ $name = $this->name ?: 'oo-ui-radioSelectInputWidget' . mt_rand();
+ foreach ( $options as $opt ) {
+ $optValue = $this->cleanUpValue( $opt['data'] );
+ $field = new FieldLayout(
+ new RadioInputWidget( array(
+ 'name' => $name,
+ 'value' => $optValue,
+ 'disabled' => $this->isDisabled(),
+ ) ),
+ array(
+ 'label' => isset( $opt['label'] ) ? $opt['label'] : $optValue,
+ 'align' => 'inline',
+ )
+ );
+
+ if ( $value === $optValue ) {
+ $isValueAvailable = true;
+ }
+
+ $this->fields[] = $field;
+ $this->appendContent( $field );
+ }
+
+ // Restore the previous value, or reset to something sensible
+ if ( $isValueAvailable ) {
+ // Previous value is still available
+ $this->setValue( $value );
+ } else {
+ // No longer valid, reset
+ if ( count( $options ) ) {
+ $this->setValue( $options[0]['data'] );
+ }
+ }
+
+ return $this;
+ }
+
+ public function setDisabled( $state ) {
+ parent::setDisabled( $state );
+ foreach ( $this->fields as $field ) {
+ $field->getField()->setDisabled( $this->isDisabled() );
+ }
+ return $this;
+ }
+
+ public function getConfig( &$config ) {
+ $o = array();
+ foreach ( $this->fields as $field ) {
+ $label = $field->getLabel();
+ $data = $field->getField()->getValue();
+ $o[] = array( 'data' => $data, 'label' => $label );
+ }
+ $config['options'] = $o;
+ return parent::getConfig( $config );
+ }
+}
diff --git a/vendor/oojs/oojs-ui/php/widgets/TextInputWidget.php b/vendor/oojs/oojs-ui/php/widgets/TextInputWidget.php
index a5f31f74..210729fd 100644
--- a/vendor/oojs/oojs-ui/php/widgets/TextInputWidget.php
+++ b/vendor/oojs/oojs-ui/php/widgets/TextInputWidget.php
@@ -10,6 +10,13 @@ class TextInputWidget extends InputWidget {
/* Properties */
/**
+ * Input field type.
+ *
+ * @var string
+ */
+ protected $type = null;
+
+ /**
* Prevent changes.
*
* @var boolean
@@ -25,27 +32,49 @@ class TextInputWidget extends InputWidget {
/**
* @param array $config Configuration options
- * @param string $config['type'] HTML tag `type` attribute (default: 'text')
+ * @param string $config['type'] HTML tag `type` attribute: 'text', 'password', 'search', 'email'
+ * or 'url'. Ignored if `multiline` is true. (default: 'text')
+ *
+ * Some values of `type` result in additional behaviors:
+ * - `search`: implies `icon: 'search'` and `indicator: 'clear'`; when clicked, the indicator
+ * empties the text field
* @param string $config['placeholder'] Placeholder text
* @param boolean $config['autofocus'] Ask the browser to focus this widget, using the 'autofocus'
* HTML attribute (default: false)
* @param boolean $config['readOnly'] Prevent changes (default: false)
* @param number $config['maxLength'] Maximum allowed number of characters to input
* @param boolean $config['multiline'] Allow multiple lines of text (default: false)
- * @param boolean $config['required'] Mark the field as required (default: false)
+ * @param int $config['rows'] If multiline, number of visible lines in textarea
+ * @param boolean $config['required'] Mark the field as required.
+ * Implies `indicator: 'required'`. (default: false)
+ * @param boolean $config['autocomplete'] If the field should support autocomplete
+ * or not (default: true)
*/
public function __construct( array $config = array() ) {
// Config initialization
$config = array_merge( array(
+ 'type' => 'text',
'readOnly' => false,
'autofocus' => false,
'required' => false,
+ 'autocomplete' => true,
), $config );
+ if ( $config['type'] === 'search' ) {
+ if ( !array_key_exists( 'icon', $config ) ) {
+ $config['icon'] = 'search';
+ }
+ }
+ if ( $config['required'] ) {
+ if ( !array_key_exists( 'indicator', $config ) ) {
+ $config['indicator'] = 'required';
+ }
+ }
// Parent constructor
parent::__construct( $config );
// Properties
+ $this->type = $this->getSaneType( $config );
$this->multiline = isset( $config['multiline'] ) ? (bool)$config['multiline'] : false;
// Mixins
@@ -54,7 +83,7 @@ class TextInputWidget extends InputWidget {
// Initialization
$this
- ->addClasses( array( 'oo-ui-textInputWidget' ) )
+ ->addClasses( array( 'oo-ui-textInputWidget', 'oo-ui-textInputWidget-type-' . $this->type ) )
->appendContent( $this->icon, $this->indicator );
$this->setReadOnly( $config['readOnly'] );
if ( isset( $config['placeholder'] ) ) {
@@ -69,6 +98,12 @@ class TextInputWidget extends InputWidget {
if ( $config['required'] ) {
$this->input->setAttributes( array( 'required' => 'required', 'aria-required' => 'true' ) );
}
+ if ( !$config['autocomplete'] ) {
+ $this->input->setAttributes( array( 'autocomplete' => 'off' ) );
+ }
+ if ( $this->multiline && isset( $config['rows'] ) ) {
+ $this->input->setAttributes( array( 'rows' => $config['rows'] ) );
+ }
}
/**
@@ -101,13 +136,23 @@ class TextInputWidget extends InputWidget {
if ( isset( $config['multiline'] ) && $config['multiline'] ) {
return new Tag( 'textarea' );
} else {
- $type = isset( $config['type'] ) ? $config['type'] : 'text';
$input = new Tag( 'input' );
- $input->setAttributes( array( 'type' => $type ) );
+ $input->setAttributes( array( 'type' => $this->getSaneType( $config ) ) );
return $input;
}
}
+ private function getSaneType( $config ) {
+ if ( isset( $config['multiline'] ) && $config['multiline'] ) {
+ return 'multiline';
+ } else {
+ $type = in_array( $config['type'], array( 'text', 'password', 'search', 'email', 'url' ) ) ?
+ $config['type'] :
+ 'text';
+ return $type;
+ }
+ }
+
/**
* Check if input supports multiple lines.
*
@@ -120,6 +165,10 @@ class TextInputWidget extends InputWidget {
public function getConfig( &$config ) {
if ( $this->isMultiline() ) {
$config['multiline'] = true;
+ $rows = $this->input->getAttribute( 'rows' );
+ if ( $rows !== null ) {
+ $config['rows'] = $rows;
+ }
} else {
$type = $this->input->getAttribute( 'type' );
if ( $type !== 'text' ) {
@@ -146,6 +195,10 @@ class TextInputWidget extends InputWidget {
if ( ( $required !== null ) || ( $ariarequired !== null ) ) {
$config['required'] = true;
}
+ $autocomplete = $this->input->getAttribute( 'autocomplete' );
+ if ( $autocomplete !== null ) {
+ $config['autocomplete'] = false;
+ }
return parent::getConfig( $config );
}
}