[git] web/doc-editor.git branch master updated. b644816

From: Date: Fri, 17 Feb 2012 13:59:12 +0000
Subject: [git] web/doc-editor.git branch master updated. b644816
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-9611@lists.php.net to get a copy of this message
The branch, master on web/doc-editor.git has been updated via b6448167ecb4c24d3c1df8ecee780a603a10e544 (commit) from 8aa7dcd6e6eb74c8d83e630b66ad510cc0e0e6ea (commit) http://git.php.net/?p=web/doc-editor.git;a=log;h=b6448167ecb4c24d3c1df8ecee780a603a10e544;hp=8aa7dcd6e6eb74c8d83e630b66ad510cc0e0e6ea Summary of changes: php/ExtJsController.php | 57 ++++++++------- php/File.php | 186 +++++++---------------------------------------- php/utility.php | 176 ++++++++++++++++++++++++++------------------ 3 files changed, 163 insertions(+), 256 deletions(-) -- Log ---------------------------------------- commit b6448167ecb4c24d3c1df8ecee780a603a10e544 Author: Alexander Moskaliov <irker@php.net> Date: Fri Feb 17 17:48:11 2012 +0400 Refactor Diff fo fix #61113 diff --git a/php/ExtJsController.php b/php/ExtJsController.php index 7a75aad..d7d1c4f 100644 --- a/php/ExtJsController.php +++ b/php/ExtJsController.php @@ -1239,12 +1239,12 @@ class ExtJsController } $DiffType = $this->getRequestVariable('DiffType'); - $FilePath = $this->getRequestVariable('FilePath'); + $FileFullPath = $this->getRequestVariable('FilePath'); $FileName = $this->getRequestVariable('FileName'); - $t = explode('/', $FilePath); - $FileLang = array_shift($t); - $FilePath = implode('/', $t); + $t = explode('/', $FileFullPath, 2); + $FileLang = $t[0]; + $FilePath = $t[1]; $opt = null; @@ -1259,25 +1259,26 @@ class ExtJsController $Rev2 = $Rev1; $Rev1 = $tmp; } + $r = VCSFactory::getInstance()->diff( + $FileFullPath, + $FileName, + $Rev1, + $Rev2 + ); - $opt = Array('rev1'=>$Rev1, 'rev2' => $Rev2); - - } elseif( $DiffType == 'file' ) { - - $opt['patchID'] = $this->getRequestVariable('patchID'); - $opt['type'] = 'file'; - - } elseif( $DiffType == 'patch' ) { + } elseif( $DiffType == 'file') { - $uniqID = $this->getRequestVariable('uniqID'); - $opt['type'] = 'patch'; - $opt['uniqID'] = $uniqID; + $patchID = $this->getRequestVariable('patchID'); + if ($patchID) { + $r = File::patchDiff($patchID); + } else { + $file = new File($FileLang, $FilePath.$FileName); + $r = $file->diff(); + } } - $file = new File($FileLang, $FilePath.$FileName); - $r = $file->Diff($DiffType, $opt); - + $r = DiffGenHTMLOutput($r); return JsonResponseBuilder::success( array( 'content' => $r @@ -2137,21 +2138,23 @@ class ExtJsController return JsonResponseBuilder::failure(); } - $FilePath = $this->getRequestVariable('FilePath'); + $FileFullPath = $this->getRequestVariable('FilePath'); $FileName = $this->getRequestVariable('FileName'); $patchID = $this->getRequestVariable('patchID'); - $t = explode('/', $FilePath); - $FileLang = array_shift($t); - $FilePath = implode('/', $t); + $t = explode('/', $FileFullPath, 2); + $FileLang = $t[0]; + $FilePath = $t[1]; - $file = new File($FileLang, $FilePath.$FileName); - $patch = $file->rawDiff($patchID); + if ($patchID) { + $patch = File::patchDiff($patchID); + } else { + $file = new File($FileLang, $FilePath.$FileName); + $patch = $file->diff(); + } $name = 'patch-' . time() . '.patch'; - $size = strlen($patch); - header("Content-Type: application/force-download; name=\"$name\""); header("Content-Transfer-Encoding: binary"); header("Content-Disposition: attachment; filename=\"$name\""); @@ -2159,7 +2162,7 @@ class ExtJsController header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); - return $patch; + return implode("\n", $patch); } /** diff --git a/php/File.php b/php/File.php index d5eca14..a46c0bc 100644 --- a/php/File.php +++ b/php/File.php @@ -38,7 +38,7 @@ class File { $appConf = AccountManager::getInstance()->appConf; $project = AccountManager::getInstance()->project; - + // Security $path = str_replace('..', '', $path); $path = str_replace('//', '/', $path); @@ -409,173 +409,43 @@ class File return $info; } - /** - * Get a raw diff between a file and its modified file. - * - * @param $patchID If set, indicate the ID of the patch from witch we have to retrieve all files diff - * @return The diff of the file with its modified version. - */ - public function rawDiff($patchID=false) - { - $am = AccountManager::getInstance(); - $appConf = $am->appConf; - $project = $am->project; - if( $patchID ) { - - $return=''; - $output = array(); - - $patchFiles = RepositoryManager::getInstance()->getPatchFilesByID($patchID); - for( $i=0; $i < count($patchFiles); $i++ ) - { - - $pathFileOrigin = $appConf[$project]['vcs.path'] . $patchFiles[$i]->lang . $patchFiles[$i]->path . $patchFiles[$i]->name; - $pathFileModified = $appConf['GLOBAL_CONFIGURATION']['data.path'].$appConf[$project]['vcs.module'].'-new/' . $patchFiles[$i]->lang . $patchFiles[$i]->path . $patchFiles[$i]->name; - - $commands = array( - new ExecStatement('diff -uN %s %s', array($pathFileOrigin, $pathFileModified)) - ); - - $trial_threshold = 3; - while ($trial_threshold-- > 0) - { - $_output = array(); - SaferExec::execMulti($commands, $_output); - if (strlen(trim(implode('', $_output))) != 0) break; - } - - $output = array_merge($output, $_output); - } - - return implode("\r\n", $output); - - } else { - - $pathFileOrigin = $appConf[$project]['vcs.path'] . $this->lang . $this->path . $this->name; - $pathFileModified = $appConf['GLOBAL_CONFIGURATION']['data.path'].$appConf[$project]['vcs.module'].'-new/' . $this->lang . $this->path . $this->name; - - $commands = array( - new ExecStatement('diff -uN %s %s', array($pathFileOrigin, $pathFileModified)) - ); + public function diff() + { + $commands = array( + new ExecStatement( + 'diff -uN --label %s --label %s %s %s', + array( + $this->lang.$this->path.$this->name, + $this->lang.$this->path.$this->name, + $this->full_path, + $this->full_new_path + ) + ) + ); + $trial_threshold = 3; + while ($trial_threshold-- > 0) + { $output = array(); SaferExec::execMulti($commands, $output); - - return implode("\r\n", $output); + if (strlen(trim(implode('', $output))) != 0) break; } + + return $output; } - /** - * Get the diff of a file with his modified version. - * - * @param $rev1 First revison. - * @param $rev2 Second revision. - * @return The diff a the file with his modified version, as HTML, ready to be display. - */ - public function Diff($type, $options) + public static function patchDiff($patchId) { - $am = AccountManager::getInstance(); - $appConf = $am->appConf; - $project = $am->project; - $return = ''; $output = array(); - - if( $type == 'vcs' ) { - - $output = VCSFactory::getInstance()->diff( - $this->lang.$this->path, - $this->name, $options['rev1'], $options['rev2'] - ); - - $return = $this->DiffGenHTMLOutput($output); - - } elseif( $type == 'file' || $type == 'patch' ) { - - //$ext = ( $options['type'] == 'patch' ) ? '.' . $options['uniqID'] . '.patch' : '.new'; - - // If this patch is for new file, we only display "This is a new file." - if( $type == 'patch' && !is_file($appConf[$project]['vcs.path'].$this->lang.$this->path.$this->name) ) { - return '<div style="size: 10px; text-align:center;margin-top:10px;">This is a new file.</div>'; - } else { - - if( $options['patchID'] == '' ) - { - - $pathFileOrigin = $appConf[$project]['vcs.path'] . $this->lang . $this->path . $this->name; - $pathFileModified = $appConf['GLOBAL_CONFIGURATION']['data.path'].$appConf[$project]['vcs.module'].'-new/' . $this->lang . $this->path . $this->name; - - $commands = array( - new ExecStatement('diff -uN %s %s', array($pathFileOrigin, $pathFileModified)) - ); - - $trial_threshold = 3; - while ($trial_threshold-- > 0) { - $output = array(); - SaferExec::execMulti($commands, $output); - if (strlen(trim(implode('', $output))) != 0) break; - } - - $return = $this->DiffGenHTMLOutput($output); - - } - else - { - // We get all files from this patch - $patchFiles = RepositoryManager::getInstance()->getPatchFilesByID($options['patchID']); - - for( $i=0; $i < count($patchFiles); $i++ ) - { - - $pathFileOrigin = $appConf[$project]['vcs.path'] . $patchFiles[$i]->lang . $patchFiles[$i]->path . $patchFiles[$i]->name; - $pathFileModified = $appConf['GLOBAL_CONFIGURATION']['data.path'].$appConf[$project]['vcs.module'].'-new/' . $patchFiles[$i]->lang . $patchFiles[$i]->path . $patchFiles[$i]->name; - - $commands = array( - new ExecStatement('diff -uN %s %s', array($pathFileOrigin, $pathFileModified)) - ); - - $trial_threshold = 3; - while ($trial_threshold-- > 0) - { - $output = array(); - SaferExec::execMulti($commands, $output); - if (strlen(trim(implode('', $output))) != 0) break; - } - - $return .= $this->DiffGenHTMLOutput($output); - } - } - } + $patchFiles = RepositoryManager::getInstance()->getPatchFilesByID($patchId); + foreach ($patchFiles as $patchFile) { + $patchFile = new File($patchFile->lang, $patchFile->path.$patchFile->name); + // file delimeter + $output[] = 'Index: '.$patchFile->lang.$patchFile->path.$patchFile->name; + $output = array_merge($output, $patchFile->diff()); } - - return $return; - } - - public function DiffGenHTMLOutput($content) { - - $header = array_shift($content)."<br>".array_shift($content); - $return = '<table class="code"> - <tr> - <td class="header">'.$header.'</td> - </tr> - '; - - $classes = array( - '+' => 'ins', - '-' => 'del', - ' ' => '', - '@' => 'line' - ); - $first = true; - foreach ($content as $string) { - if ($string[0] == '@' && !$first) $return .= '<tr><td class="truncated">&nbsp;</td></tr>'; - $first = false; - $return .= '<tr><td class="'.$classes[$string[0]].'">'.str_replace(' ', '&nbsp;', htmlentities($string, ENT_QUOTES, 'UTF-8')).'</td></tr>'; - } - $return .= '<tr><td class="truncated">&nbsp;</td></tr>'; - $return .= '<table>'; - - return $return; + return $output; } /** diff --git a/php/utility.php b/php/utility.php index 6639bb9..fed1bac 100644 --- a/php/utility.php +++ b/php/utility.php @@ -1,71 +1,105 @@ -<?php - -require_once dirname(__FILE__) . '/AccountManager.php'; - -/** - * Print debug information into a file (.debug) into data folder. - * - * @param $mess The debug message. - */ -function debug($mess) -{ - $am = AccountManager::getInstance(); - $appConf = $am->appConf; - $project = $am->project; - - $mess = '['.@date('d/m/Y H:i:s').'] by ' - .$am->vcsLogin.' : '.str_replace("\r\n", " ", $mess)."\n"; - - $fp = fopen($appConf[$project]['vcs.path'].'../.debug', 'a+'); - fwrite($fp, $mess); - fclose($fp); -} - -function errlog($mess) -{ - $am = AccountManager::getInstance(); - $appConf = $am->appConf; - $project = $am->project; - - $mess = '['.@date('d/m/Y H:i:s').'] by ' - .$am->vcsLogin.' : '.str_replace("\r\n", " ", $mess)."\n"; - - $fp = fopen($appConf[$project]['vcs.path'].'../.errlog', 'a+'); - fwrite($fp, $mess); - fclose($fp); -} - -function elapsedTime($startDate, $endDate) { - - $return = array(); - - $units = Array( - 'year(s)' => 12 *4*7*24*60*60, - 'month(s)' => 4 *7*24*60*60, - 'week(s)' => 7 *24*60*60, - 'day(s)' => 24*60*60, - 'hour(s)' => 60*60, - 'minute(s)' => 60, - 'second(s)' => 1 - ); - - $startDate = strtotime($startDate); - $endDate = strtotime($endDate); - - $seconds = floor(($endDate - $startDate)); - - if( $seconds < 1 ) { - return ''; - } - - while( list($k, $v) = each($units) ) { - - if( ($seconds / $v) >= 1 || $k == 'seconds' ) { - $secondsConverted = floor($seconds / $v); - return Array('units' => $k, - 'value' => $secondsConverted); - } - - } -} -?> +<?php + +require_once dirname(__FILE__) . '/AccountManager.php'; + +/** + * Print debug information into a file (.debug) into data folder. + * + * @param $mess The debug message. + */ +function debug($mess) +{ + $am = AccountManager::getInstance(); + $appConf = $am->appConf; + $project = $am->project; + + $mess = '['.@date('d/m/Y H:i:s').'] by ' + .$am->vcsLogin.' : '.str_replace("\r\n", " ", $mess)."\n"; + + $fp = fopen($appConf[$project]['vcs.path'].'../.debug', 'a+'); + fwrite($fp, $mess); + fclose($fp); +} + +function errlog($mess) +{ + $am = AccountManager::getInstance(); + $appConf = $am->appConf; + $project = $am->project; + + $mess = '['.@date('d/m/Y H:i:s').'] by ' + .$am->vcsLogin.' : '.str_replace("\r\n", " ", $mess)."\n"; + + $fp = fopen($appConf[$project]['vcs.path'].'../.errlog', 'a+'); + fwrite($fp, $mess); + fclose($fp); +} + +function elapsedTime($startDate, $endDate) { + + $return = array(); + + $units = Array( + 'year(s)' => 12 *4*7*24*60*60, + 'month(s)' => 4 *7*24*60*60, + 'week(s)' => 7 *24*60*60, + 'day(s)' => 24*60*60, + 'hour(s)' => 60*60, + 'minute(s)' => 60, + 'second(s)' => 1 + ); + + $startDate = strtotime($startDate); + $endDate = strtotime($endDate); + + $seconds = floor(($endDate - $startDate)); + + if( $seconds < 1 ) { + return ''; + } + + while( list($k, $v) = each($units) ) { + + if( ($seconds / $v) >= 1 || $k == 'seconds' ) { + $secondsConverted = floor($seconds / $v); + return Array('units' => $k, + 'value' => $secondsConverted); + } + + } +} + +function DiffGenHTMLOutput($content) { + + $return = '<table class="code">'; + $classes = array( + '+' => 'ins', + '-' => 'del', + ' ' => '', + '' => '', + '@' => 'line' + ); + $header = true; + foreach ($content as $string) { + if ($string[0] == '@' && !$header) $return .= '<tr><td class="truncated">&nbsp;</td></tr>'; + if ($header && $string[0] == '@') { + $header = false; //headers ended + } elseif (!$header && !in_array($string[0], array('+','-',' ','@',''))) { // Index: path/to/file or diff -uN bla bla or other headers + $return .= '<tr><td class="truncated">&nbsp;</td></tr>'; + $header = true; //headers of new file started + } + + $return .= '<tr> + <td class="'.($header ? 'header' : $classes[$string[0]]).'"> + '.str_replace(' ', '&nbsp;', htmlentities($string, ENT_QUOTES, 'UTF-8')).' + </td> + </tr>'; + + + } + $return .= '<tr><td class="truncated">&nbsp;</td></tr>'; + $return .= '<table>'; + + return $return; +} +?> Thank you for your contribution.

« previous php.doc.cvs (#9611) next »