WebInstallerPage.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. * Abstract class to define pages for the web installer.
  25. *
  26. * @ingroup Deployment
  27. * @since 1.17
  28. */
  29. abstract class WebInstallerPage {
  30. /**
  31. * The WebInstaller object this WebInstallerPage belongs to.
  32. *
  33. * @var WebInstaller
  34. */
  35. public $parent;
  36. /**
  37. * @return string
  38. */
  39. abstract public function execute();
  40. /**
  41. * @param WebInstaller $parent
  42. */
  43. public function __construct( WebInstaller $parent ) {
  44. $this->parent = $parent;
  45. }
  46. /**
  47. * Is this a slow-running page in the installer? If so, WebInstaller will
  48. * set_time_limit(0) before calling execute(). Right now this only applies
  49. * to Install and Upgrade pages
  50. *
  51. * @return bool Always false in this default implementation.
  52. */
  53. public function isSlow() {
  54. return false;
  55. }
  56. /**
  57. * @param string $html
  58. */
  59. public function addHTML( $html ) {
  60. $this->parent->output->addHTML( $html );
  61. }
  62. public function startForm() {
  63. $this->addHTML(
  64. "<div class=\"config-section\">\n" .
  65. Html::openElement(
  66. 'form',
  67. [
  68. 'method' => 'post',
  69. 'action' => $this->parent->getUrl( [ 'page' => $this->getName() ] )
  70. ]
  71. ) . "\n"
  72. );
  73. }
  74. /**
  75. * @param string|bool $continue
  76. * @param string|bool $back
  77. */
  78. public function endForm( $continue = 'continue', $back = 'back' ) {
  79. $s = "<div class=\"config-submit\">\n";
  80. $id = $this->getId();
  81. if ( $id === false ) {
  82. $s .= Html::hidden( 'lastPage', $this->parent->request->getVal( 'lastPage' ) );
  83. }
  84. if ( $continue ) {
  85. // Fake submit button for enter keypress (T28267)
  86. // Messages: config-continue, config-restart, config-regenerate
  87. $s .= Xml::submitButton(
  88. wfMessage( "config-$continue" )->text(),
  89. [
  90. 'name' => "enter-$continue",
  91. 'style' => 'width:0;border:0;height:0;padding:0'
  92. ]
  93. ) . "\n";
  94. }
  95. if ( $back ) {
  96. // Message: config-back
  97. $s .= Xml::submitButton(
  98. wfMessage( "config-$back" )->text(),
  99. [
  100. 'name' => "submit-$back",
  101. 'tabindex' => $this->parent->nextTabIndex()
  102. ]
  103. ) . "\n";
  104. }
  105. if ( $continue ) {
  106. // Messages: config-continue, config-restart, config-regenerate
  107. $s .= Xml::submitButton(
  108. wfMessage( "config-$continue" )->text(),
  109. [
  110. 'name' => "submit-$continue",
  111. 'tabindex' => $this->parent->nextTabIndex(),
  112. ]
  113. ) . "\n";
  114. }
  115. $s .= "</div></form></div>\n";
  116. $this->addHTML( $s );
  117. }
  118. /**
  119. * @return string
  120. */
  121. public function getName() {
  122. return str_replace( 'WebInstaller', '', static::class );
  123. }
  124. /**
  125. * @return string
  126. */
  127. protected function getId() {
  128. return array_search( $this->getName(), $this->parent->pageSequence );
  129. }
  130. /**
  131. * @param string $var
  132. * @param mixed|null $default
  133. *
  134. * @return mixed
  135. */
  136. public function getVar( $var, $default = null ) {
  137. return $this->parent->getVar( $var, $default );
  138. }
  139. /**
  140. * @param string $name
  141. * @param mixed $value
  142. */
  143. public function setVar( $name, $value ) {
  144. $this->parent->setVar( $name, $value );
  145. }
  146. /**
  147. * Get the starting tags of a fieldset.
  148. *
  149. * @param string $legend Message name
  150. *
  151. * @return string
  152. */
  153. protected function getFieldsetStart( $legend ) {
  154. return "\n<fieldset><legend>" . wfMessage( $legend )->escaped() . "</legend>\n";
  155. }
  156. /**
  157. * Get the end tag of a fieldset.
  158. *
  159. * @return string
  160. */
  161. protected function getFieldsetEnd() {
  162. return "</fieldset>\n";
  163. }
  164. /**
  165. * Opens a textarea used to display the progress of a long operation
  166. */
  167. protected function startLiveBox() {
  168. $this->addHTML(
  169. '<div id="config-spinner" style="display:none;">' .
  170. '<img src="images/ajax-loader.gif" /></div>' .
  171. '<script>jQuery( "#config-spinner" ).show();</script>' .
  172. '<div id="config-live-log">' .
  173. '<textarea name="LiveLog" rows="10" cols="30" readonly="readonly">'
  174. );
  175. $this->parent->output->flush();
  176. }
  177. /**
  178. * Opposite to WebInstallerPage::startLiveBox
  179. */
  180. protected function endLiveBox() {
  181. $this->addHTML( '</textarea></div>
  182. <script>jQuery( "#config-spinner" ).hide()</script>' );
  183. $this->parent->output->flush();
  184. }
  185. }