MediaWiki r64091 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r64090‎ | r64091 (on ViewVC)‎ | r64092 >
Date:20:38, 23 March 2010
Author:maxsem
Status:ok
Tags:
Comment:
Roughly working SQLite installer
Modified paths:

Diff [purge]

Index: branches/new-installer/phase3/maintenance/language/messages.inc
===================================================================
--- branches/new-installer/phase3/maintenance/language/messages.inc	(revision 64090)
+++ branches/new-installer/phase3/maintenance/language/messages.inc	(revision 64091)
@@ -3254,8 +3254,10 @@
 		'config-sqlite-name-help',
 		'config-sqlite-parent-unwritable',
 		'config-sqlite-mkdir-error',
-		'config-sqlite-unwritable',
+		'config-sqlite-dir-unwritable',
 		'config-sqlite-connection-error',
+		'config-sqlite-readonly',
+		'config-sqlite-cant-create-db',
 		'config-can-upgrade',
 		'config-upgrade-done',
 		'config-regenerate',
Index: branches/new-installer/phase3/includes/installer/WebInstaller.php
===================================================================
--- branches/new-installer/phase3/includes/installer/WebInstaller.php	(revision 64090)
+++ branches/new-installer/phase3/includes/installer/WebInstaller.php	(revision 64091)
@@ -77,6 +77,10 @@
 	 * @return array New session array
 	 */
 	function execute( $session ) {
+		//@todo decide if we really need this error handling
+		global $wgShowSQLErrors, $wgShowExceptionDetails, $wgShowDBErrorBacktrace;
+		$wgShowSQLErrors = $wgShowExceptionDetails = $wgShowDBErrorBacktrace = true;
+
 		$this->session = $session;
 		if ( isset( $session['settings'] ) ) {
 			$this->settings = $session['settings'] + $this->settings;
@@ -1531,9 +1535,11 @@
 
 		// Create tables
 		$this->startStage( 'config-install-tables' );
-		$queries = explode( ";", $schema->getSql() );
+		$queries = explode( ";", trim( $schema->getSql() ) );
 		foreach( $queries as $qry ) {
-			$db->query( $qry );
+			if ( strlen( $qry ) ) { // empty string is an invalid query
+				$db->query( $qry, __METHOD__ );
+			}
 		}
 		$this->endStage();
 
Index: branches/new-installer/phase3/includes/installer/SqliteInstaller.php
===================================================================
--- branches/new-installer/phase3/includes/installer/SqliteInstaller.php	(revision 64090)
+++ branches/new-installer/phase3/includes/installer/SqliteInstaller.php	(revision 64091)
@@ -40,8 +40,14 @@
 
 	function submitConnectForm() {
 		global $wgSQLiteDataDir;
-		$newValues = $this->setVarsFromRequest( array( 'wgSQLiteDataDir', 'wgDBname' ) );
-		$dir = $newValues['wgSQLiteDataDir'];
+		$this->setVarsFromRequest( array( 'wgSQLiteDataDir', 'wgDBname' ) );
+
+		$dir = realpath( $this->getVar( 'wgSQLiteDataDir' ) );
+		if ( !$dir ) {
+			// realpath() sometimes fails, especially on Windows
+			$dir = $this->getVar( 'wgSQLiteDataDir' );
+		}
+		$this->setVar( 'wgSQLiteDataDir', $dir );
 		if ( !is_dir( $dir ) ) {
 			if ( !is_writable( dirname( $dir ) ) ) {
 				return Status::newFatal( 'config-sqlite-parent-unwritable', $dir, dirname( $dir ) );
@@ -56,7 +62,7 @@
 			file_put_contents( "$dir/.htaccess", "Deny from all\n" );
 		}
 		if ( !is_writable( $dir ) ) {
-			return Status::newFatal( 'config-sqlite-unwritable', $dir );
+			return Status::newFatal( 'config-sqlite-dir-unwritable', $dir );
 		}
 		return Status::newGood();
 	}
@@ -101,6 +107,17 @@
 	}
 
 	function setupDatabase() {
+		$file = DatabaseSqlite::generateFileName( $this->getVar( 'wgSQLiteDataDir' ), $this->getVar( 'wgDBname' ) );
+		if ( file_exists( $file ) ) {
+			if ( !is_writable( $file ) ) {
+				return Status::newFatal( 'config-sqlite-readonly', $file );
+			}
+		} else {
+			if ( file_put_contents( $file, '' ) === false ) {
+				return Status::newFatal( 'config-sqlite-cant-create-db', $file );
+			}
+		}
+		return $this->getConnection();
 	}
 
 	function getLocalSettings() {
Index: branches/new-installer/phase3/languages/messages/MessagesEn.php
===================================================================
--- branches/new-installer/phase3/languages/messages/MessagesEn.php	(revision 64090)
+++ branches/new-installer/phase3/languages/messages/MessagesEn.php	(revision 64091)
@@ -4277,6 +4277,18 @@
 'config-sqlite-dir-help' => 'SQLite stores data into a file in the filesystem.
 This directory must be writable by the webserver.
 It should <strong>not</strong> accessible via the web.',
+'config-sqlite-readonly' => 'File $1 is not writeable.',
+'config-sqlite-name-help' => 'Choose a name that identifies your wiki. Do not use spaces or hyphens. This will be used for the SQLite data file name.',
+'config-sqlite-parent-unwritable' => 'Cannot create the data directory "$1", because the parent directory "$2" is not writable by the webserver.
+Please create this directory yourself, make it writable, and try again.',
+'config-sqlite-mkdir-error' => 'Error creating the data directory "$1".
+Please check the location and try again.',
+'config-sqlite-dir-unwritable' => 'Unable to write to the given directory: $1.
+Please change its permissions so that the webserver can write to it, and try again.',
+'config-sqlite-connection-error' => '$1.
+
+Check the data directory and database name below and try again.',
+'config-sqlite-cant-create-db' => 'Could not create database file $1.',
 'config-type-mysql' => 'MySQL',
 'config-type-postgres' => 'PostgreSQL',
 'config-type-sqlite' => 'SQLite',
@@ -4295,16 +4307,6 @@
 'config-invalid-schema' => 'Invalid schema for MediaWiki "$1". Please use only letters, numbers and underscores.',
 'config-invalid-ts2schema' => 'Invalid schema for tsearch2 "$1". Please use only letters, numbers and underscores.',
 'config-postgres-old' => 'PostgreSQL $1 or later is required, you have $2.',
-'config-sqlite-name-help' => 'Choose a name that identifies your wiki. Do not use spaces or hyphens. This will be used for the SQLite data file name.',
-'config-sqlite-parent-unwritable' => 'Cannot create the data directory "$1", because the parent directory "$2" is not writable by the webserver.
-Please create this directory yourself, make it writable, and try again.',
-'config-sqlite-mkdir-error' => 'Error creating the data directory "$1".
-Please check the location and try again.',
-'config-sqlite-unwritable' => 'Unable to write to the given directory: $1.
-Please change its permissions so that the webserver can write to it, and try again.',
-'config-sqlite-connection-error' => '$1.
-
-Check the data directory and database name below and try again.',
 'config-can-upgrade' => 'There are MediaWiki tables in this database. 
 To upgrade them to MediaWiki $1, click <strong>Continue</strong>.',
 'config-upgrade-done' => 'Upgrade complete. 

Status & tagging log

  • 14:13, 29 March 2010 ^demon (Talk | contribs) changed the status of r64091 [removed: new added: ok]
Personal tools
Namespaces
Variants
Views
Actions
Site
Support
Download
Development
Communication
Toolbox