r90075 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90074‎ | r90075 | r90076 >
Date:19:59, 14 June 2011
Author:pdhanda
Status:deferred
Tags:
Comment:
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 (modified) (history)
  • /trunk/tools/mwmultiversion/maintenance.diff (added) (history)
  • /trunk/tools/mwmultiversion/wmf-config/CommonSettings.php (modified) (history)
  • /trunk/tools/mwmultiversion/wmf-config/MWMultiVersion.php (modified) (history)

Diff [purge]

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 @@
102102 require_once( $IP . '/../wmf-config/MWMultiVersion.php' );
103103 if ( (@$_SERVER['SCRIPT_NAME']) == '/w/thumb.php' && (@$_SERVER['SERVER_NAME']) == 'upload.wikimedia.org' ) {
104104 $multiVersion = MWMultiVersion::getInstanceForUploadWiki( $_SERVER['PATH_INFO'] );
 105+} else if ( $wgCommandLineMode) {
 106+ $multiVersion = MWMultiVersion::getInstanceForMaintenance();
105107 } else {
106108 $multiVersion = MWMultiVersion::getInstanceForWiki( $_SERVER['SERVER_NAME'], $_SERVER['DOCUMENT_ROOT'] );
107109 }
Index: trunk/tools/mwmultiversion/wmf-config/MWMultiVersion.php
@@ -16,54 +16,39 @@
1717 /**
1818 * Derives site and lang from the parameters and sets $site and $lang on the instance
1919 * @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']
2121 */
2222 private function setSiteInfoForWiki( $serverName, $docRoot) {
23 - //print "serverName " . $serverName . " docRoot " . $docRoot; die();
2423 $secure = getenv( 'MW_SECURE_HOST' );
2524 $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+ }
2929
3030 $this->lang = $matches[1];
31 - $this->site = $$matches[2];
 31+ $this->site = $matches[2];
3232
3333 if (in_array($this->lang, array("commons", "grants", "sources", "wikimania", "wikimania2006", "foundation", "meta")))
3434 $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";
4435 } 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 ) ) {
4649 $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" );
6853 }
6954 }
7055
@@ -71,18 +56,25 @@
7257
7358 /**
7459 * 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']
7661 */
7762 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
8164 $pathBits = explode( '/', $pathInfo );
8265 $this->site = $pathBits[1];
8366 $this->lang = $pathBits[2];
8467 }
8568
8669 /**
 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+ /**
8779 * Get the site for this wiki
8880 * @return String site. Eg: wikipedia, wikinews, wikiversity
8981 */
@@ -103,7 +95,7 @@
10496 * otherwise derive dbname from lang and site
10597 * @return String the database name
10698 */
107 - public function getDatabase( ) {
 99+ public function getDatabase() {
108100 $dbname = getenv( 'MW_DBNAME' );
109101 if ( strlen( $dbname ) == 0 ) {
110102 if ( $this->site == "wikipedia" ) {
@@ -123,7 +115,7 @@
124116 * The key should be the dbname and the version should be the version directory for this wiki
125117 * @return String the version wirectory for this wiki
126118 */
127 - public function getVersion( ) {
 119+ public function getVersion() {
128120 $dbname = $this->getDatabase( $this->site, $this->lang );
129121 $db = dba_open( '/usr/local/apache/common/wikiversions.db', 'r', 'cdb' );
130122 if ( $db ) {
@@ -139,31 +131,44 @@
140132 /**
141133 * Factory method to get an instance of MWMultiVersion.
142134 * 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']
143137 * @return An MWMultiVersion object for this wiki
144138 */
145139 public static function getInstanceForWiki( $serverName, $docRoot ) {
146140 if (!isset(self::$mwversion)) {
147 - $c = __CLASS__;
148 - self::$mwversion = new $c;
 141+ self::$mwversion = new self;
 142+ self::$mwversion->setSiteInfoForWiki( $serverName, $docRoot );
149143 }
150 - self::$mwversion->setSiteInfoForWiki( $serverName, $docRoot);
151144 return self::$mwversion;
152145 }
153146
154147
155148 /**
156149 * 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']
157151 * @return An MWMultiVersion object for the wiki derived from the pathinfo
158152 */
159153 public static function getInstanceForUploadWiki( $pathInfo ) {
160154 if (!isset(self::$mwversion)) {
161 - $c = __CLASS__;
162 - self::$mwversion = new $c;
 155+ self::$mwversion = new self;
 156+ self::$mwversion->setSiteInfoForUploadWiki( $PathInfo );
163157 }
164 - self::$mwversion->setSiteInfoForUploadWiki( $PathInfo);
165158 return self::$mwversion;
166159 }
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+ }
168173 }
169174
170175 ?>
\ No newline at end of file
Index: trunk/tools/mwmultiversion/README
@@ -4,14 +4,17 @@
55
66 * Move wmf-config one level up
77 * 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
1011 * Copy common/php-1.17/cache/trusted-xff.cdb to the new source directory
1112 * Apply patches to CommonSettings.php
1213 * In InitialiseSettings.php make the following change:
1314 'wgCacheDirectory' => array(
1415 'default' => '/tmp/mw-cache-' . $wgVersionDirectory,
1516 * 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>
1819
 20+* TODO: Maintenance script changes are not done yet. Checked in as a patch for now.
 21+

Status & tagging log