(bug 32412) TOC links on [[Special:EditWatchlist]] now points to the fieldset
[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 $wgLocalFileRepo from backwards-compatible settings
119 */
120 if ( !$wgLocalFileRepo ) {
121 if ( isset( $wgFileStore['deleted']['hash'] ) ) {
122 $deletedHashLevel = $wgFileStore['deleted']['hash'];
123 } else {
124 $deletedHashLevel = $wgHashedUploadDirectory ? 3 : 0;
125 }
126 $wgLocalFileRepo = array(
127 'class' => 'LocalRepo',
128 'name' => 'local',
129 'directory' => $wgUploadDirectory,
130 'scriptDirUrl' => $wgScriptPath,
131 'scriptExtension' => $wgScriptExtension,
132 'url' => $wgUploadBaseUrl ? $wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
133 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
134 'thumbScriptUrl' => $wgThumbnailScriptPath,
135 'transformVia404' => !$wgGenerateThumbnailOnParse,
136 'deletedDir' => $wgDeletedDirectory,
137 'deletedHashLevels' => $deletedHashLevel
138 );
139 }
140 /**
141 * Initialise shared repo from backwards-compatible settings
142 */
143 if ( $wgUseSharedUploads ) {
144 if ( $wgSharedUploadDBname ) {
145 $wgForeignFileRepos[] = array(
146 'class' => 'ForeignDBRepo',
147 'name' => 'shared',
148 'directory' => $wgSharedUploadDirectory,
149 'url' => $wgSharedUploadPath,
150 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
151 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
152 'transformVia404' => !$wgGenerateThumbnailOnParse,
153 'dbType' => $wgDBtype,
154 'dbServer' => $wgDBserver,
155 'dbUser' => $wgDBuser,
156 'dbPassword' => $wgDBpassword,
157 'dbName' => $wgSharedUploadDBname,
158 'dbFlags' => ( $wgDebugDumpSql ? DBO_DEBUG : 0 ) | DBO_DEFAULT,
159 'tablePrefix' => $wgSharedUploadDBprefix,
160 'hasSharedCache' => $wgCacheSharedUploads,
161 'descBaseUrl' => $wgRepositoryBaseUrl,
162 'fetchDescription' => $wgFetchCommonsDescriptions,
163 );
164 } else {
165 $wgForeignFileRepos[] = array(
166 'class' => 'FSRepo',
167 'name' => 'shared',
168 'directory' => $wgSharedUploadDirectory,
169 'url' => $wgSharedUploadPath,
170 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
171 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
172 'transformVia404' => !$wgGenerateThumbnailOnParse,
173 'descBaseUrl' => $wgRepositoryBaseUrl,
174 'fetchDescription' => $wgFetchCommonsDescriptions,
175 );
176 }
177 }
178 if ( $wgUseInstantCommons ) {
179 $wgForeignFileRepos[] = array(
180 'class' => 'ForeignAPIRepo',
181 'name' => 'wikimediacommons',
182 'apibase' => 'http://commons.wikimedia.org/w/api.php',
183 'hashLevels' => 2,
184 'fetchDescription' => true,
185 'descriptionCacheExpiry' => 43200,
186 'apiThumbCacheExpiry' => 86400,
187 );
188 }
189
190 if ( is_null( $wgEnableAutoRotation ) ) {
191 // Only enable auto-rotation when the bitmap handler can rotate
192 $wgEnableAutoRotation = BitmapHandler::canRotate();
193 }
194
195 if ( $wgRCFilterByAge ) {
196 # # Trim down $wgRCLinkDays so that it only lists links which are valid
197 # # as determined by $wgRCMaxAge.
198 # # Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
199 sort( $wgRCLinkDays );
200 for ( $i = 0; $i < count( $wgRCLinkDays ); $i++ ) {
201 if ( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
202 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i + 1, false );
203 break;
204 }
205 }
206 }
207
208 if ( $wgSkipSkin ) {
209 $wgSkipSkins[] = $wgSkipSkin;
210 }
211
212 # Set default shared prefix
213 if ( $wgSharedPrefix === false ) {
214 $wgSharedPrefix = $wgDBprefix;
215 }
216
217 if ( !$wgCookiePrefix ) {
218 if ( $wgSharedDB && $wgSharedPrefix && in_array( 'user', $wgSharedTables ) ) {
219 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
220 } elseif ( $wgSharedDB && in_array( 'user', $wgSharedTables ) ) {
221 $wgCookiePrefix = $wgSharedDB;
222 } elseif ( $wgDBprefix ) {
223 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
224 } else {
225 $wgCookiePrefix = $wgDBname;
226 }
227 }
228 $wgCookiePrefix = strtr( $wgCookiePrefix, '=,; +."\'\\[', '__________' );
229
230 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
231
232 if ( $wgMetaNamespace === false ) {
233 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
234 }
235
236 /**
237 * Definitions of the NS_ constants are in Defines.php
238 * @private
239 */
240 $wgCanonicalNamespaceNames = array(
241 NS_MEDIA => 'Media',
242 NS_SPECIAL => 'Special',
243 NS_TALK => 'Talk',
244 NS_USER => 'User',
245 NS_USER_TALK => 'User_talk',
246 NS_PROJECT => 'Project',
247 NS_PROJECT_TALK => 'Project_talk',
248 NS_FILE => 'File',
249 NS_FILE_TALK => 'File_talk',
250 NS_MEDIAWIKI => 'MediaWiki',
251 NS_MEDIAWIKI_TALK => 'MediaWiki_talk',
252 NS_TEMPLATE => 'Template',
253 NS_TEMPLATE_TALK => 'Template_talk',
254 NS_HELP => 'Help',
255 NS_HELP_TALK => 'Help_talk',
256 NS_CATEGORY => 'Category',
257 NS_CATEGORY_TALK => 'Category_talk',
258 );
259
260 /// @todo UGLY UGLY
261 if( is_array( $wgExtraNamespaces ) ) {
262 $wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames + $wgExtraNamespaces;
263 }
264
265 # These are now the same, always
266 # To determine the user language, use $wgLang->getCode()
267 $wgContLanguageCode = $wgLanguageCode;
268
269 # Easy to forget to falsify $wgShowIPinHeader for static caches.
270 # If file cache or squid cache is on, just disable this (DWIMD).
271 if ( $wgUseFileCache || $wgUseSquid ) {
272 $wgShowIPinHeader = false;
273 }
274
275 # $wgAllowRealName and $wgAllowUserSkin were removed in 1.16
276 # in favor of $wgHiddenPrefs, handle b/c here
277 if ( !$wgAllowRealName ) {
278 $wgHiddenPrefs[] = 'realname';
279 }
280
281 # Doesn't make sense to have if disabled.
282 if ( !$wgEnotifMinorEdits ) {
283 $wgHiddenPrefs[] = 'enotifminoredits';
284 }
285
286 # $wgDisabledActions is deprecated as of 1.18
287 foreach( $wgDisabledActions as $action ){
288 $wgActions[$action] = false;
289 }
290 if( !$wgAllowPageInfo ){
291 $wgActions['info'] = false;
292 }
293
294 if ( !$wgHtml5Version && $wgHtml5 && $wgAllowRdfaAttributes ) {
295 # see http://www.w3.org/TR/rdfa-in-html/#document-conformance
296 if ( $wgMimeType == 'application/xhtml+xml' ) {
297 $wgHtml5Version = 'XHTML+RDFa 1.0';
298 } else {
299 $wgHtml5Version = 'HTML+RDFa 1.0';
300 }
301 }
302
303 # Blacklisted file extensions shouldn't appear on the "allowed" list
304 $wgFileExtensions = array_diff ( $wgFileExtensions, $wgFileBlacklist );
305
306 if ( $wgArticleCountMethod === null ) {
307 $wgArticleCountMethod = $wgUseCommaCount ? 'comma' : 'link';
308 }
309
310 if ( $wgInvalidateCacheOnLocalSettingsChange ) {
311 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( "$IP/LocalSettings.php" ) ) );
312 }
313
314 if ( $wgAjaxUploadDestCheck ) {
315 $wgAjaxExportList[] = 'SpecialUpload::ajaxGetExistsWarning';
316 }
317
318 if ( $wgNewUserLog ) {
319 # Add a new log type
320 $wgLogTypes[] = 'newusers';
321 $wgLogNames['newusers'] = 'newuserlogpage';
322 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
323 # newusers, create, create2, autocreate
324 $wgLogActionsHandlers['newusers/*'] = 'NewUsersLogFormatter';
325 }
326
327 if ( $wgCookieSecure === 'detect' ) {
328 $wgCookieSecure = ( substr( $wgServer, 0, 6 ) === 'https:' );
329 }
330
331 if ( !defined( 'MW_COMPILED' ) ) {
332 if ( !MWInit::classExists( 'AutoLoader' ) ) {
333 require_once( "$IP/includes/AutoLoader.php" );
334 }
335
336 wfProfileIn( $fname . '-exception' );
337 MWExceptionHandler::installHandler();
338 wfProfileOut( $fname . '-exception' );
339
340 wfProfileIn( $fname . '-includes' );
341 require_once( "$IP/includes/normal/UtfNormalUtil.php" );
342 require_once( "$IP/includes/GlobalFunctions.php" );
343 require_once( "$IP/includes/ProxyTools.php" );
344 require_once( "$IP/includes/ImageFunctions.php" );
345 require_once( "$IP/includes/normal/UtfNormalDefines.php" );
346 wfProfileOut( $fname . '-includes' );
347 }
348
349 # Now that GlobalFunctions is loaded, set the default for $wgCanonicalServer
350 if ( $wgCanonicalServer === false ) {
351 $wgCanonicalServer = wfExpandUrl( $wgServer, PROTO_HTTP );
352 }
353
354 wfProfileIn( $fname . '-misc1' );
355
356 # Raise the memory limit if it's too low
357 wfMemoryLimit();
358
359 /**
360 * Set up the timezone, suppressing the pseudo-security warning in PHP 5.1+
361 * that happens whenever you use a date function without the timezone being
362 * explicitly set. Inspired by phpMyAdmin's treatment of the problem.
363 */
364 if ( is_null( $wgLocaltimezone) ) {
365 wfSuppressWarnings();
366 $wgLocaltimezone = date_default_timezone_get();
367 wfRestoreWarnings();
368 }
369
370 date_default_timezone_set( $wgLocaltimezone );
371 if( is_null( $wgLocalTZoffset ) ) {
372 $wgLocalTZoffset = date( 'Z' ) / 60;
373 }
374
375 # Useful debug output
376 global $wgCommandLineMode;
377 if ( $wgCommandLineMode ) {
378 $wgRequest = new FauxRequest( array() );
379
380 wfDebug( "\n\nStart command line script $self\n" );
381 } else {
382 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
383 $wgRequest = new WebRequest;
384
385 $debug = "Start request\n\n{$_SERVER['REQUEST_METHOD']} {$wgRequest->getRequestURL()}";
386
387 if ( $wgDebugPrintHttpHeaders ) {
388 $debug .= "\nHTTP HEADERS:\n";
389
390 foreach ( $wgRequest->getAllHeaders() as $name => $value ) {
391 $debug .= "$name: $value\n";
392 }
393 }
394 wfDebug( "$debug\n" );
395 }
396
397 wfProfileOut( $fname . '-misc1' );
398 wfProfileIn( $fname . '-memcached' );
399
400 $wgMemc = wfGetMainCache();
401 $messageMemc = wfGetMessageCacheStorage();
402 $parserMemc = wfGetParserCacheStorage();
403
404 wfDebug( 'CACHES: ' . get_class( $wgMemc ) . '[main] ' .
405 get_class( $messageMemc ) . '[message] ' .
406 get_class( $parserMemc ) . "[parser]\n" );
407
408 wfProfileOut( $fname . '-memcached' );
409
410 # # Most of the config is out, some might want to run hooks here.
411 wfRunHooks( 'SetupAfterCache' );
412
413 wfProfileIn( $fname . '-session' );
414
415 # If session.auto_start is there, we can't touch session name
416 if ( !wfIniGetBool( 'session.auto_start' ) ) {
417 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
418 }
419
420 if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
421 if ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix . 'Token'] ) ) {
422 wfIncrStats( 'request_with_session' );
423 wfSetupSession();
424 $wgSessionStarted = true;
425 } else {
426 wfIncrStats( 'request_without_session' );
427 $wgSessionStarted = false;
428 }
429 }
430
431 wfProfileOut( $fname . '-session' );
432 wfProfileIn( $fname . '-globals' );
433
434 $wgContLang = Language::factory( $wgLanguageCode );
435 $wgContLang->initEncoding();
436 $wgContLang->initContLang();
437
438 // Now that variant lists may be available...
439 $wgRequest->interpolateTitle();
440 $wgUser = RequestContext::getMain()->getUser(); # BackCompat
441
442 /**
443 * @var Language
444 */
445 $wgLang = new StubUserLang;
446
447 /**
448 * @var OutputPage
449 */
450 $wgOut = RequestContext::getMain()->getOutput(); # BackCompat
451
452 /**
453 * @var Parser
454 */
455 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
456
457 if ( !is_object( $wgAuth ) ) {
458 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
459 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
460 }
461
462 # Placeholders in case of DB error
463 $wgTitle = null;
464
465 $wgDeferredUpdateList = array();
466
467 // We need to check for safe_mode, because mail() will throw an E_NOTICE
468 // on additional parameters
469 if( !is_null($wgAdditionalMailParams) && wfIniGetBool('safe_mode') ) {
470 $wgAdditionalMailParams = null;
471 }
472
473 wfProfileOut( $fname . '-globals' );
474 wfProfileIn( $fname . '-extensions' );
475
476 # Extension setup functions for extensions other than skins
477 # Entries should be added to this variable during the inclusion
478 # of the extension file. This allows the extension to perform
479 # any necessary initialisation in the fully initialised environment
480 foreach ( $wgExtensionFunctions as $func ) {
481 # Allow closures in PHP 5.3+
482 if ( is_object( $func ) && $func instanceof Closure ) {
483 $profName = $fname . '-extensions-closure';
484 } elseif ( is_array( $func ) ) {
485 if ( is_object( $func[0] ) )
486 $profName = $fname . '-extensions-' . get_class( $func[0] ) . '::' . $func[1];
487 else
488 $profName = $fname . '-extensions-' . implode( '::', $func );
489 } else {
490 $profName = $fname . '-extensions-' . strval( $func );
491 }
492
493 wfProfileIn( $profName );
494 call_user_func( $func );
495 wfProfileOut( $profName );
496 }
497
498 wfDebug( "Fully initialised\n" );
499 $wgFullyInitialised = true;
500
501 wfProfileOut( $fname . '-extensions' );
502 wfProfileOut( $fname );