introduce a new setting that allows extension authors to whitelist deprecated funtion...
[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 MWDebug::init();
332
333 if ( !defined( 'MW_COMPILED' ) ) {
334 if ( !MWInit::classExists( 'AutoLoader' ) ) {
335 require_once( "$IP/includes/AutoLoader.php" );
336 }
337
338 wfProfileIn( $fname . '-exception' );
339 MWExceptionHandler::installHandler();
340 wfProfileOut( $fname . '-exception' );
341
342 wfProfileIn( $fname . '-includes' );
343 require_once( "$IP/includes/normal/UtfNormalUtil.php" );
344 require_once( "$IP/includes/GlobalFunctions.php" );
345 require_once( "$IP/includes/ProxyTools.php" );
346 require_once( "$IP/includes/ImageFunctions.php" );
347 require_once( "$IP/includes/normal/UtfNormalDefines.php" );
348 wfProfileOut( $fname . '-includes' );
349 }
350
351 # Now that GlobalFunctions is loaded, set the default for $wgCanonicalServer
352 if ( $wgCanonicalServer === false ) {
353 $wgCanonicalServer = wfExpandUrl( $wgServer, PROTO_HTTP );
354 }
355
356 wfProfileIn( $fname . '-misc1' );
357
358 # Raise the memory limit if it's too low
359 wfMemoryLimit();
360
361 /**
362 * Set up the timezone, suppressing the pseudo-security warning in PHP 5.1+
363 * that happens whenever you use a date function without the timezone being
364 * explicitly set. Inspired by phpMyAdmin's treatment of the problem.
365 */
366 if ( is_null( $wgLocaltimezone) ) {
367 wfSuppressWarnings();
368 $wgLocaltimezone = date_default_timezone_get();
369 wfRestoreWarnings();
370 }
371
372 date_default_timezone_set( $wgLocaltimezone );
373 if( is_null( $wgLocalTZoffset ) ) {
374 $wgLocalTZoffset = date( 'Z' ) / 60;
375 }
376
377 # Useful debug output
378 global $wgCommandLineMode;
379 if ( $wgCommandLineMode ) {
380 $wgRequest = new FauxRequest( array() );
381
382 wfDebug( "\n\nStart command line script $self\n" );
383 } else {
384 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
385 $wgRequest = new WebRequest;
386
387 $debug = "Start request\n\n{$_SERVER['REQUEST_METHOD']} {$wgRequest->getRequestURL()}";
388
389 if ( $wgDebugPrintHttpHeaders ) {
390 $debug .= "\nHTTP HEADERS:\n";
391
392 foreach ( $wgRequest->getAllHeaders() as $name => $value ) {
393 $debug .= "$name: $value\n";
394 }
395 }
396 wfDebug( "$debug\n" );
397 MWDebug::processRequest( $wgRequest );
398 }
399
400 wfProfileOut( $fname . '-misc1' );
401 wfProfileIn( $fname . '-memcached' );
402
403 $wgMemc = wfGetMainCache();
404 $messageMemc = wfGetMessageCacheStorage();
405 $parserMemc = wfGetParserCacheStorage();
406
407 wfDebug( 'CACHES: ' . get_class( $wgMemc ) . '[main] ' .
408 get_class( $messageMemc ) . '[message] ' .
409 get_class( $parserMemc ) . "[parser]\n" );
410
411 wfProfileOut( $fname . '-memcached' );
412
413 # # Most of the config is out, some might want to run hooks here.
414 wfRunHooks( 'SetupAfterCache' );
415
416 wfProfileIn( $fname . '-session' );
417
418 # If session.auto_start is there, we can't touch session name
419 if ( !wfIniGetBool( 'session.auto_start' ) ) {
420 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
421 }
422
423 if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
424 if ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix . 'Token'] ) ) {
425 wfIncrStats( 'request_with_session' );
426 wfSetupSession();
427 $wgSessionStarted = true;
428 } else {
429 wfIncrStats( 'request_without_session' );
430 $wgSessionStarted = false;
431 }
432 }
433
434 wfProfileOut( $fname . '-session' );
435 wfProfileIn( $fname . '-globals' );
436
437 $wgContLang = Language::factory( $wgLanguageCode );
438 $wgContLang->initEncoding();
439 $wgContLang->initContLang();
440
441 // Now that variant lists may be available...
442 $wgRequest->interpolateTitle();
443 $wgUser = RequestContext::getMain()->getUser(); # BackCompat
444
445 /**
446 * @var Language
447 */
448 $wgLang = new StubUserLang;
449
450 /**
451 * @var OutputPage
452 */
453 $wgOut = RequestContext::getMain()->getOutput(); # BackCompat
454
455 /**
456 * @var Parser
457 */
458 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
459
460 if ( !is_object( $wgAuth ) ) {
461 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
462 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
463 }
464
465 # Placeholders in case of DB error
466 $wgTitle = null;
467
468 $wgDeferredUpdateList = array();
469
470 // We need to check for safe_mode, because mail() will throw an E_NOTICE
471 // on additional parameters
472 if( !is_null($wgAdditionalMailParams) && wfIniGetBool('safe_mode') ) {
473 $wgAdditionalMailParams = null;
474 }
475
476 wfProfileOut( $fname . '-globals' );
477 wfProfileIn( $fname . '-extensions' );
478
479 # Extension setup functions for extensions other than skins
480 # Entries should be added to this variable during the inclusion
481 # of the extension file. This allows the extension to perform
482 # any necessary initialisation in the fully initialised environment
483 foreach ( $wgExtensionFunctions as $func ) {
484 # Allow closures in PHP 5.3+
485 if ( is_object( $func ) && $func instanceof Closure ) {
486 $profName = $fname . '-extensions-closure';
487 } elseif ( is_array( $func ) ) {
488 if ( is_object( $func[0] ) )
489 $profName = $fname . '-extensions-' . get_class( $func[0] ) . '::' . $func[1];
490 else
491 $profName = $fname . '-extensions-' . implode( '::', $func );
492 } else {
493 $profName = $fname . '-extensions-' . strval( $func );
494 }
495
496 wfProfileIn( $profName );
497 call_user_func( $func );
498 wfProfileOut( $profName );
499 }
500
501 wfDebug( "Fully initialised\n" );
502 $wgFullyInitialised = true;
503
504 wfProfileOut( $fname . '-extensions' );
505 wfProfileOut( $fname );