2013-11-19 12:55:50 +00:00
|
|
|
<?php
|
2013-11-19 13:08:16 +00:00
|
|
|
|
2013-11-19 12:55:50 +00:00
|
|
|
class HTMLTextField extends HTMLFormField {
|
|
|
|
|
function getSize() {
|
2013-11-19 13:08:16 +00:00
|
|
|
return isset( $this->mParams['size'] ) ? $this->mParams['size'] : 45;
|
2013-11-19 12:55:50 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-18 22:35:15 +00:00
|
|
|
function getSpellCheck() {
|
|
|
|
|
$val = isset( $this->mParams['spellcheck'] ) ? $this->mParams['spellcheck'] : null;
|
2015-06-26 05:32:28 +00:00
|
|
|
if ( is_bool( $val ) ) {
|
2015-05-18 22:35:15 +00:00
|
|
|
// "spellcheck" attribute literally requires "true" or "false" to work.
|
|
|
|
|
return $val === true ? 'true' : 'false';
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-19 12:55:50 +00:00
|
|
|
function getInputHTML( $value ) {
|
|
|
|
|
$attribs = array(
|
|
|
|
|
'id' => $this->mID,
|
|
|
|
|
'name' => $this->mName,
|
|
|
|
|
'size' => $this->getSize(),
|
|
|
|
|
'value' => $value,
|
2015-04-19 19:10:45 +00:00
|
|
|
'dir' => $this->mDir,
|
2015-05-18 22:35:15 +00:00
|
|
|
'spellcheck' => $this->getSpellCheck(),
|
2013-11-19 12:55:50 +00:00
|
|
|
) + $this->getTooltipAndAccessKey();
|
|
|
|
|
|
|
|
|
|
if ( $this->mClass !== '' ) {
|
2013-11-19 13:08:16 +00:00
|
|
|
$attribs['class'] = $this->mClass;
|
2013-11-19 12:55:50 +00:00
|
|
|
}
|
|
|
|
|
|
2013-11-19 13:08:16 +00:00
|
|
|
# @todo Enforce pattern, step, required, readonly on the server side as
|
2013-11-19 12:55:50 +00:00
|
|
|
# well
|
|
|
|
|
$allowedParams = array(
|
2014-09-30 16:06:56 +00:00
|
|
|
'type',
|
2013-11-19 12:55:50 +00:00
|
|
|
'min',
|
|
|
|
|
'max',
|
|
|
|
|
'pattern',
|
|
|
|
|
'title',
|
|
|
|
|
'step',
|
|
|
|
|
'placeholder',
|
|
|
|
|
'list',
|
2013-05-02 18:27:44 +00:00
|
|
|
'maxlength',
|
|
|
|
|
'tabindex',
|
|
|
|
|
'disabled',
|
|
|
|
|
'required',
|
|
|
|
|
'autofocus',
|
|
|
|
|
'multiple',
|
|
|
|
|
'readonly'
|
2013-11-19 12:55:50 +00:00
|
|
|
);
|
|
|
|
|
|
2013-05-02 18:27:44 +00:00
|
|
|
$attribs += $this->getAttributes( $allowedParams );
|
2013-11-19 12:55:50 +00:00
|
|
|
|
2014-09-30 16:06:56 +00:00
|
|
|
# Extract 'type'
|
2015-04-21 21:03:49 +00:00
|
|
|
$type = $this->getType( $attribs );
|
|
|
|
|
return Html::input( $this->mName, $value, $type, $attribs );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getType( &$attribs ) {
|
2014-09-30 16:06:56 +00:00
|
|
|
$type = isset( $attribs['type'] ) ? $attribs['type'] : 'text';
|
|
|
|
|
unset( $attribs['type'] );
|
|
|
|
|
|
2013-11-19 12:55:50 +00:00
|
|
|
# Implement tiny differences between some field variants
|
|
|
|
|
# here, rather than creating a new class for each one which
|
|
|
|
|
# is essentially just a clone of this one.
|
2013-11-19 13:08:16 +00:00
|
|
|
if ( isset( $this->mParams['type'] ) ) {
|
|
|
|
|
switch ( $this->mParams['type'] ) {
|
2013-11-19 12:55:50 +00:00
|
|
|
case 'int':
|
2014-07-30 17:56:25 +00:00
|
|
|
$type = 'number';
|
2013-11-19 12:55:50 +00:00
|
|
|
break;
|
|
|
|
|
case 'float':
|
2014-07-30 17:56:25 +00:00
|
|
|
$type = 'number';
|
2013-11-19 13:08:16 +00:00
|
|
|
$attribs['step'] = 'any';
|
2013-11-19 12:55:50 +00:00
|
|
|
break;
|
|
|
|
|
# Pass through
|
2014-02-28 21:42:27 +00:00
|
|
|
case 'email':
|
2013-11-19 12:55:50 +00:00
|
|
|
case 'password':
|
|
|
|
|
case 'file':
|
2014-02-28 21:42:27 +00:00
|
|
|
case 'url':
|
2014-07-30 17:56:25 +00:00
|
|
|
$type = $this->mParams['type'];
|
2013-11-19 12:55:50 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-09-30 16:06:56 +00:00
|
|
|
|
2015-04-21 21:03:49 +00:00
|
|
|
return $type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getInputOOUI( $value ) {
|
|
|
|
|
$attribs = $this->getTooltipAndAccessKey();
|
|
|
|
|
|
|
|
|
|
if ( $this->mClass !== '' ) {
|
|
|
|
|
$attribs['classes'] = array( $this->mClass );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# @todo Enforce pattern, step, required, readonly on the server side as
|
|
|
|
|
# well
|
|
|
|
|
$allowedParams = array(
|
|
|
|
|
'autofocus',
|
|
|
|
|
'autosize',
|
|
|
|
|
'disabled',
|
|
|
|
|
'flags',
|
|
|
|
|
'indicator',
|
|
|
|
|
'maxlength',
|
|
|
|
|
'placeholder',
|
|
|
|
|
'readonly',
|
|
|
|
|
'required',
|
|
|
|
|
'tabindex',
|
|
|
|
|
'type',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$attribs += $this->getAttributes( $allowedParams, array(
|
|
|
|
|
'maxlength' => 'maxLength',
|
|
|
|
|
'readonly' => 'readOnly',
|
|
|
|
|
'tabindex' => 'tabIndex',
|
|
|
|
|
) );
|
|
|
|
|
|
2015-06-30 20:03:58 +00:00
|
|
|
if ( isset( $attribs['readOnly'] ) ) {
|
|
|
|
|
// This needs to be set to a boolean value
|
|
|
|
|
$attribs['readOnly'] = true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-21 21:03:49 +00:00
|
|
|
$type = $this->getType( $attribs );
|
|
|
|
|
|
|
|
|
|
return new OOUI\TextInputWidget( array(
|
|
|
|
|
'id' => $this->mID,
|
|
|
|
|
'name' => $this->mName,
|
|
|
|
|
'value' => $value,
|
|
|
|
|
'type' => $type,
|
|
|
|
|
) + $attribs );
|
2013-11-19 12:55:50 +00:00
|
|
|
}
|
2013-11-19 13:08:16 +00:00
|
|
|
}
|