[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4   * A checkbox field
   5   */
   6  class HTMLCheckField extends HTMLFormField {
   7  	function getInputHTML( $value ) {
   8          global $wgUseMediaWikiUIEverywhere;
   9  
  10          if ( !empty( $this->mParams['invert'] ) ) {
  11              $value = !$value;
  12          }
  13  
  14          $attr = $this->getTooltipAndAccessKey();
  15          $attr['id'] = $this->mID;
  16  
  17          $attr += $this->getAttributes( array( 'disabled', 'tabindex' ) );
  18  
  19          if ( $this->mClass !== '' ) {
  20              $attr['class'] = $this->mClass;
  21          }
  22  
  23          if ( $this->mParent->isVForm() ) {
  24              // Nest checkbox inside label.
  25              return Html::rawElement( 'label',
  26                  array(
  27                      'class' => 'mw-ui-checkbox-label'
  28                  ),
  29                  Xml::check( $this->mName, $value, $attr ) . $this->mLabel );
  30          } else {
  31              $chkLabel = Xml::check( $this->mName, $value, $attr )
  32              . '&#160;'
  33              . Html::rawElement( 'label', array( 'for' => $this->mID ), $this->mLabel );
  34  
  35              if ( $wgUseMediaWikiUIEverywhere ) {
  36                  $chkLabel = Html::rawElement(
  37                      'div',
  38                      array( 'class' => 'mw-ui-checkbox' ),
  39                      $chkLabel
  40                  );
  41              }
  42  
  43              return $chkLabel;
  44          }
  45      }
  46  
  47      /**
  48       * For a checkbox, the label goes on the right hand side, and is
  49       * added in getInputHTML(), rather than HTMLFormField::getRow()
  50       * @return string
  51       */
  52  	function getLabel() {
  53          return '&#160;';
  54      }
  55  
  56      /**
  57       * checkboxes don't need a label.
  58       * @return bool
  59       */
  60  	protected function needsLabel() {
  61          return false;
  62      }
  63  
  64      /**
  65       * @param WebRequest $request
  66       *
  67       * @return string
  68       */
  69  	function loadDataFromRequest( $request ) {
  70          $invert = false;
  71          if ( isset( $this->mParams['invert'] ) && $this->mParams['invert'] ) {
  72              $invert = true;
  73          }
  74  
  75          // GetCheck won't work like we want for checks.
  76          // Fetch the value in either one of the two following case:
  77          // - we have a valid token (form got posted or GET forged by the user)
  78          // - checkbox name has a value (false or true), ie is not null
  79          if ( $request->getCheck( 'wpEditToken' ) || $request->getVal( $this->mName ) !== null ) {
  80              // XOR has the following truth table, which is what we want
  81              // INVERT VALUE | OUTPUT
  82              // true   true  | false
  83              // false  true  | true
  84              // false  false | false
  85              // true   false | true
  86              return $request->getBool( $this->mName ) xor $invert;
  87          } else {
  88              return $this->getDefault();
  89          }
  90      }
  91  }


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