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