Merge "Implement routing for HTCP purges"
[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 ( !empty($wgActionPaths) && !isset($wgActionPaths['view']) ) {
45 # 'view' is assumed the default action path everywhere in the code
46 # but is rarely filled in $wgActionPaths
47 $wgActionPaths['view'] = $wgArticlePath;
48 }
49
50 if ( !empty($wgActionPaths) && !isset($wgActionPaths['view']) ) {
51 # 'view' is assumed the default action path everywhere in the code
52 # but is rarely filled in $wgActionPaths
53 $wgActionPaths['view'] = $wgArticlePath ;
54 }
55
56 if ( $wgStylePath === false ) $wgStylePath = "$wgScriptPath/skins";
57 if ( $wgLocalStylePath === false ) $wgLocalStylePath = "$wgScriptPath/skins";
58 if ( $wgStyleDirectory === false ) $wgStyleDirectory = "$IP/skins";
59 if ( $wgExtensionAssetsPath === false ) $wgExtensionAssetsPath = "$wgScriptPath/extensions";
60
61 if ( $wgLogo === false ) $wgLogo = "$wgStylePath/common/images/wiki.png";
62
63 if ( $wgUploadPath === false ) $wgUploadPath = "$wgScriptPath/images";
64 if ( $wgUploadDirectory === false ) $wgUploadDirectory = "$IP/images";
65
66 if ( $wgTmpDirectory === false ) $wgTmpDirectory = "{$wgUploadDirectory}/tmp";
67
68 if ( $wgReadOnlyFile === false ) $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
69 if ( $wgFileCacheDirectory === false ) $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
70 if ( $wgDeletedDirectory === false ) $wgDeletedDirectory = "{$wgUploadDirectory}/deleted";
71
72 if ( isset( $wgFileStore['deleted']['directory'] ) ) {
73 $wgDeletedDirectory = $wgFileStore['deleted']['directory'];
74 }
75
76 if ( isset( $wgFooterIcons['copyright'] ) &&
77 isset( $wgFooterIcons['copyright']['copyright'] ) &&
78 $wgFooterIcons['copyright']['copyright'] === array() )
79 {
80 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
81 $wgFooterIcons['copyright']['copyright'] = $wgCopyrightIcon;
82 } elseif ( $wgRightsIcon || $wgRightsText ) {
83 $wgFooterIcons['copyright']['copyright'] = array(
84 'url' => $wgRightsUrl,
85 'src' => $wgRightsIcon,
86 'alt' => $wgRightsText,
87 );
88 } else {
89 unset( $wgFooterIcons['copyright']['copyright'] );
90 }
91 }
92
93 if ( isset( $wgFooterIcons['poweredby'] ) &&
94 isset( $wgFooterIcons['poweredby']['mediawiki'] ) &&
95 $wgFooterIcons['poweredby']['mediawiki']['src'] === null )
96 {
97 $wgFooterIcons['poweredby']['mediawiki']['src'] = "$wgStylePath/common/images/poweredby_mediawiki_88x31.png";
98 }
99
100 /**
101 * Unconditional protection for NS_MEDIAWIKI since otherwise it's too easy for a
102 * sysadmin to set $wgNamespaceProtection incorrectly and leave the wiki insecure.
103 *
104 * Note that this is the definition of editinterface and it can be granted to
105 * all users if desired.
106 */
107 $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
108
109 /**
110 * The canonical names of namespaces 6 and 7 are, as of v1.14, "File"
111 * and "File_talk". The old names "Image" and "Image_talk" are
112 * retained as aliases for backwards compatibility.
113 */
114 $wgNamespaceAliases['Image'] = NS_FILE;
115 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
116
117 /**
118 * Initialise $wgLockManagers to include basic FS version
119 */
120 $wgLockManagers[] = array(
121 'name' => 'fsLockManager',
122 'class' => 'FSLockManager',
123 'lockDirectory' => "{$wgUploadDirectory}/lockdir",
124 );
125 $wgLockManagers[] = array(
126 'name' => 'nullLockManager',
127 'class' => 'NullLockManager',
128 );
129
130 /**
131 * Initialise $wgLocalFileRepo from backwards-compatible settings
132 */
133 if ( !$wgLocalFileRepo ) {
134 if ( isset( $wgFileStore['deleted']['hash'] ) ) {
135 $deletedHashLevel = $wgFileStore['deleted']['hash'];
136 } else {
137 $deletedHashLevel = $wgHashedUploadDirectory ? 3 : 0;
138 }
139 $wgLocalFileRepo = array(
140 'class' => 'LocalRepo',
141 'name' => 'local',
142 'directory' => $wgUploadDirectory,
143 'scriptDirUrl' => $wgScriptPath,
144 'scriptExtension' => $wgScriptExtension,
145 'url' => $wgUploadBaseUrl ? $wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
146 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
147 'thumbScriptUrl' => $wgThumbnailScriptPath,
148 'transformVia404' => !$wgGenerateThumbnailOnParse,
149 'deletedDir' => $wgDeletedDirectory,
150 'deletedHashLevels' => $deletedHashLevel
151 );
152 }
153 /**
154 * Initialise shared repo from backwards-compatible settings
155 */
156 if ( $wgUseSharedUploads ) {
157 if ( $wgSharedUploadDBname ) {
158 $wgForeignFileRepos[] = array(
159 'class' => 'ForeignDBRepo',
160 'name' => 'shared',
161 'directory' => $wgSharedUploadDirectory,
162 'url' => $wgSharedUploadPath,
163 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
164 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
165 'transformVia404' => !$wgGenerateThumbnailOnParse,
166 'dbType' => $wgDBtype,
167 'dbServer' => $wgDBserver,
168 'dbUser' => $wgDBuser,
169 'dbPassword' => $wgDBpassword,
170 'dbName' => $wgSharedUploadDBname,
171 'dbFlags' => ( $wgDebugDumpSql ? DBO_DEBUG : 0 ) | DBO_DEFAULT,
172 'tablePrefix' => $wgSharedUploadDBprefix,
173 'hasSharedCache' => $wgCacheSharedUploads,
174 'descBaseUrl' => $wgRepositoryBaseUrl,
175 'fetchDescription' => $wgFetchCommonsDescriptions,
176 );
177 } else {
178 $wgForeignFileRepos[] = array(
179 'class' => 'FileRepo',
180 'name' => 'shared',
181 'directory' => $wgSharedUploadDirectory,
182 'url' => $wgSharedUploadPath,
183 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
184 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
185 'transformVia404' => !$wgGenerateThumbnailOnParse,
186 'descBaseUrl' => $wgRepositoryBaseUrl,
187 'fetchDescription' => $wgFetchCommonsDescriptions,
188 );
189 }
190 }
191 if ( $wgUseInstantCommons ) {
192 $wgForeignFileRepos[] = array(
193 'class' => 'ForeignAPIRepo',
194 'name' => 'wikimediacommons',
195 'apibase' => WebRequest::detectProtocol() === 'https' ?
196 'https://commons.wikimedia.org/w/api.php' :
197 'http://commons.wikimedia.org/w/api.php',
198 'hashLevels' => 2,
199 'fetchDescription' => true,
200 'descriptionCacheExpiry' => 43200,
201 'apiThumbCacheExpiry' => 86400,
202 );
203 }
204 /*
205 * Add on default file backend config for file repos.
206 * FileBackendGroup will handle initializing the backends.
207 */
208 if ( !isset( $wgLocalFileRepo['backend'] ) ) {
209 $wgLocalFileRepo['backend'] = $wgLocalFileRepo['name'] . '-backend';
210 }
211 foreach ( $wgForeignFileRepos as &$repo ) {
212 if ( !isset( $repo['directory'] ) && $repo['class'] === 'ForeignAPIRepo' ) {
213 $repo['directory'] = $wgUploadDirectory; // b/c
214 }
215 if ( !isset( $repo['backend'] ) ) {
216 $repo['backend'] = $repo['name'] . '-backend';
217 }
218 }
219 unset( $repo ); // no global pollution; destroy reference
220
221 if ( is_null( $wgEnableAutoRotation ) ) {
222 // Only enable auto-rotation when the bitmap handler can rotate
223 $wgEnableAutoRotation = BitmapHandler::canRotate();
224 }
225
226 if ( $wgRCFilterByAge ) {
227 # # Trim down $wgRCLinkDays so that it only lists links which are valid
228 # # as determined by $wgRCMaxAge.
229 # # Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
230 sort( $wgRCLinkDays );
231 for ( $i = 0; $i < count( $wgRCLinkDays ); $i++ ) {
232 if ( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
233 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i + 1, false );
234 break;
235 }
236 }
237 }
238
239 if ( $wgSkipSkin ) {
240 $wgSkipSkins[] = $wgSkipSkin;
241 }
242
243 # Set default shared prefix
244 if ( $wgSharedPrefix === false ) {
245 $wgSharedPrefix = $wgDBprefix;
246 }
247
248 if ( !$wgCookiePrefix ) {
249 if ( $wgSharedDB && $wgSharedPrefix && in_array( 'user', $wgSharedTables ) ) {
250 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
251 } elseif ( $wgSharedDB && in_array( 'user', $wgSharedTables ) ) {
252 $wgCookiePrefix = $wgSharedDB;
253 } elseif ( $wgDBprefix ) {
254 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
255 } else {
256 $wgCookiePrefix = $wgDBname;
257 }
258 }
259 $wgCookiePrefix = strtr( $wgCookiePrefix, '=,; +."\'\\[', '__________' );
260
261 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
262
263 if ( $wgMetaNamespace === false ) {
264 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
265 }
266
267 /**
268 * Definitions of the NS_ constants are in Defines.php
269 * @private
270 */
271 $wgCanonicalNamespaceNames = array(
272 NS_MEDIA => 'Media',
273 NS_SPECIAL => 'Special',
274 NS_TALK => 'Talk',
275 NS_USER => 'User',
276 NS_USER_TALK => 'User_talk',
277 NS_PROJECT => 'Project',
278 NS_PROJECT_TALK => 'Project_talk',
279 NS_FILE => 'File',
280 NS_FILE_TALK => 'File_talk',
281 NS_MEDIAWIKI => 'MediaWiki',
282 NS_MEDIAWIKI_TALK => 'MediaWiki_talk',
283 NS_TEMPLATE => 'Template',
284 NS_TEMPLATE_TALK => 'Template_talk',
285 NS_HELP => 'Help',
286 NS_HELP_TALK => 'Help_talk',
287 NS_CATEGORY => 'Category',
288 NS_CATEGORY_TALK => 'Category_talk',
289 );
290
291 /// @todo UGLY UGLY
292 if( is_array( $wgExtraNamespaces ) ) {
293 $wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames + $wgExtraNamespaces;
294 }
295
296 # These are now the same, always
297 # To determine the user language, use $wgLang->getCode()
298 $wgContLanguageCode = $wgLanguageCode;
299
300 # Easy to forget to falsify $wgShowIPinHeader for static caches.
301 # If file cache or squid cache is on, just disable this (DWIMD).
302 # Do the same for $wgDebugToolbar.
303 if ( $wgUseFileCache || $wgUseSquid ) {
304 $wgShowIPinHeader = false;
305 $wgDebugToolbar = false;
306 }
307
308 # $wgAllowRealName and $wgAllowUserSkin were removed in 1.16
309 # in favor of $wgHiddenPrefs, handle b/c here
310 if ( !$wgAllowRealName ) {
311 $wgHiddenPrefs[] = 'realname';
312 }
313
314 # Doesn't make sense to have if disabled.
315 if ( !$wgEnotifMinorEdits ) {
316 $wgHiddenPrefs[] = 'enotifminoredits';
317 }
318
319 # $wgDisabledActions is deprecated as of 1.18
320 foreach( $wgDisabledActions as $action ){
321 $wgActions[$action] = false;
322 }
323 if( !$wgAllowPageInfo ){
324 $wgActions['info'] = false;
325 }
326
327 if ( !$wgHtml5Version && $wgHtml5 && $wgAllowRdfaAttributes ) {
328 # see http://www.w3.org/TR/rdfa-in-html/#document-conformance
329 if ( $wgMimeType == 'application/xhtml+xml' ) {
330 $wgHtml5Version = 'XHTML+RDFa 1.0';
331 } else {
332 $wgHtml5Version = 'HTML+RDFa 1.0';
333 }
334 }
335
336 # Blacklisted file extensions shouldn't appear on the "allowed" list
337 $wgFileExtensions = array_diff ( $wgFileExtensions, $wgFileBlacklist );
338
339 if ( $wgArticleCountMethod === null ) {
340 $wgArticleCountMethod = $wgUseCommaCount ? 'comma' : 'link';
341 }
342
343 if ( $wgInvalidateCacheOnLocalSettingsChange ) {
344 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( "$IP/LocalSettings.php" ) ) );
345 }
346
347 if ( $wgAjaxUploadDestCheck ) {
348 $wgAjaxExportList[] = 'SpecialUpload::ajaxGetExistsWarning';
349 }
350
351 if ( $wgNewUserLog ) {
352 # Add a new log type
353 $wgLogTypes[] = 'newusers';
354 $wgLogNames['newusers'] = 'newuserlogpage';
355 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
356 # newusers, create, create2, autocreate
357 $wgLogActionsHandlers['newusers/*'] = 'NewUsersLogFormatter';
358 }
359
360 if ( $wgCookieSecure === 'detect' ) {
361 $wgCookieSecure = ( substr( $wgServer, 0, 6 ) === 'https:' );
362 }
363
364 // Disable MWDebug for command line mode, this prevents MWDebug from eating up
365 // all the memory from logging SQL queries on maintenance scripts
366 global $wgCommandLineMode;
367 if ( $wgDebugToolbar && !$wgCommandLineMode ) {
368 MWDebug::init();
369 }
370
371 if ( !defined( 'MW_COMPILED' ) ) {
372 if ( !MWInit::classExists( 'AutoLoader' ) ) {
373 require_once( "$IP/includes/AutoLoader.php" );
374 }
375
376 wfProfileIn( $fname . '-exception' );
377 MWExceptionHandler::installHandler();
378 wfProfileOut( $fname . '-exception' );
379
380 wfProfileIn( $fname . '-includes' );
381 require_once( "$IP/includes/normal/UtfNormalUtil.php" );
382 require_once( "$IP/includes/GlobalFunctions.php" );
383 require_once( "$IP/includes/ProxyTools.php" );
384 require_once( "$IP/includes/ImageFunctions.php" );
385 require_once( "$IP/includes/normal/UtfNormalDefines.php" );
386 wfProfileOut( $fname . '-includes' );
387 }
388
389 # Now that GlobalFunctions is loaded, set the default for $wgCanonicalServer
390 if ( $wgCanonicalServer === false ) {
391 $wgCanonicalServer = wfExpandUrl( $wgServer, PROTO_HTTP );
392 }
393
394 // Initialize $wgHTCPMulticastRouting from backwards-compatible settings
395 if ( !$wgHTCPMulticastRouting && $wgHTCPMulticastAddress ) {
396 $wgHTCPMulticastRouting = array(
397 '' => array(
398 'host' => $wgHTCPMulticastAddress,
399 'port' => $wgHTCPPort,
400 )
401 );
402 }
403
404 wfProfileIn( $fname . '-misc1' );
405
406 # Raise the memory limit if it's too low
407 wfMemoryLimit();
408
409 /**
410 * Set up the timezone, suppressing the pseudo-security warning in PHP 5.1+
411 * that happens whenever you use a date function without the timezone being
412 * explicitly set. Inspired by phpMyAdmin's treatment of the problem.
413 */
414 if ( is_null( $wgLocaltimezone) ) {
415 wfSuppressWarnings();
416 $wgLocaltimezone = date_default_timezone_get();
417 wfRestoreWarnings();
418 }
419
420 date_default_timezone_set( $wgLocaltimezone );
421 if( is_null( $wgLocalTZoffset ) ) {
422 $wgLocalTZoffset = date( 'Z' ) / 60;
423 }
424
425 # Useful debug output
426 if ( $wgCommandLineMode ) {
427 $wgRequest = new FauxRequest( array() );
428
429 wfDebug( "\n\nStart command line script $self\n" );
430 } else {
431 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
432 $wgRequest = new WebRequest;
433
434 $debug = "\n\nStart request {$_SERVER['REQUEST_METHOD']} {$wgRequest->getRequestURL()}\n";
435
436 if ( $wgDebugPrintHttpHeaders ) {
437 $debug .= "HTTP HEADERS:\n";
438
439 foreach ( $wgRequest->getAllHeaders() as $name => $value ) {
440 $debug .= "$name: $value\n";
441 }
442 }
443 wfDebug( $debug );
444 }
445
446 wfProfileOut( $fname . '-misc1' );
447 wfProfileIn( $fname . '-memcached' );
448
449 $wgMemc = wfGetMainCache();
450 $messageMemc = wfGetMessageCacheStorage();
451 $parserMemc = wfGetParserCacheStorage();
452
453 wfDebug( 'CACHES: ' . get_class( $wgMemc ) . '[main] ' .
454 get_class( $messageMemc ) . '[message] ' .
455 get_class( $parserMemc ) . "[parser]\n" );
456
457 wfProfileOut( $fname . '-memcached' );
458
459 # # Most of the config is out, some might want to run hooks here.
460 wfRunHooks( 'SetupAfterCache' );
461
462 wfProfileIn( $fname . '-session' );
463
464 # If session.auto_start is there, we can't touch session name
465 if ( !wfIniGetBool( 'session.auto_start' ) ) {
466 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
467 }
468
469 if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
470 if ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix . 'Token'] ) ) {
471 wfIncrStats( 'request_with_session' );
472 wfSetupSession();
473 $wgSessionStarted = true;
474 } else {
475 wfIncrStats( 'request_without_session' );
476 $wgSessionStarted = false;
477 }
478 }
479
480 wfProfileOut( $fname . '-session' );
481 wfProfileIn( $fname . '-globals' );
482
483 $wgContLang = Language::factory( $wgLanguageCode );
484 $wgContLang->initEncoding();
485 $wgContLang->initContLang();
486
487 // Now that variant lists may be available...
488 $wgRequest->interpolateTitle();
489 $wgUser = RequestContext::getMain()->getUser(); # BackCompat
490
491 /**
492 * @var $wgLang Language
493 */
494 $wgLang = new StubUserLang;
495
496 /**
497 * @var OutputPage
498 */
499 $wgOut = RequestContext::getMain()->getOutput(); # BackCompat
500
501 /**
502 * @var $wgParser Parser
503 */
504 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
505
506 if ( !is_object( $wgAuth ) ) {
507 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
508 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
509 }
510
511 # Placeholders in case of DB error
512 $wgTitle = null;
513
514 $wgDeferredUpdateList = array();
515
516 wfProfileOut( $fname . '-globals' );
517 wfProfileIn( $fname . '-extensions' );
518
519 # Extension setup functions for extensions other than skins
520 # Entries should be added to this variable during the inclusion
521 # of the extension file. This allows the extension to perform
522 # any necessary initialisation in the fully initialised environment
523 foreach ( $wgExtensionFunctions as $func ) {
524 # Allow closures in PHP 5.3+
525 if ( is_object( $func ) && $func instanceof Closure ) {
526 $profName = $fname . '-extensions-closure';
527 } elseif ( is_array( $func ) ) {
528 if ( is_object( $func[0] ) )
529 $profName = $fname . '-extensions-' . get_class( $func[0] ) . '::' . $func[1];
530 else
531 $profName = $fname . '-extensions-' . implode( '::', $func );
532 } else {
533 $profName = $fname . '-extensions-' . strval( $func );
534 }
535
536 wfProfileIn( $profName );
537 call_user_func( $func );
538 wfProfileOut( $profName );
539 }
540
541 wfDebug( "Fully initialised\n" );
542 $wgFullyInitialised = true;
543
544 wfProfileOut( $fname . '-extensions' );
545 wfProfileOut( $fname );