Upload license preview now uses the API instead of action=ajax
[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 if( $wgExtensionAssetsPath === false ) $wgExtensionAssetsPath = "$wgScriptPath/extensions";
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 'deletedDir' => $wgFileStore['deleted']['directory'],
91 'deletedHashLevels' => $wgFileStore['deleted']['hash']
92 );
93 }
94 /**
95 * Initialise shared repo from backwards-compatible settings
96 */
97 if ( $wgUseSharedUploads ) {
98 if ( $wgSharedUploadDBname ) {
99 $wgForeignFileRepos[] = array(
100 'class' => 'ForeignDBRepo',
101 'name' => 'shared',
102 'directory' => $wgSharedUploadDirectory,
103 'url' => $wgSharedUploadPath,
104 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
105 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
106 'transformVia404' => !$wgGenerateThumbnailOnParse,
107 'dbType' => $wgDBtype,
108 'dbServer' => $wgDBserver,
109 'dbUser' => $wgDBuser,
110 'dbPassword' => $wgDBpassword,
111 'dbName' => $wgSharedUploadDBname,
112 'dbFlags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT,
113 'tablePrefix' => $wgSharedUploadDBprefix,
114 'hasSharedCache' => $wgCacheSharedUploads,
115 'descBaseUrl' => $wgRepositoryBaseUrl,
116 'fetchDescription' => $wgFetchCommonsDescriptions,
117 );
118 } else {
119 $wgForeignFileRepos[] = array(
120 'class' => 'FSRepo',
121 'name' => 'shared',
122 'directory' => $wgSharedUploadDirectory,
123 'url' => $wgSharedUploadPath,
124 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
125 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
126 'transformVia404' => !$wgGenerateThumbnailOnParse,
127 'descBaseUrl' => $wgRepositoryBaseUrl,
128 'fetchDescription' => $wgFetchCommonsDescriptions,
129 );
130 }
131 }
132 if( $wgUseInstantCommons ) {
133 $wgForeignFileRepos[] = array(
134 'class' => 'ForeignAPIRepo',
135 'name' => 'wikimediacommons',
136 'apibase' => 'http://commons.wikimedia.org/w/api.php',
137 'hashLevels' => 2,
138 'fetchDescription' => true,
139 'descriptionCacheExpiry' => 43200,
140 'apiThumbCacheExpiry' => 86400,
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
164 # Raise the memory limit if it's too low
165 wfMemoryLimit();
166
167 /**
168 * Set up the timezone, suppressing the pseudo-security warning in PHP 5.1+
169 * that happens whenever you use a date function without the timezone being
170 * explicitly set. Inspired by phpMyAdmin's treatment of the problem.
171 */
172 wfSuppressWarnings();
173 date_default_timezone_set( date_default_timezone_get() );
174 wfRestoreWarnings();
175
176 $wgIP = false; # Load on demand
177 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
178 $wgRequest = new WebRequest;
179
180 # Useful debug output
181 if ( $wgCommandLineMode ) {
182 wfDebug( "\n\nStart command line script $self\n" );
183 } elseif ( function_exists( 'getallheaders' ) ) {
184 wfDebug( "\n\nStart request\n" );
185 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
186 $headers = getallheaders();
187 foreach ($headers as $name => $value) {
188 wfDebug( "$name: $value\n" );
189 }
190 wfDebug( "\n" );
191 } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
192 wfDebug( "\n\nStart request\n" );
193 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
194 foreach ( $_SERVER as $name => $value ) {
195 if ( substr( $name, 0, 5 ) == 'HTTP_' ) {
196 $name = substr( $name, 5 );
197 wfDebug( "$name: $value\n" );
198 }
199 }
200 wfDebug( "\n" );
201 }
202
203 if( $wgRCFilterByAge ) {
204 ## Trim down $wgRCLinkDays so that it only lists links which are valid
205 ## as determined by $wgRCMaxAge.
206 ## Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
207 sort($wgRCLinkDays);
208 for( $i = 0; $i < count($wgRCLinkDays); $i++ ) {
209 if( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
210 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i+1, false );
211 break;
212 }
213 }
214 }
215
216 if ( $wgSkipSkin ) {
217 $wgSkipSkins[] = $wgSkipSkin;
218 }
219
220 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
221
222 if($wgMetaNamespace === FALSE) {
223 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
224 }
225
226 # These are now the same, always
227 # To determine the user language, use $wgLang->getCode()
228 $wgContLanguageCode = $wgLanguageCode;
229
230 # Easy to forget to falsify $wgShowIPinHeader for static caches.
231 # If file cache or squid cache is on, just disable this (DWIMD).
232 if( $wgUseFileCache || $wgUseSquid ) $wgShowIPinHeader = false;
233
234 # $wgAllowRealName and $wgAllowUserSkin were removed in 1.16
235 # in favor of $wgHiddenPrefs, handle b/c here
236 if( !$wgAllowRealName ) {
237 $wgHiddenPrefs[] = 'realname';
238 }
239
240 if( !$wgAllowUserSkin ) {
241 $wgHiddenPrefs[] = 'skin';
242 }
243
244 if ( !$wgHtml5Version && $wgHtml5 && $wgAllowRdfaAttributes ) {
245 # see http://www.w3.org/TR/rdfa-in-html/#document-conformance
246 if ( $wgMimeType == 'application/xhtml+xml' ) $wgHtml5Version = 'XHTML+RDFa 1.0';
247 else $wgHtml5Version = 'HTML+RDFa 1.0';
248 }
249
250
251 wfProfileOut( $fname.'-misc1' );
252 wfProfileIn( $fname.'-memcached' );
253
254 $wgMemc =& wfGetMainCache();
255 $messageMemc =& wfGetMessageCacheStorage();
256 $parserMemc =& wfGetParserCacheStorage();
257
258 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
259 "\nMessage cache: " . get_class( $messageMemc ) .
260 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
261
262 wfProfileOut( $fname.'-memcached' );
263
264 ## Most of the config is out, some might want to run hooks here.
265 wfRunHooks( 'SetupAfterCache' );
266
267 wfProfileIn( $fname.'-SetupSession' );
268
269 # Set default shared prefix
270 if( $wgSharedPrefix === false ) $wgSharedPrefix = $wgDBprefix;
271
272 if( !$wgCookiePrefix ) {
273 if ( $wgSharedDB && $wgSharedPrefix && in_array('user',$wgSharedTables) ) {
274 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
275 } elseif ( $wgSharedDB && in_array('user',$wgSharedTables) ) {
276 $wgCookiePrefix = $wgSharedDB;
277 } elseif ( $wgDBprefix ) {
278 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
279 } else {
280 $wgCookiePrefix = $wgDBname;
281 }
282 }
283 $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
284
285 # If session.auto_start is there, we can't touch session name
286 #
287 if( !wfIniGetBool( 'session.auto_start' ) )
288 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
289
290 if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
291 wfIncrStats( 'request_with_session' );
292 wfSetupSession();
293 $wgSessionStarted = true;
294 } else {
295 wfIncrStats( 'request_without_session' );
296 $wgSessionStarted = false;
297 }
298
299 wfProfileOut( $fname.'-SetupSession' );
300 wfProfileIn( $fname.'-globals' );
301
302 $wgContLang = new StubContLang;
303
304 // Now that variant lists may be available...
305 $wgRequest->interpolateTitle();
306
307 $wgUser = new StubUser;
308 $wgLang = new StubUserLang;
309 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
310 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
311
312 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
313 array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
314
315 wfProfileOut( $fname.'-globals' );
316 wfProfileIn( $fname.'-User' );
317
318 # Skin setup functions
319 # Entries can be added to this variable during the inclusion
320 # of the extension file. Skins can then perform any necessary initialisation.
321 #
322 foreach ( $wgSkinExtensionFunctions as $func ) {
323 call_user_func( $func );
324 }
325
326 if( !is_object( $wgAuth ) ) {
327 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
328 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
329 }
330
331 wfProfileOut( $fname.'-User' );
332
333 wfProfileIn( $fname.'-misc2' );
334
335 $wgDeferredUpdateList = array();
336 $wgPostCommitUpdateList = array();
337
338 if ( $wgAjaxWatch ) $wgAjaxExportList[] = 'wfAjaxWatch';
339 if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'SpecialUpload::ajaxGetExistsWarning';
340
341 # Placeholders in case of DB error
342 $wgTitle = null;
343 $wgArticle = null;
344
345 wfProfileOut( $fname.'-misc2' );
346 wfProfileIn( $fname.'-extensions' );
347
348 # Extension setup functions for extensions other than skins
349 # Entries should be added to this variable during the inclusion
350 # of the extension file. This allows the extension to perform
351 # any necessary initialisation in the fully initialised environment
352 foreach ( $wgExtensionFunctions as $func ) {
353 # Allow closures in PHP 5.3+
354 if ( is_object( $func ) && $func instanceof Closure ) {
355 $profName = $fname.'-extensions-closure';
356 } elseif( is_array( $func ) ) {
357 if ( is_object( $func[0] ) )
358 $profName = $fname.'-extensions-'.get_class( $func[0] ).'::'.$func[1];
359 else
360 $profName = $fname.'-extensions-'.implode( '::', $func );
361 } else {
362 $profName = $fname.'-extensions-'.strval( $func );
363 }
364
365 wfProfileIn( $profName );
366 call_user_func( $func );
367 wfProfileOut( $profName );
368 }
369
370 // For compatibility
371 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
372 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
373 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
374 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
375
376 if( !empty($wgNewUserLog) ) {
377 # Add a new log type
378 $wgLogTypes[] = 'newusers';
379 $wgLogNames['newusers'] = 'newuserlogpage';
380 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
381 $wgLogActions['newusers/newusers'] = 'newuserlogentry'; // For compatibility with older log entries
382 $wgLogActions['newusers/create'] = 'newuserlog-create-entry';
383 $wgLogActions['newusers/create2'] = 'newuserlog-create2-entry';
384 $wgLogActions['newusers/autocreate'] = 'newuserlog-autocreate-entry';
385 }
386
387 wfDebug( "Fully initialised\n" );
388 $wgFullyInitialised = true;
389 wfProfileOut( $fname.'-extensions' );
390 wfProfileOut( $fname );