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