63 $db = DatabaseSqlite::newStandaloneInstance(
':memory:' );
66 if ( DatabaseSqlite::getFulltextSearchModule() !=
'FTS3' ) {
67 $result->warning(
'config-no-fts3' );
75 $defaults = parent::getGlobalDefaults();
76 if ( !empty( $_SERVER[
'DOCUMENT_ROOT'] ) ) {
77 $path = dirname( $_SERVER[
'DOCUMENT_ROOT'] );
82 $defaults[
'wgSQLiteDataDir'] = str_replace(
93 'config-sqlite-dir', [],
94 $this->parent->getHelpBox(
'config-sqlite-dir-help' )
100 $this->parent->getHelpBox(
'config-sqlite-name-help' )
126 # Try realpath() if the directory already exists
129 if ( $result->isOK() ) {
130 # Try expanding again in case we've just created it
132 $this->
setVar(
'wgSQLiteDataDir', $dir );
134 # Table prefix is not used on SQLite, keep it empty
135 $this->
setVar(
'wgDBprefix',
'' );
146 if ( is_dir( $dir ) ) {
147 if ( !is_readable( $dir ) ) {
148 return Status::newFatal(
'config-sqlite-dir-unwritable', $dir );
152 if ( !is_writable( dirname( $dir ) ) ) {
154 if ( $webserverGroup !==
null ) {
155 return Status::newFatal(
156 'config-sqlite-parent-unwritable-group',
157 $dir, dirname( $dir ), basename( $dir ),
162 'config-sqlite-parent-unwritable-nogroup',
163 $dir, dirname( $dir ), basename( $dir )
176 if ( !is_dir( $dir ) ) {
177 Wikimedia\suppressWarnings();
179 Wikimedia\restoreWarnings();
181 return Status::newFatal(
'config-sqlite-mkdir-error', $dir );
184 # Put a .htaccess file in in case the user didn't take our advice
185 file_put_contents(
"$dir/.htaccess",
"Deny from all\n" );
186 return Status::newGood();
193 $status = Status::newGood();
194 $dir = $this->getVar(
'wgSQLiteDataDir' );
195 $dbName = $this->getVar(
'wgDBname' );
197 # @todo FIXME: Need more sensible constructor parameters, e.g. single associative array
198 $db = Database::factory(
'sqlite', [
'dbname' => $dbName,
'dbDirectory' => $dir ] );
199 $status->value = $db;
201 $status->fatal(
'config-sqlite-connection-error', $e->getMessage() );
211 $dir = $this->getVar(
'wgSQLiteDataDir' );
212 $dbName = $this->getVar(
'wgDBname' );
214 if ( !file_exists( DatabaseSqlite::generateFileName( $dir, $dbName ) ) ) {
219 return parent::needsUpgrade();
226 $dir = $this->getVar(
'wgSQLiteDataDir' );
228 # Sanity check (Only available in web installation). We checked this before but maybe someone
229 # deleted the data dir between then and now
230 $dir_status = self::checkDataDir( $dir );
231 if ( $dir_status->isGood() ) {
232 $res = self::createDataDir( $dir );
233 if ( !
$res->isGood() ) {
240 $db = $this->getVar(
'wgDBname' );
242 # Make the main and cache stub DB files
243 $status = Status::newGood();
244 $status->merge( $this->makeStubDBFile( $dir, $db ) );
245 $status->merge( $this->makeStubDBFile( $dir,
"wikicache" ) );
246 $status->merge( $this->makeStubDBFile( $dir,
"{$db}_l10n_cache" ) );
247 $status->merge( $this->makeStubDBFile( $dir,
"{$db}_jobqueue" ) );
248 if ( !$status->isOK() ) {
252 # Nuke the unused settings for clarity
253 $this->setVar(
'wgDBserver',
'' );
254 $this->setVar(
'wgDBuser',
'' );
255 $this->setVar(
'wgDBpassword',
'' );
256 $this->setupSchemaVars();
258 # Create the l10n cache DB
260 $conn = Database::factory(
261 'sqlite', [
'dbname' =>
"{$db}_l10n_cache",
'dbDirectory' => $dir ] );
262 # @todo: don't duplicate l10n_cache definition, though it's very simple
265 CREATE TABLE l10n_cache (
266 lc_lang BLOB NOT NULL,
267 lc_key TEXT NOT NULL,
268 lc_value BLOB NOT NULL,
269 PRIMARY KEY (lc_lang, lc_key)
272 $conn->query( $sql );
273 $conn->query(
"PRAGMA journal_mode=WAL" );
276 return Status::newFatal(
'config-sqlite-connection-error', $e->getMessage() );
279 # Create the job queue DB
281 $conn = Database::factory(
282 'sqlite', [
'dbname' =>
"{$db}_jobqueue",
'dbDirectory' => $dir ] );
283 # @todo: don't duplicate job definition, though it's very static
287 job_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
288 job_cmd BLOB NOT NULL
default '',
289 job_namespace INTEGER NOT NULL,
290 job_title TEXT NOT NULL,
291 job_timestamp BLOB NULL
default NULL,
292 job_params BLOB NOT NULL,
293 job_random integer NOT NULL
default 0,
294 job_attempts integer NOT NULL
default 0,
295 job_token BLOB NOT NULL
default '',
296 job_token_timestamp BLOB NULL
default NULL,
297 job_sha1 BLOB NOT NULL
default ''
299 CREATE INDEX job_sha1 ON job (job_sha1);
300 CREATE INDEX job_cmd_token ON job (job_cmd,job_token,job_random);
301 CREATE INDEX job_cmd_token_id ON job (job_cmd,job_token,job_id);
302 CREATE INDEX job_cmd ON job (job_cmd, job_namespace, job_title, job_params);
303 CREATE INDEX job_timestamp ON job (job_timestamp);
305 $conn->query( $sql );
306 $conn->query(
"PRAGMA journal_mode=WAL" );
309 return Status::newFatal(
'config-sqlite-connection-error', $e->getMessage() );
313 return $this->getConnection();
322 $file = DatabaseSqlite::generateFileName( $dir, $db );
323 if ( file_exists(
$file ) ) {
324 if ( !is_writable(
$file ) ) {
325 return Status::newFatal(
'config-sqlite-readonly',
$file );
327 } elseif ( file_put_contents(
$file,
'' ) ===
false ) {
328 return Status::newFatal(
'config-sqlite-cant-create-db',
$file );
331 return Status::newGood();
338 $status = parent::createTables();
340 return $this->setupSearchIndex( $status );
350 $module = DatabaseSqlite::getFulltextSearchModule();
351 $searchIndexSql = (string)$this->db->selectField(
352 $this->db->addIdentifierQuotes(
'sqlite_master' ),
354 [
'tbl_name' => $this->db->tableName(
'searchindex',
'raw' ) ],
357 $fts3tTable = ( stristr( $searchIndexSql,
'fts' ) !== false );
359 if ( $fts3tTable && !$module ) {
360 $status->warning(
'config-sqlite-fts3-downgrade' );
361 $this->db->sourceFile(
"$IP/maintenance/sqlite/archives/searchindex-no-fts.sql" );
362 } elseif ( !$fts3tTable && $module ==
'FTS3' ) {
363 $this->db->sourceFile(
"$IP/maintenance/sqlite/archives/searchindex-fts3.sql" );
373 $dir = LocalSettingsGenerator::escapePhpString( $this->getVar(
'wgSQLiteDataDir' ) );
377 return "# SQLite-specific settings
378\$wgSQLiteDataDir = \"{$dir}\";
379\$wgObjectCaches[CACHE_DB] = [
380 'class' => SqlBagOStuff::class,
381 'loggroup' => 'SQLBagOStuff',
384 'dbname' => 'wikicache',
386 'variables' => [ 'synchronous' => 'NORMAL' ],
387 'dbDirectory' => \$wgSQLiteDataDir,
388 'trxMode' => 'IMMEDIATE',
392\$wgLocalisationCacheConf['storeServer'] = [
394 'dbname' => \"{\$wgDBname}_l10n_cache\",
396 'variables' => [ 'synchronous' => 'NORMAL' ],
397 'dbDirectory' => \$wgSQLiteDataDir,
398 'trxMode' => 'IMMEDIATE',
401\$wgJobTypeConf['default'] = [
402 'class' => 'JobQueueDB',
406 'dbname' => \"{\$wgDBname}_jobqueue\",
408 'variables' => [ 'synchronous' => 'NORMAL' ],
409 'dbDirectory' => \$wgSQLiteDataDir,
410 'trxMode' => 'IMMEDIATE',
wfMkdirParents( $dir, $mode=null, $caller=null)
Make directory, and make all parent directories if they don't exist.
Base class for DBMS-specific installation helper classes.
static checkExtension( $name)
Convenience function.
setVarsFromRequest( $varNames)
Convenience function to set variables based on form data.
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.
setVar( $name, $value)
Convenience alias for $this->parent->setVar()
static maybeGetWebserverPrimaryGroup()
On POSIX systems return the primary group of the webserver we're running under.
Class for setting up the MediaWiki database using SQLLite.
setupSearchIndex(&$status)
static createDataDir( $dir)
getGlobalDefaults()
Get a name=>value map of MW configuration globals for the default values.
makeStubDBFile( $dir, $db)
static realpath( $path)
Safe wrapper for PHP's realpath() that fails gracefully if it's unable to canonicalize the path.
getName()
Return the internal name, e.g.
getConnectForm()
Get HTML for a web form that configures this database.
static $notMinimumVersionMessage
static checkDataDir( $dir)
Check if the data directory is writable or can be created.
static newFatal( $message,... $parameters)
Factory function for fatal errors.
static newGood( $value=null)
Factory function for good results.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.