MediaWiki  1.29.1
OracleInstaller.php
Go to the documentation of this file.
1 <?php
25 
33 
34  protected $globalNames = [
35  'wgDBserver',
36  'wgDBname',
37  'wgDBuser',
38  'wgDBpassword',
39  'wgDBprefix',
40  ];
41 
42  protected $internalDefaults = [
43  '_OracleDefTS' => 'USERS',
44  '_OracleTempTS' => 'TEMP',
45  '_InstallUser' => 'SYSTEM',
46  ];
47 
48  public $minimumVersion = '9.0.1'; // 9iR1
49 
50  protected $connError = null;
51 
52  public function getName() {
53  return 'oracle';
54  }
55 
56  public function isCompiled() {
57  return self::checkExtension( 'oci8' );
58  }
59 
60  public function getConnectForm() {
61  if ( $this->getVar( 'wgDBserver' ) == 'localhost' ) {
62  $this->parent->setVar( 'wgDBserver', '' );
63  }
64 
65  return $this->getTextBox(
66  'wgDBserver',
67  'config-db-host-oracle',
68  [],
69  $this->parent->getHelpBox( 'config-db-host-oracle-help' )
70  ) .
71  Html::openElement( 'fieldset' ) .
72  Html::element( 'legend', [], wfMessage( 'config-db-wiki-settings' )->text() ) .
73  $this->getTextBox( 'wgDBprefix', 'config-db-prefix' ) .
74  $this->getTextBox( '_OracleDefTS', 'config-oracle-def-ts' ) .
75  $this->getTextBox(
76  '_OracleTempTS',
77  'config-oracle-temp-ts',
78  [],
79  $this->parent->getHelpBox( 'config-db-oracle-help' )
80  ) .
81  Html::closeElement( 'fieldset' ) .
82  $this->parent->getWarningBox( wfMessage( 'config-db-account-oracle-warn' )->text() ) .
83  $this->getInstallUserBox() .
84  $this->getWebUserBox();
85  }
86 
87  public function submitInstallUserBox() {
88  parent::submitInstallUserBox();
89  $this->parent->setVar( '_InstallDBname', $this->getVar( '_InstallUser' ) );
90 
91  return Status::newGood();
92  }
93 
94  public function submitConnectForm() {
95  // Get variables from the request
96  $newValues = $this->setVarsFromRequest( [
97  'wgDBserver',
98  'wgDBprefix',
99  'wgDBuser',
100  'wgDBpassword'
101  ] );
102  $this->parent->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) );
103 
104  // Validate them
106  if ( !strlen( $newValues['wgDBserver'] ) ) {
107  $status->fatal( 'config-missing-db-server-oracle' );
108  } elseif ( !self::checkConnectStringFormat( $newValues['wgDBserver'] ) ) {
109  $status->fatal( 'config-invalid-db-server-oracle', $newValues['wgDBserver'] );
110  }
111  if ( !preg_match( '/^[a-zA-Z0-9_]*$/', $newValues['wgDBprefix'] ) ) {
112  $status->fatal( 'config-invalid-schema', $newValues['wgDBprefix'] );
113  }
114  if ( !$status->isOK() ) {
115  return $status;
116  }
117 
118  // Submit user box
119  $status = $this->submitInstallUserBox();
120  if ( !$status->isOK() ) {
121  return $status;
122  }
123 
124  // Try to connect trough multiple scenarios
125  // Scenario 1: Install with a manually created account
126  $status = $this->getConnection();
127  if ( !$status->isOK() ) {
128  if ( $this->connError == 28009 ) {
129  // _InstallUser seems to be a SYSDBA
130  // Scenario 2: Create user with SYSDBA and install with new user
131  $status = $this->submitWebUserBox();
132  if ( !$status->isOK() ) {
133  return $status;
134  }
135  $status = $this->openSYSDBAConnection();
136  if ( !$status->isOK() ) {
137  return $status;
138  }
139  if ( !$this->getVar( '_CreateDBAccount' ) ) {
140  $status->fatal( 'config-db-sys-create-oracle' );
141  }
142  } else {
143  return $status;
144  }
145  } else {
146  // check for web user credentials
147  // Scenario 3: Install with a priviliged user but use a restricted user
148  $statusIS3 = $this->submitWebUserBox();
149  if ( !$statusIS3->isOK() ) {
150  return $statusIS3;
151  }
152  }
153 
157  $conn = $status->value;
158 
159  // Check version
160  $version = $conn->getServerVersion();
161  if ( version_compare( $version, $this->minimumVersion ) < 0 ) {
162  return Status::newFatal( 'config-oracle-old', $this->minimumVersion, $version );
163  }
164 
165  return $status;
166  }
167 
168  public function openConnection() {
170  try {
171  $db = new DatabaseOracle(
172  $this->getVar( 'wgDBserver' ),
173  $this->getVar( '_InstallUser' ),
174  $this->getVar( '_InstallPassword' ),
175  $this->getVar( '_InstallDBname' ),
176  0,
177  $this->getVar( 'wgDBprefix' )
178  );
179  $status->value = $db;
180  } catch ( DBConnectionError $e ) {
181  $this->connError = $e->db->lastErrno();
182  $status->fatal( 'config-connection-error', $e->getMessage() );
183  }
184 
185  return $status;
186  }
187 
188  public function openSYSDBAConnection() {
190  try {
191  $db = new DatabaseOracle(
192  $this->getVar( 'wgDBserver' ),
193  $this->getVar( '_InstallUser' ),
194  $this->getVar( '_InstallPassword' ),
195  $this->getVar( '_InstallDBname' ),
196  DBO_SYSDBA,
197  $this->getVar( 'wgDBprefix' )
198  );
199  $status->value = $db;
200  } catch ( DBConnectionError $e ) {
201  $this->connError = $e->db->lastErrno();
202  $status->fatal( 'config-connection-error', $e->getMessage() );
203  }
204 
205  return $status;
206  }
207 
208  public function needsUpgrade() {
209  $tempDBname = $this->getVar( 'wgDBname' );
210  $this->parent->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) );
211  $retVal = parent::needsUpgrade();
212  $this->parent->setVar( 'wgDBname', $tempDBname );
213 
214  return $retVal;
215  }
216 
217  public function preInstall() {
218  # Add our user callback to installSteps, right before the tables are created.
219  $callback = [
220  'name' => 'user',
221  'callback' => [ $this, 'setupUser' ]
222  ];
223  $this->parent->addInstallStep( $callback, 'database' );
224  }
225 
226  public function setupDatabase() {
228 
229  return $status;
230  }
231 
232  public function setupUser() {
233  global $IP;
234 
235  if ( !$this->getVar( '_CreateDBAccount' ) ) {
236  return Status::newGood();
237  }
238 
239  // normaly only SYSDBA users can create accounts
240  $status = $this->openSYSDBAConnection();
241  if ( !$status->isOK() ) {
242  if ( $this->connError == 1031 ) {
243  // insufficient privileges (looks like a normal user)
244  $status = $this->openConnection();
245  if ( !$status->isOK() ) {
246  return $status;
247  }
248  } else {
249  return $status;
250  }
251  }
252 
253  $this->db = $status->value;
254  $this->setupSchemaVars();
255 
256  if ( !$this->db->selectDB( $this->getVar( 'wgDBuser' ) ) ) {
257  $this->db->setFlag( DBO_DDLMODE );
258  $error = $this->db->sourceFile( "$IP/maintenance/oracle/user.sql" );
259  if ( $error !== true || !$this->db->selectDB( $this->getVar( 'wgDBuser' ) ) ) {
260  $status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ), $error );
261  }
262  } elseif ( $this->db->getFlag( DBO_SYSDBA ) ) {
263  $status->fatal( 'config-db-sys-user-exists-oracle', $this->getVar( 'wgDBuser' ) );
264  }
265 
266  if ( $status->isOK() ) {
267  // user created or already existing, switching back to a normal connection
268  // as the new user has all needed privileges to setup the rest of the schema
269  // i will be using that user as _InstallUser from this point on
270  $this->db->close();
271  $this->db = false;
272  $this->parent->setVar( '_InstallUser', $this->getVar( 'wgDBuser' ) );
273  $this->parent->setVar( '_InstallPassword', $this->getVar( 'wgDBpassword' ) );
274  $this->parent->setVar( '_InstallDBname', $this->getVar( 'wgDBuser' ) );
275  $status = $this->getConnection();
276  }
277 
278  return $status;
279  }
280 
285  public function createTables() {
286  $this->setupSchemaVars();
287  $this->db->setFlag( DBO_DDLMODE );
288  $this->parent->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) );
289  $status = parent::createTables();
290  $this->db->clearFlag( DBO_DDLMODE );
291 
292  $this->db->query( 'BEGIN fill_wiki_info; END;' );
293 
294  return $status;
295  }
296 
297  public function getSchemaVars() {
298  $varNames = [
299  # These variables are used by maintenance/oracle/user.sql
300  '_OracleDefTS',
301  '_OracleTempTS',
302  'wgDBuser',
303  'wgDBpassword',
304 
305  # These are used by tables.sql
306  'wgDBprefix',
307  ];
308  $vars = [];
309  foreach ( $varNames as $name ) {
310  $vars[$name] = $this->getVar( $name );
311  }
312 
313  return $vars;
314  }
315 
316  public function getLocalSettings() {
317  $prefix = $this->getVar( 'wgDBprefix' );
318 
319  return "# Oracle specific settings
320 \$wgDBprefix = \"{$prefix}\";
321 ";
322  }
323 
338  public static function checkConnectStringFormat( $connect_string ) {
339  // @@codingStandardsIgnoreStart Long lines with regular expressions.
340  // @todo Very long regular expression. Make more readable?
341  $isValid = preg_match( '/^[[:alpha:]][\w\-]*(?:\.[[:alpha:]][\w\-]*){0,2}$/', $connect_string ); // TNS name
342  $isValid |= preg_match( '/^(?:\/\/)?[\w\-\.]+(?::[\d]+)?(?:\/(?:[\w\-\.]+(?::(pooled|dedicated|shared))?)?(?:\/[\w\-\.]+)?)?$/', $connect_string ); // EZConnect
343  // @@codingStandardsIgnoreEnd
344  return (bool)$isValid;
345  }
346 }
OracleInstaller\getConnectForm
getConnectForm()
Get HTML for a web form that configures this database.
Definition: OracleInstaller.php:60
DatabaseInstaller\checkExtension
static checkExtension( $name)
Convenience function.
Definition: DatabaseInstaller.php:411
OracleInstaller\isCompiled
isCompiled()
Definition: OracleInstaller.php:56
text
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:12
DatabaseInstaller\getConnection
getConnection()
Connect to the database using the administrative user/password currently defined in the session.
Definition: DatabaseInstaller.php:152
$status
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup 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:1049
OracleInstaller\needsUpgrade
needsUpgrade()
Determine whether an existing installation of MediaWiki is present in the configured administrative c...
Definition: OracleInstaller.php:208
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
OracleInstaller\checkConnectStringFormat
static checkConnectStringFormat( $connect_string)
Function checks the format of Oracle connect string The actual validity of the string is checked by a...
Definition: OracleInstaller.php:338
OracleInstaller\openSYSDBAConnection
openSYSDBAConnection()
Definition: OracleInstaller.php:188
StatusValue\newFatal
static newFatal( $message)
Factory function for fatal errors.
Definition: StatusValue.php:63
DatabaseInstaller\getTextBox
getTextBox( $var, $label, $attribs=[], $helpData="")
Get a labelled text box to configure a local variable.
Definition: DatabaseInstaller.php:483
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:304
OracleInstaller\$connError
$connError
Definition: OracleInstaller.php:50
php
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:35
OracleInstaller\setupUser
setupUser()
Definition: OracleInstaller.php:232
Html\closeElement
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:309
OracleInstaller\$minimumVersion
$minimumVersion
Definition: OracleInstaller.php:48
OracleInstaller\submitInstallUserBox
submitInstallUserBox()
Submit a standard install user fieldset.
Definition: OracleInstaller.php:87
DatabaseInstaller\submitWebUserBox
submitWebUserBox()
Submit the form from getWebUserBox().
Definition: DatabaseInstaller.php:671
OracleInstaller\getLocalSettings
getLocalSettings()
Get the DBMS-specific options for LocalSettings.php generation.
Definition: OracleInstaller.php:316
OracleInstaller\getSchemaVars
getSchemaVars()
Override this to provide DBMS-specific schema variables, to be substituted into tables....
Definition: OracleInstaller.php:297
$IP
$IP
Definition: update.php:3
DatabaseInstaller\setupSchemaVars
setupSchemaVars()
Set appropriate schema variables in the current database connection.
Definition: DatabaseInstaller.php:312
OracleInstaller\createTables
createTables()
Overload: after this action field info table has to be rebuilt.
Definition: OracleInstaller.php:285
DatabaseOracle
Definition: DatabaseOracle.php:33
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
$vars
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
Definition: hooks.txt:2179
DatabaseInstaller\getWebUserBox
getWebUserBox( $noCreateMsg=false)
Get a standard web-user fieldset.
Definition: DatabaseInstaller.php:644
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2122
DatabaseInstaller\getVar
getVar( $var, $default=null)
Get a variable, taking local defaults into account.
Definition: DatabaseInstaller.php:453
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:76
DBO_DDLMODE
const DBO_DDLMODE
Definition: defines.php:16
OracleInstaller\setupDatabase
setupDatabase()
Create the database and return a Status object indicating success or failure.
Definition: OracleInstaller.php:226
DBO_SYSDBA
const DBO_SYSDBA
Definition: defines.php:15
DatabaseInstaller
Base class for DBMS-specific installation helper classes.
Definition: DatabaseInstaller.php:33
OracleInstaller\openConnection
openConnection()
Open a connection to the database using the administrative user/password currently defined in the ses...
Definition: OracleInstaller.php:168
OracleInstaller\submitConnectForm
submitConnectForm()
Set variables based on the request array, assuming it was submitted via the form returned by getConne...
Definition: OracleInstaller.php:94
OracleInstaller\getName
getName()
Return the internal name, e.g.
Definition: OracleInstaller.php:52
as
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
Definition: distributors.txt:9
OracleInstaller\$globalNames
$globalNames
Definition: OracleInstaller.php:34
Html\openElement
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:251
DatabaseInstaller\getInstallUserBox
getInstallUserBox()
Get a standard install-user fieldset.
Definition: DatabaseInstaller.php:609
DatabaseInstaller\setVarsFromRequest
setVarsFromRequest( $varNames)
Convenience function to set variables based on form data.
Definition: DatabaseInstaller.php:576
Wikimedia\Rdbms\DBConnectionError
Definition: DBConnectionError.php:26
OracleInstaller\$internalDefaults
$internalDefaults
Definition: OracleInstaller.php:42
OracleInstaller
Class for setting up the MediaWiki database using Oracle.
Definition: OracleInstaller.php:32
wfMessage
either a unescaped string or a HtmlArmor object 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
DatabaseInstaller\$db
Database $db
The database connection.
Definition: DatabaseInstaller.php:49
OracleInstaller\preInstall
preInstall()
Allow DB installers a chance to make last-minute changes before installation occurs.
Definition: OracleInstaller.php:217
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:231