Merged FileBackend branch. Manually avoiding merging the many prop-only changes SVN...
[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' => 'FSRepo',
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 'directory' => $wgUploadDirectory,
196 'apibase' => 'http://commons.wikimedia.org/w/api.php',
197 'hashLevels' => 2,
198 'fetchDescription' => true,
199 'descriptionCacheExpiry' => 43200,
200 'apiThumbCacheExpiry' => 86400,
201 );
202 }
203 /*
204 * Add on default file backend config for repos to $wgFileBackends
205 */
206 if ( !isset( $wgLocalFileRepo['backend'] ) ) {
207 $wgFileBackends[] = wfBackendForLegacyRepoConf( $wgLocalFileRepo );
208 }
209 foreach ( $wgForeignFileRepos as &$repo ) {
210 if ( !isset( $repo['backend'] ) ) {
211 $wgFileBackends[] = wfBackendForLegacyRepoConf( $repo );
212 }
213 }
214 unset( $repo ); // no global pollution; destroy reference
215 /*
216 * Get file backend configuration for a given repo
217 * configuration that lacks a backend parameter.
218 * Also updates the repo config to use the backend.
219 */
220 function wfBackendForLegacyRepoConf( &$info ) {
221 // Local vars that used to be FSRepo members...
222 $directory = $info['directory'];
223 $deletedDir = isset( $info['deletedDir'] )
224 ? $info['deletedDir']
225 : false;
226 $thumbDir = isset( $info['thumbDir'] )
227 ? $info['thumbDir']
228 : "{$directory}/thumb";
229 $fileMode = isset( $info['fileMode'] )
230 ? $info['fileMode']
231 : 0644;
232
233 // Make a backend name (based on repo name)
234 $backendName = $info['name'] . '-backend';
235 // Update repo config to use this backend
236 $info['backend'] = $backendName;
237 // Disable "deleted" zone in repo config if deleted dir not set
238 if ( $deletedDir !== false ) {
239 $info['zones']['deleted'] = array(
240 'container' => 'images-deleted', 'directory' => '' );
241 }
242 // Get the FS backend configuration
243 return array(
244 'name' => $backendName,
245 'class' => 'FSFileBackend',
246 'lockManager' => 'fsLockManager',
247 'containerPaths' => array(
248 "images-public" => "{$directory}",
249 "images-temp" => "{$directory}/temp",
250 "images-thumb" => $thumbDir,
251 "images-deleted" => $deletedDir
252 ),
253 'fileMode' => $fileMode,
254 );
255 }
256
257 if ( is_null( $wgEnableAutoRotation ) ) {
258 // Only enable auto-rotation when the bitmap handler can rotate
259 $wgEnableAutoRotation = BitmapHandler::canRotate();
260 }
261
262 if ( $wgRCFilterByAge ) {
263 # # Trim down $wgRCLinkDays so that it only lists links which are valid
264 # # as determined by $wgRCMaxAge.
265 # # Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
266 sort( $wgRCLinkDays );
267 for ( $i = 0; $i < count( $wgRCLinkDays ); $i++ ) {
268 if ( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
269 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i + 1, false );
270 break;
271 }
272 }
273 }
274
275 if ( $wgSkipSkin ) {
276 $wgSkipSkins[] = $wgSkipSkin;
277 }
278
279 # Set default shared prefix
280 if ( $wgSharedPrefix === false ) {
281 $wgSharedPrefix = $wgDBprefix;
282 }
283
284 if ( !$wgCookiePrefix ) {
285 if ( $wgSharedDB && $wgSharedPrefix && in_array( 'user', $wgSharedTables ) ) {
286 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
287 } elseif ( $wgSharedDB && in_array( 'user', $wgSharedTables ) ) {
288 $wgCookiePrefix = $wgSharedDB;
289 } elseif ( $wgDBprefix ) {
290 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
291 } else {
292 $wgCookiePrefix = $wgDBname;
293 }
294 }
295 $wgCookiePrefix = strtr( $wgCookiePrefix, '=,; +."\'\\[', '__________' );
296
297 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
298
299 if ( $wgMetaNamespace === false ) {
300 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
301 }
302
303 /**
304 * Definitions of the NS_ constants are in Defines.php
305 * @private
306 */
307 $wgCanonicalNamespaceNames = array(
308 NS_MEDIA => 'Media',
309 NS_SPECIAL => 'Special',
310 NS_TALK => 'Talk',
311 NS_USER => 'User',
312 NS_USER_TALK => 'User_talk',
313 NS_PROJECT => 'Project',
314 NS_PROJECT_TALK => 'Project_talk',
315 NS_FILE => 'File',
316 NS_FILE_TALK => 'File_talk',
317 NS_MEDIAWIKI => 'MediaWiki',
318 NS_MEDIAWIKI_TALK => 'MediaWiki_talk',
319 NS_TEMPLATE => 'Template',
320 NS_TEMPLATE_TALK => 'Template_talk',
321 NS_HELP => 'Help',
322 NS_HELP_TALK => 'Help_talk',
323 NS_CATEGORY => 'Category',
324 NS_CATEGORY_TALK => 'Category_talk',
325 );
326
327 /// @todo UGLY UGLY
328 if( is_array( $wgExtraNamespaces ) ) {
329 $wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames + $wgExtraNamespaces;
330 }
331
332 # These are now the same, always
333 # To determine the user language, use $wgLang->getCode()
334 $wgContLanguageCode = $wgLanguageCode;
335
336 # Easy to forget to falsify $wgShowIPinHeader for static caches.
337 # If file cache or squid cache is on, just disable this (DWIMD).
338 if ( $wgUseFileCache || $wgUseSquid ) {
339 $wgShowIPinHeader = false;
340 }
341
342 # $wgAllowRealName and $wgAllowUserSkin were removed in 1.16
343 # in favor of $wgHiddenPrefs, handle b/c here
344 if ( !$wgAllowRealName ) {
345 $wgHiddenPrefs[] = 'realname';
346 }
347
348 # Doesn't make sense to have if disabled.
349 if ( !$wgEnotifMinorEdits ) {
350 $wgHiddenPrefs[] = 'enotifminoredits';
351 }
352
353 # $wgDisabledActions is deprecated as of 1.18
354 foreach( $wgDisabledActions as $action ){
355 $wgActions[$action] = false;
356 }
357 if( !$wgAllowPageInfo ){
358 $wgActions['info'] = false;
359 }
360
361 if ( !$wgHtml5Version && $wgHtml5 && $wgAllowRdfaAttributes ) {
362 # see http://www.w3.org/TR/rdfa-in-html/#document-conformance
363 if ( $wgMimeType == 'application/xhtml+xml' ) {
364 $wgHtml5Version = 'XHTML+RDFa 1.0';
365 } else {
366 $wgHtml5Version = 'HTML+RDFa 1.0';
367 }
368 }
369
370 # Blacklisted file extensions shouldn't appear on the "allowed" list
371 $wgFileExtensions = array_diff ( $wgFileExtensions, $wgFileBlacklist );
372
373 if ( $wgArticleCountMethod === null ) {
374 $wgArticleCountMethod = $wgUseCommaCount ? 'comma' : 'link';
375 }
376
377 if ( $wgInvalidateCacheOnLocalSettingsChange ) {
378 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( "$IP/LocalSettings.php" ) ) );
379 }
380
381 if ( $wgAjaxUploadDestCheck ) {
382 $wgAjaxExportList[] = 'SpecialUpload::ajaxGetExistsWarning';
383 }
384
385 if ( $wgNewUserLog ) {
386 # Add a new log type
387 $wgLogTypes[] = 'newusers';
388 $wgLogNames['newusers'] = 'newuserlogpage';
389 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
390 # newusers, create, create2, autocreate
391 $wgLogActionsHandlers['newusers/*'] = 'NewUsersLogFormatter';
392 }
393
394 if ( $wgCookieSecure === 'detect' ) {
395 $wgCookieSecure = ( substr( $wgServer, 0, 6 ) === 'https:' );
396 }
397
398 MWDebug::init();
399
400 if ( !defined( 'MW_COMPILED' ) ) {
401 if ( !MWInit::classExists( 'AutoLoader' ) ) {
402 require_once( "$IP/includes/AutoLoader.php" );
403 }
404
405 wfProfileIn( $fname . '-exception' );
406 MWExceptionHandler::installHandler();
407 wfProfileOut( $fname . '-exception' );
408
409 wfProfileIn( $fname . '-includes' );
410 require_once( "$IP/includes/normal/UtfNormalUtil.php" );
411 require_once( "$IP/includes/GlobalFunctions.php" );
412 require_once( "$IP/includes/ProxyTools.php" );
413 require_once( "$IP/includes/ImageFunctions.php" );
414 require_once( "$IP/includes/normal/UtfNormalDefines.php" );
415 wfProfileOut( $fname . '-includes' );
416 }
417
418 # Now that GlobalFunctions is loaded, set the default for $wgCanonicalServer
419 if ( $wgCanonicalServer === false ) {
420 $wgCanonicalServer = wfExpandUrl( $wgServer, PROTO_HTTP );
421 }
422
423 wfProfileIn( $fname . '-misc1' );
424
425 # Raise the memory limit if it's too low
426 wfMemoryLimit();
427
428 /**
429 * Set up the timezone, suppressing the pseudo-security warning in PHP 5.1+
430 * that happens whenever you use a date function without the timezone being
431 * explicitly set. Inspired by phpMyAdmin's treatment of the problem.
432 */
433 if ( is_null( $wgLocaltimezone) ) {
434 wfSuppressWarnings();
435 $wgLocaltimezone = date_default_timezone_get();
436 wfRestoreWarnings();
437 }
438
439 date_default_timezone_set( $wgLocaltimezone );
440 if( is_null( $wgLocalTZoffset ) ) {
441 $wgLocalTZoffset = date( 'Z' ) / 60;
442 }
443
444 # Useful debug output
445 global $wgCommandLineMode;
446 if ( $wgCommandLineMode ) {
447 $wgRequest = new FauxRequest( array() );
448
449 wfDebug( "\n\nStart command line script $self\n" );
450 } else {
451 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
452 $wgRequest = new WebRequest;
453
454 $debug = "Start request\n\n{$_SERVER['REQUEST_METHOD']} {$wgRequest->getRequestURL()}";
455
456 if ( $wgDebugPrintHttpHeaders ) {
457 $debug .= "\nHTTP HEADERS:\n";
458
459 foreach ( $wgRequest->getAllHeaders() as $name => $value ) {
460 $debug .= "$name: $value\n";
461 }
462 }
463 wfDebug( "$debug\n" );
464 MWDebug::processRequest( $wgRequest );
465 }
466
467 wfProfileOut( $fname . '-misc1' );
468 wfProfileIn( $fname . '-memcached' );
469
470 $wgMemc = wfGetMainCache();
471 $messageMemc = wfGetMessageCacheStorage();
472 $parserMemc = wfGetParserCacheStorage();
473
474 wfDebug( 'CACHES: ' . get_class( $wgMemc ) . '[main] ' .
475 get_class( $messageMemc ) . '[message] ' .
476 get_class( $parserMemc ) . "[parser]\n" );
477
478 wfProfileOut( $fname . '-memcached' );
479
480 # # Most of the config is out, some might want to run hooks here.
481 wfRunHooks( 'SetupAfterCache' );
482
483 wfProfileIn( $fname . '-session' );
484
485 # If session.auto_start is there, we can't touch session name
486 if ( !wfIniGetBool( 'session.auto_start' ) ) {
487 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
488 }
489
490 if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
491 if ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix . 'Token'] ) ) {
492 wfIncrStats( 'request_with_session' );
493 wfSetupSession();
494 $wgSessionStarted = true;
495 } else {
496 wfIncrStats( 'request_without_session' );
497 $wgSessionStarted = false;
498 }
499 }
500
501 wfProfileOut( $fname . '-session' );
502 wfProfileIn( $fname . '-globals' );
503
504 $wgContLang = Language::factory( $wgLanguageCode );
505 $wgContLang->initEncoding();
506 $wgContLang->initContLang();
507
508 // Now that variant lists may be available...
509 $wgRequest->interpolateTitle();
510 $wgUser = RequestContext::getMain()->getUser(); # BackCompat
511
512 /**
513 * @var Language
514 */
515 $wgLang = new StubUserLang;
516
517 /**
518 * @var OutputPage
519 */
520 $wgOut = RequestContext::getMain()->getOutput(); # BackCompat
521
522 /**
523 * @var Parser
524 */
525 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
526
527 if ( !is_object( $wgAuth ) ) {
528 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
529 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
530 }
531
532 # Register file lock managers
533 LockManagerGroup::singleton()->register( $wgLockManagers );
534 # Register file backends
535 FileBackendGroup::singleton()->register( $wgFileBackends );
536
537 # Placeholders in case of DB error
538 $wgTitle = null;
539
540 $wgDeferredUpdateList = array();
541
542 // We need to check for safe_mode, because mail() will throw an E_NOTICE
543 // on additional parameters
544 if( !is_null($wgAdditionalMailParams) && wfIniGetBool('safe_mode') ) {
545 $wgAdditionalMailParams = null;
546 }
547
548 wfProfileOut( $fname . '-globals' );
549 wfProfileIn( $fname . '-extensions' );
550
551 # Extension setup functions for extensions other than skins
552 # Entries should be added to this variable during the inclusion
553 # of the extension file. This allows the extension to perform
554 # any necessary initialisation in the fully initialised environment
555 foreach ( $wgExtensionFunctions as $func ) {
556 # Allow closures in PHP 5.3+
557 if ( is_object( $func ) && $func instanceof Closure ) {
558 $profName = $fname . '-extensions-closure';
559 } elseif ( is_array( $func ) ) {
560 if ( is_object( $func[0] ) )
561 $profName = $fname . '-extensions-' . get_class( $func[0] ) . '::' . $func[1];
562 else
563 $profName = $fname . '-extensions-' . implode( '::', $func );
564 } else {
565 $profName = $fname . '-extensions-' . strval( $func );
566 }
567
568 wfProfileIn( $profName );
569 call_user_func( $func );
570 wfProfileOut( $profName );
571 }
572
573 wfDebug( "Fully initialised\n" );
574 $wgFullyInitialised = true;
575
576 wfProfileOut( $fname . '-extensions' );
577 wfProfileOut( $fname );