(bug 24212) Added MediaWiki:ImagePage.css which is also included on foreign client...
[lhc/web/wiklou.git] / includes / Setup.php
1 <?php
2 /**
3 * Include most things that's need to customize the site
4 */
5
6 /**
7 * This file is not a valid entry point, perform no further processing unless
8 * MEDIAWIKI is defined
9 */
10 if( !defined( 'MEDIAWIKI' ) ) {
11 exit( 1 );
12 }
13
14 # The main wiki script and things like database
15 # conversion and maintenance scripts all share a
16 # common setup of including lots of classes and
17 # setting up a few globals.
18 #
19
20 $fname = 'Setup.php';
21 wfProfileIn( $fname );
22
23 // Check to see if we are at the file scope
24 if ( !isset( $wgVersion ) ) {
25 echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
26 die( 1 );
27 }
28
29 // Set various default paths sensibly...
30 if( $wgScript === false ) $wgScript = "$wgScriptPath/index$wgScriptExtension";
31 if( $wgRedirectScript === false ) $wgRedirectScript = "$wgScriptPath/redirect$wgScriptExtension";
32
33 if( $wgArticlePath === false ) {
34 if( $wgUsePathInfo ) {
35 $wgArticlePath = "$wgScript/$1";
36 } else {
37 $wgArticlePath = "$wgScript?title=$1";
38 }
39 }
40
41 if( $wgStylePath === false ) $wgStylePath = "$wgScriptPath/skins";
42 if( $wgLocalStylePath === false ) $wgLocalStylePath = "$wgScriptPath/skins";
43 if( $wgStyleDirectory === false) $wgStyleDirectory = "$IP/skins";
44 if( $wgExtensionAssetsPath === false ) $wgExtensionAssetsPath = "$wgScriptPath/extensions";
45
46 if( $wgLogo === false ) $wgLogo = "$wgStylePath/common/images/wiki.png";
47
48 if( $wgUploadPath === false ) $wgUploadPath = "$wgScriptPath/images";
49 if( $wgUploadDirectory === false ) $wgUploadDirectory = "$IP/images";
50
51 if( $wgMathPath === false ) $wgMathPath = "{$wgUploadPath}/math";
52 if( $wgMathDirectory === false ) $wgMathDirectory = "{$wgUploadDirectory}/math";
53 if( $wgTmpDirectory === false ) $wgTmpDirectory = "{$wgUploadDirectory}/tmp";
54
55 if( $wgReadOnlyFile === false ) $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
56 if( $wgFileCacheDirectory === false ) $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
57
58 if ( empty( $wgFileStore['deleted']['directory'] ) ) {
59 $wgFileStore['deleted']['directory'] = "{$wgUploadDirectory}/deleted";
60 }
61
62 /**
63 * Unconditional protection for NS_MEDIAWIKI since otherwise it's too easy for a
64 * sysadmin to set $wgNamespaceProtection incorrectly and leave the wiki insecure.
65 *
66 * Note that this is the definition of editinterface and it can be granted to
67 * all users if desired.
68 */
69 $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
70
71 /**
72 * The canonical names of namespaces 6 and 7 are, as of v1.14, "File"
73 * and "File_talk". The old names "Image" and "Image_talk" are
74 * retained as aliases for backwards compatibility.
75 */
76 $wgNamespaceAliases['Image'] = NS_FILE;
77 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
78
79 /**
80 * Initialise $wgLocalFileRepo from backwards-compatible settings
81 */
82 if ( !$wgLocalFileRepo ) {
83 $wgLocalFileRepo = array(
84 'class' => 'LocalRepo',
85 'name' => 'local',
86 'directory' => $wgUploadDirectory,
87 'scriptDirUrl' => $wgScriptPath,
88 'scriptExtension' => $wgScriptExtension,
89 'url' => $wgUploadBaseUrl ? $wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
90 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
91 'thumbScriptUrl' => $wgThumbnailScriptPath,
92 'transformVia404' => !$wgGenerateThumbnailOnParse,
93 'deletedDir' => $wgFileStore['deleted']['directory'],
94 'deletedHashLevels' => $wgFileStore['deleted']['hash']
95 );
96 }
97 /**
98 * Initialise shared repo from backwards-compatible settings
99 */
100 if ( $wgUseSharedUploads ) {
101 if ( $wgSharedUploadDBname ) {
102 $wgForeignFileRepos[] = array(
103 'class' => 'ForeignDBRepo',
104 'name' => 'shared',
105 'directory' => $wgSharedUploadDirectory,
106 'url' => $wgSharedUploadPath,
107 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
108 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
109 'transformVia404' => !$wgGenerateThumbnailOnParse,
110 'dbType' => $wgDBtype,
111 'dbServer' => $wgDBserver,
112 'dbUser' => $wgDBuser,
113 'dbPassword' => $wgDBpassword,
114 'dbName' => $wgSharedUploadDBname,
115 'dbFlags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT,
116 'tablePrefix' => $wgSharedUploadDBprefix,
117 'hasSharedCache' => $wgCacheSharedUploads,
118 'descBaseUrl' => $wgRepositoryBaseUrl,
119 'fetchDescription' => $wgFetchCommonsDescriptions,
120 );
121 } else {
122 $wgForeignFileRepos[] = array(
123 'class' => 'FSRepo',
124 'name' => 'shared',
125 'directory' => $wgSharedUploadDirectory,
126 'url' => $wgSharedUploadPath,
127 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
128 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
129 'transformVia404' => !$wgGenerateThumbnailOnParse,
130 'descBaseUrl' => $wgRepositoryBaseUrl,
131 'fetchDescription' => $wgFetchCommonsDescriptions,
132 );
133 }
134 }
135 if( $wgUseInstantCommons ) {
136 $wgForeignFileRepos[] = array(
137 'class' => 'ForeignAPIRepo',
138 'name' => 'wikimediacommons',
139 'apibase' => 'http://commons.wikimedia.org/w/api.php',
140 'hashLevels' => 2,
141 'fetchDescription' => true,
142 'descriptionCacheExpiry' => 43200,
143 'apiThumbCacheExpiry' => 86400,
144 );
145 }
146
147 if ( !class_exists( 'AutoLoader' ) ) {
148 require_once( "$IP/includes/AutoLoader.php" );
149 }
150
151 wfProfileIn( $fname.'-exception' );
152 require_once( "$IP/includes/Exception.php" );
153 wfInstallExceptionHandler();
154 wfProfileOut( $fname.'-exception' );
155
156 wfProfileIn( $fname.'-includes' );
157 require_once( "$IP/includes/GlobalFunctions.php" );
158 require_once( "$IP/includes/Hooks.php" );
159 require_once( "$IP/includes/Namespace.php" );
160 require_once( "$IP/includes/ProxyTools.php" );
161 require_once( "$IP/includes/ObjectCache.php" );
162 require_once( "$IP/includes/ImageFunctions.php" );
163 require_once( "$IP/includes/StubObject.php" );
164 wfProfileOut( $fname.'-includes' );
165 wfProfileIn( $fname.'-misc1' );
166
167 # Raise the memory limit if it's too low
168 wfMemoryLimit();
169
170 /**
171 * Set up the timezone, suppressing the pseudo-security warning in PHP 5.1+
172 * that happens whenever you use a date function without the timezone being
173 * explicitly set. Inspired by phpMyAdmin's treatment of the problem.
174 */
175 wfSuppressWarnings();
176 date_default_timezone_set( date_default_timezone_get() );
177 wfRestoreWarnings();
178
179 $wgIP = false; # Load on demand
180 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
181 $wgRequest = new WebRequest;
182
183 # Useful debug output
184 if ( $wgCommandLineMode ) {
185 wfDebug( "\n\nStart command line script $self\n" );
186 } else {
187 wfDebug( "Start request\n\n" );
188 # Output the REQUEST_URI. This is not supported by IIS in rewrite mode,
189 # so use an alternative
190 $requestUri = isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] :
191 ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ? $_SERVER['HTTP_X_ORIGINAL_URL'] :
192 $_SERVER['PHP_SELF'] );
193 wfDebug( "{$_SERVER['REQUEST_METHOD']} {$requestUri}\n" );
194
195 if ( $wgDebugPrintHttpHeaders ) {
196 $headerOut = "HTTP HEADERS:\n";
197
198 if ( function_exists( 'getallheaders' ) ) {
199 $headers = getallheaders();
200 foreach ( $headers as $name => $value ) {
201 $headerOut .= "$name: $value\n";
202 }
203 } else {
204 $headers = $_SERVER;
205 foreach ( $headers as $name => $value ) {
206 if ( substr( $name, 0, 5 ) !== 'HTTP_' ) continue;
207 $name = substr( $name, 5 );
208 $headerOut .= "$name: $value\n";
209 }
210 }
211 wfDebug( "$headerOut\n" );
212 }
213 }
214
215 if( $wgRCFilterByAge ) {
216 ## Trim down $wgRCLinkDays so that it only lists links which are valid
217 ## as determined by $wgRCMaxAge.
218 ## Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
219 sort($wgRCLinkDays);
220 for( $i = 0; $i < count($wgRCLinkDays); $i++ ) {
221 if( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
222 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i+1, false );
223 break;
224 }
225 }
226 }
227
228 if ( $wgSkipSkin ) {
229 $wgSkipSkins[] = $wgSkipSkin;
230 }
231
232 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
233
234 if($wgMetaNamespace === FALSE) {
235 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
236 }
237
238 # These are now the same, always
239 # To determine the user language, use $wgLang->getCode()
240 $wgContLanguageCode = $wgLanguageCode;
241
242 # Easy to forget to falsify $wgShowIPinHeader for static caches.
243 # If file cache or squid cache is on, just disable this (DWIMD).
244 if( $wgUseFileCache || $wgUseSquid ) $wgShowIPinHeader = false;
245
246 # $wgAllowRealName and $wgAllowUserSkin were removed in 1.16
247 # in favor of $wgHiddenPrefs, handle b/c here
248 if( !$wgAllowRealName ) {
249 $wgHiddenPrefs[] = 'realname';
250 }
251
252 if( !$wgAllowUserSkin ) {
253 $wgHiddenPrefs[] = 'skin';
254 }
255
256 if ( !$wgHtml5Version && $wgHtml5 && $wgAllowRdfaAttributes ) {
257 # see http://www.w3.org/TR/rdfa-in-html/#document-conformance
258 if ( $wgMimeType == 'application/xhtml+xml' ) $wgHtml5Version = 'XHTML+RDFa 1.0';
259 else $wgHtml5Version = 'HTML+RDFa 1.0';
260 }
261
262
263 wfProfileOut( $fname.'-misc1' );
264 wfProfileIn( $fname.'-memcached' );
265
266 $wgMemc =& wfGetMainCache();
267 $messageMemc =& wfGetMessageCacheStorage();
268 $parserMemc =& wfGetParserCacheStorage();
269
270 wfDebug( 'CACHES: ' . get_class( $wgMemc ) . '[main] ' .
271 get_class( $messageMemc ) . '[message] ' .
272 get_class( $parserMemc ) . "[parser]\n" );
273
274 wfProfileOut( $fname.'-memcached' );
275
276 ## Most of the config is out, some might want to run hooks here.
277 wfRunHooks( 'SetupAfterCache' );
278
279 wfProfileIn( $fname.'-SetupSession' );
280
281 # Set default shared prefix
282 if( $wgSharedPrefix === false ) $wgSharedPrefix = $wgDBprefix;
283
284 if( !$wgCookiePrefix ) {
285 if ( $wgSharedDB && $wgSharedPrefix && in_array('user',$wgSharedTables) ) {
286 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
287 } elseif ( $wgSharedDB && in_array('user',$wgSharedTables) ) {
288 $wgCookiePrefix = $wgSharedDB;
289 } elseif ( $wgDBprefix ) {
290 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
291 } else {
292 $wgCookiePrefix = $wgDBname;
293 }
294 }
295 $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
296
297 # If session.auto_start is there, we can't touch session name
298 #
299 if( !wfIniGetBool( 'session.auto_start' ) )
300 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
301
302 if( !defined( 'MW_NO_SESSION' ) ) {
303 if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
304 wfIncrStats( 'request_with_session' );
305 wfSetupSession();
306 $wgSessionStarted = true;
307 } else {
308 wfIncrStats( 'request_without_session' );
309 $wgSessionStarted = false;
310 }
311 }
312
313 wfProfileOut( $fname.'-SetupSession' );
314 wfProfileIn( $fname.'-globals' );
315
316 $wgContLang = new StubContLang;
317
318 // Now that variant lists may be available...
319 $wgRequest->interpolateTitle();
320
321 $wgUser = new StubUser;
322 $wgLang = new StubUserLang;
323 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
324 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
325
326 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
327 array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
328
329 wfProfileOut( $fname.'-globals' );
330 wfProfileIn( $fname.'-User' );
331
332 # Skin setup functions
333 # Entries can be added to this variable during the inclusion
334 # of the extension file. Skins can then perform any necessary initialisation.
335 #
336 foreach ( $wgSkinExtensionFunctions as $func ) {
337 call_user_func( $func );
338 }
339
340 if( !is_object( $wgAuth ) ) {
341 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
342 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
343 }
344
345 wfProfileOut( $fname.'-User' );
346
347 wfProfileIn( $fname.'-misc2' );
348
349 $wgDeferredUpdateList = array();
350 $wgPostCommitUpdateList = array();
351
352 if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'SpecialUpload::ajaxGetExistsWarning';
353
354 # Placeholders in case of DB error
355 $wgTitle = null;
356 $wgArticle = null;
357
358 wfProfileOut( $fname.'-misc2' );
359 wfProfileIn( $fname.'-extensions' );
360
361 # Extension setup functions for extensions other than skins
362 # Entries should be added to this variable during the inclusion
363 # of the extension file. This allows the extension to perform
364 # any necessary initialisation in the fully initialised environment
365 foreach ( $wgExtensionFunctions as $func ) {
366 # Allow closures in PHP 5.3+
367 if ( is_object( $func ) && $func instanceof Closure ) {
368 $profName = $fname.'-extensions-closure';
369 } elseif( is_array( $func ) ) {
370 if ( is_object( $func[0] ) )
371 $profName = $fname.'-extensions-'.get_class( $func[0] ).'::'.$func[1];
372 else
373 $profName = $fname.'-extensions-'.implode( '::', $func );
374 } else {
375 $profName = $fname.'-extensions-'.strval( $func );
376 }
377
378 wfProfileIn( $profName );
379 call_user_func( $func );
380 wfProfileOut( $profName );
381 }
382
383 // For compatibility
384 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
385 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
386 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
387 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
388
389 if( !empty($wgNewUserLog) ) {
390 # Add a new log type
391 $wgLogTypes[] = 'newusers';
392 $wgLogNames['newusers'] = 'newuserlogpage';
393 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
394 $wgLogActions['newusers/newusers'] = 'newuserlogentry'; // For compatibility with older log entries
395 $wgLogActions['newusers/create'] = 'newuserlog-create-entry';
396 $wgLogActions['newusers/create2'] = 'newuserlog-create2-entry';
397 $wgLogActions['newusers/autocreate'] = 'newuserlog-autocreate-entry';
398 }
399
400 wfDebug( "Fully initialised\n" );
401 $wgFullyInitialised = true;
402 wfProfileOut( $fname.'-extensions' );
403 wfProfileOut( $fname );