r93742 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93741‎ | r93742 | r93743 >
Date:13:56, 2 August 2011
Author:siebrand
Status:ok
Tags:
Comment:
Update whitespace, braces.
Modified paths:
  • /trunk/phase3/includes/Xml.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Xml.php
@@ -360,7 +360,7 @@
361361 public static function label( $label, $id, $attribs = array() ) {
362362 $a = array( 'for' => $id );
363363
364 - # FIXME avoid copy pasting below:
 364+ # FIXME avoid copy pasting below:
365365 if( isset( $attribs['class'] ) ){
366366 $a['class'] = $attribs['class'];
367367 }
@@ -506,19 +506,24 @@
507507 $optgroup = false;
508508 }
509509 }
 510+
510511 if( $optgroup ) $options .= self::closeElement('optgroup');
511512
512513 $attribs = array();
 514+
513515 if( $name ) {
514516 $attribs['id'] = $name;
515517 $attribs['name'] = $name;
516518 }
 519+
517520 if( $class ) {
518521 $attribs['class'] = $class;
519522 }
 523+
520524 if( $tabindex ) {
521525 $attribs['tabindex'] = $tabindex;
522526 }
 527+
523528 return Xml::openElement( 'select', $attribs )
524529 . "\n"
525530 . $options
@@ -537,9 +542,11 @@
538543 */
539544 public static function fieldset( $legend = false, $content = false, $attribs = array() ) {
540545 $s = Xml::openElement( 'fieldset', $attribs ) . "\n";
 546+
541547 if ( $legend ) {
542548 $s .= Xml::element( 'legend', null, $legend ) . "\n";
543549 }
 550+
544551 if ( $content !== false ) {
545552 $s .= $content . "\n";
546553 $s .= Xml::closeElement( 'fieldset' ) . "\n";
@@ -600,6 +607,7 @@
601608 "\xe2\x80\x8c" => "\\u200c", // ZERO WIDTH NON-JOINER
602609 "\xe2\x80\x8d" => "\\u200d", // ZERO WIDTH JOINER
603610 );
 611+
604612 return strtr( $string, $pairs );
605613 }
606614
@@ -641,6 +649,7 @@
642650 if ( $s != '{' ) {
643651 $s .= ', ';
644652 }
 653+
645654 $s .= '"' . self::escapeJsString( $name ) . '": ' .
646655 self::encodeJsVar( $elt );
647656 }
@@ -666,19 +675,22 @@
667676 public static function encodeJsCall( $name, $args ) {
668677 $s = "$name(";
669678 $first = true;
 679+
670680 foreach ( $args as $arg ) {
671681 if ( $first ) {
672682 $first = false;
673683 } else {
674684 $s .= ', ';
675685 }
 686+
676687 $s .= Xml::encodeJsVar( $arg );
677688 }
 689+
678690 $s .= ");\n";
 691+
679692 return $s;
680693 }
681694
682 -
683695 /**
684696 * Check if a string is well-formed XML.
685697 * Must include the surrounding tag.
@@ -702,7 +714,9 @@
703715 xml_parser_free( $parser );
704716 return false;
705717 }
 718+
706719 xml_parser_free( $parser );
 720+
707721 return true;
708722 }
709723
@@ -720,6 +734,7 @@
721735 '<html>' .
722736 $text .
723737 '</html>';
 738+
724739 return Xml::isWellFormed( $html );
725740 }
726741
@@ -765,7 +780,6 @@
766781
767782 $form .= "</tbody></table>";
768783
769 -
770784 return $form;
771785 }
772786
@@ -778,19 +792,31 @@
779793 */
780794 public static function buildTable( $rows, $attribs = array(), $headers = null ) {
781795 $s = Xml::openElement( 'table', $attribs );
 796+
782797 if ( is_array( $headers ) ) {
783798 foreach( $headers as $id => $header ) {
784799 $attribs = array();
785 - if ( is_string( $id ) ) $attribs['id'] = $id;
 800+
 801+ if ( is_string( $id ) ) {
 802+ $attribs['id'] = $id;
 803+ }
 804+
786805 $s .= Xml::element( 'th', $attribs, $header );
787806 }
788807 }
 808+
789809 foreach( $rows as $id => $row ) {
790810 $attribs = array();
791 - if ( is_string( $id ) ) $attribs['id'] = $id;
 811+
 812+ if ( is_string( $id ) ) {
 813+ $attribs['id'] = $id;
 814+ }
 815+
792816 $s .= Xml::buildTableRow( $attribs, $row );
793817 }
 818+
794819 $s .= Xml::closeElement( 'table' );
 820+
795821 return $s;
796822 }
797823
@@ -802,12 +828,20 @@
803829 */
804830 public static function buildTableRow( $attribs, $cells ) {
805831 $s = Xml::openElement( 'tr', $attribs );
 832+
806833 foreach( $cells as $id => $cell ) {
 834+
807835 $attribs = array();
808 - if ( is_string( $id ) ) $attribs['id'] = $id;
 836+
 837+ if ( is_string( $id ) ) {
 838+ $attribs['id'] = $id;
 839+ }
 840+
809841 $s .= Xml::element( 'td', $attribs, $cell );
810842 }
 843+
811844 $s .= Xml::closeElement( 'tr' );
 845+
812846 return $s;
813847 }
814848 }
@@ -821,9 +855,11 @@
822856 if ( $name ) {
823857 $this->setAttribute( 'name', $name );
824858 }
 859+
825860 if ( $id ) {
826861 $this->setAttribute( 'id', $id );
827862 }
 863+
828864 if ( $default !== false ) {
829865 $this->default = $default;
830866 }
@@ -863,6 +899,7 @@
864900 public function addOption( $name, $value = false ) {
865901 // Stab stab stab
866902 $value = ($value !== false) ? $value : $name;
 903+
867904 $this->options[] = array( $name => $value );
868905 }
869906
@@ -888,6 +925,7 @@
889926 */
890927 static function formatOptions( $options, $default = false ) {
891928 $data = '';
 929+
892930 foreach( $options as $label => $value ) {
893931 if ( is_array( $value ) ) {
894932 $contents = self::formatOptions( $value, $default );
@@ -905,12 +943,13 @@
906944 */
907945 public function getHTML() {
908946 $contents = '';
 947+
909948 foreach ( $this->options as $options ) {
910949 $contents .= self::formatOptions( $options, $this->default );
911950 }
 951+
912952 return Xml::tags( 'select', $this->attributes, rtrim( $contents ) );
913953 }
914 -
915954 }
916955
917956 /**

Status & tagging log