From 4725e3bd17986aa84356fc41a11db60f2447cead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nilg=C3=BCn=20Belma=20Bug=C3=BCner?= Date: Mon, 17 May 2021 00:45:45 +0300 Subject: [PATCH] 1. Doc-base revcheck.php code injected and database production accelerated: dropped from 15 minutes to 2.5 seconds. 2. As in new Doc-base revcheck.php, more detailed and more accurate information is given to the teams. 3. Indentation fixed. --- README.md | 24 +- include/lib_revcheck.inc.php | 166 ++++----- scripts/gen_picture_info.php | 2 +- scripts/rev.php | 700 +++++++++++++++++++---------------- www/revcheck.php | 606 +++++++++++++++--------------- 5 files changed, 772 insertions(+), 726 deletions(-) diff --git a/README.md b/README.md index b6cc21e..2de9e44 100644 --- a/README.md +++ b/README.md @@ -12,19 +12,19 @@ Requirements: 1. Unpack a copy of JpGraph 3.0.7 into `/include/jpgraph/` ([here](http://jpgraph.net/download/download.php?p=1)) 2. Increase memory limit for PHP scripts to at least 32MB 3. Fill in two configuration files - - `build-ops.php.sample` (rename it to `build-ops.php`) - - `@GITDIR@` - absolute path to dir where scripts will clone SVN repos to and then use them for generating data - - `@SQLITEDIR@` - absolute path to `/sqlite/` directory - - `build-ops.sample` (rename it to `build-ops` [no ext]) - - `@PHP@` - path to the PHP executable file - - `@GITDIR@` - absolute path to dir where scripts will clone SVN repos to and then use them and then use it for generating data - - `@DOCWEB@` - absolute path to `/www/` directory - - `@PHDDIR@` - absolute path to directory with PhD installed from Git master - - `@SCRIPTSDIR@`- absolute path to `/scripts/` directory - - `@SQLITEDIR@` - absolute path to `/sqlite/` directory - - `@SRCDIR@` - path to the directory with PHP source code in SVN repo +- `build-ops.php.sample` (rename it to `build-ops.php`) +- `@GITDIR@` - absolute path to dir where scripts will clone GIT repos to and then use them for generating data +- `@SQLITEDIR@` - absolute path to `/sqlite/` directory +- `build-ops.sample` (rename it to `build-ops` [no ext]) +- `@PHP@` - path to the PHP executable file +- `@GITDIR@` - absolute path to dir where scripts will clone SVN repos to and then use them and then use it for generating data +- `@DOCWEB@` - absolute path to `/www/` directory +- `@PHDDIR@` - absolute path to directory with PhD installed from Git master +- `@SCRIPTSDIR@`- absolute path to `/scripts/` directory +- `@SQLITEDIR@` - absolute path to `/sqlite/` directory +- `@SRCDIR@` - path to the directory with PHP source code in GIT repo 4. You need to run the scripts/populatedocs.sh to fetch all the required documentation for the site. -6. You need to run the scripts/generation.sh to generate the database and graphs (Time of generation: 921.84918999672 s) +6. You need to run the scripts/generation.sh to generate the database and graphs (Time of generation: 2.5009639263153 s) 7. Configure the virtual host under Apache. Current suggested settings are: ``` diff --git a/include/lib_revcheck.inc.php b/include/lib_revcheck.inc.php index fa7eb72..72d5237 100644 --- a/include/lib_revcheck.inc.php +++ b/include/lib_revcheck.inc.php @@ -26,23 +26,16 @@ function get_dirs($idx, $lang) { b.path AS dir, a.name AS name FROM - files a, - dirs b, - enfiles c + translated a, + dirs b WHERE - a.lang= '$lang' - AND - a.id = b.id - AND - c.id = a.id - AND - a.name = c.name - AND - a.revision != c.revision - AND - a.revision != 'n/a' + a.lang = '$lang' + AND a.id = b.id + AND (a.syncStatus = 'TranslatedOld' + OR a.syncStatus = 'TranslatedCritial' + OR a.syncStatus = 'TranslatedWip') ORDER BY - b.path"; + b.id"; $result = $idx->query($sql); @@ -58,10 +51,12 @@ function get_dirs($idx, $lang) { function get_outdated_files($idx, $lang, $filter = null, $value = null) { $sql = "SELECT a.status, a.name AS file, a.maintainer, c.revision AS en_rev, a.revision AS trans_rev, b.path AS dir - FROM files a, dirs b, enfiles c + FROM translated a, dirs b, enfiles c WHERE a.lang = '$lang' - AND a.revision != c.revision AND a.revision != 'n/a' - AND c.name = a.name AND c.id = a.id AND b.id = a.id"; + AND c.name = a.name AND c.id = a.id AND b.id = a.id + AND (a.syncStatus = 'TranslatedOld' + OR a.syncStatus = 'TranslatedCritial' + OR a.syncStatus = 'TranslatedWip')"; if ($filter == 'dir') { $sql .= " AND b.path = '$value'"; @@ -90,7 +85,7 @@ function get_outdated_files($idx, $lang, $filter = null, $value = null) // Return an array of available languages for manual function revcheck_available_languages($idx) { - $result = $idx->query('SELECT lang FROM description'); + $result = $idx->query('SELECT lang FROM descriptions'); while ($row = $result->fetchArray(SQLITE3_NUM)) { $tmp[] = $row[0]; } @@ -110,24 +105,23 @@ function count_en_files($idx) function get_missfiles($idx, $lang) { - $sql = 'SELECT + $sql = "SELECT d.path as dir, - b.size as size, + a.name as file, b.revision as revision, - a.name as file + a.size as size FROM - utfiles a, + Untranslated a, + enfiles b, dirs d - LEFT JOIN - enfiles b - ON - a.id = b.id + WHERE + a.lang = '$lang' AND a.name = b.name - WHERE - a.lang="' . $lang . '" AND - a.id = d.id'; + a.id = b.id + AND + a.id = d.id"; $result = $idx->query($sql); while ($r = $result->fetchArray()) { @@ -139,38 +133,26 @@ function get_missfiles($idx, $lang) function get_oldfiles($idx, $lang) { - $sql = 'SELECT - path, file, size - - FROM - old_files - - WHERE - lang="' . $lang . '"'; + $sql = "SELECT path, name, size + FROM notinen + WHERE lang = '$lang'"; $result = $idx->query($sql); - $tmp = array(); - $special_files = array( - 'translation.xml'=>1, - ); while ($r = $result->fetchArray()) { - if (isset($special_files[$r['file']])) continue; // skip some files - $tmp[] = array('dir' => $r['path'], 'size' => $r['size'], 'file' => $r['file']); + $tmp[] = array('dir' => $r['path'], 'size' => $r['size'], 'file' => $r['name']); } return $tmp; } function get_misstags($idx, $lang) { - $sql = 'SELECT - d.path AS dir, a.size AS en_size, b.size AS trans_size, a.name AS name - FROM enfiles a, dirs d - LEFT JOIN files b ON a.id = b.id AND a.name = b.name AND a.id = d.id - WHERE b.lang="'.$lang.'" AND (b.revision IS NULL OR b.revision = "n/a") - AND b.size IS NOT NULL - ORDER BY dir, name'; + $sql = "SELECT d.path AS dir, a.size AS en_size, b.size AS trans_size, a.name AS name + FROM enfiles a, translated b, dirs d + WHERE b.lang = '$lang' AND b.syncStatus = 'RevTagProblem' + AND a.id = b.id AND a.name = b.name AND a.id = d.id + ORDER BY dir, name"; $tmp = NULL; $result = $idx->query($sql); while($row = $result->fetchArray()) { @@ -190,29 +172,22 @@ function get_misstags($idx, $lang) */ function get_translators_stats($idx, $lang, $status) { if ($status == 'wip') { // special case, ehh; does anyone still use this status? - $sql = "SELECT COUNT(name) AS total, person AS maintainer - FROM wip + $sql = "SELECT files_wip AS total, nick AS maintainer + FROM translators + WHERE lang = '$lang' + GROUP BY maintainer"; + } elseif ($status == 'uptodate') { + $sql = "SELECT files_uptodate AS total, nick AS maintainer + FROM translators + WHERE lang = '$lang' + GROUP BY maintainer"; + } elseif ($status == 'outdated') { + $sql = "SELECT files_outdated AS total, nick AS maintainer + FROM translators WHERE lang = '$lang' GROUP BY maintainer"; } - else { - $sql = "SELECT COUNT(a.name) AS total, a.maintainer - FROM files a - LEFT JOIN enfiles b ON a.name = b.name AND a.id = b.id - WHERE a.lang = '$lang' AND a.size IS NOT NULL AND "; - - if ($status == 'uptodate') { - $sql .= 'a.revision = b.revision'; - } - elseif ($status == 'outdated') { - $sql .= 'b.revision != a.revision'; - } - - $sql .= ' GROUP BY a.maintainer'; - } - $result = $idx->query($sql); - $tmp = array(); while ($r = $result->fetchArray()) { $tmp[$r['maintainer']] = $r['total']; @@ -223,11 +198,11 @@ function get_translators_stats($idx, $lang, $status) { function get_translators($idx, $lang) { - $sql = "SELECT nick, name, mail, karma FROM translators WHERE lang = '$lang' ORDER BY nick COLLATE NOCASE"; + $sql = "SELECT nick, name, mail, vcs FROM translators WHERE lang = '$lang' ORDER BY nick COLLATE NOCASE"; $persons = array(); $result = $idx->query($sql); while ($r = $result->fetchArray()) { - $persons[$r['nick']] = array('name' => $r['name'], 'mail' => $r['mail'], 'karma' => $r['karma']); + $persons[$r['nick']] = array('name' => $r['name'], 'mail' => $r['mail'], 'karma' => $r['vcs']); } return $persons; } @@ -242,33 +217,32 @@ function get_translators($idx, $lang) * @return array */ function get_stats($idx, $lang, $status) { - if ($status == 'wip') { // special case, ehh; does anyone still use this status? - $sql = "SELECT COUNT(*) AS total, 0 AS size - FROM files a, dirs b, enfiles c - WHERE lang = '$lang' AND a.status ='wip' AND b.id = a.id AND b.id = c.id AND a.name = c.name"; - } - elseif ($status == 'notrans') { - $sql = "SELECT COUNT(a.name) AS total, SUM(c.size) AS size FROM utfiles a, dirs b, enfiles c WHERE a.lang = '$lang' AND b.id = a.id AND b.id = c.id AND a.name = c.name"; - } - else { - $sql = "SELECT COUNT(a.name) AS total, SUM(b.size) AS size - FROM enfiles a - LEFT JOIN files b ON a.name = b.name AND a.id = b.id - WHERE b.lang = '$lang' AND "; + if ($status == 'wip') { + $sql = "SELECT COUNT(name) AS total, SUM(size) AS size + FROM wip + WHERE lang = '$lang' "; + } elseif ($status == 'notrans') { + $sql = "SELECT COUNT(name) AS total, SUM(size) AS size + FROM Untranslated + WHERE lang = '$lang'"; + } elseif ($status == 'uptodate') { + $sql = "SELECT COUNT(name) AS total, SUM(size) AS size + FROM translated + WHERE lang = '$lang' AND syncStatus = 'TranslatedOk'"; + } elseif ($status == 'outdated') { + $sql = "SELECT COUNT(name) AS total, SUM(size) AS size + FROM translated + WHERE lang = '$lang' AND syncStatus = 'TranslatedOld'"; + } elseif ($status == 'norev') { + $sql = "SELECT COUNT(name) AS total, SUM(size) AS size + FROM translated + WHERE lang = '$lang' AND syncStatus = 'RevTagProblem'"; + } else { //notinen + $sql = "SELECT COUNT(name) AS total, SUM(size) AS size + FROM notinen WHERE lang = '$lang'"; - if ($status == 'uptodate') { - $sql .= 'a.revision = b.revision'; - } - elseif ($status == 'outdated') { - $sql .= 'b.revision != a.revision AND a.revision != "n/a" AND a.size IS NOT NULL'; - } - elseif ($status == 'norev') { - $sql .= '(a.revision IS NULL OR a.revision = "n/a") AND a.size IS NOT NULL'; - } } - $result = $idx->query($sql)->fetchArray(); - return array($result['total'], $result['size']); } diff --git a/scripts/gen_picture_info.php b/scripts/gen_picture_info.php index c655908..c43a9f6 100644 --- a/scripts/gen_picture_info.php +++ b/scripts/gen_picture_info.php @@ -59,7 +59,7 @@ function generate_image($lang, $idx) { $legend = array($percent[0] . '%% up to date ('.$up_to_date.')', $percent[1] . '%% outdated ('.$outdated.')', $percent[2] . '%% missing ('.$missing.')', $percent[3] . '%% without EN-Revision ('.$no_tag.')'); $title = 'Details for '.$LANGUAGES[$lang].' PHP Manual'; - $graph = new PieGraph(630,400); + $graph = new PieGraph(680,300); $graph->SetShadow(); $graph->title->Set($title); diff --git a/scripts/rev.php b/scripts/rev.php index 2b56088..fd5ea34 100644 --- a/scripts/rev.php +++ b/scripts/rev.php @@ -23,7 +23,6 @@ | Maciej Sobaczewski | +----------------------------------------------------------------------+ */ - error_reporting(E_ALL); set_time_limit(0); @@ -49,7 +48,7 @@ if (count($LANGS) == 0) { $CREATE = <<path . '/' . $this->name , '/' ); + } +} - $intro = "No intro available for the {$LANGUAGES[$lang]} translation of the manual."; - $charset = 'utf-8'; +class FileStatusEnum +{ + const Untranslated = 'Untranslated'; + const RevTagProblem = 'RevTagProblem'; + const TranslatedWip = 'TranslatedWip'; + const TranslatedOk = 'TranslatedOk'; + const TranslatedOld = 'TranslatedOld'; + const TranslatedCritial = 'TranslatedCritial'; + const NotInEnTree = 'NotInEnTree'; +} - if (file_exists($translation_xml)) { - // Else go on, and load in the file, replacing all - // space type chars with one space - $txml = join("", file($translation_xml)); - $txml = preg_replace("/\\s+/", " ", $txml); +class TranslatorInfo +{ + public $name; + public $email; + public $nick; + public $vcs; - // Get encoding for the output, from the translation.xml - // file encoding (should be the same as the used encoding - // in HTML) - if (preg_match("!<\?xml(.+)\?>!U", $txml, $match)) { - $xmlinfo = parse_attr_string($match); - if (isset($xmlinfo[1]["encoding"])) { - $charset = $xmlinfo[1]["encoding"]; - } - } + public $files_uptodate; + public $files_outdated; + public $files_wip; + public $files_sum; + public $files_other; - // Get intro text - if (preg_match("!(.+)!s", $txml, $match)) { - $intro = SQLite3::escapeString(@iconv($charset, 'UTF-8//IGNORE', trim($match[1]))); - } + public function __construct() { + $this->files_uptodate = 0; + $this->files_outdated = 0; + $this->files_wip = 0; + $this->files_sum = 0; + $this->files_other = 0; } - $SQL_BUFF .= "INSERT INTO description VALUES ('$lang', '$intro');\n"; - - if (isset($txml)) { - // Find all persons matching the pattern - if (preg_match_all("!!U", $txml, $matches)) { - $default = array('vcs' => 'n/a', 'nick' => 'n/a', 'editor' => 'n/a', 'email' => 'n/a', 'name' => 'n/a'); - $persons = parse_attr_string($matches[1]); - - foreach ($persons as $person) { - $person = array_merge($default, $person); - $nick = SQLite3::escapeString($person['nick']); - $name = SQLite3::escapeString(@iconv($charset, 'UTF-8//IGNORE', $person['name'])); - $email = SQLite3::escapeString($person['email']); - $vcs = SQLite3::escapeString($person['vcs']); - $editor = SQLite3::escapeString($person['editor']); - $SQL_BUFF .= "INSERT INTO translators VALUES ('$lang', '$nick', '$name', '$email', '$vcs', '$editor');\n"; - } - } - - // Get list of work in progress files - if (preg_match_all("!!U", $txml, $matches)) { - $files = parse_attr_string($matches[1]); - foreach ($files as $file) { - $name = SQLite3::escapeString($file['name']); - $person = SQLite3::escapeString($file['person']); - $type = SQLite3::escapeString(isset($file['type']) ? $file['type'] : 'translation'); - $SQL_BUFF .= "INSERT INTO wip VALUES ('$lang', '$name', '$person', '$type');\n"; - } + public static function getKey( $fileStatus ) { + switch ( $fileStatus ) { + case FileStatusEnum::RevTagProblem: + case FileStatusEnum::TranslatedOld: + case FileStatusEnum::TranslatedCritial: + case FileStatusEnum::NotInEnTree: + return "files_outdated"; + break; + case FileStatusEnum::TranslatedWip: + return "files_wip"; + break; + case FileStatusEnum::TranslatedOk: + return "files_uptodate"; + break; + default: + return "files_other"; } } -} // parse_translation() function end() - +} // Get a multidimensional array with tag attributes -function parse_attr_string($tags_attrs) -{ +function parse_attr_string ( $tags_attrs ) { $tag_attrs_processed = array(); - // Go through the tag attributes - foreach ($tags_attrs as $attrib_list) { - - // Get attr name and values + foreach($tags_attrs as $attrib_list) { preg_match_all("!(.+)=\\s*([\"'])\\s*(.+)\\2!U", $attrib_list, $attribs); - // Assign all attributes to one associative array $attrib_array = array(); foreach ($attribs[1] as $num => $attrname) { $attrib_array[trim($attrname)] = trim($attribs[3][$num]); } - // Collect in order of tags received + $tag_attrs_processed[] = $attrib_array; } - // Retrun with collected attributes + return $tag_attrs_processed; } -function dir_sort($a, $b) { - global $DOCS, $dir; - $a = $DOCS . 'en' . $dir . '/' . $a; - $b = $DOCS . 'en' . $dir . '/' . $b; - if (is_dir($a) && is_dir($b)) { - return 0; - } elseif (is_file($a) && is_file($b)) { - return 0; - } elseif (is_file($a) && is_dir($b)) { - return -1; - } elseif (is_dir($a) && is_file($b)) { - return 1; - } else { - return -1; +function computeTranslatorStatus( $lang, $enFiles, $trFiles ) +{ + global $SQL_BUFF, $DOCS, $LANGUAGES; + $translation_xml = $DOCS . $lang . "/translation.xml"; + $charset = 'utf-8'; + + if (!file_exists($translation_xml)) { + return []; + } + + $txml = join("", file($translation_xml)); + $txml = preg_replace("/\\s+/", " ", $txml); + + $intro = "No intro available for the {$LANGUAGES[$lang]} translation of the manual."; + if ( preg_match("!(.+)!s", $txml, $match) ) + $intro = SQLite3::escapeString(@iconv($charset, 'UTF-8//IGNORE', trim($match[1]))); + + $SQL_BUFF .= "INSERT INTO descriptions VALUES ('$lang', '$intro');\n"; + + $pattern = "!!U"; + preg_match_all($pattern, $txml, $matches); + $translators = parse_attr_string($matches[1]); + + $translatorInfos = []; + $unknownInfo = new TranslatorInfo(); + $unknownInfo->nick = "unknown"; + $translatorInfos["unknown"] = $unknownInfo; + + foreach ($translators as $key => $translator) + { + $info = new TranslatorInfo(); + $info->name = $translator["name"]; + $info->email = $translator["email"]; + $info->nick = $translator["nick"]; + $info->vcs = isset($translator["vcs"]) ? $translator["vcs"] : ''; + + $translatorInfos[$info->nick] = $info; + } + + foreach( $enFiles as $key => $enFile ) { + $info_exists = false; + if (array_key_exists($enFile->getKey(), $trFiles)) { + $trFile = $trFiles[$enFile->getKey()]; + $statusKey = TranslatorInfo::getKey($trFile->syncStatus); + if (array_key_exists($trFile->maintainer, $translatorInfos)) { + $translatorInfos[$trFile->maintainer]->$statusKey++; + $translatorInfos[$trFile->maintainer]->files_sum++; + $info_exists = true; + } + } + if (!$info_exists) { + $translatorInfos["unknown"]->$statusKey++; + $translatorInfos["unknown"]->files_sum++; + } + } + foreach ($translatorInfos as $key => $person) + { + if ($person->nick != "unknown" ) + { + $nick = SQLite3::escapeString($person->nick); + $name = SQLite3::escapeString(@iconv($charset, 'UTF-8//IGNORE', $person->name)); + $email = SQLite3::escapeString($person->email); + $vcs = SQLite3::escapeString($person->vcs); + + $SQL_BUFF .= "INSERT INTO translators VALUES ('$lang', + '$nick', '$name', '$email', '$vcs', $person->files_uptodate, + $person->files_outdated, $person->files_wip, + $person->files_sum, $person->files_other);\n"; + } } } -function dir_sort_old($a, $b) { - global $DOCS, $dir, $lang; - $a = $DOCS . $lang . $dir . '/' . $a; - $b = $DOCS . $lang . $dir . '/' . $b; - if (is_dir($a) && is_dir($b)) { - return 0; - } elseif (is_file($a) && is_file($b)) { - return 0; - } elseif (is_file($a) && is_dir($b)) { - return -1; - } elseif (is_dir($a) && is_file($b)) { - return 1; - } else { - return -1; +function populateFileTree( $lang ) +{ + global $DOCS; + $dir = new \DirectoryIterator( $DOCS . $lang ); + if ( $dir === false ) + { + print "$lang is not a directory.\n"; + exit; } + $cwd = getcwd(); + $ret = array(); + chdir( $DOCS . $lang ); + populateFileTreeRecurse( $lang , "." , $ret ); + chdir( $cwd ); + return $ret; } -function do_revcheck($dir = '') { - global $LANGS, $DOCS, $SQL_BUFF; - static $id = 1; - global $idx; - - if ($dh = opendir($DOCS . 'en/' . $dir)) { - - $entriesDir = array(); - $entriesFiles = array(); - - while (($file = readdir($dh)) !== false) { - if ( - (!is_dir($DOCS . 'en' . $dir.'/' .$file) && !in_array(substr($file, -3), array('xml','ent')) && substr($file, -13) != 'PHPEditBackup' ) - || strpos($file, 'entities.') === 0 - || $dir == '/chmonly' || $dir == '/internals' || $dir == '/internals2' - || $file == 'contributors.ent' || $file == 'contributors.xml' - || ($dir == '/appendices' && ($file == 'reserved.constants.xml' || $file == 'extensions.xml')) - || $file == '.editorconfig' - || $file == '.gitignore' - || $file == 'README' - || $file == 'README.md' - || $file == 'DO_NOT_TRANSLATE' - || $file == 'rsusi.txt' - || $file == 'missing-ids.xml' - || $file == 'license.xml' - || $file == 'versions.xml' - ) { - continue; - } - - if ($file != '.' && $file != '..' && $file != '.git' && $dir != '/functions' && $dir != '/.git' && $dir != '/.github' && $file != '.github') { - - if (is_dir($DOCS . 'en' . $dir.'/' .$file)) { - $entriesDir[] = $file; - } elseif (is_file($DOCS . 'en' . $dir.'/' .$file)) { - $entriesFiles[] = $file; - } - } - } - $cwd = getcwd(); - // Files first - $maintainer = NULL; - $status = NULL; - if (sizeof($entriesFiles) > 0 ) { - foreach($entriesFiles as $file) { - $path = $DOCS . 'en' . $dir . '/'; - chdir ($path); - $size = intval(filesize($file) / 1024); - $date = filemtime($file); - $revision = `git log -n1 --format=format:"%H" -- {$file};`; - $revision = ($revision == 0) ? 'NULL' : "'$revision'"; - $SQL_BUFF .= "INSERT INTO enfiles VALUES ($id, '$file', $revision, '$size', '$date');\n"; - - foreach ($LANGS as $lang) { - $path = $DOCS . $lang . $dir . '/' . $file; - if (is_file($path)) { - $size = intval(filesize($path) / 1024); - $date = filemtime($path); - - list($revision, $maintainer, $status) = get_tags($path); - echo " Adding file: {$id}, {$lang}, {$file},{$revision}, {$size}, {$date}, {$maintainer}, {$status}\n"; - - $SQL_BUFF .= "INSERT INTO files VALUES ($id, '$lang', '$file', '$revision', '$size', '$date', '$maintainer', '$status');\n"; - } else { - $SQL_BUFF .= "INSERT INTO utfiles VALUES ($id, '$lang', '$file');\n"; - } - } - } - } - chdir($cwd); - - // Directories.. - if (sizeof($entriesDir) > 0) { - usort($entriesDir, 'dir_sort'); - reset($entriesDir); - - foreach ($entriesDir as $Edir) { - if ($Edir != 'figures') { - $path = $DOCS . 'en/' . $dir . '/' . $Edir; - $id++; - echo "Adding directory: $dir/$Edir (id: $id)\n"; - - $SQL_BUFF .= "INSERT INTO dirs VALUES ($id, '$dir/$Edir');\n"; - do_revcheck($dir . '/' . $Edir); - } - } - } - } - closedir($dh); -} - -function check_old_files($lang, $dir = '') { +function populateFileTreeRecurse( $lang , $path , & $output ) +{ global $DOCS, $SQL_BUFF; - static $id = 1; - - if ($dh = opendir($DOCS . $lang . $dir)) { - - $entriesDir = array(); - $entriesFiles = array(); - - while (($file = readdir($dh)) !== false) { - if ( - (!is_dir($DOCS . $lang . $dir.'/' .$file) && !in_array(substr($file, -3), array('xml','ent')) && substr($file, -13) != 'PHPEditBackup' ) - || strpos($file, 'entities.') === 0 - || $dir == '/chmonly' || $dir == '/internals' || $dir == '/internals2' || $dir == '/.git' || $dir == '/.github' - || $file == 'contributors.ent' || $file == 'contributors.xml' - || ($dir == '/appendices' && ($file == 'reserved.constants.xml' || $file == 'extensions.xml')) - || $file == 'README' - || $file == 'README.md' - || $file == 'DO_NOT_TRANSLATE' - || $file == 'rsusi.txt' - || $file == 'missing-ids.xml' - || $file == 'translation.xml' - ) { - continue; - } - - if ($file != '.' && $file != '..' && $file != '.svn' && $dir != '/functions') { - - if (is_dir($DOCS . $lang . $dir.'/' .$file)) { - $entriesDir[] = $file; - } elseif (is_file($DOCS . $lang . $dir.'/' .$file)) { - $entriesFiles[] = $file; - } - } - } - - // Files first - if (sizeof($entriesFiles) > 0 ) { - - foreach($entriesFiles as $file) { - $path_en = $DOCS . 'en/' . $dir . '/' . $file; - $path = $DOCS . $lang . $dir . '/' . $file; - - if( !@is_file($path_en) ) { - $size = intval(filesize($path) / 1024); - $SQL_BUFF .= "INSERT INTO old_files VALUES ('$lang', '$dir', '$file', '$size');\n"; - } - } - } - - // Directories.. - if (sizeof($entriesDir) > 0) { - usort($entriesDir, 'dir_sort_old'); - reset($entriesDir); - - foreach ($entriesDir as $Edir) { - check_old_files($lang, $dir . '/' . $Edir); - } - } + $dir = new DirectoryIterator( $path ); + if ( $dir === false ) + { + print "$path is not a directory.\n"; + exit; } - closedir($dh); + $todoPaths = []; + $trimPath = ltrim( $path , "./"); + foreach( $dir as $entry ) + { + $filename = $entry->getFilename(); + if ( $filename[0] == '.' ) + continue; + if ( substr( $filename , 0 , 9 ) == "entities." ) + continue; + if ( $entry->isDir() ) + { + $todoPaths[] = $path . '/' . $entry->getFilename(); + continue; + } + if ( $entry->isFile() ) + { + $ignoredFileNames = [ + 'README.md', + 'translation.xml', + 'readme.first', + 'license.xml', + 'extensions.xml', + 'versions.xml', + 'book.developer.xml', + 'contributors.ent', + 'contributors.xml', + 'README', + 'DO_NOT_TRANSLATE', + 'rsusi.txt', + 'missing-ids.xml', + ]; + + $ignoredDirectories = [ + 'chmonly', + ]; + + if( + in_array($trimPath, $ignoredDirectories, true) + || in_array($filename, $ignoredFileNames, true) + || (strpos($filename, 'entities.') === 0) + || !in_array(substr($filename, -3), ['xml','ent'], true) + || (substr($filename, -13) === 'PHPEditBackup') + || ($trimPath === 'appendices' && (in_array($filename, ['reserved.constants.xml', 'extensions.xml'], true))) + ) continue; + + $file = new FileStatusInfo; + $file->path = $trimPath; + $file->name = $filename; + $file->size = filesize( $path . '/' . $filename ); + $file->syncStatus = null; + if ( $lang != 'en' ) + { + parseRevisionTag( $entry->getPathname() , $file ); + $path_en = $DOCS . 'en/' . $trimPath . '/' . $filename; + if( !is_file($path_en) ) //notinen + { + $filesize = $file->size < 1024 ? 1 : floor( $file->size / 1024 ); + $SQL_BUFF .= "INSERT INTO notinen VALUES ('$lang', '$trimPath', '$filename', $filesize);\n"; + } else { + $output[ $file->getKey() ] = $file; + } + } else { + $output[ $file->getKey() ] = $file; + } + } + } + sort( $todoPaths ); + foreach( $todoPaths as $path ) + populateFileTreeRecurse( $lang , $path , $output ); } -function get_tags($file) { - // Read the first 500 chars. The comment should be at - // the begining of the file - $fp = @fopen($file, "r") or die("Unable to read $file."); - $line = fread($fp, 1024); - fclose($fp); +function parseRevisionTag( $filename , FileStatusInfo $file ) +{ + $fp = fopen( $filename , "r" ); + $contents = fread( $fp , 1024 ); + fclose( $fp ); // No match before the preg $match = array (); - // Check for the translations "revision tag" - $regex = "//U"; - if (preg_match ( $regex , $line , $match )) { - // note the simple quotes - return array(trim($match[1]),trim($match[2]),trim($match[3])); + $regex = "''U"; + if (preg_match ($regex , $contents , $match )) { + $file->hash = trim( $match[1] ); + $file->maintainer = trim( $match[2] ); + $file->completion = trim( $match[3] ); } + if ( $file->hash == null or strlen( $file->hash ) != 40 or + $file->maintainer == null or + $file->completion == null ) + $file->syncStatus = FileStatusEnum::RevTagProblem; - // The tag with revision number is not found so search - // for n/a revision comment (comment where revision is not known) - if (preg_match("''U", - $line, $match)) { - // note the simple quotes - return array("'" . trim($match[1]) . "'", "'" . trim($match[2]) . "'", "'" . trim($match[3]) . "'"); - } - - // Nothing, return with NULL values - return array ("NULL", "NULL", "NULL"); - -} // get_tags() function end - -function get_original_rev($file) { - // Read the first 500 chars. The comment should be at - // the begining of the file - $fp = @fopen($file, "r") or die ("Unable to read $file."); - $line = fread($fp, 1024); - fclose($fp); - - // Return if this was needed (it should be there) - // . is for $ in the preg! - preg_match("//", $line, $match); - if (!empty($match)) { - return $match[1]; - } else { - return 0; + $regex = "//U"; + $match = array(); + preg_match ( $regex , $contents , $match ); + if ( count( $match ) == 2 ) + $file->credits = str_replace( ' ' , '' , trim( $match[1] ) ); + else + $file->credits = ''; +} + +function captureGitValues( & $output ) +{ + global $DOCS; + $cwd = getcwd(); + chdir( $DOCS . 'en' ); + $fp = popen( "git --no-pager log --name-only" , "r" ); + $hash = null; + $date = null; + $utct = new DateTimeZone( "UTC" ); + while ( ( $line = fgets( $fp ) ) !== false ) + { + if ( substr( $line , 0 , 7 ) == "commit " ) + { + $hash = trim( substr( $line , 7 ) ); + continue; + } + if ( strpos( $line , 'Date:' ) === 0 ) + { + $date = trim( substr( $line , 5 ) ); + continue; + } + if ( trim( $line ) == "" ) + continue; + if ( substr( $line , 0 , 4 ) == ' ' ) + continue; + if ( strpos( $line , ': ' ) > 0 ) + continue; + $filename = trim( $line ); + if ( isset( $output[$filename] ) ) + continue; + $output[$filename]['hash'] = $hash; } + pclose( $fp ); + chdir( $cwd ); } /** @@ -460,6 +465,61 @@ function get_original_rev($file) { $time_start = microtime(true); +$path = null; +$id = 0; +asort( $enFiles ); +foreach( $enFiles as $key => $en ) +{ + if ( $path !== $en->path ) + { + $id++; + $path = $en->path; + $path2 = $path == '' ? '/' : $path; + $SQL_BUFF .= "INSERT INTO dirs VALUES ($id, '$path2');\n"; + } + + $size = $en->size < 1024 ? 1 : floor( $en->size / 1024 ); + $filename = $path . ($path == '' ? '' : '/') . $en->name; + $en->hash = null; + if ( isset( $gitData[ $filename ] ) ) + { + $en->hash = $gitData[ $filename ]['hash']; + } + else + print "Warn: No hash for en/$filename\n"; + + $SQL_BUFF .= "INSERT INTO enfiles VALUES ($id, '$en->name', '$en->hash', $size);\n"; + + foreach( $LANGS as $lang ) + { + $trFile = isset( $trFiles[$lang][$filename] ) ? $trFiles[$lang][$filename] : null; + if ( $trFile == null ) // Untranslated + { + $SQL_BUFF .= "INSERT INTO Untranslated VALUES ($id, '$lang', + '$en->name', $size);\n"; + } else { + if ( $trFile->completion != null && $trFile->completion != "ready" ) + { + $trFile->syncStatus = FileStatusEnum::TranslatedWip; + $SQL_BUFF .= "INSERT INTO wip VALUES ($id, '$lang', '$en->name', $size, '$trFile->maintainer');\n"; + continue; + } + if ( $en->hash == $trFile->hash ){ + $trFile->syncStatus = FileStatusEnum::TranslatedOk; + } elseif ( strlen( $trFile->hash ) == 40 ) { + $trFile->syncStatus = FileStatusEnum::TranslatedOld; + } + $SQL_BUFF .= "INSERT INTO translated VALUES ($id, '$lang', + '$en->name', '$trFile->hash', $size, '$trFile->maintainer', + '$trFile->completion', '$trFile->syncStatus');\n"; + } + } +} + +foreach( $LANGS as $lang ) { + computeTranslatorStatus( $lang, $enFiles, $trFiles[$lang] ); +} + $db_name = SQLITE_DIR . 'rev.php.sqlite'; $tmp_db = SQLITE_DIR . 'rev.php.tmp.sqlite'; @@ -491,18 +551,10 @@ $db->exec($CREATE); // 3 - Fill in the description table while cleaning the langs // without revision.xml file -foreach ($LANGS as $id => $lang) { - echo "Fetching the $lang description\n"; - parse_translation($lang); -} - // 4 - Recurse in the manual seeking for files and fill $SQL_BUFF -do_revcheck(); -// 4:1 - Recurse in the manuel seeking for old files for each language and fill $SQL_BUFF -foreach ($LANGS as $lang) { - check_old_files($lang, ''); -} + + // 5 - Query $SQL_BUFF and exit $db->exec('BEGIN TRANSACTION'); diff --git a/www/revcheck.php b/www/revcheck.php index 5205c16..87dc8ee 100644 --- a/www/revcheck.php +++ b/www/revcheck.php @@ -4,18 +4,11 @@ error_reporting(E_ALL ^ E_NOTICE); include '../include/init.inc.php'; include '../include/lib_revcheck.inc.php'; -// Revision marks used to flag files -define("REV_UPTODATE", 1); // Up to date files -define("REV_OUTDATED", 2); // Outdated files -define("REV_NOREV", 3); // file with revision comment without revision -define("REV_NOTRANS", 4); // file without translation (utfiles) -define("REV_WIP", 5); // Work in progress - if (isset($_GET['lang']) && in_array($_GET['lang'], array_keys($LANGUAGES))) { - $lang = $_GET['lang']; + $lang = $_GET['lang']; } else { - $lang = 'en'; + $lang = 'en'; } if ($lang != 'en' ) $lang_name = $LANGUAGES[$lang]; @@ -23,19 +16,19 @@ if ($lang != 'en' ) $lang_name = $LANGUAGES[$lang]; $tool = ''; if (isset($_GET['p'])) { - $tool = $_GET['p']; + $tool = $_GET['p']; } // Prevent viewing other tools in EN if ($lang == 'en') { - $tool = 'default'; + $tool = 'default'; } $DBLANG = SQLITE_DIR . 'rev.php.sqlite'; // Check if db connection can be established and if revcheck for requested lang exists if ($dbhandle = new SQLite3($DBLANG)) { - $check_lang_tmp = $dbhandle->query("SELECT COUNT(lang) AS count FROM description WHERE lang = '$lang'"); + $check_lang_tmp = $dbhandle->query("SELECT COUNT(lang) AS count FROM descriptions WHERE lang = '$lang'"); $check_lang = $check_lang_tmp->fetchArray(); if ($lang != 'en' && $check_lang['count'] < 0) { site_header(); @@ -45,33 +38,33 @@ if ($dbhandle = new SQLite3($DBLANG)) { } } else { - site_header(); - echo "

Database connection couldn't be established

"; - site_footer(); - die; + site_header(); + echo "

Database connection couldn't be established

"; + site_footer(); + die; } site_header(); switch($tool) { - case 'translators': - $translators = get_translators($dbhandle, $lang); + case 'translators': + $translators = get_translators($dbhandle, $lang); - if (empty($translators)) { - echo '

Error: no translators info found in database.

'; - } - else { - $uptodate = get_translators_stats($dbhandle, $lang, 'uptodate'); - $outdated = get_translators_stats($dbhandle, $lang, 'outdated'); - $wip = get_translators_stats($dbhandle, $lang, 'wip'); + if (empty($translators)) { + echo '

Error: no translators info found in database.

'; + } + else { + $uptodate = get_translators_stats($dbhandle, $lang, 'uptodate'); + $outdated = get_translators_stats($dbhandle, $lang, 'outdated'); + $wip = get_translators_stats($dbhandle, $lang, 'wip'); - foreach($translators as $nick =>$data) { - $files_w[$nick] = array('uptodate' => '', 'outdated' => '', 'norev' => '', 'wip' => ''); - $files_w[$nick]['uptodate'] = isset($uptodate[$nick]) ? $uptodate[$nick] : ''; - $files_w[$nick]['wip'] = isset($wip[$nick]) ? $wip[$nick] : ''; - $files_w[$nick]['outdated'] = isset($outdated[$nick]) ? $outdated[$nick] : ''; - } + foreach($translators as $nick =>$data) { + $files_w[$nick] = array('uptodate' => '', 'outdated' => '', 'norev' => '', 'wip' => ''); + $files_w[$nick]['uptodate'] = isset($uptodate[$nick]) ? $uptodate[$nick] : ''; + $files_w[$nick]['wip'] = isset($wip[$nick]) ? $wip[$nick] : ''; + $files_w[$nick]['outdated'] = isset($outdated[$nick]) ? $outdated[$nick] : ''; + } - echo << Name @@ -87,225 +80,256 @@ switch($tool) { TRANSLATORS_HEAD; - foreach ($translators as $nick => $data) { - echo '', - ''.$data['name'].'', - ''.$nick.'', - ''.(($data['karma'] == 'yes') ? '✓' : ' ').'', - '' , @$files_w[$nick]['uptodate'], '', - '' , $files_w[$nick]['outdated'], '', - '', $files_w[$nick]['wip'], '', - '' , @array_sum($files_w[$nick]), '', - ''; - } - echo ''; - } - echo gen_date($DBLANG); - break; + foreach ($translators as $nick => $data) { + echo '', + ''.$data['name'].'', + ''.$nick.'', + ''.(($data['karma'] == 'yes') ? '✓' : ' ').'', + '' , @$files_w[$nick]['uptodate'], '', + '' , $files_w[$nick]['outdated'], '', + '', $files_w[$nick]['wip'], '', + '' , @array_sum($files_w[$nick]), '', + ''; + } + echo ''; + } + echo gen_date($DBLANG); + break; - case 'missfiles': - $missfiles = get_missfiles($dbhandle, $lang); - if (!$missfiles) { - echo '

All files translated? Would be nice... but it\'s probably an error :(

'; - } - else { - $num = count($missfiles); - echo ''; - echo ''; + case 'missfiles': + $missfiles = get_missfiles($dbhandle, $lang); + if (!$missfiles) { + echo '

All files translated? Would be nice... but it\'s probably an error :(

'; + } else { + $num = count($missfiles); + echo '
Available for translation ('.$num.' files):Commit HashkB
'; + echo ''; - $last_dir = false; - $total_size = 0; - foreach ($missfiles as $miss) { - if (!$last_dir || $last_dir != $miss['dir']) { - echo ''; - $last_dir = $miss['dir']; - } - echo ''; - $total_size += $miss['size']; - // flush every 200 kbytes - if (($total_size % 200) == 0) { - flush(); - } - } - echo ''; - echo '
Available for translation ('.$num.' files):Commit HashkB
'.$miss['dir'].'
'.$miss['file'].''.$miss['revision'].''.$miss['size'].'
Total Size ('.$num.' files): '.$total_size.' kB
'; - } - echo gen_date($DBLANG); - break; + $last_dir = false; + $total_size = 0; + foreach ($missfiles as $miss) { + if (!$last_dir || $last_dir != $miss['dir']) { + echo ''.$miss['dir'].''; + $last_dir = $miss['dir']; + } + $key = $miss['dir'] == '' ? "/" : $miss['dir']."/". $miss['file']; + echo "{$miss['file']}{$miss['revision']}{$miss['size']}"; + $total_size += $miss['size']; + // flush every 200 kbytes + if (($total_size % 200) == 0) + flush(); + } + echo "Total Size ($num files): $total_size kB"; + echo ''; + } + echo gen_date($DBLANG); + break; - case 'oldfiles': - $oldfiles = get_oldfiles($dbhandle, $lang); - if (!$oldfiles) { - echo '

Good, it seems that this translation doesn\'t contain any file which is not present in English tree.

'; - } - else { - $num = count($oldfiles); - echo ''; - echo ''; + case 'oldfiles': + $oldfiles = get_oldfiles($dbhandle, $lang); + if (!$oldfiles) { + echo '

Good, it seems that this translation doesn\'t contain any file which is not present in English tree.

'; + } else { + $num = count($oldfiles); + echo '
Not in EN tree ('.$num.' files):kB
'; + echo ''; - $last_dir = false; - $total_size = 0; - foreach ($oldfiles as $old) { - if (!$last_dir || $last_dir != $old['dir']) { - echo ''; - $last_dir = $old['dir']; - } - echo ''; - $total_size += $old['size']; - // flush every 200 kbytes - if (($total_size % 200) == 0) { - flush(); - } - } - echo ''; - echo '
Not in EN tree ('.$num.' files):kB
'.$old['dir'].'
', $old['file'], ''.$old['size'].'
Total Size ('.$num.' files): '.$total_size.' kB
'; - } - echo gen_date($DBLANG); - break; + $last_dir = false; + $total_size = 0; + foreach ($oldfiles as $old) { + if (!$last_dir || $last_dir != $old['dir']) { + echo ''.$old['dir'].''; + $last_dir = $old['dir']; + } + echo '', $old['file'], ''.$old['size'].''; + $total_size += $old['size']; + // flush every 200 kbytes + if (($total_size % 200) == 0) + flush(); + } + echo 'Total Size ('.$num.' files): '.$total_size.' kB'; + echo ''; + } + echo gen_date($DBLANG); + break; - case 'misstags': - $misstags = get_misstags($dbhandle, $lang); + case 'misstags': + $misstags = get_misstags($dbhandle, $lang); - if ($misstags == NULL) { - echo '

Good, all files contain revision numbers.

'; - } - else { - $num = count($misstags); - echo ''; - echo ''; - echo ''; + if ($misstags == NULL) { + echo '

Good, all files contain revision numbers.

'; + } else { + $num = count($misstags); + echo '
Files without EN-Revision number ('.$num.' files):Sizes in kB
en'.$lang.'diff
'; + echo ''; + echo ''; - $last_dir = false; + $last_dir = false; - foreach ($misstags as $row) { - if (!$last_dir || $last_dir != $row['dir']) { - echo ''; - $last_dir = $row['dir']; - } - echo ''; - } - echo '
Files without EN-Revision number ('.$num.' files):Sizes in kB
en'.$lang.'diff
'.$row['dir'].'
'.$row['name'].''.$row['en_size'].''.$row['trans_size'].''.(intval($row['en_size'] - $row['trans_size'])).'
'; - } - echo gen_date($DBLANG); - break; + foreach ($misstags as $row) { + if (!$last_dir || $last_dir != $row['dir']) { + echo ''.$row['dir'].''; + $last_dir = $row['dir']; + } + echo ''.$row['name'].''.$row['en_size'].''.$row['trans_size'].''.(intval($row['en_size'] - $row['trans_size'])).''; + } + echo ''; + } + echo gen_date($DBLANG); + break; - case 'filesummary': - $file_types = array( - array (REV_UPTODATE, 'Up to date files'), - array (REV_OUTDATED, 'Outdated files'), - array (REV_WIP, 'Work in progress'), - array (REV_NOREV, 'Files without revision number'), - array (REV_NOTRANS, 'Files available for translation') - ); + case 'filesummary': + $files_uptodate = get_stats($dbhandle, $lang, 'uptodate'); + $files_outdated = get_stats($dbhandle, $lang, 'outdated'); + $files_norev = get_stats($dbhandle, $lang, 'norev'); + $files_notrans = get_stats($dbhandle, $lang, 'notrans'); + $files_wip = get_stats($dbhandle, $lang, 'wip'); + $files_notinen = get_stats($dbhandle, $lang, 'notinen'); - $file_summary_array = array( - REV_UPTODATE => array(0,0), - REV_OUTDATED => array(0,0), - REV_NOREV => array(0,0), - REV_NOTRANS => array(0,0), - REV_WIP => array(0,0) - ); + echo ''; + echo ''; - $file_summary_array[REV_UPTODATE] = get_stats($dbhandle, $lang, 'uptodate'); - $file_summary_array[REV_OUTDATED] = get_stats($dbhandle, $lang, 'outdated'); - $file_summary_array[REV_NOREV] = get_stats($dbhandle, $lang, 'norev'); - $file_summary_array[REV_NOTRANS] = get_stats($dbhandle, $lang, 'notrans'); - $file_summary_array[REV_WIP] = get_stats($dbhandle, $lang, 'wip'); + $percent[0] = 0; + $percent[1] = 0; + #$percent[0] = count_en_files($dbhandle); - echo '
File status typeNumber of filesPercent of filesSize of files (kB)Percent of size
'; - echo ''; + $percent[0] += $files_uptodate[0]; + $percent[0] += $files_outdated[0]; + $percent[0] += $files_norev[0]; + $percent[0] += $files_notrans[0]; + $percent[0] += $files_wip[0]; + $percent[0] += $files_notinen[0]; - $percent = array(0, 0); - - foreach($file_summary_array as $t => $a) { - $percent[0] += $a[0]; - $percent[1] += $a[1]; - } - - foreach ($file_types as $num => $type) { - $tmp_num_percent_0 = ($percent[0] == 0) ? 0 : number_format($file_summary_array[$type[0]][0] * 100 / $percent[0], 2 ); - $tmp_num_percent_1 = ($percent[0] == 0) ? 0 : number_format($file_summary_array[$type[0]][1] * 100 / $percent[1], 2); - - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } - - echo ''; - echo '
File status typeNumber of filesPercent of filesSize of files (kB)Percent of size
'.$type[1].''.$file_summary_array[$type[0]][0].''.$tmp_num_percent_0.'%'.$file_summary_array[$type[0]][1].''.$tmp_num_percent_1.'%
Files total'.$percent[0].'100%'.$percent[1].'100%
'; - echo gen_date($DBLANG); - break; + $percent[1] += $files_uptodate[1]; + $percent[1] += $files_outdated[1]; + $percent[1] += $files_norev[1]; + $percent[1] += $files_notrans[1]; + $percent[1] += $files_wip[1]; + $percent[1] += $files_notinen[1]; - case 'files' : - // we need a dir to browse - $dirs = get_dirs($dbhandle, $lang); - $users = get_translators($dbhandle, $lang); + $num_uptodate_percent = number_format($files_uptodate[0] * 100 / $percent[0], 2 ); + $num_outdated_percent = number_format($files_outdated[0] * 100 / $percent[0], 2 ); + $num_wip_percent = number_format($files_wip[0] * 100 / $percent[0], 2 ); + $num_norev_percent = number_format($files_norev[0] * 100 / $percent[0], 2 ); + $num_notinen_percent = number_format($files_notinen[0] * 100 / $percent[0], 2 ); + $num_notrans_percent = number_format($files_notrans[0] * 100 / $percent[0], 2 ); - if (empty($dirs)) { - echo '

Error: no directories found in database.

'; - $sidebar = nav_tools($lang); - site_footer($sidebar); - die; - } + $size_uptodate_percent = number_format($files_uptodate[1] * 100 / $percent[1], 2 ); + $size_outdated_percent = number_format($files_outdated[1] * 100 / $percent[1], 2 ); + $size_wip_percent = number_format($files_wip[1] * 100 / $percent[1], 2 ); + $size_norev_percent = number_format($files_norev[1] * 100 / $percent[1], 2 ); + $size_notinen_percent = number_format($files_notinen[1] * 100 / $percent[1], 2 ); + $size_notrans_percent = number_format($files_notrans[1] * 100 / $percent[1], 2 ); + print << +Up to date files +{$files_uptodate[0]} +{$num_uptodate_percent}% +{$files_uptodate[1]} +{$size_uptodate_percent}% + +Outdated files +{$files_outdated[0]} +{$num_outdated_percent}% +{$files_outdated[1]} +{$size_outdated_percent}% + +Work in progress +{$files_wip[0]} +{$num_wip_percent}% +{$files_wip[1]} +{$size_wip_percent}% + +Files without revision number +{$files_norev[0]} +{$num_norev_percent}% +{$files_norev[1]} +{$size_norev_percent}% + +Not in EN tree +{$files_notinen[0]} +{$num_notinen_percent}% +{$files_notinen[1]} +{$size_notinen_percent}% + +Files available for translation +{$files_notrans[0]} +{$num_notrans_percent}% +{$files_notrans[1]} +{$size_notrans_percent}% + +Files total +{$percent[0]} +100% +{$percent[1]}100% + +HTML; + echo gen_date($DBLANG); + break; - echo '

This tool allows you to check which files in your translation need updates. To show the list '; - echo 'choose a directory (it doesn\'t work recursively) or translator.

'; - echo '

When you click on the filename you will see the plaintext diff showing changes between revisions, so '; - echo 'you will know what has changed in the English version and which information you need to update.'; - echo 'You can also click on [diff] to show the colored diff.

'; - echo '

Choose a directory:

'; - echo '

'; - echo ''; - echo ''; - echo '

'; - echo '

Or choose a translator:

'; - echo '

'; - echo ''; - echo ''; - echo '

'; + case 'files' : + // we need a dir to browse + $dirs = get_dirs($dbhandle, $lang); + $users = get_translators($dbhandle, $lang); + /* + if (empty($dirs)) { + echo '

Error: no directories found in database.

'; + $sidebar = nav_tools($lang); + site_footer($sidebar); + die; + } + */ + echo '

This tool allows you to check which files in your translation need updates. To show the list '; + echo 'choose a directory (it doesn\'t work recursively) or translator.

'; + echo '

When you click on the filename you will see the plaintext diff showing changes between revisions, so '; + echo 'you will know what has changed in the English version and which information you need to update.'; + echo 'You can also click on [diff] to show the colored diff.

'; + echo '

Choose a directory:

'; + echo '

'; + echo ''; + echo ''; + echo '

'; - // Get outdated files filtered as requested - if (isset($_GET['user'])) { - $outdated = get_outdated_files($dbhandle, $lang, 'translator', $_GET['user']); - } - elseif (isset($_GET['dir'])) { - $outdated = get_outdated_files($dbhandle, $lang, 'dir', $_GET['dir']); - } - else { - $outdated = get_outdated_files($dbhandle, $lang, 'all'); - } + echo '

Or choose a translator:

'; + echo '

'; + echo ''; + echo ''; + echo '

'; - if (empty($outdated)) { - echo '

Good, it seems that all files are up to date for these conditions.

'; - } - else { - echo <<Good, it seems that all files are up to date for these conditions.

'; + } else { + echo << Translated file @@ -319,80 +343,76 @@ TRANSLATORS_HEAD; {$outdated[0]['name']} END_OF_MULTILINE; - $last_dir = false; - $prev_name = $outdated[0]['name']; + $last_dir = false; + $prev_name = $outdated[0]['name']; - foreach ($outdated as $r) { - if ($r['name'] != $prev_name) { - echo ''.$r['name'].''; - $prev_name = $r['name']; - } + foreach ($outdated as $r) { + if ($r['name'] != $prev_name) { + echo ''.$r['name'].''; + $prev_name = $r['name']; + } - // Make the maintainer a link, if we have that maintainer in the list - if ($r['maintainer'] && $r["maintainer"] != 'nobody') { - $r["maintainer"] = '' . $r["maintainer"] . ''; - } + // Make the maintainer a link, if we have that maintainer in the list + if ($r['maintainer'] && $r["maintainer"] != 'nobody') { + $r["maintainer"] = '' . $r["maintainer"] . ''; + } - // Make a link to the GIT repository's diff script - $key = substr($r['name'] . '/' . $r['file'], 1); - if ($r['name'] == '/') { - $key = $r['file']; - } - //text - $d1 = "/gitweb/?p=doc/en.git;a=blobdiff_plain;f=$key;hb={$r['en_rev']};hpb={$r['trans_rev']};"; + // Make a link to the GIT repository's diff script + $key = $r['name'] . '/' . $r['file']; + if ($r['name'] == '/') + $key = $r['file']; - //html - $d2 = "/gitweb/?p=doc/en.git;a=blobdiff;f=$key;hb={$r['en_rev']};hpb={$r['trans_rev']};"; + //text + $d1 = "/gitweb/?p=doc/en.git;a=blobdiff_plain;f=$key;hb={$r['en_rev']};hpb={$r['trans_rev']};"; + //html + $d2 = "/gitweb/?p=doc/en.git;a=blobdiff;f=$key;hb={$r['en_rev']};hpb={$r['trans_rev']};"; - $nm = "{$r['file']} (html)"; + $h1 = "{$r['en_rev']}"; + $h2 = "{$r['trans_rev']}"; - $h1 = "{$r['en_rev']}"; + $nm = "{$r['file']} (html)"; - $h2 = "{$r['trans_rev']}"; - - // Write out the line for the current file (get file name shorter) - echo ''. - "{$nm}". - "{$h1}" . - "{$h2}" . - " {$r['maintainer']}" . - " {$r['status']}\n"; - } - echo ''; - } - echo gen_date($DBLANG); - break; + // Write out the line for the current file (get file name shorter) + echo ''. + "{$nm}". + "{$h1}" . + "{$h2}" . + " {$r['maintainer']}" . + " {$r['status']}\n"; + } + echo ''; + } + echo gen_date($DBLANG); + break; case 'graph': - $path = "images/revcheck/info_revcheck_php_$lang.png"; - if (is_readable($path)) { - echo 'info'; - echo gen_date($DBLANG); - } - else { - echo "

Can't find graph.

"; - } - break; + $path = "images/revcheck/info_revcheck_php_$lang.png"; + if (is_readable($path)) { + echo 'info'; + echo gen_date($DBLANG); + } else { + echo "

Can't find graph.

"; + } + break; - default: - if ($lang == 'en') { - echo 'Info'; - echo '

This is all what we can show for original manual. To get more tools, please select translation language.

'; - echo gen_date($DBLANG); - $sidebar = nav_languages(); - site_footer($sidebar); - } - else { - $intro_result = $dbhandle->query("SELECT intro FROM description WHERE lang = '$lang'"); - $intro = $intro_result->fetchArray(); - echo '

Intro for language

'; - echo '

'.$intro[0].'

'; - echo '

Links to available tools are placed on the right sidebar.

'; - } + default: + if ($lang == 'en') { + echo 'Info'; + echo '

This is all what we can show for original manual. To get more tools, please select translation language.

'; + echo gen_date($DBLANG); + $sidebar = nav_languages(); + site_footer($sidebar); + } else { + $intro_result = $dbhandle->query("SELECT intro FROM descriptions WHERE lang = '$lang'"); + $intro = $intro_result->fetchArray(); + echo '

Intro for language

'; + echo '

'.$intro[0].'

'; + echo '

Links to available tools are placed on the right sidebar.

'; + } break; } if ($lang != 'en') { - $sidebar = nav_tools($lang); - site_footer($sidebar); + $sidebar = nav_tools($lang); + site_footer($sidebar); }