* Reorganised the includes directory, creating subdirectories db, parser and specials
[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$wgScriptExtension";
32 if( $wgRedirectScript === false ) $wgRedirectScript = "$wgScriptPath/redirect$wgScriptExtension";
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 if ( empty( $wgFileStore['deleted']['directory'] ) ) {
58 $wgFileStore['deleted']['directory'] = "{$wgUploadDirectory}/deleted";
59 }
60
61 /**
62 * Initialise $wgLocalFileRepo from backwards-compatible settings
63 */
64 if ( !$wgLocalFileRepo ) {
65 $wgLocalFileRepo = array(
66 'class' => 'LocalRepo',
67 'name' => 'local',
68 'directory' => $wgUploadDirectory,
69 'url' => $wgUploadBaseUrl ? $wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
70 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
71 'thumbScriptUrl' => $wgThumbnailScriptPath,
72 'transformVia404' => !$wgGenerateThumbnailOnParse,
73 'initialCapital' => $wgCapitalLinks,
74 'deletedDir' => $wgFileStore['deleted']['directory'],
75 'deletedHashLevels' => $wgFileStore['deleted']['hash']
76 );
77 }
78 /**
79 * Initialise shared repo from backwards-compatible settings
80 */
81 if ( $wgUseSharedUploads ) {
82 if ( $wgSharedUploadDBname ) {
83 $wgForeignFileRepos[] = array(
84 'class' => 'ForeignDBRepo',
85 'name' => 'shared',
86 'directory' => $wgSharedUploadDirectory,
87 'url' => $wgSharedUploadPath,
88 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
89 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
90 'transformVia404' => !$wgGenerateThumbnailOnParse,
91 'dbType' => $wgDBtype,
92 'dbServer' => $wgDBserver,
93 'dbUser' => $wgDBuser,
94 'dbPassword' => $wgDBpassword,
95 'dbName' => $wgSharedUploadDBname,
96 'dbFlags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT,
97 'tablePrefix' => $wgSharedUploadDBprefix,
98 'hasSharedCache' => $wgCacheSharedUploads,
99 'descBaseUrl' => $wgRepositoryBaseUrl,
100 'fetchDescription' => $wgFetchCommonsDescriptions,
101 );
102 } else {
103 $wgForeignFileRepos[] = array(
104 'class' => 'FSRepo',
105 'name' => 'shared',
106 'directory' => $wgSharedUploadDirectory,
107 'url' => $wgSharedUploadPath,
108 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
109 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
110 'transformVia404' => !$wgGenerateThumbnailOnParse,
111 'descBaseUrl' => $wgRepositoryBaseUrl,
112 'fetchDescription' => $wgFetchCommonsDescriptions,
113 );
114 }
115 }
116
117 if ( !class_exists( 'AutoLoader' ) ) {
118 require_once( "$IP/includes/AutoLoader.php" );
119 }
120
121 wfProfileIn( $fname.'-exception' );
122 require_once( "$IP/includes/Exception.php" );
123 wfInstallExceptionHandler();
124 wfProfileOut( $fname.'-exception' );
125
126 wfProfileIn( $fname.'-includes' );
127 require_once( "$IP/includes/GlobalFunctions.php" );
128 require_once( "$IP/includes/Hooks.php" );
129 require_once( "$IP/includes/Namespace.php" );
130 require_once( "$IP/includes/ProxyTools.php" );
131 require_once( "$IP/includes/ObjectCache.php" );
132 require_once( "$IP/includes/ImageFunctions.php" );
133 require_once( "$IP/includes/StubObject.php" );
134 wfProfileOut( $fname.'-includes' );
135 wfProfileIn( $fname.'-misc1' );
136
137
138 $wgIP = false; # Load on demand
139 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
140 $wgRequest = new WebRequest;
141 if ( function_exists( 'posix_uname' ) ) {
142 $wguname = posix_uname();
143 $wgNodeName = $wguname['nodename'];
144 } else {
145 $wgNodeName = '';
146 }
147
148 # Useful debug output
149 if ( $wgCommandLineMode ) {
150 wfDebug( "\n\nStart command line script $self\n" );
151 } elseif ( function_exists( 'getallheaders' ) ) {
152 wfDebug( "\n\nStart request\n" );
153 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
154 $headers = getallheaders();
155 foreach ($headers as $name => $value) {
156 wfDebug( "$name: $value\n" );
157 }
158 wfDebug( "\n" );
159 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
160 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
161 }
162
163 if( $wgRCFilterByAge ) {
164 ## Trim down $wgRCLinkDays so that it only lists links which are valid
165 ## as determined by $wgRCMaxAge.
166 ## Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
167 sort($wgRCLinkDays);
168 for( $i = 0; $i < count($wgRCLinkDays); $i++ ) {
169 if( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
170 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i+1, false );
171 break;
172 }
173 }
174 }
175
176 if ( $wgSkipSkin ) {
177 $wgSkipSkins[] = $wgSkipSkin;
178 }
179
180 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
181
182 if($wgMetaNamespace === FALSE) {
183 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
184 }
185
186 # These are now the same, always
187 # To determine the user language, use $wgLang->getCode()
188 $wgContLanguageCode = $wgLanguageCode;
189
190 wfProfileOut( $fname.'-misc1' );
191 wfProfileIn( $fname.'-memcached' );
192
193 $wgMemc =& wfGetMainCache();
194 $messageMemc =& wfGetMessageCacheStorage();
195 $parserMemc =& wfGetParserCacheStorage();
196
197 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
198 "\nMessage cache: " . get_class( $messageMemc ) .
199 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
200
201 wfProfileOut( $fname.'-memcached' );
202 wfProfileIn( $fname.'-SetupSession' );
203
204 # Set default shared prefix
205 if( $wgSharedPrefix === false ) $wgSharedPrefix = $wgDBprefix;
206
207 if ( $wgDBprefix ) {
208 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
209 } elseif ( $wgSharedDB ) {
210 $wgCookiePrefix = $wgSharedDB;
211 } else {
212 $wgCookiePrefix = $wgDBname;
213 }
214 $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
215
216 # If session.auto_start is there, we can't touch session name
217 #
218 if( !wfIniGetBool( 'session.auto_start' ) )
219 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
220
221 if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
222 wfIncrStats( 'request_with_session' );
223 wfSetupSession();
224 $wgSessionStarted = true;
225 } else {
226 wfIncrStats( 'request_without_session' );
227 $wgSessionStarted = false;
228 }
229
230 wfProfileOut( $fname.'-SetupSession' );
231 wfProfileIn( $fname.'-globals' );
232
233 $wgContLang = new StubContLang;
234
235 // Now that variant lists may be available...
236 $wgRequest->interpolateTitle();
237
238 $wgUser = new StubUser;
239 $wgLang = new StubUserLang;
240 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
241 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
242
243 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
244 array( $parserMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
245
246 wfProfileOut( $fname.'-globals' );
247 wfProfileIn( $fname.'-User' );
248
249 # Skin setup functions
250 # Entries can be added to this variable during the inclusion
251 # of the extension file. Skins can then perform any necessary initialisation.
252 #
253 foreach ( $wgSkinExtensionFunctions as $func ) {
254 call_user_func( $func );
255 }
256
257 if( !is_object( $wgAuth ) ) {
258 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
259 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
260 }
261
262 wfProfileOut( $fname.'-User' );
263
264 wfProfileIn( $fname.'-misc2' );
265
266 $wgDeferredUpdateList = array();
267 $wgPostCommitUpdateList = array();
268
269 if ( $wgAjaxSearch ) $wgAjaxExportList[] = 'wfSajaxSearch';
270 if ( $wgAjaxWatch ) $wgAjaxExportList[] = 'wfAjaxWatch';
271 if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'UploadForm::ajaxGetExistsWarning';
272 if( $wgAjaxLicensePreview )
273 $wgAjaxExportList[] = 'UploadForm::ajaxGetLicensePreview';
274
275 wfSeedRandom();
276
277 # Placeholders in case of DB error
278 $wgTitle = null;
279 $wgArticle = null;
280
281 wfProfileOut( $fname.'-misc2' );
282 wfProfileIn( $fname.'-extensions' );
283
284 # Extension setup functions for extensions other than skins
285 # Entries should be added to this variable during the inclusion
286 # of the extension file. This allows the extension to perform
287 # any necessary initialisation in the fully initialised environment
288 foreach ( $wgExtensionFunctions as $func ) {
289 $profName = $fname.'-extensions-'.strval( $func );
290 wfProfileIn( $profName );
291 call_user_func( $func );
292 wfProfileOut( $profName );
293 }
294
295 // For compatibility
296 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
297 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
298 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
299 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
300
301
302 wfDebug( "Fully initialised\n" );
303 $wgFullyInitialised = true;
304 wfProfileOut( $fname.'-extensions' );
305 wfProfileOut( $fname );