Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 82
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
SpecialRecordSpeech
0.00% covered (danger)
0.00%
0 / 82
0.00% covered (danger)
0.00%
0 / 3
12
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
 execute
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
 addElements
0.00% covered (danger)
0.00%
0 / 71
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\WikispeechSpeechDataCollector\Specials;
4
5/**
6 * @file
7 * @ingroup Extensions
8 * @license GPL-2.0-or-later
9 */
10
11use Html;
12use OOUI\ButtonWidget;
13use OOUI\FieldLayout;
14use OOUI\FieldsetLayout;
15use OOUI\HorizontalLayout;
16use OOUI\HtmlSnippet;
17use OOUI\LabelWidget;
18use OOUI\MultilineTextInputWidget;
19use OOUI\Widget;
20use SpecialPage;
21
22/**
23 * Special page for recording speech.
24 *
25 * Presents the user with a prompt to read and controls for recording,
26 * reviewing and saving.
27 *
28 * @since 0.1.0
29 */
30
31class SpecialRecordSpeech extends SpecialPage {
32
33    /**
34     * @since 0.1.0
35     */
36    public function __construct() {
37        parent::__construct( 'RecordSpeech' );
38    }
39
40    /**
41     * @since 0.1.0
42     * @param string|null $subpage
43     */
44    public function execute( $subpage ) {
45        $out = $this->getOutput();
46
47        $out->addModuleStyles( [
48            'ext.wikispeech-sdc.specialRecordSpeech.styles'
49        ] );
50        $out->addModules( [
51            'ext.wikispeech-sdc.specialRecordSpeech'
52        ] );
53        $out->enableOOUI();
54        $out->setPageTitle( $this->msg( 'recordspeech' ) );
55        $this->addElements();
56    }
57
58    /**
59     * Add UI elements.
60     *
61     * @since 0.1.0
62     */
63    private function addElements() {
64        // Add a text box for the prompt.
65        $promptField = new FieldLayout(
66            new MultilineTextInputWidget( [
67                'classes' => [
68                    'ext-wikispeech-sdc-record-prompt',
69                ],
70                'readOnly' => true,
71                'rows' => 5
72            ] )
73        );
74
75        // Button for starting recording and status label.
76        $recordButton = new ButtonWidget( [
77            'label' => $this->msg( 'wikispeech-sdc-record' )->text(),
78            'flags' => [
79                'primary',
80                'progressive'
81            ],
82            'classes' => [ 'ext-wikispeech-sdc-record' ],
83            'infusable' => true,
84            'disabled' => true
85        ] );
86        $recordStatus = new LabelWidget( [
87            'label' => $this->msg( 'wikispeech-sdc-status-starting' )->text(),
88            'classes' => [ 'ext-wikispeech-sdc-status' ],
89            'infusable' => true
90        ] );
91        $recordField = new FieldLayout(
92            new Widget( [
93                'content' => new HorizontalLayout( [
94                    'items' => [ $recordButton, $recordStatus ]
95                ] )
96            ] )
97        );
98
99        // Preview player.
100        $playerHtml = Html::element(
101            'audio',
102            $attribs = [
103                'class' => 'ext-wikispeech-sdc-preview-player',
104                'controls'
105            ]
106        );
107        $previewPlayer = new FieldLayout(
108            new Widget( [
109                'content' => new HtmlSnippet( $playerHtml )
110            ] )
111        );
112
113        // Save recording to storage.
114        $saveButton = new ButtonWidget( [
115            'label' => $this->msg( 'wikispeech-sdc-save' )->text(),
116            'flags' => [ 'progressive' ]
117        ] );
118
119        // Skip the prompt without saving.
120        $skipButton = new ButtonWidget( [
121            'label' => $this->msg( 'wikispeech-sdc-skip' )->text(),
122            'flags' => [ 'destructive' ]
123        ] );
124
125        $actionButtons = new FieldLayout(
126            new Widget( [
127                'content' => new HorizontalLayout( [
128                    'items' => [
129                        $saveButton,
130                        $skipButton
131                    ]
132                ] )
133            ] )
134        );
135
136        $this->getOutput()->addHTML(
137            new FieldsetLayout( [
138                'items' => [
139                    $promptField,
140                    $recordField,
141                    $previewPlayer,
142                    $actionButtons
143                ]
144            ] )
145        );
146    }
147}