[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/htmlform/ -> HTMLRadioField.php (source)

   1  <?php
   2  
   3  /**
   4   * Radio checkbox fields.
   5   */
   6  class HTMLRadioField extends HTMLFormField {
   7  	function validate( $value, $alldata ) {
   8          $p = parent::validate( $value, $alldata );
   9  
  10          if ( $p !== true ) {
  11              return $p;
  12          }
  13  
  14          if ( !is_string( $value ) && !is_int( $value ) ) {
  15              return false;
  16          }
  17  
  18          $validOptions = HTMLFormField::flattenOptions( $this->getOptions() );
  19  
  20          if ( in_array( strval( $value ), $validOptions, true ) ) {
  21              return true;
  22          } else {
  23              return $this->msg( 'htmlform-select-badoption' )->parse();
  24          }
  25      }
  26  
  27      /**
  28       * This returns a block of all the radio options, in one cell.
  29       * @see includes/HTMLFormField#getInputHTML()
  30       *
  31       * @param string $value
  32       *
  33       * @return string
  34       */
  35  	function getInputHTML( $value ) {
  36          $html = $this->formatOptions( $this->getOptions(), strval( $value ) );
  37  
  38          return $html;
  39      }
  40  
  41  	function formatOptions( $options, $value ) {
  42          $html = '';
  43  
  44          $attribs = $this->getAttributes( array( 'disabled', 'tabindex' ) );
  45          $elementFunc = array( 'Html', $this->mOptionsLabelsNotFromMessage ? 'rawElement' : 'element' );
  46  
  47          # @todo Should this produce an unordered list perhaps?
  48          foreach ( $options as $label => $info ) {
  49              if ( is_array( $info ) ) {
  50                  $html .= Html::rawElement( 'h1', array(), $label ) . "\n";
  51                  $html .= $this->formatOptions( $info, $value );
  52              } else {
  53                  $id = Sanitizer::escapeId( $this->mID . "-$info" );
  54                  $radio = Xml::radio( $this->mName, $info, $info === $value, $attribs + array( 'id' => $id ) );
  55                  $radio .= '&#160;' . call_user_func( $elementFunc, 'label', array( 'for' => $id ), $label );
  56  
  57                  $html .= ' ' . Html::rawElement(
  58                      'div',
  59                      array( 'class' => 'mw-htmlform-flatlist-item' ),
  60                      $radio
  61                  );
  62              }
  63          }
  64  
  65          return $html;
  66      }
  67  
  68  	protected function needsLabel() {
  69          return false;
  70      }
  71  }


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1