15 private FormOptions $formOptions;
17 public const VALID_SCALES = [
'years',
'months',
'weeks',
'days',
'hours' ];
19 public function __construct() {
20 $this->formOptions =
new FormOptions();
21 $this->formOptions->add(
'preview',
false );
22 $this->formOptions->add(
'language', [] );
23 $this->formOptions->add(
'count',
'edits' );
24 $this->formOptions->add(
'scale',
'days' );
25 $this->formOptions->add(
'days', 30 );
26 $this->formOptions->add(
'width', 800 );
27 $this->formOptions->add(
'height', 600 );
28 $this->formOptions->add(
'group', [] );
29 $this->formOptions->add(
'uselang',
'' );
30 $this->formOptions->add(
'start',
'' );
33 public function bindArray( array $inputs ):
void {
34 foreach ( $inputs as $key => $value ) {
35 if ( $this->formOptions->validateName( $key ) ) {
36 $this->formOptions[$key] = $value;
41 public function hasValue(
string $key ):
bool {
42 return isset( $this->formOptions[$key] );
45 public function setValue(
string $key, $value ):
void {
46 $this->formOptions[$key] = $value;
49 public function getValue(
string $key ) {
50 return $this->formOptions[$key];
53 public function normalize( array $validCounts ):
void {
54 $this->formOptions->validateIntBounds(
'days', 1, 10000 );
55 $this->formOptions->validateIntBounds(
'width', 200, 1000 );
56 $this->formOptions->validateIntBounds(
'height', 200, 1000 );
58 if ( $this->formOptions[
'start'] !==
'' ) {
59 $timestamp = wfTimestamp( TS_ISO_8601, $this->formOptions[
'start'] );
61 $this->formOptions[
'start'] = rtrim( $timestamp,
'Z' );
63 $this->formOptions[
'start'] =
'';
67 if ( !in_array( $this->formOptions[
'scale'], self::VALID_SCALES ) ) {
68 $this->formOptions[
'scale'] =
'days';
71 if ( $this->formOptions[
'scale'] ===
'hours' ) {
72 $this->formOptions->validateIntBounds(
'days', 1, 4 );
75 if ( !in_array( $this->formOptions[
'count'], $validCounts ) ) {
76 $this->formOptions[
'count'] =
'edits';
79 foreach ( [
'group',
'language' ] as $t ) {
80 if ( is_string( $this->formOptions[$t] ) ) {
81 $this->formOptions[$t] = explode(
',', $this->formOptions[$t] );
84 $values = array_map(
'trim', $this->formOptions[$t] );
85 $values = array_splice( $values, 0, 4 );
86 if ( $t ===
'group' ) {
88 $values = preg_replace(
'~^page_~',
'page-', $values );
90 $this->formOptions[$t] = $values;
94 public function getGroups(): array {
95 return $this->formOptions[
'group'];
98 public function getLanguages(): array {
99 return $this->formOptions[
'language'];
102 public function getFormOptions(): FormOptions {
103 return $this->formOptions;
106 public function boundValue(
string $key,
int $min,
int $max ):
void {
107 $this->formOptions->validateIntBounds( $key, $min, $max );