r92547 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92546‎ | r92547 | r92548 >
Date:17:58, 19 July 2011
Author:aaron
Status:ok (Comments)
Tags:
Comment:
* Added shell script wrapper to MWScript.php
* Added script to checkout a new MW version
Modified paths:
  • /trunk/tools/mwmultiversion/MWScript.php (modified) (history)
  • /trunk/tools/mwmultiversion/checkoutMediaWiki.php (added) (history)
  • /trunk/tools/mwmultiversion/scripts/MWScript.sh (added) (history)

Diff [purge]

Index: trunk/tools/mwmultiversion/checkoutMediaWiki.php
@@ -0,0 +1,128 @@
 2+<?php
 3+if ( php_sapi_name() !== 'cli' ) {
 4+ exit; // sanity, script run via CLI
 5+}
 6+
 7+error_reporting( E_ALL );
 8+
 9+/**
 10+ * Automatically SVN checkout a MediaWiki version and do some basic wmf setup.
 11+ * LocalSettings.php will be created (which loads CommonSettings.php) and verious
 12+ * symlinks will also be created.
 13+ *
 14+ * The first argument is the SVN directory (relative to mediawiki/branches/wmf).
 15+ * This is typically a version of the format "X.XXwmfX" ("e.g. 1.17wmf1").
 16+ * The second argument is the target path (relative to /home/wikipedia/common/)
 17+ * to store local copy of the SVN checkout. This is typically of the format "php-X.XX".
 18+ *
 19+ * The script will not run if files already existing in the target directory.
 20+ * Also, assume the user running this script must have an SVN account
 21+ * with the SSH agent/key available.
 22+ *
 23+ * @return void
 24+ */
 25+function checkoutMediaWiki() {
 26+ global $argv;
 27+ $commonDir = '/home/wikipedia/common';
 28+
 29+ $argsValid = false;
 30+ if ( count( $argv ) >= 3 ) {
 31+ $svnVersion = $argv[1]; // e.g. "X.XXwmfX"
 32+ $dstVersion = $argv[2]; // e.g. "php-X.XX"
 33+ if ( preg_match( '/^php-(\d+\.\d+)$/', $dstVersion, $m ) ) {
 34+ $dstVersionNum = $m[1];
 35+ $argsValid = true;
 36+ }
 37+ }
 38+
 39+ if ( !$argsValid ) {
 40+ die( "Usage: checkoutMediaWiki.php X.XXwmfX php-X.XX" );
 41+ }
 42+
 43+ # The url to SVN to checkout from
 44+ $source = "svn+ssh://svn.wikimedia.org/svnroot/mediawiki/branches/wmf/$svnVersion";
 45+
 46+ # Create the destination path to SVN checkout to...
 47+ $destIP = "$commonDir/$dstVersion";
 48+ if ( file_exists( $destIP ) ) {
 49+ die( "Cannot checkout, the directory $destIP already exists.\n" );
 50+ }
 51+ print "Creating checkout directory $destIP...";
 52+ mkdir( $destIP, 0775 );
 53+ print "done.\n";
 54+
 55+ print "Checking out $source to $destIP...\n";
 56+ # Checkout the SVN directory...
 57+ $retval = 1; // error by default?
 58+ passthru( "svn checkout $source $destIP", $retval );
 59+ if ( $retval !== 0 ) {
 60+ rmdir( $destIP ); // rollback
 61+ die( "\nUnable to checkout SVN path." );
 62+ }
 63+ print "...SVN checkout done.\n";
 64+
 65+ $localSettingsCode = <<<EOT
 66+<?php
 67+# WARNING: This file is publically viewable on the web. Do not put private data here.
 68+if ( defined('TESTWIKI') ) {
 69+ include_once( "/home/wikipedia/common/wmf-config/CommonSettings.php" );
 70+} else {
 71+ include_once( "/apache/common/wmf-config/CommonSettings.php" );
 72+}
 73+EOT;
 74+
 75+ # Create LocalSettings.php stub...
 76+ $path = "$destIP/LocalSettings.php";
 77+ if ( !file_exists( $path ) ) {
 78+ $handle = fopen( $path, "w" );
 79+ if ( $handle ) {
 80+ fwrite( $handle, $localSettingsCode );
 81+ fclose( $handle );
 82+ print "Created LocalSettings.php file.\n";
 83+ }
 84+ } else {
 85+ print "File already exists: $path\n";
 86+ }
 87+
 88+ # Create symlink to wmf-config/AdminSettings.php...
 89+ $path = "$destIP/AdminSettings.php";
 90+ if ( !file_exists( $path ) ) {
 91+ if ( symlink( "../wmf-config/AdminSettings.php", $path ) ) {
 92+ print "Created AdminSettings.php symlink.\n";
 93+ }
 94+ } else {
 95+ print "File already exists: $path\n";
 96+ }
 97+
 98+ # Create symlink to wmf-config/StartProfiler.php...
 99+ $path = "$destIP/StartProfiler.php";
 100+ if ( !file_exists( $path ) ) {
 101+ if ( symlink( "../wmf-config/StartProfiler.php", $path ) ) {
 102+ print "Created StartProfiler.php symlink.\n";
 103+ }
 104+ } else {
 105+ print "File already exists: $path\n";
 106+ }
 107+
 108+ # Create bits.wikimedia.org symlinks...
 109+ $path = "$commonDir/docroot/bits/skins-$dstVersionNum";
 110+ if ( !file_exists( $path ) ) {
 111+ if ( symlink( "/usr/local/apache/common/php-$dstVersionNum/skins/", $path ) ) {
 112+ print "Created skins-$dstVersionNum symlink.\n";
 113+ }
 114+ } else {
 115+ print "File already exists: $path\n";
 116+ }
 117+ $path = "$commonDir/docroot/bits/w/extensions-$dstVersionNum";
 118+ if ( !file_exists( $path ) ) {
 119+ if ( symlink( "/usr/local/apache/common/php-$dstVersionNum/extensions", $path ) ) {
 120+ print "Created w/extensions-$dstVersionNum symlink.\n";
 121+ }
 122+ } else {
 123+ print "File already exists: $path\n";
 124+ }
 125+
 126+ print "MediaWiki $dstVersionNum, from $svnVersion, successfully checked out.\n";
 127+}
 128+
 129+checkoutMediaWiki();
