Removed JS2 work (has been moved to the js2-work branch). Has been lightly tested...
[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 'hashLevels' => 2,
137 'fetchDescription' => true,
138 'descriptionCacheExpiry' => 43200,
139 'apiThumbCacheExpiry' => 86400,
140 );
141 }
142
143
144 if ( !class_exists( 'AutoLoader' ) ) {
145 require_once( "$IP/includes/AutoLoader.php" );
146 }
147
148 wfProfileIn( $fname.'-exception' );
149 require_once( "$IP/includes/Exception.php" );
150 wfInstallExceptionHandler();
151 wfProfileOut( $fname.'-exception' );
152
153 wfProfileIn( $fname.'-includes' );
154 require_once( "$IP/includes/GlobalFunctions.php" );
155 require_once( "$IP/includes/Hooks.php" );
156 require_once( "$IP/includes/Namespace.php" );
157 require_once( "$IP/includes/ProxyTools.php" );
158 require_once( "$IP/includes/ObjectCache.php" );
159 require_once( "$IP/includes/ImageFunctions.php" );
160 require_once( "$IP/includes/StubObject.php" );
161 wfProfileOut( $fname.'-includes' );
162 wfProfileIn( $fname.'-misc1' );
163 # Raise the memory limit if it's too low
164 wfMemoryLimit();
165
166 $wgIP = false; # Load on demand
167 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
168 $wgRequest = new WebRequest;
169
170 # Useful debug output
171 if ( $wgCommandLineMode ) {
172 wfDebug( "\n\nStart command line script $self\n" );
173 } elseif ( function_exists( 'getallheaders' ) ) {
174 wfDebug( "\n\nStart request\n" );
175 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
176 $headers = getallheaders();
177 foreach ($headers as $name => $value) {
178 wfDebug( "$name: $value\n" );
179 }
180 wfDebug( "\n" );
181 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
182 wfDebug( "\n\nStart request\n" );
183 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
184 foreach ( $_SERVER as $name => $value ) {
185 if ( substr( $name, 0, 5 ) == 'HTTP_' ) {
186 $name = substr( $name, 5 );
187 wfDebug( "$name: $value\n" );
188 }
189 }
190 wfDebug( "\n" );
191 }
192
193 if( $wgRCFilterByAge ) {
194 ## Trim down $wgRCLinkDays so that it only lists links which are valid
195 ## as determined by $wgRCMaxAge.
196 ## Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
197 sort($wgRCLinkDays);
198 for( $i = 0; $i < count($wgRCLinkDays); $i++ ) {
199 if( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
200 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i+1, false );
201 break;
202 }
203 }
204 }
205
206 if ( $wgSkipSkin ) {
207 $wgSkipSkins[] = $wgSkipSkin;
208 }
209
210 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
211
212 if($wgMetaNamespace === FALSE) {
213 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
214 }
215
216 # These are now the same, always
217 # To determine the user language, use $wgLang->getCode()
218 $wgContLanguageCode = $wgLanguageCode;
219
220 # Easy to forget to falsify $wgShowIPinHeader for static caches.
221 # If file cache or squid cache is on, just disable this (DWIMD).
222 if( $wgUseFileCache || $wgUseSquid ) $wgShowIPinHeader = false;
223
224 # $wgAllowRealName and $wgAllowUserSkin were removed in 1.16
225 # in favor of $wgHiddenPrefs, handle b/c here
226 if( !$wgAllowRealName ) {
227 $wgHiddenPrefs[] = 'realname';
228 }
229
230 if( !$wgAllowUserSkin ) {
231 $wgHiddenPrefs[] = 'skin';
232 }
233
234 if ( !$wgHtml5Version && $wgHtml5 && $wgAllowRdfaAttributes ) {
235 # see http://www.w3.org/TR/rdfa-in-html/#document-conformance
236 if ( $wgMimeType == 'application/xhtml+xml' ) $wgHtml5Version = 'XHTML+RDFa 1.0';
237 else $wgHtml5Version = 'HTML+RDFa 1.0';
238 }
239
240
241 wfProfileOut( $fname.'-misc1' );
242 wfProfileIn( $fname.'-memcached' );
243
244 $wgMemc =& wfGetMainCache();
245 $messageMemc =& wfGetMessageCacheStorage();
246 $parserMemc =& wfGetParserCacheStorage();
247
248 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
249 "\nMessage cache: " . get_class( $messageMemc ) .
250 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
251
252 wfProfileOut( $fname.'-memcached' );
253
254 ## Most of the config is out, some might want to run hooks here.
255 wfRunHooks( 'SetupAfterCache' );
256
257 wfProfileIn( $fname.'-SetupSession' );
258
259 # Set default shared prefix
260 if( $wgSharedPrefix === false ) $wgSharedPrefix = $wgDBprefix;
261
262 if( !$wgCookiePrefix ) {
263 if ( $wgSharedDB && $wgSharedPrefix && in_array('user',$wgSharedTables) ) {
264 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
265 } elseif ( $wgSharedDB && in_array('user',$wgSharedTables) ) {
266 $wgCookiePrefix = $wgSharedDB;
267 } elseif ( $wgDBprefix ) {
268 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
269 } else {
270 $wgCookiePrefix = $wgDBname;
271 }
272 }
273 $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
274
275 # If session.auto_start is there, we can't touch session name
276 #
277 if( !wfIniGetBool( 'session.auto_start' ) )
278 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
279
280 if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
281 wfIncrStats( 'request_with_session' );
282 wfSetupSession();
283 $wgSessionStarted = true;
284 } else {
285 wfIncrStats( 'request_without_session' );
286 $wgSessionStarted = false;
287 }
288
289 wfProfileOut( $fname.'-SetupSession' );
290 wfProfileIn( $fname.'-globals' );
291
292 $wgContLang = new StubContLang;
293
294 // Now that variant lists may be available...
295 $wgRequest->interpolateTitle();
296
297 $wgUser = new StubUser;
298 $wgLang = new StubUserLang;
299 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
300 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
301
302 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
303 array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
304
305 wfProfileOut( $fname.'-globals' );
306 wfProfileIn( $fname.'-User' );
307
308 # Skin setup functions
309 # Entries can be added to this variable during the inclusion
310 # of the extension file. Skins can then perform any necessary initialisation.
311 #
312 foreach ( $wgSkinExtensionFunctions as $func ) {
313 call_user_func( $func );
314 }
315
316 if( !is_object( $wgAuth ) ) {
317 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
318 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
319 }
320
321 wfProfileOut( $fname.'-User' );
322
323 wfProfileIn( $fname.'-misc2' );
324
325 $wgDeferredUpdateList = array();
326 $wgPostCommitUpdateList = array();
327
328 if ( $wgAjaxWatch ) $wgAjaxExportList[] = 'wfAjaxWatch';
329 if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'SpecialUpload::ajaxGetExistsWarning';
330 if( $wgAjaxLicensePreview )
331 $wgAjaxExportList[] = 'SpecialUpload::ajaxGetLicensePreview';
332
333 # Placeholders in case of DB error
334 $wgTitle = null;
335 $wgArticle = null;
336
337 wfProfileOut( $fname.'-misc2' );
338 wfProfileIn( $fname.'-extensions' );
339
340 # Extension setup functions for extensions other than skins
341 # Entries should be added to this variable during the inclusion
342 # of the extension file. This allows the extension to perform
343 # any necessary initialisation in the fully initialised environment
344 foreach ( $wgExtensionFunctions as $func ) {
345 # Allow closures in PHP 5.3+
346 if ( is_object( $func ) && $func instanceof Closure ) {
347 $profName = $fname.'-extensions-closure';
348 } elseif( is_array( $func ) ) {
349 if ( is_object( $func[0] ) )
350 $profName = $fname.'-extensions-'.get_class( $func[0] ).'::'.$func[1];
351 else
352 $profName = $fname.'-extensions-'.implode( '::', $func );
353 } else {
354 $profName = $fname.'-extensions-'.strval( $func );
355 }
356
357 wfProfileIn( $profName );
358 call_user_func( $func );
359 wfProfileOut( $profName );
360 }
361
362 // For compatibility
363 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
364 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
365 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
366 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
367
368 if( !empty($wgNewUserLog) ) {
369 # Add a new log type
370 $wgLogTypes[] = 'newusers';
371 $wgLogNames['newusers'] = 'newuserlogpage';
372 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
373 $wgLogActions['newusers/newusers'] = 'newuserlogentry'; // For compatibility with older log entries
374 $wgLogActions['newusers/create'] = 'newuserlog-create-entry';
375 $wgLogActions['newusers/create2'] = 'newuserlog-create2-entry';
376 $wgLogActions['newusers/autocreate'] = 'newuserlog-autocreate-entry';
377 }
378
379 wfDebug( "Fully initialised\n" );
380 $wgFullyInitialised = true;
381 wfProfileOut( $fname.'-extensions' );
382 wfProfileOut( $fname );