42 '_InstallUser' =>
'postgres',
55 return self::checkExtension(
'pgsql' );
63 $this->parent->getHelpBox(
'config-db-host-help' )
65 $this->
getTextBox(
'wgDBport',
'config-db-port' ) .
72 $this->parent->getHelpBox(
'config-db-name-help' )
78 $this->parent->getHelpBox(
'config-db-schema-help' )
95 if ( !strlen( $newValues[
'wgDBname'] ) ) {
96 $status->fatal(
'config-missing-db-name' );
97 } elseif ( !preg_match(
'/^[a-zA-Z0-9_]+$/', $newValues[
'wgDBname'] ) ) {
98 $status->fatal(
'config-invalid-db-name', $newValues[
'wgDBname'] );
100 if ( !preg_match(
'/^[a-zA-Z0-9_]*$/', $newValues[
'wgDBmwschema'] ) ) {
101 $status->fatal(
'config-invalid-schema', $newValues[
'wgDBmwschema'] );
122 $version = $conn->getServerVersion();
123 if ( version_compare( $version, $this->minimumVersion ) < 0 ) {
124 return Status::newFatal(
'config-postgres-old', $this->minimumVersion, $version );
127 $this->
setVar(
'wgDBuser', $this->
getVar(
'_InstallUser' ) );
128 $this->
setVar(
'wgDBpassword', $this->
getVar(
'_InstallPassword' ) );
158 'host' => $this->
getVar(
'wgDBserver' ),
160 'password' => $password,
162 'schema' => $schema ] );
165 $status->fatal(
'config-connection-error', $e->getMessage() );
177 if ( isset( $this->pgConns[
$type] ) ) {
188 $conn->commit( __METHOD__ );
189 $this->pgConns[
$type] = $conn;
224 $this->
getVar(
'_InstallUser' ),
225 $this->
getVar(
'_InstallPassword' ) );
226 case 'create-schema':
228 $this->
getVar(
'_InstallUser' ),
229 $this->
getVar(
'_InstallPassword' ),
230 $this->
getVar(
'wgDBname' ),
231 $this->
getVar(
'wgDBmwschema' ) );
232 case 'create-tables':
239 $safeRole = $conn->addIdentifierQuotes( $this->
getVar(
'wgDBuser' ) );
240 $conn->query(
"SET ROLE $safeRole" );
245 throw new MWException(
"Invalid special connection type: \"$type\"" );
254 if ( !in_array( $this->
getVar(
'wgDBname' ), $dbs ) ) {
255 array_unshift( $dbs, $this->
getVar(
'wgDBname' ) );
259 foreach ( $dbs
as $db ) {
262 'host' => $this->
getVar(
'wgDBserver' ),
264 'password' => $password,
270 $status->fatal(
'config-pg-test-error', $db,
271 $error->getMessage() );
273 if ( $conn !==
false ) {
277 if ( $conn !==
false ) {
293 $superuser = $this->
getVar(
'_InstallUser' );
295 $row = $conn->selectRow(
'"pg_catalog"."pg_roles"',
'*',
296 [
'rolname' => $superuser ], __METHOD__ );
307 return $perms->rolsuper ===
't' || $perms->rolcreaterole ===
't';
316 return $perms->rolsuper ===
't';
321 $noCreateMsg =
false;
323 $noCreateMsg =
'config-db-web-no-create-privs';
336 $same = $this->
getVar(
'wgDBuser' ) === $this->
getVar(
'_InstallUser' );
347 $exists =
$status->value->roleExists( $this->
getVar(
'wgDBuser' ) );
352 $create = $this->
getVar(
'_CreateDBAccount' );
354 $this->
setVar(
'_CreateDBAccount',
false );
358 if ( !$create && !$exists ) {
360 $msg =
'config-install-user-missing-create';
362 $msg =
'config-install-user-missing';
375 $this->
getVar(
'wgDBuser' ),
376 $this->
getVar(
'wgDBpassword' ) );
406 $installerId = $conn->selectField(
'"pg_catalog"."pg_roles"',
'oid',
407 [
'rolname' => $this->
getVar(
'_InstallUser' ) ], __METHOD__ );
408 $webId = $conn->selectField(
'"pg_catalog"."pg_roles"',
'oid',
409 [
'rolname' => $this->
getVar(
'wgDBuser' ) ], __METHOD__ );
411 return $this->
isRoleMember( $conn, $installerId, $webId, $this->maxRoleSearchDepth );
422 protected function isRoleMember( $conn, $targetMember, $group, $maxDepth ) {
423 if ( $targetMember === $group ) {
428 $res = $conn->select(
'"pg_catalog"."pg_auth_members"', [
'member' ],
429 [
'roleid' => $group ], __METHOD__ );
430 foreach (
$res as $row ) {
431 if ( $row->member == $targetMember ) {
437 if ( $maxDepth > 0 ) {
438 if ( $this->
isRoleMember( $conn, $targetMember, $row->member, $maxDepth - 1 ) ) {
451 'callback' => [ $this,
'setupUser' ],
454 'name' =>
'pg-commit',
455 'callback' => [ $this,
'commitChanges' ],
458 'name' =>
'pg-plpgsql',
459 'callback' => [ $this,
'setupPLpgSQL' ],
463 'callback' => [ $this,
'setupSchema' ]
466 if ( $this->
getVar(
'_CreateDBAccount' ) ) {
467 $this->parent->addInstallStep( $createDbAccount,
'database' );
469 $this->parent->addInstallStep( $commitCB,
'interwiki' );
470 $this->parent->addInstallStep( $plpgCB,
'database' );
471 $this->parent->addInstallStep( $schemaCB,
'database' );
481 $dbName = $this->
getVar(
'wgDBname' );
483 $exists = $conn->selectField(
'"pg_catalog"."pg_database"',
'1',
484 [
'datname' => $dbName ], __METHOD__ );
486 $safedb = $conn->addIdentifierQuotes( $dbName );
487 $conn->query(
"CREATE DATABASE $safedb", __METHOD__ );
502 $schema = $this->
getVar(
'wgDBmwschema' );
503 $safeschema = $conn->addIdentifierQuotes( $schema );
504 $safeuser = $conn->addIdentifierQuotes( $this->
getVar(
'wgDBuser' ) );
505 if ( !$conn->schemaExists( $schema ) ) {
507 $conn->query(
"CREATE SCHEMA $safeschema AUTHORIZATION $safeuser" );
510 $this->
getVar(
'_InstallUser' ), $schema );
515 $conn->determineCoreSchema( $schema );
521 $this->db->commit( __METHOD__ );
527 if ( !$this->
getVar(
'_CreateDBAccount' ) ) {
537 $safeuser = $conn->addIdentifierQuotes( $this->
getVar(
'wgDBuser' ) );
538 $safepass = $conn->addQuotes( $this->
getVar(
'wgDBpassword' ) );
541 $userExists = $conn->roleExists( $this->
getVar(
'wgDBuser' ) );
542 if ( !$userExists ) {
545 $sql =
"CREATE ROLE $safeuser NOCREATEDB LOGIN PASSWORD $safepass";
551 $sql .=
' ROLE' . $conn->addIdentifierQuotes( $this->
getVar(
'_InstallUser' ) );
554 $conn->query( $sql, __METHOD__ );
557 $this->
getVar(
'wgDBuser' ), $e->getMessage() );
565 $port = $this->
getVar(
'wgDBport' );
566 $schema = $this->
getVar(
'wgDBmwschema' );
568 return "# Postgres specific settings
569 \$wgDBport = \"{$port}\";
570 \$wgDBmwschema = \"{$schema}\";";
576 # Normal user and password are selected after this step, so for now
577 # just copy these two
578 $wgDBuser = $this->
getVar(
'_InstallUser' );
579 $wgDBpassword = $this->
getVar(
'_InstallPassword' );
583 $schema = $this->
getVar(
'wgDBmwschema' );
593 if ( $conn->tableExists(
'archive' ) ) {
594 $status->warning(
'config-install-tables-exist' );
600 $conn->begin( __METHOD__ );
602 if ( !$conn->schemaExists( $schema ) ) {
603 $status->fatal(
'config-install-pg-schema-not-exist' );
608 if ( $error !==
true ) {
609 $conn->reportQueryError( $error, 0,
'', __METHOD__ );
610 $conn->rollback( __METHOD__ );
611 $status->fatal(
'config-install-tables-failed', $error );
613 $conn->commit( __METHOD__ );
626 return array_merge( parent::getGlobalDefaults(), [
627 'wgDBmwschema' =>
'mediawiki',
643 $exists = $conn->selectField(
'"pg_catalog"."pg_language"', 1,
644 [
'lanname' =>
'plpgsql' ], __METHOD__ );
652 $exists = $conn->selectField(
653 [
'"pg_catalog"."pg_class"',
'"pg_catalog"."pg_namespace"' ],
656 'pg_namespace.oid=relnamespace',
657 'nspname' =>
'pg_catalog',
658 'relname' =>
'pg_pltemplate',
663 $conn->query(
'CREATE LANGUAGE plpgsql' );
static closeElement($element)
Returns "$element>".
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.
openConnectionToAnyDB($user, $password)
$wgDBpassword
Database user's password.
getPgConnection($type)
Get a special type of connection.
$wgDBuser
Database username.
isRoleMember($conn, $targetMember, $group, $maxDepth)
Recursive helper for canCreateObjectsForWebUser().
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
getInstallUserPermissions()
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().
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"<
openConnectionWithParams($user, $password, $dbName, $schema)
Open a PG connection with given parameters.
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.
openPgConnection($type)
Get a connection of a specific PostgreSQL-specific type.
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
Database $db
The database connection.
getTextBox($var, $label, $attribs=[], $helpData="")
Get a labelled text box to configure a local variable.
Class for setting up the MediaWiki database using Postgres.
Base class for DBMS-specific installation helper classes.
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
canCreateObjectsForWebUser()
Returns true if the install user is able to create objects owned by the web user, false otherwise...
setVar($name, $value)
Convenience alias for $this->parent->setVar()
getSchemaPath($db)
Return a path to the DBMS-specific schema file, otherwise default to tables.sql.
static element($element, $attribs=[], $contents= '')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
enableLB()
Set up LBFactory so that wfGetDB() etc.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type