Debian Codegraph @

includes/installer/WebInstallerPage.php

raw symbols SCIP
1 <?php
2
3 /**
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
18 *
19 * @file
20 * @ingroup Installer
21 */
22
23 namespace MediaWiki\Installer;
24
25 use MediaWiki\Html\Html;
26 use MediaWiki\Xml\Xml;
27
28 /**
29 * Abstract class to define pages for the web installer.
30 *
31 * @ingroup Installer
32 * @since 1.17
33 */
34 abstract class WebInstallerPage {
35
36 /**
37 * The WebInstaller object this WebInstallerPage belongs to.
38 *
39 * @var WebInstaller
40 */
41 public $parent;
42
43 /**
44 * @return string
45 */
46 abstract public function execute();
47
48 /**
49 * @param WebInstaller $parent
50 */
51 public function __construct( WebInstaller $parent ) {
52 $this->parent = $parent;
53 }
54
55 /**
56 * Is this a slow-running page in the installer? If so, WebInstaller will
57 * set_time_limit(0) before calling execute(). Right now this only applies
58 * to Install and Upgrade pages
59 *
60 * @return bool Always false in this default implementation.
61 */
62 public function isSlow() {
63 return false;
64 }
65
66 /**
67 * @param string $html
68 */
69 public function addHTML( $html ) {
70 $this->parent->output->addHTML( $html );
71 }
72
73 public function startForm() {
74 $this->addHTML(
75 "<div class=\"config-section\">\n" .
76 Html::openElement(
77 'form',
78 [
79 'method' => 'post',
80 'action' => $this->parent->getUrl( [ 'page' => $this->getName() ] )
81 ]
82 ) . "\n"
83 );
84 }
85
86 /**
87 * @param string|bool $continue
88 * @param string|bool $back
89 */
90 public function endForm( $continue = 'continue', $back = 'back' ) {
91 $s = "<div class=\"config-submit\">\n";
92 $id = $this->getId();
93
94 if ( $id === false ) {
95 $s .= Html::hidden( 'lastPage', $this->parent->request->getVal( 'lastPage' ) );
96 }
97
98 if ( $continue ) {
99 // Fake submit button for enter keypress (T28267)
100 // Messages: config-continue, config-restart, config-regenerate
101 $s .= Xml::submitButton(
102 wfMessage( "config-$continue" )->text(),
103 [
104 'name' => "enter-$continue",
105 'style' => 'width:0;border:0;height:0;padding:0'
106 ]
107 ) . "\n";
108 }
109
110 if ( $back ) {
111 // Message: config-back
112 $s .= Xml::submitButton(
113 wfMessage( "config-$back" )->text(),
114 [
115 'name' => "submit-$back",
116 'tabindex' => $this->parent->nextTabIndex(),
117 'class' => 'cdx-button cdx-button--action-destructive'
118 ]
119 ) . "\n";
120 }
121
122 if ( $continue ) {
123 // Messages: config-continue, config-restart, config-regenerate
124 $s .= Xml::submitButton(
125 wfMessage( "config-$continue" )->text(),
126 [
127 'name' => "submit-$continue",
128 'tabindex' => $this->parent->nextTabIndex(),
129 'class' => 'cdx-button cdx-button--action-progressive'
130 ]
131 ) . "\n";
132 }
133
134 $s .= "</div></form></div>\n";
135 $this->addHTML( $s );
136 }
137
138 /**
139 * @return string
140 */
141 public function getName() {
142 return str_replace( 'MediaWiki\\Installer\\WebInstaller', '', static::class );
143 }
144
145 /**
146 * @return string
147 */
148 protected function getId() {
149 return array_search( $this->getName(), $this->parent->pageSequence );
150 }
151
152 /**
153 * @param string $var
154 * @param mixed|null $default
155 *
156 * @return mixed
157 */
158 public function getVar( $var, $default = null ) {
159 return $this->parent->getVar( $var, $default );
160 }
161
162 /**
163 * @param string $name
164 * @param mixed $value
165 */
166 public function setVar( $name, $value ) {
167 $this->parent->setVar( $name, $value );
168 }
169
170 /**
171 * Get the starting tags of a fieldset.
172 *
173 * @param string $legend Message name
174 *
175 * @return string
176 */
177 protected function getFieldsetStart( $legend ) {
178 return "\n<span class=\"cdx-card\"><span class=\"cdx-card__text\"><span class=\"cdx-card__text__title\">" .
179 wfMessage( $legend )->escaped() . "</span><span class=\"cdx-card__text__description\">\n";
180 }
181
182 /**
183 * Get the end tag of a fieldset.
184 *
185 * @return string
186 */
187 protected function getFieldsetEnd() {
188 return "</span></span></span>\n";
189 }
190
191 /**
192 * Opens a textarea used to display the progress of a long operation
193 */
194 protected function startLiveBox() {
195 $this->addHTML(
196 '<div id="config-spinner" style="display:none;">' .
197 '<img src="images/ajax-loader.gif" /></div>' .
198 '<script>jQuery( "#config-spinner" ).show();</script>' .
199 '<div id="config-live-log">' .
200 '<textarea name="LiveLog" rows="10" cols="30" readonly="readonly">'
201 );
202 $this->parent->output->flush();
203 }
204
205 /**
206 * Opposite to WebInstallerPage::startLiveBox
207 */
208 protected function endLiveBox() {
209 $this->addHTML( '</textarea></div>
210 <script>jQuery( "#config-spinner" ).hide()</script>' );
211 $this->parent->output->flush();
212 }
213
214 }