WebInstallerDBConnect.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along
  14. * with this program; if not, write to the Free Software Foundation, Inc.,
  15. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. * http://www.gnu.org/copyleft/gpl.html
  17. *
  18. * @file
  19. * @ingroup Deployment
  20. */
  21. class WebInstallerDBConnect extends WebInstallerPage {
  22. /**
  23. * @return string|null When string, "skip" or "continue"
  24. */
  25. public function execute() {
  26. if ( $this->getVar( '_ExistingDBSettings' ) ) {
  27. return 'skip';
  28. }
  29. $r = $this->parent->request;
  30. if ( $r->wasPosted() ) {
  31. $status = $this->submit();
  32. if ( $status->isGood() ) {
  33. $this->setVar( '_UpgradeDone', false );
  34. return 'continue';
  35. } else {
  36. $this->parent->showStatusBox( $status );
  37. }
  38. }
  39. $this->startForm();
  40. $types = "<ul class=\"config-settings-block\">\n";
  41. $settings = '';
  42. $defaultType = $this->getVar( 'wgDBtype' );
  43. // Messages: config-dbsupport-mysql, config-dbsupport-postgres, config-dbsupport-sqlite
  44. $dbSupport = '';
  45. foreach ( Installer::getDBTypes() as $type ) {
  46. $dbSupport .= wfMessage( "config-dbsupport-$type" )->plain() . "\n";
  47. }
  48. $this->addHTML( $this->parent->getInfoBox(
  49. wfMessage( 'config-support-info', trim( $dbSupport ) )->plain() ) );
  50. // It's possible that the library for the default DB type is not compiled in.
  51. // In that case, instead select the first supported DB type in the list.
  52. $compiledDBs = $this->parent->getCompiledDBs();
  53. if ( !in_array( $defaultType, $compiledDBs ) ) {
  54. $defaultType = $compiledDBs[0];
  55. }
  56. foreach ( $compiledDBs as $type ) {
  57. $installer = $this->parent->getDBInstaller( $type );
  58. $types .=
  59. '<li>' .
  60. Xml::radioLabel(
  61. $installer->getReadableName(),
  62. 'DBType',
  63. $type,
  64. "DBType_$type",
  65. $type == $defaultType,
  66. [ 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" ]
  67. ) .
  68. "</li>\n";
  69. // Messages: config-header-mysql, config-header-postgres, config-header-sqlite
  70. $settings .= Html::openElement(
  71. 'div',
  72. [
  73. 'id' => 'DB_wrapper_' . $type,
  74. 'class' => 'dbWrapper'
  75. ]
  76. ) .
  77. Html::element( 'h3', [], wfMessage( 'config-header-' . $type )->text() ) .
  78. $installer->getConnectForm() .
  79. "</div>\n";
  80. }
  81. $types .= "</ul><br style=\"clear: left\"/>\n";
  82. $this->addHTML( $this->parent->label( 'config-db-type', false, $types ) . $settings );
  83. $this->endForm();
  84. return null;
  85. }
  86. /**
  87. * @return Status
  88. */
  89. public function submit() {
  90. $r = $this->parent->request;
  91. $type = $r->getVal( 'DBType' );
  92. if ( !$type ) {
  93. return Status::newFatal( 'config-invalid-db-type' );
  94. }
  95. $this->setVar( 'wgDBtype', $type );
  96. $installer = $this->parent->getDBInstaller( $type );
  97. if ( !$installer ) {
  98. return Status::newFatal( 'config-invalid-db-type' );
  99. }
  100. return $installer->submitConnectForm();
  101. }
  102. }