]>
git.ipfire.org Git - thirdparty/bugzilla.git/blob - Bugzilla/BugUrl.pm
1e836ca1e8eabc2f2c0f059461069b286ec50a61
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 # This Source Code Form is "Incompatible With Secondary Licenses", as
6 # defined by the Mozilla Public License, v. 2.0.
8 package Bugzilla
::BugUrl
;
14 use parent
qw(Bugzilla::Object);
18 use Bugzilla
::Constants
;
24 ###############################
25 #### Initialization ####
26 ###############################
28 use constant DB_TABLE
=> 'bug_see_also';
29 use constant NAME_FIELD
=> 'value';
30 use constant LIST_ORDER
=> 'id';
31 # See Also is tracked in bugs_activity.
32 use constant AUDIT_CREATES
=> 0;
33 use constant AUDIT_UPDATES
=> 0;
34 use constant AUDIT_REMOVES
=> 0;
36 use constant DB_COLUMNS
=> qw(
43 # This must be strings with the names of the validations,
44 # instead of coderefs, because subclasses override these
45 # validators with their own.
46 use constant VALIDATORS
=> {
47 value
=> '_check_value',
48 bug_id
=> '_check_bug_id',
49 class => \
&_check_class
,
52 # This is the order we go through all of subclasses and
53 # pick the first one that should handle the url. New
54 # subclasses should be added at the end of the list.
55 use constant SUB_CLASSES
=> qw(
56 Bugzilla::BugUrl::Bugzilla::Local
57 Bugzilla::BugUrl::Bugzilla
58 Bugzilla::BugUrl::Launchpad
59 Bugzilla::BugUrl::Google
60 Bugzilla::BugUrl::Debian
61 Bugzilla::BugUrl::JIRA
62 Bugzilla::BugUrl::Trac
63 Bugzilla::BugUrl::MantisBT
64 Bugzilla::BugUrl::SourceForge
65 Bugzilla::BugUrl::GitHub
68 ###############################
70 ###############################
72 sub class { return $_[0]->{class} }
73 sub bug_id
{ return $_[0]->{bug_id
} }
75 ###############################
77 ###############################
84 my $bug_id = $param->{bug_id
};
85 my $name = $param->{name
} || $param->{value
};
86 if (!defined $bug_id) {
87 ThrowCodeError
('bad_arg',
88 { argument
=> 'bug_id',
89 function
=> "${class}::new" });
92 ThrowCodeError
('bad_arg',
94 function
=> "${class}::new" });
97 my $condition = 'bug_id = ? AND value = ?';
98 my @values = ($bug_id, $name);
99 $param = { condition
=> $condition, values => \
@values };
103 return $class->SUPER::new
(@_);
106 sub _do_list_select
{
108 my $objects = $class->SUPER::_do_list_select
(@_);
110 foreach my $object (@
$objects) {
111 eval "use " . $object->class; die $@
if $@
;
112 bless $object, $object->class;
118 # This is an abstract method. It must be overridden
121 my ($class, $input) = @_;
122 ThrowCodeError
('unknown_method',
123 { method
=> "${class}::should_handle" });
127 my ($class, $value) = @_;
129 my @sub_classes = $class->SUB_CLASSES;
130 Bugzilla
::Hook
::process
("bug_url_sub_classes",
131 { sub_classes
=> \
@sub_classes });
133 my $uri = URI
->new($value);
134 foreach my $subclass (@sub_classes) {
135 eval "use $subclass";
137 return wantarray ?
($subclass, $uri) : $subclass
138 if $subclass->should_handle($uri);
141 ThrowUserError
('bug_url_invalid', { url
=> $value });
145 my ($class, $subclass) = @_;
146 eval "use $subclass"; die $@
if $@
;
151 my ($class, $bug_id) = @_;
154 if (blessed
$bug_id) {
155 # We got a bug object passed in, use it
157 $bug->check_is_visible;
160 # We got a bug id passed in, check it and get the bug object
161 $bug = Bugzilla
::Bug
->check({ id
=> $bug_id });
168 my ($class, $uri) = @_;
170 my $value = $uri->as_string;
173 ThrowCodeError
('param_required',
174 { function
=> 'add_see_also', param
=> '$value' });
177 # We assume that the URL is an HTTP URL if there is no (something)://
180 # This works better than setting $uri->scheme('http'), because
181 # that creates URLs like "http:domain.com" and doesn't properly
182 # differentiate the path from the domain.
183 $uri = new URI
("http://$value");
185 elsif ($uri->scheme ne 'http' && $uri->scheme ne 'https') {
186 ThrowUserError
('bug_url_invalid', { url
=> $value, reason
=> 'http' });
189 # This stops the following edge cases from being accepted:
190 # * show_bug.cgi?id=1
191 # * /show_bug.cgi?id=1
192 # * http:///show_bug.cgi?id=1
193 if (!$uri->authority or $uri->path !~ m{/}) {
194 ThrowUserError
('bug_url_invalid',
195 { url
=> $value, reason
=> 'path_only' });
198 if (length($uri->path) > MAX_BUG_URL_LENGTH
) {
199 ThrowUserError
('bug_url_too_long', { url
=> $uri->path });
207 =head1 B<Methods in need of POD>