Add support for Number grouping(commafy) based on CLDR number grouping patterns like...
[lhc/web/wiklou.git] / includes / HTMLForm.php
index ec038c9..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.19.
+        * @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 ) {
@@ -317,6 +318,7 @@ class HTMLForm {
        /**
         * Add header text, inside the form.
         * @param $msg String complete text of message to display
+        * @param $section The section to add the header to
         */
        function addHeaderText( $msg, $section = null ) {
                if ( is_null( $section ) ) {
@@ -332,6 +334,7 @@ class HTMLForm {
        /**
         * Add footer text, inside the form.
         * @param $msg String complete text of message to display
+        * @param $section string The section to add the footer text to
         */
        function addFooterText( $msg, $section = null ) {
                if ( is_null( $section ) ) {
@@ -427,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";
@@ -458,7 +467,7 @@ class HTMLForm {
                }
 
                if ( isset( $this->mSubmitTooltip ) ) {
-                       $attribs += Linker::tooltipAndAccessKeyAttribs( $this->mSubmitTooltip );
+                       $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
                }
 
                $attribs['class'] = 'mw-htmlform-submit';
@@ -624,15 +633,15 @@ class HTMLForm {
         */
        function getTitle() {
                return $this->mTitle === false
-                       ? $this->getContext()->title
+                       ? $this->getContext()->getTitle()
                        : $this->mTitle;
        }
 
        /**
-        * @return RequestContext
+        * @return IContextSource
         */
        public function getContext(){
-               return $this->mContext instanceof RequestContext
+               return $this->mContext instanceof IContextSource
                        ? $this->mContext
                        : RequestContext::getMain();
        }
@@ -641,21 +650,21 @@ class HTMLForm {
         * @return OutputPage
         */
        public function getOutput(){
-               return $this->getContext()->output;
+               return $this->getContext()->getOutput();
        }
 
        /**
         * @return WebRequest
         */
        public function getRequest(){
-               return $this->getContext()->request;
+               return $this->getContext()->getRequest();
        }
 
        /**
         * @return User
         */
        public function getUser(){
-               return $this->getContext()->user;
+               return $this->getContext()->getUser();
        }
 
        /**
@@ -672,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 = '' ) {
+       function displaySection( $fields, $sectionName = '', $fieldsetIDPrefix = '' ) {
                $tableHtml = '';
                $subsectionHtml = '';
                $hasLeftColumn = false;
@@ -686,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 );
@@ -697,7 +709,11 @@ class HTMLForm {
                                if ( isset( $this->mSectionFooters[$key] ) ) {
                                        $section .= $this->mSectionFooters[$key];
                                }
-                               $subsectionHtml .= Xml::fieldset( $legend, $section ) . "\n";
+                               $attributes = array();
+                               if ( $fieldsetIDPrefix ) {
+                                       $attributes['id'] = Sanitizer::escapeId( "$fieldsetIDPrefix$key" );
+                               }
+                               $subsectionHtml .= Xml::fieldset( $legend, $section, $attributes ) . "\n";
                        }
                }
 
@@ -861,7 +877,7 @@ abstract class HTMLFormField {
 
        /**
         * Initialise the object
-        * @param $params Associative Array. See HTMLForm doc for syntax.
+        * @param $params array Associative Array. See HTMLForm doc for syntax.
         */
        function __construct( $params ) {
                $this->mParams = $params;
@@ -1035,7 +1051,7 @@ abstract class HTMLFormField {
                if ( empty( $this->mParams['tooltip'] ) ) {
                        return array();
                }
-               return Linker::tooltipAndAccessKeyAttribs( $this->mParams['tooltip'] );
+               return Linker::tooltipAndAccesskeyAttribs( $this->mParams['tooltip'] );
        }
 
        /**
@@ -1369,7 +1385,8 @@ class HTMLSelectOrOtherField extends HTMLTextField {
 
        function __construct( $params ) {
                if ( !in_array( 'other', $params['options'], true ) ) {
-                       $params['options'][wfMsg( 'htmlform-selectorother-other' )] = 'other';
+                       $msg = isset( $params['other'] ) ? $params['other'] : wfMsg( 'htmlform-selectorother-other' );
+                       $params['options'][$msg] = 'other';
                }
 
                parent::__construct( $params );
@@ -1568,16 +1585,19 @@ class HTMLSelectAndOtherField extends HTMLSelectField {
        function __construct( $params ) {
                if ( array_key_exists( 'other', $params ) ) {
                } elseif( array_key_exists( 'other-message', $params ) ){
-                       $params['other'] = wfMsg( $params['other-message'] );
+                       $params['other'] = wfMessage( $params['other-message'] )->escaped();
                } else {
-                       $params['other'] = wfMsg( 'htmlform-selectorother-other' );
+                       $params['other'] = null;
                }
 
                if ( array_key_exists( 'options', $params ) ) {
                        # Options array already specified
                } elseif( array_key_exists( 'options-message', $params ) ){
                        # Generate options array from a system message
-                       $params['options'] = self::parseMessage( wfMsg( $params['options-message'], $params['other'] ) );
+                       $params['options'] = self::parseMessage(
+                               wfMessage( $params['options-message'] )->inContentLanguage()->escaped(),
+                               $params['other']
+                       );
                } else {
                        # Sulk
                        throw new MWException( 'HTMLSelectAndOtherField called without any options' );
@@ -1596,7 +1616,7 @@ class HTMLSelectAndOtherField extends HTMLSelectField {
         */
        public static function parseMessage( $string, $otherName=null ) {
                if( $otherName === null ){
-                       $otherName = wfMsg( 'htmlform-selectorother-other' );
+                       $otherName = wfMessage( 'htmlform-selectorother-other' )->escaped();
                }
 
                $optgroup = false;