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