Followup r70515, commiting forgotten file
[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 if( $wgDeletedDirectory === false ) $wgDeletedDirectory = "{$wgUploadDirectory}/deleted";
58
59 if( isset( $wgFileStore['deleted']['directory'] ) ) {
60 $wgDeletedDirectory = $wgFileStore['deleted']['directory'];
61 }
62
63 /**
64 * Unconditional protection for NS_MEDIAWIKI since otherwise it's too easy for a
65 * sysadmin to set $wgNamespaceProtection incorrectly and leave the wiki insecure.
66 *
67 * Note that this is the definition of editinterface and it can be granted to
68 * all users if desired.
69 */
70 $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
71
72 /**
73 * The canonical names of namespaces 6 and 7 are, as of v1.14, "File"
74 * and "File_talk". The old names "Image" and "Image_talk" are
75 * retained as aliases for backwards compatibility.
76 */
77 $wgNamespaceAliases['Image'] = NS_FILE;
78 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
79
80 /**
81 * Initialise $wgLocalFileRepo from backwards-compatible settings
82 */
83 if ( !$wgLocalFileRepo ) {
84 if( isset( $wgFileStore['deleted']['hash'] ) ) {
85 $deletedHashLevel = $wgFileStore['deleted']['hash'];
86 } else {
87 $deletedHashLevel = $wgHashedUploadDirectory ? 3 : 0;
88 }
89 $wgLocalFileRepo = array(
90 'class' => 'LocalRepo',
91 'name' => 'local',
92 'directory' => $wgUploadDirectory,
93 'scriptDirUrl' => $wgScriptPath,
94 'scriptExtension' => $wgScriptExtension,
95 'url' => $wgUploadBaseUrl ? $wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
96 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
97 'thumbScriptUrl' => $wgThumbnailScriptPath,
98 'transformVia404' => !$wgGenerateThumbnailOnParse,
99 'deletedDir' => $wgDeletedDirectory,
100 'deletedHashLevels' => $deletedHashLevel
101 );
102 }
103 /**
104 * Initialise shared repo from backwards-compatible settings
105 */
106 if ( $wgUseSharedUploads ) {
107 if ( $wgSharedUploadDBname ) {
108 $wgForeignFileRepos[] = array(
109 'class' => 'ForeignDBRepo',
110 'name' => 'shared',
111 'directory' => $wgSharedUploadDirectory,
112 'url' => $wgSharedUploadPath,
113 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
114 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
115 'transformVia404' => !$wgGenerateThumbnailOnParse,
116 'dbType' => $wgDBtype,
117 'dbServer' => $wgDBserver,
118 'dbUser' => $wgDBuser,
119 'dbPassword' => $wgDBpassword,
120 'dbName' => $wgSharedUploadDBname,
121 'dbFlags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT,
122 'tablePrefix' => $wgSharedUploadDBprefix,
123 'hasSharedCache' => $wgCacheSharedUploads,
124 'descBaseUrl' => $wgRepositoryBaseUrl,
125 'fetchDescription' => $wgFetchCommonsDescriptions,
126 );
127 } else {
128 $wgForeignFileRepos[] = array(
129 'class' => 'FSRepo',
130 'name' => 'shared',
131 'directory' => $wgSharedUploadDirectory,
132 'url' => $wgSharedUploadPath,
133 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
134 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
135 'transformVia404' => !$wgGenerateThumbnailOnParse,
136 'descBaseUrl' => $wgRepositoryBaseUrl,
137 'fetchDescription' => $wgFetchCommonsDescriptions,
138 );
139 }
140 }
141 if( $wgUseInstantCommons ) {
142 $wgForeignFileRepos[] = array(
143 'class' => 'ForeignAPIRepo',
144 'name' => 'wikimediacommons',
145 'apibase' => 'http://commons.wikimedia.org/w/api.php',
146 'hashLevels' => 2,
147 'fetchDescription' => true,
148 'descriptionCacheExpiry' => 43200,
149 'apiThumbCacheExpiry' => 86400,
150 );
151 }
152
153 if ( !class_exists( 'AutoLoader' ) ) {
154 require_once( "$IP/includes/AutoLoader.php" );
155 }
156
157 wfProfileIn( $fname.'-exception' );
158 require_once( "$IP/includes/Exception.php" );
159 wfInstallExceptionHandler();
160 wfProfileOut( $fname.'-exception' );
161
162 wfProfileIn( $fname.'-includes' );
163 require_once( "$IP/includes/GlobalFunctions.php" );
164 require_once( "$IP/includes/Hooks.php" );
165 require_once( "$IP/includes/Namespace.php" );
166 require_once( "$IP/includes/ProxyTools.php" );
167 require_once( "$IP/includes/ObjectCache.php" );
168 require_once( "$IP/includes/ImageFunctions.php" );
169 wfProfileOut( $fname.'-includes' );
170 wfProfileIn( $fname.'-misc1' );
171
172 # Raise the memory limit if it's too low
173 wfMemoryLimit();
174
175 /**
176 * Set up the timezone, suppressing the pseudo-security warning in PHP 5.1+
177 * that happens whenever you use a date function without the timezone being
178 * explicitly set. Inspired by phpMyAdmin's treatment of the problem.
179 */
180 wfSuppressWarnings();
181 date_default_timezone_set( date_default_timezone_get() );
182 wfRestoreWarnings();
183
184 $wgIP = false; # Load on demand
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 if ( $wgCommandLineMode ) {
190 wfDebug( "\n\nStart command line script $self\n" );
191 } else {
192 wfDebug( "Start request\n\n" );
193 # Output the REQUEST_URI. This is not supported by IIS in rewrite mode,
194 # so use an alternative
195 $requestUri = isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] :
196 ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ? $_SERVER['HTTP_X_ORIGINAL_URL'] :
197 $_SERVER['PHP_SELF'] );
198 wfDebug( "{$_SERVER['REQUEST_METHOD']} {$requestUri}\n" );
199
200 if ( $wgDebugPrintHttpHeaders ) {
201 $headerOut = "HTTP HEADERS:\n";
202
203 if ( function_exists( 'getallheaders' ) ) {
204 $headers = getallheaders();
205 foreach ( $headers as $name => $value ) {
206 $headerOut .= "$name: $value\n";
207 }
208 } else {
209 $headers = $_SERVER;
210 foreach ( $headers as $name => $value ) {
211 if ( substr( $name, 0, 5 ) !== 'HTTP_' ) continue;
212 $name = substr( $name, 5 );
213 $headerOut .= "$name: $value\n";
214 }
215 }
216 wfDebug( "$headerOut\n" );
217 }
218 }
219
220 if( $wgRCFilterByAge ) {
221 ## Trim down $wgRCLinkDays so that it only lists links which are valid
222 ## as determined by $wgRCMaxAge.
223 ## Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
224 sort($wgRCLinkDays);
225 for( $i = 0; $i < count($wgRCLinkDays); $i++ ) {
226 if( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
227 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i+1, false );
228 break;
229 }
230 }
231 }
232
233 if ( $wgSkipSkin ) {
234 $wgSkipSkins[] = $wgSkipSkin;
235 }
236
237 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
238
239 if($wgMetaNamespace === FALSE) {
240 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
241 }
242
243 # These are now the same, always
244 # To determine the user language, use $wgLang->getCode()
245 $wgContLanguageCode = $wgLanguageCode;
246
247 # Easy to forget to falsify $wgShowIPinHeader for static caches.
248 # If file cache or squid cache is on, just disable this (DWIMD).
249 if( $wgUseFileCache || $wgUseSquid ) $wgShowIPinHeader = false;
250
251 # $wgAllowRealName and $wgAllowUserSkin were removed in 1.16
252 # in favor of $wgHiddenPrefs, handle b/c here
253 if( !$wgAllowRealName ) {
254 $wgHiddenPrefs[] = 'realname';
255 }
256
257 if( !$wgAllowUserSkin ) {
258 $wgHiddenPrefs[] = 'skin';
259 }
260
261 if ( !$wgHtml5Version && $wgHtml5 && $wgAllowRdfaAttributes ) {
262 # see http://www.w3.org/TR/rdfa-in-html/#document-conformance
263 if ( $wgMimeType == 'application/xhtml+xml' ) $wgHtml5Version = 'XHTML+RDFa 1.0';
264 else $wgHtml5Version = 'HTML+RDFa 1.0';
265 }
266
267
268 wfProfileOut( $fname.'-misc1' );
269 wfProfileIn( $fname.'-memcached' );
270
271 $wgMemc =& wfGetMainCache();
272 $messageMemc =& wfGetMessageCacheStorage();
273 $parserMemc =& wfGetParserCacheStorage();
274
275 wfDebug( 'CACHES: ' . get_class( $wgMemc ) . '[main] ' .
276 get_class( $messageMemc ) . '[message] ' .
277 get_class( $parserMemc ) . "[parser]\n" );
278
279 wfProfileOut( $fname.'-memcached' );
280
281 ## Most of the config is out, some might want to run hooks here.
282 wfRunHooks( 'SetupAfterCache' );
283
284 wfProfileIn( $fname.'-SetupSession' );
285
286 # Set default shared prefix
287 if( $wgSharedPrefix === false ) $wgSharedPrefix = $wgDBprefix;
288
289 if( !$wgCookiePrefix ) {
290 if ( $wgSharedDB && $wgSharedPrefix && in_array('user',$wgSharedTables) ) {
291 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
292 } elseif ( $wgSharedDB && in_array('user',$wgSharedTables) ) {
293 $wgCookiePrefix = $wgSharedDB;
294 } elseif ( $wgDBprefix ) {
295 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
296 } else {
297 $wgCookiePrefix = $wgDBname;
298 }
299 }
300 $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
301
302 # If session.auto_start is there, we can't touch session name
303 #
304 if( !wfIniGetBool( 'session.auto_start' ) )
305 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
306
307 if( !defined( 'MW_NO_SESSION' ) ) {
308 if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
309 wfIncrStats( 'request_with_session' );
310 wfSetupSession();
311 $wgSessionStarted = true;
312 } else {
313 wfIncrStats( 'request_without_session' );
314 $wgSessionStarted = false;
315 }
316 }
317
318 wfProfileOut( $fname.'-SetupSession' );
319 wfProfileIn( $fname.'-globals' );
320
321 $wgContLang = new StubContLang;
322
323 // Now that variant lists may be available...
324 $wgRequest->interpolateTitle();
325
326 $wgUser = new StubUser;
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 );