r93512 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93511‎ | r93512 | r93513 >
Date:04:53, 30 July 2011
Author:aaron
Status:resolved (Comments)
Tags:
Comment:
* Changed wikiversions.dat/wikiversions.cdb file to allow for making wikis use there own caches (like i18n). This can be done by adding the dbname as a third column column value in the dat file. This is useful if we have two versions of an extensions in the deployment branches, which some wikis using one and some the other.
* Changed scap/l10n scripts to handle wikis with seperate i18n caches.
* Refactored out a new loadVersionInfo() method and process cache the results.
* Added missing dba_close().
Modified paths:
  • /trunk/tools/mwmultiversion/multiversion/MWMultiVersion.php (modified) (history)
  • /trunk/tools/mwmultiversion/multiversion/MWScript.php (modified) (history)
  • /trunk/tools/mwmultiversion/multiversion/activeMWVersions (modified) (history)
  • /trunk/tools/mwmultiversion/multiversion/checkoutMediaWiki (modified) (history)
  • /trunk/tools/mwmultiversion/multiversion/refreshWikiversionsCDB (modified) (history)
  • /trunk/tools/mwmultiversion/scripts/l10nupdate (modified) (history)
  • /trunk/tools/mwmultiversion/scripts/scap (modified) (history)
  • /trunk/tools/mwmultiversion/scripts/sync-l10nupdate (modified) (history)

Diff [purge]

Index: trunk/tools/mwmultiversion/multiversion/refreshWikiversionsCDB
@@ -24,8 +24,13 @@
2525 die( "Unable to create wikiversions.cdb.tmp.\n" );
2626 }
2727 foreach ( $verList as $row ) {
28 - list( $dbName, $version ) = explode( ' ', $row );
29 - dba_insert( $dbName, $version, $db );
 28+ $items = explode( ' ', $row );
 29+ $dbName = $items[0];
 30+ $version = $items[1];
 31+ $extVersion = isset( $items[2] ) ? $items[2] : '';
 32+
 33+ dba_insert( "ver:$dbName", $version, $db );
 34+ dba_insert( "ext:$dbName", $extVersion, $db );
3035 }
3136 dba_close( $db );
3237
Index: trunk/tools/mwmultiversion/multiversion/activeMWVersions
@@ -7,7 +7,9 @@
88 *
99 * Given --home, versions are instead read from /home/wikipedia/common/wikiversions.cdb.
1010 * Given --withdb, each item in the list will be appended with '=' followed by
11 - * the DB name of *some* wiki that uses that version. Used to run maintenance scripts.
 11+ * the DB name of *some* wiki that uses that version. Used to run maintenance scripts.
 12+ * Given --extended, versions will include any extra suffix specified in wikiversions.cdb.
 13+ * This may result in more items being listed than without.
