Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
RepoAdminListView
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 3
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getForm
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3namespace MediaWiki\Extension\CodeReview\UI;
4
5use HTMLForm;
6use MediaWiki\Extension\CodeReview\Backend\CodeRepository;
7use OutputPage;
8use Title;
9
10/**
11 * View for viewing all of the repositories
12 */
13class RepoAdminListView {
14    /**
15     * Reference to Special:RepoAdmin
16     * @var Title
17     */
18    private $title;
19
20    /**
21     * @param Title $t Title object referring to Special:RepoAdmin
22     */
23    public function __construct( Title $t ) {
24        $this->title = $t;
25    }
26
27    /**
28     * Get "create new repo" form
29     * @param OutputPage $output
30     * @return string
31     */
32    private function getForm( OutputPage $output ) {
33        global $wgScript;
34
35        $formDescriptor = [
36            'repoadmin-label' => [
37                'type' => 'text',
38                'name' => 'repo',
39                'label-message' => 'repoadmin-new-label',
40                'id' => 'repo'
41            ]
42        ];
43
44        $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $output->getContext() );
45        $htmlForm
46            ->addHiddenField( 'title', $this->title->getPrefixedDBKey() )
47            ->setAction( $wgScript )
48            ->setMethod( 'get' )
49            ->setSubmitTextMsg( 'repoadmin-new-button' )
50            ->setWrapperLegendMsg( 'repoadmin-new-legend' )
51            ->prepareForm()
52            ->displayForm( false );
53
54        return true;
55    }
56
57    public function execute() {
58        global $wgOut;
59
60        // Todo inject instead of accessing the global
61        $output = $wgOut;
62
63        $this->getForm( $output );
64        $repos = CodeRepository::getRepoList();
65        if ( !count( $repos ) ) {
66            return;
67        }
68        $text = '';
69        foreach ( $repos as $repo ) {
70            $name = $repo->getName();
71            $text .= "* [[Special:RepoAdmin/$name|$name]]\n";
72        }
73        $output->addWikiTextAsInterface( $text );
74    }
75}