Removed $wgProto. Previously, setting this undocumented global variable to anything...
[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 ( $wgRCFilterByAge ) {
191 # # Trim down $wgRCLinkDays so that it only lists links which are valid
192 # # as determined by $wgRCMaxAge.
193 # # Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
194 sort( $wgRCLinkDays );
195 for ( $i = 0; $i < count( $wgRCLinkDays ); $i++ ) {
196 if ( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
197 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i + 1, false );
198 break;
199 }
200 }
201 }
202
203 if ( $wgSkipSkin ) {
204 $wgSkipSkins[] = $wgSkipSkin;
205 }
206
207 # Set default shared prefix
208 if ( $wgSharedPrefix === false ) {
209 $wgSharedPrefix = $wgDBprefix;
210 }
211
212 if ( !$wgCookiePrefix ) {
213 if ( $wgSharedDB && $wgSharedPrefix && in_array( 'user', $wgSharedTables ) ) {
214 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
215 } elseif ( $wgSharedDB && in_array( 'user', $wgSharedTables ) ) {
216 $wgCookiePrefix = $wgSharedDB;
217 } elseif ( $wgDBprefix ) {
218 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
219 } else {
220 $wgCookiePrefix = $wgDBname;
221 }
222 }
223 $wgCookiePrefix = strtr( $wgCookiePrefix, '=,; +."\'\\[', '__________' );
224
225 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
226
227 if ( $wgMetaNamespace === false ) {
228 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
229 }
230
231 /**
232 * Definitions of the NS_ constants are in Defines.php
233 * @private
234 */
235 $wgCanonicalNamespaceNames = array(
236 NS_MEDIA => 'Media',
237 NS_SPECIAL => 'Special',
238 NS_TALK => 'Talk',
239 NS_USER => 'User',
240 NS_USER_TALK => 'User_talk',
241 NS_PROJECT => 'Project',
242 NS_PROJECT_TALK => 'Project_talk',
243 NS_FILE => 'File',
244 NS_FILE_TALK => 'File_talk',
245 NS_MEDIAWIKI => 'MediaWiki',
246 NS_MEDIAWIKI_TALK => 'MediaWiki_talk',
247 NS_TEMPLATE => 'Template',
248 NS_TEMPLATE_TALK => 'Template_talk',
249 NS_HELP => 'Help',
250 NS_HELP_TALK => 'Help_talk',
251 NS_CATEGORY => 'Category',
252 NS_CATEGORY_TALK => 'Category_talk',
253 );
254
255 /// @todo UGLY UGLY
256 if( is_array( $wgExtraNamespaces ) ) {
257 $wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames + $wgExtraNamespaces;
258 }
259
260 # These are now the same, always
261 # To determine the user language, use $wgLang->getCode()
262 $wgContLanguageCode = $wgLanguageCode;
263
264 # Easy to forget to falsify $wgShowIPinHeader for static caches.
265 # If file cache or squid cache is on, just disable this (DWIMD).
266 if ( $wgUseFileCache || $wgUseSquid ) {
267 $wgShowIPinHeader = false;
268 }
269
270 # $wgAllowRealName and $wgAllowUserSkin were removed in 1.16
271 # in favor of $wgHiddenPrefs, handle b/c here
272 if ( !$wgAllowRealName ) {
273 $wgHiddenPrefs[] = 'realname';
274 }
275
276 # Doesn't make sense to have if disabled.
277 if ( !$wgEnotifMinorEdits ) {
278 $wgHiddenPrefs[] = 'enotifminoredits';
279 }
280
281 # $wgDisabledActions is deprecated as of 1.18
282 foreach( $wgDisabledActions as $action ){
283 $wgActions[$action] = false;
284 }
285 if( !$wgAllowPageInfo ){
286 $wgActions['info'] = false;
287 }
288
289 if ( !$wgHtml5Version && $wgHtml5 && $wgAllowRdfaAttributes ) {
290 # see http://www.w3.org/TR/rdfa-in-html/#document-conformance
291 if ( $wgMimeType == 'application/xhtml+xml' ) {
292 $wgHtml5Version = 'XHTML+RDFa 1.0';
293 } else {
294 $wgHtml5Version = 'HTML+RDFa 1.0';
295 }
296 }
297
298 # Blacklisted file extensions shouldn't appear on the "allowed" list
299 $wgFileExtensions = array_diff ( $wgFileExtensions, $wgFileBlacklist );
300
301 if ( $wgArticleCountMethod === null ) {
302 $wgArticleCountMethod = $wgUseCommaCount ? 'comma' : 'link';
303 }
304
305 if ( $wgInvalidateCacheOnLocalSettingsChange ) {
306 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( "$IP/LocalSettings.php" ) ) );
307 }
308
309 if ( $wgAjaxUploadDestCheck ) {
310 $wgAjaxExportList[] = 'SpecialUpload::ajaxGetExistsWarning';
311 }
312
313 if ( $wgNewUserLog ) {
314 # Add a new log type
315 $wgLogTypes[] = 'newusers';
316 $wgLogNames['newusers'] = 'newuserlogpage';
317 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
318 $wgLogActions['newusers/newusers'] = 'newuserlogentry'; // For compatibility with older log entries
319 $wgLogActions['newusers/create'] = 'newuserlog-create-entry';
320 $wgLogActions['newusers/create2'] = 'newuserlog-create2-entry';
321 $wgLogActions['newusers/autocreate'] = 'newuserlog-autocreate-entry';
322 }
323
324 if ( $wgCookieSecure === 'detect' ) {
325 $wgCookieSecure = ( substr( $wgServer, 0, 6 ) === 'https:' );
326 }
327
328 if ( !defined( 'MW_COMPILED' ) ) {
329 if ( !MWInit::classExists( 'AutoLoader' ) ) {
330 require_once( "$IP/includes/AutoLoader.php" );
331 }
332
333 wfProfileIn( $fname . '-exception' );
334 MWExceptionHandler::installHandler();
335 wfProfileOut( $fname . '-exception' );
336
337 wfProfileIn( $fname . '-includes' );
338 require_once( "$IP/includes/normal/UtfNormalUtil.php" );
339 require_once( "$IP/includes/GlobalFunctions.php" );
340 require_once( "$IP/includes/ProxyTools.php" );
341 require_once( "$IP/includes/ImageFunctions.php" );
342 require_once( "$IP/includes/normal/UtfNormalDefines.php" );
343 wfProfileOut( $fname . '-includes' );
344 }
345
346 wfProfileIn( $fname . '-misc1' );
347
348 # Raise the memory limit if it's too low
349 wfMemoryLimit();
350
351 /**
352 * Set up the timezone, suppressing the pseudo-security warning in PHP 5.1+
353 * that happens whenever you use a date function without the timezone being
354 * explicitly set. Inspired by phpMyAdmin's treatment of the problem.
355 */
356 if ( is_null( $wgLocaltimezone) ) {
357 wfSuppressWarnings();
358 $wgLocaltimezone = date_default_timezone_get();
359 wfRestoreWarnings();
360 }
361
362 date_default_timezone_set( $wgLocaltimezone );
363 if( is_null( $wgLocalTZoffset ) ) {
364 $wgLocalTZoffset = date( 'Z' ) / 60;
365 }
366
367 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
368 $wgRequest = new WebRequest;
369
370 # Useful debug output
371 global $wgCommandLineMode;
372 if ( $wgCommandLineMode ) {
373 wfDebug( "\n\nStart command line script $self\n" );
374 } else {
375 $debug = "Start request\n\n{$_SERVER['REQUEST_METHOD']} {$wgRequest->getRequestURL()}";
376
377 if ( $wgDebugPrintHttpHeaders ) {
378 $debug .= "\nHTTP HEADERS:\n";
379
380 foreach ( $wgRequest->getAllHeaders() as $name => $value ) {
381 $debug .= "$name: $value\n";
382 }
383 }
384 wfDebug( "$debug\n" );
385 }
386
387 wfProfileOut( $fname . '-misc1' );
388 wfProfileIn( $fname . '-memcached' );
389
390 $wgMemc = wfGetMainCache();
391 $messageMemc = wfGetMessageCacheStorage();
392 $parserMemc = wfGetParserCacheStorage();
393
394 wfDebug( 'CACHES: ' . get_class( $wgMemc ) . '[main] ' .
395 get_class( $messageMemc ) . '[message] ' .
396 get_class( $parserMemc ) . "[parser]\n" );
397
398 wfProfileOut( $fname . '-memcached' );
399
400 # # Most of the config is out, some might want to run hooks here.
401 wfRunHooks( 'SetupAfterCache' );
402
403 wfProfileIn( $fname . '-session' );
404
405 # If session.auto_start is there, we can't touch session name
406 if ( !wfIniGetBool( 'session.auto_start' ) ) {
407 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
408 }
409
410 if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
411 if ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix . 'Token'] ) ) {
412 wfIncrStats( 'request_with_session' );
413 wfSetupSession();
414 $wgSessionStarted = true;
415 } else {
416 wfIncrStats( 'request_without_session' );
417 $wgSessionStarted = false;
418 }
419 }
420
421 wfProfileOut( $fname . '-session' );
422 wfProfileIn( $fname . '-globals' );
423
424 $wgContLang = Language::factory( $wgLanguageCode );
425 $wgContLang->initEncoding();
426 $wgContLang->initContLang();
427
428 // Now that variant lists may be available...
429 $wgRequest->interpolateTitle();
430 $wgUser = RequestContext::getMain()->getUser(); # BackCompat
431
432 /**
433 * @var Language
434 */
435 $wgLang = new StubUserLang;
436
437 /**
438 * @var OutputPage
439 */
440 $wgOut = RequestContext::getMain()->getOutput(); # BackCompat
441
442 /**
443 * @var Parser
444 */
445 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
446
447 if ( !is_object( $wgAuth ) ) {
448 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
449 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
450 }
451
452 # Placeholders in case of DB error
453 $wgTitle = null;
454
455 $wgDeferredUpdateList = array();
456
457 // We need to check for safe_mode, because mail() will throw an E_NOTICE
458 // on additional parameters
459 if( !is_null($wgAdditionalMailParams) && wfIniGetBool('safe_mode') ) {
460 $wgAdditionalMailParams = null;
461 }
462
463 wfProfileOut( $fname . '-globals' );
464 wfProfileIn( $fname . '-extensions' );
465
466 # Extension setup functions for extensions other than skins
467 # Entries should be added to this variable during the inclusion
468 # of the extension file. This allows the extension to perform
469 # any necessary initialisation in the fully initialised environment
470 foreach ( $wgExtensionFunctions as $func ) {
471 # Allow closures in PHP 5.3+
472 if ( is_object( $func ) && $func instanceof Closure ) {
473 $profName = $fname . '-extensions-closure';
474 } elseif ( is_array( $func ) ) {
475 if ( is_object( $func[0] ) )
476 $profName = $fname . '-extensions-' . get_class( $func[0] ) . '::' . $func[1];
477 else
478 $profName = $fname . '-extensions-' . implode( '::', $func );
479 } else {
480 $profName = $fname . '-extensions-' . strval( $func );
481 }
482
483 wfProfileIn( $profName );
484 call_user_func( $func );
485 wfProfileOut( $profName );
486 }
487
488 wfDebug( "Fully initialised\n" );
489 $wgFullyInitialised = true;
490
491 wfProfileOut( $fname . '-extensions' );
492 wfProfileOut( $fname );