3 * Include most things that's need to customize the site
9 * This file is not a valid entry point, perform no further processing unless
10 * MEDIAWIKI is defined
12 if( !defined( 'MEDIAWIKI' ) ) {
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.
23 wfProfileIn( $fname );
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";
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";
36 if( $wgArticlePath === false ) {
37 if( $wgUsePathInfo ) {
38 $wgArticlePath = "$wgScript/$1";
40 $wgArticlePath = "$wgScript?title=$1";
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";
49 if( $wgLogo === false ) $wgLogo = "$wgStylePath/common/images/wiki.png";
51 if( $wgUploadPath === false ) $wgUploadPath = "$wgScriptPath/images";
52 if( $wgUploadDirectory === false ) $wgUploadDirectory = "$IP/images";
54 if( $wgMathPath === false ) $wgMathPath = "{$wgUploadPath}/math";
55 if( $wgMathDirectory === false ) $wgMathDirectory = "{$wgUploadDirectory}/math";
56 if( $wgTmpDirectory === false ) $wgTmpDirectory = "{$wgUploadDirectory}/tmp";
58 if( $wgReadOnlyFile === false ) $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
59 if( $wgFileCacheDirectory === false ) $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
60 if( $wgDeletedDirectory === false ) $wgDeletedDirectory = "{$wgUploadDirectory}/deleted";
62 if( isset( $wgFileStore['deleted']['directory'] ) ) {
63 $wgDeletedDirectory = $wgFileStore['deleted']['directory'];
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,
78 unset($wgFooterIcons["copyright"]["copyright"]);
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";
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.
92 * Note that this is the definition of editinterface and it can be granted to
93 * all users if desired.
95 $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
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.
102 $wgNamespaceAliases['Image'] = NS_FILE;
103 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
106 * Initialise $wgLocalFileRepo from backwards-compatible settings
108 if ( !$wgLocalFileRepo ) {
109 if( isset( $wgFileStore['deleted']['hash'] ) ) {
110 $deletedHashLevel = $wgFileStore['deleted']['hash'];
112 $deletedHashLevel = $wgHashedUploadDirectory ? 3 : 0;
114 $wgLocalFileRepo = array(
115 'class' => 'LocalRepo',
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
129 * Initialise shared repo from backwards-compatible settings
131 if ( $wgUseSharedUploads ) {
132 if ( $wgSharedUploadDBname ) {
133 $wgForeignFileRepos[] = array(
134 'class' => 'ForeignDBRepo',
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,
153 $wgForeignFileRepos[] = array(
156 'directory' => $wgSharedUploadDirectory,
157 'url' => $wgSharedUploadPath,
158 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
159 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
160 'transformVia404' => !$wgGenerateThumbnailOnParse,
161 'descBaseUrl' => $wgRepositoryBaseUrl,
162 'fetchDescription' => $wgFetchCommonsDescriptions,
166 if( $wgUseInstantCommons ) {
167 $wgForeignFileRepos[] = array(
168 'class' => 'ForeignAPIRepo',
169 'name' => 'wikimediacommons',
170 'apibase' => 'http://commons.wikimedia.org/w/api.php',
172 'fetchDescription' => true,
173 'descriptionCacheExpiry' => 43200,
174 'apiThumbCacheExpiry' => 86400,
178 if ( !class_exists( 'AutoLoader' ) ) {
179 require_once( "$IP/includes/AutoLoader.php" );
182 wfProfileIn( $fname.'-exception' );
183 require_once( "$IP/includes/Exception.php" );
184 wfInstallExceptionHandler();
185 wfProfileOut( $fname.'-exception' );
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' );
197 # Raise the memory limit if it's too low
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.
205 wfSuppressWarnings();
206 date_default_timezone_set( date_default_timezone_get() );
209 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
210 $wgRequest = new WebRequest;
212 # Useful debug output
213 global $wgCommandLineMode;
214 if ( $wgCommandLineMode ) {
215 wfDebug( "\n\nStart command line script $self\n" );
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" );
225 if ( $wgDebugPrintHttpHeaders ) {
226 $headerOut = "HTTP HEADERS:\n";
228 if ( function_exists( 'getallheaders' ) ) {
229 $headers = getallheaders();
230 foreach ( $headers as $name => $value ) {
231 $headerOut .= "$name: $value\n";
235 foreach ( $headers as $name => $value ) {
236 if ( substr( $name, 0, 5 ) !== 'HTTP_' ) continue;
237 $name = substr( $name, 5 );
238 $headerOut .= "$name: $value\n";
241 wfDebug( "$headerOut\n" );
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.
250 for( $i = 0; $i < count($wgRCLinkDays); $i++ ) {
251 if( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
252 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i+1, false );
259 $wgSkipSkins[] = $wgSkipSkin;
262 $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
264 if($wgMetaNamespace === FALSE) {
265 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
268 # These are now the same, always
269 # To determine the user language, use $wgLang->getCode()
270 $wgContLanguageCode = $wgLanguageCode;
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;
276 # $wgAllowRealName and $wgAllowUserSkin were removed in 1.16
277 # in favor of $wgHiddenPrefs, handle b/c here
278 if( !$wgAllowRealName ) {
279 $wgHiddenPrefs[] = 'realname';
282 if( !$wgAllowUserSkin ) {
283 $wgHiddenPrefs[] = 'skin';
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';
292 if ( $wgInvalidateCacheOnLocalSettingsChange ) {
293 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( "$IP/LocalSettings.php" ) ) );
296 # Blacklisted file extensions shouldn't appear on the "allowed" list
297 $wgFileExtensions = array_diff ( $wgFileExtensions, $wgFileBlacklist );
299 wfProfileOut( $fname.'-misc1' );
300 wfProfileIn( $fname.'-memcached' );
302 $wgMemc =& wfGetMainCache();
303 $messageMemc =& wfGetMessageCacheStorage();
304 $parserMemc =& wfGetParserCacheStorage();
306 wfDebug( 'CACHES: ' . get_class( $wgMemc ) . '[main] ' .
307 get_class( $messageMemc ) . '[message] ' .
308 get_class( $parserMemc ) . "[parser]\n" );
310 wfProfileOut( $fname.'-memcached' );
312 ## Most of the config is out, some might want to run hooks here.
313 wfRunHooks( 'SetupAfterCache' );
315 wfProfileIn( $fname.'-SetupSession' );
317 # Set default shared prefix
318 if( $wgSharedPrefix === false ) $wgSharedPrefix = $wgDBprefix;
320 if( !$wgCookiePrefix ) {
321 if ( $wgSharedDB && $wgSharedPrefix && in_array('user',$wgSharedTables) ) {
322 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
323 } elseif ( $wgSharedDB && in_array('user',$wgSharedTables) ) {
324 $wgCookiePrefix = $wgSharedDB;
325 } elseif ( $wgDBprefix ) {
326 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
328 $wgCookiePrefix = $wgDBname;
331 $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
333 # If session.auto_start is there, we can't touch session name
335 if( !wfIniGetBool( 'session.auto_start' ) )
336 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
338 if( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
339 if( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) {
340 wfIncrStats( 'request_with_session' );
342 $wgSessionStarted = true;
344 wfIncrStats( 'request_without_session' );
345 $wgSessionStarted = false;
349 wfProfileOut( $fname.'-SetupSession' );
350 wfProfileIn( $fname.'-globals' );
352 $wgContLang = new StubContLang;
354 // Now that variant lists may be available...
355 $wgRequest->interpolateTitle();
356 $wgUser = $wgCommandLineMode ? new User : User::newFromSession();
357 $wgLang = new StubUserLang;
358 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
359 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
361 $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
362 array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry ) );
364 wfProfileOut( $fname.'-globals' );
365 wfProfileIn( $fname.'-User' );
367 # Skin setup functions
368 # Entries can be added to this variable during the inclusion
369 # of the extension file. Skins can then perform any necessary initialisation.
371 foreach ( $wgSkinExtensionFunctions as $func ) {
372 call_user_func( $func );
375 if( !is_object( $wgAuth ) ) {
376 $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
377 wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
380 wfProfileOut( $fname.'-User' );
382 wfProfileIn( $fname.'-misc2' );
384 $wgDeferredUpdateList = array();
386 if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'SpecialUpload::ajaxGetExistsWarning';
388 # Placeholders in case of DB error
392 wfProfileOut( $fname.'-misc2' );
393 wfProfileIn( $fname.'-extensions' );
395 # Extension setup functions for extensions other than skins
396 # Entries should be added to this variable during the inclusion
397 # of the extension file. This allows the extension to perform
398 # any necessary initialisation in the fully initialised environment
399 foreach ( $wgExtensionFunctions as $func ) {
400 # Allow closures in PHP 5.3+
401 if ( is_object( $func ) && $func instanceof Closure ) {
402 $profName = $fname.'-extensions-closure';
403 } elseif( is_array( $func ) ) {
404 if ( is_object( $func[0] ) )
405 $profName = $fname.'-extensions-'.get_class( $func[0] ).'::'.$func[1];
407 $profName = $fname.'-extensions-'.implode( '::', $func );
409 $profName = $fname.'-extensions-'.strval( $func );
412 wfProfileIn( $profName );
413 call_user_func( $func );
414 wfProfileOut( $profName );
418 wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
419 wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
420 wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
421 wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
423 if( !empty($wgNewUserLog) ) {
425 $wgLogTypes[] = 'newusers';
426 $wgLogNames['newusers'] = 'newuserlogpage';
427 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
428 $wgLogActions['newusers/newusers'] = 'newuserlogentry'; // For compatibility with older log entries
429 $wgLogActions['newusers/create'] = 'newuserlog-create-entry';
430 $wgLogActions['newusers/create2'] = 'newuserlog-create2-entry';
431 $wgLogActions['newusers/autocreate'] = 'newuserlog-autocreate-entry';
434 wfDebug( "Fully initialised\n" );
435 $wgFullyInitialised = true;
436 wfProfileOut( $fname.'-extensions' );
437 wfProfileOut( $fname );