3 namespace MediaWiki\Installer
;
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;
18 * Get a variable, taking local defaults into account.
20 * @param mixed|null $default
23 protected function getVar( $var, $default = null ) {
24 return $this->dbInstaller
->getVar( $var, $default );
32 protected function setVar( $name, $value ) {
33 $this->dbInstaller
->setVar( $name, $value );
37 * Return the internal name, e.g. 'mysql', or 'sqlite'.
40 protected function getName() {
41 return $this->dbInstaller
->getName();
45 * Get a labelled text box to configure a local variable.
48 * @param string $label
49 * @param array $attribs
50 * @param string $helpData 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 ) {
61 return $this->webInstaller
->getTextBox( [
64 'attribs' => $attribs,
65 'controlName' => $name,
72 * Get a labelled password box to configure a local variable.
73 * Implements password hiding.
76 * @param string $label
77 * @param array $attribs
78 * @param string $helpData 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 ) {
89 return $this->webInstaller
->getPasswordBox( [
92 'attribs' => $attribs,
93 'controlName' => $name,
100 * Get a labelled checkbox to configure a local boolean variable.
103 * @param string $label
104 * @param array $attribs Optional.
105 * @param string $helpData Optional.
108 protected function getCheckBox( $var, $label, $attribs = [], $helpData = "" ) {
109 $name = $this->getName() . '_' . $var;
110 $value = $this->getVar( $var );
112 return $this->webInstaller
->getCheckBox( [
115 'attribs' => $attribs,
116 'controlName' => $name,
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)
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
145 * @param array $varNames
148 protected function setVarsFromRequest( $varNames ) {
149 return $this->webInstaller
->setVarsFromRequest( $varNames, $this->getName() . '_' );