c73620767a8bd30b9f216d3e512b7ed1288d98c7
[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 * The canonical names of namespaces 6 and 7 are, as of v1.14, "File"
72 * and "File_talk". The old names "Image" and "Image_talk" are
73 * retained as aliases for backwards compatibility.
74 */
75 $wgNamespaceAliases['Image'] = NS_FILE;
76 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
77
78 /**
79 * Initialise $wgLocalFileRepo from backwards-compatible settings
80 */
81 if ( !$wgLocalFileRepo ) {
82 $wgLocalFileRepo = array(
83 'class' => 'LocalRepo',
84 'name' => 'local',
85 'directory' => $wgUploadDirectory,
86 'url' => $wgUploadBaseUrl ? $wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
87 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
88 'thumbScriptUrl' => $wgThumbnailScriptPath,
89 'transformVia404' => !$wgGenerateThumbnailOnParse,
90 'initialCapital' => $wgCapitalLinks,
91 'deletedDir' => $wgFileStore['deleted']['directory'],
92 'deletedHashLevels' => $wgFileStore['deleted']['hash']
93 );
94 }
95 /**
96 * Initialise shared repo from backwards-compatible settings
97 */
98 if ( $wgUseSharedUploads ) {
99 if ( $wgSharedUploadDBname ) {
100 $wgForeignFileRepos[] = array(
101 'class' => 'ForeignDBRepo',
102 'name' => 'shared',
103 'directory' => $wgSharedUploadDirectory,
104 'url' => $wgSharedUploadPath,
105 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
106 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
107 'transformVia404' => !$wgGenerateThumbnailOnParse,
108 'dbType' => $wgDBtype,
109 'dbServer' => $wgDBserver,
110 'dbUser' => $wgDBuser,
111 'dbPassword' => $wgDBpassword,
112 'dbName' => $wgSharedUploadDBname,
113 'dbFlags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT,
114 'tablePrefix' => $wgSharedUploadDBprefix,
115 'hasSharedCache' => $wgCacheSharedUploads,
116 'descBaseUrl' => $wgRepositoryBaseUrl,
117 'fetchDescription' => $wgFetchCommonsDescriptions,
118 );
119 } else {
120 $wgForeignFileRepos[] = array(
121 'class' => 'FSRepo',
122 'name' => 'shared',
123 'directory' => $wgSharedUploadDirectory,
124 'url' => $wgSharedUploadPath,
125 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
126 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
127 'transformVia404' => !$wgGenerateThumbnailOnParse,
128 'descBaseUrl' => $wgRepositoryBaseUrl,
129 'fetchDescription' => $wgFetchCommonsDescriptions,
130 );
131 }
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 # Raise the memory limit if it's too low
153 wfMemoryLimit();
154
155 $wgIP = false; # Load on demand
156 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
157 $wgRequest = new WebRequest;
158
159 # Useful debug output
160 if ( $wgCommandLineMode ) {
161 wfDebug( "\n\nStart command line script $self\n" );
162 } elseif ( function_exists( 'getallheaders' ) ) {
163 wfDebug( "\n\nStart request\n" );
164 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
165 $headers = getallheaders();
166 foreach ($headers as $name => $value) {
167 wfDebug( "$name: $value\n" );
168 }
169 wfDebug( "\n" );
170 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
171 wfDebug( "\n\nStart request\n" );
172 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
173 foreach ( $_SERVER as $name => $value ) {
174 if ( substr( $name, 0, 5 ) == 'HTTP_' ) {
175 $name = substr( $name, 5 );
176 wfDebug( "$name: $value\n" );
177 }
178 }
179 wfDebug( "\n" );
180 }
181
182 if( $wgRCFilterByAge ) {
183 ## Trim down $wgRCLinkDays so that it only lists links which are valid
184 ## as determined by $wgRCMaxAge.
185 ## Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
186 sort($wgRCLinkDays);
187 for( $i = 0; $i < count($wgRCLinkDays); $i++ ) {
188 if( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
189 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i+1, false );
190 break;
191 }
192 }
193 }
194
195 if ( $wgSkipSkin ) {
196 $wgSkipSkins[] = $wgSkipSkin;
197 }
198
199 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
200
201 if($wgMetaNamespace === FALSE) {
202 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
203 }
204
205 # These are now the same, always
206 # To determine the user language, use $wgLang->getCode()
207 $wgContLanguageCode = $wgLanguageCode;
208
209 # Easy to forget to falsify $wgShowIPinHeader for static caches.
210 # If file cache or squid cache is on, just disable this (DWIMD).
211 if( $wgUseFileCache || $wgUseSquid ) $wgShowIPinHeader = false;
212
213 # $wgAllowRealName and $wgAllowUserSkin were removed in 1.16
214 # in favor of $wgHiddenPrefs, handle b/c here
215 if( !$wgAllowRealName ) {
216 $wgHiddenPrefs[] = 'realname';
217 }
218
219 if( !$wgAllowUserSkin ) {
220 $wgHiddenPrefs[] = 'skin';
221 }
222
223 wfProfileOut( $fname.'-misc1' );
224 wfProfileIn( $fname.'-memcached' );
225
226 $wgMemc =& wfGetMainCache();
227 $messageMemc =& wfGetMessageCacheStorage();
228 $parserMemc =& wfGetParserCacheStorage();
229
230 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
231 "\nMessage cache: " . get_class( $messageMemc ) .
232 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
233
234 wfProfileOut( $fname.'-memcached' );
235
236 ## Most of the config is out, some might want to run hooks here.
237 wfRunHooks( 'SetupAfterCache' );
238
239 wfProfileIn( $fname.'-SetupSession' );
240
241 # Set default shared prefix
242 if( $wgSharedPrefix === false ) $wgSharedPrefix = $wgDBprefix;
243
244 if( !$wgCookiePrefix ) {
245 if ( $wgSharedDB && $wgSharedPrefix && in_array('user',$wgSharedTables) ) {
246 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
247 } elseif ( $wgSharedDB && in_array('user',$wgSharedTables) ) {
248 $wgCookiePrefix = $wgSharedDB;
249 } elseif ( $wgDBprefix ) {
250 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
251 } else {
252 $wgCookiePrefix = $wgDBname;
253 }
254 }
255 $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
256
257 # If session.auto_start is there, we can't touch session name
258 #
259 if( !wfIniGetBool( 'session.auto_start' ) )
260 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
261
262 if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
263 wfIncrStats( 'request_with_session' );
264 wfSetupSession();
265 $wgSessionStarted = true;
266 } else {
267 wfIncrStats( 'request_without_session' );
268 $wgSessionStarted = false;
269 }
270
271 wfProfileOut( $fname.'-SetupSession' );
272 wfProfileIn( $fname.'-globals' );
273
274 $wgContLang = new StubContLang;
275
276 // Now that variant lists may be available...
277 $wgRequest->interpolateTitle();
278
279 $wgUser = new StubUser;
280 $wgLang = new StubUserLang;
281 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
282 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
283
284 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
285 array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
286
287 wfProfileOut( $fname.'-globals' );
288 wfProfileIn( $fname.'-User' );
289
290 # Skin setup functions
291 # Entries can be added to this variable during the inclusion
292 # of the extension file. Skins can then perform any necessary initialisation.
293 #
294 foreach ( $wgSkinExtensionFunctions as $func ) {
295 call_user_func( $func );
296 }
297
298 if( !is_object( $wgAuth ) ) {
299 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
300 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
301 }
302
303 wfProfileOut( $fname.'-User' );
304
305 wfProfileIn( $fname.'-misc2' );
306
307 $wgDeferredUpdateList = array();
308 $wgPostCommitUpdateList = array();
309
310 if ( $wgAjaxWatch ) $wgAjaxExportList[] = 'wfAjaxWatch';
311 if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'UploadForm::ajaxGetExistsWarning';
312 if( $wgAjaxLicensePreview )
313 $wgAjaxExportList[] = 'UploadForm::ajaxGetLicensePreview';
314
315 # Placeholders in case of DB error
316 $wgTitle = null;
317 $wgArticle = null;
318
319 wfProfileOut( $fname.'-misc2' );
320 wfProfileIn( $fname.'-extensions' );
321
322 # load the $wgExtensionMessagesFiles for the script loader
323 # this can't be done in a normal extension type way
324 # since the script-loader is an entry point
325 #
326 $wgExtensionMessagesFiles['mwEmbed'] = "{$IP}/js2/mwEmbed/php/languages/mwEmbed.i18n.php";
327
328 # Include the js2/mwEmbed autoLoadClasses if js2 is enabled
329 if( $wgEnableJS2system ){
330 require_once("$IP/js2/mwEmbed/php/jsAutoloadLocalClasses.php");
331 }
332
333 # Extension setup functions for extensions other than skins
334 # Entries should be added to this variable during the inclusion
335 # of the extension file. This allows the extension to perform
336 # any necessary initialisation in the fully initialised environment
337 foreach ( $wgExtensionFunctions as $func ) {
338 # Allow closures in PHP 5.3+
339 if ( is_object( $func ) && $func instanceof Closure ) {
340 $profName = $fname.'-extensions-closure';
341 } elseif( is_array( $func ) ) {
342 if ( is_object( $func[0] ) )
343 $profName = $fname.'-extensions-'.get_class( $func[0] ).'::'.$func[1];
344 else
345 $profName = $fname.'-extensions-'.implode( '::', $func );
346 } else {
347 $profName = $fname.'-extensions-'.strval( $func );
348 }
349
350 wfProfileIn( $profName );
351 call_user_func( $func );
352 wfProfileOut( $profName );
353 }
354
355 // For compatibility
356 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
357 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
358 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
359 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
360
361 if( !empty($wgNewUserLog) ) {
362 # Add a new log type
363 $wgLogTypes[] = 'newusers';
364 $wgLogNames['newusers'] = 'newuserlogpage';
365 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
366 $wgLogActions['newusers/newusers'] = 'newuserlogentry'; // For compatibility with older log entries
367 $wgLogActions['newusers/create'] = 'newuserlog-create-entry';
368 $wgLogActions['newusers/create2'] = 'newuserlog-create2-entry';
369 $wgLogActions['newusers/autocreate'] = 'newuserlog-autocreate-entry';
370 }
371
372 wfDebug( "Fully initialised\n" );
373 $wgFullyInitialised = true;
374 wfProfileOut( $fname.'-extensions' );
375 wfProfileOut( $fname );