summaryrefslogtreecommitdiff
path: root/includes/htmlform/HTMLRadioField.php
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-05-01 15:12:12 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-05-01 15:12:12 -0400
commitc9aa36da061816dee256a979c2ff8d2ee41824d9 (patch)
tree29f7002b80ee984b488bd047dbbd80b36bf892e9 /includes/htmlform/HTMLRadioField.php
parentb4274e0e33eafb5e9ead9d949ebf031a9fb8363b (diff)
parentd1ba966140d7a60cd5ae4e8667ceb27c1a138592 (diff)
Merge branch 'archwiki'
# Conflicts: # skins/ArchLinux.php # skins/ArchLinux/archlogo.gif
Diffstat (limited to 'includes/htmlform/HTMLRadioField.php')
-rw-r--r--includes/htmlform/HTMLRadioField.php71
1 files changed, 71 insertions, 0 deletions
diff --git a/includes/htmlform/HTMLRadioField.php b/includes/htmlform/HTMLRadioField.php
new file mode 100644
index 00000000..8765407b
--- /dev/null
+++ b/includes/htmlform/HTMLRadioField.php
@@ -0,0 +1,71 @@
+<?php
+
+/**
+ * Radio checkbox fields.
+ */
+class HTMLRadioField extends HTMLFormField {
+ function validate( $value, $alldata ) {
+ $p = parent::validate( $value, $alldata );
+
+ if ( $p !== true ) {
+ return $p;
+ }
+
+ if ( !is_string( $value ) && !is_int( $value ) ) {
+ return false;
+ }
+
+ $validOptions = HTMLFormField::flattenOptions( $this->getOptions() );
+
+ if ( in_array( strval( $value ), $validOptions, true ) ) {
+ return true;
+ } else {
+ return $this->msg( 'htmlform-select-badoption' )->parse();
+ }
+ }
+
+ /**
+ * This returns a block of all the radio options, in one cell.
+ * @see includes/HTMLFormField#getInputHTML()
+ *
+ * @param string $value
+ *
+ * @return string
+ */
+ function getInputHTML( $value ) {
+ $html = $this->formatOptions( $this->getOptions(), strval( $value ) );
+
+ return $html;
+ }
+
+ function formatOptions( $options, $value ) {
+ $html = '';
+
+ $attribs = $this->getAttributes( array( 'disabled', 'tabindex' ) );
+ $elementFunc = array( 'Html', $this->mOptionsLabelsNotFromMessage ? 'rawElement' : 'element' );
+
+ # @todo Should this produce an unordered list perhaps?
+ foreach ( $options as $label => $info ) {
+ if ( is_array( $info ) ) {
+ $html .= Html::rawElement( 'h1', array(), $label ) . "\n";
+ $html .= $this->formatOptions( $info, $value );
+ } else {
+ $id = Sanitizer::escapeId( $this->mID . "-$info" );
+ $radio = Xml::radio( $this->mName, $info, $info === $value, $attribs + array( 'id' => $id ) );
+ $radio .= '&#160;' . call_user_func( $elementFunc, 'label', array( 'for' => $id ), $label );
+
+ $html .= ' ' . Html::rawElement(
+ 'div',
+ array( 'class' => 'mw-htmlform-flatlist-item' ),
+ $radio
+ );
+ }
+ }
+
+ return $html;
+ }
+
+ protected function needsLabel() {
+ return false;
+ }
+}