/tools/robots.txt/robots.php

https://github.com/ChuguluGames/mediawiki-svn · PHP · 92 lines · 69 code · 15 blank · 8 comment · 18 complexity · 8c835af1d3b009fbfe40db41fdb21cfb MD5 · raw file

  1. <?php
  2. //$lang = "meta";
  3. define( "MEDIAWIKI", true );
  4. #include_once("CommonSettings.php");
  5. #include_once("/apache/common/wmf-deployment/includes/ProfileStub.php" );
  6. #include_once("/apache/common/wmf-deployment/includes/Defines.php" );
  7. #include_once("/apache/common/wmf-deployment/wmf-config/CommonSettings.php");
  8. #include_once("Setup.php");
  9. include "/apache/common/live-1.5/MWVersion.php";
  10. include getMediaWiki("includes/WebStart.php");
  11. // determine language code
  12. $secure = getenv( 'MW_SECURE_HOST' );
  13. if ( (@$_SERVER['SCRIPT_NAME']) == '/w/thumb.php' && (@$_SERVER['SERVER_NAME']) == 'upload.wikimedia.org' ) {
  14. $pathBits = explode( '/', $_SERVER['PATH_INFO'] );
  15. $site = $pathBits[1];
  16. $lang = $pathBits[2];
  17. } elseif (php_sapi_name() == 'cgi-fcgi') {
  18. if (!preg_match('/^([^.]+).([^.]+).*$/', $_SERVER['SERVER_NAME'], $m))
  19. die("invalid hostname");
  20. $lang = $m[1];
  21. $site = $m[2];
  22. if (in_array($lang, array("commons", "grants", "sources", "wikimania", "wikimania2006", "foundation", "meta")))
  23. $site = "wikipedia";
  24. } elseif( $secure ) {
  25. if (!preg_match('/^([^.]+).([^.]+).*$/', $secure, $m))
  26. die("invalid hostname");
  27. $lang = $m[1];
  28. $site = $m[2];
  29. if (in_array($lang, array("commons", "grants", "sources", "wikimania", "wikimania2006", "foundation", "meta")))
  30. $site = "wikipedia";
  31. } else {
  32. if ( !isset( $site ) ) {
  33. $site = "wikipedia";
  34. if ( !isset( $lang ) ) {
  35. $server = $_SERVER['SERVER_NAME'];
  36. $docRoot = $_SERVER['DOCUMENT_ROOT'];
  37. if ( preg_match( '/^\/usr\/local\/apache\/(?:htdocs|common\/docroot)\/([a-z]+)\.org/', $docRoot, $matches ) ) {
  38. $site = $matches[1];
  39. if ( preg_match( '/^(.*)\.' . preg_quote( $site ) . '\.org$/', $server, $matches ) ) {
  40. $lang = $matches[1];
  41. // For some special subdomains, like pa.us
  42. $lang = str_replace( '.', '-', $lang );
  43. } else {
  44. die( "Invalid host name, can't determine language" );
  45. }
  46. } elseif ( preg_match( "/^\/usr\/local\/apache\/(?:htdocs|common\/docroot)\/([a-z0-9\-_]*)$/", $docRoot, $matches ) ) {
  47. $site = "wikipedia";
  48. $lang = $matches[1];
  49. } else {
  50. die( "Invalid host name (docroot=" . $_SERVER['DOCUMENT_ROOT'] . "), can't determine language" );
  51. }
  52. }
  53. }
  54. }
  55. $wgTitle = Title::newFromText( 'Mediawiki:robots.txt' );
  56. $wgArticle = new Article( $wgTitle );
  57. header( 'Content-Type: text/plain; charset=utf-8');
  58. header( 'X-Article-ID: ' . $wgArticle->getID() );
  59. header( 'X-Language: ' . $lang );
  60. header( 'X-Site: ' . $site );
  61. $robotsfile = "/apache/common/robots.txt";
  62. $robots = fopen( $robotsfile, 'rb' );
  63. $text='';
  64. header( 'Cache-Control: s-maxage=3600, must-revalidate, max-age=0' );
  65. if ( $wgArticle->getID() != 0 ) {
  66. $text = $wgArticle->getContent( false ) ;
  67. $lastmod = gmdate( 'D, j M Y H:i:s', wfTimestamp(TS_UNIX, $wgArticle->mTouched ) ) . ' GMT';
  68. header( "Last-modified: $lastmod" );
  69. } else {
  70. $stats = fstat( $robots );
  71. $lastmod = gmdate( 'D, j M Y H:i:s', $stats['mtime'] ) . ' GMT';
  72. header( "Last-modified: $lastmod" );
  73. header("Content-Length: " . filesize($robotsfile));
  74. }
  75. fpassthru( $robots );
  76. echo "#\n#\n#----------------------------------------------------------#\n#\n#\n#\n" . $text;
  77. ?>