Add support for Number grouping(commafy) based on CLDR number grouping patterns like...
[lhc/web/wiklou.git] / includes / HTMLForm.php
index 63b8929..c8279bc 100644 (file)
@@ -102,7 +102,7 @@ class HTMLForm {
        protected $mSubmitText;
        protected $mSubmitTooltip;
 
-       protected $mContext; // <! RequestContext
+       protected $mContext; // <! IContextSource
        protected $mTitle;
        protected $mMethod = 'post';
 
@@ -115,12 +115,12 @@ class HTMLForm {
        /**
         * Build a new HTMLForm from an array of field attributes
         * @param $descriptor Array of Field constructs, as described above
-        * @param $context RequestContext available since 1.18, will become compulsory in 1.18.
+        * @param $context IContextSource available since 1.18, will become compulsory in 1.18.
         *     Obviates the need to call $form->setTitle()
         * @param $messagePrefix String a prefix to go in front of default messages
         */
-       public function __construct( $descriptor, /*RequestContext*/ $context = null, $messagePrefix = '' ) {
-               if( $context instanceof RequestContext ){
+       public function __construct( $descriptor, /*IContextSource*/ $context = null, $messagePrefix = '' ) {
+               if( $context instanceof IContextSource ){
                        $this->mContext = $context;
                        $this->mTitle = false; // We don't need them to set a title
                        $this->mMessagePrefix = $messagePrefix;
@@ -179,7 +179,8 @@ class HTMLForm {
 
        /**
         * Initialise a new Object for the field
-        * @param $descriptor input Descriptor, as described above
+        * @param $fieldname string
+        * @param $descriptor string input Descriptor, as described above
         * @return HTMLFormField subclass
         */
        static function loadInputFromParameters( $fieldname, $descriptor ) {
@@ -429,12 +430,18 @@ class HTMLForm {
         * @return String HTML.
         */
        function getHiddenFields() {
+               global $wgUsePathInfo;
+
                $html = '';
                if( $this->getMethod() == 'post' ){
                        $html .= Html::hidden( 'wpEditToken', $this->getUser()->editToken(), array( 'id' => 'wpEditToken' ) ) . "\n";
                        $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
                }
 
+               if ( !$wgUsePathInfo && $this->getMethod() == 'get' ) {
+                       $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
+               }
+
                foreach ( $this->mHiddenFields as $data ) {
                        list( $value, $attribs ) = $data;
                        $html .= Html::hidden( $attribs['name'], $value, $attribs ) . "\n";
@@ -631,10 +638,10 @@ class HTMLForm {
        }
 
        /**
-        * @return RequestContext
+        * @return IContextSource
         */
        public function getContext(){
-               return $this->mContext instanceof RequestContext
+               return $this->mContext instanceof IContextSource
                        ? $this->mContext
                        : RequestContext::getMain();
        }
@@ -674,9 +681,11 @@ class HTMLForm {
 
        /**
         * TODO: Document
-        * @param $fields
+        * @param $fields array of fields (either arrays or objects)
+        * @param $sectionName string ID attribute of the <table> tag for this section, ignored if empty
+        * @param $fieldsetIDPrefix string ID prefix for the <fieldset> tag of each subsection, ignored if empty
         */
-       function displaySection( $fields, $sectionName = '', $displayTitle = false ) {
+       function displaySection( $fields, $sectionName = '', $fieldsetIDPrefix = '' ) {
                $tableHtml = '';
                $subsectionHtml = '';
                $hasLeftColumn = false;
@@ -688,8 +697,9 @@ class HTMLForm {
                                        : $value->getDefault();
                                $tableHtml .= $value->getTableRow( $v );
 
-                               if ( $value->getLabel() != '&#160;' )
+                               if ( $value->getLabel() != '&#160;' ) {
                                        $hasLeftColumn = true;
+                               }
                        } elseif ( is_array( $value ) ) {
                                $section = $this->displaySection( $value, $key );
                                $legend = $this->getLegend( $key );
@@ -700,8 +710,8 @@ class HTMLForm {
                                        $section .= $this->mSectionFooters[$key];
                                }
                                $attributes = array();
-                               if ( $displayTitle ) {
-                                       $attributes["id"] = 'prefsection-' . Sanitizer::escapeId( $key, 'noninitial' );
+                               if ( $fieldsetIDPrefix ) {
+                                       $attributes['id'] = Sanitizer::escapeId( "$fieldsetIDPrefix$key" );
                                }
                                $subsectionHtml .= Xml::fieldset( $legend, $section, $attributes ) . "\n";
                        }