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