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