2018-03-22 05:15:16 +00:00
|
|
|
<?php
|
|
|
|
|
|
2024-02-08 15:30:18 +00:00
|
|
|
namespace MediaWiki\HTMLForm\Field;
|
|
|
|
|
|
|
|
|
|
use MediaWiki\HTMLForm\HTMLForm;
|
|
|
|
|
use MediaWiki\HTMLForm\HTMLFormField;
|
2018-03-22 05:15:16 +00:00
|
|
|
use MediaWiki\Widget\ExpiryInputWidget;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Expiry Field that allows the user to specify a precise date or a
|
|
|
|
|
* relative date string.
|
2020-07-10 19:23:59 +00:00
|
|
|
*
|
|
|
|
|
* @stable to extend
|
2018-03-22 05:15:16 +00:00
|
|
|
*/
|
|
|
|
|
class HTMLExpiryField extends HTMLFormField {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var HTMLFormField
|
|
|
|
|
*/
|
|
|
|
|
protected $relativeField;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Relative Date Time Field.
|
2020-07-10 19:23:59 +00:00
|
|
|
*
|
|
|
|
|
* @stable to call
|
2018-12-03 11:47:12 +00:00
|
|
|
* @param array $params
|
2018-03-22 05:15:16 +00:00
|
|
|
*/
|
|
|
|
|
public function __construct( array $params = [] ) {
|
|
|
|
|
parent::__construct( $params );
|
|
|
|
|
|
|
|
|
|
$type = !empty( $params['options'] ) ? 'selectorother' : 'text';
|
|
|
|
|
$this->relativeField = $this->getFieldByType( $type );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-02-26 12:57:24 +00:00
|
|
|
* @inheritDoc
|
2018-03-22 05:15:16 +00:00
|
|
|
*
|
|
|
|
|
* Use whatever the relative field is as the standard HTML input.
|
|
|
|
|
*/
|
|
|
|
|
public function getInputHTML( $value ) {
|
2018-05-04 06:58:42 +00:00
|
|
|
return $this->relativeField->getInputHTML( $value );
|
2018-03-22 05:15:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function shouldInfuseOOUI() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-02-26 12:57:24 +00:00
|
|
|
* @inheritDoc
|
2018-03-22 05:15:16 +00:00
|
|
|
*/
|
|
|
|
|
protected function getOOUIModules() {
|
|
|
|
|
return array_merge(
|
|
|
|
|
[
|
|
|
|
|
'mediawiki.widgets.expiry',
|
|
|
|
|
],
|
|
|
|
|
$this->relativeField->getOOUIModules()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-02-26 12:57:24 +00:00
|
|
|
* @inheritDoc
|
2018-03-22 05:15:16 +00:00
|
|
|
*/
|
|
|
|
|
public function getInputOOUI( $value ) {
|
|
|
|
|
return new ExpiryInputWidget(
|
|
|
|
|
$this->relativeField->getInputOOUI( $value ),
|
|
|
|
|
[
|
|
|
|
|
'id' => $this->mID,
|
2017-10-06 22:17:58 +00:00
|
|
|
'required' => $this->mParams['required'] ?? false,
|
2018-03-22 05:15:16 +00:00
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-12 20:44:35 +00:00
|
|
|
public function getInputCodex( $value, $hasErrors ) {
|
|
|
|
|
return $this->relativeField->getInputCodex( $value, $hasErrors );
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-22 05:15:16 +00:00
|
|
|
/**
|
2019-02-26 12:57:24 +00:00
|
|
|
* @inheritDoc
|
2018-03-22 05:15:16 +00:00
|
|
|
*/
|
|
|
|
|
public function loadDataFromRequest( $request ) {
|
|
|
|
|
return $this->relativeField->loadDataFromRequest( $request );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the HTMLForm field by the type string.
|
|
|
|
|
*
|
|
|
|
|
* @param string $type
|
2024-06-16 18:26:43 +00:00
|
|
|
* @return HTMLFormField
|
2018-03-22 05:15:16 +00:00
|
|
|
*/
|
|
|
|
|
protected function getFieldByType( $type ) {
|
|
|
|
|
$class = HTMLForm::$typeMappings[$type];
|
|
|
|
|
$params = $this->mParams;
|
|
|
|
|
$params['type'] = $type;
|
|
|
|
|
$params['class'] = $class;
|
|
|
|
|
|
|
|
|
|
// Remove Parameters that are being used on the parent.
|
|
|
|
|
unset( $params['label-message'] );
|
|
|
|
|
return new $class( $params );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2024-02-08 15:30:18 +00:00
|
|
|
|
2024-03-07 21:56:58 +00:00
|
|
|
/** @deprecated class alias since 1.42 */
|
2024-02-08 15:30:18 +00:00
|
|
|
class_alias( HTMLExpiryField::class, 'HTMLExpiryField' );
|