Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
HTMLJsSelectToInputField.php
1<?php
2declare( strict_types=1 );
3
5
6use HTMLTextField;
7
14class HTMLJsSelectToInputField extends HTMLTextField {
16 public function getInputHTML( $value ): string {
17 $input = parent::getInputHTML( $value );
18
19 if ( isset( $this->mParams['select'] ) ) {
21 $select = $this->mParams['select'];
22 $input = $select->getHtmlAndPrepareJS() . '<br />' . $input;
23 }
24
25 return $input;
26 }
27
29 protected function tidy( string $value ): array {
30 $value = array_map( 'trim', explode( ',', $value ) );
31 $value = array_unique( array_filter( $value ) );
32
33 return $value;
34 }
35
37 public function validate( $value, $alldata ) {
38 $p = parent::validate( $value, $alldata );
39
40 if ( $p !== true ) {
41 return $p;
42 }
43
44 if ( !isset( $this->mParams['valid-values'] ) ) {
45 return true;
46 }
47
48 if ( $value === 'default' ) {
49 return true;
50 }
51
52 $codes = $this->tidy( $value );
53 $valid = array_flip( $this->mParams['valid-values'] );
54
55 foreach ( $codes as $code ) {
56 if ( !isset( $valid[$code] ) ) {
57 return wfMessage( 'translate-pref-editassistlang-bad', $code )->parseAsBlock();
58 }
59 }
60
61 return true;
62 }
63
65 public function filter( $value, $alldata ) {
66 $value = parent::filter( $value, $alldata );
67
68 return implode( ', ', $this->tidy( $value ) );
69 }
70}
Implementation of JsSelectToInput class which is compatible with MediaWiki's preferences system.
Essentially random collection of helper functions, similar to GlobalFunctions.php.
Definition Utilities.php:31