MediaWiki REL1_27
OracleInstaller.php
Go to the documentation of this file.
1<?php
31
32 protected $globalNames = [
33 'wgDBserver',
34 'wgDBname',
35 'wgDBuser',
36 'wgDBpassword',
37 'wgDBprefix',
38 ];
39
40 protected $internalDefaults = [
41 '_OracleDefTS' => 'USERS',
42 '_OracleTempTS' => 'TEMP',
43 '_InstallUser' => 'SYSTEM',
44 ];
45
46 public $minimumVersion = '9.0.1'; // 9iR1
47
48 protected $connError = null;
49
50 public function getName() {
51 return 'oracle';
52 }
53
54 public function isCompiled() {
55 return self::checkExtension( 'oci8' );
56 }
57
58 public function getConnectForm() {
59 if ( $this->getVar( 'wgDBserver' ) == 'localhost' ) {
60 $this->parent->setVar( 'wgDBserver', '' );
61 }
62
63 return $this->getTextBox(
64 'wgDBserver',
65 'config-db-host-oracle',
66 [],
67 $this->parent->getHelpBox( 'config-db-host-oracle-help' )
68 ) .
69 Html::openElement( 'fieldset' ) .
70 Html::element( 'legend', [], wfMessage( 'config-db-wiki-settings' )->text() ) .
71 $this->getTextBox( 'wgDBprefix', 'config-db-prefix' ) .
72 $this->getTextBox( '_OracleDefTS', 'config-oracle-def-ts' ) .
73 $this->getTextBox(
74 '_OracleTempTS',
75 'config-oracle-temp-ts',
76 [],
77 $this->parent->getHelpBox( 'config-db-oracle-help' )
78 ) .
79 Html::closeElement( 'fieldset' ) .
80 $this->parent->getWarningBox( wfMessage( 'config-db-account-oracle-warn' )->text() ) .
81 $this->getInstallUserBox() .
82 $this->getWebUserBox();
83 }
84
85 public function submitInstallUserBox() {
86 parent::submitInstallUserBox();
87 $this->parent->setVar( '_InstallDBname', $this->getVar( '_InstallUser' ) );
88
89 return Status::newGood();
90 }
91
92 public function submitConnectForm() {
93 // Get variables from the request
94 $newValues = $this->setVarsFromRequest( [
95 'wgDBserver',
96 'wgDBprefix',
97 'wgDBuser',
98 'wgDBpassword'
99 ] );
100 $this->parent->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) );
101
102 // Validate them
103 $status = Status::newGood();
104 if ( !strlen( $newValues['wgDBserver'] ) ) {
105 $status->fatal( 'config-missing-db-server-oracle' );
106 } elseif ( !self::checkConnectStringFormat( $newValues['wgDBserver'] ) ) {
107 $status->fatal( 'config-invalid-db-server-oracle', $newValues['wgDBserver'] );
108 }
109 if ( !preg_match( '/^[a-zA-Z0-9_]*$/', $newValues['wgDBprefix'] ) ) {
110 $status->fatal( 'config-invalid-schema', $newValues['wgDBprefix'] );
111 }
112 if ( !$status->isOK() ) {
113 return $status;
114 }
115
116 // Submit user box
117 $status = $this->submitInstallUserBox();
118 if ( !$status->isOK() ) {
119 return $status;
120 }
121
122 // Try to connect trough multiple scenarios
123 // Scenario 1: Install with a manually created account
124 $status = $this->getConnection();
125 if ( !$status->isOK() ) {
126 if ( $this->connError == 28009 ) {
127 // _InstallUser seems to be a SYSDBA
128 // Scenario 2: Create user with SYSDBA and install with new user
129 $status = $this->submitWebUserBox();
130 if ( !$status->isOK() ) {
131 return $status;
132 }
133 $status = $this->openSYSDBAConnection();
134 if ( !$status->isOK() ) {
135 return $status;
136 }
137 if ( !$this->getVar( '_CreateDBAccount' ) ) {
138 $status->fatal( 'config-db-sys-create-oracle' );
139 }
140 } else {
141 return $status;
142 }
143 } else {
144 // check for web user credentials
145 // Scenario 3: Install with a priviliged user but use a restricted user
146 $statusIS3 = $this->submitWebUserBox();
147 if ( !$statusIS3->isOK() ) {
148 return $statusIS3;
149 }
150 }
151
155 $conn = $status->value;
156
157 // Check version
158 $version = $conn->getServerVersion();
159 if ( version_compare( $version, $this->minimumVersion ) < 0 ) {
160 return Status::newFatal( 'config-oracle-old', $this->minimumVersion, $version );
161 }
162
163 return $status;
164 }
165
166 public function openConnection() {
167 return $this->doOpenConnection();
168 }
169
170 public function openSYSDBAConnection() {
171 return $this->doOpenConnection( DatabaseOracle::DBO_SYSDBA );
172 }
173
178 private function doOpenConnection( $flags = 0 ) {
179 $status = Status::newGood();
180 try {
182 'oracle',
183 [
184 'host' => $this->getVar( 'wgDBserver' ),
185 'user' => $this->getVar( '_InstallUser' ),
186 'password' => $this->getVar( '_InstallPassword' ),
187 'dbname' => $this->getVar( '_InstallDBname' ),
188 'tablePrefix' => $this->getVar( 'wgDBprefix' ),
189 'flags' => $flags
190 ]
191 );
192 $status->value = $db;
193 } catch ( DBConnectionError $e ) {
194 $this->connError = $e->db->lastErrno();
195 $status->fatal( 'config-connection-error', $e->getMessage() );
196 }
197
198 return $status;
199 }
200
201 public function needsUpgrade() {
202 $tempDBname = $this->getVar( 'wgDBname' );
203 $this->parent->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) );
204 $retVal = parent::needsUpgrade();
205 $this->parent->setVar( 'wgDBname', $tempDBname );
206
207 return $retVal;
208 }
209
210 public function preInstall() {
211 # Add our user callback to installSteps, right before the tables are created.
212 $callback = [
213 'name' => 'user',
214 'callback' => [ $this, 'setupUser' ]
215 ];
216 $this->parent->addInstallStep( $callback, 'database' );
217 }
218
219 public function setupDatabase() {
220 $status = Status::newGood();
221
222 return $status;
223 }
224
225 public function setupUser() {
226 global $IP;
227
228 if ( !$this->getVar( '_CreateDBAccount' ) ) {
229 return Status::newGood();
230 }
231
232 // normaly only SYSDBA users can create accounts
233 $status = $this->openSYSDBAConnection();
234 if ( !$status->isOK() ) {
235 if ( $this->connError == 1031 ) {
236 // insufficient privileges (looks like a normal user)
237 $status = $this->openConnection();
238 if ( !$status->isOK() ) {
239 return $status;
240 }
241 } else {
242 return $status;
243 }
244 }
245
246 $this->db = $status->value;
247 $this->setupSchemaVars();
248
249 if ( !$this->db->selectDB( $this->getVar( 'wgDBuser' ) ) ) {
250 $this->db->setFlag( DBO_DDLMODE );
251 $error = $this->db->sourceFile( "$IP/maintenance/oracle/user.sql" );
252 if ( $error !== true || !$this->db->selectDB( $this->getVar( 'wgDBuser' ) ) ) {
253 $status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ), $error );
254 }
255 } elseif ( $this->db->getFlag( DBO_SYSDBA ) ) {
256 $status->fatal( 'config-db-sys-user-exists-oracle', $this->getVar( 'wgDBuser' ) );
257 }
258
259 if ( $status->isOK() ) {
260 // user created or already existing, switching back to a normal connection
261 // as the new user has all needed privileges to setup the rest of the schema
262 // i will be using that user as _InstallUser from this point on
263 $this->db->close();
264 $this->db = false;
265 $this->parent->setVar( '_InstallUser', $this->getVar( 'wgDBuser' ) );
266 $this->parent->setVar( '_InstallPassword', $this->getVar( 'wgDBpassword' ) );
267 $this->parent->setVar( '_InstallDBname', $this->getVar( 'wgDBuser' ) );
268 $status = $this->getConnection();
269 }
270
271 return $status;
272 }
273
278 public function createTables() {
279 $this->setupSchemaVars();
280 $this->db->setFlag( DBO_DDLMODE );
281 $this->parent->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) );
282 $status = parent::createTables();
283 $this->db->clearFlag( DBO_DDLMODE );
284
285 $this->db->query( 'BEGIN fill_wiki_info; END;' );
286
287 return $status;
288 }
289
290 public function getSchemaVars() {
291 $varNames = [
292 # These variables are used by maintenance/oracle/user.sql
293 '_OracleDefTS',
294 '_OracleTempTS',
295 'wgDBuser',
296 'wgDBpassword',
297
298 # These are used by tables.sql
299 'wgDBprefix',
300 ];
301 $vars = [];
302 foreach ( $varNames as $name ) {
303 $vars[$name] = $this->getVar( $name );
304 }
305
306 return $vars;
307 }
308
309 public function getLocalSettings() {
310 $prefix = $this->getVar( 'wgDBprefix' );
311
312 return "# Oracle specific settings
313\$wgDBprefix = \"{$prefix}\";
314";
315 }
316
331 public static function checkConnectStringFormat( $connect_string ) {
332 // @@codingStandardsIgnoreStart Long lines with regular expressions.
333 // @todo Very long regular expression. Make more readable?
334 $isValid = preg_match( '/^[[:alpha:]][\w\-]*(?:\.[[:alpha:]][\w\-]*){0,2}$/', $connect_string ); // TNS name
335 $isValid |= preg_match( '/^(?:\/\/)?[\w\-\.]+(?::[\d]+)?(?:\/(?:[\w\-\.]+(?::(pooled|dedicated|shared))?)?(?:\/[\w\-\.]+)?)?$/', $connect_string ); // EZConnect
336 // @@codingStandardsIgnoreEnd
337 return (bool)$isValid;
338 }
339}
$IP
Definition WebStart.php:58
static factory( $dbType, $p=[])
Given a DB type, construct the name of the appropriate child class of DatabaseBase.
Definition Database.php:580
Base class for DBMS-specific installation helper classes.
getWebUserBox( $noCreateMsg=false)
Get a standard web-user fieldset.
DatabaseBase $db
The database connection.
submitWebUserBox()
Submit the form from getWebUserBox().
static checkExtension( $name)
Convenience function.
setVarsFromRequest( $varNames)
Convenience function to set variables based on form data.
getConnection()
Connect to the database using the administrative user/password currently defined in the session.
getVar( $var, $default=null)
Get a variable, taking local defaults into account.
getTextBox( $var, $label, $attribs=[], $helpData="")
Get a labelled text box to configure a local variable.
getInstallUserBox()
Get a standard install-user fieldset.
setupSchemaVars()
Set appropriate schema variables in the current database connection.
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition Html.php:230
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition Html.php:248
static closeElement( $element)
Returns "</$element>".
Definition Html.php:306
Class for setting up the MediaWiki database using Oracle.
submitInstallUserBox()
Submit a standard install user fieldset.
static checkConnectStringFormat( $connect_string)
Function checks the format of Oracle connect string The actual validity of the string is checked by a...
needsUpgrade()
Determine whether an existing installation of MediaWiki is present in the configured administrative c...
getName()
Return the internal name, e.g.
setupDatabase()
Create the database and return a Status object indicating success or failure.
preInstall()
Allow DB installers a chance to make last-minute changes before installation occurs.
createTables()
Overload: after this action field info table has to be rebuilt.
getLocalSettings()
Get the DBMS-specific options for LocalSettings.php generation.
getSchemaVars()
Override this to provide DBMS-specific schema variables, to be substituted into tables....
doOpenConnection( $flags=0)
getConnectForm()
Get HTML for a web form that configures this database.
openConnection()
Open a connection to the database using the administrative user/password currently defined in the ses...
submitConnectForm()
Set variables based on the request array, assuming it was submitted via the form returned by getConne...
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition design.txt:18
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
const DBO_DDLMODE
Definition Defines.php:37
const DBO_SYSDBA
Definition Defines.php:36
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Definition hooks.txt:1007
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
Definition hooks.txt:1999
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt;div ...>$1&lt;/div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition hooks.txt:2555
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:314
returning false will NOT prevent logging $e
Definition hooks.txt:1940
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
lastErrno()
Get the last error number.
$version