r89582 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89581‎ | r89582 | r89583 >
Date:17:02, 6 June 2011
Author:pdhanda
Status:deferred
Tags:
Comment:
First version of wrapper that can handle multiple versions. Working on localhost and prototype.wikimedia.org
Modified paths:
  • /trunk/tools/mwmultiversion/live-1.5/MWVersion.php (modified) (history)

Diff [purge]

Index: trunk/tools/mwmultiversion/live-1.5/MWVersion.php
@@ -1,64 +1,93 @@
22 <?php
33
4 -function host2db( $host ) {
5 - if( $host == 'wikimediafoundation.org' || $host == 'www.wikimediafoundation.org' )
6 - return 'foundationwiki';
7 - if ( $host == 'wikisource.org' || $host == 'www.wikisource.org' )
8 - return 'sourceswiki';
9 - if ( $host == 'mediawiki.org' || $host == 'www.mediawiki.org' )
10 - return 'mediawikiwiki';
11 - if( preg_match( '/^(.*)\.(.*)\.org$/', $host, $matches ) ) {
12 - list( $whole, $lang, $site ) = $matches;
13 - $lang = str_replace( '-', '_', $lang );
14 - switch( $site ) {
15 - case 'wikipedia':
16 - case 'wikimedia':
17 - return $lang . 'wiki';
18 - default:
19 - return $lang . $site;
20 - }
 4+function host2db() {
 5+ if ( $_SERVER['SERVER_NAME'] == 'localhost') {
 6+ $dbname = getenv( 'MW_DBNAME' );
 7+ if ( !isset( $dbname ) ) {
 8+ die( 'Unable to determine MW_DBNAME on localhost' );
 9+ }
 10+ return $dbname;
2111 }
22 - return null;
23 -}
 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");
2420
25 -function wfIsConverted( $host ) {
26 - return true;
 21+ $lang = $m[1];
 22+ $site = $m[2];
2723
28 - /*
29 - $db = host2db( $host );
 24+ if (in_array($lang, array("commons", "grants", "sources", "wikimania", "wikimania2006", "foundation", "meta")))
 25+ $site = "wikipedia";
 26+ } elseif( $secure ) {
 27+ if (!preg_match('/^([^.]+).([^.]+).*$/', $secure, $m))
 28+ die("invalid hostname");
3029
31 - #$all = array_map( 'trim', file( '/usr/local/apache/common/all.dblist' ) );
32 - #$started = array_map( 'trim', file( '/home/wikipedia/logs/conversion15start' ) );
33 -
34 - $converted = array_map( 'trim', file( '/usr/local/apache/common/1.17.dblist' ) );
35 - #$converted = array( 'test2wiki' );
36 - return in_array( $db, $converted );
37 - */
 30+ $lang = $m[1];
 31+ $site = $m[2];
 32+
 33+ if (in_array($lang, array("commons", "grants", "sources", "wikimania", "wikimania2006", "foundation", "meta")))
 34+ $site = "wikipedia";
 35+ } else {
 36+ if ( !isset( $site ) ) {
 37+ $site = "wikipedia";
 38+ if ( !isset( $lang ) ) {
 39+ $server = $_SERVER['SERVER_NAME'];
 40+ $docRoot = $_SERVER['DOCUMENT_ROOT'];
 41+
 42+ if ( preg_match( '/^(?:\/usr\/local\/apache\/|\/home\/wikipedia\/)(?:htdocs|common\/docroot)\/([a-z]+)\.org/', $docRoot, $matches ) ) {
 43+ $site = $matches[1];
 44+ if ( preg_match( '/^(.*)\.' . preg_quote( $site ) . '\.org$/', $server, $matches ) ) {
 45+ $lang = $matches[1];
 46+ // For some special subdomains, like pa.us
 47+ $lang = str_replace( '.', '-', $lang );
 48+ } else if ( preg_match( '/^(.*)\.prototype\.wikimedia\.org$/', $server, $matches ) ) {
 49+ $lang = $matches[1];
 50+ } else {
 51+ die( "Invalid host name ($server), can't determine language" );
 52+ }
 53+ } elseif ( preg_match( "/^\/usr\/local\/apache\/(?:htdocs|common\/docroot)\/([a-z0-9\-_]*)$/", $docRoot, $matches ) ) {
 54+ $site = "wikipedia";
 55+ $lang = $matches[1];
 56+ } else {
 57+ die( "Invalid host name (docroot=" . $_SERVER['DOCUMENT_ROOT'] . "), can't determine language" );
 58+ }
 59+ }
 60+ }
 61+ }
 62+ if ( $site == "wikipedia" ) {
 63+ $dbSuffix = "wiki";
 64+ } else {
 65+ $dbSuffix = $site;
 66+ }
 67+ $dbname = str_replace( "-", "_", $lang . $dbSuffix );
 68+ return $dbname;
3869 }
3970
4071 function getMediaWiki( $file ) {
41 - $secure = getenv( 'MW_SECURE_HOST' );
42 - $host = $secure ? $secure : $_SERVER['HTTP_HOST'];
43 - $new = wfIsConverted( $host );
44 - $version = $new ? 'php-1.17' : 'wmf-deployment';
45 - if ( $new ) {
46 - define( 'ONE_SEVENTEEN', 1 );
 72+ $dbname = host2db( );
 73+
 74+ $db = dba_open( '/usr/local/apache/common/wikiversions.db', 'r', 'cdb' );
 75+ if ( $db ) {
 76+ $version = dba_fetch( $dbname, $db );
 77+ } else {
 78+ //don't error for now
 79+ //trigger_error( "Unable to open /usr/local/apache/common/wikiversions.db. Assuming php-1.17", E_USER_ERROR );
 80+ $version = 'php-1.17';
4781 }
4882
4983 if ( $host == 'test.wikipedia.org' && !$secure &&
50 - !preg_match( '!thumb\.php!', $_SERVER['REQUEST_URI'] ) ) {
 84+ !preg_match( '!thumb\.php!', $_SERVER['REQUEST_URI'] ) ) {
5185 define( 'TESTWIKI', 1 );
5286 // As horrible hack for NFS-less iamge scalers, use regular docroot for thumbs?
53 -# $IP = '/home/wikipedia/common/php-1.5';
 87+ # $IP = '/home/wikipedia/common/php-1.5';
5488 $IP = "/home/wikipedia/common/$version";
5589 } else {
5690 $IP = "/usr/local/apache/common/$version";
5791 }
58 - #} elseif( $host == 'www.mediawiki.org' || $host == 'meta.wikimedia.org' ) {
59 - # $IP = '/usr/local/apache/common/wmf-deployment';
60 - #} else {
61 - # $IP = '/usr/local/apache/common/php-1.5';
62 - #}
6392
6493 chdir( $IP );
6594 putenv( "MW_INSTALL_PATH=$IP" );
@@ -66,3 +95,4 @@
6796 }
6897
6998 ?>
 99+

Status & tagging log