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