3 * Include most things that's need to customize the site
7 * This file is not a valid entry point, perform no further processing unless
10 if( !defined( 'MEDIAWIKI' ) ) {
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.
21 wfProfileIn( $fname );
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";
29 // Set various default paths sensibly...
30 if( $wgScript === false ) $wgScript = "$wgScriptPath/index$wgScriptExtension";
31 if( $wgRedirectScript === false ) $wgRedirectScript = "$wgScriptPath/redirect$wgScriptExtension";
33 if( $wgArticlePath === false ) {
34 if( $wgUsePathInfo ) {
35 $wgArticlePath = "$wgScript/$1";
37 $wgArticlePath = "$wgScript?title=$1";
41 if( $wgStylePath === false ) $wgStylePath = "$wgScriptPath/skins";
42 if( $wgStyleDirectory === false) $wgStyleDirectory = "$IP/skins";
43 if( $wgExtensionAssetsPath === false ) $wgExtensionAssetsPath = "$wgScriptPath/extensions";
45 if( $wgLogo === false ) $wgLogo = "$wgStylePath/common/images/wiki.png";
47 if( $wgUploadPath === false ) $wgUploadPath = "$wgScriptPath/images";
48 if( $wgUploadDirectory === false ) $wgUploadDirectory = "$IP/images";
50 if( $wgMathPath === false ) $wgMathPath = "{$wgUploadPath}/math";
51 if( $wgMathDirectory === false ) $wgMathDirectory = "{$wgUploadDirectory}/math";
52 if( $wgTmpDirectory === false ) $wgTmpDirectory = "{$wgUploadDirectory}/tmp";
54 if( $wgReadOnlyFile === false ) $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
55 if( $wgFileCacheDirectory === false ) $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
57 if ( empty( $wgFileStore['deleted']['directory'] ) ) {
58 $wgFileStore['deleted']['directory'] = "{$wgUploadDirectory}/deleted";
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.
65 * Note that this is the definition of editinterface and it can be granted to
66 * all users if desired.
68 $wgNamespaceProtection[NS_MEDIAWIKI
] = 'editinterface';
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.
75 $wgNamespaceAliases['Image'] = NS_FILE
;
76 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK
;
79 * Initialise $wgLocalFileRepo from backwards-compatible settings
81 if ( !$wgLocalFileRepo ) {
82 $wgLocalFileRepo = array(
83 'class' => 'LocalRepo',
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']
95 * Initialise shared repo from backwards-compatible settings
97 if ( $wgUseSharedUploads ) {
98 if ( $wgSharedUploadDBname ) {
99 $wgForeignFileRepos[] = array(
100 'class' => 'ForeignDBRepo',
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,
119 $wgForeignFileRepos[] = array(
122 'directory' => $wgSharedUploadDirectory,
123 'url' => $wgSharedUploadPath,
124 'hashLevels' => $wgHashedSharedUploadDirectory ?
2 : 0,
125 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
126 'transformVia404' => !$wgGenerateThumbnailOnParse,
127 'descBaseUrl' => $wgRepositoryBaseUrl,
128 'fetchDescription' => $wgFetchCommonsDescriptions,
132 if( $wgUseInstantCommons ) {
133 $wgForeignFileRepos[] = array(
134 'class' => 'ForeignAPIRepo',
135 'name' => 'wikimediacommons',
136 'apibase' => 'http://commons.wikimedia.org/w/api.php',
138 'fetchDescription' => true,
139 'descriptionCacheExpiry' => 43200,
140 'apiThumbCacheExpiry' => 86400,
144 if ( !class_exists( 'AutoLoader' ) ) {
145 require_once( "$IP/includes/AutoLoader.php" );
148 wfProfileIn( $fname.'-exception' );
149 require_once( "$IP/includes/Exception.php" );
150 wfInstallExceptionHandler();
151 wfProfileOut( $fname.'-exception' );
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' );
164 # Raise the memory limit if it's too low
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.
172 wfSuppressWarnings();
173 date_default_timezone_set( date_default_timezone_get() );
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
;
180 # Useful debug output
181 if ( $wgCommandLineMode ) {
182 wfDebug( "\n\nStart command line script $self\n" );
184 wfDebug( "Start request\n\n" );
185 # Output the REQUEST_URI. This is not supported by IIS in rewrite mode,
186 # so use an alternative
187 $requestUri = isset( $_SERVER['REQUEST_URI'] ) ?
$_SERVER['REQUEST_URI'] :
188 ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ?
$_SERVER['HTTP_X_ORIGINAL_URL'] :
189 $_SERVER['PHP_SELF'] );
190 wfDebug( "{$_SERVER['REQUEST_METHOD']} {$requestUri}\n" );
192 if ( $wgDebugPrintHttpHeaders ) {
193 $headerOut = "HTTP HEADERS:\n";
195 if ( function_exists( 'getallheaders' ) ) {
196 $headers = getallheaders();
197 foreach ( $headers as $name => $value ) {
198 $headerOut .= "$name: $value\n";
202 foreach ( $headers as $name => $value ) {
203 if ( substr( $name, 0, 5 ) !== 'HTTP_' ) continue;
204 $name = substr( $name, 5 );
205 $headerOut .= "$name: $value\n";
208 wfDebug( "$headerOut\n" );
212 if( $wgRCFilterByAge ) {
213 ## Trim down $wgRCLinkDays so that it only lists links which are valid
214 ## as determined by $wgRCMaxAge.
215 ## Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
217 for( $i = 0; $i < count($wgRCLinkDays); $i++
) {
218 if( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
219 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i+
1, false );
226 $wgSkipSkins[] = $wgSkipSkin;
229 $wgUseEnotif = $wgEnotifUserTalk ||
$wgEnotifWatchlist;
231 if($wgMetaNamespace === FALSE) {
232 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
235 # These are now the same, always
236 # To determine the user language, use $wgLang->getCode()
237 $wgContLanguageCode = $wgLanguageCode;
239 # Easy to forget to falsify $wgShowIPinHeader for static caches.
240 # If file cache or squid cache is on, just disable this (DWIMD).
241 if( $wgUseFileCache ||
$wgUseSquid ) $wgShowIPinHeader = false;
243 # $wgAllowRealName and $wgAllowUserSkin were removed in 1.16
244 # in favor of $wgHiddenPrefs, handle b/c here
245 if( !$wgAllowRealName ) {
246 $wgHiddenPrefs[] = 'realname';
249 if( !$wgAllowUserSkin ) {
250 $wgHiddenPrefs[] = 'skin';
253 if ( !$wgHtml5Version && $wgHtml5 && $wgAllowRdfaAttributes ) {
254 # see http://www.w3.org/TR/rdfa-in-html/#document-conformance
255 if ( $wgMimeType == 'application/xhtml+xml' ) $wgHtml5Version = 'XHTML+RDFa 1.0';
256 else $wgHtml5Version = 'HTML+RDFa 1.0';
260 wfProfileOut( $fname.'-misc1' );
261 wfProfileIn( $fname.'-memcached' );
263 $wgMemc =& wfGetMainCache();
264 $messageMemc =& wfGetMessageCacheStorage();
265 $parserMemc =& wfGetParserCacheStorage();
267 wfDebug( 'CACHES: ' . get_class( $wgMemc ) . '[main] ' .
268 get_class( $messageMemc ) . '[message] ' .
269 get_class( $parserMemc ) . "[parser]\n" );
271 wfProfileOut( $fname.'-memcached' );
273 ## Most of the config is out, some might want to run hooks here.
274 wfRunHooks( 'SetupAfterCache' );
276 wfProfileIn( $fname.'-SetupSession' );
278 # Set default shared prefix
279 if( $wgSharedPrefix === false ) $wgSharedPrefix = $wgDBprefix;
281 if( !$wgCookiePrefix ) {
282 if ( $wgSharedDB && $wgSharedPrefix && in_array('user',$wgSharedTables) ) {
283 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
284 } elseif ( $wgSharedDB && in_array('user',$wgSharedTables) ) {
285 $wgCookiePrefix = $wgSharedDB;
286 } elseif ( $wgDBprefix ) {
287 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
289 $wgCookiePrefix = $wgDBname;
292 $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
294 # If session.auto_start is there, we can't touch session name
296 if( !wfIniGetBool( 'session.auto_start' ) )
297 session_name( $wgSessionName ?
$wgSessionName : $wgCookiePrefix . '_session' );
299 if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() ||
isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
300 wfIncrStats( 'request_with_session' );
302 $wgSessionStarted = true;
304 wfIncrStats( 'request_without_session' );
305 $wgSessionStarted = false;
308 wfProfileOut( $fname.'-SetupSession' );
309 wfProfileIn( $fname.'-globals' );
311 $wgContLang = new StubContLang
;
313 // Now that variant lists may be available...
314 $wgRequest->interpolateTitle();
316 $wgUser = new StubUser
;
317 $wgLang = new StubUserLang
;
318 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
319 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
321 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
322 array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
324 wfProfileOut( $fname.'-globals' );
325 wfProfileIn( $fname.'-User' );
327 # Skin setup functions
328 # Entries can be added to this variable during the inclusion
329 # of the extension file. Skins can then perform any necessary initialisation.
331 foreach ( $wgSkinExtensionFunctions as $func ) {
332 call_user_func( $func );
335 if( !is_object( $wgAuth ) ) {
336 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
337 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
340 wfProfileOut( $fname.'-User' );
342 wfProfileIn( $fname.'-misc2' );
344 $wgDeferredUpdateList = array();
345 $wgPostCommitUpdateList = array();
347 if ( $wgAjaxWatch ) $wgAjaxExportList[] = 'wfAjaxWatch';
348 if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'SpecialUpload::ajaxGetExistsWarning';
350 # Placeholders in case of DB error
354 wfProfileOut( $fname.'-misc2' );
355 wfProfileIn( $fname.'-extensions' );
357 # Extension setup functions for extensions other than skins
358 # Entries should be added to this variable during the inclusion
359 # of the extension file. This allows the extension to perform
360 # any necessary initialisation in the fully initialised environment
361 foreach ( $wgExtensionFunctions as $func ) {
362 # Allow closures in PHP 5.3+
363 if ( is_object( $func ) && $func instanceof Closure
) {
364 $profName = $fname.'-extensions-closure';
365 } elseif( is_array( $func ) ) {
366 if ( is_object( $func[0] ) )
367 $profName = $fname.'-extensions-'.get_class( $func[0] ).'::'.$func[1];
369 $profName = $fname.'-extensions-'.implode( '::', $func );
371 $profName = $fname.'-extensions-'.strval( $func );
374 wfProfileIn( $profName );
375 call_user_func( $func );
376 wfProfileOut( $profName );
380 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
381 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
382 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
383 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
385 if( !empty($wgNewUserLog) ) {
387 $wgLogTypes[] = 'newusers';
388 $wgLogNames['newusers'] = 'newuserlogpage';
389 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
390 $wgLogActions['newusers/newusers'] = 'newuserlogentry'; // For compatibility with older log entries
391 $wgLogActions['newusers/create'] = 'newuserlog-create-entry';
392 $wgLogActions['newusers/create2'] = 'newuserlog-create2-entry';
393 $wgLogActions['newusers/autocreate'] = 'newuserlog-autocreate-entry';
396 wfDebug( "Fully initialised\n" );
397 $wgFullyInitialised = true;
398 wfProfileOut( $fname.'-extensions' );
399 wfProfileOut( $fname );