Allow setting the ID of the main table in HTMLForm
authorAlexandre Emsenhuber <ialex.wiki@gmail.com>
Mon, 29 Apr 2013 06:13:05 +0000 (08:13 +0200)
committerAaron Schulz <aschulz@wikimedia.org>
Tue, 28 May 2013 21:05:35 +0000 (21:05 +0000)
- Added new method HTMLForm::setTableId() to allow to set the ID
  of the main table (or the outermost <div> element depending on
  the format).
- Changed the second parameter of HTMLForm::displaySection()
  to take the full ID so that the one set with setTableId()
  will not get prefixed with "mw-htmlform-"

Note: If someone has a better idea for the name of that method
(since it also applies to <div> elements), please tell me it :)

Change-Id: Id01bd0fa44512b0320f3c3ff79627e8a9bccd5bb

includes/HTMLForm.php

index 5e3bb06..2bf7436 100644 (file)
@@ -140,6 +140,7 @@ class HTMLForm extends ContextSource {
        protected $mSectionFooters = array();
        protected $mPost = '';
        protected $mId;
+       protected $mTableId = '';
 
        protected $mSubmitID;
        protected $mSubmitName;
@@ -742,7 +743,7 @@ class HTMLForm extends ContextSource {
         * @return String
         */
        function getBody() {
-               return $this->displaySection( $this->mFieldTree );
+               return $this->displaySection( $this->mFieldTree, $this->mTableId );
        }
 
        /**
@@ -871,6 +872,18 @@ class HTMLForm extends ContextSource {
                return $this;
        }
 
+       /**
+        * Set the id of the \<table\> or outermost \<div\> element.
+        *
+        * @since 1.22
+        * @param string $id new value of the id attribute, or "" to remove
+        * @return HTMLForm $this for chaining calls
+        */
+       public function setTableId( $id ) {
+               $this->mTableId = $id;
+               return $this;
+       }
+
        /**
         * @param string $id DOM id for the form
         * @return HTMLForm $this for chaining calls (since 1.20)
@@ -879,6 +892,7 @@ class HTMLForm extends ContextSource {
                $this->mId = $id;
                return $this;
        }
+
        /**
         * Prompt the whole form to be wrapped in a "<fieldset>", with
         * this text as its "<legend>" element.
@@ -977,7 +991,7 @@ class HTMLForm extends ContextSource {
                                        $hasLabel = true;
                                }
                        } elseif ( is_array( $value ) ) {
-                               $section = $this->displaySection( $value, $key, "$fieldsetIDPrefix$key-" );
+                               $section = $this->displaySection( $value, "mw-htmlform-$key", "$fieldsetIDPrefix$key-" );
                                $legend = $this->getLegend( $key );
                                if ( isset( $this->mSectionHeaders[$key] ) ) {
                                        $section = $this->mSectionHeaders[$key] . $section;
@@ -1005,7 +1019,7 @@ class HTMLForm extends ContextSource {
                        );
 
                        if ( $sectionName ) {
-                               $attribs['id'] = Sanitizer::escapeId( "mw-htmlform-$sectionName" );
+                               $attribs['id'] = Sanitizer::escapeId( $sectionName );
                        }
 
                        if ( $displayFormat === 'table' ) {