1 | 1 | simandl | <?php |
2 | | | // WebSVN - Subversion repository viewing via the web using PHP |
3 | | | // Copyright (C) 2004-2006 Tim Armes |
4 | | | // |
5 | | | // This program is free software; you can redistribute it and/or modify |
6 | | | // it under the terms of the GNU General Public License as published by |
7 | | | // the Free Software Foundation; either version 2 of the License, or |
8 | | | // (at your option) any later version. |
9 | | | // |
10 | | | // This program is distributed in the hope that it will be useful, |
11 | | | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | | | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | | | // GNU General Public License for more details. |
14 | | | // |
15 | | | // You should have received a copy of the GNU General Public License |
16 | | | // along with this program; if not, write to the Free Software |
17 | | | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | | | // |
19 | | | // -- |
20 | | | // |
21 | | | // log.php |
22 | | | // |
23 | | | // Show the logs for the given path |
24 | | | |
25 | | | require_once("include/setup.php"); |
26 | | | require_once("include/svnlook.php"); |
27 | | | require_once("include/utils.php"); |
28 | | | require_once("include/template.php"); |
29 | | | require_once("include/bugtraq.php"); |
30 | | | |
31 | | | $page = (int)@$_REQUEST["page"]; |
32 | | | $all = (@$_REQUEST["all"] == 1)?1:0; |
33 | | | $isDir = (@$_REQUEST["isdir"] == 1)?1:0; |
34 | | | $dosearch = (@$_REQUEST["logsearch"] == 1)?1:0; |
35 | | | $search = trim(@$_REQUEST["search"]); |
36 | | | $words = preg_split('#\s+#', $search); |
37 | | | $fromRev = (int)@$_REQUEST["fr"]; |
38 | | | $startrev = strtoupper(trim(@$_REQUEST["sr"])); |
39 | | | $endrev = strtoupper(trim(@$_REQUEST["er"])); |
40 | | | $max = isset($_REQUEST['max']) ? (int)$_REQUEST['max'] : false; |
41 | | | |
42 | | | // Max number of results to find at a time |
43 | | | $numSearchResults = 15; |
44 | | | |
45 | | | if ($search == "") { |
46 | | | $dosearch = false; |
47 | | | } |
48 | | | |
49 | | | // removeAccents |
50 | | | // |
51 | | | // Remove all the accents from a string. This function doesn't seem |
52 | | | // ideal, but expecting everyone to install 'unac' seems a little |
53 | | | // excessive as well... |
54 | | | |
55 | | | function removeAccents($string) { |
56 | | | $string = htmlentities($string, ENT_QUOTES, 'ISO-8859-1'); |
57 | | | $string = preg_replace('/&([a-z])(acute|uml|circ|grave|ring|cedil|slash|tilde|caron);/','$1',$string); |
58 | | | $string = preg_replace('/&([A-Z])(acute|uml|circ|grave|ring|cedil|slash|tilde|caron);/','$1',$string); |
59 | | | |
60 | | | return $string; |
61 | | | } |
62 | | | |
63 | | | // Normalise the search words |
64 | | | foreach ($words as $index => $word) { |
65 | | | $words[$index] = strtolower(removeAccents($word)); |
66 | | | |
67 | | | // Remove empty string introduced by multiple spaces |
68 | | | if (empty($words[$index])) unset($words[$index]); |
69 | | | } |
70 | | | |
71 | | | if (empty($page)) $page = 1; |
72 | | | |
73 | | | // If searching, display all the results |
74 | | | if ($dosearch) $all = true; |
75 | | | |
76 | | | $maxperpage = 20; |
77 | | | |
78 | | | // Make sure that we have a repository |
79 | | | if (!isset($rep)) { |
80 | | | echo $lang["NOREP"]; |
81 | | | exit; |
82 | | | } |
83 | | | |
84 | | | $svnrep = new SVNRepository($rep); |
85 | | | |
86 | | | $passrev = $rev; |
87 | | | |
88 | | | // If there's no revision info, go to the lastest revision for this path |
89 | | | $history = $svnrep->getLog($path, "", "", true); |
90 | | | $youngest = isset($history->entries[0]) ? $history->entries[0]->rev : 0; |
91 | | | |
92 | | | if (empty($rev)) { |
93 | | | $rev = $youngest; |
94 | | | } |
95 | | | |
96 | | | // make sure path is prefixed by a / |
97 | | | $ppath = $path; |
98 | | | if ($path == "" || $path{0} != "/") { |
99 | | | $ppath = "/".$path; |
100 | | | } |
101 | | | |
102 | | | $vars["action"] = $lang["LOG"]; |
103 | | | $vars["repname"] = htmlentities($rep->getDisplayName(), ENT_QUOTES, 'UTF-8'); |
104 | | | $vars["rev"] = $rev; |
105 | | | $vars["path"] = htmlentities($ppath, ENT_QUOTES, 'UTF-8'); |
106 | | | |
107 | | | createDirLinks($rep, $ppath, $passrev); |
108 | | | |
109 | | | $vars['indexurl'] = $config->getURL($rep, '', 'index'); |
110 | | | $vars['repurl'] = $config->getURL($rep, '', 'dir'); |
111 | | | |
112 | | | if (!$isDir) { |
113 | | | $url = $config->getURL($rep, $path, "file"); |
114 | | | $vars["filedetaillink"] = "<a href=\"${url}rev=$rev&isdir=0\">${lang["FILEDETAIL"]}</a>"; |
115 | | | |
116 | | | $url = $config->getURL($rep, $path, "diff"); |
117 | | | $vars["prevdifflink"] = "<a href=\"${url}rev=$rev\">${lang["DIFFPREV"]}</a>"; |
118 | | | |
119 | | | $url = $config->getURL($rep, $path, "blame"); |
120 | | | $vars["blamelink"] = "<a href=\"${url}rev=$passrev\">${lang["BLAME"]}</a>"; |
121 | | | } |
122 | | | |
123 | | | $logurl = $config->getURL($rep, $path, "log"); |
124 | | | |
125 | | | if ($rev != $youngest) { |
126 | | | $vars["goyoungestlink"] = "<a href=\"${logurl}isdir=$isDir\">${lang["GOYOUNGEST"]}</a>"; |
127 | | | } else { |
128 | | | $vars["goyoungestlink"] = ""; |
129 | | | } |
130 | | | |
131 | | | // We get the bugtraq variable just once based on the HEAD |
132 | | | $bugtraq = new Bugtraq($rep, $svnrep, $ppath); |
133 | | | |
134 | | | if ($startrev != "HEAD" && $startrev != "BASE" && $startrev != "PREV" && $startrev != "COMMITTED") $startrev = (int)$startrev; |
135 | | | if ($endrev != "HEAD" && $endrev != "BASE" && $endrev != "PREV" && $endrev != "COMMITTED") $endrev = (int)$endrev; |
136 | | | if (empty($startrev)) $startrev = $rev; |
137 | | | if (empty($endrev)) $endrev = 1; |
138 | | | |
139 | | | if ($max === false) { |
140 | | | $max = $dosearch ? 0 : 30; |
141 | | | } else { |
142 | | | if ($max < 0) $max = 30; |
143 | | | } |
144 | | | |
145 | | | $history = $svnrep->getLog($path, $startrev, $endrev, true, $max); |
146 | | | $vars["logsearch_moreresultslink"] = ""; |
147 | | | $vars["pagelinks"] = ""; |
148 | | | $vars["showalllink"] = ""; |
149 | | | $listing = array(); |
150 | | | |
151 | | | if (!empty($history)) { |
152 | | | // Get the number of separate revisions |
153 | | | $revisions = count($history->entries); |
154 | | | |
155 | | | if ($all) { |
156 | | | $firstrevindex = 0; |
157 | | | $lastrevindex = $revisions - 1; |
158 | | | $pages = 1; |
159 | | | } else { |
160 | | | // Calculate the number of pages |
161 | | | $pages = floor($revisions / $maxperpage); |
162 | | | if (($revisions % $maxperpage) > 0) $pages++; |
163 | | | |
164 | | | if ($page > $pages) $page = $pages; |
165 | | | |
166 | | | // Word out where to start and stop |
167 | | | $firstrevindex = ($page - 1) * $maxperpage; |
168 | | | $lastrevindex = $firstrevindex + $maxperpage - 1; |
169 | | | if ($lastrevindex > $revisions - 1) $lastrevindex = $revisions - 1; |
170 | | | } |
171 | | | |
172 | | | $brev = isset($history->entries[$firstrevindex ]) ? $history->entries[$firstrevindex ]->rev : false; |
173 | | | $erev = isset($history->entries[$lastrevindex]) ? $history->entries[$lastrevindex]->rev : false; |
174 | | | |
175 | | | $entries = array(); |
176 | | | if ($brev && $erev) { |
177 | | | $history = $svnrep->getLog($path, $brev, $erev, false, 0); |
178 | | | $entries = $history->entries; |
179 | | | } |
180 | | | |
181 | | | $row = 0; |
182 | | | $index = 0; |
183 | | | $listing = array(); |
184 | | | $found = false; |
185 | | | |
186 | | | foreach ($entries as $r) { |
187 | | | // Assume a good match |
188 | | | $match = true; |
189 | | | $thisrev = $r->rev; |
190 | | | |
191 | | | // Check the log for the search words, if searching |
192 | | | if ($dosearch) { |
193 | | | if ((empty($fromRev) || $fromRev > $thisrev)) { |
194 | | | // Turn all the HTML entities into real characters. |
195 | | | |
196 | | | // Make sure that each word in the search in also in the log |
197 | | | foreach ($words as $word) { |
198 | | | if (strpos(strtolower(removeAccents($r->msg)), $word) === false && strpos(strtolower(removeAccents($r->author)), $word) === false) { |
199 | | | $match = false; |
200 | | | break; |
201 | | | } |
202 | | | } |
203 | | | |
204 | | | if ($match) { |
205 | | | $numSearchResults--; |
206 | | | $found = true; |
207 | | | } |
208 | | | } else { |
209 | | | $match = false; |
210 | | | } |
211 | | | } |
212 | | | |
213 | | | if ($match) |
214 | | | { |
215 | | | // Add the trailing slash if we need to (svnlook history doesn't return trailing slashes!) |
216 | | | $rpath = $r->path; |
217 | | | |
218 | | | if (empty($rpath)) { |
219 | | | $rpath = "/"; |
220 | | | } else if ($isDir && $rpath{strlen($rpath) - 1} != "/") { |
221 | | | $rpath .= "/"; |
222 | | | } |
223 | | | |
224 | | | // Find the parent path (or the whole path if it's already a directory) |
225 | | | $pos = strrpos($rpath, "/"); |
226 | | | $parent = substr($rpath, 0, $pos + 1); |
227 | | | |
228 | | | $url = $config->getURL($rep, $parent, "revision"); |
229 | | | $listing[$index]["revlink"] = "<a href=\"${url}rev=$thisrev\">$thisrev</a>"; |
230 | | | |
231 | | | if ($isDir) { |
232 | | | $listing[$index]["compare_box"] = "<input type=\"checkbox\" name=\"compare[]\" value=\"$parent@$thisrev\" onclick=\"checkCB(this)\" />"; |
233 | | | $url = $config->getURL($rep, $rpath, "dir"); |
234 | | | $listing[$index]["revpathlink"] = "<a href=\"${url}rev=$thisrev\">$rpath</a>"; |
235 | | | } else { |
236 | | | $listing[$index]["compare_box"] = "<input type=\"checkbox\" name=\"compare[]\" value=\"$rpath@$thisrev\" onclick=\"checkCB(this)\" />"; |
237 | | | $url = $config->getURL($rep, $rpath, "file"); |
238 | | | $listing[$index]["revpathlink"] = "<a href=\"${url}rev=$thisrev\">$rpath</a>"; |
239 | | | } |
240 | | | |
241 | | | $listing[$index]["revauthor"] = $r->author; |
242 | | | $listing[$index]["revage"] = $r->age; |
243 | | | $listing[$index]["revlog"] = nl2br($bugtraq->replaceIDs(create_anchors($r->msg))); |
244 | | | $listing[$index]["rowparity"] = $row; |
245 | | | |
246 | | | $row = 1 - $row; |
247 | | | $index++; |
248 | | | } |
249 | | | |
250 | | | // If we've reached the search limit, stop here... |
251 | | | if (!$numSearchResults) { |
252 | | | $url = $config->getURL($rep, $path, "log"); |
253 | | | $vars["logsearch_moreresultslink"] = "<a href=\"${url}rev=$rev&isdir=$isDir&logsearch=1&search=$search&fr=$thisrev\">${lang["MORERESULTS"]}</a>"; |
254 | | | break; |
255 | | | } |
256 | | | } |
257 | | | |
258 | | | $vars["logsearch_resultsfound"] = true; |
259 | | | |
260 | | | if ($dosearch && !$found) { |
261 | | | if ($fromRev == 0) { |
262 | | | $vars["logsearch_nomatches"] = true; |
263 | | | $vars["logsearch_resultsfound"] = false; |
264 | | | } else { |
265 | | | $vars["logsearch_nomorematches"] = true; |
266 | | | } |
267 | | | } else if ($dosearch && $numSearchResults > 0) { |
268 | | | $vars["logsearch_nomorematches"] = true; |
269 | | | } |
270 | | | |
271 | | | // Work out the paging options |
272 | | | |
273 | | | if ($pages > 1) { |
274 | | | $prev = $page - 1; |
275 | | | $next = $page + 1; |
276 | | | |
277 | | | if ($page > 1) $vars["pagelinks"] .= "<a href=\"${logurl}rev=$rev&sr=$startrev&er=$endrev&max=$max&page=$prev\">< ${lang["PREV"]}</a> "; |
278 | | | for ($p = 1; $p <= $pages; $p++) { |
279 | | | if ($p != $page) { |
280 | | | $vars["pagelinks"].= "<a href=\"${logurl}rev=$rev&sr=$startrev&er=$endrev&isdir=$isDir&max=$max&page=$p\">$p</a> "; |
281 | | | } else { |
282 | | | $vars["pagelinks"] .= "<b>$p </b>"; |
283 | | | } |
284 | | | } |
285 | | | if ($page < $pages) $vars["pagelinks"] .=" <a href=\"${logurl}rev=$rev&sr=$startrev&er=$endrev&isdir=$isDir&max=$max&page=$next\">${lang["NEXT"]} ></a>"; |
286 | | | |
287 | | | $vars["showalllink"] = "<a href=\"${logurl}rev=$rev&sr=$startrev&er=$endrev&isdir=$isDir&all=1&max=$max\">${lang["SHOWALL"]}</a>"; |
288 | | | } |
289 | | | } |
290 | | | |
291 | | | // Create the project change combo box |
292 | | | |
293 | | | $url = $config->getURL($rep, $path, "log"); |
294 | | | // XXX: forms don't have the name attribute, but _everything_ has the id attribute, |
295 | | | // so what you're trying to do (if anything?) should be done via that ~J |
296 | | | $vars["logsearch_form"] = "<form action=\"$url\" method=\"post\">"; |
297 | | | |
298 | | | $vars["logsearch_startbox"] = "<input name=\"sr\" size=\"5\" value=\"$startrev\" />"; |
299 | | | $vars["logsearch_endbox" ] = "<input name=\"er\" size=\"5\" value=\"$endrev\" />"; |
300 | | | $vars["logsearch_maxbox" ] = "<input name=\"max\" size=\"5\" value=\"".($max==0?"":$max)."\" />"; |
301 | | | $vars["logsearch_inputbox"] = "<input name=\"search\" value=\"".htmlentities($search, ENT_QUOTES, 'UTF-8')."\" />"; |
302 | | | |
303 | | | $vars["logsearch_submit"] = "<input type=\"submit\" value=\"${lang["GO"]}\" />"; |
304 | | | $vars["logsearch_hidden"] = "<input type=\"hidden\" name=\"logsearch\" value=\"1\" />". |
305 | | | "<input type=\"hidden\" name=\"op\" value=\"log\" />". |
306 | | | "<input type=\"hidden\" name=\"rev\" value=\"$rev\" />". |
307 | | | "<input type=\"hidden\" name=\"isdir\" value=\"$isDir\" />"; |
308 | | | $vars["logsearch_endform"] = "</form>"; |
309 | | | |
310 | | | $url = $config->getURL($rep, $path, "log"); |
311 | | | $vars["logsearch_clearloglink"] = "<a href=\"${url}rev=$rev&isdir=$isDir\">${lang["CLEARLOG"]}</a>"; |
312 | | | |
313 | | | $url = $config->getURL($rep, "/", "comp"); |
314 | | | $vars["compare_form"] = "<form action=\"$url\" method=\"post\">"; |
315 | | | $vars["compare_submit"] = "<input name=\"comparesubmit\" type=\"submit\" value=\"${lang["COMPAREREVS"]}\" />"; |
316 | | | $vars["compare_hidden"] = "<input type=\"hidden\" name=\"op\" value=\"comp\" />"; |
317 | | | $vars["compare_endform"] = "</form>"; |
318 | | | |
319 | | | $vars["version"] = $version; |
320 | | | |
321 | | | if (!$rep->hasReadAccess($path, false)) { |
322 | | | $vars["noaccess"] = true; |
323 | | | } |
324 | | | |
325 | | | parseTemplate($rep->getTemplatePath()."header.tmpl", $vars, $listing); |
326 | | | parseTemplate($rep->getTemplatePath()."log.tmpl", $vars, $listing); |
327 | | | parseTemplate($rep->getTemplatePath()."footer.tmpl", $vars, $listing); |