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