$this->getOptions();
if ( $this->mOptions && !in_array( 'other', $this->mOptions, true ) ) {
if ( isset( $params['other-message'] ) ) {
- $msg = wfMessage( $params['other-message'] )->text();
+ $msg = $this->getMessage( $params['other-message'] )->text();
} elseif ( isset( $params['other'] ) ) {
$msg = $params['other'];
} else {
# Generate the label from a message, if possible
if ( isset( $info['buttonlabel-message'] ) ) {
- $msgInfo = $info['buttonlabel-message'];
-
- if ( is_array( $msgInfo ) ) {
- $msg = array_shift( $msgInfo );
- } else {
- $msg = $msgInfo;
- $msgInfo = [];
- }
-
- $this->buttonLabel = $this->msg( $msg, $msgInfo )->parse();
+ $this->buttonLabel = $this->getMessage( $info['buttonlabel-message'] )->parse();
} elseif ( isset( $info['buttonlabel'] ) ) {
if ( $info['buttonlabel'] === ' ' ) {
// Apparently some things set   directly and in an odd format
if ( empty( $this->mParams['message'] ) ) {
$msg = $this->msg( 'edittools' );
} else {
- $msg = $this->msg( $this->mParams['message'] );
+ $msg = $this->getMessage( $this->mParams['message'] );
if ( $msg->isDisabled() ) {
$msg = $this->msg( 'edittools' );
}
* Some field types support multi-level arrays.
* 'options-messages' -- associative array mapping message keys to values.
* Some field types support multi-level arrays.
- * 'options-message' -- message key to be parsed to extract the list of
+ * 'options-message' -- message key or object to be parsed to extract the list of
* options (like 'ipbreason-dropdown').
- * 'label-message' -- message key for a message to use as the label.
+ * 'label-message' -- message key or object for a message to use as the label.
* can be an array of msg key and then parameters to
* the message.
* 'label' -- alternatively, a raw text message. Overridden by
* label-message
* 'help' -- message text for a message to use as a help text.
- * 'help-message' -- message key for a message to use as a help text.
+ * 'help-message' -- message key or object for a message to use as a help text.
* can be an array of msg key and then parameters to
* the message.
* Overwrites 'help-messages' and 'help'.
- * 'help-messages' -- array of message key. As above, each item can
+ * 'help-messages' -- array of message keys/objects. As above, each item can
* be an array of msg key and then parameters.
* Overwrites 'help'.
* 'required' -- passed through to the object, indicating that it
# Generate the label from a message, if possible
if ( isset( $params['label-message'] ) ) {
- $msgInfo = $params['label-message'];
-
- if ( is_array( $msgInfo ) ) {
- $msg = array_shift( $msgInfo );
- } else {
- $msg = $msgInfo;
- $msgInfo = [];
- }
-
- $this->mLabel = $this->msg( $msg, $msgInfo )->parse();
+ $this->mLabel = $this->getMessage( $params['label-message'] )->parse();
} elseif ( isset( $params['label'] ) ) {
if ( $params['label'] === ' ' ) {
// Apparently some things set   directly and in an odd format
}
if ( isset( $this->mParams['help-messages'] ) ) {
- foreach ( $this->mParams['help-messages'] as $name ) {
- $helpMessage = (array)$name;
- $msg = $this->msg( array_shift( $helpMessage ), $helpMessage );
+ foreach ( $this->mParams['help-messages'] as $msg ) {
+ $msg = $this->getMessage( $msg );
if ( $msg->exists() ) {
if ( is_null( $helptext ) ) {
$this->mOptions = self::forceToStringRecursive( $this->mParams['options'] );
} elseif ( array_key_exists( 'options-message', $this->mParams ) ) {
/** @todo This is copied from Xml::listDropDown(), deprecate/avoid duplication? */
- $message = $this->msg( $this->mParams['options-message'] )->inContentLanguage()->plain();
+ $message = $this->getMessage( $this->mParams['options-message'] )->inContentLanguage()->plain();
$optgroup = false;
$this->mOptions = [];
return Html::rawElement( 'span', [ 'class' => 'error' ], $errors );
}
}
+
+ /**
+ * Turns a *-message parameter (which could be a MessageSpecifier, or a message name, or a
+ * name + parameters array) into a Message.
+ * @param mixed $value
+ * @return Message
+ */
+ protected function getMessage( $value ) {
+ if ( $value instanceof Message ) {
+ return $value;
+ } elseif ( $value instanceof MessageSpecifier ) {
+ return Message::newFromKey( $value );
+ } elseif ( is_array( $value ) ) {
+ $msg = array_shift( $value );
+ return $this->msg( $msg, $value );
+ } else {
+ return $this->msg( $value, [] );
+ }
+ }
}
* 'table', 'div', or 'raw'.
* row-legend - If non-empty, each group of subfields will be enclosed in a
* fieldset. The value is the name of a message key to use as the legend.
- * create-button-message - Message key to use as the text of the button to
+ * create-button-message - Message to use as the text of the button to
* add an additional group of fields.
- * delete-button-message - Message key to use as the text of automatically-
+ * delete-button-message - Message to use as the text of automatically-
* generated 'delete' button. Ignored if 'delete' is included in 'fields'.
*
* In the generated HTML, the subfields will be named along the lines of
'name' => $name,
'id' => Sanitizer::escapeId( "{$this->mID}--$key--delete" ),
'cssclass' => 'mw-htmlform-cloner-delete-button',
- 'default' => $this->msg( $label )->text(),
+ 'default' => $this->getMessage( $label )->text(),
], $this->mParent );
$v = $field->getDefault();
'name' => $name,
'id' => Sanitizer::escapeId( "{$this->mID}--create" ),
'cssclass' => 'mw-htmlform-cloner-create-button',
- 'default' => $this->msg( $label )->text(),
+ 'default' => $this->getMessage( $label )->text(),
], $this->mParent );
$html .= $field->getInputHTML( $field->getDefault() );
if ( array_key_exists( 'other', $params ) ) {
// Do nothing
} elseif ( array_key_exists( 'other-message', $params ) ) {
- $params['other'] = wfMessage( $params['other-message'] )->plain();
+ $params['other'] = $this->getMessage( $params['other-message'] )->plain();
} else {
- $params['other'] = wfMessage( 'htmlform-selectorother-other' )->plain();
+ $params['other'] = $this->msg( 'htmlform-selectorother-other' )->plain();
}
parent::__construct( $params );