Merge ".mailmap: Correct two contributor names"
[mediawiki.git] / includes / installer / DatabaseForm.php
bloba674b31fa212e2258a3b65691ce33921e116cf70
1 <?php
3 namespace MediaWiki\Installer;
5 /**
6 * @internal
7 */
8 abstract class DatabaseForm {
9 protected WebInstaller $webInstaller;
10 protected DatabaseInstaller $dbInstaller;
12 public function __construct( WebInstaller $webInstaller, DatabaseInstaller $dbInstaller ) {
13 $this->webInstaller = $webInstaller;
14 $this->dbInstaller = $dbInstaller;
17 /**
18 * Get a variable, taking local defaults into account.
19 * @param string $var
20 * @param mixed|null $default
21 * @return mixed
23 protected function getVar( $var, $default = null ) {
24 return $this->dbInstaller->getVar( $var, $default );
27 /**
28 * Set a variable
29 * @param string $name
30 * @param mixed $value
32 protected function setVar( $name, $value ) {
33 $this->dbInstaller->setVar( $name, $value );
36 /**
37 * Return the internal name, e.g. 'mysql', or 'sqlite'.
38 * @return string
40 protected function getName() {
41 return $this->dbInstaller->getName();
44 /**
45 * Get a labelled text box to configure a local variable.
47 * @param string $var
48 * @param string $label
49 * @param array $attribs
50 * @param string $helpData HTML
51 * @return string HTML
52 * @return-taint escaped
54 protected function getTextBox( $var, $label, $attribs = [], $helpData = "" ) {
55 $name = $this->getName() . '_' . $var;
56 $value = $this->getVar( $var );
57 if ( $attribs === null ) {
58 $attribs = [];
61 return $this->webInstaller->getTextBox( [
62 'var' => $var,
63 'label' => $label,
64 'attribs' => $attribs,
65 'controlName' => $name,
66 'value' => $value,
67 'help' => $helpData
68 ] );
71 /**
72 * Get a labelled password box to configure a local variable.
73 * Implements password hiding.
75 * @param string $var
76 * @param string $label
77 * @param array $attribs
78 * @param string $helpData HTML
79 * @return string HTML
80 * @return-taint escaped
82 protected function getPasswordBox( $var, $label, $attribs = [], $helpData = "" ) {
83 $name = $this->getName() . '_' . $var;
84 $value = $this->getVar( $var );
85 if ( $attribs === null ) {
86 $attribs = [];
89 return $this->webInstaller->getPasswordBox( [
90 'var' => $var,
91 'label' => $label,
92 'attribs' => $attribs,
93 'controlName' => $name,
94 'value' => $value,
95 'help' => $helpData
96 ] );
99 /**
100 * Get a labelled checkbox to configure a local boolean variable.
102 * @param string $var
103 * @param string $label
104 * @param array $attribs Optional.
105 * @param string $helpData Optional.
106 * @return string
108 protected function getCheckBox( $var, $label, $attribs = [], $helpData = "" ) {
109 $name = $this->getName() . '_' . $var;
110 $value = $this->getVar( $var );
112 return $this->webInstaller->getCheckBox( [
113 'var' => $var,
114 'label' => $label,
115 'attribs' => $attribs,
116 'controlName' => $name,
117 'value' => $value,
118 'help' => $helpData
119 ] );
123 * Get a set of labelled radio buttons.
125 * @param array $params Parameters are:
126 * var: The variable to be configured (required)
127 * label: The message name for the label (required)
128 * itemLabelPrefix: The message name prefix for the item labels (required)
129 * values: List of allowed values (required)
130 * itemAttribs Array of attribute arrays, outer key is the value name (optional)
132 * @return string
134 protected function getRadioSet( $params ) {
135 $params['controlName'] = $this->getName() . '_' . $params['var'];
136 $params['value'] = $this->getVar( $params['var'] );
138 return $this->webInstaller->getRadioSet( $params );
142 * Convenience function to set variables based on form data.
143 * Assumes that variables containing "password" in the name are (potentially
144 * fake) passwords.
145 * @param array $varNames
146 * @return array
148 protected function setVarsFromRequest( $varNames ) {
149 return $this->webInstaller->setVarsFromRequest( $varNames, $this->getName() . '_' );