Index: trunk/tools/mwmultiversion/live-1.5/MWVersion.php |
— | — | @@ -1,27 +1,36 @@ |
2 | 2 | <?php |
3 | | - |
| 3 | +/* |
| 4 | + * Get the location of the correct version of a MediaWiki web |
| 5 | + * entry-point file given environmental variables such as the server name. |
| 6 | + * This also sets the MW_INSTALL_PATH environmental variable and changes |
| 7 | + * PHP's current directory to the directory of this file. |
| 8 | + * |
| 9 | + * @return string File path |
| 10 | + */ |
4 | 11 | function getMediaWiki( $file ) { |
5 | 12 | $secure = getenv( 'MW_SECURE_HOST' ); |
6 | | - $host = $secure ? $secure : $_SERVER['HTTP_HOST']; |
7 | | - |
| 13 | + $host = $secure ? $secure : $_SERVER['HTTP_HOST']; |
| 14 | + |
8 | 15 | require( dirname( __FILE__ ) . '/../wmf-config/MWMultiVersion.php' ); |
9 | | - $multiVersion = MWMultiVersion::getInstanceForWiki( $_SERVER['SERVER_NAME'], $_SERVER['DOCUMENT_ROOT'] ); |
| 16 | + $multiVersion = MWMultiVersion::getInstanceForWiki( |
| 17 | + $_SERVER['SERVER_NAME'], $_SERVER['DOCUMENT_ROOT'] ); |
10 | 18 | |
11 | 19 | $version = $multiVersion->getVersion(); |
12 | | - |
| 20 | + |
13 | 21 | if ( $host == 'test.wikipedia.org' && !$secure && |
14 | | - !preg_match( '!thumb\.php!', $_SERVER['REQUEST_URI'] ) ) { |
| 22 | + !preg_match( '!thumb\.php!', $_SERVER['REQUEST_URI'] ) ) |
| 23 | + { |
15 | 24 | define( 'TESTWIKI', 1 ); |
16 | | - // As horrible hack for NFS-less iamge scalers, use regular docroot for thumbs? |
| 25 | + # Test wiki mostly runs off the version of MediaWiki on /home. |
| 26 | + # As horrible hack for NFS-less image scalers, use regular docroot for thumbs? |
17 | 27 | # $IP = '/home/wikipedia/common/php-1.5'; |
18 | 28 | $IP = "/home/wikipedia/common/$version"; |
19 | 29 | } else { |
20 | 30 | $IP = "/usr/local/apache/common/$version"; |
21 | 31 | } |
22 | | - |
| 32 | + |
23 | 33 | chdir( $IP ); |
24 | 34 | putenv( "MW_INSTALL_PATH=$IP" ); |
| 35 | + |
25 | 36 | return "$IP/$file"; |
26 | 37 | } |
27 | | - |
28 | | - |
Index: trunk/tools/mwmultiversion/wmf-config/MWMultiVersion.php |
— | — | @@ -1,7 +1,11 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | class MWMultiVersion { |
| 5 | + /** |
| 6 | + * @var MWMultiVersion |
| 7 | + */ |
5 | 8 | private static $mwversion; |
| 9 | + |
6 | 10 | private $site; |
7 | 11 | private $lang; |
8 | 12 | |
— | — | @@ -10,25 +14,66 @@ |
11 | 15 | * @see getInstanceForWiki |
12 | 16 | * @see getInstanceForUploadWiki |
13 | 17 | */ |
14 | | - private function __construct() { |
| 18 | + private function __construct() {} |
| 19 | + private function __clone() {} |
| 20 | + |
| 21 | + /** |
| 22 | + * Factory method to get an instance of MWMultiVersion. |
| 23 | + * Use this for all wikis except calls to /w/thumb.php on upload.wikmedia.org. |
| 24 | + * @param $serverName the ServerName for this wiki -- $_SERVER['SERVER_NAME'] |
| 25 | + * @param $docroot the DocumentRoot for this wiki -- $_SERVER['DOCUMENT_ROOT'] |
| 26 | + * @return An MWMultiVersion object for this wiki |
| 27 | + */ |
| 28 | + public static function getInstanceForWiki( $serverName, $docRoot ) { |
| 29 | + if ( !isset( self::$mwversion ) ) { |
| 30 | + self::$mwversion = new self; |
| 31 | + self::$mwversion->setSiteInfoForWiki( $serverName, $docRoot ); |
| 32 | + } |
| 33 | + return self::$mwversion; |
15 | 34 | } |
16 | 35 | |
17 | 36 | /** |
| 37 | + * Factory method to get an instance of MWMultiVersion used for calls to /w/thumb.php on upload.wikmedia.org. |
| 38 | + * @param $pathInfo the PathInfo -- $_SERVER['PATH_INFO'] |
| 39 | + * @return An MWMultiVersion object for the wiki derived from the pathinfo |
| 40 | + */ |
| 41 | + public static function getInstanceForUploadWiki( $pathInfo ) { |
| 42 | + if ( !isset( self::$mwversion ) ) { |
| 43 | + self::$mwversion = new self; |
| 44 | + self::$mwversion->setSiteInfoForUploadWiki( $PathInfo ); |
| 45 | + } |
| 46 | + return self::$mwversion; |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Factory method to get an instance of MWMultiVersion |
| 51 | + * via maintenance scripts since they need to set site and lang. |
| 52 | + * @return An MWMultiVersion object for the wiki derived from the env variables set by Maintenance.php |
| 53 | + */ |
| 54 | + public static function getInstanceForMaintenance() { |
| 55 | + if ( !isset( self::$mwversion ) ) { |
| 56 | + self::$mwversion = new self; |
| 57 | + self::$mwversion->setSiteInfoForMaintenance(); |
| 58 | + } |
| 59 | + return self::$mwversion; |
| 60 | + } |
| 61 | + |
| 62 | + /** |
18 | 63 | * Derives site and lang from the parameters and sets $site and $lang on the instance |
19 | 64 | * @param $serverName the ServerName for this wiki -- $_SERVER['SERVER_NAME'] |
20 | 65 | * @param $docroot the DocumentRoot for this wiki -- $_SERVER['DOCUMENT_ROOT'] |
21 | 66 | */ |
22 | | - private function setSiteInfoForWiki( $serverName, $docRoot) { |
| 67 | + private function setSiteInfoForWiki( $serverName, $docRoot ) { |
23 | 68 | $secure = getenv( 'MW_SECURE_HOST' ); |
24 | 69 | $matches = array(); |
25 | | - if( $secure ) { |
| 70 | + if ( $secure ) { |
26 | 71 | if ( !preg_match('/^([^.]+).([^.]+).*$/', $secure, $matches ) ) { |
27 | 72 | die("invalid hostname"); |
28 | 73 | } |
29 | | - |
30 | 74 | $this->lang = $matches[1]; |
31 | 75 | $this->site = $matches[2]; |
32 | | - |
| 76 | + |
| 77 | + // @TODO: move/use some dblist? |
33 | 78 | if (in_array($this->lang, array("commons", "grants", "sources", "wikimania", "wikimania2006", "foundation", "meta"))) |
34 | 79 | $this->site = "wikipedia"; |
35 | 80 | } else { |
— | — | @@ -51,15 +96,14 @@ |
52 | 97 | die( "Invalid host name (docroot=" . $_SERVER['DOCUMENT_ROOT'] . "), can't determine language" ); |
53 | 98 | } |
54 | 99 | } |
55 | | - |
56 | 100 | } |
57 | | - |
| 101 | + |
58 | 102 | /** |
59 | 103 | * Derives site and lang from the parameter and sets $site and $lang on the instance |
60 | 104 | * @param $pathInfo the PathInfo -- $_SERVER['PATH_INFO'] |
61 | 105 | */ |
62 | | - private function setSiteInfoForUploadWiki( $pathInfo) { |
63 | | - //TODO: error if we don't get what we expect |
| 106 | + private function setSiteInfoForUploadWiki( $pathInfo ) { |
| 107 | + // @TODO: error if we don't get what we expect |
64 | 108 | $pathBits = explode( '/', $pathInfo ); |
65 | 109 | $this->site = $pathBits[1]; |
66 | 110 | $this->lang = $pathBits[2]; |
— | — | @@ -69,11 +113,11 @@ |
70 | 114 | * Gets the site and lang from env variables |
71 | 115 | */ |
72 | 116 | private function setSiteInfoForMaintenance() { |
73 | | - //TODO: some error checking |
| 117 | + // @TODO: some error checking |
74 | 118 | $this->site = getenv( 'wikisite' ); |
75 | 119 | $this->lang = getenv( 'wikilang' ); |
76 | 120 | } |
77 | | - |
| 121 | + |
78 | 122 | /** |
79 | 123 | * Get the site for this wiki |
80 | 124 | * @return String site. Eg: wikipedia, wikinews, wikiversity |
— | — | @@ -81,7 +125,7 @@ |
82 | 126 | public function getSite() { |
83 | 127 | return $this->site; |
84 | 128 | } |
85 | | - |
| 129 | + |
86 | 130 | /** |
87 | 131 | * Get the lang for this wiki |
88 | 132 | * @return String lang Eg: en, de, ar, hi |
— | — | @@ -127,46 +171,4 @@ |
128 | 172 | } |
129 | 173 | return $version; |
130 | 174 | } |
131 | | - |
132 | | - /** |
133 | | - * Factory method to get an instance of MWMultiVersion. |
134 | | - * Use this for all wikis except calls to /w/thumb.php on upload.wikmedia.org. |
135 | | - * @param $serverName the ServerName for this wiki -- $_SERVER['SERVER_NAME'] |
136 | | - * @param $docroot the DocumentRoot for this wiki -- $_SERVER['DOCUMENT_ROOT'] |
137 | | - * @return An MWMultiVersion object for this wiki |
138 | | - */ |
139 | | - public static function getInstanceForWiki( $serverName, $docRoot ) { |
140 | | - if (!isset(self::$mwversion)) { |
141 | | - self::$mwversion = new self; |
142 | | - self::$mwversion->setSiteInfoForWiki( $serverName, $docRoot ); |
143 | | - } |
144 | | - return self::$mwversion; |
145 | | - } |
146 | | - |
147 | | - /** |
148 | | - * Factory method to get an instance of MWMultiVersion used for calls to /w/thumb.php on upload.wikmedia.org. |
149 | | - * @param $pathInfo the PathInfo -- $_SERVER['PATH_INFO'] |
150 | | - * @return An MWMultiVersion object for the wiki derived from the pathinfo |
151 | | - */ |
152 | | - public static function getInstanceForUploadWiki( $pathInfo ) { |
153 | | - if (!isset(self::$mwversion)) { |
154 | | - self::$mwversion = new self; |
155 | | - self::$mwversion->setSiteInfoForUploadWiki( $PathInfo ); |
156 | | - } |
157 | | - return self::$mwversion; |
158 | | - } |
159 | | - |
160 | | - /** |
161 | | - * Factory method to get an instance of MWMultiVersion via maintenance scripts since they need to set site and lang. |
162 | | - * @return An MWMultiVersion object for the wiki derived from the env variables set by Maintenance.php |
163 | | - */ |
164 | | - public static function getInstanceForMaintenance( ) { |
165 | | - if (!isset(self::$mwversion)) { |
166 | | - self::$mwversion = new self; |
167 | | - self::$mwversion->setSiteInfoForMaintenance(); |
168 | | - } |
169 | | - return self::$mwversion; |
170 | | - } |
171 | 175 | } |
172 | | - |
173 | | -?> |
\ No newline at end of file |