Skip to content

Instantly share code, notes, and snippets.

@lethosor
Last active January 4, 2016 09:49
Show Gist options
  • Save lethosor/8604512 to your computer and use it in GitHub Desktop.
Save lethosor/8604512 to your computer and use it in GitHub Desktop.
LocalSettings.php allowing multiple MW instances in the same directory
#! /usr/bin/python
import re, os, readline, sys
input = raw_input if sys.version_info.major == 2 else input
choices = []
for f in os.listdir('settings'):
if re.match(r'^[a-z]+\.php', f):
choices.append(f.replace('.php', ''))
def set_wiki(wiki):
if wiki in choices:
with open('active_wiki.txt', 'w') as f:
f.write(wiki)
return True
return False
first = True
while True:
for arg in sys.argv[1:]:
if set_wiki(arg):
sys.exit()
if first:
first = False
print('Available wikis:')
for wiki in choices:
print('* %s' % wiki)
wiki = input('Select active wiki: ')
if set_wiki(wiki):
sys.exit()
<?php
namespace Localsettings_switch;
$wikis = array(); // Add wikis to this array, corresponding to settings file - e.g. "test" should have its settings in settings/test.php
$activeWiki = preg_replace('/[^a-z]/', '', @file_get_contents(__DIR__ . '/active_wiki.txt'));
$settings = __DIR__ . "/settings/$activeWiki.php";
if (in_array($activeWiki, $wikis) && file_exists($settings)) {
require_once $settings;
}
else {
$wikis = implode("</li>\n<li>", $wikis);
$help = <<<END
<h1>Error</h1>
<p>The specified wiki ("$activeWiki") is not valid. Possible reasons:</p>
<ol>
<li>active_wiki.txt is empty or does not refer to a valid wiki</li>
<li>You forgot to add the specified wiki to \$wikis in LocalSettings.php</li>
<li>The wiki's settings file does not exist</li>
</ol>
<h2>Valid wikis are:</h2>
<ul><li>$wikis</li></ul>
END;
if (php_sapi_name() == 'cli') $help = strip_tags($help);
die($help);
}
require_once(__DIR__ . '/settings/_common.php');
@lethosor
Copy link
Author

"Multiwiki.php" should be renamed to "LocalSettings.php"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment