r55911 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55910‎ | r55911 | r55912 >
Date:01:48, 7 September 2009
Author:simetrical
Status:ok
Tags:
Comment:
Don't output for= that doesn't point anywhere

This fixes an HTML validity issue with HTMLForm.
Modified paths:
  • /trunk/phase3/includes/HTMLForm.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/HTMLForm.php
@@ -384,6 +384,16 @@
385385 return $value;
386386 }
387387
 388+ /**
 389+ * Should this field have a label, or is there no input element with the
 390+ * appropriate id for the label to point to?
 391+ *
 392+ * @return bool True to output a label, false to suppress
 393+ */
 394+ protected function needsLabel() {
 395+ return true;
 396+ }
 397+
388398 function loadDataFromRequest( $request ) {
389399 if( $request->getCheck( $this->mName ) ) {
390400 return $request->getText( $this->mName );
@@ -455,8 +465,14 @@
456466
457467 $html = '';
458468
 469+ # Don't output a for= attribute for labels with no associated input.
 470+ # Kind of hacky here, possibly we don't want these to be <label>s at all.
 471+ $for = array();
 472+ if ( $this->needsLabel() ) {
 473+ $for['for'] = $this->mID;
 474+ }
459475 $html .= Html::rawElement( 'td', array( 'class' => 'mw-label' ),
460 - Html::rawElement( 'label', array( 'for' => $this->mID ), $this->getLabel() )
 476+ Html::rawElement( 'label', $for, $this->getLabel() )
461477 );
462478 $html .= Html::rawElement( 'td', array( 'class' => 'mw-input' ),
463479 $this->getInputHTML( $value ) ."\n$errors" );
@@ -837,6 +853,10 @@
838854 return array();
839855 }
840856 }
 857+
 858+ protected function needsLabel() {
 859+ return false;
 860+ }
841861 }
842862
843863 class HTMLRadioField extends HTMLFormField {
@@ -886,6 +906,10 @@
887907
888908 return $html;
889909 }
 910+
 911+ protected function needsLabel() {
 912+ return false;
 913+ }
890914 }
891915
892916 class HTMLInfoField extends HTMLFormField {
@@ -906,4 +930,8 @@
907931
908932 return parent::getTableRow( $value );
909933 }
 934+
 935+ protected function needsLabel() {
 936+ return false;
 937+ }
910938 }

Status & tagging log