Legoktm has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/180651

Change subject: Avoid GlobalTitleFail in HTMLFormField::__construct
......................................................................

Avoid GlobalTitleFail in HTMLFormField::__construct

Pass the HTMLForm parent instance in the constructor so context
is available when parsing a message.

Change-Id: I532c0d95698cbcc57294b9bd2725f33838f393a9
---
M includes/Preferences.php
M includes/htmlform/HTMLForm.php
M includes/htmlform/HTMLFormField.php
M includes/htmlform/HTMLFormFieldCloner.php
4 files changed, 15 insertions(+), 14 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/51/180651/1

diff --git a/includes/Preferences.php b/includes/Preferences.php
index 44995ac..aca6dcb 100644
--- a/includes/Preferences.php
+++ b/includes/Preferences.php
@@ -130,8 +130,7 @@
                        if ( $disable && !in_array( $name, self::$saveBlacklist 
) ) {
                                $info['disabled'] = 'disabled';
                        }
-                       $field = HTMLForm::loadInputFromParameters( $name, 
$info ); // For validation
-                       $field->mParent = $dummyForm;
+                       $field = HTMLForm::loadInputFromParameters( $name, 
$info, $dummyForm ); // For validation
                        $defaultOptions = User::getDefaultOptions();
                        $globalDefault = isset( $defaultOptions[$name] )
                                ? $defaultOptions[$name]
diff --git a/includes/htmlform/HTMLForm.php b/includes/htmlform/HTMLForm.php
index 62345b8..df805aa 100644
--- a/includes/htmlform/HTMLForm.php
+++ b/includes/htmlform/HTMLForm.php
@@ -246,10 +246,7 @@
                                $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() ) {
@@ -359,14 +356,18 @@
         *
         * @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
diff --git a/includes/htmlform/HTMLFormField.php 
b/includes/htmlform/HTMLFormField.php
index 4cf2394..861ae4c 100644
--- a/includes/htmlform/HTMLFormField.php
+++ b/includes/htmlform/HTMLFormField.php
@@ -343,6 +343,10 @@
        function __construct( $params ) {
                $this->mParams = $params;
 
+               if ( isset( $params['parent'] ) && $params['parent'] instanceof 
HTMLForm ) {
+                       $this->mParent = $params['parent'];
+               }
+
                # Generate the label from a message, if possible
                if ( isset( $params['label-message'] ) ) {
                        $msgInfo = $params['label-message'];
@@ -354,7 +358,7 @@
                                $msgInfo = array();
                        }
 
-                       $this->mLabel = wfMessage( $msg, $msgInfo )->parse();
+                       $this->mLabel = $this->msg( $msg, $msgInfo )->parse();
                } elseif ( isset( $params['label'] ) ) {
                        if ( $params['label'] === ' ' ) {
                                // Apparently some things set &nbsp directly 
and in an odd format
diff --git a/includes/htmlform/HTMLFormFieldCloner.php 
b/includes/htmlform/HTMLFormFieldCloner.php
index 5dadaf8..d1b7746 100644
--- a/includes/htmlform/HTMLFormFieldCloner.php
+++ b/includes/htmlform/HTMLFormFieldCloner.php
@@ -96,8 +96,7 @@
                        } else {
                                $info['id'] = Sanitizer::escapeId( 
"{$this->mID}--$key--$fieldname" );
                        }
-                       $field = HTMLForm::loadInputFromParameters( $name, 
$info );
-                       $field->mParent = $this->mParent;
+                       $field = HTMLForm::loadInputFromParameters( $name, 
$info, $this->mParent );
                        $fields[$fieldname] = $field;
                }
                return $fields;
@@ -310,8 +309,7 @@
                                'id' => Sanitizer::escapeId( 
"{$this->mID}--$key--delete" ),
                                'cssclass' => 
'mw-htmlform-cloner-delete-button',
                                'default' => $this->msg( $label )->text(),
-                       ) );
-                       $field->mParent = $this->mParent;
+                       ), $this->mParent );
                        $v = $field->getDefault();
 
                        if ( $displayFormat === 'table' ) {
@@ -383,8 +381,7 @@
                        'id' => Sanitizer::escapeId( "{$this->mID}--create" ),
                        'cssclass' => 'mw-htmlform-cloner-create-button',
                        'default' => $this->msg( $label )->text(),
-               ) );
-               $field->mParent = $this->mParent;
+               ), $this->mParent );
                $html .= $field->getInputHTML( $field->getDefault() );
 
                return $html;

-- 
To view, visit https://gerrit.wikimedia.org/r/180651
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I532c0d95698cbcc57294b9bd2725f33838f393a9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to