Self-revert 40530, 40531. Too many things still depend on $_GET and $_POST. Needs...
[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 echo "This file is part of MediaWiki, it is not a valid entry point.\n";
12 exit( 1 );
13 }
14
15 # The main wiki script and things like database
16 # conversion and maintenance scripts all share a
17 # common setup of including lots of classes and
18 # setting up a few globals.
19 #
20
21 $fname = 'Setup.php';
22 wfProfileIn( $fname );
23
24 // Check to see if we are at the file scope
25 if ( !isset( $wgVersion ) ) {
26 echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
27 die( 1 );
28 }
29
30 // Set various default paths sensibly...
31 if( $wgScript === false ) $wgScript = "$wgScriptPath/index$wgScriptExtension";
32 if( $wgRedirectScript === false ) $wgRedirectScript = "$wgScriptPath/redirect$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( $wgStyleDirectory === false) $wgStyleDirectory = "$IP/skins";
44
45 if( $wgLogo === false ) $wgLogo = "$wgStylePath/common/images/wiki.png";
46
47 if( $wgUploadPath === false ) $wgUploadPath = "$wgScriptPath/images";
48 if( $wgUploadDirectory === false ) $wgUploadDirectory = "$IP/images";
49
50 if( $wgMathPath === false ) $wgMathPath = "{$wgUploadPath}/math";
51 if( $wgMathDirectory === false ) $wgMathDirectory = "{$wgUploadDirectory}/math";
52 if( $wgTmpDirectory === false ) $wgTmpDirectory = "{$wgUploadDirectory}/tmp";
53
54 if( $wgReadOnlyFile === false ) $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
55 if( $wgFileCacheDirectory === false ) $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
56
57 if ( empty( $wgFileStore['deleted']['directory'] ) ) {
58 $wgFileStore['deleted']['directory'] = "{$wgUploadDirectory}/deleted";
59 }
60
61 /**
62 * Unconditional protection for NS_MEDIAWIKI since otherwise it's too easy for a
63 * sysadmin to set $wgNamespaceProtection incorrectly and leave the wiki insecure.
64 *
65 * Note that this is the definition of editinterface and it can be granted to
66 * all users if desired.
67 */
68 $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
69
70 /**
71 * Initialise $wgLocalFileRepo from backwards-compatible settings
72 */
73 if ( !$wgLocalFileRepo ) {
74 $wgLocalFileRepo = array(
75 'class' => 'LocalRepo',
76 'name' => 'local',
77 'directory' => $wgUploadDirectory,
78 'url' => $wgUploadBaseUrl ? $wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
79 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
80 'thumbScriptUrl' => $wgThumbnailScriptPath,
81 'transformVia404' => !$wgGenerateThumbnailOnParse,
82 'initialCapital' => $wgCapitalLinks,
83 'deletedDir' => $wgFileStore['deleted']['directory'],
84 'deletedHashLevels' => $wgFileStore['deleted']['hash']
85 );
86 }
87 /**
88 * Initialise shared repo from backwards-compatible settings
89 */
90 if ( $wgUseSharedUploads ) {
91 if ( $wgSharedUploadDBname ) {
92 $wgForeignFileRepos[] = array(
93 'class' => 'ForeignDBRepo',
94 'name' => 'shared',
95 'directory' => $wgSharedUploadDirectory,
96 'url' => $wgSharedUploadPath,
97 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
98 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
99 'transformVia404' => !$wgGenerateThumbnailOnParse,
100 'dbType' => $wgDBtype,
101 'dbServer' => $wgDBserver,
102 'dbUser' => $wgDBuser,
103 'dbPassword' => $wgDBpassword,
104 'dbName' => $wgSharedUploadDBname,
105 'dbFlags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT,
106 'tablePrefix' => $wgSharedUploadDBprefix,
107 'hasSharedCache' => $wgCacheSharedUploads,
108 'descBaseUrl' => $wgRepositoryBaseUrl,
109 'fetchDescription' => $wgFetchCommonsDescriptions,
110 );
111 } else {
112 $wgForeignFileRepos[] = array(
113 'class' => 'FSRepo',
114 'name' => 'shared',
115 'directory' => $wgSharedUploadDirectory,
116 'url' => $wgSharedUploadPath,
117 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
118 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
119 'transformVia404' => !$wgGenerateThumbnailOnParse,
120 'descBaseUrl' => $wgRepositoryBaseUrl,
121 'fetchDescription' => $wgFetchCommonsDescriptions,
122 );
123 }
124 }
125
126 /**
127 * Workaround for http://bugs.php.net/bug.php?id=45132
128 * escapeshellarg() destroys non-ASCII characters if LANG is not a UTF-8 locale
129 */
130 putenv( 'LC_CTYPE=en_US.UTF-8' );
131 setlocale( LC_CTYPE, 'en_US.UTF-8' );
132
133 if ( !class_exists( 'AutoLoader' ) ) {
134 require_once( "$IP/includes/AutoLoader.php" );
135 }
136
137 wfProfileIn( $fname.'-exception' );
138 require_once( "$IP/includes/Exception.php" );
139 wfInstallExceptionHandler();
140 wfProfileOut( $fname.'-exception' );
141
142 wfProfileIn( $fname.'-includes' );
143 require_once( "$IP/includes/GlobalFunctions.php" );
144 require_once( "$IP/includes/Hooks.php" );
145 require_once( "$IP/includes/Namespace.php" );
146 require_once( "$IP/includes/ProxyTools.php" );
147 require_once( "$IP/includes/ObjectCache.php" );
148 require_once( "$IP/includes/ImageFunctions.php" );
149 require_once( "$IP/includes/StubObject.php" );
150 wfProfileOut( $fname.'-includes' );
151 wfProfileIn( $fname.'-misc1' );
152
153
154 $wgIP = false; # Load on demand
155 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
156 $wgRequest = new WebRequest;
157 if ( function_exists( 'posix_uname' ) ) {
158 $wguname = posix_uname();
159 $wgNodeName = $wguname['nodename'];
160 } else {
161 $wgNodeName = '';
162 }
163
164 # Useful debug output
165 if ( $wgCommandLineMode ) {
166 wfDebug( "\n\nStart command line script $self\n" );
167 } elseif ( function_exists( 'getallheaders' ) ) {
168 wfDebug( "\n\nStart request\n" );
169 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
170 $headers = getallheaders();
171 foreach ($headers as $name => $value) {
172 wfDebug( "$name: $value\n" );
173 }
174 wfDebug( "\n" );
175 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
176 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
177 }
178
179 if( $wgRCFilterByAge ) {
180 ## Trim down $wgRCLinkDays so that it only lists links which are valid
181 ## as determined by $wgRCMaxAge.
182 ## Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
183 sort($wgRCLinkDays);
184 for( $i = 0; $i < count($wgRCLinkDays); $i++ ) {
185 if( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
186 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i+1, false );
187 break;
188 }
189 }
190 }
191
192 if ( $wgSkipSkin ) {
193 $wgSkipSkins[] = $wgSkipSkin;
194 }
195
196 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
197
198 if($wgMetaNamespace === FALSE) {
199 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
200 }
201
202 # These are now the same, always
203 # To determine the user language, use $wgLang->getCode()
204 $wgContLanguageCode = $wgLanguageCode;
205
206 wfProfileOut( $fname.'-misc1' );
207 wfProfileIn( $fname.'-memcached' );
208
209 $wgMemc =& wfGetMainCache();
210 $messageMemc =& wfGetMessageCacheStorage();
211 $parserMemc =& wfGetParserCacheStorage();
212
213 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
214 "\nMessage cache: " . get_class( $messageMemc ) .
215 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
216
217 wfProfileOut( $fname.'-memcached' );
218 wfProfileIn( $fname.'-SetupSession' );
219
220 # Set default shared prefix
221 if( $wgSharedPrefix === false ) $wgSharedPrefix = $wgDBprefix;
222
223 if( !$wgCookiePrefix ) {
224 if ( in_array('user', $wgSharedTables) && $wgSharedDB && $wgSharedPrefix ) {
225 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
226 } elseif ( in_array('user', $wgSharedTables) && $wgSharedDB ) {
227 $wgCookiePrefix = $wgSharedDB;
228 } elseif ( $wgDBprefix ) {
229 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
230 } else {
231 $wgCookiePrefix = $wgDBname;
232 }
233 }
234 $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
235
236 # If session.auto_start is there, we can't touch session name
237 #
238 if( !wfIniGetBool( 'session.auto_start' ) )
239 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
240
241 if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
242 wfIncrStats( 'request_with_session' );
243 wfSetupSession();
244 $wgSessionStarted = true;
245 } else {
246 wfIncrStats( 'request_without_session' );
247 $wgSessionStarted = false;
248 }
249
250 wfProfileOut( $fname.'-SetupSession' );
251 wfProfileIn( $fname.'-globals' );
252
253 $wgContLang = new StubContLang;
254
255 // Now that variant lists may be available...
256 $wgRequest->interpolateTitle();
257
258 $wgUser = new StubUser;
259 $wgLang = new StubUserLang;
260 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
261 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
262
263 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
264 array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
265
266 wfProfileOut( $fname.'-globals' );
267 wfProfileIn( $fname.'-User' );
268
269 # Skin setup functions
270 # Entries can be added to this variable during the inclusion
271 # of the extension file. Skins can then perform any necessary initialisation.
272 #
273 foreach ( $wgSkinExtensionFunctions as $func ) {
274 call_user_func( $func );
275 }
276
277 if( !is_object( $wgAuth ) ) {
278 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
279 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
280 }
281
282 wfProfileOut( $fname.'-User' );
283
284 wfProfileIn( $fname.'-misc2' );
285
286 $wgDeferredUpdateList = array();
287 $wgPostCommitUpdateList = array();
288
289 if ( $wgAjaxWatch ) $wgAjaxExportList[] = 'wfAjaxWatch';
290 if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'UploadForm::ajaxGetExistsWarning';
291 if( $wgAjaxLicensePreview )
292 $wgAjaxExportList[] = 'UploadForm::ajaxGetLicensePreview';
293
294 # Placeholders in case of DB error
295 $wgTitle = null;
296 $wgArticle = null;
297
298 wfProfileOut( $fname.'-misc2' );
299 wfProfileIn( $fname.'-extensions' );
300
301 # Extension setup functions for extensions other than skins
302 # Entries should be added to this variable during the inclusion
303 # of the extension file. This allows the extension to perform
304 # any necessary initialisation in the fully initialised environment
305 foreach ( $wgExtensionFunctions as $func ) {
306 $profName = $fname.'-extensions-'.strval( $func );
307 wfProfileIn( $profName );
308 call_user_func( $func );
309 wfProfileOut( $profName );
310 }
311
312 // For compatibility
313 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
314 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
315 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
316 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
317
318
319 wfDebug( "Fully initialised\n" );
320 $wgFullyInitialised = true;
321 wfProfileOut( $fname.'-extensions' );
322 wfProfileOut( $fname );