This repository was archived by the owner on Feb 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocalSettings.php
More file actions
191 lines (156 loc) · 5.51 KB
/
LocalSettings.php
File metadata and controls
191 lines (156 loc) · 5.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?php
# This is the LocalSettings.php file.
# This file determines the database name, loads the common settings, the $wgConf wiki-specific
# settings, skins, shared and wiki-specific extensions and the conditional CommonSettings
# This file is linked from $IP, either by symlink or by require_once( "$IP/config/LocalSettings.php" );
$configDir = __DIR__;
$wgConf = new SiteConfiguration();
$wgConf->suffixes = file( "$configDir/suffixes.list" );
# Generate the db name
if ( defined( 'MW_DB' ) ) {
// Command-line mode and maintenance scripts (e.g. update.php)
$wgDBname = MW_DB;
foreach ( $wgConf->suffixes as $suffix ) {
if ( substr( MW_DB, -strlen( $suffix ) ) === $suffix ) {
$wikiname = substr( MW_DB, 0, -strlen( $suffix ) );
break;
}
}
} else {
// Web server
$server = $_SERVER['SERVER_NAME'];
$urlComponents = explode( '.', $server );
if ( !$urlComponents ) {
require_once "$configDir/WikiNotFound404.php";
}
// Reverse the array so the tld is the first item in the array
// Content will look like:
// $urlComponents = [
// [0] => tld (org)
// [1] => domain (example)
// [2] => sub domain (www)
// [3...] => other sub domains
// ]
$urlComponents = array_reverse( $urlComponents );
// If no sub domain has been given, set it to www as default
if ( count( $urlComponents ) < 3 ) {
$urlComponents[2] = 'www';
}
// Optional: Redirect different tld's to different wikis
// Example: www.example.nl => nl.example.org
if ( $urlComponents[0] !== 'org' && $urlComponents[0] !== 'example' ) {
switch ( $urlComponents[0] ) {
default:
$urlComponents[2] = $urlComponents[0];
$urlComponents[0] = 'org';
break;
}
}
// Determine wiki name by adding all segments after the domain together
$wikiname = implode( '', array_slice( $urlComponents, 2 ) );
// Optional: Override database name of your "main" wiki (otherwise 'wwwwiki')
if ( $urlComponents[2] === 'www' ) {
$wikiname = 'meta';
}
// Determine the database name suffix by checking the domain name
// Remember to update suffixes.list when making edits to this configuration!
switch ( $urlComponents[1] ) {
default:
$suffix = 'wiki';
break;
}
$wgDBname = $wikiname . $suffix;
}
# Import private settings
require_once "$configDir/PrivateSettings.php";
# Get the shared settings for all wikis
require_once "$configDir/CommonSettings.php";
# Load the settings from InitialiseSettings.php which contains the settings for all wikis
require_once "$configDir/InitialiseSettings.php";
$wgLocalDatabases = [];
# Load all databases
$fgDatabaseList = file( "$configDir/dblists/all.dblist" );
# Set the language and site name for each database/wiki
foreach ( $fgDatabaseList as $wiki ) {
$wikiDB = explode( '|', $wiki, 3 );
list( $dbName, $siteName, $siteLang ) = array_pad( $wikiDB, 3, '' );
$wgLocalDatabases[] = trim( $dbName );
$wgConf->settings['wgSitename'][$dbName] = trim( $siteName );
$wgConf->settings['wgLanguageCode'][$dbName] = trim( $siteLang );
}
# Check if the obtained database name is in the list of databases
if ( !in_array( $wgDBname, $wgLocalDatabases ) ) {
require_once "$configDir/WikiNotFound404.php";
// Optional: Redirect to a "No such wiki" page on the central wiki.
}
/**
* Callback function used to determine the language code and suffix from a given wiki and Site configuration object.
*
* This is passed to siteParamsCallback of a SiteConfiguration instance (see below)
*
* @param SiteConfiguration $conf
* @param string $wiki
* @return array
*/
function efGetSiteParams( SiteConfiguration $conf, $wiki ) {
// phpcs:ignore MediaWiki.NamingConventions.ValidGlobalName.allowedPrefix
global $configDir;
$site = null;
$lang = null;
$tags = [];
foreach ( $conf->suffixes as $suffix ) {
if ( substr( $wiki, -strlen( $suffix ) ) === $suffix ) {
$site = $suffix;
break;
}
}
// Get a list of all the tag dblists
$tagDbLists = glob( "$configDir/dblists/tags/*" );
foreach ( $tagDbLists as $dblistfile ) {
$dblist = file( $dblistfile );
if ( in_array( $wiki, $dblist ) ) {
// Add the tag to the list of tags, which is equal to the name of the dblist, minus the
// file extension
$tags[] = basename( $dblistfile, '.dblist' );
}
}
// Set the language code based on a value in the settings area because the regular approach
// does not suffice, as sub domains are not limited to language codes
// Go the extra mile by checking the tags that are available for this wiki if an entry in the
// settings array does not exist, before picking the default language code
if ( isset( $conf->settings['wgLanguageCode'][$wiki] ) ) {
$lang = $conf->settings['wgLanguageCode'][$wiki];
} else {
foreach ( $tags as $tag ) {
if ( isset( $conf->settings['wgLanguageCode'][$tag] ) ) {
$lang = $conf->settings['wgLanguageCode'][$tag];
}
}
// Could not find the language code anywhere, so fallback to the default
if ( $lang === null ) {
$lang = $conf->settings['wgLanguageCode']['default'];
}
}
return [
'suffix' => $site,
'lang' => $lang,
'tags' => $tags,
'params' => [
'lang' => $lang,
'site' => $site,
'wiki' => $wiki,
],
];
}
$wgConf->siteParamsCallback = 'efGetSiteParams';
# Set the wikis for $wgConf
$wgConf->wikis = $wgLocalDatabases;
# Extract the globals
$wgConf->extractAllGlobals( $wgDBname );
# Load the extensions
require_once "$configDir/SharedExtensions.php";
require_once "$configDir/LocalExtensions.php";
# Load the skins
require_once "$configDir/Skins.php";
# Load the Conditional Common Settings File
require_once "$configDir/ConditionalCommonSettings.php";