c62f61045a120055ccca576557bbb09fd3191f96
[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 if ( empty( $wgFileStore['hidden']['directory'] ) ) {
61 $wgFileStore['hidden']['directory'] = "{$wgUploadDirectory}/hidden";
62 }
63
64 /**
65 * Initialise $wgLocalFileRepo from backwards-compatible settings
66 */
67 if ( !$wgLocalFileRepo ) {
68 $wgLocalFileRepo = array(
69 'class' => 'LocalRepo',
70 'name' => 'local',
71 'directory' => $wgUploadDirectory,
72 'url' => $wgUploadBaseUrl ? $wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
73 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
74 'thumbScriptUrl' => $wgThumbnailScriptPath,
75 'transformVia404' => !$wgGenerateThumbnailOnParse,
76 'initialCapital' => $wgCapitalLinks,
77 'deletedDir' => $wgFileStore['deleted']['directory'],
78 'deletedHashLevels' => $wgFileStore['deleted']['hash'],
79 'hiddenDir' => $wgFileStore['hidden']['directory'],
80 'hiddenHashLevels' => $wgFileStore['hidden']['hash']
81 );
82 }
83 /**
84 * Initialise shared repo from backwards-compatible settings
85 */
86 if ( $wgUseSharedUploads ) {
87 if ( $wgSharedUploadDBname ) {
88 $wgForeignFileRepos[] = array(
89 'class' => 'ForeignDBRepo',
90 'name' => 'shared',
91 'directory' => $wgSharedUploadDirectory,
92 'url' => $wgSharedUploadPath,
93 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
94 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
95 'transformVia404' => !$wgGenerateThumbnailOnParse,
96 'dbType' => $wgDBtype,
97 'dbServer' => $wgDBserver,
98 'dbUser' => $wgDBuser,
99 'dbPassword' => $wgDBpassword,
100 'dbName' => $wgSharedUploadDBname,
101 'dbFlags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT,
102 'tablePrefix' => $wgSharedUploadDBprefix,
103 'hasSharedCache' => $wgCacheSharedUploads,
104 'descBaseUrl' => $wgRepositoryBaseUrl,
105 'fetchDescription' => $wgFetchCommonsDescriptions,
106 );
107 } else {
108 $wgForeignFileRepos[] = array(
109 'class' => 'FSRepo',
110 'name' => 'shared',
111 'directory' => $wgSharedUploadDirectory,
112 'url' => $wgSharedUploadPath,
113 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
114 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
115 'transformVia404' => !$wgGenerateThumbnailOnParse,
116 'descBaseUrl' => $wgRepositoryBaseUrl,
117 'fetchDescription' => $wgFetchCommonsDescriptions,
118 );
119 }
120 }
121
122 require_once( "$IP/includes/AutoLoader.php" );
123
124 wfProfileIn( $fname.'-exception' );
125 require_once( "$IP/includes/Exception.php" );
126 wfInstallExceptionHandler();
127 wfProfileOut( $fname.'-exception' );
128
129 wfProfileIn( $fname.'-includes' );
130 require_once( "$IP/includes/GlobalFunctions.php" );
131 require_once( "$IP/includes/Hooks.php" );
132 require_once( "$IP/includes/Namespace.php" );
133 require_once( "$IP/includes/ProxyTools.php" );
134 require_once( "$IP/includes/ObjectCache.php" );
135 require_once( "$IP/includes/ImageFunctions.php" );
136 require_once( "$IP/includes/StubObject.php" );
137 wfProfileOut( $fname.'-includes' );
138 wfProfileIn( $fname.'-misc1' );
139
140
141 $wgIP = false; # Load on demand
142 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
143 $wgRequest = new WebRequest;
144 if ( function_exists( 'posix_uname' ) ) {
145 $wguname = posix_uname();
146 $wgNodeName = $wguname['nodename'];
147 } else {
148 $wgNodeName = '';
149 }
150
151 # Useful debug output
152 if ( $wgCommandLineMode ) {
153 wfDebug( "\n\nStart command line script $self\n" );
154 } elseif ( function_exists( 'getallheaders' ) ) {
155 wfDebug( "\n\nStart request\n" );
156 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
157 $headers = getallheaders();
158 foreach ($headers as $name => $value) {
159 wfDebug( "$name: $value\n" );
160 }
161 wfDebug( "\n" );
162 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
163 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
164 }
165
166 if ( $wgSkipSkin ) {
167 $wgSkipSkins[] = $wgSkipSkin;
168 }
169
170 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
171
172 if($wgMetaNamespace === FALSE) {
173 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
174 }
175
176 # These are now the same, always
177 # To determine the user language, use $wgLang->getCode()
178 $wgContLanguageCode = $wgLanguageCode;
179
180 wfProfileOut( $fname.'-misc1' );
181 wfProfileIn( $fname.'-memcached' );
182
183 $wgMemc =& wfGetMainCache();
184 $messageMemc =& wfGetMessageCacheStorage();
185 $parserMemc =& wfGetParserCacheStorage();
186
187 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
188 "\nMessage cache: " . get_class( $messageMemc ) .
189 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
190
191 wfProfileOut( $fname.'-memcached' );
192 wfProfileIn( $fname.'-SetupSession' );
193
194 if ( $wgDBprefix ) {
195 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
196 } elseif ( $wgSharedDB ) {
197 $wgCookiePrefix = $wgSharedDB;
198 } else {
199 $wgCookiePrefix = $wgDBname;
200 }
201 $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
202
203 # If session.auto_start is there, we can't touch session name
204 #
205 if( !wfIniGetBool( 'session.auto_start' ) )
206 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
207
208 if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
209 wfIncrStats( 'request_with_session' );
210 wfSetupSession();
211 $wgSessionStarted = true;
212 } else {
213 wfIncrStats( 'request_without_session' );
214 $wgSessionStarted = false;
215 }
216
217 wfProfileOut( $fname.'-SetupSession' );
218 wfProfileIn( $fname.'-globals' );
219
220 if ( !$wgDBservers ) {
221 $wgDBservers = array(array(
222 'host' => $wgDBserver,
223 'user' => $wgDBuser,
224 'password' => $wgDBpassword,
225 'dbname' => $wgDBname,
226 'type' => $wgDBtype,
227 'load' => 1,
228 'flags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT
229 ));
230 }
231
232 $wgLoadBalancer = new StubObject( 'wgLoadBalancer', 'LoadBalancer',
233 array( $wgDBservers, false, $wgMasterWaitTimeout, true ) );
234 $wgContLang = new StubContLang;
235
236 // Now that variant lists may be available...
237 $wgRequest->interpolateTitle();
238
239 $wgUser = new StubUser;
240 $wgLang = new StubUserLang;
241 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
242 $wgParser = new StubObject( 'wgParser', 'Parser' );
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 );
306
307