X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FHTMLForm.php;h=ef24b62b26eb9cda1ffc6abb1b514a0e5528f2ce;hb=0177eab9d7384b474b5e9c69b902b21dfc608520;hp=ab12377866202c3469e4c3ea43b624d63920bd27;hpb=51f6f61a7ef4447e86913e37694f272938bbf970;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/HTMLForm.php b/includes/HTMLForm.php index ab12377866..ef24b62b26 100644 --- a/includes/HTMLForm.php +++ b/includes/HTMLForm.php @@ -248,6 +248,7 @@ class HTMLForm extends ContextSource { * Set format in which to display the form * @param $format String the name of the format to use, must be one of * $this->availableDisplayFormats + * @throws MWException * @since 1.20 * @return HTMLForm $this for chaining calls (since 1.20) */ @@ -279,6 +280,7 @@ class HTMLForm extends ContextSource { * Initialise a new Object for the field * @param $fieldname string * @param $descriptor string input Descriptor, as described above + * @throws MWException * @return HTMLFormField subclass */ static function loadInputFromParameters( $fieldname, $descriptor ) { @@ -312,6 +314,7 @@ class HTMLForm extends ContextSource { * @attention When doing method chaining, that should be the very last * method call before displayForm(). * + * @throws MWException * @return HTMLForm $this for chaining calls (since 1.20) */ function prepareForm() { @@ -375,9 +378,10 @@ class HTMLForm extends ContextSource { /** * Validate all the fields, and call the submision callback * function if everything is kosher. + * @throws MWException * @return Mixed Bool true == Successful submission, Bool false - * == No submission attempted, anything else == Error to - * display. + * == No submission attempted, anything else == Error to + * display. */ function trySubmit() { # Check for validation @@ -424,7 +428,7 @@ class HTMLForm extends ContextSource { /** * Set a message to display on a validation error. - * @param $msg Mixed String or Array of valid inputs to wfMsgExt() + * @param $msg Mixed String or Array of valid inputs to wfMessage() * (so each entry can be either a String or Array) * @return HTMLForm $this for chaining calls (since 1.20) */ @@ -700,7 +704,7 @@ class HTMLForm extends ContextSource { 'input', array( 'type' => 'reset', - 'value' => wfMsg( 'htmlform-reset' ) + 'value' => $this->msg( 'htmlform-reset' )->text() ) ) . "\n"; } @@ -776,7 +780,7 @@ class HTMLForm extends ContextSource { $errorstr .= Html::rawElement( 'li', array(), - wfMsgExt( $msg, array( 'parseinline' ), $error ) + wfMessage( $msg, $error )->parse() ); } @@ -813,7 +817,7 @@ class HTMLForm extends ContextSource { function getSubmitText() { return $this->mSubmitText ? $this->mSubmitText - : wfMsg( 'htmlform-submit' ); + : $this->msg( 'htmlform-submit' )->text(); } /** @@ -1051,7 +1055,7 @@ class HTMLForm extends ContextSource { * @return String */ public function getLegend( $key ) { - return wfMsg( "{$this->mMessagePrefix}-$key" ); + return $this->msg( "{$this->mMessagePrefix}-$key" )->text(); } /** @@ -1100,6 +1104,28 @@ abstract class HTMLFormField { */ abstract function getInputHTML( $value ); + /** + * Get a translated interface message + * + * This is a wrapper arround $this->mParent->msg() if $this->mParent is set + * and wfMessage() otherwise. + * + * Parameters are the same as wfMessage(). + * + * @return Message object + */ + function msg() { + $args = func_get_args(); + + if ( $this->mParent ) { + $callback = array( $this->mParent, 'msg' ); + } else { + $callback = 'wfMessage'; + } + + return call_user_func_array( $callback, $args ); + } + /** * Override this function to add specific validation checks on the * field input. Don't forget to call parent::validate() to ensure @@ -1110,7 +1136,7 @@ abstract class HTMLFormField { */ function validate( $value, $alldata ) { if ( isset( $this->mParams['required'] ) && $this->mParams['required'] !== false && $value === '' ) { - return wfMsgExt( 'htmlform-required', 'parseinline' ); + return $this->msg( 'htmlform-required' )->parse(); } if ( isset( $this->mValidationCallback ) ) { @@ -1155,6 +1181,7 @@ abstract class HTMLFormField { /** * Initialise the object * @param $params array Associative Array. See HTMLForm doc for syntax. + * @throws MWException */ function __construct( $params ) { $this->mParams = $params; @@ -1170,7 +1197,7 @@ abstract class HTMLFormField { $msgInfo = array(); } - $this->mLabel = wfMsgExt( $msg, 'parseinline', $msgInfo ); + $this->mLabel = wfMessage( $msg, $msgInfo )->parse(); } elseif ( isset( $params['label'] ) ) { $this->mLabel = $params['label']; } @@ -1299,7 +1326,6 @@ abstract class HTMLFormField { public function getRaw( $value ) { list( $errors, $errorClass ) = $this->getErrorsAndErrorClass( $value ); $inputHtml = $this->getInputHTML( $value ); - $fieldType = get_class( $this ); $helptext = $this->getHelpTextHtmlRaw( $this->getHelpText() ); $cellAttributes = array(); $label = $this->getLabelHtml( $cellAttributes ); @@ -1371,13 +1397,13 @@ abstract class HTMLFormField { if ( isset( $this->mParams['help-messages'] ) ) { foreach ( $this->mParams['help-messages'] as $name ) { $helpMessage = (array)$name; - $msg = wfMessage( array_shift( $helpMessage ), $helpMessage ); + $msg = $this->msg( array_shift( $helpMessage ), $helpMessage ); if ( $msg->exists() ) { if ( is_null( $helptext ) ) { $helptext = ''; } else { - $helptext .= wfMessage( 'word-separator' )->escaped(); // some space + $helptext .= $this->msg( 'word-separator' )->escaped(); // some space } $helptext .= $msg->parse(); // Append message } @@ -1642,7 +1668,7 @@ class HTMLFloatField extends HTMLTextField { # http://dev.w3.org/html5/spec/common-microsyntaxes.html#real-numbers # with the addition that a leading '+' sign is ok. if ( !preg_match( '/^((\+|\-)?\d+(\.\d+)?(E(\+|\-)?\d+)?)?$/i', $value ) ) { - return wfMsgExt( 'htmlform-float-invalid', 'parse' ); + return $this->msg( 'htmlform-float-invalid' )->parseAsBlock(); } # The "int" part of these message names is rather confusing. @@ -1651,7 +1677,7 @@ class HTMLFloatField extends HTMLTextField { $min = $this->mParams['min']; if ( $min > $value ) { - return wfMsgExt( 'htmlform-int-toolow', 'parse', array( $min ) ); + return $this->msg( 'htmlform-int-toolow', $min )->parseAsBlock(); } } @@ -1659,7 +1685,7 @@ class HTMLFloatField extends HTMLTextField { $max = $this->mParams['max']; if ( $max < $value ) { - return wfMsgExt( 'htmlform-int-toohigh', 'parse', array( $max ) ); + return $this->msg( 'htmlform-int-toohigh', $max )->parseAsBlock(); } } @@ -1686,7 +1712,7 @@ class HTMLIntField extends HTMLFloatField { # value to, eg, save in the DB, clean it up with intval(). if ( !preg_match( '/^((\+|\-)?\d+)?$/', trim( $value ) ) ) { - return wfMsgExt( 'htmlform-int-invalid', 'parse' ); + return $this->msg( 'htmlform-int-invalid' )->parseAsBlock(); } return true; @@ -1770,7 +1796,7 @@ class HTMLSelectField extends HTMLFormField { if ( in_array( $value, $validOptions ) ) return true; else - return wfMsgExt( 'htmlform-select-badoption', 'parseinline' ); + return $this->msg( 'htmlform-select-badoption' )->parse(); } function getInputHTML( $value ) { @@ -1808,7 +1834,9 @@ class HTMLSelectOrOtherField extends HTMLTextField { function __construct( $params ) { if ( !in_array( 'other', $params['options'], true ) ) { - $msg = isset( $params['other'] ) ? $params['other'] : wfMsg( 'htmlform-selectorother-other' ); + $msg = isset( $params['other'] ) ? + $params['other'] : + wfMessage( 'htmlform-selectorother-other' )->text(); $params['options'][$msg] = 'other'; } @@ -1912,7 +1940,7 @@ class HTMLMultiSelectField extends HTMLFormField { if ( count( $validValues ) == count( $value ) ) { return true; } else { - return wfMsgExt( 'htmlform-select-badoption', 'parseinline' ); + return $this->msg( 'htmlform-select-badoption' )->parse(); } } @@ -2114,7 +2142,7 @@ class HTMLSelectAndOtherField extends HTMLSelectField { } elseif ( $text == '' ) { $final = $list; } else { - $final = $list . wfMsgForContent( 'colon-separator' ) . $text; + $final = $list . $this->msg( 'colon-separator' )->inContentLanguage()->text() . $text; } } else { @@ -2123,7 +2151,7 @@ class HTMLSelectAndOtherField extends HTMLSelectField { $list = 'other'; $text = $final; foreach ( $this->mFlatOptions as $option ) { - $match = $option . wfMsgForContent( 'colon-separator' ); + $match = $option . $this->msg( 'colon-separator' )->inContentLanguage()->text(); if ( strpos( $text, $match ) === 0 ) { $list = $option; $text = substr( $text, strlen( $match ) ); @@ -2151,7 +2179,7 @@ class HTMLSelectAndOtherField extends HTMLSelectField { } if ( isset( $this->mParams['required'] ) && $this->mParams['required'] !== false && $value[1] === '' ) { - return wfMsgExt( 'htmlform-required', 'parseinline' ); + return $this->msg( 'htmlform-required' )->parse(); } return true; @@ -2180,7 +2208,7 @@ class HTMLRadioField extends HTMLFormField { if ( in_array( $value, $validOptions ) ) { return true; } else { - return wfMsgExt( 'htmlform-select-badoption', 'parseinline' ); + return $this->msg( 'htmlform-select-badoption' )->parse(); } } @@ -2390,11 +2418,11 @@ class HTMLEditTools extends HTMLFormField { protected function formatMsg() { if ( empty( $this->mParams['message'] ) ) { - $msg = wfMessage( 'edittools' ); + $msg = $this->msg( 'edittools' ); } else { - $msg = wfMessage( $this->mParams['message'] ); + $msg = $this->msg( $this->mParams['message'] ); if ( $msg->isDisabled() ) { - $msg = wfMessage( 'edittools' ); + $msg = $this->msg( 'edittools' ); } } $msg->inContentLanguage();