Page MenuHomePhabricator

Feature Request: Distinct LocalSettings.php for virtual websites
Closed, ResolvedPublic

Description

Author: mediawiki

Description:
I have MediaWiki installed on a webserver one, and want to have multiple Wikis,
each in their own database, with their own users and administrators etc. I have
the Apache virtual sites, and DNS all configured. MediaWiki only supports a
single LocalSettings.php.

I would like to in Apache say <Virtual >SetEnv MEDIAWIKI myname </Virtual> and
have MediaWiki look for myname.LocalSettings.php. config/index should also
create the correctly named settings file.

Here is a patch that does what I want:
<pre>

  • mediawiki-1.5.5/config/index.php 2006-01-06 21:17:44.000000000 +0000

+++ mediawiki-1.5.5.orig/config/index.php 2005-10-28 10:02:36.000000000 +0100
@@ -132,31 +132,15 @@

/* Check for existing configurations and bug out! */

  • Enable SetEnv override of LocalSettings.php name: virtual Wikis!
  • in Apache, you can SetEnv MEDIAWIKI mywiki and have different
  • LocalSettings.php for each named site

-$wgSiteName = getenv("MEDIAWIKI");
-if ( $wgSiteName ) {

  • $wgLocalSettings = "$wgSiteName.LocalSettings.php";

-} else {

  • $wgLocalSettings = "LocalSettings.php";

-}

    • Fail safely if SetEnv is invalid...

-if( !file_exists( "../$wgLocalSettings" ) && file_exists(
"../LocalSettings.php" ) ) {

  • $wgLocalSettings = 'LocalSettings.php';

-}

  • -

