Workaround for PHP 5.2.6 escapeshellcmd()/escapeshellarg() bug
[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 if ( version_compare( PHP_VERSION, '5.2.6', '>=' ) ) {
122 putenv( 'LC_CTYPE=en_US.UTF-8' );
123 setlocale( LC_CTYPE, 'en_US.UTF-8' );
124 }
125
126 if ( !class_exists( 'AutoLoader' ) ) {
127 require_once( "$IP/includes/AutoLoader.php" );
128 }
129
130 wfProfileIn( $fname.'-exception' );
131 require_once( "$IP/includes/Exception.php" );
132 wfInstallExceptionHandler();
133 wfProfileOut( $fname.'-exception' );
134
135 wfProfileIn( $fname.'-includes' );
136 require_once( "$IP/includes/GlobalFunctions.php" );
137 require_once( "$IP/includes/Hooks.php" );
138 require_once( "$IP/includes/Namespace.php" );
139 require_once( "$IP/includes/ProxyTools.php" );
140 require_once( "$IP/includes/ObjectCache.php" );
141 require_once( "$IP/includes/ImageFunctions.php" );
142 require_once( "$IP/includes/StubObject.php" );
143 wfProfileOut( $fname.'-includes' );
144 wfProfileIn( $fname.'-misc1' );
145
146
147 $wgIP = false; # Load on demand
148 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
149 $wgRequest = new WebRequest;
150 if ( function_exists( 'posix_uname' ) ) {
151 $wguname = posix_uname();
152 $wgNodeName = $wguname['nodename'];
153 } else {
154 $wgNodeName = '';
155 }
156
157 # Useful debug output
158 if ( $wgCommandLineMode ) {
159 wfDebug( "\n\nStart command line script $self\n" );
160 } elseif ( function_exists( 'getallheaders' ) ) {
161 wfDebug( "\n\nStart request\n" );
162 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
163 $headers = getallheaders();
164 foreach ($headers as $name => $value) {
165 wfDebug( "$name: $value\n" );
166 }
167 wfDebug( "\n" );
168 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
169 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
170 }
171
172 if( $wgRCFilterByAge ) {
173 ## Trim down $wgRCLinkDays so that it only lists links which are valid
174 ## as determined by $wgRCMaxAge.
175 ## Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
176 sort($wgRCLinkDays);
177 for( $i = 0; $i < count($wgRCLinkDays); $i++ ) {
178 if( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
179 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i+1, false );
180 break;
181 }
182 }
183 }
184
185 if ( $wgSkipSkin ) {
186 $wgSkipSkins[] = $wgSkipSkin;
187 }
188
189 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
190
191 if($wgMetaNamespace === FALSE) {
192 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
193 }
194
195 # These are now the same, always
196 # To determine the user language, use $wgLang->getCode()
197 $wgContLanguageCode = $wgLanguageCode;
198
199 wfProfileOut( $fname.'-misc1' );
200 wfProfileIn( $fname.'-memcached' );
201
202 $wgMemc =& wfGetMainCache();
203 $messageMemc =& wfGetMessageCacheStorage();
204 $parserMemc =& wfGetParserCacheStorage();
205
206 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
207 "\nMessage cache: " . get_class( $messageMemc ) .
208 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
209
210 wfProfileOut( $fname.'-memcached' );
211 wfProfileIn( $fname.'-SetupSession' );
212
213 # Set default shared prefix
214 if( $wgSharedPrefix === false ) $wgSharedPrefix = $wgDBprefix;
215
216 if( !$wgCookiePrefix ) {
217 if ( in_array('user', $wgSharedTables) && $wgSharedDB && $wgSharedPrefix ) {
218 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
219 } elseif ( in_array('user', $wgSharedTables) && $wgSharedDB ) {
220 $wgCookiePrefix = $wgSharedDB;
221 } elseif ( $wgDBprefix ) {
222 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
223 } else {
224 $wgCookiePrefix = $wgDBname;
225 }
226 }
227 $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
228
229 # If session.auto_start is there, we can't touch session name
230 #
231 if( !wfIniGetBool( 'session.auto_start' ) )
232 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
233
234 if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
235 wfIncrStats( 'request_with_session' );
236 wfSetupSession();
237 $wgSessionStarted = true;
238 } else {
239 wfIncrStats( 'request_without_session' );
240 $wgSessionStarted = false;
241 }
242
243 wfProfileOut( $fname.'-SetupSession' );
244 wfProfileIn( $fname.'-globals' );
245
246 $wgContLang = new StubContLang;
247
248 // Now that variant lists may be available...
249 $wgRequest->interpolateTitle();
250
251 $wgUser = new StubUser;
252 $wgLang = new StubUserLang;
253 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
254 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
255
256 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
257 array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
258
259 wfProfileOut( $fname.'-globals' );
260 wfProfileIn( $fname.'-User' );
261
262 # Skin setup functions
263 # Entries can be added to this variable during the inclusion
264 # of the extension file. Skins can then perform any necessary initialisation.
265 #
266 foreach ( $wgSkinExtensionFunctions as $func ) {
267 call_user_func( $func );
268 }
269
270 if( !is_object( $wgAuth ) ) {
271 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
272 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
273 }
274
275 wfProfileOut( $fname.'-User' );
276
277 wfProfileIn( $fname.'-misc2' );
278
279 $wgDeferredUpdateList = array();
280 $wgPostCommitUpdateList = array();
281
282 if ( $wgAjaxSearch ) $wgAjaxExportList[] = 'wfSajaxSearch';
283 if ( $wgAjaxWatch ) $wgAjaxExportList[] = 'wfAjaxWatch';
284 if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'UploadForm::ajaxGetExistsWarning';
285 if( $wgAjaxLicensePreview )
286 $wgAjaxExportList[] = 'UploadForm::ajaxGetLicensePreview';
287
288 # Placeholders in case of DB error
289 $wgTitle = null;
290 $wgArticle = null;
291
292 wfProfileOut( $fname.'-misc2' );
293 wfProfileIn( $fname.'-extensions' );
294
295 # Extension setup functions for extensions other than skins
296 # Entries should be added to this variable during the inclusion
297 # of the extension file. This allows the extension to perform
298 # any necessary initialisation in the fully initialised environment
299 foreach ( $wgExtensionFunctions as $func ) {
300 $profName = $fname.'-extensions-'.strval( $func );
301 wfProfileIn( $profName );
302 call_user_func( $func );
303 wfProfileOut( $profName );
304 }
305
306 // For compatibility
307 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
308 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
309 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
310 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
311
312
313 wfDebug( "Fully initialised\n" );
314 $wgFullyInitialised = true;
315 wfProfileOut( $fname.'-extensions' );
316 wfProfileOut( $fname );