r66504 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66503‎ | r66504 | r66505 >
Date:23:57, 15 May 2010
Author:siebrand
Status:ok (Comments)
Tags:
Comment:
HTML5 fix: Bad value for attribute size on element input: The empty string is not a valid positive integer.

Spotted in Special:BlockList. Also fixed when attribute value is false.
Modified paths:
  • /trunk/phase3/includes/Xml.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Xml.php
@@ -173,7 +173,7 @@
174174 . implode( "\n", $options )
175175 . self::closeElement( 'select' );
176176 }
177 -
 177+
178178 /**
179179 * @param $year Integer
180180 * @param $month Integer
@@ -248,7 +248,7 @@
249249 * @param $text content of the element, will be escaped
250250 * @param $class class name of the span element
251251 * @param $attribs other attributes
252 - * @return string
 252+ * @return string
253253 */
254254 public static function span( $text, $class, $attribs=array() ) {
255255 return self::element( 'span', array( 'class' => $class ) + $attribs, $text );
@@ -260,7 +260,7 @@
261261 * @param $class class name of the span element
262262 * @param $tag element name
263263 * @param $attribs other attributes
264 - * @return string
 264+ * @return string
265265 */
266266 public static function wrapClass( $text, $class, $tag='span', $attribs=array() ) {
267267 return self::tags( $tag, array( 'class' => $class ) + $attribs, $text );
@@ -275,10 +275,18 @@
276276 * @return string HTML
277277 */
278278 public static function input( $name, $size=false, $value=false, $attribs=array() ) {
279 - return self::element( 'input', array(
280 - 'name' => $name,
281 - 'size' => $size,
282 - 'value' => $value ) + $attribs );
 279+ $attributes = array();
 280+ if( $size ) {
 281+ $attributes['size'] = $size;
 282+ }
 283+
 284+ if( $size ) {
 285+ $attributes['value'] = $value;
 286+ }
 287+
 288+ $attributes['name'] = $name;
 289+
 290+ return self::element( 'input', $attributes + $attribs );
283291 }
284292
285293 /**
@@ -337,7 +345,7 @@
338346 * Convenience function to build an HTML form label
339347 * @param $label text of the label
340348 * @param $id
341 - * @param $attribs Array, other attributes
 349+ * @param $attribs Array, other attributes
342350 * @return string HTML
343351 */
344352 public static function label( $label, $id, $attribs=array() ) {
@@ -506,7 +514,7 @@
507515
508516 return $s;
509517 }
510 -
 518+
511519 /**
512520 * Shortcut for creating textareas.
513521 *
@@ -660,7 +668,7 @@
661669 array( '"', '>', '<' ),
662670 $in );
663671 }
664 -
 672+
665673 /**
666674 * Generate a form (without the opening form element).
667675 * Output optionally includes a submit button.
@@ -671,7 +679,7 @@
672680 public static function buildForm( $fields, $submitLabel = null ) {
673681 $form = '';
674682 $form .= "<table><tbody>";
675 -
 683+
676684 foreach( $fields as $labelmsg => $input ) {
677685 $id = "mw-$labelmsg";
678686 $form .= Xml::openElement( 'tr', array( 'id' => $id ) );
@@ -686,13 +694,13 @@
687695 $form .= Xml::openElement( 'td', array( 'class' => 'mw-submit' ) ) . Xml::submitButton( wfMsg( $submitLabel ) ) . Xml::closeElement( 'td' );
688696 $form .= Xml::closeElement( 'tr' );
689697 }
690 -
 698+
691699 $form .= "</tbody></table>";
692700
693 -
 701+
694702 return $form;
695703 }
696 -
 704+
697705 /**
698706 * Build a table of data
699707 * @param $rows An array of arrays of strings, each to be a row in a table
@@ -717,7 +725,7 @@
718726 $s .= Xml::closeElement( 'table' );
719727 return $s;
720728 }
721 -
 729+
722730 /**
723731 * Build a row for a table
724732 * @param $attribs An array of attributes to apply to the tr tag
@@ -768,7 +776,7 @@
769777 $value = ($value !== false) ? $value : $name;
770778 $this->options[] = Xml::option( $name, $value, $value === $this->default );
771779 }
772 -
 780+
773781 // This accepts an array of form
774782 // label => value
775783 // label => ( label => value, label => value )
@@ -778,7 +786,7 @@
779787
780788 // This accepts an array of form
781789 // label => value
782 - // label => ( label => value, label => value )
 790+ // label => ( label => value, label => value )
783791 static function formatOptions( $options, $default = false ) {
784792 $data = '';
785793 foreach( $options as $label => $value ) {
@@ -789,7 +797,7 @@
790798 $data .= Xml::option( $label, $value, $value === $default ) . "\n";
791799 }
792800 }
793 -
 801+
794802 return $data;
795803 }
796804

Follow-up revisions

RevisionCommit summaryAuthorDate
r66516Fix for r66504 per Nikerabbit's CR. Actually copy-paste and not adjust issue.siebrand08:26, 16 May 2010
r67760Make r66504 a little more concisesimetrical20:49, 9 June 2010

Comments

#Comment by Nikerabbit (talk | contribs)   06:57, 16 May 2010
+               if( $size ) {
+                       $attributes['value'] = $value;

Is that a bug?

#Comment by Siebrand (talk | contribs)   08:26, 16 May 2010

Yes. My bad; fixed in r66516.

Status & tagging log