r93032 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93031‎ | r93032 | r93033 >
Date:00:04, 25 July 2011
Author:aaron
Status:resolved
Tags:
Comment:
* Ported mwversionsinuse code to activeMWVersions PHP script file. mwversionsinuse is now a thin wrapper around activeMWVersions.
* activeMWVersions has a '--home' option (to be used by scap).
* mwscript comment tweak.
Modified paths:
  • /trunk/tools/mwmultiversion/multiversion/activeMWVersions (added) (history)
  • /trunk/tools/mwmultiversion/scripts/mwscript (modified) (history)
  • /trunk/tools/mwmultiversion/scripts/mwversionsinuse (modified) (history)

Diff [purge]

Index: trunk/tools/mwmultiversion/multiversion/activeMWVersions
@@ -0,0 +1,46 @@
 2+#!/usr/bin/env php
 3+<?php
 4+error_reporting( E_ALL );
 5+/*
 6+ * Returns a space separated list of all active MW versions (e.g. "x.xx").
 7+ * Versions are read from /usr/local/apache/common-local/wikiversions.cdb.
 8+ *
 9+ * Given --home, versions are instead read from /home/wikipedia/common/wikiversions.cdb.
 10+ * 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.
 12+ *
 13+ * @return string
 14+ */
 15+function getActiveWikiVersions() {
 16+ global $argv;
 17+ $options = array_shift( $argv ); // this file
 18+
 19+ if ( in_array( '--home', $options ) ) {
 20+ $path = '/home/wikipedia/common/wikiversions.dat';
 21+ } else {
 22+ $path = '/usr/local/apache/common-local/wikiversions.dat';
 23+ }
 24+
 25+ $verList = array_filter( explode( "\n", file_get_contents( $path ) ) );
 26+ if ( !count( $verList ) ) {
 27+ die( "Unable to read wikiversions.dat.\n" );
 28+ }
 29+
 30+ $result = $activeVersions = array();
 31+ foreach ( $verList as $item ) {
 32+ list( $dbname, $version ) = explode( ' ', $item );
 33+ $version = str_replace( 'php-', '', $version ); // remove 'php-'
 34+ if ( !isset( $activeVersions[$version] ) ) {
 35+ $activeVersions[$version] = 1;
 36+ if ( in_array( '--withdb', $options ) ) {
 37+ $result[] = "{$version}={$dbname}";
 38+ } else {
 39+ $result[] = "{$version}";
 40+ }
 41+ }
 42+ }
 43+
 44+ return implode( ' ', $result );
 45+}
 46+
 47+echo getActiveWikiVersions();
Index: trunk/tools/mwmultiversion/scripts/mwversionsinuse
@@ -1,36 +1,4 @@
2 -#!/bin/bash
3 -# Returns a space separated list of all active MW versions (e.g. "x.xx").
4 -# Versions are defined in /usr/local/apache/common-local/wmf-config/wikiversions.cdb.
5 -# If --withdb is passed in, then each item in the list will be appended
6 -# with '=' followed by the DB name of *some* wiki that uses that version.
7 -# This script belongs in /usr/bin/.
8 -declare -a mwVersionsRes
9 -declare -a mwVersionsNums
10 -while read line
11 -do
12 - mwDbName=${line% *}
13 - mwVersion=${line#* }
14 - mwVersionNum=${mwVersion#*-}
15 - if [ -n "$mwDbName" -a -n "$mwVersionNum" ]; then
16 - mwVersionInArray=0
17 - for i in "${mwVersionsNums[@]}"
18 - do
19 - if [ "$i" = "$mwVersionNum" ]; then
20 - mwVersionInArray=1
21 - break
22 - fi
23 - done
24 -
25 - if [ "$mwVersionInArray" -eq "0" ]; then
26 - mwVersionsNums=("${mwVersionsNums[@]}" "$mwVersionNum")
27 - if [ "$1" = "--withdb" ]; then
28 - mwVersionsRes=("${mwVersionsRes[@]}" "$mwVersionNum=$mwDbName")
29 - else
30 - mwVersionsRes=("${mwVersionsRes[@]}" "$mwVersionNum")
31 - fi
32 - fi
33 - else
34 - exit 1
35 - fi
36 -done < /usr/local/apache/common-local/wikiversions.dat
37 -echo "${mwVersionsRes[@]}"
 2+#!/bin/sh
 3+# Shell wrapper for the local version of multiversion/activeMWVersions.
 4+# This script belongs in /usr/bin/ and should be in PATH.
 5+echo `/usr/local/apache/common-local/multiversion/activeMWVersions $@`
Index: trunk/tools/mwmultiversion/scripts/mwscript
@@ -1,5 +1,5 @@
22 #!/bin/sh
3 -# Shell wrapper for the local version of MWScript.php.
 3+# Shell wrapper for the local version of multiversion/MWScript.php.
44 # This script belongs in /usr/bin/ and should be in PATH.
55 if [ ! php /usr/local/apache/common/multiversion/MWScript.php "$@" ]; then
66 exit 1

Follow-up revisions

RevisionCommit summaryAuthorDate
r93033Follow-up r93032: fixed use of $options var. Restored newline in output.aaron01:00, 25 July 2011
r93086svn:eol-style native for r93032catrope18:53, 25 July 2011

Status & tagging log