Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 66
0.00% covered (danger)
0.00%
0 / 14
CRAP
0.00% covered (danger)
0.00%
0 / 1
WebInstallerPage
0.00% covered (danger)
0.00%
0 / 66
0.00% covered (danger)
0.00%
0 / 14
342
0.00% covered (danger)
0.00%
0 / 1
 execute
n/a
0 / 0
n/a
0 / 0
0
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isSlow
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 addHTML
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 startForm
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
 endForm
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 1
30
 getName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getId
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getVar
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setVar
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getFieldsetStart
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getFieldsetEnd
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 startLiveBox
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 endLiveBox
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 inlineScript
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * @license GPL-2.0-or-later
5 * @file
6 * @ingroup Installer
7 */
8
9namespace MediaWiki\Installer;
10
11use MediaWiki\Html\Html;
12
13/**
14 * Abstract class to define pages for the web installer.
15 *
16 * @ingroup Installer
17 * @since 1.17
18 */
19abstract class WebInstallerPage {
20
21    /**
22     * The WebInstaller object this WebInstallerPage belongs to.
23     *
24     * @var WebInstaller
25     */
26    public $parent;
27
28    /**
29     * @return string
30     */
31    abstract public function execute();
32
33    public function __construct( WebInstaller $parent ) {
34        $this->parent = $parent;
35    }
36
37    /**
38     * Is this a slow-running page in the installer? If so, WebInstaller will
39     * set_time_limit(0) before calling execute(). Right now this only applies
40     * to Install and Upgrade pages
41     *
42     * @return bool Always false in this default implementation.
43     */
44    public function isSlow() {
45        return false;
46    }
47
48    /**
49     * @param string $html
50     */
51    public function addHTML( $html ) {
52        $this->parent->output->addHTML( $html );
53    }
54
55    public function startForm() {
56        $this->addHTML(
57            "<div class=\"config-section\">\n" .
58            Html::openElement(
59                'form',
60                [
61                    'method' => 'post',
62                    'action' => $this->parent->getUrl( [ 'page' => $this->getName() ] )
63                ]
64            ) . "\n"
65        );
66    }
67
68    /**
69     * @param string|bool $continue
70     * @param string|bool $back
71     */
72    public function endForm( $continue = 'continue', $back = 'back' ) {
73        $s = "<div class=\"config-submit\">\n";
74        $id = $this->getId();
75
76        if ( $id === false ) {
77            $s .= Html::hidden( 'lastPage', $this->parent->request->getVal( 'lastPage' ) );
78        }
79
80        if ( $continue ) {
81            // Fake submit button for enter keypress (T28267)
82            // Messages: config-continue, config-restart, config-regenerate
83            $s .= Html::submitButton(
84                wfMessage( "config-$continue" )->text(),
85                [
86                    'name' => "enter-$continue",
87                    'style' => 'width:0;border:0;height:0;padding:0'
88                ]
89            ) . "\n";
90        }
91
92        if ( $back ) {
93            // Message: config-back
94            $s .= Html::submitButton(
95                wfMessage( "config-$back" )->text(),
96                [
97                    'name' => "submit-$back",
98                    'tabindex' => $this->parent->nextTabIndex(),
99                    'class' => [ 'cdx-button', 'cdx-button--action-default' ]
100                ]
101            ) . "\n";
102        }
103
104        if ( $continue ) {
105            // Messages: config-continue, config-restart, config-regenerate
106            $s .= Html::submitButton(
107                wfMessage( "config-$continue" )->text(),
108                [
109                    'name' => "submit-$continue",
110                    'tabindex' => $this->parent->nextTabIndex(),
111                    'class' => [ 'cdx-button', 'cdx-button--action-progressive' ]
112                ]
113            ) . "\n";
114        }
115
116        $s .= "</div></form></div>\n";
117        $this->addHTML( $s );
118    }
119
120    /**
121     * @return string
122     */
123    public function getName() {
124        return str_replace( 'MediaWiki\\Installer\\WebInstaller', '', static::class );
125    }
126
127    /**
128     * @return string
129     */
130    protected function getId() {
131        return array_search( $this->getName(), $this->parent->pageSequence );
132    }
133
134    /**
135     * @param string $var
136     * @param mixed|null $default
137     *
138     * @return mixed
139     */
140    public function getVar( $var, $default = null ) {
141        return $this->parent->getVar( $var, $default );
142    }
143
144    /**
145     * @param string $name
146     * @param mixed $value
147     */
148    public function setVar( $name, $value ) {
149        $this->parent->setVar( $name, $value );
150    }
151
152    /**
153     * Get the starting tags of a fieldset.
154     *
155     * @param string $legend Message name
156     *
157     * @return string
158     */
159    protected function getFieldsetStart( $legend ) {
160        return "\n<div class=\"cdx-card\"><div class=\"cdx-card__text\"><div class=\"cdx-card__text__title\">" .
161            wfMessage( $legend )->escaped() . "</div><div class=\"cdx-card__text__description\">\n";
162    }
163
164    /**
165     * Get the end tag of a fieldset.
166     *
167     * @return string
168     */
169    protected function getFieldsetEnd() {
170        return "</div></div></div>\n";
171    }
172
173    /**
174     * Opens a textarea used to display the progress of a long operation
175     */
176    protected function startLiveBox() {
177        $this->addHTML(
178            '<div id="config-spinner" style="display:none;">' .
179            '<img src="images/ajax-loader.gif" /></div>' .
180            $this->inlineScript( 'jQuery( "#config-spinner" ).show();' ) .
181            '<div id="config-live-log">' .
182            '<textarea name="LiveLog" rows="10" cols="30" readonly="readonly">'
183        );
184        $this->parent->output->flush();
185    }
186
187    /**
188     * Opposite to WebInstallerPage::startLiveBox
189     */
190    protected function endLiveBox() {
191        $this->addHTML(
192            '</textarea></div>' .
193            $this->inlineScript( 'jQuery( "#config-spinner" ).hide()' )
194        );
195        $this->parent->output->flush();
196    }
197
198    /**
199     * Javascript to include inline. Handles addings CSP nonce.
200     *
201     * @since 1.45
202     * @param string $script Script, not including <script> tag
203     * @return string HTML to output
204     */
205    protected function inlineScript( $script ) {
206        return Html::inlineScript( $script, $this->parent->output->getCSPNonce() );
207    }
208}