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