Replace XML->HTML methods throughout most of the installer
[lhc/web/wiklou.git] / includes / installer / OracleInstaller.php
1 <?php
2 /**
3 * Oracle-specific installer.
4 *
5 * @file
6 * @ingroup Deployment
7 */
8
9 /**
10 * Class for setting up the MediaWiki database using Oracle.
11 *
12 * @ingroup Deployment
13 * @since 1.17
14 */
15 class OracleInstaller extends DatabaseInstaller {
16
17 protected $globalNames = array(
18 'wgDBport',
19 'wgDBname',
20 'wgDBuser',
21 'wgDBpassword',
22 'wgDBprefix',
23 );
24
25 protected $internalDefaults = array(
26 '_OracleDefTS' => 'USERS',
27 '_OracleTempTS' => 'TEMP',
28 '_OracleUseSysdba' => true
29 );
30
31 public $minimumVersion = '9.0.1'; // 9iR1
32
33 public function getName() {
34 return 'oracle';
35 }
36
37 public function isCompiled() {
38 return self::checkExtension( 'oci8' );
39 }
40
41 public function getWebUserBox( $noCreateMsg = false ) {
42 $name = $this->getName();
43 $this->parent->setVar( '_SameAccount', false );
44 $this->parent->setVar( '_CreateDBAccount', true );
45 $this->parent->setVar( 'wgDBname', '' );
46 return Html::openElement( 'fieldset' ) .
47 Html::element( 'legend', array(), wfMsg( 'config-db-web-account' ) ) .
48 Html::openElement( 'div', array( 'id' => 'dbOtherAccount' ) ) .
49 $this->getTextBox( 'wgDBuser', 'config-db-username' ) .
50 $this->getPasswordBox( 'wgDBpassword', 'config-db-password', array(), $this->parent->getHelpBox( 'config-db-web-help' ) ) .
51 $this->getCheckBox( '_CreateDBAccount', 'config-db-web-create', array( 'disabled' => true ) ).
52 Html::closeElement( 'div' ) . Html::closeElement( 'fieldset' );
53 }
54
55 public function getConnectForm() {
56 $this->parent->setVar( '_InstallUser', 'sys' );
57 $this->parent->setVar( 'wgDBserver', '' );
58 return
59 $this->getTextBox( 'wgDBserver', 'config-db-host-oracle', array(), $this->parent->getHelpBox( 'config-db-host-oracle-help' ) ) .
60 Xml::openElement( 'fieldset' ) .
61 Xml::element( 'legend', array(), wfMsg( 'config-db-wiki-settings' ) ) .
62 $this->getTextBox( 'wgDBprefix', 'config-db-prefix' ) .
63 $this->getTextBox( '_OracleDefTS', 'config-oracle-def-ts' ) .
64 $this->getTextBox( '_OracleTempTS', 'config-oracle-temp-ts', array(), $this->parent->getHelpBox( 'config-db-oracle-help' ) ) .
65 Xml::closeElement( 'fieldset' ) .
66 $this->getInstallUserBox().
67 $this->getWebUserBox();
68 }
69
70 public function submitConnectForm() {
71 // Get variables from the request
72 $newValues = $this->setVarsFromRequest( array( 'wgDBserver', 'wgDBprefix', 'wgDBuser', 'wgDBpassword' ) );
73 $this->parent->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) );
74
75 // Validate them
76 $status = Status::newGood();
77 if ( !strlen( $newValues['wgDBserver'] ) ) {
78 $status->fatal( 'config-missing-db-server-oracle' );
79 } elseif ( !preg_match( '/^[a-zA-Z0-9_\.]+$/', $newValues['wgDBserver'] ) ) {
80 $status->fatal( 'config-invalid-db-server-oracle', $newValues['wgDBserver'] );
81 }
82 if ( !preg_match( '/^[a-zA-Z0-9_]*$/', $newValues['wgDBprefix'] ) ) {
83 $status->fatal( 'config-invalid-schema', $newValues['wgDBprefix'] );
84 }
85 if ( !$status->isOK() ) {
86 return $status;
87 }
88
89 // Submit user box
90 $status = $this->submitInstallUserBox();
91 if ( !$status->isOK() ) {
92 return $status;
93 }
94
95 // Try to connect
96 $status = $this->getConnection();
97 if ( !$status->isOK() ) {
98 return $status;
99 }
100 $conn = $status->value;
101
102 // Check version
103 $version = $conn->getServerVersion();
104 if ( version_compare( $version, $this->minimumVersion ) < 0 ) {
105 return Status::newFatal( 'config-oracle-old', $this->minimumVersion, $version );
106 }
107
108 return $status;
109 }
110
111 public function getConnection() {
112 $status = Status::newGood();
113 try {
114 if ( $this->getVar( '_OracleUseSysdba' ) ) {
115 $this->db = new DatabaseOracle(
116 $this->getVar( 'wgDBserver' ),
117 $this->getVar( '_InstallUser' ),
118 $this->getVar( '_InstallPassword' ),
119 $this->getVar( 'wgDBname' ),
120 DBO_SYSDBA,
121 $this->getVar( 'wgDBprefix' )
122 );
123 } else {
124 $this->db = new DatabaseOracle(
125 $this->getVar( 'wgDBserver' ),
126 $this->getVar( 'wgDBuser' ),
127 $this->getVar( 'wgDBpassword' ),
128 $this->getVar( 'wgDBname' ),
129 0,
130 $this->getVar( 'wgDBprefix' )
131 );
132 }
133 $status->value = $this->db;
134 } catch ( DBConnectionError $e ) {
135 $status->fatal( 'config-connection-error', $e->getMessage() );
136 }
137 return $status;
138 }
139
140 public function needsUpgrade() {
141 $tempDBname = $this->getVar( 'wgDBname' );
142 $this->parent->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) );
143 $retVal = parent::needsUpgrade();
144 $this->parent->setVar( 'wgDBname', $tempDBname );
145 return $retVal;
146 }
147
148 public function preInstall() {
149 # Add our user callback to installSteps, right before the tables are created.
150 $callback = array(
151 array(
152 'name' => 'user',
153 'callback' => array( $this, 'setupUser' ),
154 )
155 );
156 $this->parent->addInstallStepFollowing( "database", $callback );
157 }
158
159
160 public function setupDatabase() {
161 $this->parent->setVar( '_OracleUseSysdba', false );
162 $status = Status::newGood();
163 return $status;
164 }
165
166 public function setupUser() {
167 global $IP;
168
169 if ( !$this->getVar( '_CreateDBAccount' ) ) {
170 return Status::newGood();
171 }
172 $status = $this->getConnection();
173 if ( !$status->isOK() ) {
174 return $status;
175 }
176
177 if ( !$this->db->selectDB( $this->getVar( 'wgDBuser' ) ) ) {
178 global $_OracleDefTS, $_OracleTempTS;
179 $_OracleDefTS = $this->getVar( '_OracleDefTS' );
180 $_OracleTempTS = $this->getVar( '_OracleTempTS' );
181 $error = $this->db->sourceFile( "$IP/maintenance/oracle/user.sql" );
182 if ( $error !== true || !$this->db->selectDB( $this->getVar( 'wgDBuser' ) ) ) {
183 $status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ), $error );
184 }
185 }
186
187 return $status;
188 }
189
190 /**
191 * Overload: after this action field info table has to be rebuilt
192 */
193 public function createTables() {
194 $status = parent::createTables();
195
196 $this->db->doQuery( 'BEGIN fill_wiki_info; END;' );
197
198 return $status;
199 }
200
201
202 public function getLocalSettings() {
203 $prefix = $this->getVar( 'wgDBprefix' );
204 return
205 "# Oracle specific settings
206 \$wgDBprefix = \"{$prefix}\";
207 ";
208 }
209
210 }