PageRenderTime 65ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/WebStart.php

https://bitbucket.org/kgrashad/thawrapedia
PHP | 141 lines | 89 code | 17 blank | 35 comment | 20 complexity | ed2c6b6f9f3f3041af23e5c74cf43187 MD5 | raw file
Possible License(s): GPL-2.0, Apache-2.0, LGPL-3.0
  1. <?php
  2. /**
  3. * This does the initial setup for a web request.
  4. * It does some security checks, starts the profiler and loads the
  5. * configuration, and optionally loads Setup.php depending on whether
  6. * MW_NO_SETUP is defined.
  7. *
  8. * @file
  9. */
  10. # Protect against register_globals
  11. # This must be done before any globals are set by the code
  12. if ( ini_get( 'register_globals' ) ) {
  13. if ( isset( $_REQUEST['GLOBALS'] ) ) {
  14. die( '<a href="http://www.hardened-php.net/globals-problem">$GLOBALS overwrite vulnerability</a>');
  15. }
  16. $verboten = array(
  17. 'GLOBALS',
  18. '_SERVER',
  19. 'HTTP_SERVER_VARS',
  20. '_GET',
  21. 'HTTP_GET_VARS',
  22. '_POST',
  23. 'HTTP_POST_VARS',
  24. '_COOKIE',
  25. 'HTTP_COOKIE_VARS',
  26. '_FILES',
  27. 'HTTP_POST_FILES',
  28. '_ENV',
  29. 'HTTP_ENV_VARS',
  30. '_REQUEST',
  31. '_SESSION',
  32. 'HTTP_SESSION_VARS'
  33. );
  34. foreach ( $_REQUEST as $name => $value ) {
  35. if( in_array( $name, $verboten ) ) {
  36. header( "HTTP/1.1 500 Internal Server Error" );
  37. echo "register_globals security paranoia: trying to overwrite superglobals, aborting.";
  38. die( -1 );
  39. }
  40. unset( $GLOBALS[$name] );
  41. }
  42. }
  43. $wgRequestTime = microtime(true);
  44. # getrusage() does not exist on the Microsoft Windows platforms, catching this
  45. if ( function_exists ( 'getrusage' ) ) {
  46. $wgRUstart = getrusage();
  47. } else {
  48. $wgRUstart = array();
  49. }
  50. unset( $IP );
  51. # Valid web server entry point, enable includes.
  52. # Please don't move this line to includes/Defines.php. This line essentially
  53. # defines a valid entry point. If you put it in includes/Defines.php, then
  54. # any script that includes it becomes an entry point, thereby defeating
  55. # its purpose.
  56. define( 'MEDIAWIKI', true );
  57. # Full path to working directory.
  58. # Makes it possible to for example to have effective exclude path in apc.
  59. # Also doesn't break installations using symlinked includes, like
  60. # dirname( __FILE__ ) would do.
  61. $IP = getenv( 'MW_INSTALL_PATH' );
  62. if ( $IP === false ) {
  63. $IP = realpath( '.' );
  64. }
  65. # Start profiler
  66. if( file_exists("$IP/StartProfiler.php") ) {
  67. require_once( "$IP/StartProfiler.php" );
  68. } else {
  69. require_once( "$IP/includes/ProfilerStub.php" );
  70. }
  71. wfProfileIn( 'WebStart.php-conf' );
  72. # Load up some global defines.
  73. require_once( "$IP/includes/Defines.php" );
  74. # Check for PHP 5
  75. if ( !function_exists( 'version_compare' )
  76. || version_compare( phpversion(), '5.0.0' ) < 0
  77. ) {
  78. define( 'MW_PHP4', '1' );
  79. require( "$IP/includes/DefaultSettings.php" );
  80. require( "$IP/includes/templates/PHP4.php" );
  81. exit;
  82. }
  83. # Start the autoloader, so that extensions can derive classes from core files
  84. require_once( "$IP/includes/AutoLoader.php" );
  85. # Load default settings
  86. require_once( "$IP/includes/DefaultSettings.php" );
  87. if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
  88. # Use a callback function to configure MediaWiki
  89. $callback = MW_CONFIG_CALLBACK;
  90. # PHP 5.1 doesn't support "class::method" for call_user_func, so split it
  91. if ( strpos( $callback, '::' ) !== false ) {
  92. $callback = explode( '::', $callback, 2);
  93. }
  94. call_user_func( $callback );
  95. } else {
  96. if ( !defined('MW_CONFIG_FILE') )
  97. define('MW_CONFIG_FILE', "$IP/LocalSettings.php");
  98. # LocalSettings.php is the per site customization file. If it does not exist
  99. # the wiki installer needs to be launched or the generated file uploaded to
  100. # the root wiki directory
  101. if( !file_exists( MW_CONFIG_FILE ) ) {
  102. require_once( "$IP/includes/templates/NoLocalSettings.php" );
  103. die();
  104. }
  105. # Include site settings. $IP may be changed (hopefully before the AutoLoader is invoked)
  106. require_once( MW_CONFIG_FILE );
  107. }
  108. if ( $wgEnableSelenium ) {
  109. require_once( "$IP/includes/SeleniumWebSettings.php" );
  110. }
  111. wfProfileOut( 'WebStart.php-conf' );
  112. wfProfileIn( 'WebStart.php-ob_start' );
  113. # Initialise output buffering
  114. # Check that there is no previous output or previously set up buffers, because
  115. # that would cause us to potentially mix gzip and non-gzip output, creating a
  116. # big mess.
  117. if ( !defined( 'MW_NO_OUTPUT_BUFFER' ) && ob_get_level() == 0 ) {
  118. require_once( "$IP/includes/OutputHandler.php" );
  119. ob_start( 'wfOutputHandler' );
  120. }
  121. wfProfileOut( 'WebStart.php-ob_start' );
  122. if ( !defined( 'MW_NO_SETUP' ) ) {
  123. require_once( "$IP/includes/Setup.php" );
  124. }