(missing .= part) r58512#c4384
[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 exit( 1 );
12 }
13
14 # The main wiki script and things like database
15 # conversion and maintenance scripts all share a
16 # common setup of including lots of classes and
17 # setting up a few globals.
18 #
19
20 $fname = 'Setup.php';
21 wfProfileIn( $fname );
22
23 // Check to see if we are at the file scope
24 if ( !isset( $wgVersion ) ) {
25 echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
26 die( 1 );
27 }
28
29 // Set various default paths sensibly...
30 if( $wgScript === false ) $wgScript = "$wgScriptPath/index$wgScriptExtension";
31 if( $wgRedirectScript === false ) $wgRedirectScript = "$wgScriptPath/redirect$wgScriptExtension";
32
33 if( $wgArticlePath === false ) {
34 if( $wgUsePathInfo ) {
35 $wgArticlePath = "$wgScript/$1";
36 } else {
37 $wgArticlePath = "$wgScript?title=$1";
38 }
39 }
40
41 if( $wgStylePath === false ) $wgStylePath = "$wgScriptPath/skins";
42 if( $wgStyleDirectory === false) $wgStyleDirectory = "$IP/skins";
43
44 if( $wgLogo === false ) $wgLogo = "$wgStylePath/common/images/wiki.png";
45
46 if( $wgUploadPath === false ) $wgUploadPath = "$wgScriptPath/images";
47 if( $wgUploadDirectory === false ) $wgUploadDirectory = "$IP/images";
48
49 if( $wgMathPath === false ) $wgMathPath = "{$wgUploadPath}/math";
50 if( $wgMathDirectory === false ) $wgMathDirectory = "{$wgUploadDirectory}/math";
51 if( $wgTmpDirectory === false ) $wgTmpDirectory = "{$wgUploadDirectory}/tmp";
52
53 if( $wgReadOnlyFile === false ) $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
54 if( $wgFileCacheDirectory === false ) $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
55
56 if ( empty( $wgFileStore['deleted']['directory'] ) ) {
57 $wgFileStore['deleted']['directory'] = "{$wgUploadDirectory}/deleted";
58 }
59
60 /**
61 * Unconditional protection for NS_MEDIAWIKI since otherwise it's too easy for a
62 * sysadmin to set $wgNamespaceProtection incorrectly and leave the wiki insecure.
63 *
64 * Note that this is the definition of editinterface and it can be granted to
65 * all users if desired.
66 */
67 $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
68
69 /**
70 * The canonical names of namespaces 6 and 7 are, as of v1.14, "File"
71 * and "File_talk". The old names "Image" and "Image_talk" are
72 * retained as aliases for backwards compatibility.
73 */
74 $wgNamespaceAliases['Image'] = NS_FILE;
75 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
76
77 /**
78 * Initialise $wgLocalFileRepo from backwards-compatible settings
79 */
80 if ( !$wgLocalFileRepo ) {
81 $wgLocalFileRepo = array(
82 'class' => 'LocalRepo',
83 'name' => 'local',
84 'directory' => $wgUploadDirectory,
85 'url' => $wgUploadBaseUrl ? $wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
86 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
87 'thumbScriptUrl' => $wgThumbnailScriptPath,
88 'transformVia404' => !$wgGenerateThumbnailOnParse,
89 'deletedDir' => $wgFileStore['deleted']['directory'],
90 'deletedHashLevels' => $wgFileStore['deleted']['hash']
91 );
92 }
93 /**
94 * Initialise shared repo from backwards-compatible settings
95 */
96 if ( $wgUseSharedUploads ) {
97 if ( $wgSharedUploadDBname ) {
98 $wgForeignFileRepos[] = array(
99 'class' => 'ForeignDBRepo',
100 'name' => 'shared',
101 'directory' => $wgSharedUploadDirectory,
102 'url' => $wgSharedUploadPath,
103 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
104 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
105 'transformVia404' => !$wgGenerateThumbnailOnParse,
106 'dbType' => $wgDBtype,
107 'dbServer' => $wgDBserver,
108 'dbUser' => $wgDBuser,
109 'dbPassword' => $wgDBpassword,
110 'dbName' => $wgSharedUploadDBname,
111 'dbFlags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT,
112 'tablePrefix' => $wgSharedUploadDBprefix,
113 'hasSharedCache' => $wgCacheSharedUploads,
114 'descBaseUrl' => $wgRepositoryBaseUrl,
115 'fetchDescription' => $wgFetchCommonsDescriptions,
116 );
117 } else {
118 $wgForeignFileRepos[] = array(
119 'class' => 'FSRepo',
120 'name' => 'shared',
121 'directory' => $wgSharedUploadDirectory,
122 'url' => $wgSharedUploadPath,
123 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
124 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
125 'transformVia404' => !$wgGenerateThumbnailOnParse,
126 'descBaseUrl' => $wgRepositoryBaseUrl,
127 'fetchDescription' => $wgFetchCommonsDescriptions,
128 );
129 }
130 }
131 if( $wgUseInstantCommons ) {
132 $wgForeignFileRepos[] = array(
133 'class' => 'ForeignAPIRepo',
134 'name' => 'wikimediacommons',
135 'apibase' => 'http://commons.wikimedia.org/w/api.php',
136 'fetchDescription' => true,
137 'descriptionCacheExpiry' => 43200,
138 'apiThumbCacheExpiry' => 86400,
139 );
140 }
141
142
143 if ( !class_exists( 'AutoLoader' ) ) {
144 require_once( "$IP/includes/AutoLoader.php" );
145 }
146
147 wfProfileIn( $fname.'-exception' );
148 require_once( "$IP/includes/Exception.php" );
149 wfInstallExceptionHandler();
150 wfProfileOut( $fname.'-exception' );
151
152 wfProfileIn( $fname.'-includes' );
153 require_once( "$IP/includes/GlobalFunctions.php" );
154 require_once( "$IP/includes/Hooks.php" );
155 require_once( "$IP/includes/Namespace.php" );
156 require_once( "$IP/includes/ProxyTools.php" );
157 require_once( "$IP/includes/ObjectCache.php" );
158 require_once( "$IP/includes/ImageFunctions.php" );
159 require_once( "$IP/includes/StubObject.php" );
160 wfProfileOut( $fname.'-includes' );
161 wfProfileIn( $fname.'-misc1' );
162 # Raise the memory limit if it's too low
163 wfMemoryLimit();
164
165 $wgIP = false; # Load on demand
166 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
167 $wgRequest = new WebRequest;
168
169 # Useful debug output
170 if ( $wgCommandLineMode ) {
171 wfDebug( "\n\nStart command line script $self\n" );
172 } elseif ( function_exists( 'getallheaders' ) ) {
173 wfDebug( "\n\nStart request\n" );
174 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
175 $headers = getallheaders();
176 foreach ($headers as $name => $value) {
177 wfDebug( "$name: $value\n" );
178 }
179 wfDebug( "\n" );
180 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
181 wfDebug( "\n\nStart request\n" );
182 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
183 foreach ( $_SERVER as $name => $value ) {
184 if ( substr( $name, 0, 5 ) == 'HTTP_' ) {
185 $name = substr( $name, 5 );
186 wfDebug( "$name: $value\n" );
187 }
188 }
189 wfDebug( "\n" );
190 }
191
192 if( $wgRCFilterByAge ) {
193 ## Trim down $wgRCLinkDays so that it only lists links which are valid
194 ## as determined by $wgRCMaxAge.
195 ## Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
196 sort($wgRCLinkDays);
197 for( $i = 0; $i < count($wgRCLinkDays); $i++ ) {
198 if( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
199 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i+1, false );
200 break;
201 }
202 }
203 }
204
205 if ( $wgSkipSkin ) {
206 $wgSkipSkins[] = $wgSkipSkin;
207 }
208
209 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
210
211 if($wgMetaNamespace === FALSE) {
212 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
213 }
214
215 # These are now the same, always
216 # To determine the user language, use $wgLang->getCode()
217 $wgContLanguageCode = $wgLanguageCode;
218
219 # Easy to forget to falsify $wgShowIPinHeader for static caches.
220 # If file cache or squid cache is on, just disable this (DWIMD).
221 if( $wgUseFileCache || $wgUseSquid ) $wgShowIPinHeader = false;
222
223 # $wgAllowRealName and $wgAllowUserSkin were removed in 1.16
224 # in favor of $wgHiddenPrefs, handle b/c here
225 if( !$wgAllowRealName ) {
226 $wgHiddenPrefs[] = 'realname';
227 }
228
229 if( !$wgAllowUserSkin ) {
230 $wgHiddenPrefs[] = 'skin';
231 }
232
233 wfProfileOut( $fname.'-misc1' );
234 wfProfileIn( $fname.'-memcached' );
235
236 $wgMemc =& wfGetMainCache();
237 $messageMemc =& wfGetMessageCacheStorage();
238 $parserMemc =& wfGetParserCacheStorage();
239
240 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
241 "\nMessage cache: " . get_class( $messageMemc ) .
242 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
243
244 wfProfileOut( $fname.'-memcached' );
245
246 ## Most of the config is out, some might want to run hooks here.
247 wfRunHooks( 'SetupAfterCache' );
248
249 wfProfileIn( $fname.'-SetupSession' );
250
251 # Set default shared prefix
252 if( $wgSharedPrefix === false ) $wgSharedPrefix = $wgDBprefix;
253
254 if( !$wgCookiePrefix ) {
255 if ( $wgSharedDB && $wgSharedPrefix && in_array('user',$wgSharedTables) ) {
256 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
257 } elseif ( $wgSharedDB && in_array('user',$wgSharedTables) ) {
258 $wgCookiePrefix = $wgSharedDB;
259 } elseif ( $wgDBprefix ) {
260 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
261 } else {
262 $wgCookiePrefix = $wgDBname;
263 }
264 }
265 $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
266
267 # If session.auto_start is there, we can't touch session name
268 #
269 if( !wfIniGetBool( 'session.auto_start' ) )
270 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
271
272 if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
273 wfIncrStats( 'request_with_session' );
274 wfSetupSession();
275 $wgSessionStarted = true;
276 } else {
277 wfIncrStats( 'request_without_session' );
278 $wgSessionStarted = false;
279 }
280
281 wfProfileOut( $fname.'-SetupSession' );
282 wfProfileIn( $fname.'-globals' );
283
284 $wgContLang = new StubContLang;
285
286 // Now that variant lists may be available...
287 $wgRequest->interpolateTitle();
288
289 $wgUser = new StubUser;
290 $wgLang = new StubUserLang;
291 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
292 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
293
294 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
295 array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
296
297 wfProfileOut( $fname.'-globals' );
298 wfProfileIn( $fname.'-User' );
299
300 # Skin setup functions
301 # Entries can be added to this variable during the inclusion
302 # of the extension file. Skins can then perform any necessary initialisation.
303 #
304 foreach ( $wgSkinExtensionFunctions as $func ) {
305 call_user_func( $func );
306 }
307
308 if( !is_object( $wgAuth ) ) {
309 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
310 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
311 }
312
313 wfProfileOut( $fname.'-User' );
314
315 wfProfileIn( $fname.'-misc2' );
316
317 $wgDeferredUpdateList = array();
318 $wgPostCommitUpdateList = array();
319
320 if ( $wgAjaxWatch ) $wgAjaxExportList[] = 'wfAjaxWatch';
321 if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'SpecialUpload::ajaxGetExistsWarning';
322 if( $wgAjaxLicensePreview )
323 $wgAjaxExportList[] = 'SpecialUpload::ajaxGetLicensePreview';
324
325 # Placeholders in case of DB error
326 $wgTitle = null;
327 $wgArticle = null;
328
329 wfProfileOut( $fname.'-misc2' );
330 wfProfileIn( $fname.'-extensions' );
331
332 # load the $wgExtensionMessagesFiles for the script loader
333 # this can't be done in a normal extension type way
334 # since the script-loader is an entry point
335 #
336 $wgExtensionMessagesFiles['mwEmbed'] = "{$IP}/js2/mwEmbed/php/languages/mwEmbed.i18n.php";
337
338 # Include the js2/mwEmbed autoLoadClasses if js2 is enabled
339 if( $wgEnableJS2system ){
340 require_once("$IP/js2/mwEmbed/php/jsAutoloadLocalClasses.php");
341 }
342
343 # Extension setup functions for extensions other than skins
344 # Entries should be added to this variable during the inclusion
345 # of the extension file. This allows the extension to perform
346 # any necessary initialisation in the fully initialised environment
347 foreach ( $wgExtensionFunctions as $func ) {
348 # Allow closures in PHP 5.3+
349 if ( is_object( $func ) && $func instanceof Closure ) {
350 $profName = $fname.'-extensions-closure';
351 } elseif( is_array( $func ) ) {
352 if ( is_object( $func[0] ) )
353 $profName = $fname.'-extensions-'.get_class( $func[0] ).'::'.$func[1];
354 else
355 $profName = $fname.'-extensions-'.implode( '::', $func );
356 } else {
357 $profName = $fname.'-extensions-'.strval( $func );
358 }
359
360 wfProfileIn( $profName );
361 call_user_func( $func );
362 wfProfileOut( $profName );
363 }
364
365 // For compatibility
366 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
367 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
368 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
369 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
370
371 if( !empty($wgNewUserLog) ) {
372 # Add a new log type
373 $wgLogTypes[] = 'newusers';
374 $wgLogNames['newusers'] = 'newuserlogpage';
375 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
376 $wgLogActions['newusers/newusers'] = 'newuserlogentry'; // For compatibility with older log entries
377 $wgLogActions['newusers/create'] = 'newuserlog-create-entry';
378 $wgLogActions['newusers/create2'] = 'newuserlog-create2-entry';
379 $wgLogActions['newusers/autocreate'] = 'newuserlog-autocreate-entry';
380 }
381
382 wfDebug( "Fully initialised\n" );
383 $wgFullyInitialised = true;
384 wfProfileOut( $fname.'-extensions' );
385 wfProfileOut( $fname );