-if( file_exists( "../$wgLocalSettings" ) ) {
+if( file_exists( "../LocalSettings.php" ) ) {

	dieout( "<h2>Wiki is configured.</h2>
  • <p>Already configured... ($wgLocalSettings) <a href='../index.php'>return to

the wiki</a>.</p>
+ <p>Already configured... <a href='../index.php'>return to the wiki</a>.</p>

	<p>(You should probably remove this directory for added security.)</p>" );

}

-if( file_exists( "./$wgLocalSettings" ) ) {
+if( file_exists( "./LocalSettings.php" ) ) {

	writeSuccessMessage();

	dieout( '' );

@@ -276,7 +260,7 @@

	$conf->prettyURLs = false;
	break;

default:

  • print "unknown; using pretty URLs (<tt>index.php/Page_Title</tt>), if you have

trouble change this in <tt>$wgLocalSettings</tt>";
+ print "unknown; using pretty URLs (<tt>index.php/Page_Title</tt>), if you have
trouble change this in <tt>LocalSettings.php</tt>";
}
print "</li>\n";

@@ -690,7 +674,7 @@

		}

		/* Write out the config file now that all is well */
  • print "<p>Creating $wgLocalSettings...</p>\n\n";

+ print "<p>Creating LocalSettings.php...</p>\n\n";

		$localSettings =  "<" . "?php$endl$local$endl?" . ">";
		// Fix up a common line-ending problem (due to CVS on Windows)
		$localSettings = str_replace( "\r\n", "\n", $localSettings );

@@ -700,10 +684,10 @@

		} else {
			$xt = "wt"; # 'x' is not available prior to PHP 4.3.2. We did check above,

but race conditions blah blah

		}
  • $f = fopen( $wgLocalSettings, $xt );

+ $f = fopen( "LocalSettings.php", $xt );

		if( $f == false ) {
  • dieout( "<p>Couldn't write out $wgLocalSettings. Check that the directory

permissions are correct and that there isn't already a file of that name
here...</p>\n" .
+ dieout( "<p>Couldn't write out LocalSettings.php. Check that the directory
permissions are correct and that there isn't already a file of that name
here...</p>\n" .

			"<p>Here's the file that would have been written, try to paste it into place

manually:</p>\n" .

			"<pre>\n" . htmlspecialchars( $localSettings ) . "</pre>\n" );
		}

@@ -712,7 +696,7 @@

			writeSuccessMessage();
		} else {
			fclose( $f );
  • die("<p class='error'>An error occured while writing the

config/$wgLocalSettings file. Check user rights and disk space then try
again.</p>\n");
+ die("<p class='error'>An error occured while writing the
config/LocalSettings.php file. Check user rights and disk space then try
again.</p>\n");

		}

@@ -975,7 +959,7 @@

		<p>Avoid exotic characters; something like <tt>mw_</tt> is good.</p>
	</dt>

+

	<dd><label class="column">Database charset</label>
		<div>Select one:</div>
		<ul class="plain">

@@ -1023,18 +1007,18 @@
<p>Installation successful!</p>
<p>To complete the installation, please do the following:
<ol>

  • <li>Download config/$wgLocalSettings with your FTP client or file manager</li>

+ <li>Download config/LocalSettings.php with your FTP client or file manager</li>

	<li>Upload it to the parent directory</li>
  • <li>Delete config/$wgLocalSettings</li>

+ <li>Delete config/LocalSettings.php</li>

	<li>Start using <a href='../index.php'>your wiki</a>!

</ol>
-<p>If you are in a shared hosting environment, do <strong>not</strong> just
move $wgLocalSettings
-remotely. $wgLocalSettings is currently owned by the user your webserver is
running under,
+<p>If you are in a shared hosting environment, do <strong>not</strong> just
move LocalSettings.php
+remotely. LocalSettings.php is currently owned by the user your webserver is
running under,
which means that anyone on the same server can read your database password!
Downloading
it and uploading it again will hopefully change the ownership to a user ID
specific to you.</p>
EOT;

	} else {
  • echo "<p>Installation successful! Move the config/$wgLocalSettings file into

the parent directory, then follow
+ echo "<p>Installation successful! Move the config/LocalSettings.php file into
the parent directory, then follow

			<a href='../index.php'>this link</a> to your wiki.</p>\n";
	}

}
@@ -1125,7 +1109,6 @@

	$sep = (DIRECTORY_SEPARATOR == "\\") ? ";" : ":";
	$localsettings = "
  • $wgLocalSettings
  • This file was automatically generated by the MediaWiki installer.
  • If you make manual changes, please keep track in case you need to
  • recreate them later.

Only in mediawiki-1.5.5: debian
diff -ur mediawiki-1.5.5/index.php mediawiki-1.5.5.orig/index.php

  • mediawiki-1.5.5/index.php 2006-01-06 21:11:15.000000000 +0000

+++ mediawiki-1.5.5.orig/index.php 2005-11-16 21:29:24.000000000 +0000
@@ -16,22 +16,7 @@
define( 'MEDIAWIKI', true );
require_once( './includes/Defines.php' );

  • Enable SetEnv override of LocalSettings.php name: virtual Wikis!
  • in Apache, you can SetEnv MEDIAWIKI mywiki and have different
  • LocalSettings.php for each named site

-$wgSiteName = getenv("MEDIAWIKI");
-if ( $wgSiteName ) {

  • $wgLocalSettings = "./$wgSiteName.LocalSettings.php";

-} else {

  • $wgLocalSettings = "./LocalSettings.php";

-}

    • Fail safely if SetEnv is invalid...

-if( !file_exists( $wgLocalSettings ) && file_exists( './LocalSettings.php') ) {

  • $wgLocalSettings = './LocalSettings.php';

-}

-if( !file_exists( $wgLocalSettings ) ) {
+if( !file_exists( 'LocalSettings.php' ) ) {

	$IP = "." ;
	require_once( 'includes/DefaultSettings.php' ); # used for printing the version

?>
@@ -74,7 +59,7 @@

	die();

}

-require_once( $wgLocalSettings );
+require_once( './LocalSettings.php' );
require_once( 'includes/Setup.php' );

wfProfileIn( 'main-misc-setup' );

</pre>


Version: unspecified
Severity: normal
OS: Windows XP
Platform: PC

Details

Reference
bz4509

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 9:01 PM
bzimport set Reference to bz4509.
bzimport added a subscriber: Unknown Object (MLST).

mediawiki wrote:

Support Virtual Wikis

Attached:

  • This bug has been marked as a duplicate of 4505 ***