MediaWiki  1.23.2
SqliteInstaller.php
Go to the documentation of this file.
1 <?php
31  const MINIMUM_VERSION = '3.3.7';
32 
36  public $db;
37 
38  protected $globalNames = array(
39  'wgDBname',
40  'wgSQLiteDataDir',
41  );
42 
43  public function getName() {
44  return 'sqlite';
45  }
46 
47  public function isCompiled() {
48  return self::checkExtension( 'pdo_sqlite' );
49  }
50 
55  public function checkPrerequisites() {
57  // Bail out if SQLite is too old
58  $db = new DatabaseSqliteStandalone( ':memory:' );
59  if ( version_compare( $db->getServerVersion(), self::MINIMUM_VERSION, '<' ) ) {
60  $result->fatal( 'config-outdated-sqlite', $db->getServerVersion(), self::MINIMUM_VERSION );
61  }
62  // Check for FTS3 full-text search module
63  if ( DatabaseSqlite::getFulltextSearchModule() != 'FTS3' ) {
64  $result->warning( 'config-no-fts3' );
65  }
66 
67  return $result;
68  }
69 
70  public function getGlobalDefaults() {
71  if ( isset( $_SERVER['DOCUMENT_ROOT'] ) ) {
72  $path = str_replace(
73  array( '/', '\\' ),
74  DIRECTORY_SEPARATOR,
75  dirname( $_SERVER['DOCUMENT_ROOT'] ) . '/data'
76  );
77 
78  return array( 'wgSQLiteDataDir' => $path );
79  } else {
80  return array();
81  }
82  }
83 
84  public function getConnectForm() {
85  return $this->getTextBox(
86  'wgSQLiteDataDir',
87  'config-sqlite-dir', array(),
88  $this->parent->getHelpBox( 'config-sqlite-dir-help' )
89  ) .
90  $this->getTextBox(
91  'wgDBname',
92  'config-db-name',
93  array(),
94  $this->parent->getHelpBox( 'config-sqlite-name-help' )
95  );
96  }
97 
105  private static function realpath( $path ) {
106  $result = realpath( $path );
107  if ( !$result ) {
108  return $path;
109  }
110 
111  return $result;
112  }
113 
117  public function submitConnectForm() {
118  $this->setVarsFromRequest( array( 'wgSQLiteDataDir', 'wgDBname' ) );
119 
120  # Try realpath() if the directory already exists
121  $dir = self::realpath( $this->getVar( 'wgSQLiteDataDir' ) );
122  $result = self::dataDirOKmaybeCreate( $dir, true /* create? */ );
123  if ( $result->isOK() ) {
124  # Try expanding again in case we've just created it
125  $dir = self::realpath( $dir );
126  $this->setVar( 'wgSQLiteDataDir', $dir );
127  }
128  # Table prefix is not used on SQLite, keep it empty
129  $this->setVar( 'wgDBprefix', '' );
130 
131  return $result;
132  }
133 
139  private static function dataDirOKmaybeCreate( $dir, $create = false ) {
140  if ( !is_dir( $dir ) ) {
141  if ( !is_writable( dirname( $dir ) ) ) {
142  $webserverGroup = Installer::maybeGetWebserverPrimaryGroup();
143  if ( $webserverGroup !== null ) {
144  return Status::newFatal(
145  'config-sqlite-parent-unwritable-group',
146  $dir, dirname( $dir ), basename( $dir ),
147  $webserverGroup
148  );
149  } else {
150  return Status::newFatal(
151  'config-sqlite-parent-unwritable-nogroup',
152  $dir, dirname( $dir ), basename( $dir )
153  );
154  }
155  }
156 
157  # Called early on in the installer, later we just want to sanity check
158  # if it's still writable
159  if ( $create ) {
161  $ok = wfMkdirParents( $dir, 0700, __METHOD__ );
163  if ( !$ok ) {
164  return Status::newFatal( 'config-sqlite-mkdir-error', $dir );
165  }
166  # Put a .htaccess file in in case the user didn't take our advice
167  file_put_contents( "$dir/.htaccess", "Deny from all\n" );
168  }
169  }
170  if ( !is_writable( $dir ) ) {
171  return Status::newFatal( 'config-sqlite-dir-unwritable', $dir );
172  }
173 
174  # We haven't blown up yet, fall through
175  return Status::newGood();
176  }
177 
181  public function openConnection() {
182  global $wgSQLiteDataDir;
183 
184  $status = Status::newGood();
185  $dir = $this->getVar( 'wgSQLiteDataDir' );
186  $dbName = $this->getVar( 'wgDBname' );
187  try {
188  # @todo FIXME: Need more sensible constructor parameters, e.g. single associative array
189  # Setting globals kind of sucks
190  $wgSQLiteDataDir = $dir;
191  $db = new DatabaseSqlite( false, false, false, $dbName );
192  $status->value = $db;
193  } catch ( DBConnectionError $e ) {
194  $status->fatal( 'config-sqlite-connection-error', $e->getMessage() );
195  }
196 
197  return $status;
198  }
199 
203  public function needsUpgrade() {
204  $dir = $this->getVar( 'wgSQLiteDataDir' );
205  $dbName = $this->getVar( 'wgDBname' );
206  // Don't create the data file yet
207  if ( !file_exists( DatabaseSqlite::generateFileName( $dir, $dbName ) ) ) {
208  return false;
209  }
210 
211  // If the data file exists, look inside it
212  return parent::needsUpgrade();
213  }
214 
218  public function setupDatabase() {
219  $dir = $this->getVar( 'wgSQLiteDataDir' );
220 
221  # Sanity check. We checked this before but maybe someone deleted the
222  # data dir between then and now
223  $dir_status = self::dataDirOKmaybeCreate( $dir, false /* create? */ );
224  if ( !$dir_status->isOK() ) {
225  return $dir_status;
226  }
227 
228  $db = $this->getVar( 'wgDBname' );
230  if ( file_exists( $file ) ) {
231  if ( !is_writable( $file ) ) {
232  return Status::newFatal( 'config-sqlite-readonly', $file );
233  }
234  } else {
235  if ( file_put_contents( $file, '' ) === false ) {
236  return Status::newFatal( 'config-sqlite-cant-create-db', $file );
237  }
238  }
239  // nuke the unused settings for clarity
240  $this->setVar( 'wgDBserver', '' );
241  $this->setVar( 'wgDBuser', '' );
242  $this->setVar( 'wgDBpassword', '' );
243  $this->setupSchemaVars();
244 
245  return $this->getConnection();
246  }
247 
251  public function createTables() {
252  $status = parent::createTables();
253 
254  return $this->setupSearchIndex( $status );
255  }
256 
261  public function setupSearchIndex( &$status ) {
262  global $IP;
263 
265  $fts3tTable = $this->db->checkForEnabledSearch();
266  if ( $fts3tTable && !$module ) {
267  $status->warning( 'config-sqlite-fts3-downgrade' );
268  $this->db->sourceFile( "$IP/maintenance/sqlite/archives/searchindex-no-fts.sql" );
269  } elseif ( !$fts3tTable && $module == 'FTS3' ) {
270  $this->db->sourceFile( "$IP/maintenance/sqlite/archives/searchindex-fts3.sql" );
271  }
272 
273  return $status;
274  }
275 
279  public function getLocalSettings() {
280  $dir = LocalSettingsGenerator::escapePhpString( $this->getVar( 'wgSQLiteDataDir' ) );
281 
282  return "# SQLite-specific settings
283 \$wgSQLiteDataDir = \"{$dir}\";";
284  }
285 }
SqliteInstaller\setupDatabase
setupDatabase()
Definition: SqliteInstaller.php:217
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. $reader:XMLReader object $logInfo:Array of information Return false to stop further processing of the tag 'ImportHandlePageXMLTag':When parsing a XML tag in a page. $reader:XMLReader object $pageInfo:Array of information Return false to stop further processing of the tag 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information Return false to stop further processing of the tag 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. $reader:XMLReader object Return false to stop further processing of the tag 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. $reader:XMLReader object $revisionInfo:Array of information Return false to stop further processing of the tag 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. $title:Title object for the current page $request:WebRequest $ignoreRedirect:boolean to skip redirect check $target:Title/string of redirect target $article:Article object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) $article:article(object) being checked 'IsTrustedProxy':Override the result of wfIsTrustedProxy() $ip:IP being check $result:Change this value to override the result of wfIsTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of User::isValidEmailAddr(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetMagic':DEPRECATED, use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetSpecialPageAliases':DEPRECATED, use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Associative array mapping language codes to prefixed links of the form "language:title". & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LinkBegin':Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1528
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
SqliteInstaller
Class for setting up the MediaWiki database using SQLLite.
Definition: SqliteInstaller.php:30
SqliteInstaller\openConnection
openConnection()
Definition: SqliteInstaller.php:180
DatabaseInstaller\checkExtension
static checkExtension( $name)
Convenience function.
Definition: DatabaseInstaller.php:326
wfMkdirParents
wfMkdirParents( $dir, $mode=null, $caller=null)
Make directory, and make all parent directories if they don't exist.
Definition: GlobalFunctions.php:2590
SqliteInstaller\dataDirOKmaybeCreate
static dataDirOKmaybeCreate( $dir, $create=false)
Definition: SqliteInstaller.php:138
DatabaseInstaller\getConnection
getConnection()
Connect to the database using the administrative user/password currently defined in the session.
Definition: DatabaseInstaller.php:145
wfSuppressWarnings
wfSuppressWarnings( $end=false)
Reference-counted warning suppression.
Definition: GlobalFunctions.php:2387
DatabaseSqliteStandalone
This class allows simple acccess to a SQLite database independently from main database settings.
Definition: DatabaseSqlite.php:974
Status\newGood
static newGood( $value=null)
Factory function for good results.
Definition: Status.php:77
SqliteInstaller\getConnectForm
getConnectForm()
Get HTML for a web form that configures this database.
Definition: SqliteInstaller.php:83
SqliteInstaller\isCompiled
isCompiled()
Definition: SqliteInstaller.php:46
DatabaseInstaller\getTextBox
getTextBox( $var, $label, $attribs=array(), $helpData="")
Get a labelled text box to configure a local variable.
Definition: DatabaseInstaller.php:393
DatabaseSqlite\generateFileName
static generateFileName( $dir, $dbName)
Generates a database file name.
Definition: DatabaseSqlite.php:170
SqliteInstaller\$globalNames
$globalNames
Definition: SqliteInstaller.php:37
SqliteInstaller\realpath
static realpath( $path)
Safe wrapper for PHP's realpath() that fails gracefully if it's unable to canonicalize the path.
Definition: SqliteInstaller.php:104
wfRestoreWarnings
wfRestoreWarnings()
Restore error level to previous value.
Definition: GlobalFunctions.php:2417
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
DBConnectionError
Definition: DatabaseError.php:98
SqliteInstaller\MINIMUM_VERSION
const MINIMUM_VERSION
Definition: SqliteInstaller.php:31
$ok
$ok
Definition: UtfNormalTest.php:71
SqliteInstaller\setupSearchIndex
setupSearchIndex(&$status)
Definition: SqliteInstaller.php:260
SqliteInstaller\submitConnectForm
submitConnectForm()
Definition: SqliteInstaller.php:116
DatabaseInstaller\getVar
getVar( $var, $default=null)
Get a variable, taking local defaults into account.
Definition: DatabaseInstaller.php:363
SqliteInstaller\createTables
createTables()
Definition: SqliteInstaller.php:250
DatabaseSqlite
Definition: DatabaseSqlite.php:28
DatabaseInstaller
Base class for DBMS-specific installation helper classes.
Definition: DatabaseInstaller.php:30
SqliteInstaller\getGlobalDefaults
getGlobalDefaults()
Get a name=>value map of MW configuration globals that overrides.
Definition: SqliteInstaller.php:69
DatabaseSqlite\getServerVersion
getServerVersion()
Definition: DatabaseSqlite.php:668
$file
if(PHP_SAPI !='cli') $file
Definition: UtfNormalTest2.php:30
SqliteInstaller\checkPrerequisites
checkPrerequisites()
Definition: SqliteInstaller.php:54
SqliteInstaller\getLocalSettings
getLocalSettings()
Definition: SqliteInstaller.php:278
$dir
if(count( $args)==0) $dir
Definition: importImages.php:49
SqliteInstaller\getName
getName()
Return the internal name, e.g.
Definition: SqliteInstaller.php:42
$path
$path
Definition: NoLocalSettings.php:35
SqliteInstaller\needsUpgrade
needsUpgrade()
Definition: SqliteInstaller.php:202
DatabaseInstaller\setVar
setVar( $name, $value)
Convenience alias for $this->parent->setVar()
Definition: DatabaseInstaller.php:380
DatabaseInstaller\setVarsFromRequest
setVarsFromRequest( $varNames)
Convenience function to set variables based on form data.
Definition: DatabaseInstaller.php:487
LocalSettingsGenerator\escapePhpString
static escapePhpString( $string)
Returns the escaped version of a string of php code.
Definition: LocalSettingsGenerator.php:111
$e
if( $useReadline) $e
Definition: eval.php:66
SqliteInstaller\$db
DatabaseSqlite $db
Definition: SqliteInstaller.php:35
$IP
$IP
Definition: WebStart.php:88
DatabaseSqlite\getFulltextSearchModule
static getFulltextSearchModule()
Returns version of currently supported SQLite fulltext search module or false if none present.
Definition: DatabaseSqlite.php:196
Installer\maybeGetWebserverPrimaryGroup
static maybeGetWebserverPrimaryGroup()
On POSIX systems return the primary group of the webserver we're running under.
Definition: Installer.php:556
Status\newFatal
static newFatal( $message)
Factory function for fatal errors.
Definition: Status.php:63