Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 40 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
CodeRepoListView | |
0.00% |
0 / 40 |
|
0.00% |
0 / 2 |
110 | |
0.00% |
0 / 1 |
execute | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
30 | |||
getNavItem | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
30 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\CodeReview\UI; |
4 | |
5 | use MediaWiki\Extension\CodeReview\Backend\CodeRepository; |
6 | use MediaWiki\MediaWikiServices; |
7 | use RequestContext; |
8 | use SpecialPage; |
9 | use User; |
10 | |
11 | /** |
12 | * Class for showing the list of repositories, if none was specified |
13 | */ |
14 | class CodeRepoListView { |
15 | public function execute() { |
16 | global $wgOut; |
17 | $repos = CodeRepository::getRepoList(); |
18 | $user = RequestContext::getMain()->getUser(); |
19 | $services = MediaWikiServices::getInstance(); |
20 | $groupPermissionsLookup = $services->getGroupPermissionsLookup(); |
21 | if ( !count( $repos ) ) { |
22 | $wgOut->addWikiMsg( 'code-no-repo' ); |
23 | |
24 | if ( $user->isAllowed( 'repoadmin' ) ) { |
25 | $wgOut->addWikiMsg( 'code-create-repo' ); |
26 | } else { |
27 | $wgOut->addWikiMsg( 'code-need-repoadmin-rights' ); |
28 | |
29 | if ( !count( $groupPermissionsLookup->getGroupsWithPermission( 'repoadmin' ) ) ) { |
30 | $wgOut->addWikiMsg( 'code-need-group-with-rights' ); |
31 | } |
32 | } |
33 | return; |
34 | } |
35 | $text = ''; |
36 | foreach ( $repos as $repo ) { |
37 | $text .= '* ' . self::getNavItem( $repo, $user ) . "\n"; |
38 | } |
39 | $wgOut->addWikiTextAsInterface( $text ); |
40 | } |
41 | |
42 | /** |
43 | * @param CodeRepository $repo |
44 | * @param User $user |
45 | * @return string |
46 | */ |
47 | public static function getNavItem( $repo, User $user ) { |
48 | global $wgLang; |
49 | $name = $repo->getName(); |
50 | |
51 | $code = SpecialPage::getTitleFor( 'Code', $name ); |
52 | $links = []; |
53 | $links[] = "[[$code/comments|" . wfMessage( 'code-notes' )->escaped() . ']]'; |
54 | $links[] = "[[$code/statuschanges|" . wfMessage( 'code-statuschanges' )->escaped() . ']]'; |
55 | if ( $user->getId() ) { |
56 | $author = $repo->wikiUserAuthor( $user->getName() ); |
57 | if ( $author !== false ) { |
58 | $links[] = "[[$code/author/$author|" . wfMessage( 'code-mycommits' )->escaped() . ']]'; |
59 | } |
60 | } |
61 | |
62 | if ( $user->isAllowed( 'codereview-post-comment' ) ) { |
63 | $userName = $user->getName(); |
64 | $links[] = "[[$code/comments/author/$userName|" . wfMessage( 'code-mycomments' )->escaped() . |
65 | ']]'; |
66 | } |
67 | |
68 | $links[] = "[[$code/tag|" . wfMessage( 'code-tags' )->escaped() . ']]'; |
69 | $links[] = "[[$code/author|" . wfMessage( 'code-authors' )->escaped() . ']]'; |
70 | $links[] = "[[$code/status|" . wfMessage( 'code-status' )->escaped() . ']]'; |
71 | $links[] = "[[$code/releasenotes|" . wfMessage( 'code-releasenotes' )->escaped() . ']]'; |
72 | $links[] = "[[$code/stats|" . wfMessage( 'code-stats' )->escaped() . ']]'; |
73 | if ( $user->isAllowed( 'repoadmin' ) ) { |
74 | $links[] = "[[Special:RepoAdmin/$name|" . wfMessage( 'repoadmin-nav' )->escaped() . ']]'; |
75 | } |
76 | return "'''[[$code|$name]]''' " . |
77 | wfMessage( 'parentheses', $wgLang->pipeList( $links ) )->text(); |
78 | } |
79 | } |