+
+ /**
+ * Generate a form (without the opening form element).
+ * Output optionally includes a submit button.
+ * @param $fields Associative array, key is message corresponding to a description for the field (colon is in the message), value is appropriate input.
+ * @param $submitLabel A message containing a label for the submit button.
+ * @return string HTML form.
+ */
+ public static function buildForm( $fields, $submitLabel = null ) {
+ $form = '';
+ $form .= "<table><tbody>";
+
+ foreach( $fields as $labelmsg => $input ) {
+ $id = "mw-$labelmsg";
+
+ $form .= Xml::openElement( 'tr', array( 'id' => $id ) );
+ $form .= Xml::tags( 'td', array('class' => 'mw-label'), wfMsgExt( $labelmsg, array('parseinline') ) );
+ $form .= Xml::openElement( 'td', array( 'class' => 'mw-input' ) ) . $input . Xml::closeElement( 'td' );
+ $form .= Xml::closeElement( 'tr' );
+ }
+
+ if( $submitLabel ) {
+ $form .= Xml::openElement( 'tr', array( 'id' => $id ) );
+ $form .= Xml::tags( 'td', array(), '' );
+ $form .= Xml::openElement( 'td', array( 'class' => 'mw-submit' ) ) . Xml::submitButton( wfMsg( $submitLabel ) ) . Xml::closeElement( 'td' );
+ $form .= Xml::closeElement( 'tr' );
+ }
+
+ $form .= "</tbody></table>";
+
+
+ return $form;
+ }
+
+ /**
+ * Build a table of data
+ * @param array $rows An array of arrays of strings, each to be a row in a table
+ * @param array $attribs Attributes to apply to the table tag [optional]
+ * @param array $headers An array of strings to use as table headers [optional]
+ * @return string
+ */
+ public static function buildTable( $rows, $attribs = array(), $headers = null ) {
+ $s = Xml::openElement( 'table', $attribs );
+ if ( is_array( $headers ) ) {
+ foreach( $headers as $id => $header ) {
+ $attribs = array();
+ if ( is_string( $id ) ) $attribs['id'] = $id;
+ $s .= Xml::element( 'th', $attribs, $header );
+ }
+ }
+ foreach( $rows as $id => $row ) {
+ $attribs = array();
+ if ( is_string( $id ) ) $attribs['id'] = $id;
+ $s .= Xml::buildTableRow( $attribs, $row );
+ }
+ $s .= Xml::closeElement( 'table' );
+ return $s;
+ }
+
+ /**
+ * Build a row for a table
+ * @param array $cells An array of strings to put in <td>
+ * @return string
+ */
+ public static function buildTableRow( $attribs, $cells ) {
+ $s = Xml::openElement( 'tr', $attribs );
+ foreach( $cells as $id => $cell ) {
+ $attribs = array();
+ if ( is_string( $id ) ) $attribs['id'] = $id;
+ $s .= Xml::element( 'td', $attribs, $cell );
+ }
+ $s .= Xml::closeElement( 'tr' );
+ return $s;
+ }