Revert r69291, other references-related problems reported
[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 require_once( "$IP/includes/StubObject.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 $wgIP = false; # Load on demand
186 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
187 $wgRequest = new WebRequest;
188
189 # Useful debug output
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
327 $wgUser = new StubUser;
328 $wgLang = new StubUserLang;
329 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
330 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
331
332 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
333 array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
334
335 wfProfileOut( $fname.'-globals' );
336 wfProfileIn( $fname.'-User' );
337
338 # Skin setup functions
339 # Entries can be added to this variable during the inclusion
340 # of the extension file. Skins can then perform any necessary initialisation.
341 #
342 foreach ( $wgSkinExtensionFunctions as $func ) {
343 call_user_func( $func );
344 }
345
346 if( !is_object( $wgAuth ) ) {
347 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
348 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
349 }
350
351 wfProfileOut( $fname.'-User' );
352
353 wfProfileIn( $fname.'-misc2' );
354
355 $wgDeferredUpdateList = array();
356 $wgPostCommitUpdateList = array();
357
358 if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'SpecialUpload::ajaxGetExistsWarning';
359
360 # Placeholders in case of DB error
361 $wgTitle = null;
362 $wgArticle = null;
363
364 wfProfileOut( $fname.'-misc2' );
365 wfProfileIn( $fname.'-extensions' );
366
367 # Extension setup functions for extensions other than skins
368 # Entries should be added to this variable during the inclusion
369 # of the extension file. This allows the extension to perform
370 # any necessary initialisation in the fully initialised environment
371 foreach ( $wgExtensionFunctions as $func ) {
372 # Allow closures in PHP 5.3+
373 if ( is_object( $func ) && $func instanceof Closure ) {
374 $profName = $fname.'-extensions-closure';
375 } elseif( is_array( $func ) ) {
376 if ( is_object( $func[0] ) )
377 $profName = $fname.'-extensions-'.get_class( $func[0] ).'::'.$func[1];
378 else
379 $profName = $fname.'-extensions-'.implode( '::', $func );
380 } else {
381 $profName = $fname.'-extensions-'.strval( $func );
382 }
383
384 wfProfileIn( $profName );
385 call_user_func( $func );
386 wfProfileOut( $profName );
387 }
388
389 // For compatibility
390 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
391 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
392 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
393 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
394
395 if( !empty($wgNewUserLog) ) {
396 # Add a new log type
397 $wgLogTypes[] = 'newusers';
398 $wgLogNames['newusers'] = 'newuserlogpage';
399 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
400 $wgLogActions['newusers/newusers'] = 'newuserlogentry'; // For compatibility with older log entries
401 $wgLogActions['newusers/create'] = 'newuserlog-create-entry';
402 $wgLogActions['newusers/create2'] = 'newuserlog-create2-entry';
403 $wgLogActions['newusers/autocreate'] = 'newuserlog-autocreate-entry';
404 }
405
406 wfDebug( "Fully initialised\n" );
407 $wgFullyInitialised = true;
408 wfProfileOut( $fname.'-extensions' );
409 wfProfileOut( $fname );