On the preferences form, make preferences and other items at the top level of a secti...
authorRoan Kattouw <catrope@users.mediawiki.org>
Mon, 31 Oct 2011 14:41:02 +0000 (14:41 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Mon, 31 Oct 2011 14:41:02 +0000 (14:41 +0000)
This change is needed for my work on the Gadgets extension in the RL2 branch (one example is adding text on top of a preferences section using a dummy type=>'info' preference, you want that to show up on top, not after all the subsections). The targeted use case (sections that contain both subsections and form elements) does not occur for core preferences, and is very uncommon in extensions. I managed to find such uses in only 3 of them: CreateAPage (in unreachable code), Tasks and EditSimilar add preferences to core sections that also contain subsections.

includes/HTMLForm.php
includes/Preferences.php

index 84ae9ed..f883967 100644 (file)
@@ -113,6 +113,15 @@ class HTMLForm extends ContextSource {
        protected $mButtons = array();
 
        protected $mWrapperLegend = false;
+       
+       /**
+        * If true, sections that contain both fields and subsections will
+        * render their subsections before their fields.
+        * 
+        * Subclasses may set this to false to render subsections after fields
+        * instead.
+        */
+       protected $mSubSectionBeforeFields = true;
 
        /**
         * Build a new HTMLForm from an array of field attributes
@@ -775,7 +784,11 @@ class HTMLForm extends ContextSource {
                $tableHtml = Html::rawElement( 'table', $attribs,
                        Html::rawElement( 'tbody', array(), "\n$tableHtml\n" ) ) . "\n";
 
-               return $subsectionHtml . "\n" . $tableHtml;
+               if ( $this->mSubSectionBeforeFields ) {
+                       return $subsectionHtml . "\n" . $tableHtml;
+               } else {
+                       return $tableHtml . "\n" . $subsectionHtml;
+               }
        }
 
        /**
index a1d35be..122cbff 100644 (file)
@@ -1487,6 +1487,9 @@ class Preferences {
 
 /** Some tweaks to allow js prefs to work */
 class PreferencesForm extends HTMLForm {
+       // Override default value from HTMLForm
+       protected $mSubSectionBeforeFields = false;
+       
        private $modifiedUser;
 
        public function setModifiedUser( $user ) {