PageRenderTime 22ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/mediawiki-1.16.5/includes/WebStart.php.commoncode

#
Unknown | 133 lines | 118 code | 15 blank | 0 comment | 0 complexity | 27a722e2317e40c5042cea87fb5bbf08 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-3.0, Apache-2.0
  1. <?php
  2. # This does the initial setup for a web request. It does some security checks,
  3. # starts the profiler and loads the configuration, and optionally loads
  4. # Setup.php depending on whether MW_NO_SETUP is defined.
  5. # Protect against register_globals
  6. # This must be done before any globals are set by the code
  7. if ( ini_get( 'register_globals' ) ) {
  8. if ( isset( $_REQUEST['GLOBALS'] ) ) {
  9. die( '<a href="http://www.hardened-php.net/index.76.html">$GLOBALS overwrite vulnerability</a>');
  10. }
  11. $verboten = array(
  12. 'GLOBALS',
  13. '_SERVER',
  14. 'HTTP_SERVER_VARS',
  15. '_GET',
  16. 'HTTP_GET_VARS',
  17. '_POST',
  18. 'HTTP_POST_VARS',
  19. '_COOKIE',
  20. 'HTTP_COOKIE_VARS',
  21. '_FILES',
  22. 'HTTP_POST_FILES',
  23. '_ENV',
  24. 'HTTP_ENV_VARS',
  25. '_REQUEST',
  26. '_SESSION',
  27. 'HTTP_SESSION_VARS'
  28. );
  29. foreach ( $_REQUEST as $name => $value ) {
  30. if( in_array( $name, $verboten ) ) {
  31. header( "HTTP/1.x 500 Internal Server Error" );
  32. echo "register_globals security paranoia: trying to overwrite superglobals, aborting.";
  33. die( -1 );
  34. }
  35. unset( $GLOBALS[$name] );
  36. }
  37. }
  38. $wgRequestTime = microtime(true);
  39. # getrusage() does not exist on the Microsoft Windows platforms, catching this
  40. if ( function_exists ( 'getrusage' ) ) {
  41. $wgRUstart = getrusage();
  42. } else {
  43. $wgRUstart = array();
  44. }
  45. unset( $IP );
  46. # Valid web server entry point, enable includes.
  47. # Please don't move this line to includes/Defines.php. This line essentially
  48. # defines a valid entry point. If you put it in includes/Defines.php, then
  49. # any script that includes it becomes an entry point, thereby defeating
  50. # its purpose.
  51. define( 'MEDIAWIKI', true );
  52. # Full path to working directory.
  53. # Makes it possible to for example to have effective exclude path in apc.
  54. # Also doesn't break installations using symlinked includes, like
  55. # dirname( __FILE__ ) would do.
  56. $IP = getenv( 'MW_INSTALL_PATH' );
  57. if ( $IP === false ) {
  58. $IP = realpath( '.' );
  59. }
  60. # Start profiler
  61. if( file_exists("$IP/StartProfiler.php") ) {
  62. require_once( "$IP/StartProfiler.php" );
  63. } else {
  64. require_once( "$IP/includes/ProfilerStub.php" );
  65. }
  66. wfProfileIn( 'WebStart.php-conf' );
  67. # Load up some global defines.
  68. require_once( "$IP/includes/Defines.php" );
  69. # Check for PHP 5
  70. if ( !function_exists( 'version_compare' )
  71. || version_compare( phpversion(), '5.0.0' ) < 0
  72. ) {
  73. define( 'MW_PHP4', '1' );
  74. require( "$IP/includes/DefaultSettings.php" );
  75. require( "$IP/includes/templates/PHP4.php" );
  76. exit;
  77. }
  78. # Test for PHP bug which breaks PHP 5.0.x on 64-bit...
  79. # As of 1.8 this breaks lots of common operations instead
  80. # of just some rare ones like export.
  81. $borked = str_replace( 'a', 'b', array( -1 => -1 ) );
  82. if( !isset( $borked[-1] ) ) {
  83. echo "PHP 5.0.x is buggy on your 64-bit system; you must upgrade to PHP 5.1.x\n" .
  84. "or higher. ABORTING. (http://bugs.php.net/bug.php?id=34879 for details)\n";
  85. exit;
  86. }
  87. # Start the autoloader, so that extensions can derive classes from core files
  88. require_once( "$IP/includes/AutoLoader.php" );
  89. if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
  90. # Use a callback function to configure MediaWiki
  91. require_once( "$IP/includes/DefaultSettings.php" );
  92. call_user_func( MW_CONFIG_CALLBACK );
  93. } else {
  94. # LocalSettings.php is the per site customization file. If it does not exit
  95. # the wiki installer need to be launched or the generated file moved from
  96. # ./config/ to ./
  97. if( !file_exists( "$IP/LocalSettings.php" ) ) {
  98. require_once( "$IP/includes/DefaultSettings.php" ); # used for printing the version
  99. require_once( "$IP/includes/templates/NoLocalSettings.php" );
  100. die();
  101. }
  102. # Include site settings. $IP may be changed (hopefully before the AutoLoader is invoked)
  103. require_once( "$IP/LocalSettings.php" );
  104. }
  105. wfProfileOut( 'WebStart.php-conf' );
  106. wfProfileIn( 'WebStart.php-ob_start' );
  107. # Initialise output buffering
  108. if ( ob_get_level() ) {
  109. # Someone's been mixing configuration data with code!
  110. # How annoying.
  111. } elseif ( !defined( 'MW_NO_OUTPUT_BUFFER' ) ) {
  112. require_once( "$IP/includes/OutputHandler.php" );
  113. ob_start( 'wfOutputHandler' );
  114. }
  115. wfProfileOut( 'WebStart.php-ob_start' );
  116. if ( !defined( 'MW_NO_SETUP' ) ) {
  117. require_once( "$IP/includes/Setup.php" );
  118. }