MediaWiki  1.23.13
OracleInstaller.php
Go to the documentation of this file.
1 <?php
31 
32  protected $globalNames = array(
33  'wgDBserver',
34  'wgDBname',
35  'wgDBuser',
36  'wgDBpassword',
37  'wgDBprefix',
38  );
39 
40  protected $internalDefaults = array(
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  array(),
67  $this->parent->getHelpBox( 'config-db-host-oracle-help' )
68  ) .
69  Html::openElement( 'fieldset' ) .
70  Html::element( 'legend', array(), 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  array(),
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( array(
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  $status = Status::newGood();
168  try {
169  $db = new DatabaseOracle(
170  $this->getVar( 'wgDBserver' ),
171  $this->getVar( '_InstallUser' ),
172  $this->getVar( '_InstallPassword' ),
173  $this->getVar( '_InstallDBname' ),
174  0,
175  $this->getVar( 'wgDBprefix' )
176  );
177  $status->value = $db;
178  } catch ( DBConnectionError $e ) {
179  $this->connError = $e->db->lastErrno();
180  $status->fatal( 'config-connection-error', $e->getMessage() );
181  }
182 
183  return $status;
184  }
185 
186  public function openSYSDBAConnection() {
187  $status = Status::newGood();
188  try {
189  $db = new DatabaseOracle(
190  $this->getVar( 'wgDBserver' ),
191  $this->getVar( '_InstallUser' ),
192  $this->getVar( '_InstallPassword' ),
193  $this->getVar( '_InstallDBname' ),
194  DBO_SYSDBA,
195  $this->getVar( 'wgDBprefix' )
196  );
197  $status->value = $db;
198  } catch ( DBConnectionError $e ) {
199  $this->connError = $e->db->lastErrno();
200  $status->fatal( 'config-connection-error', $e->getMessage() );
201  }
202 
203  return $status;
204  }
205 
206  public function needsUpgrade() {
207  $tempDBname = $this->getVar( 'wgDBname' );
208  $this->parent->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) );
209  $retVal = parent::needsUpgrade();
210  $this->parent->setVar( 'wgDBname', $tempDBname );
211 
212  return $retVal;
213  }
214 
215  public function preInstall() {
216  # Add our user callback to installSteps, right before the tables are created.
217  $callback = array(
218  'name' => 'user',
219  'callback' => array( $this, 'setupUser' )
220  );
221  $this->parent->addInstallStep( $callback, 'database' );
222  }
223 
224  public function setupDatabase() {
225  $status = Status::newGood();
226 
227  return $status;
228  }
229 
230  public function setupUser() {
231  global $IP;
232 
233  if ( !$this->getVar( '_CreateDBAccount' ) ) {
234  return Status::newGood();
235  }
236 
237  // normaly only SYSDBA users can create accounts
238  $status = $this->openSYSDBAConnection();
239  if ( !$status->isOK() ) {
240  if ( $this->connError == 1031 ) {
241  // insufficient privileges (looks like a normal user)
242  $status = $this->openConnection();
243  if ( !$status->isOK() ) {
244  return $status;
245  }
246  } else {
247  return $status;
248  }
249  }
250 
251  $this->db = $status->value;
252  $this->setupSchemaVars();
253 
254  if ( !$this->db->selectDB( $this->getVar( 'wgDBuser' ) ) ) {
255  $this->db->setFlag( DBO_DDLMODE );
256  $error = $this->db->sourceFile( "$IP/maintenance/oracle/user.sql" );
257  if ( $error !== true || !$this->db->selectDB( $this->getVar( 'wgDBuser' ) ) ) {
258  $status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ), $error );
259  }
260  } elseif ( $this->db->getFlag( DBO_SYSDBA ) ) {
261  $status->fatal( 'config-db-sys-user-exists-oracle', $this->getVar( 'wgDBuser' ) );
262  }
263 
264  if ( $status->isOK() ) {
265  // user created or already existing, switching back to a normal connection
266  // as the new user has all needed privileges to setup the rest of the schema
267  // i will be using that user as _InstallUser from this point on
268  $this->db->close();
269  $this->db = false;
270  $this->parent->setVar( '_InstallUser', $this->getVar( 'wgDBuser' ) );
271  $this->parent->setVar( '_InstallPassword', $this->getVar( 'wgDBpassword' ) );
272  $this->parent->setVar( '_InstallDBname', $this->getVar( 'wgDBuser' ) );
273  $status = $this->getConnection();
274  }
275 
276  return $status;
277  }
278 
283  public function createTables() {
284  $this->setupSchemaVars();
285  $this->db->setFlag( DBO_DDLMODE );
286  $this->parent->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) );
287  $status = parent::createTables();
288  $this->db->clearFlag( DBO_DDLMODE );
289 
290  $this->db->query( 'BEGIN fill_wiki_info; END;' );
291 
292  return $status;
293  }
294 
295  public function getSchemaVars() {
296  $varNames = array(
297  # These variables are used by maintenance/oracle/user.sql
298  '_OracleDefTS',
299  '_OracleTempTS',
300  'wgDBuser',
301  'wgDBpassword',
302 
303  # These are used by tables.sql
304  'wgDBprefix',
305  );
306  $vars = array();
307  foreach ( $varNames as $name ) {
308  $vars[$name] = $this->getVar( $name );
309  }
310 
311  return $vars;
312  }
313 
314  public function getLocalSettings() {
315  $prefix = $this->getVar( 'wgDBprefix' );
316 
317  return "# Oracle specific settings
318 \$wgDBprefix = \"{$prefix}\";
319 ";
320  }
321 
336  public static function checkConnectStringFormat( $connect_string ) {
337  // @@codingStandardsIgnoreStart Long lines with regular expressions.
338  // @todo Very long regular expression. Make more readable?
339  $isValid = preg_match( '/^[[:alpha:]][\w\-]*(?:\.[[:alpha:]][\w\-]*){0,2}$/', $connect_string ); // TNS name
340  $isValid |= preg_match( '/^(?:\/\/)?[\w\-\.]+(?::[\d]+)?(?:\/(?:[\w\-\.]+(?::(pooled|dedicated|shared))?)?(?:\/[\w\-\.]+)?)?$/', $connect_string ); // EZConnect
341  // @@codingStandardsIgnoreEnd
342  return (bool)$isValid;
343  }
344 }
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
OracleInstaller\getConnectForm
getConnectForm()
Get HTML for a web form that configures this database.
Definition: OracleInstaller.php:58
DatabaseInstaller\checkExtension
static checkExtension( $name)
Convenience function.
Definition: DatabaseInstaller.php:326
OracleInstaller\isCompiled
isCompiled()
Definition: OracleInstaller.php:54
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:145
OracleInstaller\needsUpgrade
needsUpgrade()
Determine whether an existing installation of MediaWiki is present in the configured administrative c...
Definition: OracleInstaller.php:206
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:336
OracleInstaller\openSYSDBAConnection
openSYSDBAConnection()
Definition: OracleInstaller.php:186
Status\newGood
static newGood( $value=null)
Factory function for good results.
Definition: Status.php:77
DBO_SYSDBA
const DBO_SYSDBA
Definition: Defines.php:45
OracleInstaller\$connError
$connError
Definition: OracleInstaller.php:48
DatabaseInstaller\getTextBox
getTextBox( $var, $label, $attribs=array(), $helpData="")
Get a labelled text box to configure a local variable.
Definition: DatabaseInstaller.php:393
OracleInstaller\setupUser
setupUser()
Definition: OracleInstaller.php:230
Html\closeElement
static closeElement( $element)
Returns "</$element>", except if $wgWellFormedXml is off, in which case it returns the empty string w...
Definition: Html.php:235
OracleInstaller\$minimumVersion
$minimumVersion
Definition: OracleInstaller.php:46
Html\openElement
static openElement( $element, $attribs=array())
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:166
OracleInstaller\submitInstallUserBox
submitInstallUserBox()
Submit a standard install user fieldset.
Definition: OracleInstaller.php:85
DBO_DDLMODE
const DBO_DDLMODE
Definition: Defines.php:46
Html\element
static element( $element, $attribs=array(), $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:148
DatabaseInstaller\submitWebUserBox
submitWebUserBox()
Submit the form from getWebUserBox().
Definition: DatabaseInstaller.php:582
OracleInstaller\getLocalSettings
getLocalSettings()
Get the DBMS-specific options for LocalSettings.php generation.
Definition: OracleInstaller.php:314
OracleInstaller\getSchemaVars
getSchemaVars()
Override this to provide DBMS-specific schema variables, to be substituted into tables....
Definition: OracleInstaller.php:295
wfMessage
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 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\setupSchemaVars
setupSchemaVars()
Set appropriate schema variables in the current database connection.
Definition: DatabaseInstaller.php:237
OracleInstaller\createTables
createTables()
Overload: after this action field info table has to be rebuilt.
Definition: OracleInstaller.php:283
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
DatabaseOracle
Definition: DatabaseOracle.php:188
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
DBConnectionError
Definition: DatabaseError.php:98
DatabaseInstaller\getWebUserBox
getWebUserBox( $noCreateMsg=false)
Get a standard web-user fieldset.
Definition: DatabaseInstaller.php:555
DatabaseInstaller\$db
DatabaseBase $db
The database connection.
Definition: DatabaseInstaller.php:44
user
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 and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same user
Definition: distributors.txt:9
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
DatabaseInstaller\getVar
getVar( $var, $default=null)
Get a variable, taking local defaults into account.
Definition: DatabaseInstaller.php:363
OracleInstaller\setupDatabase
setupDatabase()
Create the database and return a Status object indicating success or failure.
Definition: OracleInstaller.php:224
$version
$version
Definition: parserTests.php:86
DatabaseInstaller
Base class for DBMS-specific installation helper classes.
Definition: DatabaseInstaller.php:30
OracleInstaller\openConnection
openConnection()
Open a connection to the database using the administrative user/password currently defined in the ses...
Definition: OracleInstaller.php:166
OracleInstaller\submitConnectForm
submitConnectForm()
Set variables based on the request array, assuming it was submitted via the form returned by getConne...
Definition: OracleInstaller.php:92
OracleInstaller\getName
getName()
Return the internal name, e.g.
Definition: OracleInstaller.php:50
are
The ContentHandler facility adds support for arbitrary content types on wiki instead of relying on wikitext for everything It was introduced in MediaWiki Each kind of and so on Built in content types are
Definition: contenthandler.txt:5
used
you don t have to do a grep find to see where the $wgReverseTitle variable is used
Definition: hooks.txt:117
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:32
DatabaseInstaller\getInstallUserBox
getInstallUserBox()
Get a standard install-user fieldset.
Definition: DatabaseInstaller.php:520
DatabaseInstaller\setVarsFromRequest
setVarsFromRequest( $varNames)
Convenience function to set variables based on form data.
Definition: DatabaseInstaller.php:487
OracleInstaller\$internalDefaults
$internalDefaults
Definition: OracleInstaller.php:40
OracleInstaller
Class for setting up the MediaWiki database using Oracle.
Definition: OracleInstaller.php:30
OracleInstaller\preInstall
preInstall()
Allow DB installers a chance to make last-minute changes before installation occurs.
Definition: OracleInstaller.php:215
$vars
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
Definition: hooks.txt:1684
$error
usually copyright or history_copyright This message must be in HTML not wikitext $subpages will be ignored and the rest of subPageSubtitle() will run. 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink' whether MediaWiki currently thinks this is a CSS JS page Hooks may change this value to override the return value of Title::isCssOrJsPage(). 'TitleIsAlwaysKnown' whether MediaWiki currently thinks this page is known isMovable() always returns false. $title whether MediaWiki currently thinks this page is movable Hooks may change this value to override the return value of Title::isMovable(). 'TitleIsWikitextPage' whether MediaWiki currently thinks this is a wikitext page Hooks may change this value to override the return value of Title::isWikitextPage() 'TitleMove' use UploadVerification and UploadVerifyFile instead where the first element is the message key and the remaining elements are used as parameters to the message based on mime etc Preferred in most cases over UploadVerification object with all info about the upload string as detected by MediaWiki Handlers will typically only apply for specific mime types object & $error
Definition: hooks.txt:2578
$IP
$IP
Definition: WebStart.php:88
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:1632
Status\newFatal
static newFatal( $message)
Factory function for fatal errors.
Definition: Status.php:63