(bug 16084) Default memory limit should be increased
[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 global $wgMemoryLimit;
154 $memlimit = ini_get( "memory_limit" );
155 if( !( empty( $memlimit ) || $memlimit == -1 ) ) {
156 if( wfParseMemoryLimit( $memlimit ) < wfParseMemoryLimit( $wgMemoryLimit ) ) {
157 wfDebug( "\n\nRaise PHP's memory limit from $memlimit to $wgMemoryLimit\n" );
158 ini_set( "memory_limit", $wgMemoryLimit );
159 }
160 }
161
162 $wgIP = false; # Load on demand
163 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
164 $wgRequest = new WebRequest;
165
166 # Useful debug output
167 if ( $wgCommandLineMode ) {
168 wfDebug( "\n\nStart command line script $self\n" );
169 } elseif ( function_exists( 'getallheaders' ) ) {
170 wfDebug( "\n\nStart request\n" );
171 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
172 $headers = getallheaders();
173 foreach ($headers as $name => $value) {
174 wfDebug( "$name: $value\n" );
175 }
176 wfDebug( "\n" );
177 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
178 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
179 }
180
181 if( $wgRCFilterByAge ) {
182 ## Trim down $wgRCLinkDays so that it only lists links which are valid
183 ## as determined by $wgRCMaxAge.
184 ## Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
185 sort($wgRCLinkDays);
186 for( $i = 0; $i < count($wgRCLinkDays); $i++ ) {
187 if( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
188 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i+1, false );
189 break;
190 }
191 }
192 }
193
194 if ( $wgSkipSkin ) {
195 $wgSkipSkins[] = $wgSkipSkin;
196 }
197
198 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
199
200 if($wgMetaNamespace === FALSE) {
201 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
202 }
203
204 # These are now the same, always
205 # To determine the user language, use $wgLang->getCode()
206 $wgContLanguageCode = $wgLanguageCode;
207
208 # Easy to forget to falsify $wgShowIPinHeader for static caches.
209 # If file cache or squid cache is on, just disable this (DWIMD).
210 if( $wgUseFileCache || $wgUseSquid ) $wgShowIPinHeader = false;
211
212 # $wgAllowRealName and $wgAllowUserSkin were removed in 1.16
213 # in favor of $wgHiddenPrefs, handle b/c here
214 if( !$wgAllowRealName ) {
215 $wgHiddenPrefs[] = 'realname';
216 }
217
218 if( !$wgAllowUserSkin ) {
219 $wgHiddenPrefs[] = 'skin';
220 }
221
222 wfProfileOut( $fname.'-misc1' );
223 wfProfileIn( $fname.'-memcached' );
224
225 $wgMemc =& wfGetMainCache();
226 $messageMemc =& wfGetMessageCacheStorage();
227 $parserMemc =& wfGetParserCacheStorage();
228
229 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
230 "\nMessage cache: " . get_class( $messageMemc ) .
231 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
232
233 wfProfileOut( $fname.'-memcached' );
234
235 ## Most of the config is out, some might want to run hooks here.
236 wfRunHooks( 'SetupAfterCache' );
237
238 wfProfileIn( $fname.'-SetupSession' );
239
240 # Set default shared prefix
241 if( $wgSharedPrefix === false ) $wgSharedPrefix = $wgDBprefix;
242
243 if( !$wgCookiePrefix ) {
244 if ( $wgSharedDB && $wgSharedPrefix && in_array('user',$wgSharedTables) ) {
245 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
246 } elseif ( $wgSharedDB && in_array('user',$wgSharedTables) ) {
247 $wgCookiePrefix = $wgSharedDB;
248 } elseif ( $wgDBprefix ) {
249 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
250 } else {
251 $wgCookiePrefix = $wgDBname;
252 }
253 }
254 $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
255
256 # If session.auto_start is there, we can't touch session name
257 #
258 if( !wfIniGetBool( 'session.auto_start' ) )
259 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
260
261 if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
262 wfIncrStats( 'request_with_session' );
263 wfSetupSession();
264 $wgSessionStarted = true;
265 } else {
266 wfIncrStats( 'request_without_session' );
267 $wgSessionStarted = false;
268 }
269
270 wfProfileOut( $fname.'-SetupSession' );
271 wfProfileIn( $fname.'-globals' );
272
273 $wgContLang = new StubContLang;
274
275 // Now that variant lists may be available...
276 $wgRequest->interpolateTitle();
277
278 $wgUser = new StubUser;
279 $wgLang = new StubUserLang;
280 $wgVariant = new StubUserVariant;
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 /*
323 * load the $wgExtensionMessagesFiles for the script loader
324 * this can't be done in a normal extension type way
325 * since the script-loader is an entry point
326 */
327 if( $wgEnableScriptLoader && strpos( wfGetScriptUrl(), "mwScriptLoader.php" ) !== false ){
328 $wgExtensionMessagesFiles['mwEmbed'] = "{$IP}/js2/mwEmbed/php/languages/mwEmbed.i18n.php";
329 }
330
331
332 # Extension setup functions for extensions other than skins
333 # Entries should be added to this variable during the inclusion
334 # of the extension file. This allows the extension to perform
335 # any necessary initialisation in the fully initialised environment
336 foreach ( $wgExtensionFunctions as $func ) {
337 # Allow closures in PHP 5.3+
338 if ( is_object( $func ) && $func instanceof Closure ) {
339 $profName = $fname.'-extensions-closure';
340 } elseif( is_array( $func ) ) {
341 if ( is_object( $func[0] ) )
342 $profName = $fname.'-extensions-'.get_class( $func[0] ).'::'.$func[1];
343 else
344 $profName = $fname.'-extensions-'.implode( '::', $func );
345 } else {
346 $profName = $fname.'-extensions-'.strval( $func );
347 }
348
349 wfProfileIn( $profName );
350 call_user_func( $func );
351 wfProfileOut( $profName );
352 }
353
354 // For compatibility
355 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
356 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
357 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
358 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
359
360 if( !empty($wgNewUserLog) ) {
361 # Add a new log type
362 $wgLogTypes[] = 'newusers';
363 $wgLogNames['newusers'] = 'newuserlogpage';
364 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
365 $wgLogActions['newusers/newusers'] = 'newuserlogentry'; // For compatibility with older log entries
366 $wgLogActions['newusers/create'] = 'newuserlog-create-entry';
367 $wgLogActions['newusers/create2'] = 'newuserlog-create2-entry';
368 $wgLogActions['newusers/autocreate'] = 'newuserlog-autocreate-entry';
369 }
370
371 wfDebug( "Fully initialised\n" );
372 $wgFullyInitialised = true;
373 wfProfileOut( $fname.'-extensions' );
374 wfProfileOut( $fname );