43 '_MysqlEngine' =>
'InnoDB',
44 '_MysqlCharset' =>
'binary',
45 '_InstallUser' =>
'root',
57 'CREATE TEMPORARY TABLES',
71 return self::checkExtension(
'mysql' ) || self::checkExtension(
'mysqli' );
82 $this->parent->getHelpBox(
'config-db-host-help' )
86 $this->
getTextBox(
'wgDBname',
'config-db-name', [
'dir' =>
'ltr' ],
87 $this->parent->getHelpBox(
'config-db-name-help' ) ) .
88 $this->
getTextBox(
'wgDBprefix',
'config-db-prefix', [
'dir' =>
'ltr' ],
89 $this->parent->getHelpBox(
'config-db-prefix-help' ) ) .
100 if ( !strlen( $newValues[
'wgDBserver'] ) ) {
101 $status->fatal(
'config-missing-db-host' );
103 if ( !strlen( $newValues[
'wgDBname'] ) ) {
104 $status->fatal(
'config-missing-db-name' );
105 } elseif ( !preg_match(
'/^[a-z0-9+_-]+$/i', $newValues[
'wgDBname'] ) ) {
106 $status->fatal(
'config-invalid-db-name', $newValues[
'wgDBname'] );
108 if ( !preg_match(
'/^[a-z0-9_-]*$/i', $newValues[
'wgDBprefix'] ) ) {
109 $status->fatal(
'config-invalid-db-prefix', $newValues[
'wgDBprefix'] );
132 $version = $conn->getServerVersion();
133 if ( version_compare( $version, $this->minimumVersion ) < 0 ) {
134 return Status::newFatal(
'config-mysql-old', $this->minimumVersion, $version );
147 'host' => $this->
getVar(
'wgDBserver' ),
148 'user' => $this->
getVar(
'_InstallUser' ),
149 'password' => $this->
getVar(
'_InstallPassword' ),
152 'tablePrefix' => $this->
getVar(
'wgDBprefix' ) ] );
155 $status->fatal(
'config-connection-error', $e->getMessage() );
166 $this->parent->showStatusError(
$status );
174 $conn->selectDB( $this->
getVar(
'wgDBname' ) );
176 # Determine existing default character set
177 if ( $conn->tableExists(
"revision", __METHOD__ ) ) {
178 $revision = $conn->buildLike( $this->
getVar(
'wgDBprefix' ) .
'revision' );
179 $res = $conn->query(
"SHOW TABLE STATUS $revision", __METHOD__ );
180 $row = $conn->fetchObject(
$res );
182 $this->parent->showMessage(
'config-show-table-status' );
183 $existingSchema =
false;
184 $existingEngine =
false;
186 if ( preg_match(
'/^latin1/', $row->Collation ) ) {
187 $existingSchema =
'latin1';
188 } elseif ( preg_match(
'/^utf8/', $row->Collation ) ) {
189 $existingSchema =
'utf8';
190 } elseif ( preg_match(
'/^binary/', $row->Collation ) ) {
191 $existingSchema =
'binary';
193 $existingSchema =
false;
194 $this->parent->showMessage(
'config-unknown-collation' );
196 if ( isset( $row->Engine ) ) {
197 $existingEngine = $row->Engine;
199 $existingEngine = $row->Type;
203 $existingSchema =
false;
204 $existingEngine =
false;
207 if ( $existingSchema && $existingSchema != $this->
getVar(
'_MysqlCharset' ) ) {
208 $this->
setVar(
'_MysqlCharset', $existingSchema );
210 if ( $existingEngine && $existingEngine != $this->
getVar(
'_MysqlEngine' ) ) {
211 $this->
setVar(
'_MysqlEngine', $existingEngine );
214 # Normal user and password are selected after this step, so for now
215 # just copy these two
216 $wgDBuser = $this->
getVar(
'_InstallUser' );
217 $wgDBpassword = $this->
getVar(
'_InstallPassword' );
234 $res = $conn->query(
'SHOW ENGINES', __METHOD__ );
235 foreach (
$res as $row ) {
236 if ( $row->Support ==
'YES' || $row->Support ==
'DEFAULT' ) {
237 $engines[] = $row->Engine;
240 $engines = array_intersect( $this->supportedEngines, $engines );
251 return [
'binary',
'utf8' ];
268 $currentName = $conn->selectField(
'',
'CURRENT_USER()',
'', __METHOD__ );
269 $parts = explode(
'@', $currentName );
270 if ( count( $parts ) != 2 ) {
273 $quotedUser = $conn->addQuotes( $parts[0] ) .
274 '@' . $conn->addQuotes( $parts[1] );
278 $res = $conn->select(
'INFORMATION_SCHEMA.USER_PRIVILEGES',
'*',
279 [
'GRANTEE' => $quotedUser ], __METHOD__ );
280 $insertMysql =
false;
281 $grantOptions = array_flip( $this->webUserPrivs );
282 foreach (
$res as $row ) {
283 if ( $row->PRIVILEGE_TYPE ==
'INSERT' ) {
286 if ( $row->IS_GRANTABLE ) {
287 unset( $grantOptions[$row->PRIVILEGE_TYPE] );
292 if ( !$insertMysql ) {
293 $row = $conn->selectRow(
'INFORMATION_SCHEMA.SCHEMA_PRIVILEGES',
'*',
295 'GRANTEE' => $quotedUser,
296 'TABLE_SCHEMA' =>
'mysql',
297 'PRIVILEGE_TYPE' =>
'INSERT',
304 if ( !$insertMysql ) {
309 $res = $conn->select(
'INFORMATION_SCHEMA.SCHEMA_PRIVILEGES',
'*',
311 'GRANTEE' => $quotedUser,
314 foreach (
$res as $row ) {
315 $regex = $conn->likeToRegex( $row->TABLE_SCHEMA );
316 if ( preg_match( $regex, $this->
getVar(
'wgDBname' ) ) ) {
317 unset( $grantOptions[$row->PRIVILEGE_TYPE] );
320 if ( count( $grantOptions ) ) {
333 $noCreateMsg =
false;
335 $noCreateMsg =
'config-db-web-no-create-privs';
342 if ( !in_array( $this->
getVar(
'_MysqlEngine' ), $engines ) ) {
343 $this->
setVar(
'_MysqlEngine', reset( $engines ) );
347 'id' =>
'dbMyisamWarning'
349 $myisamWarning =
'config-mysql-myisam-dep';
350 if ( count( $engines ) === 1 ) {
351 $myisamWarning =
'config-mysql-only-myisam-dep';
353 $s .= $this->parent->getWarningBox(
wfMessage( $myisamWarning )->
text() );
356 if ( $this->
getVar(
'_MysqlEngine' ) !=
'MyISAM' ) {
358 $s .=
'$(\'#dbMyisamWarning\').hide();';
362 if ( count( $engines ) >= 2 ) {
367 'var' =>
'_MysqlEngine',
368 'label' =>
'config-mysql-engine',
369 'itemLabelPrefix' =>
'config-mysql-',
370 'values' => $engines,
373 'class' =>
'showHideRadio',
374 'rel' =>
'dbMyisamWarning'
377 'class' =>
'hideShowRadio',
378 'rel' =>
'dbMyisamWarning'
382 $s .= $this->parent->getHelpBox(
'config-mysql-engine-help' );
387 if ( !in_array( $this->
getVar(
'_MysqlCharset' ), $charsets ) ) {
388 $this->
setVar(
'_MysqlCharset', reset( $charsets ) );
392 if ( count( $charsets ) >= 2 ) {
397 'var' =>
'_MysqlCharset',
398 'label' =>
'config-mysql-charset',
399 'itemLabelPrefix' =>
'config-mysql-',
400 'values' => $charsets
402 $s .= $this->parent->getHelpBox(
'config-mysql-charset-help' );
421 $this->
setVar(
'_CreateDBAccount',
false );
424 $create = $this->
getVar(
'_CreateDBAccount' );
431 'host' => $this->
getVar(
'wgDBserver' ),
432 'user' => $this->
getVar(
'wgDBuser' ),
433 'password' => $this->
getVar(
'wgDBpassword' ),
436 'tablePrefix' => $this->
getVar(
'wgDBprefix' )
446 if ( !in_array( $this->
getVar(
'_MysqlEngine' ), $engines ) ) {
447 $this->
setVar(
'_MysqlEngine', reset( $engines ) );
450 if ( !in_array( $this->
getVar(
'_MysqlCharset' ), $charsets ) ) {
451 $this->
setVar(
'_MysqlCharset', reset( $charsets ) );
458 # Add our user callback to installSteps, right before the tables are created.
461 'callback' => [ $this,
'setupUser' ],
463 $this->parent->addInstallStep( $callback,
'tables' );
476 $dbName = $this->
getVar(
'wgDBname' );
477 if ( !$conn->selectDB( $dbName ) ) {
479 "CREATE DATABASE " . $conn->addIdentifierQuotes( $dbName ) .
"CHARACTER SET utf8",
482 $conn->selectDB( $dbName );
493 $dbUser = $this->
getVar(
'wgDBuser' );
494 if ( $dbUser == $this->
getVar(
'_InstallUser' ) ) {
503 $dbName = $this->
getVar(
'wgDBname' );
504 $this->db->selectDB( $dbName );
505 $server = $this->
getVar(
'wgDBserver' );
506 $password = $this->
getVar(
'wgDBpassword' );
507 $grantableNames = [];
509 if ( $this->
getVar(
'_CreateDBAccount' ) ) {
515 'password' => $password,
518 'tablePrefix' => $this->
getVar(
'wgDBprefix' )
521 $tryToCreate =
false;
527 $tryToCreate =
false;
530 if ( $tryToCreate ) {
534 'localhost.localdomain',
538 $createHostList = array_unique( $createHostList );
539 $escPass = $this->db->addQuotes( $password );
541 foreach ( $createHostList
as $host ) {
545 $this->db->begin( __METHOD__ );
546 $this->db->query(
"CREATE USER $fullName IDENTIFIED BY $escPass", __METHOD__ );
547 $this->db->commit( __METHOD__ );
550 if ( $this->db->lastErrno() == 1396 ) {
552 $this->db->rollback( __METHOD__ );
553 $status->warning(
'config-install-user-alreadyexists', $dbUser );
559 $this->db->rollback( __METHOD__ );
560 $status->warning(
'config-install-user-create-failed', $dbUser, $dqe->getText() );
564 $status->warning(
'config-install-user-alreadyexists', $dbUser );
572 $dbAllTables = $this->db->addIdentifierQuotes( $dbName ) .
'.*';
573 foreach ( $grantableNames
as $name ) {
575 $this->db->begin( __METHOD__ );
576 $this->db->query(
"GRANT ALL PRIVILEGES ON $dbAllTables TO $name", __METHOD__ );
577 $this->db->commit( __METHOD__ );
579 $this->db->rollback( __METHOD__ );
580 $status->fatal(
'config-install-user-grant-failed', $dbUser, $dqe->getText() );
594 return $this->db->addQuotes(
$name ) .
'@' . $this->db->addQuotes( $host );
606 $res = $this->db->selectRow(
'mysql.user', [
'Host',
'User' ],
607 [
'Host' => $host,
'User' =>
$user ], __METHOD__ );
623 if ( $this->
getVar(
'_MysqlEngine' ) !== null ) {
626 if ( $this->
getVar(
'_MysqlCharset' ) !== null ) {
627 $options[] =
'DEFAULT CHARSET=' . $this->
getVar(
'_MysqlCharset' );
641 'wgDBname' => $this->
getVar(
'wgDBname' ),
642 'wgDBuser' => $this->
getVar(
'wgDBuser' ),
643 'wgDBpassword' => $this->
getVar(
'wgDBpassword' ),
652 return "# MySQL specific settings
653 \$wgDBprefix = \"{$prefix}\";
655 # MySQL table options to use during installation or update
656 \$wgDBTableOptions = \"{$tblOpts}\";
658 # Experimental charset support for MySQL 5.0.
659 \$wgDBmysql5 = {$dbmysql5};";
static closeElement($element)
Returns "$element>".
getSchemaVars()
Get variables to substitute into tables.sql and the SQL patch files.
Class for setting up the MediaWiki database using MySQL.
userDefinitelyExists($host, $user)
Try to see if the user account exists.
static factory($dbType, $p=[])
Construct a Database subclass instance given a database type and parameters.
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException'returning false will NOT prevent logging $e
static newFatal($message)
Factory function for fatal errors.
$wgDBpassword
Database user's password.
static escapePhpString($string)
Returns the escaped version of a string of php code.
$wgDBuser
Database username.
getVar($var, $default=null)
Get a variable, taking local defaults into account.
when a variable name is used in a it is silently declared as a new local masking the global
wfBoolToStr($value)
Convenience function converts boolean values into "true" or "false" (string) values.
getCharsets()
Get a list of character sets that are available and supported.
getConnection()
Connect to the database using the administrative user/password currently defined in the session...
static closeElement($element)
Shortcut to close an XML element.
static openElement($element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
submitWebUserBox()
Submit the form from getWebUserBox().
setupSchemaVars()
Set appropriate schema variables in the current database connection.
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock()-offset Set to overwrite offset parameter in $wgRequest set to ''to unsetoffset-wrap String Wrap the message in html(usually something like"<
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
static openElement($element, $attribs=null)
This opens an XML element.
getWebUserBox($noCreateMsg=false)
Get a standard web-user fieldset.
static newGood($value=null)
Factory function for good results.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
submitInstallUserBox()
Submit a standard install user fieldset.
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
setVarsFromRequest($varNames)
Convenience function to set variables based on form data.
getInstallUserBox()
Get a standard install-user fieldset.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
buildFullUserName($name, $host)
Return a formal 'User'@'Host' username for use in queries.
Database $db
The database connection.
canCreateAccounts()
Return true if the install user can create accounts.
getTextBox($var, $label, $attribs=[], $helpData="")
Get a labelled text box to configure a local variable.
Base class for DBMS-specific installation helper classes.
getEngines()
Get a list of storage engines that are available and supported.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
setVar($name, $value)
Convenience alias for $this->parent->setVar()
getTableOptions()
Return any table options to be applied to all tables that don't override them.
getRadioSet($params)
Get a set of labelled radio buttons.
static element($element, $attribs=[], $contents= '')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Allows to change the fields on the form that will be generated $name