Index: trunk/tools/mwmultiversion/maintenance.diff |
— | — | @@ -0,0 +1,39 @@ |
| 2 | +Index: doMaintenance.php |
| 3 | +=================================================================== |
| 4 | +--- doMaintenance.php (revision 89980) |
| 5 | +@@ -74,7 +74,7 @@ |
| 6 | + if ( defined( 'MW_CONFIG_CALLBACK' ) ) { |
| 7 | + # Use a callback function to configure MediaWiki |
| 8 | + MWFunction::call( MW_CONFIG_CALLBACK ); |
| 9 | +-} elseif ( file_exists( "$IP/wmf-config/wikimedia-mode" ) ) { |
| 10 | ++} elseif ( file_exists( "$IP/../wmf-config/wikimedia-mode" ) ) { |
| 11 | + // Load settings, using wikimedia-mode if needed |
| 12 | + // @todo FIXME: Replace this hack with general farm-friendly code |
| 13 | + # @todo FIXME: Wikimedia-specific stuff needs to go away to an ext |
| 14 | +@@ -82,9 +82,9 @@ |
| 15 | + global $cluster; |
| 16 | + $cluster = 'pmtpa'; |
| 17 | + require_once( MWInit::compiledPath( 'includes/SiteConfiguration.php' ) ); |
| 18 | +- require( MWInit::interpretedPath( 'wmf-config/wgConf.php' ) ); |
| 19 | ++ require( MWInit::interpretedPath( '/../wmf-config/wgConf.php' ) ); |
| 20 | + $maintenance->loadWikimediaSettings(); |
| 21 | +- require( MWInit::interpretedPath( '/wmf-config/CommonSettings.php' ) ); |
| 22 | ++ require( MWInit::interpretedPath( '/../wmf-config/CommonSettings.php' ) ); |
| 23 | + } else { |
| 24 | + require_once( $maintenance->loadSettings() ); |
| 25 | + } |
| 26 | +Index: Maintenance.php |
| 27 | +=================================================================== |
| 28 | +--- Maintenance.php (revision 89980) |
| 29 | +@@ -915,7 +915,9 @@ |
| 30 | + $wgUseNormalUser = true; |
| 31 | + } |
| 32 | + |
| 33 | ++ putenv( 'MW_DBNAME=' . $db ); |
| 34 | + putenv( 'wikilang=' . $lang ); |
| 35 | ++ putenv( 'wikisite=' . $site ); |
| 36 | + |
| 37 | + ini_set( 'include_path', ".:$IP:$IP/includes:$IP/languages:$IP/maintenance" ); |
| 38 | + |
Index: trunk/tools/mwmultiversion/wmf-config/CommonSettings.php |
— | — | @@ -101,6 +101,8 @@ |
102 | 102 | require_once( $IP . '/../wmf-config/MWMultiVersion.php' ); |
103 | 103 | if ( (@$_SERVER['SCRIPT_NAME']) == '/w/thumb.php' && (@$_SERVER['SERVER_NAME']) == 'upload.wikimedia.org' ) { |
104 | 104 | $multiVersion = MWMultiVersion::getInstanceForUploadWiki( $_SERVER['PATH_INFO'] ); |
| 105 | +} else if ( $wgCommandLineMode) { |
| 106 | + $multiVersion = MWMultiVersion::getInstanceForMaintenance(); |
105 | 107 | } else { |
106 | 108 | $multiVersion = MWMultiVersion::getInstanceForWiki( $_SERVER['SERVER_NAME'], $_SERVER['DOCUMENT_ROOT'] ); |
107 | 109 | } |
Index: trunk/tools/mwmultiversion/wmf-config/MWMultiVersion.php |
— | — | @@ -16,54 +16,39 @@ |
17 | 17 | /** |
18 | 18 | * Derives site and lang from the parameters and sets $site and $lang on the instance |
19 | 19 | * @param $serverName the ServerName for this wiki -- $_SERVER['SERVER_NAME'] |
20 | | - * @docroot the DocumentRoot for this wiki -- $_SERVER['DOCUMENT_ROOT'] |
| 20 | + * @param $docroot the DocumentRoot for this wiki -- $_SERVER['DOCUMENT_ROOT'] |
21 | 21 | */ |
22 | 22 | private function setSiteInfoForWiki( $serverName, $docRoot) { |
23 | | - //print "serverName " . $serverName . " docRoot " . $docRoot; die(); |
24 | 23 | $secure = getenv( 'MW_SECURE_HOST' ); |
25 | 24 | $matches = array(); |
26 | | - if (php_sapi_name() == 'cgi-fcgi') { |
27 | | - if (!preg_match('/^([^.]+).([^.]+).*$/', $serverName, $matches)) |
28 | | - die("invalid hostname"); |
| 25 | + if( $secure ) { |
| 26 | + if ( !preg_match('/^([^.]+).([^.]+).*$/', $secure, $matches ) ) { |
| 27 | + die("invalid hostname"); |
| 28 | + } |
29 | 29 | |
30 | 30 | $this->lang = $matches[1]; |
31 | | - $this->site = $$matches[2]; |
| 31 | + $this->site = $matches[2]; |
32 | 32 | |
33 | 33 | if (in_array($this->lang, array("commons", "grants", "sources", "wikimania", "wikimania2006", "foundation", "meta"))) |
34 | 34 | $this->site = "wikipedia"; |
35 | | - } elseif( $secure ) { |
36 | | - if (!preg_match('/^([^.]+).([^.]+).*$/', $secure, $$matches)) |
37 | | - die("invalid hostname"); |
38 | | - |
39 | | - $this->lang = $$matches[1]; |
40 | | - $this->site = $$matches[2]; |
41 | | - |
42 | | - if (in_array($this->lang, array("commons", "grants", "sources", "wikimania", "wikimania2006", "foundation", "meta"))) |
43 | | - $this->site = "wikipedia"; |
44 | 35 | } else { |
45 | | - if ( !isset( $this->site ) ) { |
| 36 | + $this->site = "wikipedia"; |
| 37 | + if ( preg_match( '/^(?:\/usr\/local\/apache\/|\/home\/wikipedia\/)(?:htdocs|common\/docroot)\/([a-z]+)\.org/', $docRoot, $matches ) ) { |
| 38 | + $this->site = $matches[1]; |
| 39 | + if ( preg_match( '/^(.*)\.' . preg_quote( $this->site ) . '\.org$/', $serverName, $matches ) ) { |
| 40 | + $this->lang = $matches[1]; |
| 41 | + // For some special subdomains, like pa.us |
| 42 | + $this->lang = str_replace( '.', '-', $this->lang ); |
| 43 | + } else if ( preg_match( '/^(.*)\.prototype\.wikimedia\.org$/', $serverName, $matches ) ) { |
| 44 | + $this->lang = $matches[1]; |
| 45 | + } else { |
| 46 | + die( "Invalid host name ($serverName), can't determine language" ); |
| 47 | + } |
| 48 | + } elseif ( preg_match( "/^\/usr\/local\/apache\/(?:htdocs|common\/docroot)\/([a-z0-9\-_]*)$/", $docRoot, $matches ) ) { |
46 | 49 | $this->site = "wikipedia"; |
47 | | - if ( !isset( $this->lang ) ) { |
48 | | - if ( preg_match( '/^(?:\/usr\/local\/apache\/|\/home\/wikipedia\/)(?:htdocs|common\/docroot)\/([a-z]+)\.org/', $docRoot, $matches ) ) { |
49 | | - $this->site = $matches[1]; |
50 | | - if ( preg_match( '/^(.*)\.' . preg_quote( $this->site ) . '\.org$/', $serverName, $matches ) ) { |
51 | | - $this->lang = $matches[1]; |
52 | | - // For some special subdomains, like pa.us |
53 | | - $this->lang = str_replace( '.', '-', $this->lang ); |
54 | | - } else if ( preg_match( '/^(.*)\.prototype\.wikimedia\.org$/', $serverName, $matches ) ) { |
55 | | - $this->lang = $matches[1]; |
56 | | - } else { |
57 | | - die( "Invalid host name ($serverName), can't determine language" ); |
58 | | - } |
59 | | - } elseif ( preg_match( "/^\/usr\/local\/apache\/(?:htdocs|common\/docroot)\/([a-z0-9\-_]*)$/", $docRoot, $matches ) ) { |
60 | | - $this->site = "wikipedia"; |
61 | | - $this->lang = $matches[1]; |
62 | | - } elseif ( $this->siteName == 'localhost' ) { |
63 | | - $this->lang = getenv( 'MW_LANG' ); |
64 | | - } else { |
65 | | - die( "Invalid host name (docroot=" . $_SERVER['DOCUMENT_ROOT'] . "), can't determine language" ); |
66 | | - } |
67 | | - } |
| 50 | + $this->lang = $matches[1]; |
| 51 | + } else { |
| 52 | + die( "Invalid host name (docroot=" . $_SERVER['DOCUMENT_ROOT'] . "), can't determine language" ); |
68 | 53 | } |
69 | 54 | } |
70 | 55 | |
— | — | @@ -71,18 +56,25 @@ |
72 | 57 | |
73 | 58 | /** |
74 | 59 | * Derives site and lang from the parameter and sets $site and $lang on the instance |
75 | | - * @param pathInfo the PathInfo -- $_SERVER['PATH_INFO'] |
| 60 | + * @param $pathInfo the PathInfo -- $_SERVER['PATH_INFO'] |
76 | 61 | */ |
77 | 62 | private function setSiteInfoForUploadWiki( $pathInfo) { |
78 | | - if ( !empty( $this->siteInfo ) ) { |
79 | | - return $this->siteInfo; |
80 | | - } |
| 63 | + //TODO: error if we don't get what we expect |
81 | 64 | $pathBits = explode( '/', $pathInfo ); |
82 | 65 | $this->site = $pathBits[1]; |
83 | 66 | $this->lang = $pathBits[2]; |
84 | 67 | } |
85 | 68 | |
86 | 69 | /** |
| 70 | + * Gets the site and lang from env variables |
| 71 | + */ |
| 72 | + private function setSiteInfoForMaintenance() { |
| 73 | + //TODO: some error checking |
| 74 | + $this->site = getenv( 'wikisite' ); |
| 75 | + $this->lang = getenv( 'wikilang' ); |
| 76 | + } |
| 77 | + |
| 78 | + /** |
87 | 79 | * Get the site for this wiki |
88 | 80 | * @return String site. Eg: wikipedia, wikinews, wikiversity |
89 | 81 | */ |
— | — | @@ -103,7 +95,7 @@ |
104 | 96 | * otherwise derive dbname from lang and site |
105 | 97 | * @return String the database name |
106 | 98 | */ |
107 | | - public function getDatabase( ) { |
| 99 | + public function getDatabase() { |
108 | 100 | $dbname = getenv( 'MW_DBNAME' ); |
109 | 101 | if ( strlen( $dbname ) == 0 ) { |
110 | 102 | if ( $this->site == "wikipedia" ) { |
— | — | @@ -123,7 +115,7 @@ |
124 | 116 | * The key should be the dbname and the version should be the version directory for this wiki |
125 | 117 | * @return String the version wirectory for this wiki |
126 | 118 | */ |
127 | | - public function getVersion( ) { |
| 119 | + public function getVersion() { |
128 | 120 | $dbname = $this->getDatabase( $this->site, $this->lang ); |
129 | 121 | $db = dba_open( '/usr/local/apache/common/wikiversions.db', 'r', 'cdb' ); |
130 | 122 | if ( $db ) { |
— | — | @@ -139,31 +131,44 @@ |
140 | 132 | /** |
141 | 133 | * Factory method to get an instance of MWMultiVersion. |
142 | 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'] |
143 | 137 | * @return An MWMultiVersion object for this wiki |
144 | 138 | */ |
145 | 139 | public static function getInstanceForWiki( $serverName, $docRoot ) { |
146 | 140 | if (!isset(self::$mwversion)) { |
147 | | - $c = __CLASS__; |
148 | | - self::$mwversion = new $c; |
| 141 | + self::$mwversion = new self; |
| 142 | + self::$mwversion->setSiteInfoForWiki( $serverName, $docRoot ); |
149 | 143 | } |
150 | | - self::$mwversion->setSiteInfoForWiki( $serverName, $docRoot); |
151 | 144 | return self::$mwversion; |
152 | 145 | } |
153 | 146 | |
154 | 147 | |
155 | 148 | /** |
156 | 149 | * Factory method to get an instance of MWMultiVersion used for calls to /w/thumb.php on upload.wikmedia.org. |
| 150 | + * @param $pathInfo the PathInfo -- $_SERVER['PATH_INFO'] |
157 | 151 | * @return An MWMultiVersion object for the wiki derived from the pathinfo |
158 | 152 | */ |
159 | 153 | public static function getInstanceForUploadWiki( $pathInfo ) { |
160 | 154 | if (!isset(self::$mwversion)) { |
161 | | - $c = __CLASS__; |
162 | | - self::$mwversion = new $c; |
| 155 | + self::$mwversion = new self; |
| 156 | + self::$mwversion->setSiteInfoForUploadWiki( $PathInfo ); |
163 | 157 | } |
164 | | - self::$mwversion->setSiteInfoForUploadWiki( $PathInfo); |
165 | 158 | return self::$mwversion; |
166 | 159 | } |
167 | | - |
| 160 | + |
| 161 | + /** |
| 162 | + * Factory method to get an instance of MWMultiVersion via maintenance scripts since they need to set site and lang. |
| 163 | + * @return An MWMultiVersion object for the wiki derived from the env variables set by Maintenance.php |
| 164 | + */ |
| 165 | + public static function getInstanceForMaintenance( ) { |
| 166 | + if (!isset(self::$mwversion)) { |
| 167 | + self::$mwversion = new self; |
| 168 | + self::$mwversion->site = $site; |
| 169 | + self::$mwversion->lang = $lang; |
| 170 | + } |
| 171 | + return self::$mwversion; |
| 172 | + } |
168 | 173 | } |
169 | 174 | |
170 | 175 | ?> |
\ No newline at end of file |
Index: trunk/tools/mwmultiversion/README |
— | — | @@ -4,14 +4,17 @@ |
5 | 5 | |
6 | 6 | * Move wmf-config one level up |
7 | 7 | * Change all references to wmf-confing to have the correct value in LocalSettings.php |
8 | | -* Change all references to wmf-confing to have the correct value in includes/maintenance |
9 | | -* For all new wikis being deployed add a /usr/local/apache/common/wikiversions.db (maybe add a script for this later) |
| 8 | +* For all new wikis being deployed add a /usr/local/apache/common/wikiversions.db |
| 9 | +** A helper script to do this is checked into scripts/cdbmake-12.sh |
| 10 | +** A sample file that contains input for cdbmake-12.sh is checked into scripts/wikiversions.dat.sample |
10 | 11 | * Copy common/php-1.17/cache/trusted-xff.cdb to the new source directory |
11 | 12 | * Apply patches to CommonSettings.php |
12 | 13 | * In InitialiseSettings.php make the following change: |
13 | 14 | 'wgCacheDirectory' => array( |
14 | 15 | 'default' => '/tmp/mw-cache-' . $wgVersionDirectory, |
15 | 16 | * Create the following new symlinks |
16 | | -** /apache/common/live-1.5/extensions-1.<new-version> |
17 | | -** /apache/common/live-1.5/skins-1.<new-version> |
| 17 | +** /apache/common/live-1.5/extensions-<version> |
| 18 | +** /apache/common/live-1.5/skins-<version> |
18 | 19 | |
| 20 | +* TODO: Maintenance script changes are not done yet. Checked in as a patch for now. |
| 21 | + |