r98877 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98876‎ | r98877 | r98878 >
Date:17:56, 4 October 2011
Author:aaron
Status:ok (Comments)
Tags:
Comment:
Simplified script a bit with preg_replace. Tested with local .dat files.
Modified paths:
  • /trunk/tools/mwmultiversion/multiversion/switchAllMediaWikis (modified) (history)

Diff [purge]

Index: trunk/tools/mwmultiversion/multiversion/switchAllMediaWikis
@@ -40,24 +40,15 @@
4141 die( "Unable to read wikiversions.dat.\n" );
4242 }
4343
44 - $datList = "";
 44+ $what = '/^(\w+) ' . preg_quote( $oldVersion ) . '( |$)/';
 45+ $with = '$1 ' . $newVersion . '$2';
 46+
4547 $count = 0;
 48+ $datList = "";
4649 foreach ( $verList as $row ) {
47 - $items = explode( ' ', trim( $row ) );
48 - # Existing values...
49 - $dbName = $items[0];
50 - $version = $items[1];
51 - $extVersion = isset( $items[2] ) ? $items[2] : '';
52 - # Update this wiki?
53 - if ( $version === $oldVersion || $oldVersion === 'all' ) {
54 - $version = $newVersion; // switch!
55 - $count++;
56 - }
57 - if ( $extVersion !== '' ) {
58 - $datList .= "{$dbName} {$version} {$extVersion}\n";
59 - } else {
60 - $datList .= "{$dbName} {$version}\n";
61 - }
 50+ $n = 0;
 51+ $datList .= preg_replace( $what, $with, trim( $row ), -1, $n ) . "\n";
 52+ $count += $n;
6253 }
6354
6455 # Backup old wikiversions.dat...

Comments

#Comment by Catrope (talk | contribs)   20:47, 4 October 2011

Unrelated to this commit, but elsewhere in the file:

die( "Usage: upgradeMediaWikis php-X.XX php-X.XX\n" );

doesn't match the script's current name.

Status & tagging log