* (bug 10181) Support the XCache object caching mechanism [patch from Kurt Radwanski]
[lhc/web/wiklou.git] / includes / Setup.php
1 <?php
2 /**
3 * Include most things that's need to customize the site
4 */
5
6 /**
7 * This file is not a valid entry point, perform no further processing unless
8 * MEDIAWIKI is defined
9 */
10 if( !defined( 'MEDIAWIKI' ) ) {
11 echo "This file is part of MediaWiki, it is not a valid entry point.\n";
12 exit( 1 );
13 }
14
15 # The main wiki script and things like database
16 # conversion and maintenance scripts all share a
17 # common setup of including lots of classes and
18 # setting up a few globals.
19 #
20
21 $fname = 'Setup.php';
22 wfProfileIn( $fname );
23
24 // Check to see if we are at the file scope
25 if ( !isset( $wgVersion ) ) {
26 echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
27 die( 1 );
28 }
29
30 // Set various default paths sensibly...
31 if( $wgScript === false ) $wgScript = "$wgScriptPath/index.php";
32 if( $wgRedirectScript === false ) $wgRedirectScript = "$wgScriptPath/redirect.php";
33
34 if( $wgArticlePath === false ) {
35 if( $wgUsePathInfo ) {
36 $wgArticlePath = "$wgScript/$1";
37 } else {
38 $wgArticlePath = "$wgScript?title=$1";
39 }
40 }
41
42 if( $wgStylePath === false ) $wgStylePath = "$wgScriptPath/skins";
43 if( $wgStyleDirectory === false) $wgStyleDirectory = "$IP/skins";
44
45 if( $wgLogo === false ) $wgLogo = "$wgStylePath/common/images/wiki.png";
46
47 if( $wgUploadPath === false ) $wgUploadPath = "$wgScriptPath/images";
48 if( $wgUploadDirectory === false ) $wgUploadDirectory = "$IP/images";
49
50 if( $wgMathPath === false ) $wgMathPath = "{$wgUploadPath}/math";
51 if( $wgMathDirectory === false ) $wgMathDirectory = "{$wgUploadDirectory}/math";
52 if( $wgTmpDirectory === false ) $wgTmpDirectory = "{$wgUploadDirectory}/tmp";
53
54 if( $wgReadOnlyFile === false ) $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
55 if( $wgFileCacheDirectory === false ) $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
56
57 /**
58 * Initialise $wgLocalFileRepo from backwards-compatible settings
59 */
60 if ( !$wgLocalFileRepo ) {
61 $wgLocalFileRepo = array(
62 'class' => 'LocalRepo',
63 'name' => 'local',
64 'directory' => $wgUploadDirectory,
65 'url' => $wgUploadBaseUrl ? $wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
66 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
67 'thumbScriptUrl' => $wgThumbnailScriptPath,
68 'transformVia404' => !$wgGenerateThumbnailOnParse,
69 );
70 }
71 /**
72 * Initialise shared repo from backwards-compatible settings
73 */
74 if ( $wgUseSharedUploads ) {
75 if ( $wgSharedUploadDBname ) {
76 $wgForeignFileRepos[] = array(
77 'class' => 'ForeignDBRepo',
78 'name' => 'shared',
79 'directory' => $wgSharedUploadDirectory,
80 'url' => $wgSharedUploadPath,
81 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
82 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
83 'transformVia404' => !$wgGenerateThumbnailOnParse,
84 'dbType' => $wgDBtype,
85 'dbServer' => $wgDBserver,
86 'dbUser' => $wgDBuser,
87 'dbPassword' => $wgDBpassword,
88 'dbName' => $wgSharedUploadDBname,
89 'dbFlags' => DBO_DEFAULT,
90 'tablePrefix' => $wgSharedUploadDBprefix,
91 'hasSharedCache' => $wgCacheSharedUploads,
92 'descBaseUrl' => $wgRepositoryBaseUrl,
93 'fetchDescription' => $wgFetchCommonsDescriptions,
94 );
95 } else {
96 $wgForeignFileRepos[] = array(
97 'class' => 'FSRepo',
98 'name' => 'shared',
99 'directory' => $wgSharedUploadDirectory,
100 'url' => $wgSharedUploadPath,
101 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
102 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
103 'transformVia404' => !$wgGenerateThumbnailOnParse,
104 'descBaseUrl' => $wgRepositoryBaseUrl,
105 'fetchDescription' => $wgFetchCommonsDescriptions,
106 );
107 }
108 }
109
110 require_once( "$IP/includes/AutoLoader.php" );
111
112 wfProfileIn( $fname.'-exception' );
113 require_once( "$IP/includes/Exception.php" );
114 wfInstallExceptionHandler();
115 wfProfileOut( $fname.'-exception' );
116
117 wfProfileIn( $fname.'-includes' );
118 require_once( "$IP/includes/GlobalFunctions.php" );
119 require_once( "$IP/includes/Hooks.php" );
120 require_once( "$IP/includes/Namespace.php" );
121 require_once( "$IP/includes/ProxyTools.php" );
122 require_once( "$IP/includes/ObjectCache.php" );
123 require_once( "$IP/includes/ImageFunctions.php" );
124 require_once( "$IP/includes/StubObject.php" );
125 wfProfileOut( $fname.'-includes' );
126 wfProfileIn( $fname.'-misc1' );
127
128
129 $wgIP = false; # Load on demand
130 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
131 $wgRequest = new WebRequest;
132 if ( function_exists( 'posix_uname' ) ) {
133 $wguname = posix_uname();
134 $wgNodeName = $wguname['nodename'];
135 } else {
136 $wgNodeName = '';
137 }
138
139 # Useful debug output
140 if ( $wgCommandLineMode ) {
141 wfDebug( "\n\nStart command line script $self\n" );
142 } elseif ( function_exists( 'getallheaders' ) ) {
143 wfDebug( "\n\nStart request\n" );
144 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
145 $headers = getallheaders();
146 foreach ($headers as $name => $value) {
147 wfDebug( "$name: $value\n" );
148 }
149 wfDebug( "\n" );
150 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
151 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
152 }
153
154 if ( $wgSkipSkin ) {
155 $wgSkipSkins[] = $wgSkipSkin;
156 }
157
158 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
159
160 if($wgMetaNamespace === FALSE) {
161 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
162 }
163
164 # These are now the same, always
165 # To determine the user language, use $wgLang->getCode()
166 $wgContLanguageCode = $wgLanguageCode;
167
168 wfProfileOut( $fname.'-misc1' );
169 wfProfileIn( $fname.'-memcached' );
170
171 $wgMemc =& wfGetMainCache();
172 $messageMemc =& wfGetMessageCacheStorage();
173 $parserMemc =& wfGetParserCacheStorage();
174
175 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
176 "\nMessage cache: " . get_class( $messageMemc ) .
177 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
178
179 wfProfileOut( $fname.'-memcached' );
180 wfProfileIn( $fname.'-SetupSession' );
181
182 if ( $wgDBprefix ) {
183 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
184 } elseif ( $wgSharedDB ) {
185 $wgCookiePrefix = $wgSharedDB;
186 } else {
187 $wgCookiePrefix = $wgDBname;
188 }
189 $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
190
191 # If session.auto_start is there, we can't touch session name
192 #
193 if( !ini_get( 'session.auto_start' ) )
194 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
195
196 if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
197 wfIncrStats( 'request_with_session' );
198 wfSetupSession();
199 $wgSessionStarted = true;
200 } else {
201 wfIncrStats( 'request_without_session' );
202 $wgSessionStarted = false;
203 }
204
205 wfProfileOut( $fname.'-SetupSession' );
206 wfProfileIn( $fname.'-globals' );
207
208 if ( !$wgDBservers ) {
209 $wgDBservers = array(array(
210 'host' => $wgDBserver,
211 'user' => $wgDBuser,
212 'password' => $wgDBpassword,
213 'dbname' => $wgDBname,
214 'type' => $wgDBtype,
215 'load' => 1,
216 'flags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT
217 ));
218 }
219
220 $wgLoadBalancer = new StubObject( 'wgLoadBalancer', 'LoadBalancer',
221 array( $wgDBservers, false, $wgMasterWaitTimeout, true ) );
222 $wgContLang = new StubContLang;
223
224 // Now that variant lists may be available...
225 $wgRequest->interpolateTitle();
226
227 $wgUser = new StubUser;
228 $wgLang = new StubUserLang;
229 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
230 $wgParser = new StubObject( 'wgParser', 'Parser' );
231 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
232 array( $parserMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
233
234 wfProfileOut( $fname.'-globals' );
235 wfProfileIn( $fname.'-User' );
236
237 # Skin setup functions
238 # Entries can be added to this variable during the inclusion
239 # of the extension file. Skins can then perform any necessary initialisation.
240 #
241 foreach ( $wgSkinExtensionFunctions as $func ) {
242 call_user_func( $func );
243 }
244
245 if( !is_object( $wgAuth ) ) {
246 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
247 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
248 }
249
250 wfProfileOut( $fname.'-User' );
251
252 wfProfileIn( $fname.'-misc2' );
253
254 $wgDeferredUpdateList = array();
255 $wgPostCommitUpdateList = array();
256
257 if ( $wgAjaxSearch ) $wgAjaxExportList[] = 'wfSajaxSearch';
258 if ( $wgAjaxWatch ) $wgAjaxExportList[] = 'wfAjaxWatch';
259
260 wfSeedRandom();
261
262 # Placeholders in case of DB error
263 $wgTitle = null;
264 $wgArticle = null;
265
266 wfProfileOut( $fname.'-misc2' );
267 wfProfileIn( $fname.'-extensions' );
268
269 # Extension setup functions for extensions other than skins
270 # Entries should be added to this variable during the inclusion
271 # of the extension file. This allows the extension to perform
272 # any necessary initialisation in the fully initialised environment
273 foreach ( $wgExtensionFunctions as $func ) {
274 $profName = $fname.'-extensions-'.strval( $func );
275 wfProfileIn( $profName );
276 call_user_func( $func );
277 wfProfileOut( $profName );
278 }
279
280 // For compatibility
281 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
282 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
283 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
284 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
285
286
287 wfDebug( "Fully initialised\n" );
288 $wgFullyInitialised = true;
289 wfProfileOut( $fname.'-extensions' );
290 wfProfileOut( $fname );
291
292 ?>