1
|
|
|
<?php |
2
|
|
|
// |
3
|
|
|
// Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved |
4
|
|
|
// |
5
|
|
|
// |
6
|
|
|
// |
7
|
|
|
// |
8
|
|
|
// Written for Codendi by Nicolas Guérin |
9
|
|
|
// |
10
|
|
|
// This script performs a redirection to the proper artifact page, given |
11
|
|
|
// only the artifact id, and possibly the artifact name detected in text and a group_id. |
12
|
|
|
// It is called from function util_make_links |
13
|
|
|
|
14
|
|
|
/******************************************************************** |
15
|
|
|
* WARNING * |
16
|
|
|
* Please note that this script has been replaced by src/www/goto |
17
|
|
|
* We only keep it for compatibility with existing commit messages and legacy trackers |
18
|
|
|
********************************************************************/ |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
require_once('../svn/svn_data.php'); |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Redirect function for generic trackers. |
25
|
|
|
* This function checks the artifact short name and project. |
26
|
|
|
* If the name is not the same as the tracker's short name, a warning is displayed. |
27
|
|
|
* If the artifact does not belong to the same project as the referring page, a warning is also displayed. |
28
|
|
|
*/ |
29
|
|
|
function generic_redirect($location,$aid,$group_id,$art_group_id,$atid,$atn,$art_name) { |
30
|
|
|
global $Language; |
31
|
|
|
$feed = ''; |
32
|
|
|
if (($group_id)&&($group_id != $art_group_id)) { |
33
|
|
|
// The link is coming from another project, add a warning msg |
34
|
|
|
$group_name=util_get_group_name_from_id($art_group_id); |
35
|
|
|
$feed="&feedback=".urlencode($Language->getText('tracker_gotoid','art_belongs_to',$group_name)); |
36
|
|
|
} |
37
|
|
|
if (($atn)&&(strtolower($atn) != strtolower($art_name))) { |
38
|
|
|
if ((strtolower($atn)!="art")&&(strtolower($atn)!="artifact")) { |
39
|
|
|
$feed.=urlencode($Language->getText('tracker_gotoid','art_is_a',array($art_name,$atn))); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$location .= "/tracker/?func=detail&aid=".(int)$aid."&group_id=".(int)$art_group_id."&atid=".((int)$atid).$feed; |
44
|
|
|
header($location); |
45
|
|
|
exit; |
|
|
|
|
46
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
// Start of main code |
51
|
|
|
|
52
|
|
|
$location = "Location: ".get_server_url(); |
53
|
|
|
|
54
|
|
|
// $atn is the "artifact type name" i.e. the tracker short name detected in the text |
55
|
|
|
// Detected: 'xxx #nnn', transformed to '$atn #$aid' |
56
|
|
|
$atn = strtolower($request->get('atn')); |
57
|
|
|
|
58
|
|
|
// If group_name given as argument then infer group_id first |
59
|
|
|
$group_name = $request->get('group_name'); |
60
|
|
|
if ($group_name && !$group_id) { |
61
|
|
|
$grp = group_get_object_by_name($group_name); |
62
|
|
|
$group_id = $grp->getGroupId(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
// Commit and patch are not ambiguous (not trackers) |
66
|
|
|
$svn_loc = "/svn/?func=detailrevision&rev_id=". (int)$aid ."&group_id=". (int)$group_id; |
67
|
|
|
$cvs_loc = "/cvs/?func=detailcommit&commit_id=". (int)$aid ."&group_id=". (int)$group_id; |
68
|
|
|
if (($atn == 'rev') || ($atn == 'revision')) { |
69
|
|
|
$location .= $svn_loc; |
70
|
|
|
header($location); |
71
|
|
|
exit; |
72
|
|
|
} |
73
|
|
|
if ($atn == 'commit') { |
74
|
|
|
// when commit is used see if it revision exists in SVN else redirect to CVS |
75
|
|
|
$res = svn_data_get_revision_detail($group_id, 0, $aid); |
76
|
|
|
$feed = ''; |
77
|
|
|
if ($res && db_numrows($res) > 0) { |
78
|
|
|
$location .= $svn_loc.$feed; |
79
|
|
|
} else { |
80
|
|
|
// Check that the commit belongs to the same project |
81
|
|
|
$commit_group_id=util_get_group_from_commit_id($aid); |
82
|
|
|
if (($commit_group_id)&&($group_id != $commit_group_id)) { |
83
|
|
|
// The link is coming from another project, add a warning msg |
84
|
|
|
$group_name=util_get_group_name_from_id($commit_group_id); |
85
|
|
|
$feed="&feedback".urlencode($Language->getText('tracker_gotoid','commit_belongs_to',$group_name)); |
86
|
|
|
} |
87
|
|
|
$location .= $cvs_loc.$feed; |
88
|
|
|
} |
89
|
|
|
header($location); |
90
|
|
|
exit; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
// Document link |
94
|
|
|
if ($atn == 'doc') { |
95
|
|
|
$location .= "/docman/display_doc.php?docid=". (int)$aid ."&group_id=". (int)$group_id; |
96
|
|
|
header($location); |
97
|
|
|
exit; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
// Should we remove this one? |
102
|
|
|
if (!$group_id) { |
103
|
|
|
// group_id is necessary for legacy trackers -> link to generic tracker |
104
|
|
|
$art_group_id = $request->get('art_group_id'); |
105
|
|
|
$art_name = $request->get('art_name'); |
106
|
|
|
if (!util_get_ids_from_aid($aid,$art_group_id,$atid,$art_name)) { |
107
|
|
|
exit_error($Language->getText('global','error'),$Language->getText('tracker_gotoid', 'invalid_art_nb', $aid)); |
108
|
|
|
} |
109
|
|
|
generic_redirect($location,$aid,$art_group_id,$art_group_id,$atid,$atn,$art_name); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
// not standard atn -> generic tracker. |
113
|
|
|
if (!util_get_ids_from_aid($aid, $art_group_id, $atid, $art_name)) { |
114
|
|
|
exit_error($Language->getText('global', 'error'), $Language->getText('tracker_gotoid', 'invalid_art_nb', $aid)); |
115
|
|
|
} |
116
|
|
|
generic_redirect($location, $aid, $group_id, $art_group_id, $atid, $atn, $art_name); |
117
|
|
|
|
118
|
|
|
?> |
119
|
|
|
|
An exit expression should only be used in rare cases. For example, if you write a short command line script.
In most cases however, using an
exit
expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.