Avoid GlobalTitleFail in HTMLFormField::__construct
[lhc/web/wiklou.git] / includes / htmlform / HTMLForm.php
index 5fda7bd..df805aa 100644 (file)
@@ -115,6 +115,8 @@ class HTMLForm extends ContextSource {
                'info' => 'HTMLInfoField',
                'selectorother' => 'HTMLSelectOrOtherField',
                'selectandother' => 'HTMLSelectAndOtherField',
+               'namespaceselect' => 'HTMLSelectNamespace',
+               'tagfilter' => 'HTMLTagFilter',
                'submit' => 'HTMLSubmitField',
                'hidden' => 'HTMLHiddenField',
                'edittools' => 'HTMLEditTools',
@@ -139,6 +141,7 @@ class HTMLForm extends ContextSource {
        protected $mFieldTree;
        protected $mShowReset = false;
        protected $mShowSubmit = true;
+       protected $mSubmitModifierClass = 'mw-ui-constructive';
 
        protected $mSubmitCallback;
        protected $mValidationErrorMessage;
@@ -243,10 +246,7 @@ class HTMLForm extends ContextSource {
                                $this->mUseMultipart = true;
                        }
 
-                       $field = self::loadInputFromParameters( $fieldname, $info );
-                       // FIXME During field's construct, the parent form isn't available!
-                       // could add a 'parent' name-value to $info, could add a third parameter.
-                       $field->mParent = $this;
+                       $field = self::loadInputFromParameters( $fieldname, $info, $this );
 
                        // vform gets too much space if empty labels generate HTML.
                        if ( $this->isVForm() ) {
@@ -356,14 +356,18 @@ class HTMLForm extends ContextSource {
         *
         * @param string $fieldname Name of the field
         * @param array $descriptor Input Descriptor, as described above
+        * @param HTMLForm|null $parent Parent instance of HTMLForm
         *
         * @throws MWException
         * @return HTMLFormField Instance of a subclass of HTMLFormField
         */
-       public static function loadInputFromParameters( $fieldname, $descriptor ) {
+       public static function loadInputFromParameters( $fieldname, $descriptor, HTMLForm $parent = null ) {
                $class = self::getClassFromDescriptor( $fieldname, $descriptor );
 
                $descriptor['fieldname'] = $fieldname;
+               if ( $parent ) {
+                       $descriptor['parent'] = $parent;
+               }
 
                # @todo This will throw a fatal error whenever someone try to use
                # 'class' to feed a CSS class instead of 'cssclass'. Would be
@@ -787,9 +791,14 @@ class HTMLForm extends ContextSource {
                $this->getOutput()->preventClickjacking();
                $this->getOutput()->addModules( 'mediawiki.htmlform' );
                if ( $this->isVForm() ) {
+                       // This is required for VForm HTMLForms that use that style regardless
+                       // of wgUseMediaWikiUIEverywhere (since they pre-date it).
+                       // When wgUseMediaWikiUIEverywhere is removed, this should be consolidated
+                       // with the addModuleStyles in SpecialPage->setHeaders.
                        $this->getOutput()->addModuleStyles( array(
                                'mediawiki.ui',
                                'mediawiki.ui.button',
+                               'mediawiki.ui.input',
                        ) );
                        // @todo Should vertical form set setWrapperLegend( false )
                        // to hide ugly fieldsets?
@@ -897,7 +906,7 @@ class HTMLForm extends ContextSource {
                        $attribs['class'] = array( 'mw-htmlform-submit' );
 
                        if ( $this->isVForm() || $useMediaWikiUIEverywhere ) {
-                               array_push( $attribs['class'], 'mw-ui-button', 'mw-ui-constructive' );
+                               array_push( $attribs['class'], 'mw-ui-button', $this->mSubmitModifierClass );
                        }
 
                        if ( $this->isVForm() ) {
@@ -1042,6 +1051,22 @@ class HTMLForm extends ContextSource {
                return $this;
        }
 
+       /**
+        * Identify that the submit button in the form has a destructive action
+        * @since 1.24
+        */
+       public function setSubmitDestructive() {
+               $this->mSubmitModifierClass = 'mw-ui-destructive';
+       }
+
+       /**
+        * Identify that the submit button in the form has a progressive action
+        * @since 1.25
+        */
+       public function setSubmitProgressive() {
+               $this->mSubmitModifierClass = 'mw-ui-progressive';
+       }
+
        /**
         * Set the text for the submit button to a message
         * @since 1.19