Manual:$wgSharedDB

From MediaWiki.org

Jump to: navigation, search
Shared DB settings: $wgSharedDB
The name of the shared database.
Introduced in version: 1.4.0
Removed in version: still in use
Allowed Values:
Default Value: null

Other settings: Alphabetical | By Function


Contents

[edit] Details

The name of the shared database.

Shared database for multiple wikis. Commonly used for storing a user table for single sign-on (actually not real SSO, since the user may still have to log in into each wiki separately, but at least registration has to be done only once). The server for this database must be the same as for the main database. From 1.13 on you may use $wgSharedPrefix to specify a separate prefix for this database.

[edit] Read Access

Make sure that the database user you set in $wgDBuser has read-access to that database. It might be sufficient to grant read-access to the user table only.

[edit] Prior to MediaWiki 1.13

[edit] Table Prefix

The databases needs to have matching (or no) table prefixes in order to work (tested with 1.9.1 towards 1.8.2).

[edit] Table Prefix Hack

To enable the use of a shared usertable on a database that is already shared using different prefixes for each installation of MediaWiki you will need to manually edit the tableName function in Database.php under the includes folder to look like this:

 function tableName( $name ) {
     global $wgSharedDB;
     global $wgSharedDBUserTable;
     # Skip quoted literals
     if ( $name{0} != '`' ) {
          if ( $this->mTablePrefix !== '' &&  strpos( '.', $name ) === false ) {
               $name = "{$this->mTablePrefix}$name";
          }
          if ( isset( $wgSharedDB ) && "{$this->mTablePrefix}user" == $name ) {
               if ( isset($wgSharedDBUserTable) ) {
                    $name = "`$wgSharedDB`.`$wgSharedDBUserTable`";
               }
               else {
                    $name = "`$wgSharedDB`.`$name`";
               }
          } else {
               # Standard quoting
               $name = "`$name`";
          }
     }
     return $name;
 }

You will then need to set the variables $wgSharedDB and $wgSharedDBUserTable in your LocalSettings.php file. It is also advisable to define $wgSharedDBUserTable after $wgSharedDB on line 571 of DefaultSettings.php

$wgSharedDBUserTable = null;
EXPERIMENTAL!


Alternative solution for multiple tables:

 function tableName( $name ) {
     global $wgSharedDB;
     global $wgSharedTables;
     global $wgSharedPrefix;
     # Skip quoted literals
     if ( $name{0} != '`' ) {
          $found = 0;
          if ( $this->mTablePrefix !== '' &&  strpos( '.', $name ) === false ) {
               $name = "{$this->mTablePrefix}$name";
          }
 
          if ( isset( $wgSharedDB ) ) {
              foreach ($wgSharedTables as $fromshared) {
                  if ($name == $fromshared) {
                      $name = "`$wgSharedDB`.`$name`";  #you may add $wgSharedPrefix here
                      $found = 1;
                  }
              }
          }
 
          if ($found == 0) {
               # Standard quoting
               $name = "`$name`";
          }
     }
     return $name;
 }

In LocalSettings.php:

$wgSharedDB = 'wiki';
$wgSharedTables = array( 'user', 'user_groups', 'interwiki', 'ipblocks');
$wgSharedPrefix = '';

[edit] See Also

Personal tools