http://www.mediawiki.org/wiki/Special:Code/MediaWiki/90075
Revision: 90075
Author: pdhanda
Date: 2011-06-14 19:59:38 +0000 (Tue, 14 Jun 2011)
Log Message:
-----------
Cleanup of some debugging code and bad untested code.
Added some support for maintenance scripts to MWMultiVersion.
Temporary diff for maintenance scripts.
Modified Paths:
--------------
trunk/tools/mwmultiversion/README
trunk/tools/mwmultiversion/wmf-config/CommonSettings.php
trunk/tools/mwmultiversion/wmf-config/MWMultiVersion.php
Added Paths:
-----------
trunk/tools/mwmultiversion/maintenance.diff
Modified: trunk/tools/mwmultiversion/README
===================================================================
--- trunk/tools/mwmultiversion/README 2011-06-14 19:27:42 UTC (rev 90074)
+++ trunk/tools/mwmultiversion/README 2011-06-14 19:59:38 UTC (rev 90075)
@@ -4,14 +4,17 @@
* Move wmf-config one level up
* Change all references to wmf-confing to have the correct value in
LocalSettings.php
-* Change all references to wmf-confing to have the correct value in
includes/maintenance
-* For all new wikis being deployed add a
/usr/local/apache/common/wikiversions.db (maybe add a script for this later)
+* For all new wikis being deployed add a
/usr/local/apache/common/wikiversions.db
+** A helper script to do this is checked into scripts/cdbmake-12.sh
+** A sample file that contains input for cdbmake-12.sh is checked into
scripts/wikiversions.dat.sample
* Copy common/php-1.17/cache/trusted-xff.cdb to the new source directory
* Apply patches to CommonSettings.php
* In InitialiseSettings.php make the following change:
'wgCacheDirectory' => array(
'default' => '/tmp/mw-cache-' . $wgVersionDirectory,
* Create the following new symlinks
-** /apache/common/live-1.5/extensions-1.<new-version>
-** /apache/common/live-1.5/skins-1.<new-version>
+** /apache/common/live-1.5/extensions-<version>
+** /apache/common/live-1.5/skins-<version>
+* TODO: Maintenance script changes are not done yet. Checked in as a patch for
now.
+
Added: trunk/tools/mwmultiversion/maintenance.diff
===================================================================
--- trunk/tools/mwmultiversion/maintenance.diff (rev 0)
+++ trunk/tools/mwmultiversion/maintenance.diff 2011-06-14 19:59:38 UTC (rev
90075)
@@ -0,0 +1,39 @@
+Index: doMaintenance.php
+===================================================================
+--- doMaintenance.php (revision 89980)
++++ doMaintenance.php (working copy)
+@@ -74,7 +74,7 @@
+ if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
+ # Use a callback function to configure MediaWiki
+ MWFunction::call( MW_CONFIG_CALLBACK );
+-} elseif ( file_exists( "$IP/wmf-config/wikimedia-mode" ) ) {
++} elseif ( file_exists( "$IP/../wmf-config/wikimedia-mode" ) ) {
+ // Load settings, using wikimedia-mode if needed
+ // @todo FIXME: Replace this hack with general farm-friendly code
+ # @todo FIXME: Wikimedia-specific stuff needs to go away to an ext
+@@ -82,9 +82,9 @@
+ global $cluster;
+ $cluster = 'pmtpa';
+ require_once( MWInit::compiledPath( 'includes/SiteConfiguration.php' )
);
+- require( MWInit::interpretedPath( 'wmf-config/wgConf.php' ) );
++ require( MWInit::interpretedPath( '/../wmf-config/wgConf.php' ) );
+ $maintenance->loadWikimediaSettings();
+- require( MWInit::interpretedPath( '/wmf-config/CommonSettings.php' ) );
++ require( MWInit::interpretedPath( '/../wmf-config/CommonSettings.php' )
);
+ } else {
+ require_once( $maintenance->loadSettings() );
+ }
+Index: Maintenance.php
+===================================================================
+--- Maintenance.php (revision 89980)
++++ Maintenance.php (working copy)
+@@ -915,7 +915,9 @@
+ $wgUseNormalUser = true;
+ }
+
++ putenv( 'MW_DBNAME=' . $db );
+ putenv( 'wikilang=' . $lang );
++ putenv( 'wikisite=' . $site );
+
+ ini_set( 'include_path',
".:$IP:$IP/includes:$IP/languages:$IP/maintenance" );
+
Modified: trunk/tools/mwmultiversion/wmf-config/CommonSettings.php
===================================================================
--- trunk/tools/mwmultiversion/wmf-config/CommonSettings.php 2011-06-14
19:27:42 UTC (rev 90074)
+++ trunk/tools/mwmultiversion/wmf-config/CommonSettings.php 2011-06-14
19:59:38 UTC (rev 90075)
@@ -101,6 +101,8 @@
require_once( $IP . '/../wmf-config/MWMultiVersion.php' );
if ( (@$_SERVER['SCRIPT_NAME']) == '/w/thumb.php' &&
(@$_SERVER['SERVER_NAME']) == 'upload.wikimedia.org' ) {
$multiVersion = MWMultiVersion::getInstanceForUploadWiki(
$_SERVER['PATH_INFO'] );
+} else if ( $wgCommandLineMode) {
+ $multiVersion = MWMultiVersion::getInstanceForMaintenance();
} else {
$multiVersion = MWMultiVersion::getInstanceForWiki(
$_SERVER['SERVER_NAME'], $_SERVER['DOCUMENT_ROOT'] );
}
Modified: trunk/tools/mwmultiversion/wmf-config/MWMultiVersion.php
===================================================================
--- trunk/tools/mwmultiversion/wmf-config/MWMultiVersion.php 2011-06-14
19:27:42 UTC (rev 90074)
+++ trunk/tools/mwmultiversion/wmf-config/MWMultiVersion.php 2011-06-14
19:59:38 UTC (rev 90075)
@@ -16,54 +16,39 @@
/**
* Derives site and lang from the parameters and sets $site and $lang
on the instance
* @param $serverName the ServerName for this wiki --
$_SERVER['SERVER_NAME']
- * @docroot the DocumentRoot for this wiki -- $_SERVER['DOCUMENT_ROOT']
+ * @param $docroot the DocumentRoot for this wiki --
$_SERVER['DOCUMENT_ROOT']
*/
private function setSiteInfoForWiki( $serverName, $docRoot) {
- //print "serverName " . $serverName . " docRoot " . $docRoot;
die();
$secure = getenv( 'MW_SECURE_HOST' );
$matches = array();
- if (php_sapi_name() == 'cgi-fcgi') {
- if (!preg_match('/^([^.]+).([^.]+).*$/', $serverName,
$matches))
- die("invalid hostname");
+ if( $secure ) {
+ if ( !preg_match('/^([^.]+).([^.]+).*$/', $secure,
$matches ) ) {
+ die("invalid hostname");
+ }
$this->lang = $matches[1];
- $this->site = $$matches[2];
+ $this->site = $matches[2];
if (in_array($this->lang, array("commons", "grants",
"sources", "wikimania", "wikimania2006", "foundation", "meta")))
$this->site = "wikipedia";
- } elseif( $secure ) {
- if (!preg_match('/^([^.]+).([^.]+).*$/', $secure,
$$matches))
- die("invalid hostname");
-
- $this->lang = $$matches[1];
- $this->site = $$matches[2];
-
- if (in_array($this->lang, array("commons", "grants",
"sources", "wikimania", "wikimania2006", "foundation", "meta")))
- $this->site = "wikipedia";
} else {
- if ( !isset( $this->site ) ) {
+ $this->site = "wikipedia";
+ if ( preg_match(
'/^(?:\/usr\/local\/apache\/|\/home\/wikipedia\/)(?:htdocs|common\/docroot)\/([a-z]+)\.org/',
$docRoot, $matches ) ) {
+ $this->site = $matches[1];
+ if ( preg_match( '/^(.*)\.' . preg_quote(
$this->site ) . '\.org$/', $serverName, $matches ) ) {
+ $this->lang = $matches[1];
+ // For some special subdomains, like
pa.us
+ $this->lang = str_replace( '.', '-',
$this->lang );
+ } else if ( preg_match(
'/^(.*)\.prototype\.wikimedia\.org$/', $serverName, $matches ) ) {
+ $this->lang = $matches[1];
+ } else {
+ die( "Invalid host name ($serverName),
can't determine language" );
+ }
+ } elseif ( preg_match(
"/^\/usr\/local\/apache\/(?:htdocs|common\/docroot)\/([a-z0-9\-_]*)$/",
$docRoot, $matches ) ) {
$this->site = "wikipedia";
- if ( !isset( $this->lang ) ) {
- if ( preg_match(
'/^(?:\/usr\/local\/apache\/|\/home\/wikipedia\/)(?:htdocs|common\/docroot)\/([a-z]+)\.org/',
$docRoot, $matches ) ) {
- $this->site = $matches[1];
- if ( preg_match( '/^(.*)\.' .
preg_quote( $this->site ) . '\.org$/', $serverName, $matches ) ) {
- $this->lang =
$matches[1];
- // For some special
subdomains, like pa.us
- $this->lang =
str_replace( '.', '-', $this->lang );
- } else if ( preg_match(
'/^(.*)\.prototype\.wikimedia\.org$/', $serverName, $matches ) ) {
- $this->lang =
$matches[1];
- } else {
- die( "Invalid host name
($serverName), can't determine language" );
- }
- } elseif ( preg_match(
"/^\/usr\/local\/apache\/(?:htdocs|common\/docroot)\/([a-z0-9\-_]*)$/",
$docRoot, $matches ) ) {
- $this->site = "wikipedia";
- $this->lang = $matches[1];
- } elseif ( $this->siteName ==
'localhost' ) {
- $this->lang = getenv( 'MW_LANG'
);
- } else {
- die( "Invalid host name
(docroot=" . $_SERVER['DOCUMENT_ROOT'] . "), can't determine language" );
- }
- }
+ $this->lang = $matches[1];
+ } else {
+ die( "Invalid host name (docroot=" .
$_SERVER['DOCUMENT_ROOT'] . "), can't determine language" );
}
}
@@ -71,18 +56,25 @@
/**
* Derives site and lang from the parameter and sets $site and $lang on
the instance
- * @param pathInfo the PathInfo -- $_SERVER['PATH_INFO']
+ * @param $pathInfo the PathInfo -- $_SERVER['PATH_INFO']
*/
private function setSiteInfoForUploadWiki( $pathInfo) {
- if ( !empty( $this->siteInfo ) ) {
- return $this->siteInfo;
- }
+ //TODO: error if we don't get what we expect
$pathBits = explode( '/', $pathInfo );
$this->site = $pathBits[1];
$this->lang = $pathBits[2];
}
/**
+ * Gets the site and lang from env variables
+ */
+ private function setSiteInfoForMaintenance() {
+ //TODO: some error checking
+ $this->site = getenv( 'wikisite' );
+ $this->lang = getenv( 'wikilang' );
+ }
+
+ /**
* Get the site for this wiki
* @return String site. Eg: wikipedia, wikinews, wikiversity
*/
@@ -103,7 +95,7 @@
* otherwise derive dbname from lang and site
* @return String the database name
*/
- public function getDatabase( ) {
+ public function getDatabase() {
$dbname = getenv( 'MW_DBNAME' );
if ( strlen( $dbname ) == 0 ) {
if ( $this->site == "wikipedia" ) {
@@ -123,7 +115,7 @@
* The key should be the dbname and the version should be the version
directory for this wiki
* @return String the version wirectory for this wiki
*/
- public function getVersion( ) {
+ public function getVersion() {
$dbname = $this->getDatabase( $this->site, $this->lang );
$db = dba_open( '/usr/local/apache/common/wikiversions.db',
'r', 'cdb' );
if ( $db ) {
@@ -139,31 +131,44 @@
/**
* Factory method to get an instance of MWMultiVersion.
* Use this for all wikis except calls to /w/thumb.php on
upload.wikmedia.org.
+ * @param $serverName the ServerName for this wiki --
$_SERVER['SERVER_NAME']
+ * @param $docroot the DocumentRoot for this wiki --
$_SERVER['DOCUMENT_ROOT']
* @return An MWMultiVersion object for this wiki
*/
public static function getInstanceForWiki( $serverName, $docRoot ) {
if (!isset(self::$mwversion)) {
- $c = __CLASS__;
- self::$mwversion = new $c;
+ self::$mwversion = new self;
+ self::$mwversion->setSiteInfoForWiki( $serverName,
$docRoot );
}
- self::$mwversion->setSiteInfoForWiki( $serverName, $docRoot);
return self::$mwversion;
}
/**
* Factory method to get an instance of MWMultiVersion used for calls
to /w/thumb.php on upload.wikmedia.org.
+ * @param $pathInfo the PathInfo -- $_SERVER['PATH_INFO']
* @return An MWMultiVersion object for the wiki derived from the
pathinfo
*/
public static function getInstanceForUploadWiki( $pathInfo ) {
if (!isset(self::$mwversion)) {
- $c = __CLASS__;
- self::$mwversion = new $c;
+ self::$mwversion = new self;
+ self::$mwversion->setSiteInfoForUploadWiki( $PathInfo );
}
- self::$mwversion->setSiteInfoForUploadWiki( $PathInfo);
return self::$mwversion;
}
-
+
+ /**
+ * Factory method to get an instance of MWMultiVersion via maintenance
scripts since they need to set site and lang.
+ * @return An MWMultiVersion object for the wiki derived from the env
variables set by Maintenance.php
+ */
+ public static function getInstanceForMaintenance( ) {
+ if (!isset(self::$mwversion)) {
+ self::$mwversion = new self;
+ self::$mwversion->site = $site;
+ self::$mwversion->lang = $lang;
+ }
+ return self::$mwversion;
+ }
}
?>
\ No newline at end of file
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs