* (bug 26253) Removed $wgPostCommitUpdateList
[lhc/web/wiklou.git] / includes / Setup.php
1 <?php
2 /**
3 * Include most things that's need to customize the site
4 *
5 * @file
6 */
7
8 /**
9 * This file is not a valid entry point, perform no further processing unless
10 * MEDIAWIKI is defined
11 */
12 if( !defined( 'MEDIAWIKI' ) ) {
13 exit( 1 );
14 }
15
16 # The main wiki script and things like database
17 # conversion and maintenance scripts all share a
18 # common setup of including lots of classes and
19 # setting up a few globals.
20 #
21
22 $fname = 'Setup.php';
23 wfProfileIn( $fname );
24
25 // Check to see if we are at the file scope
26 if ( !isset( $wgVersion ) ) {
27 echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
28 die( 1 );
29 }
30
31 // Set various default paths sensibly...
32 if( $wgScript === false ) $wgScript = "$wgScriptPath/index$wgScriptExtension";
33 if( $wgRedirectScript === false ) $wgRedirectScript = "$wgScriptPath/redirect$wgScriptExtension";
34 if( $wgLoadScript === false ) $wgLoadScript = "$wgScriptPath/load$wgScriptExtension";
35
36 if( $wgArticlePath === false ) {
37 if( $wgUsePathInfo ) {
38 $wgArticlePath = "$wgScript/$1";
39 } else {
40 $wgArticlePath = "$wgScript?title=$1";
41 }
42 }
43
44 if( $wgStylePath === false ) $wgStylePath = "$wgScriptPath/skins";
45 if( $wgLocalStylePath === false ) $wgLocalStylePath = "$wgScriptPath/skins";
46 if( $wgStyleDirectory === false) $wgStyleDirectory = "$IP/skins";
47 if( $wgExtensionAssetsPath === false ) $wgExtensionAssetsPath = "$wgScriptPath/extensions";
48
49 if( $wgLogo === false ) $wgLogo = "$wgStylePath/common/images/wiki.png";
50
51 if( $wgUploadPath === false ) $wgUploadPath = "$wgScriptPath/images";
52 if( $wgUploadDirectory === false ) $wgUploadDirectory = "$IP/images";
53
54 if( $wgMathPath === false ) $wgMathPath = "{$wgUploadPath}/math";
55 if( $wgMathDirectory === false ) $wgMathDirectory = "{$wgUploadDirectory}/math";
56 if( $wgTmpDirectory === false ) $wgTmpDirectory = "{$wgUploadDirectory}/tmp";
57
58 if( $wgReadOnlyFile === false ) $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
59 if( $wgFileCacheDirectory === false ) $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
60 if( $wgDeletedDirectory === false ) $wgDeletedDirectory = "{$wgUploadDirectory}/deleted";
61
62 if( isset( $wgFileStore['deleted']['directory'] ) ) {
63 $wgDeletedDirectory = $wgFileStore['deleted']['directory'];
64 }
65
66 if( isset($wgFooterIcons["copyright"]) &&
67 isset($wgFooterIcons["copyright"]["copyright"]) &&
68 $wgFooterIcons["copyright"]["copyright"] === array() ) {
69 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
70 $wgFooterIcons["copyright"]["copyright"] = $wgCopyrightIcon;
71 } elseif ( $wgRightsIcon || $wgRightsText ) {
72 $wgFooterIcons["copyright"]["copyright"] = array(
73 "url" => $wgRightsUrl,
74 "src" => $wgRightsIcon,
75 "alt" => $wgRightsText,
76 );
77 } else {
78 unset($wgFooterIcons["copyright"]["copyright"]);
79 }
80 }
81
82 if( isset($wgFooterIcons["poweredby"]) &&
83 isset($wgFooterIcons["poweredby"]["mediawiki"]) &&
84 $wgFooterIcons["poweredby"]["mediawiki"]["src"] === null ) {
85 $wgFooterIcons["poweredby"]["mediawiki"]["src"] = "$wgStylePath/common/images/poweredby_mediawiki_88x31.png";
86 }
87
88 /**
89 * Unconditional protection for NS_MEDIAWIKI since otherwise it's too easy for a
90 * sysadmin to set $wgNamespaceProtection incorrectly and leave the wiki insecure.
91 *
92 * Note that this is the definition of editinterface and it can be granted to
93 * all users if desired.
94 */
95 $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
96
97 /**
98 * The canonical names of namespaces 6 and 7 are, as of v1.14, "File"
99 * and "File_talk". The old names "Image" and "Image_talk" are
100 * retained as aliases for backwards compatibility.
101 */
102 $wgNamespaceAliases['Image'] = NS_FILE;
103 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
104
105 /**
106 * Initialise $wgLocalFileRepo from backwards-compatible settings
107 */
108 if ( !$wgLocalFileRepo ) {
109 if( isset( $wgFileStore['deleted']['hash'] ) ) {
110 $deletedHashLevel = $wgFileStore['deleted']['hash'];
111 } else {
112 $deletedHashLevel = $wgHashedUploadDirectory ? 3 : 0;
113 }
114 $wgLocalFileRepo = array(
115 'class' => 'LocalRepo',
116 'name' => 'local',
117 'directory' => $wgUploadDirectory,
118 'scriptDirUrl' => $wgScriptPath,
119 'scriptExtension' => $wgScriptExtension,
120 'url' => $wgUploadBaseUrl ? $wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
121 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
122 'thumbScriptUrl' => $wgThumbnailScriptPath,
123 'transformVia404' => !$wgGenerateThumbnailOnParse,
124 'deletedDir' => $wgDeletedDirectory,
125 'deletedHashLevels' => $deletedHashLevel
126 );
127 }
128 /**
129 * Initialise shared repo from backwards-compatible settings
130 */
131 if ( $wgUseSharedUploads ) {
132 if ( $wgSharedUploadDBname ) {
133 $wgForeignFileRepos[] = array(
134 'class' => 'ForeignDBRepo',
135 'name' => 'shared',
136 'directory' => $wgSharedUploadDirectory,
137 'url' => $wgSharedUploadPath,
138 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
139 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
140 'transformVia404' => !$wgGenerateThumbnailOnParse,
141 'dbType' => $wgDBtype,
142 'dbServer' => $wgDBserver,
143 'dbUser' => $wgDBuser,
144 'dbPassword' => $wgDBpassword,
145 'dbName' => $wgSharedUploadDBname,
146 'dbFlags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT,
147 'tablePrefix' => $wgSharedUploadDBprefix,
148 'hasSharedCache' => $wgCacheSharedUploads,
149 'descBaseUrl' => $wgRepositoryBaseUrl,
150 'fetchDescription' => $wgFetchCommonsDescriptions,
151 );
152 } else {
153 $wgForeignFileRepos[] = array(
154 'class' => 'FSRepo',
155 'name' => 'shared',
156 'directory' => $wgSharedUploadDirectory,
157 'url' => $wgSharedUploadPath,
158 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
159 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
160 'transformVia404' => !$wgGenerateThumbnailOnParse,
161 'descBaseUrl' => $wgRepositoryBaseUrl,
162 'fetchDescription' => $wgFetchCommonsDescriptions,
163 );
164 }
165 }
166 if( $wgUseInstantCommons ) {
167 $wgForeignFileRepos[] = array(
168 'class' => 'ForeignAPIRepo',
169 'name' => 'wikimediacommons',
170 'apibase' => 'http://commons.wikimedia.org/w/api.php',
171 'hashLevels' => 2,
172 'fetchDescription' => true,
173 'descriptionCacheExpiry' => 43200,
174 'apiThumbCacheExpiry' => 86400,
175 );
176 }
177
178 if ( !class_exists( 'AutoLoader' ) ) {
179 require_once( "$IP/includes/AutoLoader.php" );
180 }
181
182 wfProfileIn( $fname.'-exception' );
183 require_once( "$IP/includes/Exception.php" );
184 wfInstallExceptionHandler();
185 wfProfileOut( $fname.'-exception' );
186
187 wfProfileIn( $fname.'-includes' );
188 require_once( "$IP/includes/GlobalFunctions.php" );
189 require_once( "$IP/includes/Hooks.php" );
190 require_once( "$IP/includes/Namespace.php" );
191 require_once( "$IP/includes/ProxyTools.php" );
192 require_once( "$IP/includes/ObjectCache.php" );
193 require_once( "$IP/includes/ImageFunctions.php" );
194 wfProfileOut( $fname.'-includes' );
195 wfProfileIn( $fname.'-misc1' );
196
197 # Raise the memory limit if it's too low
198 wfMemoryLimit();
199
200 /**
201 * Set up the timezone, suppressing the pseudo-security warning in PHP 5.1+
202 * that happens whenever you use a date function without the timezone being
203 * explicitly set. Inspired by phpMyAdmin's treatment of the problem.
204 */
205 wfSuppressWarnings();
206 date_default_timezone_set( date_default_timezone_get() );
207 wfRestoreWarnings();
208
209 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
210 $wgRequest = new WebRequest;
211
212 # Useful debug output
213 global $wgCommandLineMode;
214 if ( $wgCommandLineMode ) {
215 wfDebug( "\n\nStart command line script $self\n" );
216 } else {
217 wfDebug( "Start request\n\n" );
218 # Output the REQUEST_URI. This is not supported by IIS in rewrite mode,
219 # so use an alternative
220 $requestUri = isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] :
221 ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ? $_SERVER['HTTP_X_ORIGINAL_URL'] :
222 $_SERVER['PHP_SELF'] );
223 wfDebug( "{$_SERVER['REQUEST_METHOD']} {$requestUri}\n" );
224
225 if ( $wgDebugPrintHttpHeaders ) {
226 $headerOut = "HTTP HEADERS:\n";
227
228 if ( function_exists( 'getallheaders' ) ) {
229 $headers = getallheaders();
230 foreach ( $headers as $name => $value ) {
231 $headerOut .= "$name: $value\n";
232 }
233 } else {
234 $headers = $_SERVER;
235 foreach ( $headers as $name => $value ) {
236 if ( substr( $name, 0, 5 ) !== 'HTTP_' ) continue;
237 $name = substr( $name, 5 );
238 $headerOut .= "$name: $value\n";
239 }
240 }
241 wfDebug( "$headerOut\n" );
242 }
243 }
244
245 if( $wgRCFilterByAge ) {
246 ## Trim down $wgRCLinkDays so that it only lists links which are valid
247 ## as determined by $wgRCMaxAge.
248 ## Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
249 sort($wgRCLinkDays);
250 for( $i = 0; $i < count($wgRCLinkDays); $i++ ) {
251 if( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
252 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i+1, false );
253 break;
254 }
255 }
256 }
257
258 if ( $wgSkipSkin ) {
259 $wgSkipSkins[] = $wgSkipSkin;
260 }
261
262 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
263
264 if($wgMetaNamespace === FALSE) {
265 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
266 }
267
268 # These are now the same, always
269 # To determine the user language, use $wgLang->getCode()
270 $wgContLanguageCode = $wgLanguageCode;
271
272 # Easy to forget to falsify $wgShowIPinHeader for static caches.
273 # If file cache or squid cache is on, just disable this (DWIMD).
274 if( $wgUseFileCache || $wgUseSquid ) $wgShowIPinHeader = false;
275
276 # $wgAllowRealName and $wgAllowUserSkin were removed in 1.16
277 # in favor of $wgHiddenPrefs, handle b/c here
278 if( !$wgAllowRealName ) {
279 $wgHiddenPrefs[] = 'realname';
280 }
281
282 if( !$wgAllowUserSkin ) {
283 $wgHiddenPrefs[] = 'skin';
284 }
285
286 if ( !$wgHtml5Version && $wgHtml5 && $wgAllowRdfaAttributes ) {
287 # see http://www.w3.org/TR/rdfa-in-html/#document-conformance
288 if ( $wgMimeType == 'application/xhtml+xml' ) $wgHtml5Version = 'XHTML+RDFa 1.0';
289 else $wgHtml5Version = 'HTML+RDFa 1.0';
290 }
291
292 if ( $wgInvalidateCacheOnLocalSettingsChange ) {
293 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( "$IP/LocalSettings.php" ) ) );
294 }
295
296 wfProfileOut( $fname.'-misc1' );
297 wfProfileIn( $fname.'-memcached' );
298
299 $wgMemc =& wfGetMainCache();
300 $messageMemc =& wfGetMessageCacheStorage();
301 $parserMemc =& wfGetParserCacheStorage();
302
303 wfDebug( 'CACHES: ' . get_class( $wgMemc ) . '[main] ' .
304 get_class( $messageMemc ) . '[message] ' .
305 get_class( $parserMemc ) . "[parser]\n" );
306
307 wfProfileOut( $fname.'-memcached' );
308
309 ## Most of the config is out, some might want to run hooks here.
310 wfRunHooks( 'SetupAfterCache' );
311
312 wfProfileIn( $fname.'-SetupSession' );
313
314 # Set default shared prefix
315 if( $wgSharedPrefix === false ) $wgSharedPrefix = $wgDBprefix;
316
317 if( !$wgCookiePrefix ) {
318 if ( $wgSharedDB && $wgSharedPrefix && in_array('user',$wgSharedTables) ) {
319 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
320 } elseif ( $wgSharedDB && in_array('user',$wgSharedTables) ) {
321 $wgCookiePrefix = $wgSharedDB;
322 } elseif ( $wgDBprefix ) {
323 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
324 } else {
325 $wgCookiePrefix = $wgDBname;
326 }
327 }
328 $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
329
330 # If session.auto_start is there, we can't touch session name
331 #
332 if( !wfIniGetBool( 'session.auto_start' ) )
333 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
334
335 if( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
336 if( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) {
337 wfIncrStats( 'request_with_session' );
338 wfSetupSession();
339 $wgSessionStarted = true;
340 } else {
341 wfIncrStats( 'request_without_session' );
342 $wgSessionStarted = false;
343 }
344 }
345
346 wfProfileOut( $fname.'-SetupSession' );
347 wfProfileIn( $fname.'-globals' );
348
349 $wgContLang = new StubContLang;
350
351 // Now that variant lists may be available...
352 $wgRequest->interpolateTitle();
353 $wgUser = $wgCommandLineMode ? new User : User::newFromSession();
354 $wgLang = new StubUserLang;
355 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
356 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
357
358 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
359 array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry ) );
360
361 wfProfileOut( $fname.'-globals' );
362 wfProfileIn( $fname.'-User' );
363
364 # Skin setup functions
365 # Entries can be added to this variable during the inclusion
366 # of the extension file. Skins can then perform any necessary initialisation.
367 #
368 foreach ( $wgSkinExtensionFunctions as $func ) {
369 call_user_func( $func );
370 }
371
372 if( !is_object( $wgAuth ) ) {
373 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
374 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
375 }
376
377 wfProfileOut( $fname.'-User' );
378
379 wfProfileIn( $fname.'-misc2' );
380
381 $wgDeferredUpdateList = array();
382
383 if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'SpecialUpload::ajaxGetExistsWarning';
384
385 # Placeholders in case of DB error
386 $wgTitle = null;
387 $wgArticle = null;
388
389 wfProfileOut( $fname.'-misc2' );
390 wfProfileIn( $fname.'-extensions' );
391
392 # Extension setup functions for extensions other than skins
393 # Entries should be added to this variable during the inclusion
394 # of the extension file. This allows the extension to perform
395 # any necessary initialisation in the fully initialised environment
396 foreach ( $wgExtensionFunctions as $func ) {
397 # Allow closures in PHP 5.3+
398 if ( is_object( $func ) && $func instanceof Closure ) {
399 $profName = $fname.'-extensions-closure';
400 } elseif( is_array( $func ) ) {
401 if ( is_object( $func[0] ) )
402 $profName = $fname.'-extensions-'.get_class( $func[0] ).'::'.$func[1];
403 else
404 $profName = $fname.'-extensions-'.implode( '::', $func );
405 } else {
406 $profName = $fname.'-extensions-'.strval( $func );
407 }
408
409 wfProfileIn( $profName );
410 call_user_func( $func );
411 wfProfileOut( $profName );
412 }
413
414 // For compatibility
415 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
416 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
417 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
418 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
419
420 if( !empty($wgNewUserLog) ) {
421 # Add a new log type
422 $wgLogTypes[] = 'newusers';
423 $wgLogNames['newusers'] = 'newuserlogpage';
424 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
425 $wgLogActions['newusers/newusers'] = 'newuserlogentry'; // For compatibility with older log entries
426 $wgLogActions['newusers/create'] = 'newuserlog-create-entry';
427 $wgLogActions['newusers/create2'] = 'newuserlog-create2-entry';
428 $wgLogActions['newusers/autocreate'] = 'newuserlog-autocreate-entry';
429 }
430
431 wfDebug( "Fully initialised\n" );
432 $wgFullyInitialised = true;
433 wfProfileOut( $fname.'-extensions' );
434 wfProfileOut( $fname );