Property changes on: trunk/tools/mwmultiversion/checkoutMediaWiki.php
___________________________________________________________________
Added: svn:eol-style
1130 + native
Index: trunk/tools/mwmultiversion/scripts/MWScript.sh
@@ -0,0 +1,4 @@
 2+#!/bin/sh
 3+# Shell wrapper for the local version of MWScript.php.
 4+# This script belongs in /usr/bin/ and should be in PATH.
 5+php /usr/local/apache/common/MWScript.php "$@"
Property changes on: trunk/tools/mwmultiversion/scripts/MWScript.sh
___________________________________________________________________
Added: svn:eol-style
16 + native
Added: svn:executable
27 + *
Index: trunk/tools/mwmultiversion/MWScript.php
@@ -3,6 +3,8 @@
44 exit; // sanity, script run via CLI
55 }
66
 7+error_reporting( E_ALL );
 8+
79 /**
810 * Run a MediaWiki script based on the parameters (like --wiki) given to CLI.
911 *

Follow-up revisions

RevisionCommit summaryAuthorDate
r92667Code cleanups per r92547aaron19:17, 20 July 2011

Comments

#Comment by Catrope (talk | contribs)   19:07, 20 July 2011
+	exit; // sanity, script run via CLI

Should be at least a little bit descriptive, e.g. die( 'This script can only be run from the command line' ).

+		$handle = fopen( $path, "w" );
+		if ( $handle ) {
+			fwrite( $handle, $localSettingsCode );
+			fclose( $handle );
+			print "Created LocalSettings.php file.\n";
+		}

Could file_put_contents() make your life easier?

+	$path = "$commonDir/docroot/bits/w/extensions-$dstVersionNum";

Undefined var $dstVersionNum.

#Comment by Aaron Schulz (talk | contribs)   19:12, 20 July 2011

$dstVersionNum is defined in line 33.

#Comment by Catrope (talk | contribs)   19:15, 20 July 2011

D'oh!

Status & tagging log