18 public const VALID_SCALES = [
'years',
'months',
'weeks',
'days',
'hours' ];
20 public function __construct() {
21 $this->formOptions =
new FormOptions();
22 $this->formOptions->add(
'preview',
false );
23 $this->formOptions->add(
'language', [] );
24 $this->formOptions->add(
'count',
'edits' );
25 $this->formOptions->add(
'scale',
'days' );
26 $this->formOptions->add(
'days', 30 );
27 $this->formOptions->add(
'width', 800 );
28 $this->formOptions->add(
'height', 600 );
29 $this->formOptions->add(
'group', [] );
30 $this->formOptions->add(
'uselang',
'' );
31 $this->formOptions->add(
'start',
'' );
34 public function bindArray( array $inputs ):
void {
35 foreach ( $inputs as $key => $value ) {
36 if ( $this->formOptions->validateName( $key ) ) {
37 $this->formOptions[$key] = $value;
42 public function hasValue(
string $key ):
bool {
43 return isset( $this->formOptions[$key] );
46 public function setValue(
string $key, $value ):
void {
47 $this->formOptions[$key] = $value;
50 public function getValue(
string $key ) {
51 return $this->formOptions[$key];
54 public function normalize( array $validCounts ):
void {
55 $this->formOptions->validateIntBounds(
'days', 1, 10000 );
56 $this->formOptions->validateIntBounds(
'width', 200, 1000 );
57 $this->formOptions->validateIntBounds(
'height', 200, 1000 );
59 if ( $this->formOptions[
'start'] !==
'' ) {
60 $timestamp = wfTimestamp( TS_ISO_8601, $this->formOptions[
'start'] );
62 $this->formOptions[
'start'] = rtrim( $timestamp,
'Z' );
64 $this->formOptions[
'start'] =
'';
68 if ( !in_array( $this->formOptions[
'scale'], self::VALID_SCALES ) ) {
69 $this->formOptions[
'scale'] =
'days';
72 if ( $this->formOptions[
'scale'] ===
'hours' ) {
73 $this->formOptions->validateIntBounds(
'days', 1, 4 );
76 if ( !in_array( $this->formOptions[
'count'], $validCounts ) ) {
77 $this->formOptions[
'count'] =
'edits';
80 foreach ( [
'group',
'language' ] as $t ) {
81 if ( is_string( $this->formOptions[$t] ) ) {
82 $this->formOptions[$t] = explode(
',', $this->formOptions[$t] );
85 $values = array_map(
'trim', $this->formOptions[$t] );
86 $values = array_splice( $values, 0, 4 );
87 if ( $t ===
'group' ) {
89 $values = preg_replace(
'~^page_~',
'page-', $values );
91 $this->formOptions[$t] = $values;
95 public function getGroups(): array {
96 return $this->formOptions[
'group'];
99 public function getLanguages(): array {
100 return $this->formOptions[
'language'];
103 public function getFormOptions(): FormOptions {
104 return $this->formOptions;
107 public function boundValue(
string $key,
int $min,
int $max ):
void {
108 $this->formOptions->validateIntBounds( $key, $min, $max );