Skip to content

Commit 000d85a

Browse files
committed
Adapt to hashes in external file
1 parent 0d50c90 commit 000d85a

File tree

1 file changed

+39
-11
lines changed

1 file changed

+39
-11
lines changed

scripts/revcheck.php

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ functionality in the PHP Documentation Howto:
6868
define("REV_CREDIT", 7); // only used in translators list
6969
define("REV_WIP", 8); // only used in translators list
7070

71+
define('TEMPLATE_HISTORY_URL_BASE_FILE', 'https://github.com/phpdoctest/%2$s/commits/master/%1$s');
72+
define('TEMPLATE_URL_BASE_FILE', 'https://github.com/phpdoctest/%2$s/blob/master/%1$s');
73+
7174
// Colors used to mark files by status (colors for the above types)
7275
$CSS = array(
7376
REV_UPTODATE => "act",
@@ -94,6 +97,16 @@ function init_files_by_maint($persons) {
9497
return $result;
9598
}
9699

100+
function get_file_path_identifier($file)
101+
{
102+
global $LANG;
103+
$slashPos = 0;
104+
if (strpos($file, '.') === 0) {
105+
$slashPos = strpos($file, '/');
106+
}
107+
return ltrim(substr($file, strlen($LANG) + $slashPos + 1), '/');
108+
}
109+
97110
$file_sizes_by_mark = $files_by_mark = init_revisions();
98111

99112
// Initializing variables from parameters
@@ -122,7 +135,14 @@ function init_files_by_maint($persons) {
122135
} else {
123136
$DOCDIR = "../";
124137
}
125-
$DOCDIR = "./";
138+
//$DOCDIR = "./";
139+
140+
$englishRevisions = [];
141+
142+
foreach (file($DOCDIR . '/' . $LANG . '/.en-revisions.ref') as $line) {
143+
$colonPos = strpos($line, ':');
144+
$englishRevisions[substr($line, 0, $colonPos)] = trim(substr($line, $colonPos + 1));
145+
}
126146
// =========================================================================
127147
// Functions to get revision info and credits from a file
128148
// =========================================================================
@@ -142,8 +162,9 @@ function get_original_info($file, $hash)
142162
// Grabs the revision tag and stores credits from the file given
143163
function get_tags($file, $val = "en-rev") {
144164

145-
global $LANG, $DOCDIR;
146-
$basefile = substr($file, strlen($LANG) + 3);
165+
global $LANG, $DOCDIR, $englishRevisions;
166+
167+
$basefile = get_file_path_identifier($file);
147168

148169
// Read the first 500 chars. The comment should be at
149170
// the begining of the file
@@ -214,6 +235,9 @@ function get_tags($file, $val = "en-rev") {
214235

215236
$match[4] = new DateTimeImmutable();
216237
$match[5] = 0;
238+
239+
$match[1] = $englishRevisions[$basefile];
240+
217241
if (isset($match[1]) && $match[1] && $match[1] !== 'n/a') {
218242
// We have a revision number of the english original and should now see to
219243
// Get the last change date of that revision…
@@ -316,7 +340,8 @@ function get_file_status($file) {
316340
// Compute times and diffs
317341
$en_date = (new DateTimeImmutable())->diff($en_last_date)->days;
318342
$trans_date = intval((time() - filemtime($trans_file)) / 86400);
319-
// $trans_date = (new DateTimeImmutable())->diff($this_rev)->days;
343+
$trans_date = (new DateTimeImmutable())->diff(get_tags($trans_file))->days;
344+
//$trans_date = (new DateTimeImmutable())->diff($this_rev)->days;
320345
$date_diff = $en_date - $trans_date;
321346
$date_diff = 0;
322347
if ($trans_rev instanceof DateTimeInterface) {
@@ -924,21 +949,24 @@ function parse_translation($DOCDIR, $LANG, $MAINT) {
924949
// make a link to the SVN repository's diff script
925950
if ($file["revision"][2] != "n/a" && $file["revision"][2] !== 0) {
926951
$history_url = sprintf(
927-
'https://github.com/phpdoctest/en/commits/master/%1$s',
928-
$file['full_name']
952+
TEMPLATE_HISTORY_URL_BASE_FILE,
953+
get_file_path_identifier($file['full_name']),
954+
$LANG
929955
);
930956

931957
$url = sprintf(
932-
'https://github.com/phpdoctest/en/blob/master/%1$s',
933-
$file['full_name']
958+
TEMPLATE_URL_BASE_FILE,
959+
get_file_path_identifier($file['full_name']),
960+
$LANG
934961
);
935962

936963
$file['short_name'] = '<a href="' . $url . '">'. $file["short_name"] . '</a> '.
937964
'<a href="' . $history_url . '">[History]</a>';
938965
}
939966

940967
// Guess the new directory from the full name of the file
941-
$new_dir = dirname($file["full_name"]);
968+
$new_dir = dirname($file["fu
969+
ll_name"]);
942970

943971
// If this is a new directory, put out old dir lines
944972
if ($new_dir !== $prev_dir) {
@@ -1035,7 +1063,7 @@ function parse_translation($DOCDIR, $LANG, $MAINT) {
10351063
// If we need the revision column, print it out
10361064
if ($using_rev) {
10371065
echo "<td>$finfo[revision]</td><td>" .
1038-
$missing_files[$finfo["name"]][1] .
1066+
$missing_tags[$finfo["name"]][1] .
10391067
"</td>";
10401068
}
10411069

@@ -1123,7 +1151,7 @@ function parse_translation($DOCDIR, $LANG, $MAINT) {
11231151
$prev_dir = $new_dir;
11241152
}
11251153

1126-
echo "<tr class=wip><td><a href=\"https://github.com/phpdoctest/en/blob/master/$file?view=markup\">$short_file</a></td>" .
1154+
echo "<tr class=wip><td><a href=\"" . sprintf(TEMPLATE_URL_BASE_FILE,$file, $LANG) . "?view=markup\">$short_file</a></td>" .
11271155
"<td class=r>$info[0]</td></tr>\n";
11281156
}
11291157
echo "</table>\n<p>&nbsp;</p>\n$navbar<p>&nbsp;</p>\n";

0 commit comments

Comments
 (0)