]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - includes/Setup.php
MediaWiki 1.5.8 (initial commit)
[autoinstalls/mediawiki.git] / includes / Setup.php
1 <?php
2 /**
3  * Include most things that's need to customize the site
4  * @package MediaWiki
5  */
6
7 /**
8  * This file is not a valid entry point, perform no further processing unless
9  * MEDIAWIKI is defined
10  */
11 if( defined( 'MEDIAWIKI' ) ) {
12
13 # The main wiki script and things like database
14 # conversion and maintenance scripts all share a
15 # common setup of including lots of classes and
16 # setting up a few globals.
17 #
18
19 // Check to see if we are at the file scope
20 if ( !isset( $wgVersion ) ) {
21         die( "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n" );
22 }
23
24 if( !isset( $wgProfiling ) )
25         $wgProfiling = false;
26
27 if ( $wgProfiling and (0 == rand() % $wgProfileSampleRate ) ) {
28         require_once( 'Profiling.php' );
29 } else {
30         function wfProfileIn( $fn = '' ) {
31                 global $hackwhere, $wgDBname;
32                 $hackwhere[] = $fn;
33                 if (function_exists("setproctitle"))
34                         setproctitle($fn . " [$wgDBname]");
35         }
36         function wfProfileOut( $fn = '' ) {
37                 global $hackwhere, $wgDBname;
38                 if (count($hackwhere))
39                         array_pop($hackwhere);
40                 if (function_exists("setproctitle") && count($hackwhere))
41                         setproctitle($hackwhere[count($hackwhere)-1] . " [$wgDBname]");
42         }
43         function wfGetProfilingOutput( $s, $e ) {}
44         function wfProfileClose() {}
45 }
46
47 $fname = 'Setup.php';
48 wfProfileIn( $fname );
49 wfProfileIn( $fname.'-includes' );
50
51 require_once( 'GlobalFunctions.php' );
52 require_once( 'Hooks.php' );
53 require_once( 'Namespace.php' );
54 require_once( 'RecentChange.php' );
55 require_once( 'User.php' );
56 require_once( 'Skin.php' );
57 require_once( 'OutputPage.php' );
58 require_once( 'LinkCache.php' );
59 require_once( 'Title.php' );
60 require_once( 'Article.php' );
61 require_once( 'MagicWord.php' );
62 require_once( 'Block.php' );
63 require_once( 'MessageCache.php' );
64 require_once( 'BlockCache.php' );
65 require_once( 'Parser.php' );
66 require_once( 'ParserCache.php' );
67 require_once( 'WebRequest.php' );
68 require_once( 'LoadBalancer.php' );
69 require_once( 'HistoryBlob.php' );
70 require_once( 'ProxyTools.php' );
71 require_once( 'ObjectCache.php' );
72 require_once( 'WikiError.php' );
73 require_once( 'SpecialPage.php' );
74
75 if ( $wgUseDynamicDates ) {
76         require_once( 'DateFormatter.php' );
77 }
78
79 wfProfileOut( $fname.'-includes' );
80 wfProfileIn( $fname.'-misc1' );
81
82 $wgIP = wfGetIP();
83 $wgRequest = new WebRequest();
84
85 # Useful debug output
86 if ( $wgCommandLineMode ) {
87         # wfDebug( '"' . implode( '"  "', $argv ) . '"' );
88 } elseif ( function_exists( 'getallheaders' ) ) {
89         wfDebug( "\n\nStart request\n" );
90         wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
91         $headers = getallheaders();
92         foreach ($headers as $name => $value) {
93                 wfDebug( "$name: $value\n" );
94         }
95         wfDebug( "\n" );
96 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
97         wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
98 }
99
100 if ( $wgSkipSkin ) {
101         $wgSkipSkins[] = $wgSkipSkin;
102 }
103
104 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
105
106 wfProfileOut( $fname.'-misc1' );
107 wfProfileIn( $fname.'-memcached' );
108
109 $wgMemc =& wfGetMainCache();
110 $messageMemc =& wfGetMessageCacheStorage();
111 $parserMemc =& wfGetParserCacheStorage();
112
113 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
114        "\nMessage cache: " . get_class( $messageMemc ) .
115            "\nParser cache: " . get_class( $parserMemc ) . "\n" );
116
117 wfProfileOut( $fname.'-memcached' );
118 wfProfileIn( $fname.'-SetupSession' );
119
120 if ( $wgDBprefix ) {
121         $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
122 } elseif ( $wgSharedDB ) {
123         $wgCookiePrefix = $wgSharedDB;
124 } else {
125         $wgCookiePrefix = $wgDBname;
126 }
127
128 session_name( $wgCookiePrefix . '_session' );
129
130 if( !$wgCommandLineMode && ( isset( $_COOKIE[session_name()] ) || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
131         User::SetupSession();
132         $wgSessionStarted = true;
133 } else {
134         $wgSessionStarted = false;
135 }
136
137 wfProfileOut( $fname.'-SetupSession' );
138 wfProfileIn( $fname.'-database' );
139
140 if ( !$wgDBservers ) {
141         $wgDBservers = array(array(
142                 'host' => $wgDBserver,
143                 'user' => $wgDBuser,
144                 'password' => $wgDBpassword,
145                 'dbname' => $wgDBname,
146                 'type' => $wgDBtype,
147                 'load' => 1,
148                 'flags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT
149         ));
150 }
151 $wgLoadBalancer = LoadBalancer::newFromParams( $wgDBservers, false, $wgMasterWaitTimeout );
152 $wgLoadBalancer->loadMasterPos();
153
154 wfProfileOut( $fname.'-database' );
155 wfProfileIn( $fname.'-language1' );
156
157 require_once( "$IP/languages/Language.php" );
158
159 function setupLangObj($langclass) {
160         global $IP;
161
162         if( ! class_exists( $langclass ) ) {
163                 # Default to English/UTF-8
164                 $baseclass = 'LanguageUtf8';
165                 require_once( "$IP/languages/$baseclass.php" );
166                 $lc = strtolower(substr($langclass, 8));
167                 $snip = "
168                         class $langclass extends $baseclass {
169                                 function getVariants() {
170                                         return array(\"$lc\");
171                                 }
172
173                         }";
174                 eval($snip);
175         }
176
177         $lang = new $langclass();
178
179         return $lang;
180 }
181
182 # $wgLanguageCode may be changed later to fit with user preference.
183 # The content language will remain fixed as per the configuration,
184 # so let's keep it.
185 $wgContLanguageCode = $wgLanguageCode;
186 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
187
188 $wgContLang = setupLangObj( $wgContLangClass );
189 $wgContLang->initEncoding();
190
191 wfProfileOut( $fname.'-language1' );
192 wfProfileIn( $fname.'-User' );
193
194 # Skin setup functions
195 # Entries can be added to this variable during the inclusion
196 # of the extension file. Skins can then perform any necessary initialisation.
197 foreach ( $wgSkinExtensionFunctions as $func ) {
198         $func();
199 }
200
201 if( !is_object( $wgAuth ) ) {
202         require_once( 'AuthPlugin.php' );
203         $wgAuth = new AuthPlugin();
204 }
205
206 if( $wgCommandLineMode ) {
207         # Used for some maintenance scripts; user session cookies can screw things up
208         # when the database is in an in-between state.
209         $wgUser = new User();
210         # Prevent loading User settings from the DB.
211         $wgUser->setLoaded( true );
212 } else {
213         $wgUser = null;
214         wfRunHooks('AutoAuthenticate',array(&$wgUser));
215         if ($wgUser === null) {
216                 $wgUser = User::loadFromSession();
217         }
218 }
219
220 wfProfileOut( $fname.'-User' );
221 wfProfileIn( $fname.'-language2' );
222
223 // wgLanguageCode now specifically means the UI language
224 $wgLanguageCode = $wgRequest->getText('uselang', '');
225 if ($wgLanguageCode == '')
226         $wgLanguageCode = $wgUser->getOption('language');
227 # Validate $wgLanguageCode, which will soon be sent to an eval()
228 if( empty( $wgLanguageCode ) || !preg_match( '/^[a-z]+(-[a-z]+)?$/', $wgLanguageCode ) ) {
229         $wgLanguageCode = $wgContLanguageCode;
230 }
231
232 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
233
234 if( $wgLangClass == $wgContLangClass ) {
235         $wgLang = &$wgContLang;
236 } else {
237         wfSuppressWarnings();
238         include_once("$IP/languages/$wgLangClass.php");
239         wfRestoreWarnings();
240
241         $wgLang = setupLangObj( $wgLangClass );
242 }
243
244 wfProfileOut( $fname.'-language2' );
245 wfProfileIn( $fname.'-MessageCache' );
246
247 $wgMessageCache = new MessageCache;
248 $wgMessageCache->initialise( $parserMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname);
249
250 wfProfileOut( $fname.'-MessageCache' );
251
252 #
253 # I guess the warning about UI switching might still apply...
254 #
255 # FIXME: THE ABOVE MIGHT BREAK NAMESPACES, VARIABLES,
256 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
257 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
258 #
259 # To disable it, the easiest thing could be to uncomment the
260 # following; they should effectively disable the UI switch functionality
261 #
262 # $wgLangClass = $wgContLangClass;
263 # $wgLanguageCode = $wgContLanguageCode;
264 # $wgLang = $wgContLang;
265 #
266 # TODO: Need to change reference to $wgLang to $wgContLang at proper
267 #       places, including namespaces, dates in signatures, magic words,
268 #       and links
269 #
270 # TODO: Need to look at the issue of input/output encoding
271 #
272
273
274 wfProfileIn( $fname.'-OutputPage' );
275
276 $wgOut = new OutputPage();
277
278 wfProfileOut( $fname.'-OutputPage' );
279 wfProfileIn( $fname.'-BlockCache' );
280
281 $wgBlockCache = new BlockCache( true );
282
283 wfProfileOut( $fname.'-BlockCache' );
284 wfProfileIn( $fname.'-misc2' );
285
286 $wgDeferredUpdateList = array();
287 $wgPostCommitUpdateList = array();
288
289 $wgLinkCache = new LinkCache();
290 $wgMagicWords = array();
291 $wgMwRedir =& MagicWord::get( MAG_REDIRECT );
292 $wgParserCache = new ParserCache( $messageMemc );
293
294 if ( $wgUseXMLparser ) {
295         require_once( 'ParserXML.php' );
296         $wgParser = new ParserXML();
297 } else {
298         $wgParser = new Parser();
299 }
300 $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
301 $wgMsgParserOptions = ParserOptions::newFromUser($wgUser);
302 wfSeedRandom();
303
304 # Placeholders in case of DB error
305 $wgTitle = Title::makeTitle( NS_SPECIAL, 'Error' );
306 $wgArticle = new Article($wgTitle);
307
308 wfProfileOut( $fname.'-misc2' );
309 wfProfileIn( $fname.'-extensions' );
310
311 # Extension setup functions for extensions other than skins
312 # Entries should be added to this variable during the inclusion
313 # of the extension file. This allows the extension to perform
314 # any necessary initialisation in the fully initialised environment
315 foreach ( $wgExtensionFunctions as $func ) {
316         $func();
317 }
318
319 wfDebug( "\n" );
320 $wgFullyInitialised = true;
321 wfProfileOut( $fname.'-extensions' );
322 wfProfileOut( $fname );
323
324 }
325 ?>