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