r41437 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41436‎ | r41437 | r41438 >
Date:18:54, 30 September 2008
Author:brion
Status:old
Tags:
Comment:
Quickie remote proxy for Subversion accessor for CodeReview extension.
Wikimedia's web servers currently don't have direct access to our
Subversion server, which is in a separate data center.
Modified paths:
  • /trunk/tools/codereview-proxy (added) (history)
  • /trunk/tools/codereview-proxy/index.php (added) (history)

Diff [purge]

Index: trunk/tools/codereview-proxy/index.php
@@ -0,0 +1,126 @@
 2+<?php
 3+
 4+// Quickie remote proxy for Subversion accessor for CodeReview extension.
 5+// Wikimedia's web servers currently don't have direct access to our
 6+// Subversion server, which is in a separate data center.
 7+
 8+$data = runAction( "http://svn.wikimedia.org/svnroot/mediawiki" );
 9+
 10+header('Content-type: application/x-json');
 11+echo json_encode( $data );
 12+
 13+function inputStr( $key, $default=null ) {
 14+ if( isset( $_GET[$key] ) ) {
 15+ return str_replace( "\n", " ",
 16+ str_replace( "\r", "",
 17+ strval( $_GET[$key] ) ) );
 18+ } else {
 19+ return $default;
 20+ }
 21+}
 22+
 23+function inputInt( $key, $default=null ) {
 24+ if( isset( $_GET[$key] ) ) {
 25+ return intval( $_GET[$key] );
 26+ } else {
 27+ return $default;
 28+ }
 29+}
 30+
 31+function runAction( $basePath ) {
 32+ $svn = SubversionAdaptor::newFromRepo( $basePath );
 33+ $action = inputStr( 'action' );
 34+ if( $action == 'log' ) {
 35+ $path = inputStr( 'path' );
 36+ $start = inputInt( 'start' );
 37+ $end = inputInt( 'end' );
 38+ return $svn->getLog( $path, $start, $end );
 39+ } elseif( $action == 'diff' ) {
 40+ $path = inputStr( 'path' );
 41+ $rev1 = inputInt( 'rev1' );
 42+ $rev2 = inputInt( 'rev2' );
 43+ return $svn->getDiff( $path, $rev1, $rev2 );
 44+ } else {
 45+ return false;
 46+ }
 47+}
 48+
 49+abstract class SubversionAdaptor {
 50+ protected $mRepo;
 51+
 52+ public static function newFromRepo( $repo ) {
 53+ if( function_exists( 'svn_log' ) ) {
 54+ return new SubversionPecl( $repo );
 55+ } else {
 56+ throw new Exception("Requires SVN pecl module" );
 57+ }
 58+ }
 59+
 60+ function __construct( $repo ) {
 61+ $this->mRepo = $repo;
 62+ }
 63+
 64+ abstract function getFile( $path, $rev=null );
 65+
 66+ abstract function getDiff( $path, $rev1, $rev2 );
 67+
 68+ /*
 69+ array of array(
 70+ 'rev' => 123,
 71+ 'author' => 'myname',
 72+ 'msg' => 'log message'
 73+ 'date' => '8601 date',
 74+ 'paths' => array(
 75+ array(
 76+ 'action' => one of M, A, D, R
 77+ 'path' => repo URL of file,
 78+ ),
 79+ ...
 80+ )
 81+ */
 82+ abstract function getLog( $path, $startRev=null, $endRev=null );
 83+
 84+ protected function _rev( $rev, $default ) {
 85+ if( $rev === null ) {
 86+ return $default;
 87+ } else {
 88+ return intval( $rev );
 89+ }
 90+ }
 91+}
 92+
 93+/**
 94+ * Using the SVN PECL extension...
 95+ * Untested!
 96+ */
 97+class SubversionPecl extends SubversionAdaptor {
 98+ function getFile( $path, $rev=null ) {
 99+ return svn_cat( $this->mRepo . $path, $rev );
 100+ }
 101+
 102+ function getDiff( $path, $rev1, $rev2 ) {
 103+ list( $fout, $ferr ) = svn_diff(
 104+ $this->mRepo . $path, $rev1,
 105+ $this->mRepo . $path, $rev2 );
 106+
 107+ if( $fout ) {
 108+ // We have to read out the file descriptors. :P
 109+ $out = '';
 110+ while( !feof( $fout ) ) {
 111+ $out .= fgets( $fout );
 112+ }
 113+ fclose( $fout );
 114+ fclose( $ferr );
 115+
 116+ return $out;
 117+ } else {
 118+ return new Exception("Diffing error");
 119+ }
 120+ }
 121+
 122+ function getLog( $path, $startRev=null, $endRev=null ) {
 123+ return svn_log( $this->mRepo . $path,
 124+ $this->_rev( $startRev, SVN_REVISION_INTIAL ),
 125+ $this->_rev( $endRev, SVN_REVISION_HEAD ) );
 126+ }
 127+}
Property changes on: trunk/tools/codereview-proxy/index.php
___________________________________________________________________
Added: svn:eol-style
1128 + native

Status & tagging log