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