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