Setup.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <?php
  2. /**
  3. * Include most things that's need to customize the site
  4. */
  5. /**
  6. * This file is not a valid entry point, perform no further processing unless
  7. * MEDIAWIKI is defined
  8. */
  9. if( !defined( 'MEDIAWIKI' ) ) {
  10. echo "This file is part of MediaWiki, it is not a valid entry point.\n";
  11. exit( 1 );
  12. }
  13. # The main wiki script and things like database
  14. # conversion and maintenance scripts all share a
  15. # common setup of including lots of classes and
  16. # setting up a few globals.
  17. #
  18. $fname = 'Setup.php';
  19. wfProfileIn( $fname );
  20. // Check to see if we are at the file scope
  21. if ( !isset( $wgVersion ) ) {
  22. echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
  23. die( 1 );
  24. }
  25. // Set various default paths sensibly...
  26. if( $wgScript === false ) $wgScript = "$wgScriptPath/index$wgScriptExtension";
  27. if( $wgRedirectScript === false ) $wgRedirectScript = "$wgScriptPath/redirect$wgScriptExtension";
  28. if( $wgArticlePath === false ) {
  29. if( $wgUsePathInfo ) {
  30. $wgArticlePath = "$wgScript/$1";
  31. } else {
  32. $wgArticlePath = "$wgScript?title=$1";
  33. }
  34. }
  35. if( $wgStylePath === false ) $wgStylePath = "$wgScriptPath/skins";
  36. if( $wgStyleDirectory === false) $wgStyleDirectory = "$IP/skins";
  37. if( $wgLogo === false ) $wgLogo = "$wgStylePath/common/images/wiki.png";
  38. if( $wgUploadPath === false ) $wgUploadPath = "$wgScriptPath/images";
  39. if( $wgUploadDirectory === false ) $wgUploadDirectory = "$IP/images";
  40. if( $wgMathPath === false ) $wgMathPath = "{$wgUploadPath}/math";
  41. if( $wgMathDirectory === false ) $wgMathDirectory = "{$wgUploadDirectory}/math";
  42. if( $wgTmpDirectory === false ) $wgTmpDirectory = "{$wgUploadDirectory}/tmp";
  43. if( $wgReadOnlyFile === false ) $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
  44. if( $wgFileCacheDirectory === false ) $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
  45. if ( empty( $wgFileStore['deleted']['directory'] ) ) {
  46. $wgFileStore['deleted']['directory'] = "{$wgUploadDirectory}/deleted";
  47. }
  48. /**
  49. * Unconditional protection for NS_MEDIAWIKI since otherwise it's too easy for a
  50. * sysadmin to set $wgNamespaceProtection incorrectly and leave the wiki insecure.
  51. *
  52. * Note that this is the definition of editinterface and it can be granted to
  53. * all users if desired.
  54. */
  55. $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
  56. /**
  57. * The canonical names of namespaces 6 and 7 are, as of v1.14, "File"
  58. * and "File_talk". The old names "Image" and "Image_talk" are
  59. * retained as aliases for backwards compatibility.
  60. */
  61. $wgNamespaceAliases['Image'] = NS_FILE;
  62. $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
  63. /**
  64. * Initialise $wgLocalFileRepo from backwards-compatible settings
  65. */
  66. if ( !$wgLocalFileRepo ) {
  67. $wgLocalFileRepo = array(
  68. 'class' => 'LocalRepo',
  69. 'name' => 'local',
  70. 'directory' => $wgUploadDirectory,
  71. 'url' => $wgUploadBaseUrl ? $wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
  72. 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
  73. 'thumbScriptUrl' => $wgThumbnailScriptPath,
  74. 'transformVia404' => !$wgGenerateThumbnailOnParse,
  75. 'initialCapital' => $wgCapitalLinks,
  76. 'deletedDir' => $wgFileStore['deleted']['directory'],
  77. 'deletedHashLevels' => $wgFileStore['deleted']['hash']
  78. );
  79. }
  80. /**
  81. * Initialise shared repo from backwards-compatible settings
  82. */
  83. if ( $wgUseSharedUploads ) {
  84. if ( $wgSharedUploadDBname ) {
  85. $wgForeignFileRepos[] = array(
  86. 'class' => 'ForeignDBRepo',
  87. 'name' => 'shared',
  88. 'directory' => $wgSharedUploadDirectory,
  89. 'url' => $wgSharedUploadPath,
  90. 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
  91. 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
  92. 'transformVia404' => !$wgGenerateThumbnailOnParse,
  93. 'dbType' => $wgDBtype,
  94. 'dbServer' => $wgDBserver,
  95. 'dbUser' => $wgDBuser,
  96. 'dbPassword' => $wgDBpassword,
  97. 'dbName' => $wgSharedUploadDBname,
  98. 'dbFlags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT,
  99. 'tablePrefix' => $wgSharedUploadDBprefix,
  100. 'hasSharedCache' => $wgCacheSharedUploads,
  101. 'descBaseUrl' => $wgRepositoryBaseUrl,
  102. 'fetchDescription' => $wgFetchCommonsDescriptions,
  103. );
  104. } else {
  105. $wgForeignFileRepos[] = array(
  106. 'class' => 'FSRepo',
  107. 'name' => 'shared',
  108. 'directory' => $wgSharedUploadDirectory,
  109. 'url' => $wgSharedUploadPath,
  110. 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
  111. 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
  112. 'transformVia404' => !$wgGenerateThumbnailOnParse,
  113. 'descBaseUrl' => $wgRepositoryBaseUrl,
  114. 'fetchDescription' => $wgFetchCommonsDescriptions,
  115. );
  116. }
  117. }
  118. if ( !class_exists( 'AutoLoader' ) ) {
  119. require_once( "$IP/includes/AutoLoader.php" );
  120. }
  121. wfProfileIn( $fname.'-exception' );
  122. require_once( "$IP/includes/Exception.php" );
  123. wfInstallExceptionHandler();
  124. wfProfileOut( $fname.'-exception' );
  125. wfProfileIn( $fname.'-includes' );
  126. require_once( "$IP/includes/GlobalFunctions.php" );
  127. require_once( "$IP/includes/Hooks.php" );
  128. require_once( "$IP/includes/Namespace.php" );
  129. require_once( "$IP/includes/ProxyTools.php" );
  130. require_once( "$IP/includes/ObjectCache.php" );
  131. require_once( "$IP/includes/ImageFunctions.php" );
  132. require_once( "$IP/includes/StubObject.php" );
  133. wfProfileOut( $fname.'-includes' );
  134. wfProfileIn( $fname.'-misc1' );
  135. $wgIP = false; # Load on demand
  136. # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
  137. $wgRequest = new WebRequest;
  138. # Useful debug output
  139. if ( $wgCommandLineMode ) {
  140. if ( isset($self) ) {
  141. wfDebug( "\n\nStart command line script $self\n" );
  142. } else {
  143. wfDebug( "\n\nStart command line script *unknown*\n" );
  144. }
  145. } elseif ( function_exists( 'getallheaders' ) ) {
  146. wfDebug( "\n\nStart request\n" );
  147. wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
  148. $headers = getallheaders();
  149. foreach ($headers as $name => $value) {
  150. wfDebug( "$name: $value\n" );
  151. }
  152. wfDebug( "\n" );
  153. } elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
  154. wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
  155. }
  156. if( $wgRCFilterByAge ) {
  157. ## Trim down $wgRCLinkDays so that it only lists links which are valid
  158. ## as determined by $wgRCMaxAge.
  159. ## Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
  160. sort($wgRCLinkDays);
  161. for( $i = 0; $i < count($wgRCLinkDays); $i++ ) {
  162. if( $wgRCLinkDays[$i] >= $wgRCMaxAge / ( 3600 * 24 ) ) {
  163. $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i+1, false );
  164. break;
  165. }
  166. }
  167. }
  168. if ( $wgSkipSkin ) {
  169. $wgSkipSkins[] = $wgSkipSkin;
  170. }
  171. $wgUseEnotif = $wgEnotifUserTalk || $wgEnotifWatchlist;
  172. if($wgMetaNamespace === FALSE) {
  173. $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
  174. }
  175. # These are now the same, always
  176. # To determine the user language, use $wgLang->getCode()
  177. $wgContLanguageCode = $wgLanguageCode;
  178. # Easy to forget to falsify $wgShowIPinHeader for static caches.
  179. # If file cache or squid cache is on, just disable this (DWIMD).
  180. if( $wgUseFileCache || $wgUseSquid ) $wgShowIPinHeader = false;
  181. wfProfileOut( $fname.'-misc1' );
  182. wfProfileIn( $fname.'-memcached' );
  183. $wgMemc =& wfGetMainCache();
  184. $messageMemc =& wfGetMessageCacheStorage();
  185. $parserMemc =& wfGetParserCacheStorage();
  186. wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
  187. "\nMessage cache: " . get_class( $messageMemc ) .
  188. "\nParser cache: " . get_class( $parserMemc ) . "\n" );
  189. wfProfileOut( $fname.'-memcached' );
  190. ## Most of the config is out, some might want to run hooks here.
  191. wfRunHooks( 'SetupAfterCache' );
  192. wfProfileIn( $fname.'-SetupSession' );
  193. # Set default shared prefix
  194. if( $wgSharedPrefix === false ) $wgSharedPrefix = $wgDBprefix;
  195. if( !$wgCookiePrefix ) {
  196. if ( $wgSharedDB && $wgSharedPrefix && in_array('user',$wgSharedTables) ) {
  197. $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
  198. } elseif ( $wgSharedDB && in_array('user',$wgSharedTables) ) {
  199. $wgCookiePrefix = $wgSharedDB;
  200. } elseif ( $wgDBprefix ) {
  201. $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
  202. } else {
  203. $wgCookiePrefix = $wgDBname;
  204. }
  205. }
  206. $wgCookiePrefix = strtr($wgCookiePrefix, "=,; +.\"'\\[", "__________");
  207. # If session.auto_start is there, we can't touch session name
  208. #
  209. if( !wfIniGetBool( 'session.auto_start' ) )
  210. session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
  211. if( !$wgCommandLineMode && ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix.'Token'] ) ) ) {
  212. wfIncrStats( 'request_with_session' );
  213. wfSetupSession();
  214. $wgSessionStarted = true;
  215. } else {
  216. wfIncrStats( 'request_without_session' );
  217. $wgSessionStarted = false;
  218. }
  219. wfProfileOut( $fname.'-SetupSession' );
  220. wfProfileIn( $fname.'-globals' );
  221. $wgContLang = new StubContLang;
  222. // Now that variant lists may be available...
  223. $wgRequest->interpolateTitle();
  224. $wgUser = new StubUser;
  225. $wgLang = new StubUserLang;
  226. $wgOut = new StubObject( 'wgOut', 'OutputPage' );
  227. $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
  228. $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
  229. array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
  230. wfProfileOut( $fname.'-globals' );
  231. wfProfileIn( $fname.'-User' );
  232. # Skin setup functions
  233. # Entries can be added to this variable during the inclusion
  234. # of the extension file. Skins can then perform any necessary initialisation.
  235. #
  236. foreach ( $wgSkinExtensionFunctions as $func ) {
  237. call_user_func( $func );
  238. }
  239. if( !is_object( $wgAuth ) ) {
  240. $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
  241. wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
  242. }
  243. wfProfileOut( $fname.'-User' );
  244. wfProfileIn( $fname.'-misc2' );
  245. $wgDeferredUpdateList = array();
  246. $wgPostCommitUpdateList = array();
  247. if ( $wgAjaxWatch ) $wgAjaxExportList[] = 'wfAjaxWatch';
  248. if ( $wgAjaxUploadDestCheck ) $wgAjaxExportList[] = 'UploadForm::ajaxGetExistsWarning';
  249. if( $wgAjaxLicensePreview )
  250. $wgAjaxExportList[] = 'UploadForm::ajaxGetLicensePreview';
  251. # Placeholders in case of DB error
  252. $wgTitle = null;
  253. $wgArticle = null;
  254. wfProfileOut( $fname.'-misc2' );
  255. wfProfileIn( $fname.'-extensions' );
  256. # Extension setup functions for extensions other than skins
  257. # Entries should be added to this variable during the inclusion
  258. # of the extension file. This allows the extension to perform
  259. # any necessary initialisation in the fully initialised environment
  260. foreach ( $wgExtensionFunctions as $func ) {
  261. $profName = $fname.'-extensions-'.strval( $func );
  262. wfProfileIn( $profName );
  263. call_user_func( $func );
  264. wfProfileOut( $profName );
  265. }
  266. // For compatibility
  267. wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
  268. wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
  269. wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
  270. wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
  271. if( !empty($wgNewUserLog) ) {
  272. # Add a new log type
  273. $wgLogTypes[] = 'newusers';
  274. $wgLogNames['newusers'] = 'newuserlogpage';
  275. $wgLogHeaders['newusers'] = 'newuserlogpagetext';
  276. $wgLogActions['newusers/newusers'] = 'newuserlogentry'; // For compatibility with older log entries
  277. $wgLogActions['newusers/create'] = 'newuserlog-create-entry';
  278. $wgLogActions['newusers/create2'] = 'newuserlog-create2-entry';
  279. $wgLogActions['newusers/autocreate'] = 'newuserlog-autocreate-entry';
  280. }
  281. wfDebug( "Fully initialised\n" );
  282. $wgFullyInitialised = true;
  283. wfProfileOut( $fname.'-extensions' );
  284. wfProfileOut( $fname );