r101358 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101357‎ | r101358 | r101359 >
Date:14:41, 31 October 2011
Author:catrope
Status:ok
Tags:
Comment:
On the preferences form, make preferences and other items at the top level of a section (e.g. with 'section' => 'foo') appear above rather than below subsections (e.g. stuff with 'section' => 'foo/bar'). This seems like natural behavior to me, but for some reason HTMLForm had it the other way around. I left the default behavior unchanged in HTMLForm and changed it only in PreferencesForm.

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.
Modified paths:
  • /trunk/phase3/includes/HTMLForm.php (modified) (history)
  • /trunk/phase3/includes/Preferences.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/HTMLForm.php
@@ -113,6 +113,15 @@
114114 protected $mButtons = array();
115115
116116 protected $mWrapperLegend = false;
 117+
 118+ /**
 119+ * If true, sections that contain both fields and subsections will
 120+ * render their subsections before their fields.
 121+ *
 122+ * Subclasses may set this to false to render subsections after fields
 123+ * instead.
 124+ */
 125+ protected $mSubSectionBeforeFields = true;
117126
118127 /**
119128 * Build a new HTMLForm from an array of field attributes
@@ -775,7 +784,11 @@
776785 $tableHtml = Html::rawElement( 'table', $attribs,
777786 Html::rawElement( 'tbody', array(), "\n$tableHtml\n" ) ) . "\n";
778787
779 - return $subsectionHtml . "\n" . $tableHtml;
 788+ if ( $this->mSubSectionBeforeFields ) {
 789+ return $subsectionHtml . "\n" . $tableHtml;
 790+ } else {
 791+ return $tableHtml . "\n" . $subsectionHtml;
 792+ }
780793 }
781794
782795 /**
Index: trunk/phase3/includes/Preferences.php
@@ -1487,6 +1487,9 @@
14881488
14891489 /** Some tweaks to allow js prefs to work */
14901490 class PreferencesForm extends HTMLForm {
 1491+ // Override default value from HTMLForm
 1492+ protected $mSubSectionBeforeFields = false;
 1493+
14911494 private $modifiedUser;
14921495
14931496 public function setModifiedUser( $user ) {

Status & tagging log