PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/mediawiki-1.16.5/includes/WebStart.php

#
PHP | 126 lines | 86 code | 14 blank | 26 comment | 16 complexity | c515f588c9d4dc86846bcc959a0f6a11 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. if (! isset($DIR)) $DIR = getcwd();
  53. $IP = '/usr/share/mediawiki';
  54. # Start profiler
  55. if( file_exists("$IP/StartProfiler.php") ) {
  56. require_once( "$IP/StartProfiler.php" );
  57. } else {
  58. require_once( "$IP/includes/ProfilerStub.php" );
  59. }
  60. wfProfileIn( 'WebStart.php-conf' );
  61. # Load up some global defines.
  62. require_once( "$IP/includes/Defines.php" );
  63. # Check for PHP 5
  64. if ( !function_exists( 'version_compare' )
  65. || version_compare( phpversion(), '5.0.0' ) < 0
  66. ) {
  67. define( 'MW_PHP4', '1' );
  68. require( "$IP/includes/DefaultSettings.php" );
  69. require( "$IP/includes/templates/PHP4.php" );
  70. exit;
  71. }
  72. # Test for PHP bug which breaks PHP 5.0.x on 64-bit...
  73. # As of 1.8 this breaks lots of common operations instead
  74. # of just some rare ones like export.
  75. $borked = str_replace( 'a', 'b', array( -1 => -1 ) );
  76. if( !isset( $borked[-1] ) ) {
  77. echo "PHP 5.0.x is buggy on your 64-bit system; you must upgrade to PHP 5.1.x\n" .
  78. "or higher. ABORTING. (http://bugs.php.net/bug.php?id=34879 for details)\n";
  79. exit;
  80. }
  81. # Start the autoloader, so that extensions can derive classes from core files
  82. require_once( "$IP/includes/AutoLoader.php" );
  83. if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
  84. # Use a callback function to configure MediaWiki
  85. require_once( "$IP/includes/DefaultSettings.php" );
  86. call_user_func( MW_CONFIG_CALLBACK );
  87. } else {
  88. # LocalSettings.php is the per site customization file. If it does not exit
  89. # the wiki installer need to be launched or the generated file moved from
  90. # ./config/ to ./
  91. if( !file_exists( "$DIR/LocalSettings.php" ) ) {
  92. require_once( "$IP/includes/DefaultSettings.php" ); # used for printing the version
  93. require_once( "$IP/includes/templates/NoLocalSettings.php" );
  94. die();
  95. }
  96. # Include site settings.
  97. require_once( "$DIR/LocalSettings.php" );
  98. }
  99. wfProfileOut( 'WebStart.php-conf' );
  100. wfProfileIn( 'WebStart.php-ob_start' );
  101. # Initialise output buffering
  102. if ( ob_get_level() ) {
  103. # Someone's been mixing configuration data with code!
  104. # How annoying.
  105. } elseif ( !defined( 'MW_NO_OUTPUT_BUFFER' ) ) {
  106. require_once( "$IP/includes/OutputHandler.php" );
  107. ob_start( 'wfOutputHandler' );
  108. }
  109. wfProfileOut( 'WebStart.php-ob_start' );
  110. if ( !defined( 'MW_NO_SETUP' ) ) {
  111. require_once( "$IP/includes/Setup.php" );
  112. }