X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22articles_versions%22%2C%22id_article=%24id_article%22%29%20.%20%22?a=blobdiff_plain;f=includes%2FHTMLForm.php;h=952022f4bb94465ecc58b9e9a210f71322bfb270;hb=4477e5dbac5764af4b40d338e58f2975e34bd159;hp=4fc43389e052ece03c2ab58c110ea29b5e7268d2;hpb=57b9354ca93e46bf3d0873a90ceb933de9175b9e;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/HTMLForm.php b/includes/HTMLForm.php index 4fc43389e0..952022f4bb 100644 --- a/includes/HTMLForm.php +++ b/includes/HTMLForm.php @@ -96,6 +96,7 @@ class HTMLForm extends ContextSource { // A mapping of 'type' inputs onto standard HTMLFormField subclasses static $typeMappings = array( + 'api' => 'HTMLApiField', 'text' => 'HTMLTextField', 'textarea' => 'HTMLTextAreaField', 'select' => 'HTMLSelectField', @@ -248,6 +249,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 +281,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 +315,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 +379,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 @@ -1100,6 +1105,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 +1137,7 @@ abstract class HTMLFormField { */ function validate( $value, $alldata ) { if ( isset( $this->mParams['required'] ) && $this->mParams['required'] !== false && $value === '' ) { - return $this->mParent->msg( 'htmlform-required' )->parse(); + return $this->msg( 'htmlform-required' )->parse(); } if ( isset( $this->mValidationCallback ) ) { @@ -1155,6 +1182,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; @@ -1299,7 +1327,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 +1398,13 @@ abstract class HTMLFormField { if ( isset( $this->mParams['help-messages'] ) ) { foreach ( $this->mParams['help-messages'] as $name ) { $helpMessage = (array)$name; - $msg = $this->mParent->msg( array_shift( $helpMessage ), $helpMessage ); + $msg = $this->msg( array_shift( $helpMessage ), $helpMessage ); if ( $msg->exists() ) { if ( is_null( $helptext ) ) { $helptext = ''; } else { - $helptext .= $this->mParent->msg( 'word-separator' )->escaped(); // some space + $helptext .= $this->msg( 'word-separator' )->escaped(); // some space } $helptext .= $msg->parse(); // Append message } @@ -1642,7 +1669,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 $this->mParent->msg( 'htmlform-float-invalid' )->parseAsBlock(); + return $this->msg( 'htmlform-float-invalid' )->parseAsBlock(); } # The "int" part of these message names is rather confusing. @@ -1651,7 +1678,7 @@ class HTMLFloatField extends HTMLTextField { $min = $this->mParams['min']; if ( $min > $value ) { - return $this->mParent->msg( 'htmlform-int-toolow', $min )->parseAsBlock(); + return $this->msg( 'htmlform-int-toolow', $min )->parseAsBlock(); } } @@ -1659,7 +1686,7 @@ class HTMLFloatField extends HTMLTextField { $max = $this->mParams['max']; if ( $max < $value ) { - return $this->mParent->msg( 'htmlform-int-toohigh', $max )->parseAsBlock(); + return $this->msg( 'htmlform-int-toohigh', $max )->parseAsBlock(); } } @@ -1686,7 +1713,7 @@ class HTMLIntField extends HTMLFloatField { # value to, eg, save in the DB, clean it up with intval(). if ( !preg_match( '/^((\+|\-)?\d+)?$/', trim( $value ) ) ) { - return $this->mParent->msg( 'htmlform-int-invalid' )->parseAsBlock(); + return $this->msg( 'htmlform-int-invalid' )->parseAsBlock(); } return true; @@ -1770,7 +1797,7 @@ class HTMLSelectField extends HTMLFormField { if ( in_array( $value, $validOptions ) ) return true; else - return $this->mParent->msg( 'htmlform-select-badoption' )->parse(); + return $this->msg( 'htmlform-select-badoption' )->parse(); } function getInputHTML( $value ) { @@ -1914,7 +1941,7 @@ class HTMLMultiSelectField extends HTMLFormField { if ( count( $validValues ) == count( $value ) ) { return true; } else { - return $this->mParent->msg( 'htmlform-select-badoption' )->parse(); + return $this->msg( 'htmlform-select-badoption' )->parse(); } } @@ -2116,7 +2143,7 @@ class HTMLSelectAndOtherField extends HTMLSelectField { } elseif ( $text == '' ) { $final = $list; } else { - $final = $list . $this->mParent->msg( 'colon-separator' )->inContentLanguage()->text() . $text; + $final = $list . $this->msg( 'colon-separator' )->inContentLanguage()->text() . $text; } } else { @@ -2125,7 +2152,7 @@ class HTMLSelectAndOtherField extends HTMLSelectField { $list = 'other'; $text = $final; foreach ( $this->mFlatOptions as $option ) { - $match = $option . $this->mParent->msg( 'colon-separator' )->inContentLanguage()->text(); + $match = $option . $this->msg( 'colon-separator' )->inContentLanguage()->text(); if ( strpos( $text, $match ) === 0 ) { $list = $option; $text = substr( $text, strlen( $match ) ); @@ -2153,7 +2180,7 @@ class HTMLSelectAndOtherField extends HTMLSelectField { } if ( isset( $this->mParams['required'] ) && $this->mParams['required'] !== false && $value[1] === '' ) { - return $this->mParent->msg( 'htmlform-required' )->parse(); + return $this->msg( 'htmlform-required' )->parse(); } return true; @@ -2182,7 +2209,7 @@ class HTMLRadioField extends HTMLFormField { if ( in_array( $value, $validOptions ) ) { return true; } else { - return $this->mParent->msg( 'htmlform-select-badoption' )->parse(); + return $this->msg( 'htmlform-select-badoption' )->parse(); } } @@ -2392,14 +2419,32 @@ class HTMLEditTools extends HTMLFormField { protected function formatMsg() { if ( empty( $this->mParams['message'] ) ) { - $msg = $this->mParent->msg( 'edittools' ); + $msg = $this->msg( 'edittools' ); } else { - $msg = $this->mParent->msg( $this->mParams['message'] ); + $msg = $this->msg( $this->mParams['message'] ); if ( $msg->isDisabled() ) { - $msg = $this->mParent->msg( 'edittools' ); + $msg = $this->msg( 'edittools' ); } } $msg->inContentLanguage(); return $msg; } } + +class HTMLApiField extends HTMLFormField { + public function getTableRow( $value ) { + return ''; + } + + public function getDiv( $value ) { + return $this->getTableRow( $value ); + } + + public function getRaw( $value ) { + return $this->getTableRow( $value ); + } + + public function getInputHTML( $value ) { + return ''; + } +}