r64165 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64164‎ | r64165 | r64166 >
Date:18:18, 25 March 2010
Author:jeluf
Status:ok
Tags:
Comment:
robots.php from wikimedia site
Modified paths:
  • /trunk/tools/robots.txt (added) (history)
  • /trunk/tools/robots.txt/robots.php (added) (history)

Diff [purge]

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

Status & tagging log