Conversion from 1.4 schema, zero downtime
[lhc/web/wiklou.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
52 require_once( 'GlobalFunctions.php' );
53 require_once( 'Hooks.php' );
54 require_once( 'Namespace.php' );
55 require_once( 'RecentChange.php' );
56 require_once( 'User.php' );
57 require_once( 'Skin.php' );
58 require_once( 'OutputPage.php' );
59 require_once( 'LinkCache.php' );
60 require_once( 'Title.php' );
61 require_once( 'Article.php' );
62 require_once( 'MagicWord.php' );
63 require_once( 'Block.php' );
64 require_once( 'MessageCache.php' );
65 require_once( 'BlockCache.php' );
66 require_once( 'Parser.php' );
67 require_once( 'Parser.php' );
68 require_once( 'ParserCache.php' );
69 require_once( 'WebRequest.php' );
70 require_once( 'LoadBalancer.php' );
71 require_once( 'HistoryBlob.php' );
72 require_once( 'ProxyTools.php' );
73 require_once( 'ObjectCache.php' );
74
75 wfProfileOut( $fname.'-includes' );
76 wfProfileIn( $fname.'-misc1' );
77
78 $wgIP = wfGetIP();
79 $wgRequest = new WebRequest();
80
81 # Useful debug output
82 if ( $wgCommandLineMode ) {
83 # wfDebug( '"' . implode( '" "', $argv ) . '"' );
84 } elseif ( function_exists( 'getallheaders' ) ) {
85 wfDebug( "\n\nStart request\n" );
86 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
87 $headers = getallheaders();
88 foreach ($headers as $name => $value) {
89 wfDebug( "$name: $value\n" );
90 }
91 wfDebug( "\n" );
92 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
93 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
94 }
95
96 # Disable linkscc except if the old existence check method is enabled
97 if (!$wgUseOldExistenceCheck) {
98 $wgEnablePersistentLC = false;
99 }
100
101 wfProfileOut( $fname.'-misc1' );
102 wfProfileIn( $fname.'-memcached' );
103
104 $wgMemc =& wfGetMainCache();
105 $messageMemc =& wfGetMessageCacheStorage();
106 $parserMemc =& wfGetParserCacheStorage();
107
108 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
109 "\nMessage cache: " . get_class( $messageMemc ) .
110 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
111
112 wfProfileOut( $fname.'-memcached' );
113 wfProfileIn( $fname.'-SetupSession' );
114
115 if( !$wgCommandLineMode && ( isset( $_COOKIE[ini_get('session.name')] ) || isset( $_COOKIE[$wgDBname.'Token'] ) ) ) {
116 User::SetupSession();
117 $wgSessionStarted = true;
118 } else {
119 $wgSessionStarted = false;
120 }
121
122 wfProfileOut( $fname.'-SetupSession' );
123 wfProfileIn( $fname.'-database' );
124
125 if ( !$wgDBservers ) {
126 $wgDBservers = array(array(
127 'host' => $wgDBserver,
128 'user' => $wgDBuser,
129 'password' => $wgDBpassword,
130 'dbname' => $wgDBname,
131 'type' => $wgDBtype,
132 'load' => 1,
133 'flags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT
134 ));
135 }
136 $wgLoadBalancer = LoadBalancer::newFromParams( $wgDBservers, false, $wgMasterWaitTimeout );
137 $wgLoadBalancer->loadMasterPos();
138
139 wfProfileOut( $fname.'-database' );
140 wfProfileIn( $fname.'-language1' );
141
142 require_once( "$IP/languages/Language.php" );
143
144 wfProfileOut( $fname.'-language1' );
145 wfProfileIn( $fname.'-User' );
146
147 # Skin setup functions
148 # Entries can be added to this variable during the inclusion
149 # of the extension file. Skins can then perform any necessary initialisation.
150 foreach ( $wgSkinExtensionFunctions as $func ) {
151 $func();
152 }
153
154 if( !is_object( $wgAuth ) ) {
155 require_once( 'AuthPlugin.php' );
156 $wgAuth = new AuthPlugin();
157 }
158
159 if( $wgCommandLineMode ) {
160 # Used for some maintenance scripts; user session cookies can screw things up
161 # when the database is in an in-between state.
162 $wgUser = new User();
163 # Prevent loading User settings from the DB.
164 $wgUser->setLoaded( true );
165 } else {
166 $wgUser = User::loadFromSession();
167 }
168
169 wfProfileOut( $fname.'-User' );
170 wfProfileIn( $fname.'-language2' );
171
172 function setupLangObj(&$langclass) {
173 global $IP;
174
175 if( ! class_exists( $langclass ) ) {
176 # Default to English/UTF-8
177 $baseclass = 'LanguageUtf8';
178 require_once( "$IP/languages/$baseclass.php" );
179 $lc = strtolower(substr($langclass, 8));
180 $snip = "
181 class $langclass extends $baseclass {
182 function getVariants() {
183 return array(\"$lc\");
184 }
185
186 }";
187 eval($snip);
188 }
189
190 $lang = new $langclass();
191
192 return $lang;
193 }
194
195 # $wgLanguageCode may be changed later to fit with user preference.
196 # The content language will remain fixed as per the configuration,
197 # so let's keep it.
198 $wgContLanguageCode = $wgLanguageCode;
199 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
200
201 $wgContLang = setupLangObj( $wgContLangClass );
202 $wgContLang->initEncoding();
203
204 // set default user option from content language
205 if( !$wgUser->mDataLoaded ) {
206 $wgUser->loadDefaultFromLanguage();
207 }
208
209 // wgLanguageCode now specifically means the UI language
210 $wgLanguageCode = $wgUser->getOption('language');
211 # Validate $wgLanguageCode, which will soon be sent to an eval()
212 if( empty( $wgLanguageCode ) || !preg_match( '/^[a-z\-]*$/', $wgLanguageCode ) ) {
213 $wgLanguageCode = $wgContLanguageCode;
214 }
215
216 $wgLangClass = 'Language'. str_replace( '-', '_', ucfirst( $wgLanguageCode ) );
217
218 if( $wgLangClass == $wgContLangClass ) {
219 $wgLang = &$wgContLang;
220 } else {
221 wfSuppressWarnings();
222 include_once("$IP/languages/$wgLangClass.php");
223 wfRestoreWarnings();
224
225 $wgLang = setupLangObj( $wgLangClass );
226 }
227
228 wfProfileOut( $fname.'-language' );
229 wfProfileIn( $fname.'-MessageCache' );
230
231 $wgMessageCache = new MessageCache;
232 $wgMessageCache->initialise( $parserMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $wgDBname);
233
234 wfProfileOut( $fname.'-MessageCache' );
235
236 #
237 # I guess the warning about UI switching might still apply...
238 #
239 # FIXME: THE ABOVE MIGHT BREAK NAMESPACES, VARIABLES,
240 # SEARCH INDEX UPDATES, AND MANY MANY THINGS.
241 # DO NOT USE THIS MODE EXCEPT FOR TESTING RIGHT NOW.
242 #
243 # To disable it, the easiest thing could be to uncomment the
244 # following; they should effectively disable the UI switch functionality
245 #
246 # $wgLangClass = $wgContLangClass;
247 # $wgLanguageCode = $wgContLanguageCode;
248 # $wgLang = $wgContLang;
249 #
250 # TODO: Need to change reference to $wgLang to $wgContLang at proper
251 # places, including namespaces, dates in signatures, magic words,
252 # and links
253 #
254 # TODO: Need to look at the issue of input/output encoding
255 #
256
257
258 wfProfileIn( $fname.'-OutputPage' );
259
260 $wgOut = new OutputPage();
261
262 wfProfileOut( $fname.'-OutputPage' );
263 wfProfileIn( $fname.'-DateFormatter' );
264
265 if ( $wgUseDynamicDates ) {
266 require_once( 'DateFormatter.php' );
267 $wgDateFormatter = new DateFormatter;
268 }
269
270 wfProfileOut( $fname.'-DateFormatter' );
271 wfProfileIn( $fname.'-BlockCache' );
272
273 $wgBlockCache = new BlockCache( true );
274
275 wfProfileOut( $fname.'-BlockCache' );
276 wfProfileIn( $fname.'-misc2' );
277
278 $wgDeferredUpdateList = array();
279 $wgPostCommitUpdateList = array();
280
281 $wgLinkCache = new LinkCache();
282 $wgMagicWords = array();
283 $wgMwRedir =& MagicWord::get( MAG_REDIRECT );
284 $wgParserCache = new ParserCache( $messageMemc );
285
286 if ( $wgUseXMLparser ) {
287 require_once( 'ParserXML.php' );
288 $wgParser = new ParserXML();
289 } else {
290 $wgParser = new Parser();
291 }
292 $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
293 $wgMsgParserOptions = ParserOptions::newFromUser($wgUser);
294 wfSeedRandom();
295
296 # Placeholders in case of DB error
297 $wgTitle = Title::makeTitle( NS_SPECIAL, 'Error' );
298 $wgArticle = new Article($wgTitle);
299
300 wfProfileOut( $fname.'-misc2' );
301 wfProfileIn( $fname.'-extensions' );
302
303 # Extension setup functions for extensions other than skins
304 # Entries should be added to this variable during the inclusion
305 # of the extension file. This allows the extension to perform
306 # any necessary initialisation in the fully initialised environment
307 foreach ( $wgExtensionFunctions as $func ) {
308 $func();
309 }
310
311 wfDebug( "\n" );
312 $wgFullyInitialised = true;
313 wfProfileOut( $fname.'-extensions' );
314 wfProfileOut( $fname );
315
316 }
317 ?>