Update git submodules
[mediawiki.git] / includes / installer / WebInstallerPage.php
blob8c0a84c9f7d4bad2d4e909445bf90390375e05b0
1 <?php
2 /**
3 * Base code for web installer pages.
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.
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.
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
20 * @file
21 * @ingroup Installer
24 use MediaWiki\Html\Html;
26 /**
27 * Abstract class to define pages for the web installer.
29 * @ingroup Installer
30 * @since 1.17
32 abstract class WebInstallerPage {
34 /**
35 * The WebInstaller object this WebInstallerPage belongs to.
37 * @var WebInstaller
39 public $parent;
41 /**
42 * @return string
44 abstract public function execute();
46 /**
47 * @param WebInstaller $parent
49 public function __construct( WebInstaller $parent ) {
50 $this->parent = $parent;
53 /**
54 * Is this a slow-running page in the installer? If so, WebInstaller will
55 * set_time_limit(0) before calling execute(). Right now this only applies
56 * to Install and Upgrade pages
58 * @return bool Always false in this default implementation.
60 public function isSlow() {
61 return false;
64 /**
65 * @param string $html
67 public function addHTML( $html ) {
68 $this->parent->output->addHTML( $html );
71 public function startForm() {
72 $this->addHTML(
73 "<div class=\"config-section\">\n" .
74 Html::openElement(
75 'form',
77 'method' => 'post',
78 'action' => $this->parent->getUrl( [ 'page' => $this->getName() ] )
80 ) . "\n"
84 /**
85 * @param string|bool $continue
86 * @param string|bool $back
88 public function endForm( $continue = 'continue', $back = 'back' ) {
89 $s = "<div class=\"config-submit\">\n";
90 $id = $this->getId();
92 if ( $id === false ) {
93 $s .= Html::hidden( 'lastPage', $this->parent->request->getVal( 'lastPage' ) );
96 if ( $continue ) {
97 // Fake submit button for enter keypress (T28267)
98 // Messages: config-continue, config-restart, config-regenerate
99 $s .= Xml::submitButton(
100 wfMessage( "config-$continue" )->text(),
102 'name' => "enter-$continue",
103 'style' => 'width:0;border:0;height:0;padding:0'
105 ) . "\n";
108 if ( $back ) {
109 // Message: config-back
110 $s .= Xml::submitButton(
111 wfMessage( "config-$back" )->text(),
113 'name' => "submit-$back",
114 'tabindex' => $this->parent->nextTabIndex()
116 ) . "\n";
119 if ( $continue ) {
120 // Messages: config-continue, config-restart, config-regenerate
121 $s .= Xml::submitButton(
122 wfMessage( "config-$continue" )->text(),
124 'name' => "submit-$continue",
125 'tabindex' => $this->parent->nextTabIndex(),
127 ) . "\n";
130 $s .= "</div></form></div>\n";
131 $this->addHTML( $s );
135 * @return string
137 public function getName() {
138 return str_replace( 'WebInstaller', '', static::class );
142 * @return string
144 protected function getId() {
145 return array_search( $this->getName(), $this->parent->pageSequence );
149 * @param string $var
150 * @param mixed|null $default
152 * @return mixed
154 public function getVar( $var, $default = null ) {
155 return $this->parent->getVar( $var, $default );
159 * @param string $name
160 * @param mixed $value
162 public function setVar( $name, $value ) {
163 $this->parent->setVar( $name, $value );
167 * Get the starting tags of a fieldset.
169 * @param string $legend Message name
171 * @return string
173 protected function getFieldsetStart( $legend ) {
174 return "\n<fieldset><legend>" . wfMessage( $legend )->escaped() . "</legend>\n";
178 * Get the end tag of a fieldset.
180 * @return string
182 protected function getFieldsetEnd() {
183 return "</fieldset>\n";
187 * Opens a textarea used to display the progress of a long operation
189 protected function startLiveBox() {
190 $this->addHTML(
191 '<div id="config-spinner" style="display:none;">' .
192 '<img src="images/ajax-loader.gif" /></div>' .
193 '<script>jQuery( "#config-spinner" ).show();</script>' .
194 '<div id="config-live-log">' .
195 '<textarea name="LiveLog" rows="10" cols="30" readonly="readonly">'
197 $this->parent->output->flush();
201 * Opposite to WebInstallerPage::startLiveBox
203 protected function endLiveBox() {
204 $this->addHTML( '</textarea></div>
205 <script>jQuery( "#config-spinner" ).hide()</script>' );
206 $this->parent->output->flush();