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