Proposed fix for bug 14944, specifically the reports that some servers do not have...
[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 if ( !class_exists( 'AutoLoader' ) ) {
126 require_once( "$IP/includes/AutoLoader.php" );
127 }
128
129 wfProfileIn( $fname.'-exception' );
130 require_once( "$IP/includes/Exception.php" );
131 wfInstallExceptionHandler();
132 wfProfileOut( $fname.'-exception' );
133
134 wfProfileIn( $fname.'-includes' );
135 require_once( "$IP/includes/GlobalFunctions.php" );
136 require_once( "$IP/includes/Hooks.php" );
137 require_once( "$IP/includes/Namespace.php" );
138 require_once( "$IP/includes/ProxyTools.php" );
139 require_once( "$IP/includes/ObjectCache.php" );
140 require_once( "$IP/includes/ImageFunctions.php" );
141 require_once( "$IP/includes/StubObject.php" );
142 wfProfileOut( $fname.'-includes' );
143 wfProfileIn( $fname.'-misc1' );
144
145
146 $wgIP = false; # Load on demand
147 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
148 $wgRequest = new WebRequest;
149 if ( function_exists( 'posix_uname' ) ) {
150 $wguname = posix_uname();
151 $wgNodeName = $wguname['nodename'];
152 } else {
153 $wgNodeName = '';
154 }
155
156 # Useful debug output
157 if ( $wgCommandLineMode ) {
158 wfDebug( "\n\nStart command line script $self\n" );
159 } elseif ( function_exists( 'getallheaders' ) ) {
160 wfDebug( "\n\nStart request\n" );
161 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
162 $headers = getallheaders();
163 foreach ($headers as $name => $value) {
164 wfDebug( "$name: $value\n" );
165 }
166 wfDebug( "\n" );
167 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
168 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
169 }
170
171 if( $wgRCFilterByAge ) {
172 ## Trim down $wgRCLinkDays so that it only lists links which are valid
173 ## as determined by $wgRCMaxAge.
174 ## Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
175 sort($wgRCLinkDays);
176 for( $i = 0; $i < count($wgRCLinkDays); $i++ ) {
177 if( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
178 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i+1, false );
179 break;
180 }
181 }
182 }
183
184 if ( $wgSkipSkin ) {
185 $wgSkipSkins[] = $wgSkipSkin;
186 }
187
188 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
189
190 if($wgMetaNamespace === FALSE) {
191 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
192 }
193
194 # These are now the same, always
195 # To determine the user language, use $wgLang->getCode()
196 $wgContLanguageCode = $wgLanguageCode;
197
198 wfProfileOut( $fname.'-misc1' );
199 wfProfileIn( $fname.'-memcached' );
200
201 $wgMemc =& wfGetMainCache();
202 $messageMemc =& wfGetMessageCacheStorage();
203 $parserMemc =& wfGetParserCacheStorage();
204
205 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
206 "\nMessage cache: " . get_class( $messageMemc ) .
207 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
208
209 wfProfileOut( $fname.'-memcached' );
210 wfProfileIn( $fname.'-SetupSession' );
211
212 # Set default shared prefix
213 if( $wgSharedPrefix === false ) $wgSharedPrefix = $wgDBprefix;
214
215 if( !$wgCookiePrefix ) {
216 if ( in_array('user', $wgSharedTables) && $wgSharedDB && $wgSharedPrefix ) {
217 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
218 } elseif ( in_array('user', $wgSharedTables) && $wgSharedDB ) {
219 $wgCookiePrefix = $wgSharedDB;
220 } elseif ( $wgDBprefix ) {
221 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
222 } else {
223 $wgCookiePrefix = $wgDBname;
224 }
225 }
226 $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
227
228 # If session.auto_start is there, we can't touch session name
229 #
230 if( !wfIniGetBool( 'session.auto_start' ) )
231 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
232
233 if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
234 wfIncrStats( 'request_with_session' );
235 wfSetupSession();
236 $wgSessionStarted = true;
237 } else {
238 wfIncrStats( 'request_without_session' );
239 $wgSessionStarted = false;
240 }
241
242 wfProfileOut( $fname.'-SetupSession' );
243 wfProfileIn( $fname.'-globals' );
244
245 $wgContLang = new StubContLang;
246
247 // Now that variant lists may be available...
248 $wgRequest->interpolateTitle();
249
250 $wgUser = new StubUser;
251 $wgLang = new StubUserLang;
252 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
253 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
254
255 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
256 array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
257
258 wfProfileOut( $fname.'-globals' );
259 wfProfileIn( $fname.'-User' );
260
261 # Skin setup functions
262 # Entries can be added to this variable during the inclusion
263 # of the extension file. Skins can then perform any necessary initialisation.
264 #
265 foreach ( $wgSkinExtensionFunctions as $func ) {
266 call_user_func( $func );
267 }
268
269 if( !is_object( $wgAuth ) ) {
270 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
271 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
272 }
273
274 wfProfileOut( $fname.'-User' );
275
276 wfProfileIn( $fname.'-misc2' );
277
278 $wgDeferredUpdateList = array();
279 $wgPostCommitUpdateList = array();
280
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 if( !empty($wgNewUserLog) ) {
311 # Add a new log type
312 $wgLogTypes[] = 'newusers';
313 $wgLogNames['newusers'] = 'newuserlogpage';
314 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
315 $wgLogActions['newusers/newusers'] = 'newuserlogentry'; // For compatibility with older log entries
316 $wgLogActions['newusers/create'] = 'newuserlog-create-entry';
317 $wgLogActions['newusers/create2'] = 'newuserlog-create2-entry';
318 $wgLogActions['newusers/autocreate'] = 'newuserlog-autocreate-entry';
319 }
320
321 wfDebug( "Fully initialised\n" );
322 $wgFullyInitialised = true;
323 wfProfileOut( $fname.'-extensions' );
324 wfProfileOut( $fname );