Rev Author Line No. Line
130 kaklik 1 <?php
2 # vim:et:ts=3:sts=3:sw=3:fdm=marker:
3  
4 // WebSVN - Subversion repository viewing via the web using PHP
5 // Copyright © 2004-2006 Tim Armes, Matt Sicker
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 //
21 // --
22 //
23 // setup.inc
24 //
25 // Global setup
26  
27 // --- DON'T CHANGE THIS FILE ---
28 //
29 // User changes should be done in config.ini
30  
31 // Include the configuration class
32 require_once 'include/configclass.inc';
33 require_once 'include/svnlook.inc';
34  
35 // Define the language array
36 $lang = array();
37 $langNames = array();
38  
39 // Include a default language file.
40 require 'languages/english.inc';
41  
42 // Set up locwebsvnhttp
43 // Note: we will use nothing in MultiViews mode so that the URLs use the root
44 // directory by default.
45 if (empty($locwebsvnhttp))
46 $locwebsvnhttp = defined('WSVN_MULTIVIEWS') ? '' : '.';
47  
48 if (empty($locwebsvnreal))
49 $locwebsvnreal = '.';
50  
51 $vars['locwebsvnhttp'] = $locwebsvnhttp;
52  
53 // Make sure that the input locale is set up correctly
54 setlocale(LC_ALL, '');
55  
56 // Create the config
57 $config = new Config;
58  
59 // Set up the default character encodings
60 if (function_exists('iconv_get_encoding'))
61 {
62 $config->setInputEncoding(iconv_get_encoding('input_encoding'));
63 }
64  
65 // {{{ Content-Type's
66 // Set up the default content-type extension handling
67  
68 $contentType = array (
69  
70 '.dwg' => 'application/acad', // AutoCAD Drawing files
71 '.DWG' => 'application/acad', // AutoCAD Drawing files
72 '.arj' => 'application/arj', //  
73 '.ccAD' => 'application/clariscad', // ClarisCAD files
74 '.DRW' => 'application/drafting', // MATRA Prelude drafting
75 '.dxf' => 'application/dxf', // DXF (AutoCAD)
76 '.DXF' => 'application/dxf', // DXF (AutoCAD)
77 '.xl' => 'application/excel', // Microsoft Excel
78 '.unv' => 'application/i-deas', //SDRC I-DEAS files
79 '.UNV' => 'application/i-deas', //SDRC I-DEAS files
80 '.igs' => 'application/iges', // IGES graphics format
81 '.iges' => 'application/iges', // IGES graphics format
82 '.IGS' => 'application/iges', // IGES graphics format
83 '.IGES' => 'application/iges', // IGES graphics format
84 '.hqx' => 'application/mac-binhex40', // Macintosh BinHex format
85 '.word' => 'application/msword', // Microsoft Word
86 '.w6w' => 'application/msword', // Microsoft Word
87 '.doc' => 'application/msword', // Microsoft Word
88 '.wri' => 'application/mswrite', // Microsoft Write
89 '.bin' => 'application/octet-stream', // Uninterpreted binary
90 '.exe' => 'application/x-msdownload', // Windows EXE
91 '.EXE' => 'application/x-msdownload', // Windows EXE
92 '.oda' => 'application/oda', //  
93 '.pdf' => 'application/pdf', // PDF (Adobe Acrobat)
94 '.ai' => 'application/postscript', // PostScript
95 '.PS' => 'application/postscript', // PostScript
96 '.ps' => 'application/postscript', // PostScript
97 '.eps' => 'application/postscript', // PostScript
98 '.prt' => 'application/pro_eng', // PTC Pro/ENGINEER
99 '.PRT' => 'application/pro_eng', // PTC Pro/ENGINEER
100 '.part' => 'application/pro_eng', // PTC Pro/ENGINEER
101 '.rtf' => 'application/rtf', // Rich Text Format
102 '.set' => 'application/set', // SET (French CAD standard)
103 '.SET' => 'application/set', // SET (French CAD standard)
104 '.stl' => 'application/sla', // Stereolithography
105 '.STL' => 'application/sla', // Stereolithography
106 '.SOL' => 'application/solids', // MATRA Prelude Solids
107 '.stp' => 'application/STEP', // ISO-10303 STEP data files
108 '.STP' => 'application/STEP', // ISO-10303 STEP data files
109 '.step' => 'application/STEP', // ISO-10303 STEP data files
110 '.STEP' => 'application/STEP', // ISO-10303 STEP data files
111 '.vda' => 'application/vda', // VDA-FS Surface data
112 '.VDA' => 'application/vda', // VDA-FS Surface data
113 '.dir' => 'application/x-director', // Macromedia Director
114 '.dcr' => 'application/x-director', // Macromedia Director
115 '.dxr' => 'application/x-director', // Macromedia Director
116 '.mif' => 'application/x-mif', // FrameMaker MIF Format
117 '.csh' => 'application/x-csh', // C-shell script
118 '.dvi' => 'application/x-dvi', // TeX DVI
119 '.gz' => 'application/x-gzip', // GNU Zip
120 '.gzip' => 'application/x-gzip', // GNU Zip
121 '.hdf' => 'application/x-hdf', // ncSA HDF Data File
122 '.latex' => 'application/x-latex', // LaTeX source
123 '.nc' => 'application/x-netcdf', // Unidata netCDF
124 '.cdf' => 'application/x-netcdf', // Unidata netCDF
125 '.sit' => 'application/x-stuffit', // Stiffut Archive
126 '.tcl' => 'application/x-tcl', // TCL script
127 '.texinfo' => 'application/x-texinfo', // Texinfo (Emacs)
128 '.texi' => 'application/x-texinfo', // Texinfo (Emacs)
129 '.t' => 'application/x-troff', // Troff
130 '.tr' => 'application/x-troff', // Troff
131 '.roff' => 'application/x-troff', // Troff
132 '.man' => 'application/x-troff-man', // Troff with MAN macros
133 '.me' => 'application/x-troff-me', // Troff with ME macros
134 '.ms' => 'application/x-troff-ms', // Troff with MS macros
135 '.src' => 'application/x-wais-source', // WAIS source
136 '.bcpio' => 'application/x-bcpio', // Old binary CPIO
137 '.cpio' => 'application/x-cpio', // POSIX CPIO
138 '.gtar' => 'application/x-gtar', // GNU tar
139 '.shar' => 'application/x-shar', // Shell archive
140 '.sv4cpio' => 'application/x-sv4cpio', // SVR4 CPIO
141 '.sv4crc' => 'application/x-sv4crc', // SVR4 CPIO with CRC
142 '.tar' => 'application/x-tar', // 4.3BSD tar format
143 '.ustar' => 'application/x-ustar', // POSIX tar format
144 '.hlp' => 'application/x-winhelp', // Windows Help
145 '.zip' => 'application/zip', // ZIP archive
146 '.au' => 'audio/basic', // Basic audio (usually m-law)
147 '.snd' => 'audio/basic', // Basic audio (usually m-law)
148 '.aif' => 'audio/x-aiff', // AIFF audio
149 '.aiff' => 'audio/x-aiff', // AIFF audio
150 '.aifc' => 'audio/x-aiff', // AIFF audio
151 '.ra' => 'audio/x-pn-realaudio', // RealAudio
152 '.ram' => 'audio/x-pn-realaudio', // RealAudio
153 '.rpm' => 'audio/x-pn-realaudio-plugin', // RealAudio (plug-in)
154 '.wav' => 'audio/x-wav', // Windows WAVE audio
155 '.mp3' => 'audio/x-mp3', // MP3 files
156 '.gif' => 'image/gif', // gif image
157 '.ief' => 'image/ief', // Image Exchange Format
158 '.jpg' => 'image/jpeg', // JPEG image
159 '.JPG' => 'image/jpeg', // JPEG image
160 '.JPE' => 'image/jpeg', // JPEG image
161 '.jpe' => 'image/jpeg', // JPEG image
162 '.JPEG' => 'image/jpeg', // JPEG image
163 '.jpeg' => 'image/jpeg', // JPEG image
164 '.pict' => 'image/pict', // Macintosh PICT
165 '.tiff' => 'image/tiff', // TIFF image
166 '.tif' => 'image/tiff', // TIFF image
167 '.ras' => 'image/x-cmu-raster', // CMU raster
168 '.pnm' => 'image/x-portable-anymap', // PBM Anymap format
169 '.pbm' => 'image/x-portable-bitmap', // PBM Bitmap format
170 '.pgm' => 'image/x-portable-graymap', // PBM Graymap format
171 '.ppm' => 'image/x-portable-pixmap', // PBM Pixmap format
172 '.rgb' => 'image/x-rgb', // RGB Image
173 '.xbm' => 'image/x-xbitmap', // X Bitmap
174 '.xpm' => 'image/x-xpixmap', // X Pixmap
175 '.xwd' => 'image/x-xwindowdump', // X Windows dump (xwd) format
176 '.zip' => 'multipart/x-zip', // PKZIP Archive
177 '.gzip' => 'multipart/x-gzip', // GNU ZIP Archive
178 '.mpeg' => 'video/mpeg', // MPEG video
179 '.mpg' => 'video/mpeg', // MPEG video
180 '.MPG' => 'video/mpeg', // MPEG video
181 '.MPE' => 'video/mpeg', // MPEG video
182 '.mpe' => 'video/mpeg', // MPEG video
183 '.MPEG' => 'video/mpeg', // MPEG video
184 '.mpeg' => 'video/mpeg', // MPEG video
185 '.qt' => 'video/quicktime', // QuickTime Video
186 '.mov' => 'video/quicktime', // QuickTime Video
187 '.avi' => 'video/msvideo', // Microsoft Windows Video
188 '.movie' => 'video/x-sgi-movie', // SGI Movieplayer format
189 '.wrl' => 'x-world/x-vrml' // VRML Worlds
190  
191 );
192  
193 // }}}
194  
195 // {{{ Enscript file extensions
196  
197 // List of extensions recognised by enscript.
198  
199 $extEnscript = array
200 (
201 '.ada' => 'ada',
202 '.adb' => 'ada',
203 '.ads' => 'ada',
204 '.awk' => 'awk',
205 '.c' => 'c',
206 '.c++' => 'cpp',
207 '.cc' => 'cpp',
208 '.cpp' => 'cpp',
209 '.csh' => 'csh',
210 '.cxx' => 'cpp',
211 '.diff' => 'diffu',
212 '.dpr' => 'delphi',
213 '.el' => 'elisp',
214 '.eps' => 'postscript',
215 '.f' => 'fortran',
216 '.for' => 'fortran',
217 '.gs' => 'haskell',
218 '.h' => 'c',
219 '.hpp' => 'cpp',
220 '.hs' => 'haskell',
221 '.htm' => 'html',
222 '.html' => 'html',
223 '.idl' => 'idl',
224 '.java' => 'java',
225 '.js' => 'javascript',
226 '.lgs' => 'haskell',
227 '.lhs' => 'haskell',
228 '.m' => 'objc',
229 '.m4' => 'm4',
230 '.man' => 'nroff',
231 '.nr' => 'nroff',
232 '.p' => 'pascal',
233 '.pas' => 'delphi',
234 '.patch' => 'diffu',
235 '.pkg' => 'sql',
236 '.pl' => 'perl',
237 '.pm' => 'perl',
238 '.pp' => 'pascal',
239 '.ps' => 'postscript',
240 '.s' => 'asm',
241 '.scheme' => 'scheme',
242 '.scm' => 'scheme',
243 '.scr' => 'synopsys',
244 '.sh' => 'sh',
245 '.shtml' => 'html',
246 '.sql' => 'sql',
247 '.st' => 'states',
248 '.syn' => 'synopsys',
249 '.synth' => 'synopsys',
250 '.tcl' => 'tcl',
251 '.tex' => 'tex',
252 '.texi' => 'tex',
253 '.texinfo' => 'tex',
254 '.v' => 'verilog',
255 '.vba' => 'vba',
256 '.vh' => 'verilog',
257 '.vhd' => 'vhdl',
258 '.vhdl' => 'vhdl',
259 '.py' => 'python',
260  
261 // The following are handled internally by WebSVN, since there's no
262 // support for them in Enscript
263  
264 '.php' => 'php',
265 '.phtml' => 'php',
266 '.php3' => 'php',
267 '.inc' => 'php'
268 );
269  
270 // }}}
271  
272 // Default 'zipped' array
273  
274 $zipped = array ();
275  
276 // Get the user's personalised config
277  
278 require_once 'config.inc';
279  
280 // Set up the version info
281  
282 initSvnVersion($major,$minor);
283  
284 // Get the language choice as defained as the default by config.inc
285 $user_defaultLang = $lang['LANGUAGENAME'];
286  
287 // Override this with the user choice if there is one, and memorise the setting
288 // as a cookie (since we don't have user accounts, we can't store the setting
289 // anywhere else). We try to memorise a permanant cookie and a per session cookie
290 // in case the user's disabled permanant ones.
291  
292 if (!empty($_REQUEST['langchoice']))
293 {
294 $user_defaultLang = $_REQUEST['langchoice'];
295 setcookie('storedlang', $_REQUEST['langchoice'], time()+(3600*24*356*10), '/');
296 setcookie('storedsesslang', $_REQUEST['langchoice']);
297 }
298 else // Try to read an existing cookie if there is one
299 {
300 if (!empty($_COOKIE['storedlang'])) $user_defaultLang = $_COOKIE['storedlang'];
301 else if (!empty($_COOKIE['storedsesslang'])) $user_defaultLang = $_COOKIE['storedsesslang'];
302 }
303  
304 $user_defaultFile = '';
305 if ($handle = opendir('languages'))
306 {
307 // Read the language name for each language.
308 while (false !== ($file = readdir($handle)))
309 {
310 if ($file{0} != '.' && !is_dir('languages'.DIRECTORY_SEPARATOR.$file))
311 {
312 $lang['LANGUAGENAME'] = '';
313 require 'languages/'.$file;
314 if ($lang['LANGUAGENAME'] != '')
315 {
316 $langNames[] = $lang['LANGUAGENAME'];
317 if ($lang['LANGUAGENAME'] == $user_defaultLang)
318 $user_defaultFile = $file;
319 }
320 }
321 }
322  
323 closedir($handle);
324  
325 // XXX: this shouldn't be necessary
326 // ^ i.e. just require english.inc, then the desired language
327 // Reload english to get untranslated strings
328 require 'languages/english.inc';
329  
330 // Reload the default language
331 if (!empty($user_defaultFile))
332 require 'languages/'.$user_defaultFile;
333  
334 $url = getParameterisedSelfUrl(true);
335 $vars["lang_form"] = "<form action=\"$url\" method=\"post\" id=\"langform\">";
336 $vars["lang_select"] = "<select name=\"langchoice\" onchange=\"javascript:this.form.submit();\">";
337  
338 reset($langNames);
339 foreach ($langNames as $name)
340 {
341 $sel = "";
342 if ($name == $user_defaultLang) $sel = "selected";
343 $vars["lang_select"] .= "<option value=\"$name\" $sel>$name</option>";
344 }
345  
346 $vars["lang_select"] .= "</select>";
347 $vars["lang_submit"] = "<input type=\"submit\" value=\"${lang["GO"]}\">";
348 $vars["lang_endform"] = "</form>";
349 }
350  
351 // Set up headers
352  
353 header("Content-type: text/html; charset=".$config->outputEnc);
354  
355 // Make sure that the user has set up a repository
356  
357 $reps = $config->getRepositories();
358 if (empty($reps[0]))
359 {
360 echo $lang["SUPPLYREP"];
361 exit;
362 }
363  
364 // Override the rep parameter with the repository name if it's available
365 $repname = @$_REQUEST["repname"];
366 if (isset($repname))
367 {
368 $rep = $config->findRepository($repname);
369 }
370 else
371 $rep = $reps[0];
372  
373 // Retrieve other standard parameters
374  
375 # due to possible XSS exploit, we need to clean up path first
376 $path = !empty($_REQUEST['path']) ? $_REQUEST['path'] : null;
377 $vars['safepath'] = htmlentities($path);
378 $rev = (int)@$_REQUEST["rev"];
379 $showchanged = (@$_REQUEST["sc"] == 1)?1:0;
380  
381 // Function to create the project selection HTML form
382 function createProjectSelectionForm()
383 {
384 global $config, $vars, $rep, $lang, $showchanged;
385  
386 $url = $config->getURL(-1, "", "form");
387 $vars["projects_form"] = "<form action=\"$url\" method=\"post\" id=\"projectform\">";
388  
389 $reps = $config->getRepositories();
390 $vars["projects_select"] = "<select name=\"repname\" onchange=\"javascript:this.form.submit();\">";
391  
392 foreach ($reps as $trep)
393 {
394 if ($trep->hasReadAccess("/", true))
395 {
396 if ($rep->getDisplayName() == $trep->getDisplayName())
397 $sel = "selected";
398 else
399 $sel = "";
400  
401 $vars["projects_select"] .= "<option value=\"".$trep->getDisplayName()."\" $sel>".$trep->getDisplayName()."</option>";
402 }
403 }
404  
405 $vars["projects_select"] .= "</select>";
406  
407 $vars["projects_submit"] = "<input type=\"submit\" value=\"${lang["GO"]}\" />";
408 $vars["projects_endform"] = "<input type=\"hidden\" name=\"selectproj\" value=\"1\" /><input type=\"hidden\" name=\"op\" value=\"form\" /><input type=\"hidden\" name=\"sc\" value=\"$showchanged\" /></form>";
409 }
410  
411 // Create the form if we're not in MultiViews. Otherwise wsvn must create the form once the current project has
412 // been found
413  
414 if (!$config->multiViews)
415 {
416 createProjectSelectionForm();
417 }
418  
419 if ($rep)
420 {
421 $vars["allowdownload"] = $rep->getAllowDownload();
422 $vars["repname"] = $rep->getDisplayName();
423 }
424  
425 // As of version 1.70 the output encoding is forced to be UTF-8, since this is the output
426 // encoding returned by svn log --xml. This is good, since we are no longer reliant on PHP's
427 // rudimentary conversions.
428  
429 $vars["charset"] = "UTF-8";
430 ?>