* 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)
*/
* 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 ) {
* @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() {
/**
* 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
*/
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
*/
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 ) ) {
/**
* Initialise the object
* @param $params array Associative Array. See HTMLForm doc for syntax.
+ * @throws MWException
*/
function __construct( $params ) {
$this->mParams = $params;
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 );
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
}
# 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.
$min = $this->mParams['min'];
if ( $min > $value ) {
- return $this->mParent->msg( 'htmlform-int-toolow', $min )->parseAsBlock();
+ return $this->msg( 'htmlform-int-toolow', $min )->parseAsBlock();
}
}
$max = $this->mParams['max'];
if ( $max < $value ) {
- return $this->mParent->msg( 'htmlform-int-toohigh', $max )->parseAsBlock();
+ return $this->msg( 'htmlform-int-toohigh', $max )->parseAsBlock();
}
}
# 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;
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 ) {
if ( count( $validValues ) == count( $value ) ) {
return true;
} else {
- return $this->mParent->msg( 'htmlform-select-badoption' )->parse();
+ return $this->msg( 'htmlform-select-badoption' )->parse();
}
}
} 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 {
$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 ) );
}
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;
if ( in_array( $value, $validOptions ) ) {
return true;
} else {
- return $this->mParent->msg( 'htmlform-select-badoption' )->parse();
+ return $this->msg( 'htmlform-select-badoption' )->parse();
}
}
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();