Hello! I'm reaching the final stage of the process of implementing the
option for the Git webpage repository.
This patch basically covers the PHP changes.
The default configuration for new projects will be Git, and I've
implemented a radio button for transitioning from CVS to Git. For the
old projects, it will be a choice-based approach.
From 52c63fd768c04135f5fb9f2684f65699a0a57ef3 Mon Sep 17 00:00:00 2001
From: Ayushman Tripathi <ayush...@gnu.org>
Date: Fri, 12 Jan 2024 01:46:51 +0530
Subject: [PATCH] add git homepage source code web browsing
---
frontend/php/include/form.php | 2 +-
frontend/php/include/group.php | 19 ++++++++++---
frontend/php/include/pagemenu.php | 6 ++--
frontend/php/include/vcs.php | 7 +++--
.../php/project/admin/editgroupfeatures.php | 28 +++++++++++++++++--
frontend/php/siteadmin/group_type.php | 10 +++++++
frontend/php/testing/sane.php | 1 +
7 files changed, 62 insertions(+), 11 deletions(-)
diff --git a/frontend/php/include/form.php b/frontend/php/include/form.php
index f46c3564..b65908c6 100644
--- a/frontend/php/include/form.php
+++ b/frontend/php/include/form.php
@@ -115,7 +115,7 @@ function form_set_label_attr (&$attr)
return $ret;
}
-function form_radio ($name, $value, $attr)
+function form_radio ($name, $value, $attr = [])
{
$label = form_set_label_attr ($attr);
$extra = '';
diff --git a/frontend/php/include/group.php b/frontend/php/include/group.php
index 4afea29b..9e9707cd 100644
--- a/frontend/php/include/group.php
+++ b/frontend/php/include/group.php
@@ -87,7 +87,7 @@ class Group extends savane_error
parent::__construct ();
$this->group_id = $id;
$this->db_result =
- db_execute ("SELECT * FROM groups WHERE group_id = ?", [$id]);
+ db_execute ("SELECT * FROM `groups` WHERE group_id = ?", [$id]);
$this->type_data_array = $this->data_array = [];
if (db_numrows ($this->db_result) < 1)
{
@@ -379,6 +379,17 @@ class Group extends savane_error
return $keyring;
}
+ function isArtifactUrlSet ($artifact)
+ {
+ # Returns true if the artifact url is set for this group.
+ return $this->data_array["url_$artifact"] != "";
+ }
+
+ function getHomepageVcs ()
+ {
+ return $this->data_array['homepage_vcs'];
+ }
+
function getUrl ($artifact)
{
# Similar to getArtifactUrl but refers to GroupType in case nothing
@@ -452,7 +463,7 @@ class Group extends savane_error
function UsesForHomepage ($artifact)
{
- # Useful to determine whether the project is a specific artifact
+ # Useful to determine whether the project has a specific artifact
# to manage its homepage:
# - must use homepage
# - must be set as homepage SCM for the group type
@@ -560,7 +571,7 @@ function group_getid ($group_name)
{
$res =
db_execute (
- "SELECT group_id FROM groups WHERE unix_group_name = ?", [$group_name]
+ "SELECT group_id FROM `groups` WHERE unix_group_name = ?", [$group_name]
);
if (db_numrows ($res) > 0)
return db_result ($res, 0, 'group_id');
@@ -743,7 +754,7 @@ function group_get_artifact_url ($artifact, $hostname = 1)
global $project, $sys_home;
$type_urls = [
"homepage", "download", "cvs_viewcvs", "cvs_viewcvs_homepage",
- "arch_viewcvs", "svn_viewcvs", "git_viewcvs", "hg_viewcvs", "bzr_viewcvs"
+ "arch_viewcvs", "svn_viewcvs", "git_viewcvs", "git_viewcvs_homepage",
"hg_viewcvs", "bzr_viewcvs"
];
if (in_array ($artifact, $type_urls))
return $project->getTypeUrl ($artifact);
diff --git a/frontend/php/include/pagemenu.php
b/frontend/php/include/pagemenu.php
index 9af82f33..274a0e65 100644
--- a/frontend/php/include/pagemenu.php
+++ b/frontend/php/include/pagemenu.php
@@ -344,14 +344,16 @@ function pagemenu_vcs_browse_entry ($group, $vcs, $name)
function pagemenu_vcs_web_browse_url ($group, $vcs)
{
- if (!pagemenu_url_is_set ($group, "cvs_viewcvs_homepage"))
+ if (!pagemenu_url_is_set ($group, "cvs_viewcvs_homepage") &&
!pagemenu_url_is_set ($group, "git_viewcvs_homepage"))
return '';
- if ($vcs == 'cvs')
+ if ($vcs == 'cvs'|| $vcs == 'git')
$have_entry = $group->Uses ('homepage');
else
$have_entry = $group->UsesForHomepage ($vcs);
if (!$have_entry)
return '';
+ if (pagemenu_url_is_set($group, "git_viewcvs_homepage"))
+ return $group->getUrl ("git_viewcvs_homepage");
return $group->getUrl ("cvs_viewcvs_homepage");
}
diff --git a/frontend/php/include/vcs.php b/frontend/php/include/vcs.php
index e8947ba9..f5577c72 100644
--- a/frontend/php/include/vcs.php
+++ b/frontend/php/include/vcs.php
@@ -210,16 +210,19 @@ function vcs_print_links_to_repos ($group, $group_id,
$vcs_exfix, $vcs_name)
$have_links = $group->Uses ($vcs_exfix)
&& pagemenu_url_is_set ($group, "{$vcs_exfix}_viewcvs");
$have_web_links = $group->UsesForHomepage ($vcs_exfix)
- && pagemenu_url_is_set ($group, "cvs_viewcvs_homepage");
+ && (pagemenu_url_is_set ($group, "cvs_viewcvs_homepage") ||
pagemenu_url_is_set($group, "git_viewcvs_homepage"));
if (!($have_links || $have_web_links))
return;
vcs_print_browsing_preface ($vcs_name);
print "<ul>\n";
if ($have_links)
vcs_print_source_repo_links ($group, $vcs_exfix, $repo_list);
- if ($have_web_links)
+ if ($have_web_links && pagemenu_url_is_set($group, "cvs_viewcvs_homepage"))
print '<li><a href="' . $group->getUrl ("cvs_viewcvs_homepage") . '">'
. _("Browse Web Pages Repository") . "</a></li>\n";
+ if ($have_web_links && pagemenu_url_is_set($group, "git_viewcvs_homepage"))
+ print '<li><a href="' . $group->getUrl ("git_viewcvs_homepage") . '">'
+ . _("Browse Web Pages Repository") . "</a></li>\n";
print "</ul>\n";
}
diff --git a/frontend/php/project/admin/editgroupfeatures.php
b/frontend/php/project/admin/editgroupfeatures.php
index 0744da1b..a2626ae4 100644
--- a/frontend/php/project/admin/editgroupfeatures.php
+++ b/frontend/php/project/admin/editgroupfeatures.php
@@ -66,6 +66,8 @@ $post_names = function ()
foreach ($urls as $u)
$names['specialchars'][] = 'url_' . $u;
$names['specialchars'][] = 'url_cvs_viewcvs_homepage';
+ $names['specialchars'][] = 'url_git_viewcvs_homepage';
+ $names['specialchars'][] = 'homepage_vcs';
return $names;
};
@@ -126,6 +128,9 @@ if ($update)
|| ($field_name == "extralink_documentation")
|| ($field == "url_cvs_viewcvs_homepage"
&& $project->CanUse("homepage"))
+ || ($field == "url_git_viewcvs_homepage"
+ && $project->CanUse("homepage"))
+ || ($field == "homepage_vcs" && $project->CanUse("homepage"))
|| ($field == "url_cvs_viewcvs" && $project->CanUse("cvs"))
|| ($field == "url_arch_viewcvs" && $project->CanUse("arch"))
|| ($field == "url_svn_viewcvs" && $project->CanUse("svn"))
@@ -146,6 +151,10 @@ if ($update)
{
$upd_list[$field] = $$field;
}
+ elseif ($field == "homepage_vcs")
+ {
+ $upd_list[$field] = $$field;
+ }
}
}
@@ -192,6 +201,11 @@ function specific_line ($artifact, $explanation, $use,
$increment=1)
# (viewcvs cannot be activated or deactivated, they are not in the menu).
if (str_match ("viewcvs", $artifact))
print "---";
+
+ else if ($artifact == "homepage_vcs") {
+ print form_radio("homepage_vcs", "cvs", ["checked" =>
($project->getHomepageVcs()=="cvs") , "label" => "Cvs"]);
+ print form_radio("homepage_vcs", "git", ["checked" =>
($project->getHomepageVcs() == "git"), "label" => "Git"]);
+ }
else
print form_checkbox ("use_$artifact", $use);
$close_td ();
@@ -242,13 +256,23 @@ print html_build_list_table_top (
]
);
-if ($project->CanUse("homepage"))
+if ($project->CanUse("homepage")&& ($project->getHomepageVcs() == "cvs"))
{
specific_line("homepage", _("Homepage"), $project->Uses("homepage"));
+ specific_line("homepage_vcs", _("Select Homepage Source Code VCS"), 0, 0);
specific_line("cvs_viewcvs_homepage",
- _("Homepage Source Code Web Browsing"), 0, 0);
+ _("Homepage Source Code Web Browsing"), 0, 0);
}
+
+if ($project->CanUse("homepage") && ($project->getHomepageVcs() == "git")) {
+ specific_line("homepage", _("Homepage"), $project->Uses("homepage"));
+ specific_line("homepage_vcs", _("Select Homepage Source Code VCS"), 0, 0);
+ specific_line(
+ "git_viewcvs_homepage",
+ _("Homepage Source Code Web Browsing-Git"),0,0);
+}
+
if ($project->CanModifyUrl("extralink_documentation"))
specific_line("extralink_documentation", _("Documentation"),
$project->Uses("extralink_documentation"));
diff --git a/frontend/php/siteadmin/group_type.php
b/frontend/php/siteadmin/group_type.php
index d0c10a8d..6e4fb392 100644
--- a/frontend/php/siteadmin/group_type.php
+++ b/frontend/php/siteadmin/group_type.php
@@ -141,6 +141,7 @@ $name_matching = function ($trackers, $vcs_list)
foreach ($vcs_list as $vcs)
$names['specialchars'][] = "url_{$vcs}_viewcvs";
$names['specialchars'][] = "url_cvs_viewcvs_homepage";
+ $names['specialchars'][] = 'url_git_viewcvs_homepage';
foreach (
[
'listinfo', 'subscribe', 'unsubscribe', 'archives', 'archives_private',
@@ -359,6 +360,13 @@ specific_input (
no_i18n ("Homepage CVS view URL (webcvs, viewcvs):"),
$row_grp[$idx], $idx, $textfield_size
);
+$idx = 'url_git_viewcvs_homepage';
+specific_input(
+ no_i18n("Homepage Git view URL (webcvs, viewcvs):"),
+ $row_grp[$idx],
+ $idx,
+ $textfield_size
+);
print "</p>";
function source_code_manager ($HTML, $row_grp, $textfield_size,
@@ -686,6 +694,8 @@ $checkboxes = [
"git" => no_i18n ("the Git link can be modified"),
"git_viewcvs" => [no_i18n ("the Git viewcvs link can be modified")],
+ "git_viewcvs_homepage" =>
+ [no_i18n("the viewcvs link for homepage code can be modified")],
"hg" => no_i18n ("the Mercurial link can be modified"),
"hg_viewcvs" => [no_i18n ("the Mercurial viewcvs link can be modified")],
diff --git a/frontend/php/testing/sane.php b/frontend/php/testing/sane.php
index fe0fdf05..ca72dff2 100644
--- a/frontend/php/testing/sane.php
+++ b/frontend/php/testing/sane.php
@@ -1932,6 +1932,7 @@ $reference = 'project/admin/editgroupfeatures.php';
foreach ($urls as $u)
$names['specialchars'][] = 'url_' . $u;
$names['specialchars'][] = 'url_cvs_viewcvs_homepage';
+ $names['specialchars'][] = 'url_git_viewcvs_homepage';
return $names;
};
$names = $post_names ();
--
2.34.1