Index: trunk/tools/mwmultiversion/live-1.5/MWVersion.php |
— | — | @@ -1,20 +1,13 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | function getMediaWiki( $file ) { |
5 | | -$dbname = $multiVersion->getDatabase( $siteInfo['site'], $siteInfo['lang']); |
6 | 5 | $secure = getenv( 'MW_SECURE_HOST' ); |
7 | 6 | $host = $secure ? $secure : $_SERVER['HTTP_HOST']; |
8 | 7 | |
9 | 8 | require( dirname( __FILE__ ) . '/../wmf-config/MWMultiVersion.php' ); |
10 | | - $multiVersion = new MWMultiVersion; |
11 | | - $siteInfo = array(); |
12 | | - if ( (@$_SERVER['SCRIPT_NAME']) == '/w/thumb.php' && (@$_SERVER['SERVER_NAME']) == 'upload.wikimedia.org' ) { |
13 | | - $siteInfo = $multiVersion->getUploadSiteInfo( $_SERVER['PATH_INFO'] ); |
14 | | - } else { |
15 | | - $siteInfo = $multiVersion->getSiteInfo( $_SERVER['SERVER_NAME'], $_SERVER['DOCUMENT_ROOT'] ); |
16 | | - } |
| 9 | + $multiVersion = MWMultiVersion::getInstanceForWiki( $_SERVER['SERVER_NAME'], $_SERVER['DOCUMENT_ROOT'] ); |
17 | 10 | |
18 | | - $version = $multiVersion->getVersion( $siteInfo['site'], $siteInfo['lang']); |
| 11 | + $version = $multiVersion->getVersion(); |
19 | 12 | |
20 | 13 | if ( $host == 'test.wikipedia.org' && !$secure && |
21 | 14 | !preg_match( '!thumb\.php!', $_SERVER['REQUEST_URI'] ) ) { |
Index: trunk/tools/mwmultiversion/wmf-config/CommonSettings.php |
— | — | @@ -97,18 +97,17 @@ |
98 | 98 | wfProfileOut( "$fname-init" ); |
99 | 99 | wfProfileIn( "$fname-host" ); |
100 | 100 | |
101 | | -# Determine domain and language |
| 101 | +# Determine domain and language and the directories for this instance |
102 | 102 | require_once( $IP . '/../wmf-config/MWMultiVersion.php' ); |
103 | | -$multiVersion = new MWMultiVersion; |
104 | | -$siteInfo = array(); |
105 | 103 | if ( (@$_SERVER['SCRIPT_NAME']) == '/w/thumb.php' && (@$_SERVER['SERVER_NAME']) == 'upload.wikimedia.org' ) { |
106 | | - $siteInfo = $multiVersion->getUploadSiteInfo( $_SERVER['PATH_INFO'] ); |
| 104 | + $multiVersion = MWMultiVersion::getInstanceForUploadWiki( $_SERVER['PATH_INFO'] ); |
107 | 105 | } else { |
108 | | - $siteInfo = $multiVersion->getSiteInfo( $_SERVER['SERVER_NAME'], $_SERVER['DOCUMENT_ROOT'] ); |
| 106 | + $multiVersion = MWMultiVersion::getInstanceForWiki( $_SERVER['SERVER_NAME'], $_SERVER['DOCUMENT_ROOT'] ); |
109 | 107 | } |
110 | | -$site = $siteInfo['site']; |
111 | | -$lang = $siteInfo['lang']; |
112 | | -$wgDBname = $multiVersion->getDatabase( $site, $lang); |
| 108 | +$site = $multiVersion->getSite(); |
| 109 | +$lang = $multiVersion->getLang(); |
| 110 | +$wgDBname = $multiVersion->getDatabase(); |
| 111 | +$wgVersionDirectory = $multiVersion->getVersion(); |
113 | 112 | |
114 | 113 | # Disabled, no IPv6 support, waste of a regex -- TS 20051207 |
115 | 114 | /* |
— | — | @@ -117,15 +116,6 @@ |
118 | 117 | $ipv6 = true; |
119 | 118 | }*/ |
120 | 119 | |
121 | | - |
122 | | -//changed for hetdeploy testing --pdhanda |
123 | | -$match = array(); |
124 | | -if ( preg_match("/^[0-9.]*/", $wgVersion, $match) ) { |
125 | | - $wgVersionDirectory = $match[0]; |
126 | | -} else { |
127 | | - $wgVersionDirectory = "1.17"; |
128 | | -} |
129 | | - |
130 | 120 | # Shutting eswiki down |
131 | 121 | #if ( $wgDBname == 'eswiki' && php_sapi_name() != 'cli' ) { die(); } |
132 | 122 | |
Index: trunk/tools/mwmultiversion/wmf-config/MWMultiVersion.php |
— | — | @@ -1,88 +1,130 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | class MWMultiVersion { |
| 5 | + private static $mwversion; |
| 6 | + private $site; |
| 7 | + private $lang; |
5 | 8 | |
6 | | - function getSiteInfo( $serverName, $docRoot ) { |
| 9 | + /** |
| 10 | + * To get an inststance of this class, use the statuc helper methods. |
| 11 | + * @see getInstanceForWiki |
| 12 | + * @see getInstanceForUploadWiki |
| 13 | + */ |
| 14 | + private function __construct() { |
| 15 | + } |
| 16 | + |
| 17 | + /** |
| 18 | + * Derives site and lang from the parameters and sets $site and $lang on the instance |
| 19 | + * @param $serverName the ServerName for this wiki -- $_SERVER['SERVER_NAME'] |
| 20 | + * @docroot the DocumentRoot for this wiki -- $_SERVER['DOCUMENT_ROOT'] |
| 21 | + */ |
| 22 | + private function setSiteInfoForWiki( $serverName, $docRoot) { |
| 23 | + //print "serverName " . $serverName . " docRoot " . $docRoot; die(); |
7 | 24 | $secure = getenv( 'MW_SECURE_HOST' ); |
8 | 25 | $matches = array(); |
9 | 26 | if (php_sapi_name() == 'cgi-fcgi') { |
10 | 27 | if (!preg_match('/^([^.]+).([^.]+).*$/', $serverName, $matches)) |
11 | 28 | die("invalid hostname"); |
12 | 29 | |
13 | | - $lang = $matches[1]; |
14 | | - $site = $$matches[2]; |
| 30 | + $this->lang = $matches[1]; |
| 31 | + $this->site = $$matches[2]; |
15 | 32 | |
16 | | - if (in_array($lang, array("commons", "grants", "sources", "wikimania", "wikimania2006", "foundation", "meta"))) |
17 | | - $site = "wikipedia"; |
| 33 | + if (in_array($this->lang, array("commons", "grants", "sources", "wikimania", "wikimania2006", "foundation", "meta"))) |
| 34 | + $this->site = "wikipedia"; |
18 | 35 | } elseif( $secure ) { |
19 | 36 | if (!preg_match('/^([^.]+).([^.]+).*$/', $secure, $$matches)) |
20 | 37 | die("invalid hostname"); |
21 | 38 | |
22 | | - $lang = $$matches[1]; |
23 | | - $site = $$matches[2]; |
| 39 | + $this->lang = $$matches[1]; |
| 40 | + $this->site = $$matches[2]; |
24 | 41 | |
25 | | - if (in_array($lang, array("commons", "grants", "sources", "wikimania", "wikimania2006", "foundation", "meta"))) |
26 | | - $site = "wikipedia"; |
| 42 | + if (in_array($this->lang, array("commons", "grants", "sources", "wikimania", "wikimania2006", "foundation", "meta"))) |
| 43 | + $this->site = "wikipedia"; |
27 | 44 | } else { |
28 | | - if ( !isset( $site ) ) { |
29 | | - $site = "wikipedia"; |
30 | | - if ( !isset( $lang ) ) { |
| 45 | + if ( !isset( $this->site ) ) { |
| 46 | + $this->site = "wikipedia"; |
| 47 | + if ( !isset( $this->lang ) ) { |
31 | 48 | if ( preg_match( '/^(?:\/usr\/local\/apache\/|\/home\/wikipedia\/)(?:htdocs|common\/docroot)\/([a-z]+)\.org/', $docRoot, $matches ) ) { |
32 | | - $site = $matches[1]; |
33 | | - if ( preg_match( '/^(.*)\.' . preg_quote( $site ) . '\.org$/', $serverName, $matches ) ) { |
34 | | - $lang = $matches[1]; |
| 49 | + $this->site = $matches[1]; |
| 50 | + if ( preg_match( '/^(.*)\.' . preg_quote( $this->site ) . '\.org$/', $serverName, $matches ) ) { |
| 51 | + $this->lang = $matches[1]; |
35 | 52 | // For some special subdomains, like pa.us |
36 | | - $lang = str_replace( '.', '-', $lang ); |
| 53 | + $this->lang = str_replace( '.', '-', $this->lang ); |
37 | 54 | } else if ( preg_match( '/^(.*)\.prototype\.wikimedia\.org$/', $serverName, $matches ) ) { |
38 | | - $lang = $matches[1]; |
| 55 | + $this->lang = $matches[1]; |
39 | 56 | } else { |
40 | 57 | die( "Invalid host name ($serverName), can't determine language" ); |
41 | 58 | } |
42 | 59 | } elseif ( preg_match( "/^\/usr\/local\/apache\/(?:htdocs|common\/docroot)\/([a-z0-9\-_]*)$/", $docRoot, $matches ) ) { |
43 | | - $site = "wikipedia"; |
44 | | - $lang = $matches[1]; |
45 | | - } elseif ( $siteName == 'localhost' ) { |
46 | | - $lang = getenv( 'MW_LANG' ); |
| 60 | + $this->site = "wikipedia"; |
| 61 | + $this->lang = $matches[1]; |
| 62 | + } elseif ( $this->siteName == 'localhost' ) { |
| 63 | + $this->lang = getenv( 'MW_LANG' ); |
47 | 64 | } else { |
48 | 65 | die( "Invalid host name (docroot=" . $_SERVER['DOCUMENT_ROOT'] . "), can't determine language" ); |
49 | 66 | } |
50 | 67 | } |
51 | 68 | } |
52 | 69 | } |
53 | | - return array( |
54 | | - 'site' => $site, |
55 | | - 'lang' => $lang, |
56 | | - ); |
57 | 70 | |
58 | 71 | } |
59 | 72 | |
60 | | - function getUploadSiteInfo( $pathInfo) { |
| 73 | + /** |
| 74 | + * Derives site and lang from the parameter and sets $site and $lang on the instance |
| 75 | + * @param pathInfo the PathInfo -- $_SERVER['PATH_INFO'] |
| 76 | + */ |
| 77 | + private function setSiteInfoForUploadWiki( $pathInfo) { |
| 78 | + if ( !empty( $this->siteInfo ) ) { |
| 79 | + return $this->siteInfo; |
| 80 | + } |
61 | 81 | $pathBits = explode( '/', $pathInfo ); |
62 | | - $site = $pathBits[1]; |
63 | | - $lang = $pathBits[2]; |
64 | | - return array( |
65 | | - 'site' => $site, |
66 | | - 'lang' => $lang, |
67 | | - ); |
68 | | - } |
| 82 | + $this->site = $pathBits[1]; |
| 83 | + $this->lang = $pathBits[2]; |
| 84 | + } |
69 | 85 | |
70 | | - function getDatabase( $site, $lang ) { |
| 86 | + /** |
| 87 | + * Get the site for this wiki |
| 88 | + * @return String site. Eg: wikipedia, wikinews, wikiversity |
| 89 | + */ |
| 90 | + public function getSite() { |
| 91 | + return $this->site; |
| 92 | + } |
| 93 | + |
| 94 | + /** |
| 95 | + * Get the lang for this wiki |
| 96 | + * @return String lang Eg: en, de, ar, hi |
| 97 | + */ |
| 98 | + public function getLang() { |
| 99 | + return $this->lang; |
| 100 | + } |
| 101 | + |
| 102 | + /** |
| 103 | + * If in env variable MW_DBNAME is found then use that, |
| 104 | + * otherwise derive dbname from lang and site |
| 105 | + * @return String the database name |
| 106 | + */ |
| 107 | + public function getDatabase( ) { |
71 | 108 | $dbname = getenv( 'MW_DBNAME' ); |
72 | 109 | if ( strlen( $dbname ) == 0 ) { |
73 | | - if ( $site == "wikipedia" ) { |
| 110 | + if ( $this->site == "wikipedia" ) { |
74 | 111 | $dbSuffix = "wiki"; |
75 | 112 | } else { |
76 | | - $dbSuffix = $site; |
| 113 | + $dbSuffix = $this->site; |
77 | 114 | } |
78 | | - $dbname = str_replace( "-", "_", $lang . $dbSuffix ); |
| 115 | + $dbname = str_replace( "-", "_", $this->lang . $dbSuffix ); |
79 | 116 | putenv( 'MW_DBNAME=' . $dbname ); |
80 | 117 | } |
81 | 118 | return $dbname; |
82 | 119 | |
83 | 120 | } |
84 | 121 | |
85 | | - function getVersion( $site, $lang ) { |
86 | | - $dbname = $this->getDatabase( $site, $lang ); |
| 122 | + /** |
| 123 | + * Get the version as specified in a cdb file located in /usr/local/apache/common/wikiversions.db |
| 124 | + * The key should be the dbname and the version should be the version directory for this wiki |
| 125 | + * @return String the version wirectory for this wiki |
| 126 | + */ |
| 127 | + public function getVersion( ) { |
| 128 | + $dbname = $this->getDatabase( $this->site, $this->lang ); |
87 | 129 | $db = dba_open( '/usr/local/apache/common/wikiversions.db', 'r', 'cdb' ); |
88 | 130 | if ( $db ) { |
89 | 131 | $version = dba_fetch( $dbname, $db ); |
— | — | @@ -93,6 +135,34 @@ |
94 | 136 | } |
95 | 137 | return $version; |
96 | 138 | } |
| 139 | + |
| 140 | + /** |
| 141 | + * Factory method to get an instance of MWMultiVersion. |
| 142 | + * Use this for all wikis except calls to /w/thumb.php on upload.wikmedia.org. |
| 143 | + * @return An MWMultiVersion object for this wiki |
| 144 | + */ |
| 145 | + public static function getInstanceForWiki( $serverName, $docRoot ) { |
| 146 | + if (!isset(self::$mwversion)) { |
| 147 | + $c = __CLASS__; |
| 148 | + self::$mwversion = new $c; |
| 149 | + } |
| 150 | + self::$mwversion->setSiteInfoForWiki( $serverName, $docRoot); |
| 151 | + return self::$mwversion; |
| 152 | + } |
| 153 | + |
| 154 | + |
| 155 | + /** |
| 156 | + * Factory method to get an instance of MWMultiVersion used for calls to /w/thumb.php on upload.wikmedia.org. |
| 157 | + * @return An MWMultiVersion object for the wiki derived from the pathinfo |
| 158 | + */ |
| 159 | + public static function getInstanceForUploadWiki( $pathInfo ) { |
| 160 | + if (!isset(self::$mwversion)) { |
| 161 | + $c = __CLASS__; |
| 162 | + self::$mwversion = new $c; |
| 163 | + } |
| 164 | + self::$mwversion->setSiteInfoForUploadWiki( $PathInfo); |
| 165 | + return self::$mwversion; |
| 166 | + } |
97 | 167 | |
98 | 168 | } |
99 | 169 | |