From: Andrew Garrett Date: Fri, 2 Jul 2010 21:20:54 +0000 (+0000) Subject: Add vertical-label option to HTMLForm, for CommunityHiring X-Git-Tag: 1.31.0-rc.0~36295 X-Git-Url: http://git.cyclocoop.org/%24self?a=commitdiff_plain;h=351e25c2111d069470c6cfae69b4d7b46e80db71;p=lhc%2Fweb%2Fwiklou.git Add vertical-label option to HTMLForm, for CommunityHiring --- diff --git a/includes/HTMLForm.php b/includes/HTMLForm.php index b5472ac0ba..145585a0a7 100644 --- a/includes/HTMLForm.php +++ b/includes/HTMLForm.php @@ -23,7 +23,7 @@ * through HTMLForm::$typeMappings to get the class name. * 'default' -- default value when the form is displayed * 'id' -- HTML id attribute - * 'cssclass' -- CSS class + * 'cssclass' -- CSS class * 'options' -- varies according to the specific object. * 'label-message' -- message key for a message to use as the label. * can be an array of msg key and then parameters to @@ -812,6 +812,14 @@ abstract class HTMLFormField { global $wgRequest; $errors = $this->validate( $value, $this->mParent->mFieldData ); + + $cellAttributes = array(); + $verticalLabel = false; + + if ( !empty($this->mParams['vertical-label']) ) { + $cellAttributes['colspan'] = 2; + $verticalLabel = true; + } if ( $errors === true || !$wgRequest->wasPosted() ) { $errors = ''; @@ -819,18 +827,30 @@ abstract class HTMLFormField { $errors = Html::rawElement( 'span', array( 'class' => 'error' ), $errors ); } - $html = $this->getLabelHtml(); - $html .= Html::rawElement( + $label = $this->getLabelHtml( $cellAttributes ); + $field = Html::rawElement( 'td', - array( 'class' => 'mw-input' ), + array( 'class' => 'mw-input' ) + $cellAttributes, $this->getInputHTML( $value ) . "\n$errors" ); - + $fieldType = get_class( $this ); + + if ($verticalLabel) { + $html = Html::rawElement( 'tr', + array( 'class' => 'mw-htmlform-vertical-label' ), $label ); + $html .= Html::rawElement( 'tr', + array( 'class' => "mw-htmlform-field-$fieldType {$this->mClass}" ), + $field ); + } else { + $html = Html::rawElement( 'tr', + array( 'class' => "mw-htmlform-field-$fieldType {$this->mClass}" ), + $label . $field ); + } $html = Html::rawElement( 'tr', - array( 'class' => "mw-htmlform-field-$fieldType {$this->mClass}" ), + array( ), $html ) . "\n"; @@ -860,7 +880,7 @@ abstract class HTMLFormField { function getLabel() { return $this->mLabel; } - function getLabelHtml() { + function getLabelHtml( $cellAttributes = array() ) { # Don't output a for= attribute for labels with no associated input. # Kind of hacky here, possibly we don't want these to be