GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (4873)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

plugins/git/include/GitViews.class.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
4
 * Copyright (c) Enalean, 2011 - 2016. All Rights Reserved.
5
 *
6
 * This file is a part of Tuleap.
7
 *
8
 * Codendi is free software; you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation; either version 2 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * Codendi is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with Codendi. If not, see <http://www.gnu.org/licenses/
20
 */
21
22
require_once 'www/project/admin/permissions.php';
23
24
/**
25
 * GitViews
26
 */
27
class GitViews extends PluginViews {
28
29
    /** @var Project */
30
    private $project;
31
32
    /** @var GitPermissionsManager */
33
    private $git_permissions_manager;
34
35
    /** @var UGroupManager */
36
    private $ugroup_manager;
37
38
    /** @var Git_GitRepositoryUrlManager */
39
    private $url_manager;
40
41
    /** @var Git_Mirror_MirrorDataMapper */
42
    private $mirror_data_mapper;
43
44
    public function __construct(
45
        $controller,
46
        Git_GitRepositoryUrlManager $url_manager,
47
        Git_Mirror_MirrorDataMapper $mirror_data_mapper,
48
        GitPermissionsManager $permissions_manager
49
    ) {
50
        parent::__construct($controller);
51
        $this->groupId                 = (int)$this->request->get('group_id');
52
        $this->project                 = ProjectManager::instance()->getProject($this->groupId);
53
        $this->projectName             = $this->project->getUnixName();
54
        $this->userName                = $this->user->getName();
55
        $this->git_permissions_manager = $permissions_manager;
56
        $this->ugroup_manager          = new UGroupManager();
57
        $this->url_manager             = $url_manager;
58
        $this->mirror_data_mapper      = $mirror_data_mapper;
59
    }
60
61
    public function header() {
62
        $title = $GLOBALS['Language']->getText('plugin_git','title');
63
64
        $this->getToolbar();
65
66
        $GLOBALS['HTML']->header(array('title'=>$title, 'group'=>$this->groupId, 'toptab'=>'plugin_git'));
67
    }
68
69
    public function footer() {
70
        $GLOBALS['HTML']->footer(array());
71
    }
72
73
    public function getText($key, $params=array() ) {
74
        return $GLOBALS['Language']->getText('plugin_git', $key, $params);
75
    }
76
77
    protected function getToolbar() {
78
        $GLOBALS['HTML']->addToolbarItem($this->linkTo($this->getText('bread_crumb_home'), '/plugins/git/?group_id='.$this->groupId));
79
        $GLOBALS['HTML']->addToolbarItem($this->linkTo($this->getText('fork_repositories'), '/plugins/git/?group_id='.$this->groupId .'&action=fork_repositories'));
80
        $GLOBALS['HTML']->addToolbarItem($this->linkTo($this->getText('bread_crumb_help'), 'javascript:help_window(\'/doc/'.$this->user->getShortLocale().'/user-guide/git.html\')'));
81
82
        if ($this->git_permissions_manager->userIsGitAdmin($this->user, $this->project)) {
83
            $GLOBALS['HTML']->addToolbarItem($this->linkTo($this->getText('bread_crumb_admin'), '/plugins/git/?group_id='.$this->groupId .'&action=admin'));
84
        }
85
    }
86
87
    /**
88
     * HELP VIEW
89
     */
90
    public function help($topic, $params=array()) {
91
        if ( empty($topic) ) {
92
            return false;
93
        }
94
        $display = 'block';
95
        if ( !empty($params['display']) ) {
96
            $display = $params['display'];
97
        }
98
        switch( $topic ) {
99
                case 'init':
100
             ?>
101
<div id="help_init" class="alert alert-info" style="display:<?php echo $display?>">
102
    <h3><?php echo $this->getText('help_reference_title'); ?></h3>
103
    <p>
104
                       <?php
105
                       echo '<ul>'.$this->getText('help_init_reference').'</ul>';
106
                       ?>
107
    </p>
108
    </div>
109
                    <?php
110
                    break;
111
                    case 'create':
112
                        ?>
113
                        <div id="help_create" class="alert alert-info" style="display:<?php echo $display?>">
114
                            <h3><?php echo $this->getText('help_create_reference_title'); ?></h3>
115
                        <?php
116
                        echo '<ul>'.$this->getText('help_create_reference').'</ul>';
117
                        ?>
118
                        </div>
119
                        <?php
120
                        break;
121
                    case 'tree':
122
                        ?>
123
                        <div id="help_tree" class="alert alert-info" style="display:<?php echo $display?>">
124
                        <?php
125
                        echo '<ul>'.$this->getText('help_tree').'</ul>';
126
                        ?>
127
                        </div>
128
                        <?php
129
                        break;
130
                    case 'fork':
131
                        ?>
132
                        <div id="help_fork" class="alert alert-info" style="display:<?php echo $display?>">
133
                        <?php
134
                        echo '<ul>'.$this->getText('help_fork').'</ul>';
135
                        ?>
136
                        </div>
137
                        <?php
138
                        break;
139
                default:
140
                    break;
141
            }
142
        }
143
144
    /**
145
     * REPO VIEW
146
     */
147
    public function view() {
148
        $params     = $this->getData();
149
        $repository = $params['repository'];
150
        $request    = $this->controller->getRequest();
151
152
        $index_view = new GitViews_ShowRepo(
153
            $repository,
154
            $this->controller,
0 ignored issues
show
$this->controller of type object<PluginController> is not a sub-type of object<Git>. It seems like you assume a child class of the class PluginController to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
155
            $this->url_manager,
156
            $this->controller->getRequest(),
157
            $params['driver_factory'],
158
            $params['gerrit_usermanager'],
159
            $params['gerrit_servers'],
160
            $this->mirror_data_mapper
161
        );
162
        $index_view->display();
163
    }
164
165
    /**
166
     * REPOSITORY MANAGEMENT VIEW
167
     */
168
    public function repoManagement() {
169
        $params = $this->getData();
170
        $repository   = $params['repository'];
171
172
        echo '<h1>'. $repository->getHTMLLink($this->url_manager) .' - '. $GLOBALS['Language']->getText('global', 'Settings') .'</h1>';
173
        $repo_management_view = new GitViews_RepoManagement(
174
            $repository,
175
            $this->controller->getRequest(),
176
            $params['driver_factory'],
177
            $params['gerrit_servers'],
178
            $params['gerrit_templates'],
179
            $this->mirror_data_mapper
180
        );
181
        $repo_management_view->display();
182
    }
183
184
    /**
185
     * FORK VIEW
186
     */
187
    public function fork() {
188
        $params = $this->getData();
189
        $repository   = $params['repository'];
190
        $repoId       = $repository->getId();
191
        $initialized  = $repository->isInitialized();
192
193
        echo "<h1>". $repository->getHTMLLink($this->url_manager) ."</h1>";
194
        ?>
195
        <form id="repoAction" name="repoAction" method="POST" action="/plugins/git/?group_id=<?php echo $this->groupId?>">
196
        <input type="hidden" id="action" name="action" value="edit" />
197
        <input type="hidden" id="repo_id" name="repo_id" value="<?php echo $repoId?>" />
198
        <?php
199
        if ( $initialized && $this->getController()->isAPermittedAction('clone') ) :
200
        ?>
201
            <p id="plugin_git_fork_form">
202
                <input type="hidden" id="parent_id" name="parent_id" value="<?php echo $repoId?>">
203
                <label for="repo_name"><?php echo $this->getText('admin_fork_creation_input_name');
204
        ?>:     </label>
205
                <input type="text" id="repo_name" name="repo_name" value="" /><input type="submit" class="btn btn-default" name="clone" value="<?php echo $this->getText('admin_fork_creation_submit');?>" />
206
                <a href="#" onclick="$('help_fork').toggle();"> [?]</a>
207
            </p>
208
        </form>
209
        <?php
210
        endif;
211
        $this->help('fork', array('display'=>'none'));
212
    }
213
214
    /**
215
     * CONFIRM PRIVATE
216
     */
217
    public function confirmPrivate() {
218
        $params = $this->getData();
219
        $repository   = $params['repository'];
220
        $repoId       = $repository->getId();
221
        $repoName     = $repository->getName();
222
        $initialized  = $repository->isInitialized();
223
        $mails        = $params['mails'];
224
        if ( $this->getController()->isAPermittedAction('save') ) :
225
        ?>
226
        <div class="confirm">
227
        <h3><?php echo $this->getText('set_private_confirm'); ?></h3>
228
        <form id="confirm_private" method="POST" action="/plugins/git/?group_id=<?php echo $this->groupId; ?>" >
229
        <input type="hidden" id="action" name="action" value="set_private" />
230
        <input type="hidden" id="repo_id" name="repo_id" value="<?php echo $repoId; ?>" />
231
        <input type="submit" id="submit" name="submit" value="<?php echo $this->getText('yes') ?>"/><span><input type="button" value="<?php echo $this->getText('no')?>" onclick="window.location='/plugins/git/?action=view&group_id=<?php echo $this->groupId;?>&repo_id=<?php echo $repoId?>'"/> </span>
232
        </form>
233
        <h3><?php echo $this->getText('set_private_mails'); ?></h3>
234
    <table>
235
        <?php
236
        $i = 0;
237
        foreach ($mails as $mail) {
238
            echo '<tr class="'.html_get_alt_row_color(++$i).'">';
239
            echo '<td>'.$mail.'</td>';
240
            echo '</tr>';
241
        }
242
        ?>
243
    </table>
244
    </div>
245
        <?php
246
        endif;
247
    }
248
249
    /**
250
     * TREE VIEW
251
     */
252
    public function index() {
253
        $params = $this->getData();
254
255
        $this->_tree($params);
256
        if ( $this->getController()->isAPermittedAction('add') ) {
257
            $this->_createForm();
258
        }
259
    }
260
261
    /**
262
     * CREATE REF FORM
263
     */
264
    protected function _createForm() {
265
        $user = UserManager::instance()->getCurrentUser();
266
        ?>
267
<h2><?php echo $this->getText('admin_reference_creation_title');
268
        ?> <a href="#" onclick="$('help_create').toggle();$('help_init').toggle()"><i class="icon-question-sign"></i></a></h2>
269
<form id="addRepository" action="/plugins/git/?group_id=<?php echo $this->groupId ?>" method="POST" class="form-inline">
270
    <input type="hidden" id="action" name="action" value="add" />
271
272
    <label for="repo_name"><?= $this->getText('admin_reference_creation_input_name'); ?></label>
273
    <input id="repo_name" name="repo_name" class="" type="text" value=""/>
274
275
    <input type="submit" id="repo_add" name="repo_add" value="<?php echo $this->getText('admin_reference_creation_submit')?>" class="btn btn-primary">
276
</form>
277
        <?php
278
        $this->help('create', array('display'=>'none')) ;
279
        $this->help('init', array('display'=>'none')) ;
280
    }
281
282
    /**
283
     * @todo several cases ssh, http ...
284
     * @param <type> $repositoryName
0 ignored issues
show
The doc-type <type> could not be parsed: Unknown type name "<" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
285
     * @return <type>
0 ignored issues
show
The doc-type <type> could not be parsed: Unknown type name "<" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
286
     */
287
    protected function _getRepositoryUrl($repositoryName) {
288
        $serverName  = $_SERVER['SERVER_NAME'];
289
        return  $this->userName.'@'.$serverName.':/gitroot/'.$this->projectName.'/'.$repositoryName.'.git';
290
    }
291
292
    protected function forkRepositories() {
293
        $params = $this->getData();
294
295
        echo '<h1>'. $this->getText('fork_repositories') .'</h1>';
296
        if ($this->user->isMember($this->groupId)) {
297
            echo $this->getText('fork_personal_repositories_desc');
298
        }
299
        echo $this->getText('fork_project_repositories_desc');
300
        if ( !empty($params['repository_list']) ) {
301
            echo '<form action="" method="POST">';
302
            echo '<input type="hidden" name="group_id" value="'. (int)$this->groupId .'" />';
303
            echo '<input type="hidden" name="action" value="fork_repositories_permissions" />';
304
            $token = new CSRFSynchronizerToken('/plugins/git/?group_id='. (int)$this->groupId .'&action=fork_repositories');
305
            echo $token->fetchHTMLInput();
306
307
            echo '<table id="fork_repositories" cellspacing="0">';
308
            echo '<thead>';
309
            echo '<tr valign="top">';
310
            echo '<td class="first">';
311
            echo '<label style="font-weight: bold;">'. $this->getText('fork_repositories_select') .'</label>';
312
            echo '</td>';
313
            echo '<td>';
314
            echo '<label style="font-weight: bold;">'. $this->getText('fork_destination_project') .'</label>';
315
            echo '</td>';
316
            echo '<td>';
317
            echo '<label style="font-weight: bold;">'. $this->getText('fork_repositories_path') .'</label>';
318
            echo '</td>';
319
            echo '<td class="last">&nbsp;</td>';
320
            echo '</tr>';
321
            echo '</thead>';
322
323
            echo '<tbody><tr valign="top">';
324
            echo '<td class="first">';
325
            $strategy = new GitViewsRepositoriesTraversalStrategy_Selectbox($this);
326
            echo $strategy->fetch($params['repository_list'], $this->user);
327
            echo '</td>';
328
329
            echo '<td>';
330
            $options = ' disabled="true" ';
331
            if ($this->user->isMember($this->groupId)) {
332
                $options = ' checked="true" ';
333
            }
334
            echo '<div>
335
                <input id="choose_personal" type="radio" name="choose_destination" value="'. Git::SCOPE_PERSONAL .'" '.$options.' />
336
                <label class="radio" for="choose_personal">'.$this->getText('fork_choose_destination_personal').'</label>
337
            </div>';
338
339
            echo $this->fetchCopyToAnotherProject();
340
341
            echo '</td>';
342
343
            echo '<td>';
344
            $placeholder = $this->getText('fork_repositories_placeholder');
345
            echo '<input type="text" title="'. $placeholder .'" placeholder="'. $placeholder .'" id="fork_repositories_path" name="path" />';
346
            echo '<input type="hidden" id="fork_repositories_prefix" value="u/'. $this->user->getName() .'" />';
347
            echo '</td>';
348
349
            echo '<td class="last">';
350
            echo '<input type="submit" class="btn btn-primary" value="'. $this->getText('fork_repositories') .'" />';
351
            echo '</td>';
352
353
            echo '</tr></tbody></table>';
354
355
            echo '</form>';
356
        }
357
        echo '<br />';
358
    }
359
360
    protected function adminGitAdminsView($are_mirrors_defined) {
361
        $params = $this->getData();
362
363
        $presenter = new GitPresenters_AdminGitAdminsPresenter(
364
            $this->groupId,
365
            $are_mirrors_defined,
366
            $this->ugroup_manager->getStaticUGroups($this->project),
367
            $this->git_permissions_manager->getCurrentGitAdminUgroups($this->project->getId())
368
        );
369
370
        $renderer = TemplateRendererFactory::build()->getRenderer(dirname(GIT_BASE_DIR).'/templates');
371
372
        echo $renderer->renderToString('admin', $presenter);
373
    }
374
375
    protected function adminGerritTemplatesView($are_mirrors_defined) {
376
        $params = $this->getData();
377
378
        $repository_list       = (isset($params['repository_list'])) ? $params['repository_list'] : array();
379
        $templates_list        = (isset($params['templates_list'])) ? $params['templates_list'] : array();
380
        $parent_templates_list = (isset($params['parent_templates_list'])) ? $params['parent_templates_list'] : array();
381
382
        $presenter = new GitPresenters_AdminGerritTemplatesPresenter(
383
            $repository_list,
384
            $templates_list,
385
            $parent_templates_list,
386
            $this->groupId,
387
            $are_mirrors_defined,
388
            $params['has_gerrit_servers_set_up']
389
        );
390
391
        $renderer = TemplateRendererFactory::build()->getRenderer(dirname(GIT_BASE_DIR).'/templates');
392
393
        echo $renderer->renderToString('admin', $presenter);
394
    }
395
396
    protected function adminMassUpdateSelectRepositoriesView() {
397
        $params = $this->getData();
398
399
        $repository_list = $this->getGitRepositoryFactory()->getAllRepositories($this->project);
400
        $presenter       = new GitPresenters_AdminMassUpdateSelectRepositoriesPresenter(
401
            $this->generateMassUpdateCSRF(),
402
            $this->groupId,
403
            $repository_list
404
        );
405
406
        $renderer = TemplateRendererFactory::build()->getRenderer(dirname(GIT_BASE_DIR).'/templates');
407
408
        echo $renderer->renderToString('admin', $presenter);
409
    }
410
411
    protected function adminMassUpdateView() {
412
        $params = $this->getData();
413
414
        $repositories = $params['repositories'];
415
        $mirrors      = $this->getAdminMassUpdateMirrorPresenters();
416
        $presenter    = new GitPresenters_AdminMassUpdatePresenter(
417
            $this->generateMassUpdateCSRF(),
418
            $this->groupId,
419
            $this->buildListOfMirroredRepositoriesPresenters(
420
                $repositories,
421
                $mirrors,
422
                $this->mirror_data_mapper->getListOfMirrorIdsPerRepositoryForProject($this->project)
423
            ),
424
            new GitPresenters_AdminMassUdpdateMirroringPresenter($mirrors)
425
        );
426
427
        $renderer = TemplateRendererFactory::build()->getRenderer(dirname(GIT_BASE_DIR).'/templates');
428
429
        echo $renderer->renderToString('admin', $presenter);
430
    }
431
432
    private function buildListOfMirroredRepositoriesPresenters(
433
        array $repositories,
434
        array $mirrors,
435
        array $mirror_ids_per_repository
436
    ) {
437
        $mirrored_repositories_presenters = array();
438
439
        foreach ($repositories as $repository) {
440
            $used_mirrors = array();
441
            foreach ($mirrors as $mirror) {
442
                $is_used = isset($mirror_ids_per_repository[$repository->getId()])
443
                    && in_array($mirror->mirror_id, $mirror_ids_per_repository[$repository->getId()]);
444
445
                $copy_of_mirror = clone $mirror;
446
                $copy_of_mirror->is_used = $is_used;
447
448
                $used_mirrors[] = $copy_of_mirror;
449
            }
450
451
            $mirrored_repositories_presenters[] = new GitPresenters_MirroredRepositoryPresenter(
452
                $repository,
453
                $used_mirrors
454
            );
455
        }
456
457
        return $mirrored_repositories_presenters;
458
    }
459
460
    private function generateMassUpdateCSRF() {
461
        return new CSRFSynchronizerToken('/plugins/git/?group_id='. (int)$this->groupId .'&action=admin-mass-update');
462
    }
463
464
    private function getAdminMassUpdateMirrorPresenters() {
465
        $mirrors           = $this->mirror_data_mapper->fetchAllForProject($this->project);
466
        $mirror_presenters = array();
467
468
        foreach($mirrors as $mirror) {
469
            $mirror_presenters[] = new GitPresenters_MirrorPresenter($mirror, false);
470
        }
471
472
        return $mirror_presenters;
473
    }
474
475
    /**
476
     * Creates form to set permissions when fork repositories is performed
477
     *
478
     * @return void
479
     */
480
    protected function forkRepositoriesPermissions() {
481
        $params = $this->getData();
482
483
484
        if ($params['scope'] == 'project') {
485
            $groupId = $params['group_id'];
486
        } else {
487
            $groupId = (int)$this->groupId;
488
        }
489
        $repositories = explode(',', $params['repos']);
490
        $repository   = $this->getGitRepositoryFactory()->getRepositoryById($repositories[0]);
491
        if (!empty($repository)) {
492
            $forkPermissionsManager = new GitForkPermissionsManager($repository);
493
            $userName               = $this->user->getName();
494
            echo $forkPermissionsManager->displayRepositoriesPermissionsForm($params, $groupId, $userName);
495
        }
496
    }
497
498
    private function getGitRepositoryFactory() {
499
        return new GitRepositoryFactory(new GitDao(), ProjectManager::instance());
500
    }
501
502
    private function fetchCopyToAnotherProject() {
503
        $html = '';
504
        $userProjectOptions = $this->getUserProjectsAsOptions($this->user, ProjectManager::instance(), $this->groupId);
505
        if ($userProjectOptions) {
506
            $options = ' checked="true" ';
507
            if ($this->user->isMember($this->groupId)) {
508
                $options = '';
509
            }
510
            $html .= '<div>
511
            <label class="radio">
512
                <input id="choose_project" type="radio" name="choose_destination" value="project" '.$options.' />
513
                '.$this->getText('fork_choose_destination_project').'</label>
514
            </div>';
515
516
            $html .= '<select name="to_project" id="fork_destination">';
517
            $html .= $userProjectOptions;
518
            $html .= '</select>';
519
        }
520
        return $html;
521
    }
522
523
    public function getUserProjectsAsOptions(PFUser $user, ProjectManager $manager, $currentProjectId) {
524
        $purifier   = Codendi_HTMLPurifier::instance();
525
        $html       = '';
526
        $option     = '<option value="%d" title="%s">%s</option>';
527
        $usrProject = array_diff($user->getAllProjects(), array($currentProjectId));
528
529
        foreach ($usrProject as $projectId) {
530
            $project = $manager->getProject($projectId);
531
            if ($user->isMember($projectId, 'A') && $project->usesService(GitPlugin::SERVICE_SHORTNAME)) {
532
                $projectName     = $project->getPublicName();
533
                $projectUnixName = $purifier->purify($project->getUnixName());
534
                $html           .= sprintf($option, $projectId, $projectUnixName, $projectName);
535
            }
536
        }
537
        return $html;
538
    }
539
540
    /**
541
     * TREE SUBVIEW
542
     */
543
    protected function _tree($params=array()) {
544
        if ( empty($params) ) {
545
            $params = $this->getData();
546
        }
547
        if (!empty($params['repository_list']) || (isset($params['repositories_owners']) && $params['repositories_owners']->rowCount() > 0)) {
548
            echo '<h1>'.$this->getText('tree_title_available_repo').' <a href="#" onclick="$(\'help_tree\').toggle();"><i class="icon-question-sign"></i></a></h1>';
549
            if (isset($params['repositories_owners']) && $params['repositories_owners']->rowCount() > 0) {
550
                $purifier   = Codendi_HTMLPurifier::instance();
551
                $current_id = null;
552
                if (!empty($params['user'])) {
553
                    $current_id = (int)$params['user'];
554
                }
555
                $select = '<select name="user" onchange="this.form.submit()">';
556
                $uh = UserHelper::instance();
557
                $selected = 'selected="selected"';
558
                $select .= '<option value="" '. ($current_id ? '' : $selected) .'>'. $this->getText('tree_title_available_repo') .'</option>';
559
                foreach ($params['repositories_owners'] as $owner) {
560
                    $select .= '<option value="'. (int)$owner['repository_creation_user_id'] .'" '.
561
                        ($owner['repository_creation_user_id'] == $current_id ? $selected : '') .'>'.
562
                        $purifier->purify($uh->getDisplayName($owner['user_name'], $owner['realname'])) .
563
                        '</option>';
564
                }
565
                $select .= '</select>';
566
                echo '<form action="" class="form-tree" method="GET">';
567
                echo '<input type="hidden" name="action" value="index" />';
568
                echo '<input type="hidden" name="group_id" value="'. (int)$this->groupId .'" />';
569
                echo $select;
570
                echo '<noscript><input type="submit" value="'. $GLOBALS['Language']->getText('global', 'btn_submit') .'" /></noscript>';
571
                echo '</form>';
572
            }
573
            $this->help('tree', array('display' => 'none'));
574
575
576
            $lastPushes = array();
577
            $dao = new Git_LogDao();
578
            foreach ($params['repository_list'] as $repository) {
579
                $id  = $repository['repository_id'];
580
                $dar = $dao->searchLastPushForRepository($id);
581
                if ($dar && !$dar->isError() && $dar->rowCount() == 1) {
582
                    $lastPushes[$id] = $dar->getRow();
583
                }
584
            }
585
            $strategy = new GitViewsRepositoriesTraversalStrategy_Tree($lastPushes, $this->url_manager);
586
            echo $strategy->fetch($params['repository_list'], $this->user);
587
        }
588
        else {
589
            echo "<h3>".$this->getText('tree_msg_no_available_repo')."</h3>";
590
        }
591
    }
592
593
    protected function adminDefaultSettings($are_mirrors_defined) {
594
        $mirror_presenters = $this->getMirrorPresentersForGitAdmin();
595
596
        $presenter = new GitPresenters_AdminDefaultSettingsPresenter(
597
            $this->groupId,
598
            $are_mirrors_defined,
599
            $mirror_presenters
600
        );
601
602
        $renderer = TemplateRendererFactory::build()->getRenderer(dirname(GIT_BASE_DIR).'/templates');
603
604
        echo $renderer->renderToString('admin', $presenter);
605
    }
606
607
    private function getMirrorPresentersForGitAdmin() {
608
        $mirrors            = $this->mirror_data_mapper->fetchAllForProject($this->project);
609
        $default_mirror_ids = $this->mirror_data_mapper->getDefaultMirrorIdsForProject($this->project);
610
        $mirror_presenters  = array();
611
612
        foreach ($mirrors as $mirror) {
613
            $is_used = in_array($mirror->id, $default_mirror_ids);
614
615
            $mirror_presenters[] = new GitPresenters_MirrorPresenter($mirror, $is_used);
616
        }
617
618
        return $mirror_presenters;
619
    }
620
}