MediaWiki  1.23.13
DatabaseInstaller.php
Go to the documentation of this file.
1 <?php
30 abstract class DatabaseInstaller {
31 
39  public $parent;
40 
46  public $db = null;
47 
53  protected $internalDefaults = array();
54 
60  protected $globalNames = array();
61 
65  abstract public function getName();
66 
70  abstract public function isCompiled();
71 
77  public function checkPrerequisites() {
78  return Status::newGood();
79  }
80 
88  abstract public function getConnectForm();
89 
99  abstract public function submitConnectForm();
100 
108  public function getSettingsForm() {
109  return false;
110  }
111 
118  public function submitSettingsForm() {
119  return Status::newGood();
120  }
121 
130  abstract public function openConnection();
131 
138  abstract public function setupDatabase();
139 
149  public function getConnection() {
150  if ( $this->db ) {
151  return Status::newGood( $this->db );
152  }
153 
154  $status = $this->openConnection();
155  if ( $status->isOK() ) {
156  $this->db = $status->value;
157  // Enable autocommit
158  $this->db->clearFlag( DBO_TRX );
159  $this->db->commit( __METHOD__ );
160  }
161 
162  return $status;
163  }
164 
170  public function createTables() {
171  $status = $this->getConnection();
172  if ( !$status->isOK() ) {
173  return $status;
174  }
175  $this->db->selectDB( $this->getVar( 'wgDBname' ) );
176 
177  if ( $this->db->tableExists( 'archive', __METHOD__ ) ) {
178  $status->warning( 'config-install-tables-exist' );
179  $this->enableLB();
180 
181  return $status;
182  }
183 
184  $this->db->setFlag( DBO_DDLMODE ); // For Oracle's handling of schema files
185  $this->db->begin( __METHOD__ );
186 
187  $error = $this->db->sourceFile( $this->db->getSchemaPath() );
188  if ( $error !== true ) {
189  $this->db->reportQueryError( $error, 0, '', __METHOD__ );
190  $this->db->rollback( __METHOD__ );
191  $status->fatal( 'config-install-tables-failed', $error );
192  } else {
193  $this->db->commit( __METHOD__ );
194  }
195  // Resume normal operations
196  if ( $status->isOk() ) {
197  $this->enableLB();
198  }
199 
200  return $status;
201  }
202 
207  public function createExtensionTables() {
208  $status = $this->getConnection();
209  if ( !$status->isOK() ) {
210  return $status;
211  }
212 
213  // Now run updates to create tables for old extensions
214  DatabaseUpdater::newForDB( $this->db )->doUpdates( array( 'extensions' ) );
215 
216  return $status;
217  }
218 
224  abstract public function getLocalSettings();
225 
231  public function getSchemaVars() {
232  return array();
233  }
234 
241  public function setupSchemaVars() {
242  $status = $this->getConnection();
243  if ( $status->isOK() ) {
244  $status->value->setSchemaVars( $this->getSchemaVars() );
245  } else {
246  $msg = __METHOD__ . ': unexpected error while establishing'
247  . ' a database connection with message: '
248  . $status->getMessage()->plain();
249  throw new MWException( $msg );
250  }
251  }
252 
258  public function enableLB() {
259  $status = $this->getConnection();
260  if ( !$status->isOK() ) {
261  throw new MWException( __METHOD__ . ': unexpected DB connection error' );
262  }
264  'connection' => $status->value ) ) );
265  }
266 
272  public function doUpgrade() {
273  $this->setupSchemaVars();
274  $this->enableLB();
275 
276  $ret = true;
277  ob_start( array( $this, 'outputHandler' ) );
278  $up = DatabaseUpdater::newForDB( $this->db );
279  try {
280  $up->doUpdates();
281  } catch ( MWException $e ) {
282  echo "\nAn error occurred:\n";
283  echo $e->getText();
284  $ret = false;
285  }
286  $up->purgeCache();
287  ob_end_flush();
288 
289  return $ret;
290  }
291 
297  public function preInstall() {
298  }
299 
303  public function preUpgrade() {
304  }
305 
310  public function getGlobalNames() {
311  return $this->globalNames;
312  }
313 
319  public function __construct( $parent ) {
320  $this->parent = $parent;
321  }
322 
330  protected static function checkExtension( $name ) {
331  return extension_loaded( $name );
332  }
333 
338  public function getReadableName() {
339  // Messages: config-type-mysql, config-type-postgres, config-type-sqlite,
340  // config-type-oracle
341  return wfMessage( 'config-type-' . $this->getName() )->text();
342  }
343 
349  public function getGlobalDefaults() {
350  return array();
351  }
352 
357  public function getInternalDefaults() {
359  }
360 
367  public function getVar( $var, $default = null ) {
368  $defaults = $this->getGlobalDefaults();
369  $internal = $this->getInternalDefaults();
370  if ( isset( $defaults[$var] ) ) {
371  $default = $defaults[$var];
372  } elseif ( isset( $internal[$var] ) ) {
373  $default = $internal[$var];
374  }
375 
376  return $this->parent->getVar( $var, $default );
377  }
378 
384  public function setVar( $name, $value ) {
385  $this->parent->setVar( $name, $value );
386  }
387 
397  public function getTextBox( $var, $label, $attribs = array(), $helpData = "" ) {
398  $name = $this->getName() . '_' . $var;
399  $value = $this->getVar( $var );
400  if ( !isset( $attribs ) ) {
401  $attribs = array();
402  }
403 
404  return $this->parent->getTextBox( array(
405  'var' => $var,
406  'label' => $label,
407  'attribs' => $attribs,
408  'controlName' => $name,
409  'value' => $value,
410  'help' => $helpData
411  ) );
412  }
413 
424  public function getPasswordBox( $var, $label, $attribs = array(), $helpData = "" ) {
425  $name = $this->getName() . '_' . $var;
426  $value = $this->getVar( $var );
427  if ( !isset( $attribs ) ) {
428  $attribs = array();
429  }
430 
431  return $this->parent->getPasswordBox( array(
432  'var' => $var,
433  'label' => $label,
434  'attribs' => $attribs,
435  'controlName' => $name,
436  'value' => $value,
437  'help' => $helpData
438  ) );
439  }
440 
450  public function getCheckBox( $var, $label, $attribs = array(), $helpData = "" ) {
451  $name = $this->getName() . '_' . $var;
452  $value = $this->getVar( $var );
453 
454  return $this->parent->getCheckBox( array(
455  'var' => $var,
456  'label' => $label,
457  'attribs' => $attribs,
458  'controlName' => $name,
459  'value' => $value,
460  'help' => $helpData
461  ) );
462  }
463 
477  public function getRadioSet( $params ) {
478  $params['controlName'] = $this->getName() . '_' . $params['var'];
479  $params['value'] = $this->getVar( $params['var'] );
480 
481  return $this->parent->getRadioSet( $params );
482  }
483 
491  public function setVarsFromRequest( $varNames ) {
492  return $this->parent->setVarsFromRequest( $varNames, $this->getName() . '_' );
493  }
494 
505  public function needsUpgrade() {
506  $status = $this->getConnection();
507  if ( !$status->isOK() ) {
508  return false;
509  }
510 
511  if ( !$this->db->selectDB( $this->getVar( 'wgDBname' ) ) ) {
512  return false;
513  }
514 
515  return $this->db->tableExists( 'cur', __METHOD__ ) ||
516  $this->db->tableExists( 'revision', __METHOD__ );
517  }
518 
524  public function getInstallUserBox() {
525  return Html::openElement( 'fieldset' ) .
526  Html::element( 'legend', array(), wfMessage( 'config-db-install-account' )->text() ) .
527  $this->getTextBox(
528  '_InstallUser',
529  'config-db-username',
530  array( 'dir' => 'ltr' ),
531  $this->parent->getHelpBox( 'config-db-install-username' )
532  ) .
533  $this->getPasswordBox(
534  '_InstallPassword',
535  'config-db-password',
536  array( 'dir' => 'ltr' ),
537  $this->parent->getHelpBox( 'config-db-install-password' )
538  ) .
539  Html::closeElement( 'fieldset' );
540  }
541 
546  public function submitInstallUserBox() {
547  $this->setVarsFromRequest( array( '_InstallUser', '_InstallPassword' ) );
548 
549  return Status::newGood();
550  }
551 
559  public function getWebUserBox( $noCreateMsg = false ) {
560  $wrapperStyle = $this->getVar( '_SameAccount' ) ? 'display: none' : '';
561  $s = Html::openElement( 'fieldset' ) .
562  Html::element( 'legend', array(), wfMessage( 'config-db-web-account' )->text() ) .
563  $this->getCheckBox(
564  '_SameAccount', 'config-db-web-account-same',
565  array( 'class' => 'hideShowRadio', 'rel' => 'dbOtherAccount' )
566  ) .
567  Html::openElement( 'div', array( 'id' => 'dbOtherAccount', 'style' => $wrapperStyle ) ) .
568  $this->getTextBox( 'wgDBuser', 'config-db-username' ) .
569  $this->getPasswordBox( 'wgDBpassword', 'config-db-password' ) .
570  $this->parent->getHelpBox( 'config-db-web-help' );
571  if ( $noCreateMsg ) {
572  $s .= $this->parent->getWarningBox( wfMessage( $noCreateMsg )->plain() );
573  } else {
574  $s .= $this->getCheckBox( '_CreateDBAccount', 'config-db-web-create' );
575  }
576  $s .= Html::closeElement( 'div' ) . Html::closeElement( 'fieldset' );
577 
578  return $s;
579  }
580 
586  public function submitWebUserBox() {
587  $this->setVarsFromRequest(
588  array( 'wgDBuser', 'wgDBpassword', '_SameAccount', '_CreateDBAccount' )
589  );
590 
591  if ( $this->getVar( '_SameAccount' ) ) {
592  $this->setVar( 'wgDBuser', $this->getVar( '_InstallUser' ) );
593  $this->setVar( 'wgDBpassword', $this->getVar( '_InstallPassword' ) );
594  }
595 
596  if ( $this->getVar( '_CreateDBAccount' ) && strval( $this->getVar( 'wgDBpassword' ) ) == '' ) {
597  return Status::newFatal( 'config-db-password-empty', $this->getVar( 'wgDBuser' ) );
598  }
599 
600  return Status::newGood();
601  }
602 
608  public function populateInterwikiTable() {
609  $status = $this->getConnection();
610  if ( !$status->isOK() ) {
611  return $status;
612  }
613  $this->db->selectDB( $this->getVar( 'wgDBname' ) );
614 
615  if ( $this->db->selectRow( 'interwiki', '*', array(), __METHOD__ ) ) {
616  $status->warning( 'config-install-interwiki-exists' );
617 
618  return $status;
619  }
620  global $IP;
622  $rows = file( "$IP/maintenance/interwiki.list",
623  FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
625  $interwikis = array();
626  if ( !$rows ) {
627  return Status::newFatal( 'config-install-interwiki-list' );
628  }
629  foreach ( $rows as $row ) {
630  $row = preg_replace( '/^\s*([^#]*?)\s*(#.*)?$/', '\\1', $row ); // strip comments - whee
631  if ( $row == "" ) {
632  continue;
633  }
634  $row .= "||";
635  $interwikis[] = array_combine(
636  array( 'iw_prefix', 'iw_url', 'iw_local', 'iw_api', 'iw_wikiid' ),
637  explode( '|', $row )
638  );
639  }
640  $this->db->insert( 'interwiki', $interwikis, __METHOD__ );
641 
642  return Status::newGood();
643  }
644 
645  public function outputHandler( $string ) {
646  return htmlspecialchars( $string );
647  }
648 }
DatabaseInstaller\$globalNames
array $globalNames
Array of MW configuration globals this class uses.
Definition: DatabaseInstaller.php:56
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
DatabaseInstaller\checkExtension
static checkExtension( $name)
Convenience function.
Definition: DatabaseInstaller.php:326
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\doUpgrade
doUpgrade()
Perform database upgrades.
Definition: DatabaseInstaller.php:268
WebInstaller
Class for the core installer web interface.
Definition: WebInstaller.php:30
DatabaseInstaller\getConnection
getConnection()
Connect to the database using the administrative user/password currently defined in the session.
Definition: DatabaseInstaller.php:145
$ret
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 & $ret
Definition: hooks.txt:1530
wfSuppressWarnings
wfSuppressWarnings( $end=false)
Reference-counted warning suppression.
Definition: GlobalFunctions.php:2434
DatabaseInstaller\getPasswordBox
getPasswordBox( $var, $label, $attribs=array(), $helpData="")
Get a labelled password box to configure a local variable.
Definition: DatabaseInstaller.php:420
Status\newGood
static newGood( $value=null)
Factory function for good results.
Definition: Status.php:77
DatabaseInstaller\getCheckBox
getCheckBox( $var, $label, $attribs=array(), $helpData="")
Get a labelled checkbox to configure a local boolean variable.
Definition: DatabaseInstaller.php:446
$params
$params
Definition: styleTest.css.php:40
DatabaseInstaller\checkPrerequisites
checkPrerequisites()
Checks for installation prerequisites other than those checked by isCompiled()
Definition: DatabaseInstaller.php:73
DatabaseInstaller\getSchemaVars
getSchemaVars()
Override this to provide DBMS-specific schema variables, to be substituted into tables....
Definition: DatabaseInstaller.php:227
$s
$s
Definition: mergeMessageFileList.php:156
DatabaseInstaller\preUpgrade
preUpgrade()
Allow DB installers a chance to make checks before upgrade.
Definition: DatabaseInstaller.php:299
DatabaseInstaller\preInstall
preInstall()
Allow DB installers a chance to make last-minute changes before installation occurs.
Definition: DatabaseInstaller.php:293
DatabaseInstaller\submitSettingsForm
submitSettingsForm()
Set variables based on the request array, assuming it was submitted via the form return by getSetting...
Definition: DatabaseInstaller.php:114
DatabaseInstaller\getLocalSettings
getLocalSettings()
Get the DBMS-specific options for LocalSettings.php generation.
DatabaseInstaller\getTextBox
getTextBox( $var, $label, $attribs=array(), $helpData="")
Get a labelled text box to configure a local variable.
Definition: DatabaseInstaller.php:393
DatabaseInstaller\getReadableName
getReadableName()
Get the internationalised name for this DBMS.
Definition: DatabaseInstaller.php:334
DatabaseInstaller\createTables
createTables()
Create database tables from scratch.
Definition: DatabaseInstaller.php:166
DatabaseInstaller\getInternalDefaults
getInternalDefaults()
Get a name=>value map of internal variables used during installation.
Definition: DatabaseInstaller.php:353
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
file
We ve cleaned up the code here by removing clumps of infrequently used code and moving them off somewhere else It s much easier for someone working with this code to see what s _really_ going and make changes or fix bugs In we can take all the code that deals with the little used title reversing we can concentrate it all in an extension file
Definition: hooks.txt:93
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
DatabaseInstaller\getConnectForm
getConnectForm()
Get HTML for a web form that configures this database.
MWException
MediaWiki exception.
Definition: MWException.php:26
wfRestoreWarnings
wfRestoreWarnings()
Restore error level to previous value.
Definition: GlobalFunctions.php:2464
DBO_DDLMODE
const DBO_DDLMODE
Definition: Defines.php:46
DatabaseUpdater\newForDB
static newForDB(&$db, $shared=false, $maintenance=null)
Definition: DatabaseUpdater.php:159
Html\element
static element( $element, $attribs=array(), $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:148
DatabaseInstaller\submitConnectForm
submitConnectForm()
Set variables based on the request array, assuming it was submitted via the form returned by getConne...
DatabaseInstaller\submitWebUserBox
submitWebUserBox()
Submit the form from getWebUserBox().
Definition: DatabaseInstaller.php:582
DatabaseInstaller\getName
getName()
Return the internal name, e.g.
DatabaseInstaller\outputHandler
outputHandler( $string)
Definition: DatabaseInstaller.php:641
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
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
DatabaseInstaller\getWebUserBox
getWebUserBox( $noCreateMsg=false)
Get a standard web-user fieldset.
Definition: DatabaseInstaller.php:555
DatabaseInstaller\getRadioSet
getRadioSet( $params)
Get a set of labelled radio buttons.
Definition: DatabaseInstaller.php:473
DatabaseInstaller\$db
DatabaseBase $db
The database connection.
Definition: DatabaseInstaller.php:44
DatabaseInstaller\getGlobalDefaults
getGlobalDefaults()
Get a name=>value map of MW configuration globals that overrides.
Definition: DatabaseInstaller.php:345
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
$value
$value
Definition: styleTest.css.php:45
DatabaseInstaller\getVar
getVar( $var, $default=null)
Get a variable, taking local defaults into account.
Definition: DatabaseInstaller.php:363
LBFactory\setInstance
static setInstance( $instance)
Set the instance to be the given object.
Definition: LBFactory.php:103
DatabaseBase
Database abstraction object.
Definition: Database.php:219
DatabaseInstaller\createExtensionTables
createExtensionTables()
Create the tables for each extension the user enabled.
Definition: DatabaseInstaller.php:203
DatabaseInstaller\submitInstallUserBox
submitInstallUserBox()
Submit a standard install user fieldset.
Definition: DatabaseInstaller.php:542
DatabaseInstaller
Base class for DBMS-specific installation helper classes.
Definition: DatabaseInstaller.php:30
DatabaseInstaller\getGlobalNames
getGlobalNames()
Get an array of MW configuration globals that will be configured by this class.
Definition: DatabaseInstaller.php:306
DatabaseInstaller\getSettingsForm
getSettingsForm()
Get HTML for a web form that retrieves settings used for installation.
Definition: DatabaseInstaller.php:104
DatabaseInstaller\openConnection
openConnection()
Open a connection to the database using the administrative user/password currently defined in the ses...
DatabaseInstaller\enableLB
enableLB()
Set up LBFactory so that wfGetDB() etc.
Definition: DatabaseInstaller.php:254
DatabaseInstaller\populateInterwikiTable
populateInterwikiTable()
Common function for databases that don't understand the MySQLish syntax of interwiki....
Definition: DatabaseInstaller.php:604
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
DatabaseInstaller\setVar
setVar( $name, $value)
Convenience alias for $this->parent->setVar()
Definition: DatabaseInstaller.php:380
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
DatabaseInstaller\$parent
WebInstaller $parent
The Installer object.
Definition: DatabaseInstaller.php:38
DatabaseInstaller\isCompiled
isCompiled()
DatabaseInstaller\setupDatabase
setupDatabase()
Create the database and return a Status object indicating success or failure.
$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
$attribs
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 & $attribs
Definition: hooks.txt:1530
$IP
$IP
Definition: WebStart.php:88
LBFactorySingle
An LBFactory class that always returns a single database object.
Definition: LBFactorySingle.php:27
DBO_TRX
const DBO_TRX
Definition: Defines.php:42
DatabaseInstaller\$internalDefaults
array $internalDefaults
Internal variables for installation.
Definition: DatabaseInstaller.php:50
$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
DatabaseInstaller\__construct
__construct( $parent)
Construct and initialise parent.
Definition: DatabaseInstaller.php:315
DatabaseInstaller\needsUpgrade
needsUpgrade()
Determine whether an existing installation of MediaWiki is present in the configured administrative c...
Definition: DatabaseInstaller.php:501
Status\newFatal
static newFatal( $message)
Factory function for fatal errors.
Definition: Status.php:63