1214 * Given --report, error messages would be displayed if this dies.
1315 *
1416 * @return string
@@ -33,7 +35,11 @@
3436
3537 $result = $activeVersions = array();
3638 foreach ( $verList as $item ) {
37 - list( $dbname, $version ) = explode( ' ', $item );
 39+ $items = explode( ' ', $row );
 40+ $dbName = $items[0];
 41+ $version = $items[1];
 42+ $extVersion = isset( $items[2] ) ? $items[2] : '';
 43+
3844 if ( substr( $version, 0, 4 ) !== 'php-' ) {
3945 if ( in_array( '--report', $options ) ) {
4046 echo( "Unable to read wikiversions.dat entry: $version.\n" );
@@ -41,10 +47,15 @@
4248 die( 1 );
4349 }
4450 $version = substr( $version, 4 ); // remove 'php-'
 51+
 52+ if ( $extVersion !== '' && in_array( '--extended', $options ) ) {
 53+ $version .= "-$extVersion";
 54+ }
 55+
4556 if ( !isset( $activeVersions[$version] ) ) {
4657 $activeVersions[$version] = 1;
4758 if ( in_array( '--withdb', $options ) ) {
48 - $result[] = "{$version}={$dbname}";
 59+ $result[] = "{$version}={$dbName}";
4960 } else {
5061 $result[] = "{$version}";
5162 }
Index: trunk/tools/mwmultiversion/multiversion/checkoutMediaWiki
@@ -25,7 +25,7 @@
2626 if ( count( $argv ) >= 3 ) {
2727 $svnVersion = $argv[1]; // e.g. "X.XXwmfX"
2828 $dstVersion = $argv[2]; // e.g. "php-X.XX"
29 - if ( preg_match( '/^php-(\d+\.\d+|trunk)$/', $dstVersion, $m ) ) {
 29+ if ( preg_match( '/^php-((?:\d+\.\d+|trunk)(?:-\d)?)$/', $dstVersion, $m ) ) {
3030 $dstVersionNum = $m[1];
3131 $argsValid = true;
3232 }
Index: trunk/tools/mwmultiversion/multiversion/MWMultiVersion.php
@@ -12,6 +12,18 @@
1313 * @var string
1414 */
1515 private $db;
 16+ /**
 17+ * @var string
 18+ */
 19+ private $version;
 20+ /**
 21+ * @var string
 22+ */
 23+ private $extVersion;
 24+ /**
 25+ * @var bool
 26+ */
 27+ private $versionLoaded = false;
1628
1729 /**
1830 * To get an inststance of this class, use the statuc helper methods.
@@ -155,7 +167,7 @@
156168 $dbname = isset( $argv[2] ) ? $argv[2] : ''; // "script.php --wiki dbname"
157169 } elseif ( isset( $argv[1] ) && substr( $argv[1], 0, 7 ) === '--wiki=' ) {
158170 $dbname = substr( $argv[1], 7 ); // "script.php --wiki=dbname"
159 - } elseif ( isset( $argv[1] )&& substr( $argv[1], 0, 2 ) !== '--' ) {
 171+ } elseif ( isset( $argv[1] ) && substr( $argv[1], 0, 2 ) !== '--' ) {
160172 $dbname = $argv[1]; // "script.php dbname"
161173 } elseif ( in_array( $argv[0], self::wikilessScripts() ) ) {
162174 # For addwiki.php, the DB doesn't yet exist, and for nextJobDB.php
@@ -205,34 +217,75 @@
206218 }
207219
208220 /**
209 - * Get the version as specified in a cdb file located
210 - * at /usr/local/apache/common/wikiversions.cdb.
211 - * The key should be the dbname and the version should be the version directory.
212 - * @return String the version directory for this wiki
 221+ * Get the space-seperated list of version params for this wiki.
 222+ * The first item is the MW version and the optional second item
 223+ * an extra version parameter to use for builds and caches.
 224+ * @return void
213225 */
214 - public function getVersion() {
 226+ private function loadVersionInfo() {
 227+ if ( $this->versionLoaded ) {
 228+ return;
 229+ }
 230+ $this->versionLoaded = true;
 231+
215232 $db = dba_open( '/usr/local/apache/common/wikiversions.cdb', 'r', 'cdb' );
216233 if ( $db ) {
217 - $version = dba_fetch( $this->getDatabase(), $db );
 234+ $version = dba_fetch( "ver:{$this->db}", $db );
218235 if ( $version === false ) {
219 - die( "wikiversions.cdb has no entry for `$db`.\n" );
 236+ die( "wikiversions.cdb has no version entry for `$db`.\n" );
220237 } elseif ( strpos( $version, 'php-' ) !== 0 ) {
221 - die( "wikiversions.cdb entry does not start with `php-` (got `$version`).\n" );
 238+ die( "wikiversions.cdb version entry does not start with `php-` (got `$version`).\n" );
222239 }
 240+ $extraVersion = dba_fetch( "ext:{$this->db}", $db );
 241+ if ( $extraVersion === false ) {
 242+ die( "wikiversions.cdb has no extra version entry for `$db`.\n" );
 243+ }
223244 } else {
224 - //trigger_error( "Unable to open /usr/local/apache/common/wikiversions.cdb. Assuming php-1.17", E_USER_ERROR );
 245+ //trigger_error( "Unable to open wikiversions.cdb. Assuming php-1.17", E_USER_ERROR );
225246 $version = 'php-1.17';
 247+ $extraVersion = '';
226248 }
227 - return $version;
 249+ dba_close( $db );
 250+
 251+ $this->version = $version;
 252+ $this->extVersion = $extraVersion;
228253 }
229254
230255 /**
 256+ * Get the version as specified in a cdb file located
 257+ * at /usr/local/apache/common/wikiversions.cdb.
 258+ * Result is of the form "php-X.XX" or "php-trunk".
 259+ * @return String the version directory for this wiki
 260+ */
 261+ public function getVersion() {
 262+ $this->loadVersionInfo();
 263+ return $this->version;
 264+ }
 265+
 266+ /**
231267 * Get the version number as specified in a cdb file located
232 - * at /usr/local/apache/common/wikiversions.cdb.
 268+ * at /usr/local/apache/common/wikiversions.cdb. Do not use this
 269+ * to determine the path to cache or binary files, only the core MW code.
233270 * @return String the version number for this wiki (e.g. "x.xx" or "trunk")
234271 */
235272 public function getVersionNumber() {
236 - list( /*...*/, $ver ) = explode( '-', $this->getVersion(), 2 );
 273+ $this->loadVersionInfo();
 274+ return substr( $this->version, 4 ); // remove "php-"
 275+ }
 276+
 277+ /*
 278+ * Get the version number to use for building caches & binaries for this wiki.
 279+ * Like getVersionNumber() but may have a dash with another string appended.
 280+ * Some wikis may share core MW versions but be using different extension versions.
 281+ * We need to keep the caches and binary builds separate for such wikis.
 282+ * @return String
 283+ */
 284+ public function getExtendedVersionNumber() {
 285+ $this->loadVersionInfo();
 286+ $ver = $this->getVersionNumber();
 287+ if ( $this->extVersion !== '' ) {
 288+ $ver .= "-{$this->extVersion}";
 289+ }
237290 return $ver;
238291 }
239292 }
Index: trunk/tools/mwmultiversion/multiversion/MWScript.php
@@ -46,5 +46,5 @@
4747 return $file;
4848 }
4949
50 -# Run the script! (for HipHip, we will need to shell out here)
 50+# Run the script!
5151 require_once( getMWScriptWithArgs() );
Index: trunk/tools/mwmultiversion/scripts/scap
@@ -43,6 +43,7 @@
4444 $BINDIR/sync-common
4545
4646
 47+mwVerDbSets=(`mwversionsinuse --extended --withdb`)
4748 # Regenerate the extension message file list for all active MediaWiki versions
4849 for i in "${mwVerDbSets[@]}"
4950 do
Index: trunk/tools/mwmultiversion/scripts/sync-l10nupdate
@@ -3,11 +3,10 @@
44 PATH=/bin:/usr/bin:/sbin:/usr/sbin:
55 MWVER="$1"
66
7 -mwVersionNums=(`mwversionsinuse`)
 7+mwVersionNums=(`mwversionsinuse --extended`)
88
99 echo "Synchronizing /home/wikipedia/common/php-$MWVER/cache/l10n to /usr/local/apache/common-local/php-$MWVER/cache/l10n..."
1010 echo "mediawiki-installation:"
1111
1212 ddsh -cM -g mediawiki-installation \
1313 "sudo -u mwdeploy rsync -a 10.0.5.8::common/php-$MWVER/cache/l10n/ /usr/local/apache/common-local/php-$MWVER/cache/l10n"
14 -
Index: trunk/tools/mwmultiversion/scripts/l10nupdate
@@ -15,7 +15,7 @@
1616 exit 1
1717 fi
1818
19 -mwVerDbSets=(`mwversionsinuse --withdb`)
 19+mwVerDbSets=(`mwversionsinuse --extended --withdb`)
2020 if [ -z "$mwVerDbSets" ]; then
2121 /home/wikipedia/bin/dologmsg "!log LocalisationUpdate failed"
2222 echo "FAILED"

Follow-up revisions

RevisionCommit summaryAuthorDate
r93632* Fixed undefined $item var in r93512...aaron17:15, 1 August 2011

Comments

#Comment by Aaron Schulz (talk | contribs)   04:57, 30 July 2011

Also loosened the version name restriction in checkoutMediaWiki a bit.

#Comment by Catrope (talk | contribs)   21:50, 10 August 2011
+		if ( preg_match( '/^php-((?:\d+\.\d+|trunk)(?:-\d)?)$/', $dstVersion, $m ) ) {

This restricts extversions to be a single digit, which is a problem if we want to have >10 of them.

#Comment by Aaron Schulz (talk | contribs)   21:59, 10 August 2011

I was aware of that. It will be a while before that becomes a problem at this rate.

If we do need it, it can be expanded.

Status & tagging log