diff options
Diffstat (limited to 'includes/htmlform/HTMLCheckField.php')
-rw-r--r-- | includes/htmlform/HTMLCheckField.php | 62 |
1 files changed, 58 insertions, 4 deletions
diff --git a/includes/htmlform/HTMLCheckField.php b/includes/htmlform/HTMLCheckField.php index 4942327f..9666c4ea 100644 --- a/includes/htmlform/HTMLCheckField.php +++ b/includes/htmlform/HTMLCheckField.php @@ -20,9 +20,15 @@ class HTMLCheckField extends HTMLFormField { $attr['class'] = $this->mClass; } - $chkLabel = Xml::check( $this->mName, $value, $attr ) - . ' ' - . Html::rawElement( 'label', array( 'for' => $this->mID ), $this->mLabel ); + $attrLabel = array( 'for' => $this->mID ); + if ( isset( $attr['title'] ) ) { + // propagate tooltip to label + $attrLabel['title'] = $attr['title']; + } + + $chkLabel = Xml::check( $this->mName, $value, $attr ) . + ' ' . + Html::rawElement( 'label', $attrLabel, $this->mLabel ); if ( $wgUseMediaWikiUIEverywhere || $this->mParent instanceof VFormHTMLForm ) { $chkLabel = Html::rawElement( @@ -36,12 +42,60 @@ class HTMLCheckField extends HTMLFormField { } /** + * Get the OOUI version of this field. + * @since 1.26 + * @param string $value + * @return OOUI\\CheckboxInputWidget The checkbox widget. + */ + public function getInputOOUI( $value ) { + if ( !empty( $this->mParams['invert'] ) ) { + $value = !$value; + } + + $attr = $this->getTooltipAndAccessKey(); + $attr['id'] = $this->mID; + $attr['name'] = $this->mName; + + $attr += $this->getAttributes( array( 'disabled', 'tabindex' ), array( 'tabindex' => 'tabIndex' ) ); + + if ( $this->mClass !== '' ) { + $attr['classes'] = array( $this->mClass ); + } + + $attr['selected'] = $value; + $attr['value'] = '1'; // Nasty hack, but needed to make this work + + return new OOUI\CheckboxInputWidget( $attr ); + } + + /** * For a checkbox, the label goes on the right hand side, and is * added in getInputHTML(), rather than HTMLFormField::getRow() + * + * ...unless OOUI is being used, in which case we actually return + * the label here. + * * @return string */ function getLabel() { - return ' '; + if ( $this->mParent instanceof OOUIHTMLForm ) { + return $this->mLabel; + } elseif ( + $this->mParent instanceof HTMLForm && + $this->mParent->getDisplayFormat() === 'div' + ) { + return ''; + } else { + return ' '; + } + } + + /** + * Get label alignment when generating field for OOUI. + * @return string 'left', 'right', 'top' or 'inline' + */ + protected function getLabelAlignOOUI() { + return 'inline'; } /** |