Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 72 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
RepoAdminRepoView | |
0.00% |
0 / 72 |
|
0.00% |
0 / 2 |
72 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 68 |
|
0.00% |
0 / 1 |
56 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\CodeReview\UI; |
4 | |
5 | use HTMLForm; |
6 | use MediaWiki\Extension\CodeReview\Backend\CodeRepository; |
7 | use Title; |
8 | use User; |
9 | |
10 | /** |
11 | * View for editing a single repository |
12 | */ |
13 | class RepoAdminRepoView { |
14 | /** |
15 | * Reference to Special:RepoAdmin |
16 | * @var Title |
17 | */ |
18 | private $title; |
19 | |
20 | /** |
21 | * Human-readable name of the repository |
22 | * @var string |
23 | */ |
24 | private $repoName; |
25 | |
26 | /** |
27 | * Actual repository object |
28 | * @var CodeRepository |
29 | */ |
30 | private $repo; |
31 | |
32 | /** |
33 | * @var User |
34 | */ |
35 | private $user; |
36 | |
37 | /** |
38 | * @param Title $t Special page title (with repo subpage) |
39 | * @param string $repo |
40 | * @param User $user |
41 | */ |
42 | public function __construct( Title $t, $repo, $user ) { |
43 | $this->title = $t; |
44 | $this->repoName = $repo; |
45 | $this->repo = CodeRepository::newFromName( $repo ); |
46 | $this->user = $user; |
47 | } |
48 | |
49 | public function execute() { |
50 | global $wgOut, $wgRequest; |
51 | $repoExists = (bool)$this->repo; |
52 | $repoPath = $wgRequest->getVal( 'wpRepoPath', $repoExists ? $this->repo->getPath() : '' ); |
53 | $bugPath = $wgRequest->getVal( 'wpBugPath', |
54 | $repoExists ? $this->repo->getBugzillaBase() : '' ); |
55 | $viewPath = $wgRequest->getVal( 'wpViewPath', |
56 | $repoExists ? $this->repo->getViewVcBase() : '' ); |
57 | if ( $wgRequest->wasPosted() |
58 | && $this->user->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $this->repoName ) |
59 | ) { |
60 | // @todo log |
61 | $dbw = wfGetDB( DB_PRIMARY ); |
62 | if ( $repoExists ) { |
63 | $dbw->update( |
64 | 'code_repo', |
65 | [ |
66 | 'repo_path' => $repoPath, |
67 | 'repo_viewvc' => $viewPath, |
68 | 'repo_bugzilla' => $bugPath |
69 | ], |
70 | [ 'repo_id' => $this->repo->getId() ], |
71 | __METHOD__ |
72 | ); |
73 | } else { |
74 | $dbw->insert( |
75 | 'code_repo', |
76 | [ |
77 | 'repo_name' => $this->repoName, |
78 | 'repo_path' => $repoPath, |
79 | 'repo_viewvc' => $viewPath, |
80 | 'repo_bugzilla' => $bugPath |
81 | ], |
82 | __METHOD__ |
83 | ); |
84 | } |
85 | $wgOut->wrapWikiMsg( '<div class="successbox">$1</div>', |
86 | [ 'repoadmin-edit-sucess', $this->repoName ] ); |
87 | return; |
88 | } |
89 | $formDescriptor = [ |
90 | 'repoadmin-edit-path' => [ |
91 | 'type' => 'text', |
92 | 'name' => 'wpRepoPath', |
93 | 'size' => 60, |
94 | 'default' => $repoPath, |
95 | 'dir' => 'ltr', |
96 | 'label-message' => 'repoadmin-edit-path' |
97 | ], |
98 | 'repoadmin-edit-bug' => [ |
99 | 'type' => 'text', |
100 | 'name' => 'wpBugPath', |
101 | 'size' => 60, |
102 | 'default' => $bugPath, |
103 | 'dir' => 'ltr', |
104 | 'label-message' => 'repoadmin-edit-bug' |
105 | ], |
106 | 'repoadmin-edit-view' => [ |
107 | 'type' => 'text', |
108 | 'name' => 'wpViewPath', |
109 | 'size' => 60, |
110 | 'default' => $viewPath, |
111 | 'dir' => 'ltr', |
112 | 'label-message' => 'repoadmin-edit-view' |
113 | ] |
114 | ]; |
115 | |
116 | $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $wgOut->getContext() ); |
117 | $htmlForm |
118 | ->setTitle( $this->title ) |
119 | ->setTokenSalt( $this->repoName ) |
120 | ->setSubmitTextMsg( 'repoadmin-edit-button' ) |
121 | ->setWrapperLegend( wfMessage( 'repoadmin-edit-legend', $this->repoName )->text() ) |
122 | ->prepareForm() |
123 | ->displayForm( false ); |
124 | } |
125 | } |