Patched jquery-1.4.2 to not crash in IE7 when a style property is set with 'null...
[mediawiki.git] / includes / installer / InstallerDBType.php
blob2b03d637dc79e1a223d782f2bfddfff1e26b7f75
1 <?php
3 /**
4 * Base class for DBMS-specific installation helper classes
5 */
6 abstract class InstallerDBType {
7 /** The Installer object */
8 var $parent;
10 /* Database connection */
11 var $db;
13 /** Internal variables for installation */
14 protected $internalDefaults = array();
16 /** Array of MW configuration globals this class uses */
17 protected $globalNames = array();
19 /**
20 * Return the internal name, e.g. 'mysql', or 'sqlite'
22 abstract function getName();
24 /**
25 * @return true if the client library is compiled in
27 abstract function isCompiled();
29 /**
30 * Get an array of MW configuration globals that will be configured by this class.
32 public function getGlobalNames() {
33 return $this->globalNames;
36 /**
37 * Get HTML for a web form that configures this database. Configuration
38 * at this time should be the minimum needed to connect and test
39 * whether install or upgrade is required.
41 * If this is called, $this->parent can be assumed to be a WebInstaller
43 abstract function getConnectForm();
45 /**
46 * Set variables based on the request array, assuming it was submitted
47 * via the form returned by getConnectForm(). Validate the connection
48 * settings by attempting to connect with them.
50 * If this is called, $this->parent can be assumed to be a WebInstaller
52 * @return Status
54 abstract function submitConnectForm();
56 /**
57 * Get HTML for a web form that retrieves settings used for installation.
58 * $this->parent can be assumed to be a WebInstaller.
59 * If the DB type has no settings beyond those already configured with
60 * getConnectForm(), this should return false.
62 abstract function getSettingsForm();
64 /**
65 * Set variables based on the request array, assuming it was submitted via
66 * the form return by getSettingsForm().
67 * @return Status
69 abstract function submitSettingsForm();
71 /**
72 * Connect to the database using the administrative user/password currently
73 * defined in the session. On success, return the connection, on failure,
74 * return a Status object.
76 * This may be called multiple times, so the result should be cached.
78 abstract function getConnection();
80 /**
81 * Create the database and return a Status object indicating success or
82 * failure.
84 * @return Status
86 abstract function setupDatabase();
88 /**
89 * Create database tables from scratch
90 * @return \type Status
92 abstract function createTables();
94 /**
95 * Perform database upgrades
96 * @todo make abstract
98 /*abstract*/ function doUpgrade() {
99 return false;
103 * Return any table options to be applied to all tables that don't
104 * override them
105 * @return Array
107 function getTableOptions() {
108 return array();
112 * Get the DBMS-specific options for LocalSettings.php generation.
113 * @return String
115 abstract function getLocalSettings();
117 /**
118 * Construct and initialise parent.
119 * This is typically only called from Installer::getDBInstaller()
121 function __construct( $parent ) {
122 $this->parent = $parent;
126 * Convenience function
127 * Check if a named extension is present
129 function checkExtension( $name ) {
130 wfSuppressWarnings();
131 $compiled = extension_loaded( $name )
132 || ( $this->parent->haveDl() && dl( $name . '.' . PHP_SHLIB_SUFFIX ) );
133 wfRestoreWarnings();
134 return $compiled;
138 * Get the internationalised name for this DBMS
140 function getReadableName() {
141 return wfMsg( 'config-type-' . $this->getName() );
145 * Get a name=>value map of MW configuration globals that overrides
146 * DefaultSettings.php
148 function getGlobalDefaults() {
149 return array();
153 * Get a name=>value map of internal variables used during installation
155 public function getInternalDefaults() {
156 return $this->internalDefaults;
160 * Get a variable, taking local defaults into account
162 function getVar( $var, $default = null ) {
163 $defaults = $this->getGlobalDefaults();
164 $internal = $this->getInternalDefaults();
165 if ( isset( $defaults[$var] ) ) {
166 $default = $defaults[$var];
167 } elseif ( isset( $internal[$var] ) ) {
168 $default = $internal[$var];
170 return $this->parent->getVar( $var, $default );
174 * Convenience alias for $this->parent->setVar()
176 function setVar( $name, $value ) {
177 $this->parent->setVar( $name, $value );
181 * Get a labelled text box to configure a local variable
183 function getTextBox( $var, $label, $attribs = array() ) {
184 $name = $this->getName() . '_' . $var;
185 $value = $this->getVar( $var );
186 return $this->parent->getTextBox( array(
187 'var' => $var,
188 'label' => $label,
189 'attribs' => $attribs,
190 'controlName' => $name,
191 'value' => $value
192 ) );
196 * Get a labelled password box to configure a local variable
197 * Implements password hiding
199 function getPasswordBox( $var, $label, $attribs = array() ) {
200 $name = $this->getName() . '_' . $var;
201 $value = $this->getVar( $var );
202 return $this->parent->getPasswordBox( array(
203 'var' => $var,
204 'label' => $label,
205 'attribs' => $attribs,
206 'controlName' => $name,
207 'value' => $value
208 ) );
212 * Get a labelled checkbox to configure a local boolean variable
214 function getCheckBox( $var, $label, $attribs = array() ) {
215 $name = $this->getName() . '_' . $var;
216 $value = $this->getVar( $var );
217 return $this->parent->getCheckBox( array(
218 'var' => $var,
219 'label' => $label,
220 'attribs' => $attribs,
221 'controlName' => $name,
222 'value' => $value,
227 * Get a set of labelled radio buttons
229 * @param $params Array:
230 * Parameters are:
231 * var: The variable to be configured (required)
232 * label: The message name for the label (required)
233 * itemLabelPrefix: The message name prefix for the item labels (required)
234 * values: List of allowed values (required)
235 * itemAttribs Array of attribute arrays, outer key is the value name (optional)
238 function getRadioSet( $params ) {
239 $params['controlName'] = $this->getName() . '_' . $params['var'];
240 $params['value'] = $this->getVar( $params['var'] );
241 return $this->parent->getRadioSet( $params );
245 * Convenience function to set variables based on form data.
246 * Assumes that variables containing "password" in the name are (potentially
247 * fake) passwords.
248 * @param $varNames Array
250 function setVarsFromRequest( $varNames ) {
251 return $this->parent->setVarsFromRequest( $varNames, $this->getName() . '_' );
255 * Determine whether an existing installation of MediaWiki is present in
256 * the configured administrative connection. Returns true if there is
257 * such a wiki, false if the database doesn't exist.
259 * Traditionally, this is done by testing for the existence of either
260 * the revision table or the cur table.
262 * @return Boolean
264 function needsUpgrade() {
265 $status = $this->getConnection();
266 if ( !$status->isOK() ) {
267 return false;
269 $conn = $status->value;
270 if ( !$conn->selectDB( $this->getVar( 'wgDBname' ) ) ) {
271 return false;
273 return $conn->tableExists( 'cur' ) || $conn->tableExists( 'revision' );
277 * Get a standard install-user fieldset
279 function getInstallUserBox() {
280 return
281 Xml::openElement( 'fieldset' ) .
282 Xml::element( 'legend', array(), wfMsg( 'config-db-install-account' ) ) .
283 $this->getTextBox( '_InstallUser', 'config-db-username' ) .
284 $this->getPasswordBox( '_InstallPassword', 'config-db-password' ) .
285 $this->parent->getHelpBox( 'config-db-install-help' ) .
286 Xml::closeElement( 'fieldset' );
290 * Submit a standard install user fieldset
292 function submitInstallUserBox() {
293 $this->setVarsFromRequest( array( '_InstallUser', '_InstallPassword' ) );
294 return Status::newGood();
298 * Get a standard web-user fieldset
299 * @param $noCreateMsg String: Message to display instead of the creation checkbox.
300 * Set this to false to show a creation checkbox.
302 function getWebUserBox( $noCreateMsg = false ) {
303 $name = $this->getName();
304 $s = Xml::openElement( 'fieldset' ) .
305 Xml::element( 'legend', array(), wfMsg( 'config-db-web-account' ) ) .
306 $this->getCheckBox(
307 '_SameAccount', 'config-db-web-account-same',
308 array( 'class' => 'hideShowRadio', 'rel' => 'dbOtherAccount' )
310 Xml::openElement( 'div', array( 'id' => 'dbOtherAccount', 'style' => 'display: none;' ) ) .
311 $this->getTextBox( 'wgDBuser', 'config-db-username' ) .
312 $this->getPasswordBox( 'wgDBpassword', 'config-db-password' ) .
313 $this->parent->getHelpBox( 'config-db-web-help' );
314 if ( $noCreateMsg ) {
315 $s .= $this->parent->getWarningBox( wfMsgNoTrans( $noCreateMsg ) );
316 } else {
317 $s .= $this->getCheckBox( '_CreateDBAccount', 'config-db-web-create' );
319 $s .= Xml::closeElement( 'div' ) . Xml::closeElement( 'fieldset' );
320 return $s;
324 * Submit the form from getWebUserBox().
325 * @return Status
327 function submitWebUserBox() {
328 $this->setVarsFromRequest( array( 'wgDBuser', 'wgDBpassword',
329 '_SameAccount', '_CreateDBAccount' ) );
330 if ( $this->getVar( '_SameAccount' ) ) {
331 $this->setVar( 'wgDBuser', $this->getVar( '_InstallUser' ) );
332 $this->setVar( 'wgDBpassword', $this->getVar( '_InstallPassword' ) );
334 return Status::newGood();
338 * Common function for databases that don't understand the MySQLish syntax of interwiki.sql
340 public function populateInterwikiTable() {
341 $status = $this->getConnection();
342 if ( !$status->isOK() ) {
343 return $status;
345 $this->db->selectDB( $this->getVar( 'wgDBname' ) );
346 global $IP;
347 $rows = file( "$IP/maintenance/interwiki.list",
348 FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
349 $interwikis = array();
350 if ( !$rows ) {
351 return Status::newFatal( 'config-install-interwiki-sql' );
353 foreach( $rows as $row ) {
354 if( substr( $row, 0, 2 ) == '--' ) continue; // skip comments -- Whee
355 $interwikis[] = array_combine(
356 array( 'iw_prefix', 'iw_url', 'iw_local' ),
357 explode( '|', $row )
360 $this->db->insert( 'interwiki', $interwikis, __METHOD__ );
361 return Status::newGood();