Fix for r58652: use tabs for indentation, not spaces :)
[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 exit( 1 );
12 }
13
14 # The main wiki script and things like database
15 # conversion and maintenance scripts all share a
16 # common setup of including lots of classes and
17 # setting up a few globals.
18 #
19
20 $fname = 'Setup.php';
21 wfProfileIn( $fname );
22
23 // Check to see if we are at the file scope
24 if ( !isset( $wgVersion ) ) {
25 echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
26 die( 1 );
27 }
28
29 // Set various default paths sensibly...
30 if( $wgScript === false ) $wgScript = "$wgScriptPath/index$wgScriptExtension";
31 if( $wgRedirectScript === false ) $wgRedirectScript = "$wgScriptPath/redirect$wgScriptExtension";
32
33 if( $wgArticlePath === false ) {
34 if( $wgUsePathInfo ) {
35 $wgArticlePath = "$wgScript/$1";
36 } else {
37 $wgArticlePath = "$wgScript?title=$1";
38 }
39 }
40
41 if( $wgStylePath === false ) $wgStylePath = "$wgScriptPath/skins";
42 if( $wgStyleDirectory === false) $wgStyleDirectory = "$IP/skins";
43
44 if( $wgLogo === false ) $wgLogo = "$wgStylePath/common/images/wiki.png";
45
46 if( $wgUploadPath === false ) $wgUploadPath = "$wgScriptPath/images";
47 if( $wgUploadDirectory === false ) $wgUploadDirectory = "$IP/images";
48
49 if( $wgMathPath === false ) $wgMathPath = "{$wgUploadPath}/math";
50 if( $wgMathDirectory === false ) $wgMathDirectory = "{$wgUploadDirectory}/math";
51 if( $wgTmpDirectory === false ) $wgTmpDirectory = "{$wgUploadDirectory}/tmp";
52
53 if( $wgReadOnlyFile === false ) $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
54 if( $wgFileCacheDirectory === false ) $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
55
56 if ( empty( $wgFileStore['deleted']['directory'] ) ) {
57 $wgFileStore['deleted']['directory'] = "{$wgUploadDirectory}/deleted";
58 }
59
60 /**
61 * Unconditional protection for NS_MEDIAWIKI since otherwise it's too easy for a
62 * sysadmin to set $wgNamespaceProtection incorrectly and leave the wiki insecure.
63 *
64 * Note that this is the definition of editinterface and it can be granted to
65 * all users if desired.
66 */
67 $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
68
69 /**
70 * The canonical names of namespaces 6 and 7 are, as of v1.14, "File"
71 * and "File_talk". The old names "Image" and "Image_talk" are
72 * retained as aliases for backwards compatibility.
73 */
74 $wgNamespaceAliases['Image'] = NS_FILE;
75 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
76
77 /**
78 * Initialise $wgLocalFileRepo from backwards-compatible settings
79 */
80 if ( !$wgLocalFileRepo ) {
81 $wgLocalFileRepo = array(
82 'class' => 'LocalRepo',
83 'name' => 'local',
84 'directory' => $wgUploadDirectory,
85 'url' => $wgUploadBaseUrl ? $wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
86 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
87 'thumbScriptUrl' => $wgThumbnailScriptPath,
88 'transformVia404' => !$wgGenerateThumbnailOnParse,
89 'deletedDir' => $wgFileStore['deleted']['directory'],
90 'deletedHashLevels' => $wgFileStore['deleted']['hash']
91 );
92 }
93 /**
94 * Initialise shared repo from backwards-compatible settings
95 */
96 if ( $wgUseSharedUploads ) {
97 if ( $wgSharedUploadDBname ) {
98 $wgForeignFileRepos[] = array(
99 'class' => 'ForeignDBRepo',
100 'name' => 'shared',
101 'directory' => $wgSharedUploadDirectory,
102 'url' => $wgSharedUploadPath,
103 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
104 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
105 'transformVia404' => !$wgGenerateThumbnailOnParse,
106 'dbType' => $wgDBtype,
107 'dbServer' => $wgDBserver,
108 'dbUser' => $wgDBuser,
109 'dbPassword' => $wgDBpassword,
110 'dbName' => $wgSharedUploadDBname,
111 'dbFlags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT,
112 'tablePrefix' => $wgSharedUploadDBprefix,
113 'hasSharedCache' => $wgCacheSharedUploads,
114 'descBaseUrl' => $wgRepositoryBaseUrl,
115 'fetchDescription' => $wgFetchCommonsDescriptions,
116 );
117 } else {
118 $wgForeignFileRepos[] = array(
119 'class' => 'FSRepo',
120 'name' => 'shared',
121 'directory' => $wgSharedUploadDirectory,
122 'url' => $wgSharedUploadPath,
123 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
124 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
125 'transformVia404' => !$wgGenerateThumbnailOnParse,
126 'descBaseUrl' => $wgRepositoryBaseUrl,
127 'fetchDescription' => $wgFetchCommonsDescriptions,
128 );
129 }
130 }
131 if( $wgUseInstantCommons ) {
132 $wgForeignFileRepos[] = array(
133 'class' => 'ForeignAPIRepo',
134 'name' => 'wikimediacommons',
135 'apibase' => 'http://commons.wikimedia.org/w/api.php',
136 'fetchDescription' => true,
137 'descriptionCacheExpiry' => 43200,
138 'apiThumbCacheExpiry' => 86400,
139 );
140 }
141
142
143 if ( !class_exists( 'AutoLoader' ) ) {
144 require_once( "$IP/includes/AutoLoader.php" );
145 }
146
147 wfProfileIn( $fname.'-exception' );
148 require_once( "$IP/includes/Exception.php" );
149 wfInstallExceptionHandler();
150 wfProfileOut( $fname.'-exception' );
151
152 wfProfileIn( $fname.'-includes' );
153 require_once( "$IP/includes/GlobalFunctions.php" );
154 require_once( "$IP/includes/Hooks.php" );
155 require_once( "$IP/includes/Namespace.php" );
156 require_once( "$IP/includes/ProxyTools.php" );
157 require_once( "$IP/includes/ObjectCache.php" );
158 require_once( "$IP/includes/ImageFunctions.php" );
159 require_once( "$IP/includes/StubObject.php" );
160 wfProfileOut( $fname.'-includes' );
161 wfProfileIn( $fname.'-misc1' );
162 # Raise the memory limit if it's too low
163 wfMemoryLimit();
164
165 $wgIP = false; # Load on demand
166 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
167 $wgRequest = new WebRequest;
168
169 # Useful debug output
170 if ( $wgCommandLineMode ) {
171 wfDebug( "\n\nStart command line script $self\n" );
172 } elseif ( function_exists( 'getallheaders' ) ) {
173 wfDebug( "\n\nStart request\n" );
174 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
175 $headers = getallheaders();
176 foreach ($headers as $name => $value) {
177 wfDebug( "$name: $value\n" );
178 }
179 wfDebug( "\n" );
180 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
181 wfDebug( "\n\nStart request\n" );
182 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
183 foreach ( $_SERVER as $name => $value ) {
184 if ( substr( $name, 0, 5 ) == 'HTTP_' ) {
185 $name = substr( $name, 5 );
186 wfDebug( "$name: $value\n" );
187 }
188 }
189 wfDebug( "\n" );
190 }
191
192 if( $wgRCFilterByAge ) {
193 ## Trim down $wgRCLinkDays so that it only lists links which are valid
194 ## as determined by $wgRCMaxAge.
195 ## Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
196 sort($wgRCLinkDays);
197 for( $i = 0; $i < count($wgRCLinkDays); $i++ ) {
198 if( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
199 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i+1, false );
200 break;
201 }
202 }
203 }
204
205 if ( $wgSkipSkin ) {
206 $wgSkipSkins[] = $wgSkipSkin;
207 }
208
209 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
210
211 if($wgMetaNamespace === FALSE) {
212 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
213 }
214
215 # These are now the same, always
216 # To determine the user language, use $wgLang->getCode()
217 $wgContLanguageCode = $wgLanguageCode;
218
219 # Easy to forget to falsify $wgShowIPinHeader for static caches.
220 # If file cache or squid cache is on, just disable this (DWIMD).
221 if( $wgUseFileCache || $wgUseSquid ) $wgShowIPinHeader = false;
222
223 # $wgAllowRealName and $wgAllowUserSkin were removed in 1.16
224 # in favor of $wgHiddenPrefs, handle b/c here
225 if( !$wgAllowRealName ) {
226 $wgHiddenPrefs[] = 'realname';
227 }
228
229 if( !$wgAllowUserSkin ) {
230 $wgHiddenPrefs[] = 'skin';
231 }
232
233 if ( !$wgHtml5Version && $wgHtml5 && $wgAllowRdfaAttributes ) {
234 # see http://www.w3.org/TR/rdfa-in-html/#document-conformance
235 if ( $wgMimeType == 'application/xhtml+xml' ) $wgHtml5Version = 'XHTML+RDFa 1.0';
236 else $wgHtml5Version = 'HTML+RDFa 1.0';
237 }
238
239
240 wfProfileOut( $fname.'-misc1' );
241 wfProfileIn( $fname.'-memcached' );
242
243 $wgMemc =& wfGetMainCache();
244 $messageMemc =& wfGetMessageCacheStorage();
245 $parserMemc =& wfGetParserCacheStorage();
246
247 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
248 "\nMessage cache: " . get_class( $messageMemc ) .
249 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
250
251 wfProfileOut( $fname.'-memcached' );
252
253 ## Most of the config is out, some might want to run hooks here.
254 wfRunHooks( 'SetupAfterCache' );
255
256 wfProfileIn( $fname.'-SetupSession' );
257
258 # Set default shared prefix
259 if( $wgSharedPrefix === false ) $wgSharedPrefix = $wgDBprefix;
260
261 if( !$wgCookiePrefix ) {
262 if ( $wgSharedDB && $wgSharedPrefix && in_array('user',$wgSharedTables) ) {
263 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
264 } elseif ( $wgSharedDB && in_array('user',$wgSharedTables) ) {
265 $wgCookiePrefix = $wgSharedDB;
266 } elseif ( $wgDBprefix ) {
267 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
268 } else {
269 $wgCookiePrefix = $wgDBname;
270 }
271 }
272 $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
273
274 # If session.auto_start is there, we can't touch session name
275 #
276 if( !wfIniGetBool( 'session.auto_start' ) )
277 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
278
279 if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
280 wfIncrStats( 'request_with_session' );
281 wfSetupSession();
282 $wgSessionStarted = true;
283 } else {
284 wfIncrStats( 'request_without_session' );
285 $wgSessionStarted = false;
286 }
287
288 wfProfileOut( $fname.'-SetupSession' );
289 wfProfileIn( $fname.'-globals' );
290
291 $wgContLang = new StubContLang;
292
293 // Now that variant lists may be available...
294 $wgRequest->interpolateTitle();
295
296 $wgUser = new StubUser;
297 $wgLang = new StubUserLang;
298 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
299 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
300
301 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
302 array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
303
304 wfProfileOut( $fname.'-globals' );
305 wfProfileIn( $fname.'-User' );
306
307 # Skin setup functions
308 # Entries can be added to this variable during the inclusion
309 # of the extension file. Skins can then perform any necessary initialisation.
310 #
311 foreach ( $wgSkinExtensionFunctions as $func ) {
312 call_user_func( $func );
313 }
314
315 if( !is_object( $wgAuth ) ) {
316 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
317 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
318 }
319
320 wfProfileOut( $fname.'-User' );
321
322 wfProfileIn( $fname.'-misc2' );
323
324 $wgDeferredUpdateList = array();
325 $wgPostCommitUpdateList = array();
326
327 if ( $wgAjaxWatch ) $wgAjaxExportList[] = 'wfAjaxWatch';
328 if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'SpecialUpload::ajaxGetExistsWarning';
329 if( $wgAjaxLicensePreview )
330 $wgAjaxExportList[] = 'SpecialUpload::ajaxGetLicensePreview';
331
332 # Placeholders in case of DB error
333 $wgTitle = null;
334 $wgArticle = null;
335
336 wfProfileOut( $fname.'-misc2' );
337 wfProfileIn( $fname.'-extensions' );
338
339 # load the $wgExtensionMessagesFiles for the script loader
340 # this can't be done in a normal extension type way
341 # since the script-loader is an entry point
342 #
343 $wgExtensionMessagesFiles['mwEmbed'] = "{$IP}/js2/mwEmbed/php/languages/mwEmbed.i18n.php";
344
345 # Include the js2/mwEmbed autoLoadClasses if js2 is enabled
346 if( $wgEnableJS2system ){
347 require_once("$IP/js2/mwEmbed/php/jsAutoloadLocalClasses.php");
348 }
349
350 # Extension setup functions for extensions other than skins
351 # Entries should be added to this variable during the inclusion
352 # of the extension file. This allows the extension to perform
353 # any necessary initialisation in the fully initialised environment
354 foreach ( $wgExtensionFunctions as $func ) {
355 # Allow closures in PHP 5.3+
356 if ( is_object( $func ) && $func instanceof Closure ) {
357 $profName = $fname.'-extensions-closure';
358 } elseif( is_array( $func ) ) {
359 if ( is_object( $func[0] ) )
360 $profName = $fname.'-extensions-'.get_class( $func[0] ).'::'.$func[1];
361 else
362 $profName = $fname.'-extensions-'.implode( '::', $func );
363 } else {
364 $profName = $fname.'-extensions-'.strval( $func );
365 }
366
367 wfProfileIn( $profName );
368 call_user_func( $func );
369 wfProfileOut( $profName );
370 }
371
372 // For compatibility
373 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
374 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
375 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
376 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
377
378 if( !empty($wgNewUserLog) ) {
379 # Add a new log type
380 $wgLogTypes[] = 'newusers';
381 $wgLogNames['newusers'] = 'newuserlogpage';
382 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
383 $wgLogActions['newusers/newusers'] = 'newuserlogentry'; // For compatibility with older log entries
384 $wgLogActions['newusers/create'] = 'newuserlog-create-entry';
385 $wgLogActions['newusers/create2'] = 'newuserlog-create2-entry';
386 $wgLogActions['newusers/autocreate'] = 'newuserlog-autocreate-entry';
387 }
388
389 wfDebug( "Fully initialised\n" );
390 $wgFullyInitialised = true;
391 wfProfileOut( $fname.'-extensions' );
392 wfProfileOut( $fname );