Index: trunk/tools/mwmultiversion/live-1.5/MWVersion.php |
— | — | @@ -1,64 +1,93 @@ |
2 | 2 | <?php |
3 | 3 | |
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; |
21 | 11 | } |
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"); |
24 | 20 | |
25 | | -function wfIsConverted( $host ) { |
26 | | - return true; |
| 21 | + $lang = $m[1]; |
| 22 | + $site = $m[2]; |
27 | 23 | |
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"); |
30 | 29 | |
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; |
38 | 69 | } |
39 | 70 | |
40 | 71 | 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'; |
47 | 81 | } |
48 | 82 | |
49 | 83 | if ( $host == 'test.wikipedia.org' && !$secure && |
50 | | - !preg_match( '!thumb\.php!', $_SERVER['REQUEST_URI'] ) ) { |
| 84 | + !preg_match( '!thumb\.php!', $_SERVER['REQUEST_URI'] ) ) { |
51 | 85 | define( 'TESTWIKI', 1 ); |
52 | 86 | // 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'; |
54 | 88 | $IP = "/home/wikipedia/common/$version"; |
55 | 89 | } else { |
56 | 90 | $IP = "/usr/local/apache/common/$version"; |
57 | 91 | } |
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 | | - #} |
63 | 92 | |
64 | 93 | chdir( $IP ); |
65 | 94 | putenv( "MW_INSTALL_PATH=$IP" ); |
— | — | @@ -66,3 +95,4 @@ |
67 | 96 | } |
68 | 97 | |
69 | 98 | ?> |
| 99 | + |