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