Rev Author Line No. Line
4988 kaklik 1 <?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 // setup.php
22 //
23 // Global setup
24  
25 // --- DON'T CHANGE THIS FILE ---
26 //
27 // User changes should be done in config.php
28  
29 // Include the configuration class
30 require_once 'include/configclass.php';
31  
32 // Register Composer autoloader if available
33 if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
34 require_once __DIR__ . '/../vendor/autoload.php';
35 define('USE_AUTOLOADER', true);
36 }
37  
38 // Create the config
39 $config = new WebSvnConfig();
40  
41 if (DIRECTORY_SEPARATOR == '\\') {
42 $config->setServerIsWindows();
43 }
44  
45 // Set up locwebsvnhttp
46 // Note: we will use nothing in MultiViews mode so that the URLs use the root
47 // directory by default.
48 if (empty($locwebsvnhttp)) {
49 $locwebsvnhttp = defined('WSVN_MULTIVIEWS') ? '' : '.';
50 }
51 if (empty($locwebsvnreal)) {
52 $locwebsvnreal = '.';
53 }
54  
55 $vars['locwebsvnhttp'] = $locwebsvnhttp;
56  
57 // {{{ Content Types
58 // Set up the default content-type extension handling
59  
60 $contentType = array(
61 '.dwg' => 'application/acad', // AutoCAD Drawing files
62 '.arj' => 'application/arj',
63 '.ccad' => 'application/clariscad', // ClarisCAD files
64 '.drw' => 'application/drafting', // MATRA Prelude drafting
65 '.dxf' => 'application/dxf', // DXF (AutoCAD)
66 '.xls' => 'application/excel', // Microsoft Excel
67 '.unv' => 'application/i-deas', //SDRC I-DEAS files
68 '.igs' => 'application/iges', // IGES graphics format
69 '.iges' => 'application/iges', // IGES graphics format
70 '.hqx' => 'application/mac-binhex40', // Macintosh BinHex format
71 '.word' => 'application/msword', // Microsoft Word
72 '.w6w' => 'application/msword', // Microsoft Word
73 '.doc' => 'application/msword', // Microsoft Word
74 '.wri' => 'application/mswrite', // Microsoft Write
75 '.bin' => 'application/octet-stream', // Uninterpreted binary
76 '.exe' => 'application/x-msdownload', // Windows EXE
77 '.oda' => 'application/oda',
78 '.pdf' => 'application/pdf', // PDF (Adobe Acrobat)
79 '.ai' => 'application/postscript', // PostScript
80 '.ps' => 'application/postscript', // PostScript
81 '.eps' => 'application/postscript', // PostScript
82 '.prt' => 'application/pro_eng', // PTC Pro/ENGINEER
83 '.part' => 'application/pro_eng', // PTC Pro/ENGINEER
84 '.rtf' => 'application/rtf', // Rich Text Format
85 '.set' => 'application/set', // SET (French CAD standard)
86 '.stl' => 'application/sla', // Stereolithography
87 '.sol' => 'application/solids', // MATRA Prelude Solids
88 '.stp' => 'application/STEP', // ISO-10303 STEP data files
89 '.step' => 'application/STEP', // ISO-10303 STEP data files
90 '.vda' => 'application/vda', // VDA-FS Surface data
91 '.dir' => 'application/x-director', // Macromedia Director
92 '.dcr' => 'application/x-director', // Macromedia Director
93 '.dxr' => 'application/x-director', // Macromedia Director
94 '.mif' => 'application/x-mif', // FrameMaker MIF Format
95 '.csh' => 'application/x-csh', // C-shell script
96 '.dvi' => 'application/x-dvi', // TeX DVI
97 '.gz' => 'application/gzip', // GNU Zip
98 '.gzip' => 'application/gzip', // GNU Zip
99 '.hdf' => 'application/x-hdf', // ncSA HDF Data File
100 '.latex' => 'application/x-latex', // LaTeX source
101 '.nc' => 'application/x-netcdf', // Unidata netCDF
102 '.cdf' => 'application/x-netcdf', // Unidata netCDF
103 '.sit' => 'application/x-stuffit', // Stiffut Archive
104 '.tcl' => 'application/x-tcl', // TCL script
105 '.texinfo' => 'application/x-texinfo', // Texinfo (Emacs)
106 '.texi' => 'application/x-texinfo', // Texinfo (Emacs)
107 '.t' => 'application/x-troff', // Troff
108 '.tr' => 'application/x-troff', // Troff
109 '.roff' => 'application/x-troff', // Troff
110 '.man' => 'application/x-troff-man', // Troff with MAN macros
111 '.me' => 'application/x-troff-me', // Troff with ME macros
112 '.ms' => 'application/x-troff-ms', // Troff with MS macros
113 '.src' => 'application/x-wais-source', // WAIS source
114 '.bcpio' => 'application/x-bcpio', // Old binary CPIO
115 '.cpio' => 'application/x-cpio', // POSIX CPIO
116 '.gtar' => 'application/x-gtar', // GNU tar
117 '.shar' => 'application/x-shar', // Shell archive
118 '.sv4cpio' => 'application/x-sv4cpio', // SVR4 CPIO
119 '.sv4crc' => 'application/x-sv4crc', // SVR4 CPIO with CRC
120 '.tar' => 'application/x-tar', // 4.3BSD tar format
121 '.ustar' => 'application/x-ustar', // POSIX tar format
122 '.hlp' => 'application/x-winhelp', // Windows Help
123 '.zip' => 'application/zip', // ZIP archive
124  
125 '.au' => 'audio/basic', // Basic audio (usually m-law)
126 '.snd' => 'audio/basic', // Basic audio (usually m-law)
127 '.aif' => 'audio/x-aiff', // AIFF audio
128 '.aiff' => 'audio/x-aiff', // AIFF audio
129 '.aifc' => 'audio/x-aiff', // AIFF audio
130 '.ra' => 'audio/x-pn-realaudio', // RealAudio
131 '.ram' => 'audio/x-pn-realaudio', // RealAudio
132 '.rpm' => 'audio/x-pn-realaudio-plugin', // RealAudio (plug-in)
133 '.wav' => 'audio/x-wav', // Windows WAVE audio
134 '.mp3' => 'audio/x-mp3', // MP3 files
135  
136 '.gif' => 'image/gif', // gif image
137 '.ief' => 'image/ief', // Image Exchange Format
138 '.jpg' => 'image/jpeg', // JPEG image
139 '.jpe' => 'image/jpeg', // JPEG image
140 '.jpeg' => 'image/jpeg', // JPEG image
141 '.pict' => 'image/pict', // Macintosh PICT
142 '.png' => 'image/png', // PNG image
143 '.svg' => 'image/svg+xml', // Scalable vector graphics
144 '.tiff' => 'image/tiff', // TIFF image
145 '.tif' => 'image/tiff', // TIFF image
146 '.ras' => 'image/x-cmu-raster', // CMU raster
147 '.pnm' => 'image/x-portable-anymap', // PBM Anymap format
148 '.pbm' => 'image/x-portable-bitmap', // PBM Bitmap format
149 '.pgm' => 'image/x-portable-graymap', // PBM Graymap format
150 '.ppm' => 'image/x-portable-pixmap', // PBM Pixmap format
151 '.rgb' => 'image/x-rgb', // RGB Image
152 '.xbm' => 'image/x-xbitmap', // X Bitmap
153 '.xpm' => 'image/x-xpixmap', // X Pixmap
154 '.xwd' => 'image/x-xwindowdump', // X Windows dump (xwd) format
155  
156 '.mpeg' => 'video/mpeg', // MPEG video
157 '.mpg' => 'video/mpeg', // MPEG video
158 '.mpe' => 'video/mpeg', // MPEG video
159 '.mpeg' => 'video/mpeg', // MPEG video
160 '.qt' => 'video/quicktime', // QuickTime Video
161 '.mov' => 'video/quicktime', // QuickTime Video
162 '.avi' => 'video/msvideo', // Microsoft Windows Video
163 '.movie' => 'video/x-sgi-movie', // SGI Movieplayer format
164 '.wrl' => 'x-world/x-vrml', // VRML Worlds
165  
166 '.ods' => 'application/vnd.oasis.opendocument.spreadsheet', // OpenDocument Spreadsheet
167 '.ots' => 'application/vnd.oasis.opendocument.spreadsheet-template', // OpenDocument Spreadsheet Template
168 '.odp' => 'application/vnd.oasis.opendocument.presentation', // OpenDocument Presentation
169 '.otp' => 'application/vnd.oasis.opendocument.presentation-template', // OpenDocument Presentation Template
170 '.odg' => 'application/vnd.oasis.opendocument.graphics', // OpenDocument Drawing
171 '.otg' => 'application/vnd.oasis.opendocument.graphics-template', // OpenDocument Drawing Template
172 '.odc' => 'application/vnd.oasis.opendocument.chart', // OpenDocument Chart
173 '.otc' => 'application/vnd.oasis.opendocument.chart-template', // OpenDocument Chart Template
174 '.odf' => 'application/vnd.oasis.opendocument.formula', // OpenDocument Formula
175 '.otf' => 'application/vnd.oasis.opendocument.formula-template', // OpenDocument Formula Template
176 '.odi' => 'application/vnd.oasis.opendocument.image', // OpenDocument Image
177 '.oti' => 'application/vnd.oasis.opendocument.image-template', // OpenDocument Image Template
178 '.odb' => 'application/vnd.oasis.opendocument.database', // OpenDocument Database
179 '.odt' => 'application/vnd.oasis.opendocument.text', // OpenDocument Text
180 '.ott' => 'application/vnd.oasis.opendocument.text-template', // OpenDocument Text Template
181 '.odm' => 'application/vnd.oasis.opendocument.text-master', // OpenDocument Master Document
182 '.oth' => 'application/vnd.oasis.opendocument.text-web', // OpenDocument HTML Template
183 );
184  
185 // }}}
186  
187 // {{{ Enscript file extensions
188  
189 // List of extensions recognised by enscript.
190  
191 $extEnscript = array(
192 '.ada' => 'ada',
193 '.adb' => 'ada',
194 '.ads' => 'ada',
195 '.awk' => 'awk',
196 '.c' => 'c',
197 '.c++' => 'cpp',
198 '.cc' => 'cpp',
199 '.cmake' => 'cmake',
200 'CMakeLists.txt' => 'cmake',
201 '.cpp' => 'cpp',
202 '.csh' => 'csh',
203 '.cxx' => 'cpp',
204 '.diff' => 'diffu',
205 '.dpr' => 'delphi',
206 '.e' => 'eiffel',
207 '.el' => 'elisp',
208 '.eps' => 'postscript',
209 '.f' => 'fortran',
210 '.for' => 'fortran',
211 '.gs' => 'haskell',
212 '.h' => 'c',
213 '.hpp' => 'cpp',
214 '.hs' => 'haskell',
215 '.htm' => 'html',
216 '.html' => 'html',
217 '.idl' => 'idl',
218 '.java' => 'java',
219 '.js' => 'javascript',
220 '.json' => 'javascript',
221 '.lgs' => 'haskell',
222 '.lhs' => 'haskell',
223 '.m' => 'objc',
224 '.m4' => 'm4',
225 '.man' => 'nroff',
226 '.nr' => 'nroff',
227 '.p' => 'pascal',
228 '.pas' => 'delphi',
229 '.patch' => 'diffu',
230 '.pkg' => 'sql',
231 '.pl' => 'perl',
232 '.pm' => 'perl',
233 '.pp' => 'pascal',
234 '.ps' => 'postscript',
235 '.s' => 'asm',
236 '.scheme' => 'scheme',
237 '.scm' => 'scheme',
238 '.scr' => 'synopsys',
239 '.sh' => 'sh',
240 '.shtml' => 'html',
241 '.sql' => 'sql',
242 '.st' => 'states',
243 '.syn' => 'synopsys',
244 '.synth' => 'synopsys',
245 '.tcl' => 'tcl',
246 '.tex' => 'tex',
247 '.texi' => 'tex',
248 '.texinfo' => 'tex',
249 '.v' => 'verilog',
250 '.vba' => 'vba',
251 '.vh' => 'verilog',
252 '.vhd' => 'vhdl',
253 '.vhdl' => 'vhdl',
254 '.py' => 'python',
255 );
256  
257 // }}}
258  
259 // {{{ GeSHi file extensions
260  
261 // List of extensions recognised by GeSHi.
262  
263 $extGeshi = array(
264 'actionscript3' => array('as'),
265 'ada' => array('ada', 'adb', 'ads'),
266 'asm' => array('ash', 'asi', 'asm'),
267 'asp' => array('asp'),
268 'bash' => array('sh'),
269 'bibtex' => array('bib'),
270 'c' => array('c'),
271 'cfm' => array('cfm', 'cfml'),
272 'cmake' => array('cmake', 'CMakeLists.txt'),
273 'cobol' => array('cbl'),
274 'cpp' => array('cc', 'cpp', 'cxx', 'c++', 'h', 'hpp'),
275 'csharp' => array('cs'),
276 'css' => array('css'),
277 'd' => array('d'),
278 'delphi' => array('dpk', 'dpr', 'pas'),
279 'diff' => array('diff', 'patch'),
280 'dos' => array('bat', 'cmd'),
281 'eiffel' => array('e'),
282 'erlang' => array('erl'),
283 'email' => array('eml'),
284 'fortran' => array('f', 'for', 'f90'),
285 'gettext' => array('po', 'pot'),
286 'gml' => array('gml'),
287 'gnuplot' => array('plt'),
288 'groovy' => array('groovy'),
289 'haskell' => array('gs', 'hs', 'lgs', 'lhs'),
290 'html4strict' => array('html', 'htm'),
291 'idl' => array('idl'),
292 'ini' => array('desktop', 'ini'),
293 'java5' => array('java'),
294 'javascript' => array('js', 'json'),
295 'latex' => array('tex'),
296 'lisp' => array('lisp'),
297 'lua' => array('lua'),
298 'make' => array('make'),
299 'matlab' => array('m'),
300 'perl' => array('pl', 'pm'),
301 'php' => array('php', 'php3', 'php4', 'php5', 'phps', 'phtml'),
302 'povray' => array('pov'),
303 'properties' => array('properties'),
304 'providex' => array('pvc', 'pvx'),
305 'python' => array('py'),
306 'reg' => array('reg'),
307 'ruby' => array('rb'),
308 'scala' => array('scala'),
309 'scheme' => array('scm', 'scheme'),
310 'scilab' => array('sci'),
311 'smalltalk' => array('st'),
312 'sql' => array('sql'),
313 'tcl' => array('tcl'),
314 'vb' => array('bas'),
315 'vbnet' => array('vb'),
316 'vh' => array('v', 'verilog'),
317 'vhdl' => array('vhd', 'vhdl'),
318 'vim' => array('vim'),
319 'whitespace' => array('ws'),
320 'xml' => array('xml', 'xsl', 'xsd', 'xib', 'wsdl', 'svg', 'plist', 'jmx'),
321 'z80' => array('z80'),
322 );
323  
324 // }}}
325  
326 // Loads English localized strings by default (must go before config.php)
327 require 'languages/english.php';
328  
329 // Support one WebSVN installation hosting multiple different SVNParentPaths, distinguished by their
330 // location. Per location, the web server needs to set some environment variable providing the path
331 // to the config to either exclusively or additionally include, implementing a simple layered config
332 // this way. That allows, e.g., changing paths to repos per location only and share everything else.
333 //
334 // The following implementation deals with multiple most likely problems in such an environment, like
335 // HTTP redirects influencing the name of the environment variable set and "preg_grep" indexing its
336 // results depending on the input, so optionally changing between requests.
337 //
338 // https://stackoverflow.com/q/3050444/696632
339 // https://bz.apache.org/bugzilla/show_bug.cgi?id=58739
340 $confSuccess = 0;
341 $envPathConf = preg_grep('/^(?:REDIRECT_)*WEBSVN_PATH_CONF$/', array_keys($_SERVER));
342 $envPathConf = array_values($envPathConf);
343 $envPathConf = array_key_exists(0, $envPathConf)
344 ? $_SERVER[$envPathConf[0]]
345 : '';
346  
347 // Get the user's personalised config (requires the locwebsvnhttp stuff above).
348 if (file_exists('include/config.php')) {
349 require_once 'include/config.php';
350 $confSuccess = 1;
351 }
352 if (!empty($envPathConf)) {
353 require_once $envPathConf;
354 $confSuccess = 1;
355 }
356 if (!$confSuccess) {
357 die('No config applied, either create "include/config.php" or use environment variable ' .
358 '"WEBSVN_PATH_CONF". The example file "include/distconfig.php" should be copied and ' .
359 'modified as needed.');
360 }
361  
362 // Make sure that the input locale is set up correctly
363 putenv("LANG=".setlocale(LC_ALL, $config->getLocale()));
364  
365 $vars['showageinsteadofdate'] = $config->showAgeInsteadOfDate();
366  
367 // Initialize the version of SVN that is being used by WebSVN internally.
368 require_once 'include/svnlook.php';
369 $vars['svnversion'] = $config->getSubversionVersion();
370  
371 // Initialize an array with all query parameters except language and template.
372 $queryParams = $_GET + $_POST;
373 unset($queryParams['language']);
374 unset($queryParams['template']);
375 $hidden = '';
376 foreach ($queryParams as $key => $value) {
377 if (is_array($value)) {
378 for ($i = 0; $i < count($value); $i++) {
379 $hidden .= '<input type="hidden" name="'.escape($key).'[]" value="'.escape($value[$i]).'"/>';
380 }
381 } else {
382 $hidden .= '<input type="hidden" name="'.escape($key).'" value="'.escape($value).'"/>';
383 }
384 }
385  
386 // If the request specifies a language, store in a cookie. Otherwise, check for cookies specifying a
387 // particular language already.
388 $language = ''; // RFC 4646 language tag for representing the selected language.
389 if (!empty($_REQUEST['language'])) {
390 $language = $_REQUEST['language'];
391 setcookie('storedlang', $language, time() + (60 * 60 * 24 * 356 * 10));
392 setcookie('storedsesslang', $language);
393 } else if (isset($_COOKIE['storedlang'])) {
394 $language = $_COOKIE['storedlang'];
395 } else if (isset($_COOKIE['storedsesslang'])) {
396 $language = $_COOKIE['storedsesslang'];
397 }
398  
399 // Load available languages (populates $languages array)
400 require 'languages/languages.php';
401 // Get the default language as defined by config.php
402 $defaultLanguage = $config->getDefaultLanguage();
403 if (!isset($languages[$defaultLanguage]))
404 $defaultLanguage = 'en';
405 // Determine which language to actually use
406 $language = getUserLanguage($languages, $defaultLanguage, $language);
407 $vars['language_code'] = $language;
408 // For languages other than English, load translated strings over existing ones.
409 if ($language != 'en')
410 require 'languages/'.$languages[$language][0].'.php';
411 // Generate the HTML form for selecting a different language
412 $vars['language_form'] = '<form method="get" action="" id="language">'.$hidden;
413 $vars['language_select'] = '<select name="language" onchange="javascript:this.form.submit();">';
414 foreach ($languages as $code => $names) {
415 $sel = ($code == $language) ? '" selected="selected' : '';
416 $vars['language_select'] .= '<option value="'.$code.$sel.'">'.$names[2].' &ndash; '.$names[1].'</option>';
417 }
418 $vars['language_select'] .= '</select>';
419 $vars['language_submit'] = '<noscript><input type="submit" value="'.$lang['GO'].'" /></noscript>';
420 $vars['language_endform'] = '</form>';
421  
422 // Load repository if possible
423 if ($config->multiViews) {
424 $rep = null; // MultiViews has custom code to load a repository
425 } else {
426 // Load repository matching 'repname' parameter (if set) or the default.
427 $repname = @$_REQUEST['repname'];
428 if (isset($repname)) {
429 $rep = $config->findRepository($repname);
430 } else {
431 $reps = $config->getRepositories();
432 $rep = (isset($reps[0]) ? $reps[0] : null);
433 }
434 // Make sure that the user has set up a repository
435 if ($rep == null) {
436 $vars['error'] = $lang['SUPPLYREP'];
437 } else if (is_string($rep)) {
438 $vars['error'] = $rep;
439 $rep = null;
440 } else {
441 $vars['repurl'] = $config->getURL($rep, '', 'dir');
442 $vars['clientrooturl'] = $rep->clientRootURL;
443 $vars['repname'] = escape($rep->getDisplayName());
444 $vars['allowdownload'] = $rep->getAllowDownload();
445 }
446 }
447  
448 // If the request specifies a template, store in a cookie. Otherwise, check for cookies specifying a
449 // particular template already.
450 $template = '';
451 if (!empty($_REQUEST['template'])) {
452 $template = $_REQUEST['template'];
453 setcookie('storedtemplate', $template, time() + (60 * 60 * 24 * 365 * 10));
454 setcookie('storedsesstemplate', $template);
455 } else if (isset($_COOKIE['storedtemplate'])) {
456 $template = $_COOKIE['storedtemplate'];
457 } else if (isset($_COOKIE['storedsesstemplate'])) {
458 $template = $_COOKIE['storedsesstemplate'];
459 }
460  
461 $templates = array();
462 // Skip creating template list when selected repository has specific template.
463 if ($rep == null || $rep->templatePath === false) {
464 // Get all templates defined in config.php; use last path component as name.
465 foreach ($config->templatePaths as $path) {
466 $templates[$path] = basename($path);
467 }
468 $selectedTemplatePath = $config->getTemplatePath();
469 if ($template != '' && in_array($template, $templates)) {
470 $selectedTemplatePath = array_search($template, $templates);
471 $config->userTemplate = $selectedTemplatePath;
472 }
473 }
474  
475 // Generate the HTML form for selecting a different template
476 if (count($templates) > 1) {
477 $vars['template_form'] = '<form method="get" action="" id="template">'.$hidden;
478 $vars['template_select'] = '<select name="template" onchange="javascript:this.form.submit();">';
479 natcasesort($templates);
480 foreach ($templates as $path => $name) {
481 $sel = ($path == $selectedTemplatePath) ? ' selected="selected"' : '';
482 $vars['template_select'] .= '<option value="'.$name.'"'.$sel.'>'.$name.'</option>';
483 }
484 $vars['template_select'] .= '</select>';
485 $vars['template_submit'] = '<noscript><input type="submit" value="'.$lang['GO'].'" /></noscript>';
486 $vars['template_endform'] = '</form>';
487 } else {
488 $vars['template_form'] = '';
489 $vars['template_select'] = '';
490 $vars['template_submit'] = '';
491 $vars['template_endform'] = '';
492 }
493  
494 $vars['indexurl'] = $config->getURL('', '', 'index');
495 $vars['validationurl'] = getFullURL($_SERVER['SCRIPT_NAME']).'?'.buildQuery($queryParams + array('template' => $template, 'language' => $language), '%26');
496  
497 $path = !empty($_REQUEST['path']) ? $_REQUEST['path'] : null;
498 if ($path === null || $path === '')
499 $path = '/';
500 $vars['path'] = str_replace('%2F', '/', rawurlencode($path));
501 $vars['safepath'] = escape($path);
502 // Set operative and peg revisions (if specified) and save passed-in revision
503 $rev = (int)@$_REQUEST['rev'];
504 $peg = (int)@$_REQUEST['peg'];
505 $search = (string)@$_REQUEST['search'];
506 if ($peg === 0)
507 $peg = '';
508 $passrev = $rev;
509  
510 if (!$config->multiViews) {
511 // With MultiViews, browse creates the form once the current project is found.
512 createProjectSelectionForm();
513 createRevisionSelectionForm();
514 createSearchSelectionForm();
515 }
516  
517 // set flag if robots should be blocked
518 $vars['blockrobots'] = $config->areRobotsBlocked();
519  
520 $listing = array();
521  
522 // Set up response headers
523 header('Content-Type: text/html; charset=UTF-8');
524 header('Content-Language: '.$language);
525  
526 // Function to create the project selection HTML form
527 function createProjectSelectionForm() {
528 global $config, $vars, $rep, $lang;
529  
530 $vars['projects_form'] = '';
531 $vars['projects_select'] = '';
532 $vars['projects_submit'] = '';
533 $vars['projects_endform'] = '';
534  
535 if (!$config->showRepositorySelectionForm() || count($config->getRepositories()) < 2)
536 return;
537  
538 if ($rep) {
539 $currentRepoName = $rep->getDisplayName();
540 $options = '';
541 } else {
542 $currentRepoName = '';
543 $options = '<option value="" selected="selected"></option>';
544 }
545 foreach ($config->getRepositories() as $repository) {
546 if ($repository->hasReadAccess('/')) {
547 $repoName = $repository->getDisplayName();
548 $sel = ($repoName == $currentRepoName) ? ' selected="selected"' : '';
549 $options .= '<option value="'.escape($repoName).'"'.$sel.'>'.escape($repoName).'</option>';
550 }
551 }
552 if (strlen($options) === 0)
553 return;
554  
555 $vars['projects_form'] = '<form method="get" action="" id="project">';
556 if ($config->multiViews)
557 $vars['projects_form'] .= '<input type="hidden" name="op" value="rep" />';
558 $vars['projects_select'] = '<select name="repname" onchange="javascript:this.form.submit();">'.$options.'</select>';
559 $vars['projects_submit'] = '<noscript><input type="submit" value="'.$lang['GO'].'" /></noscript>';
560 $vars['projects_endform'] = '</form>';
561 }
562  
563 // Function to create the revision selection HTML form
564 function createRevisionSelectionForm() {
565 global $config, $lang, $vars, $rep, $path, $rev, $peg;
566  
567 if ($rep == null)
568 return;
569  
570 $params = array();
571 if (!$config->multiViews) {
572 $params['repname'] = $rep->getDisplayName();
573 if ($path === null)
574 $path = !empty($_REQUEST['path']) ? $_REQUEST['path'] : null;
575 if ($path && $path != '/')
576 $params['path'] = $path;
577 }
578 if ($peg || $rev)
579 $params['peg'] = ($peg ? $peg : $rev);
580 $hidden = '';
581 foreach ($params as $key => $value) {
582 $hidden .= '<input type="hidden" name="'.$key.'" value="'.escape($value).'" />';
583 }
584 // The blank "action" attribute makes form link back to the containing page.
585 $vars['revision_form'] = '<form method="get" action="" id="revision">'.$hidden;
586 if ($rev === null)
587 $rev = (int)@$_REQUEST['rev'];
588 $vars['revision_input'] = '<input type="text" size="5" name="rev" placeholder="'.($rev ? $rev : 'HEAD').'" />';
589 $vars['revision_submit'] = '<input type="submit" value="'.$lang['GO'].'" />';
590 $vars['revision_endform'] = '</form>';
591 }
592  
593 function createSearchSelectionForm() {
594 global $config, $lang, $vars, $rep, $path, $rev, $peg, $search;
595 if ($rep === null)
596 return;
597 $params = array();
598 if (!$config->multiViews) {
599 $params['repname'] = $rep->getDisplayName();
600 if ($path === null)
601 $path = !empty($_REQUEST['path']) ? $_REQUEST['path'] : null;
602 if ($path && $path != '/')
603 $params['path'] = $path;
604 }
605 if ($peg || $rev)
606 $params['rev'] = ($peg ? $peg : $rev);
607 $hidden = '';
608 foreach ($params as $key => $value) {
609 $hidden .= '<input type="hidden" name="'.$key.'" value="'.escape($value).'" />';
610 }
611 $vars['search'] = true;
612 $vars['search_form'] = '<form method="get" action="'.$config->getURL($rep, '', 'search').'" id="search">'.$hidden;
613 $search = $search? $search : $lang['SEARCH_PLACEHOLDER'];
614 $vars['search_input'] = '<input type="text" size="20" name="search" placeholder="'.$search.'" />';
615 $vars['search_submit'] = '<input type="submit" value="'.$lang['SEARCH'].'" />';
616 $vars['search_endform'] = '</form>';
617 }
618 function sendHeaderForbidden() {
619 http_response_code(403);
620 }