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" );
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" );
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" );
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.
208 for( $i = 0; $i < count($wgRCLinkDays); $i++
) {
209 if( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
210 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i+
1, false );
217 $wgSkipSkins[] = $wgSkipSkin;
220 $wgUseEnotif = $wgEnotifUserTalk ||
$wgEnotifWatchlist;
222 if($wgMetaNamespace === FALSE) {
223 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
226 # These are now the same, always
227 # To determine the user language, use $wgLang->getCode()
228 $wgContLanguageCode = $wgLanguageCode;
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;
234 # $wgAllowRealName and $wgAllowUserSkin were removed in 1.16
235 # in favor of $wgHiddenPrefs, handle b/c here
236 if( !$wgAllowRealName ) {
237 $wgHiddenPrefs[] = 'realname';
240 if( !$wgAllowUserSkin ) {
241 $wgHiddenPrefs[] = 'skin';
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';
251 wfProfileOut( $fname.'-misc1' );
252 wfProfileIn( $fname.'-memcached' );
254 $wgMemc =& wfGetMainCache();
255 $messageMemc =& wfGetMessageCacheStorage();
256 $parserMemc =& wfGetParserCacheStorage();
258 wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
259 "\nMessage cache: " . get_class( $messageMemc ) .
260 "\nParser cache: " . get_class( $parserMemc ) . "\n" );
262 wfProfileOut( $fname.'-memcached' );
264 ## Most of the config is out, some might want to run hooks here.
265 wfRunHooks( 'SetupAfterCache' );
267 wfProfileIn( $fname.'-SetupSession' );
269 # Set default shared prefix
270 if( $wgSharedPrefix === false ) $wgSharedPrefix = $wgDBprefix;
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;
280 $wgCookiePrefix = $wgDBname;
283 $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
285 # If session.auto_start is there, we can't touch session name
287 if( !wfIniGetBool( 'session.auto_start' ) )
288 session_name( $wgSessionName ?
$wgSessionName : $wgCookiePrefix . '_session' );
290 if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() ||
isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
291 wfIncrStats( 'request_with_session' );
293 $wgSessionStarted = true;
295 wfIncrStats( 'request_without_session' );
296 $wgSessionStarted = false;
299 wfProfileOut( $fname.'-SetupSession' );
300 wfProfileIn( $fname.'-globals' );
302 $wgContLang = new StubContLang
;
304 // Now that variant lists may be available...
305 $wgRequest->interpolateTitle();
307 $wgUser = new StubUser
;
308 $wgLang = new StubUserLang
;
309 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
310 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
312 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
313 array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
315 wfProfileOut( $fname.'-globals' );
316 wfProfileIn( $fname.'-User' );
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.
322 foreach ( $wgSkinExtensionFunctions as $func ) {
323 call_user_func( $func );
326 if( !is_object( $wgAuth ) ) {
327 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
328 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
331 wfProfileOut( $fname.'-User' );
333 wfProfileIn( $fname.'-misc2' );
335 $wgDeferredUpdateList = array();
336 $wgPostCommitUpdateList = array();
338 if ( $wgAjaxWatch ) $wgAjaxExportList[] = 'wfAjaxWatch';
339 if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'SpecialUpload::ajaxGetExistsWarning';
341 # Placeholders in case of DB error
345 wfProfileOut( $fname.'-misc2' );
346 wfProfileIn( $fname.'-extensions' );
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];
360 $profName = $fname.'-extensions-'.implode( '::', $func );
362 $profName = $fname.'-extensions-'.strval( $func );
365 wfProfileIn( $profName );
366 call_user_func( $func );
367 wfProfileOut( $profName );
371 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
372 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
373 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
374 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
376 if( !empty($wgNewUserLog) ) {
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';
387 wfDebug( "Fully initialised\n" );
388 $wgFullyInitialised = true;
389 wfProfileOut( $fname.'-extensions' );
390 wfProfileOut( $fname );