| 1293 |
dpurdie |
1 |
###############################################################################
|
|
|
2 |
# Codestriker: Copyright (c) 2001, 2002 David Sitsky. All rights reserved.
|
|
|
3 |
# sits@users.sourceforge.net
|
|
|
4 |
#
|
|
|
5 |
# This program is free software; you can redistribute it and modify it under
|
|
|
6 |
# the terms of the GPL.
|
|
|
7 |
|
|
|
8 |
# Collection of routines for building codestriker URLs.
|
|
|
9 |
|
|
|
10 |
package Codestriker::Http::UrlBuilder;
|
|
|
11 |
|
|
|
12 |
use strict;
|
|
|
13 |
|
|
|
14 |
# Constants for different viewing file modes - set by the type CGI parameter.
|
|
|
15 |
$UrlBuilder::OLD_FILE = 0;
|
|
|
16 |
$UrlBuilder::NEW_FILE = 1;
|
|
|
17 |
$UrlBuilder::BOTH_FILES = 2;
|
|
|
18 |
|
|
|
19 |
# Constructor for this class.
|
|
|
20 |
sub new($$) {
|
|
|
21 |
my ($type, $query) = @_;
|
|
|
22 |
my $self = {};
|
|
|
23 |
$self->{query} = $query;
|
|
|
24 |
|
|
|
25 |
# Determine what prefix is required when using relative URLs.
|
|
|
26 |
# Unfortunately, Netcsape 4.x does things differently to everyone
|
|
|
27 |
# else.
|
|
|
28 |
my $browser = $ENV{'HTTP_USER_AGENT'};
|
|
|
29 |
$self->{url_prefix} = "";
|
|
|
30 |
if (defined $browser && $browser =~ m%^Mozilla/(\d)% && $1 <= 4) {
|
|
|
31 |
$self->{url_prefix} = $query->url(-relative=>1);
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
# Check if the HTML files are accessible vi another URL (required for
|
|
|
35 |
# sourceforge deployment). Check $Codestriker::codestriker_css.
|
|
|
36 |
my $htmlurl;
|
|
|
37 |
if (defined $Codestriker::codestriker_css &&
|
|
|
38 |
$Codestriker::codestriker_css ne "") {
|
|
|
39 |
$htmlurl = $Codestriker::codestriker_css;
|
|
|
40 |
$htmlurl =~ s/\/codestriker\.css//;
|
|
|
41 |
}
|
|
|
42 |
else {
|
|
|
43 |
# Standard Codestriker deployment.
|
|
|
44 |
$htmlurl = $query->url();
|
|
|
45 |
$htmlurl =~ s/codestriker\/codestriker\.pl/codestrikerhtml/;
|
|
|
46 |
}
|
|
|
47 |
$self->{htmldir} = $htmlurl;
|
|
|
48 |
|
|
|
49 |
return bless $self, $type;
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
# Create the URL for viewing a topic with a specified tabwidth.
|
|
|
53 |
sub view_url_extended ($$$$$$$$$$) {
|
|
|
54 |
my ($self, $topic, $line, $mode, $tabwidth, $email, $prefix,
|
|
|
55 |
$updated, $brmode, $fview) = @_;
|
|
|
56 |
|
|
|
57 |
return ($prefix ne "" ? $prefix : $self->{query}->url()) .
|
|
|
58 |
"?topic=$topic&action=view" .
|
|
|
59 |
($updated ? "&updated=$updated" : "") .
|
|
|
60 |
((defined $tabwidth && $tabwidth ne "") ? "&tabwidth=$tabwidth" : "") .
|
|
|
61 |
((defined $mode && $mode ne "") ? "&mode=$mode" : "") .
|
|
|
62 |
((defined $brmode && $brmode ne "") ? "&brmode=$brmode" : "") .
|
|
|
63 |
((defined $fview && $fview ne "") ? "&fview=$fview" : "") .
|
|
|
64 |
((defined $email && $email ne "") ? "&email=$email" : "") .
|
|
|
65 |
($line != -1 ? "#${line}" : "");
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
# Create the URL for viewing a topic.
|
|
|
69 |
sub view_url ($$$$$$) {
|
|
|
70 |
my ($self, $topic, $line, $mode, $brmode, $fview) = @_;
|
|
|
71 |
if (!(defined $mode)) { $mode = $Codestriker::default_topic_create_mode; }
|
|
|
72 |
if (!(defined $brmode)) { $brmode = $Codestriker::default_topic_br_mode; }
|
|
|
73 |
if (!(defined $fview)) { $fview = $Codestriker::default_file_to_view; }
|
|
|
74 |
return $self->view_url_extended($topic, $line, $mode, "", "", "",
|
|
|
75 |
undef, $brmode, $fview);
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
# Create the URL for downloading the topic text.
|
|
|
79 |
sub download_url ($$) {
|
|
|
80 |
my ($self, $topic) = @_;
|
|
|
81 |
return $self->{query}->url() . "?action=download&topic=$topic";
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
# Create the URL for creating a topic.
|
|
|
85 |
sub create_topic_url ($$) {
|
|
|
86 |
my ($self, $obsoletes) = @_;
|
|
|
87 |
return $self->{query}->url() . "?action=create" .
|
|
|
88 |
(defined $obsoletes ? "&obsoletes=$obsoletes" : "");
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
# Create the URL for editing a topic.
|
|
|
92 |
sub edit_url ($$$$$$$) {
|
|
|
93 |
my ($self, $filenumber, $line, $new, $topic, $context,
|
|
|
94 |
$anchor, $prefix) = @_;
|
|
|
95 |
return ($prefix ne "" ? $prefix : $self->{url_prefix}) .
|
|
|
96 |
"?fn=$filenumber&line=$line&new=$new&topic=$topic&action=edit" .
|
|
|
97 |
((defined $anchor && $anchor ne "") ? "&a=$anchor" : "") .
|
|
|
98 |
((defined $context && $context ne "") ? "&context=$context" : "");
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
# Create the URL for viewing a new file.
|
|
|
102 |
sub view_file_url ($$$$$$$) {
|
|
|
103 |
my ($self, $topic, $filenumber, $new, $line, $mode, $parallel) = @_;
|
|
|
104 |
if (!(defined $mode)) { $mode = $Codestriker::default_topic_create_mode; }
|
|
|
105 |
return $self->{url_prefix} . "?action=view_file&fn=$filenumber&" .
|
|
|
106 |
"topic=$topic&new=$new&mode=$mode¶llel=$parallel#$filenumber|$line|$new";
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
# Create the URL for the search page.
|
|
|
110 |
sub search_url ($) {
|
|
|
111 |
my ($self) = @_;
|
|
|
112 |
return $self->{query}->url() . "?action=search";
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
# Create the URL for the documentation page.
|
|
|
116 |
sub doc_url ($) {
|
|
|
117 |
my ($self) = @_;
|
|
|
118 |
return $self->{htmldir};
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
# Create the URL for listing the topics (and topic search). See
|
|
|
122 |
# _list_topics_url for true param list.
|
|
|
123 |
sub list_topics_url ($$$$$$$$$$$\@\@$) {
|
|
|
124 |
my ($self) = @_;
|
|
|
125 |
|
|
|
126 |
shift @_; # peal off self.
|
|
|
127 |
|
|
|
128 |
return $self->_list_topics_url("list_topics",@_);
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
# Create the URL for listing the topics (and topic search) via RSS. See
|
|
|
132 |
# _list_topics_url for true param list.
|
|
|
133 |
sub list_topics_url_rss ($$$$$$$$$$$\@\@$) {
|
|
|
134 |
my ($self) = @_;
|
|
|
135 |
|
|
|
136 |
shift @_; # peal off self.
|
|
|
137 |
|
|
|
138 |
return $self->_list_topics_url("list_topics_rss",@_);
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
# Create the URL for listing the topics.
|
|
|
142 |
sub _list_topics_url ($$$$$$$$$$$$\@\@$) {
|
|
|
143 |
my ($self, $action,$sauthor, $sreviewer, $scc, $sbugid, $stext,
|
|
|
144 |
$stitle, $sdescription, $scomments, $sbody, $sfilename,
|
|
|
145 |
$state_array_ref, $project_array_ref, $content) = @_;
|
|
|
146 |
|
|
|
147 |
my $sstate = defined $state_array_ref ? (join ',', @$state_array_ref) : "";
|
|
|
148 |
my $sproject = defined $project_array_ref ?
|
|
|
149 |
(join ',', @$project_array_ref) : "";
|
|
|
150 |
return $self->{query}->url() . "?action=$action" .
|
|
|
151 |
($sauthor ne "" ? "&sauthor=$sauthor" : "") .
|
|
|
152 |
($sreviewer ne "" ? "&sreviewer=$sreviewer" : "") .
|
|
|
153 |
($scc ne "" ? "&scc=$scc" : "") .
|
|
|
154 |
($sbugid ne "" ? "&sbugid=$sbugid" : "") .
|
|
|
155 |
($stext ne "" ? "&stext=" . CGI::escape($stext) : "") .
|
|
|
156 |
($stitle ne "" ? "&stitle=$stitle" : "") .
|
|
|
157 |
($sdescription ne "" ? "&sdescription=$sdescription" : "") .
|
|
|
158 |
($scomments ne "" ? "&scomments=$scomments" : "") .
|
|
|
159 |
($sbody ne "" ? "&sbody=$sbody" : "") .
|
|
|
160 |
($sfilename ne "" ? "&sfilename=$sfilename" : "") .
|
|
|
161 |
($sstate ne "" ? "&sstate=$sstate" : "") .
|
|
|
162 |
($sproject ne "" ? "&sproject=$sproject" : "") .
|
|
|
163 |
(defined $content && $content ne "" ? "&content=$content" : "");
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
|
|
|
167 |
# Construct a URL for editing a specific project.
|
|
|
168 |
sub edit_project_url ($$) {
|
|
|
169 |
my ($self, $projectid) = @_;
|
|
|
170 |
|
|
|
171 |
return $self->{query}->url() . "?action=edit_project&projectid=$projectid";
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
# Construct a URL for listing all projects.
|
|
|
175 |
sub list_projects_url ($) {
|
|
|
176 |
my ($self) = @_;
|
|
|
177 |
|
|
|
178 |
return $self->{query}->url() . "?action=list_projects";
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
# Construct a URL for creating a project.
|
|
|
182 |
sub create_project_url ($) {
|
|
|
183 |
my ($self) = @_;
|
|
|
184 |
|
|
|
185 |
return $self->{query}->url() . "?action=create_project";
|
|
|
186 |
}
|
|
|
187 |
|
|
|
188 |
# Create the URL for viewing comments.
|
|
|
189 |
sub view_comments_url ($$) {
|
|
|
190 |
my ($self, $topic) = @_;
|
|
|
191 |
|
|
|
192 |
return $self->{query}->url() . "?action=list_comments&topic=$topic";
|
|
|
193 |
}
|
|
|
194 |
|
|
|
195 |
# Create the URL for viewing the topic properties.
|
|
|
196 |
sub view_topic_properties_url ($$) {
|
|
|
197 |
my ($self, $topic) = @_;
|
|
|
198 |
|
|
|
199 |
return $self->{query}->url() .
|
|
|
200 |
"?action=view_topic_properties&topic=$topic";
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
# Create the URL for viewing the topic metrics.
|
|
|
204 |
sub view_topicinfo_url ($$) {
|
|
|
205 |
my ($self, $topic) = @_;
|
|
|
206 |
|
|
|
207 |
return $self->{query}->url() . "?action=viewinfo&topic=$topic";
|
|
|
208 |
}
|
|
|
209 |
|
|
|
210 |
sub metric_report_url {
|
|
|
211 |
my ($self) = @_;
|
|
|
212 |
|
|
|
213 |
return $self->{query}->url() . "?action=metrics_report";
|
|
|
214 |
}
|
|
|
215 |
|
|
|
216 |
sub metric_report_download_raw_data {
|
|
|
217 |
my ($self) = @_;
|
|
|
218 |
|
|
|
219 |
return $self->{query}->url() . "?action=metrics_download";
|
|
|
220 |
}
|
|
|
221 |
|
|
|
222 |
|
|
|
223 |
|
|
|
224 |
1;
|