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