Merge "docs: Fix typo"
[mediawiki.git] / includes / installer / SqliteConnectForm.php
blob4080dd3808b679e1632db46631a9b86aa2b57ad0
1 <?php
3 namespace MediaWiki\Installer;
5 use MediaWiki\Installer\Task\SqliteUtils;
6 use MediaWiki\Status\Status;
8 /**
9 * @internal
11 class SqliteConnectForm extends DatabaseConnectForm {
13 public function getHtml() {
14 return $this->getTextBox(
15 'wgSQLiteDataDir',
16 'config-sqlite-dir', [],
17 $this->webInstaller->getHelpBox( 'config-sqlite-dir-help' )
18 ) .
19 $this->getTextBox(
20 'wgDBname',
21 'config-db-name',
22 [],
23 $this->webInstaller->getHelpBox( 'config-sqlite-name-help' )
27 /**
28 * @return Status
30 public function submit() {
31 $this->setVarsFromRequest( [ 'wgSQLiteDataDir', 'wgDBname' ] );
33 # Try realpath() if the directory already exists
34 $dir = $this->realpath( $this->getVar( 'wgSQLiteDataDir' ) );
35 $result = $this->getSqliteUtils()->checkDataDir( $dir );
36 if ( $result->isOK() ) {
37 # Try expanding again in case we've just created it
38 $dir = $this->realpath( $dir );
39 $this->setVar( 'wgSQLiteDataDir', $dir );
41 # Table prefix is not used on SQLite, keep it empty
42 $this->setVar( 'wgDBprefix', '' );
44 return $result;
47 /**
48 * Safe wrapper for PHP's realpath() that fails gracefully if it's unable to canonicalize the path.
50 * @param string $path
52 * @return string
54 private function realpath( $path ) {
55 return realpath( $path ) ?: $path;
58 private function getSqliteUtils() {
59 return new SqliteUtils;