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( $wgLocalStylePath === false ) $wgLocalStylePath = "$wgScriptPath/skins";
43 if( $wgStyleDirectory === false) $wgStyleDirectory = "$IP/skins";
44 if( $wgExtensionAssetsPath === false ) $wgExtensionAssetsPath = "$wgScriptPath/extensions";
46 if( $wgLogo === false ) $wgLogo = "$wgStylePath/common/images/wiki.png";
48 if( $wgUploadPath === false ) $wgUploadPath = "$wgScriptPath/images";
49 if( $wgUploadDirectory === false ) $wgUploadDirectory = "$IP/images";
51 if( $wgMathPath === false ) $wgMathPath = "{$wgUploadPath}/math";
52 if( $wgMathDirectory === false ) $wgMathDirectory = "{$wgUploadDirectory}/math";
53 if( $wgTmpDirectory === false ) $wgTmpDirectory = "{$wgUploadDirectory}/tmp";
55 if( $wgReadOnlyFile === false ) $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
56 if( $wgFileCacheDirectory === false ) $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
58 if ( empty( $wgFileStore['deleted']['directory'] ) ) {
59 $wgFileStore['deleted']['directory'] = "{$wgUploadDirectory}/deleted";
63 * Unconditional protection for NS_MEDIAWIKI since otherwise it's too easy for a
64 * sysadmin to set $wgNamespaceProtection incorrectly and leave the wiki insecure.
66 * Note that this is the definition of editinterface and it can be granted to
67 * all users if desired.
69 $wgNamespaceProtection[NS_MEDIAWIKI
] = 'editinterface';
72 * The canonical names of namespaces 6 and 7 are, as of v1.14, "File"
73 * and "File_talk". The old names "Image" and "Image_talk" are
74 * retained as aliases for backwards compatibility.
76 $wgNamespaceAliases['Image'] = NS_FILE
;
77 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK
;
80 * Initialise $wgLocalFileRepo from backwards-compatible settings
82 if ( !$wgLocalFileRepo ) {
83 $wgLocalFileRepo = array(
84 'class' => 'LocalRepo',
86 'directory' => $wgUploadDirectory,
87 'scriptDirUrl' => $wgScriptPath,
88 'scriptExtension' => $wgScriptExtension,
89 'url' => $wgUploadBaseUrl ?
$wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
90 'hashLevels' => $wgHashedUploadDirectory ?
2 : 0,
91 'thumbScriptUrl' => $wgThumbnailScriptPath,
92 'transformVia404' => !$wgGenerateThumbnailOnParse,
93 'deletedDir' => $wgFileStore['deleted']['directory'],
94 'deletedHashLevels' => $wgFileStore['deleted']['hash']
98 * Initialise shared repo from backwards-compatible settings
100 if ( $wgUseSharedUploads ) {
101 if ( $wgSharedUploadDBname ) {
102 $wgForeignFileRepos[] = array(
103 'class' => 'ForeignDBRepo',
105 'directory' => $wgSharedUploadDirectory,
106 'url' => $wgSharedUploadPath,
107 'hashLevels' => $wgHashedSharedUploadDirectory ?
2 : 0,
108 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
109 'transformVia404' => !$wgGenerateThumbnailOnParse,
110 'dbType' => $wgDBtype,
111 'dbServer' => $wgDBserver,
112 'dbUser' => $wgDBuser,
113 'dbPassword' => $wgDBpassword,
114 'dbName' => $wgSharedUploadDBname,
115 'dbFlags' => ($wgDebugDumpSql ? DBO_DEBUG
: 0) | DBO_DEFAULT
,
116 'tablePrefix' => $wgSharedUploadDBprefix,
117 'hasSharedCache' => $wgCacheSharedUploads,
118 'descBaseUrl' => $wgRepositoryBaseUrl,
119 'fetchDescription' => $wgFetchCommonsDescriptions,
122 $wgForeignFileRepos[] = array(
125 'directory' => $wgSharedUploadDirectory,
126 'url' => $wgSharedUploadPath,
127 'hashLevels' => $wgHashedSharedUploadDirectory ?
2 : 0,
128 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
129 'transformVia404' => !$wgGenerateThumbnailOnParse,
130 'descBaseUrl' => $wgRepositoryBaseUrl,
131 'fetchDescription' => $wgFetchCommonsDescriptions,
135 if( $wgUseInstantCommons ) {
136 $wgForeignFileRepos[] = array(
137 'class' => 'ForeignAPIRepo',
138 'name' => 'wikimediacommons',
139 'apibase' => 'http://commons.wikimedia.org/w/api.php',
141 'fetchDescription' => true,
142 'descriptionCacheExpiry' => 43200,
143 'apiThumbCacheExpiry' => 86400,
147 if ( !class_exists( 'AutoLoader' ) ) {
148 require_once( "$IP/includes/AutoLoader.php" );
151 wfProfileIn( $fname.'-exception' );
152 require_once( "$IP/includes/Exception.php" );
153 wfInstallExceptionHandler();
154 wfProfileOut( $fname.'-exception' );
156 wfProfileIn( $fname.'-includes' );
157 require_once( "$IP/includes/GlobalFunctions.php" );
158 require_once( "$IP/includes/Hooks.php" );
159 require_once( "$IP/includes/Namespace.php" );
160 require_once( "$IP/includes/ProxyTools.php" );
161 require_once( "$IP/includes/ObjectCache.php" );
162 require_once( "$IP/includes/ImageFunctions.php" );
163 require_once( "$IP/includes/StubObject.php" );
164 wfProfileOut( $fname.'-includes' );
165 wfProfileIn( $fname.'-misc1' );
167 # Raise the memory limit if it's too low
171 * Set up the timezone, suppressing the pseudo-security warning in PHP 5.1+
172 * that happens whenever you use a date function without the timezone being
173 * explicitly set. Inspired by phpMyAdmin's treatment of the problem.
175 wfSuppressWarnings();
176 date_default_timezone_set( date_default_timezone_get() );
179 $wgIP = false; # Load on demand
180 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
181 $wgRequest = new WebRequest
;
183 # Useful debug output
184 if ( $wgCommandLineMode ) {
185 wfDebug( "\n\nStart command line script $self\n" );
187 wfDebug( "Start request\n\n" );
188 # Output the REQUEST_URI. This is not supported by IIS in rewrite mode,
189 # so use an alternative
190 $requestUri = isset( $_SERVER['REQUEST_URI'] ) ?
$_SERVER['REQUEST_URI'] :
191 ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ?
$_SERVER['HTTP_X_ORIGINAL_URL'] :
192 $_SERVER['PHP_SELF'] );
193 wfDebug( "{$_SERVER['REQUEST_METHOD']} {$requestUri}\n" );
195 if ( $wgDebugPrintHttpHeaders ) {
196 $headerOut = "HTTP HEADERS:\n";
198 if ( function_exists( 'getallheaders' ) ) {
199 $headers = getallheaders();
200 foreach ( $headers as $name => $value ) {
201 $headerOut .= "$name: $value\n";
205 foreach ( $headers as $name => $value ) {
206 if ( substr( $name, 0, 5 ) !== 'HTTP_' ) continue;
207 $name = substr( $name, 5 );
208 $headerOut .= "$name: $value\n";
211 wfDebug( "$headerOut\n" );
215 if( $wgRCFilterByAge ) {
216 ## Trim down $wgRCLinkDays so that it only lists links which are valid
217 ## as determined by $wgRCMaxAge.
218 ## Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
220 for( $i = 0; $i < count($wgRCLinkDays); $i++
) {
221 if( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
222 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i+
1, false );
229 $wgSkipSkins[] = $wgSkipSkin;
232 $wgUseEnotif = $wgEnotifUserTalk ||
$wgEnotifWatchlist;
234 if($wgMetaNamespace === FALSE) {
235 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
238 # These are now the same, always
239 # To determine the user language, use $wgLang->getCode()
240 $wgContLanguageCode = $wgLanguageCode;
242 # Easy to forget to falsify $wgShowIPinHeader for static caches.
243 # If file cache or squid cache is on, just disable this (DWIMD).
244 if( $wgUseFileCache ||
$wgUseSquid ) $wgShowIPinHeader = false;
246 # $wgAllowRealName and $wgAllowUserSkin were removed in 1.16
247 # in favor of $wgHiddenPrefs, handle b/c here
248 if( !$wgAllowRealName ) {
249 $wgHiddenPrefs[] = 'realname';
252 if( !$wgAllowUserSkin ) {
253 $wgHiddenPrefs[] = 'skin';
256 if ( !$wgHtml5Version && $wgHtml5 && $wgAllowRdfaAttributes ) {
257 # see http://www.w3.org/TR/rdfa-in-html/#document-conformance
258 if ( $wgMimeType == 'application/xhtml+xml' ) $wgHtml5Version = 'XHTML+RDFa 1.0';
259 else $wgHtml5Version = 'HTML+RDFa 1.0';
263 wfProfileOut( $fname.'-misc1' );
264 wfProfileIn( $fname.'-memcached' );
266 $wgMemc =& wfGetMainCache();
267 $messageMemc =& wfGetMessageCacheStorage();
268 $parserMemc =& wfGetParserCacheStorage();
270 wfDebug( 'CACHES: ' . get_class( $wgMemc ) . '[main] ' .
271 get_class( $messageMemc ) . '[message] ' .
272 get_class( $parserMemc ) . "[parser]\n" );
274 wfProfileOut( $fname.'-memcached' );
276 ## Most of the config is out, some might want to run hooks here.
277 wfRunHooks( 'SetupAfterCache' );
279 wfProfileIn( $fname.'-SetupSession' );
281 # Set default shared prefix
282 if( $wgSharedPrefix === false ) $wgSharedPrefix = $wgDBprefix;
284 if( !$wgCookiePrefix ) {
285 if ( $wgSharedDB && $wgSharedPrefix && in_array('user',$wgSharedTables) ) {
286 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
287 } elseif ( $wgSharedDB && in_array('user',$wgSharedTables) ) {
288 $wgCookiePrefix = $wgSharedDB;
289 } elseif ( $wgDBprefix ) {
290 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
292 $wgCookiePrefix = $wgDBname;
295 $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
297 # If session.auto_start is there, we can't touch session name
299 if( !wfIniGetBool( 'session.auto_start' ) )
300 session_name( $wgSessionName ?
$wgSessionName : $wgCookiePrefix . '_session' );
302 if( !defined( 'MW_NO_SESSION' ) ) {
303 if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() ||
isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
304 wfIncrStats( 'request_with_session' );
306 $wgSessionStarted = true;
308 wfIncrStats( 'request_without_session' );
309 $wgSessionStarted = false;
313 wfProfileOut( $fname.'-SetupSession' );
314 wfProfileIn( $fname.'-globals' );
316 $wgContLang = new StubContLang
;
318 // Now that variant lists may be available...
319 $wgRequest->interpolateTitle();
321 $wgUser = new StubUser
;
322 $wgLang = new StubUserLang
;
323 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
324 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
326 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
327 array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
329 wfProfileOut( $fname.'-globals' );
330 wfProfileIn( $fname.'-User' );
332 # Skin setup functions
333 # Entries can be added to this variable during the inclusion
334 # of the extension file. Skins can then perform any necessary initialisation.
336 foreach ( $wgSkinExtensionFunctions as $func ) {
337 call_user_func( $func );
340 if( !is_object( $wgAuth ) ) {
341 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
342 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
345 wfProfileOut( $fname.'-User' );
347 wfProfileIn( $fname.'-misc2' );
349 $wgDeferredUpdateList = array();
350 $wgPostCommitUpdateList = array();
352 if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'SpecialUpload::ajaxGetExistsWarning';
354 # Placeholders in case of DB error
358 wfProfileOut( $fname.'-misc2' );
359 wfProfileIn( $fname.'-extensions' );
361 # Extension setup functions for extensions other than skins
362 # Entries should be added to this variable during the inclusion
363 # of the extension file. This allows the extension to perform
364 # any necessary initialisation in the fully initialised environment
365 foreach ( $wgExtensionFunctions as $func ) {
366 # Allow closures in PHP 5.3+
367 if ( is_object( $func ) && $func instanceof Closure
) {
368 $profName = $fname.'-extensions-closure';
369 } elseif( is_array( $func ) ) {
370 if ( is_object( $func[0] ) )
371 $profName = $fname.'-extensions-'.get_class( $func[0] ).'::'.$func[1];
373 $profName = $fname.'-extensions-'.implode( '::', $func );
375 $profName = $fname.'-extensions-'.strval( $func );
378 wfProfileIn( $profName );
379 call_user_func( $func );
380 wfProfileOut( $profName );
384 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
385 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
386 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
387 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
389 if( !empty($wgNewUserLog) ) {
391 $wgLogTypes[] = 'newusers';
392 $wgLogNames['newusers'] = 'newuserlogpage';
393 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
394 $wgLogActions['newusers/newusers'] = 'newuserlogentry'; // For compatibility with older log entries
395 $wgLogActions['newusers/create'] = 'newuserlog-create-entry';
396 $wgLogActions['newusers/create2'] = 'newuserlog-create2-entry';
397 $wgLogActions['newusers/autocreate'] = 'newuserlog-autocreate-entry';
400 wfDebug( "Fully initialised\n" );
401 $wgFullyInitialised = true;
402 wfProfileOut( $fname.'-extensions' );
403 wfProfileOut( $fname );