--- /dev/null
+<?
+
+function install_version_checks() {
+ if( !function_exists( "version_compare" ) ) {
+ # version_compare was introduced in 4.1.0
+ die( "Your PHP version is much too old; 4.0.x will _not_ work. 4.3.2 or higher is recommended. ABORTING.\n" );
+ }
+ if( version_compare( phpversion(), "4.3.2" ) < 0 ) {
+ echo "WARNING: PHP 4.3.2 or higher is recommended. Older versions from 4.1.x up may work but are not actively supported.\n\n";
+ }
+ if( !ini_get( "register_globals" ) ) {
+ echo "WARNING: register_globals is not on; MediaWiki currently relies on this option.\n\n";
+ }
+
+ if (!extension_loaded('mysql')) {
+ if (!dl('mysql.so')) {
+ print "Could not load MySQL driver! Please compile ".
+ "php --with-mysql or install the mysql.so module.\n";
+ exit;
+ }
+ }
+
+ global $wgCommandLineMode;
+ $wgCommandLineMode = true;
+ umask( 000 );
+ set_time_limit( 0 );
+}
+
+function copyfile( $sdir, $name, $ddir, $perms = 0664 ) {
+ global $wgInstallOwner, $wgInstallGroup;
+
+ $d = "{$ddir}/{$name}";
+ if ( copy( "{$sdir}/{$name}", $d ) ) {
+ if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
+ if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
+ chmod( $d, $perms );
+ # print "Copied \"{$name}\" to \"{$ddir}\".\n";
+ } else {
+ print "Failed to copy file \"{$name}\" to \"{$ddir}\".\n";
+ exit();
+ }
+}
+
+function copydirectory( $source, $dest ) {
+ $handle = opendir( $source );
+ while ( false !== ( $f = readdir( $handle ) ) ) {
+ if ( "." == $f{0} ) continue;
+ # Something made all my "CVSs" go lowercase :(
+ if ( !strcasecmp( "CVS", $f ) ) continue;
+ copyfile( $source, $f, $dest );
+ }
+}
+
+function readconsole() {
+ $fp = fopen( "php://stdin", "r" );
+ $resp = trim( fgets( $fp, 1024 ) );
+ fclose( $fp );
+ return $resp;
+}
+
+
+function replacevars( $ins ) {
+ $varnames = array(
+ "wgDBserver", "wgDBname", "wgDBintlname", "wgDBuser",
+ "wgDBpassword", "wgDBsqluser", "wgDBsqlpassword",
+ "wgDBadminuser", "wgDBadminpassword"
+ );
+
+ foreach ( $varnames as $var ) {
+ global $$var;
+ $ins = str_replace( '{$' . $var . '}', $$var, $ins );
+ }
+ return $ins;
+}
+
+#
+# Read and execute SQL commands from a file
+#
+function dbsource( $fname, $conn = false ) {
+ $fp = fopen( $fname, "r" );
+ if ( false === $fp ) {
+ print "Could not open \"{$fname}\".\n";
+ exit();
+ }
+
+ $cmd = "";
+ $done = false;
+
+ while ( ! feof( $fp ) ) {
+ $line = trim( fgets( $fp, 1024 ) );
+ $sl = strlen( $line ) - 1;
+
+ if ( $sl < 0 ) { continue; }
+ if ( "-" == $line{0} && "-" == $line{1} ) { continue; }
+
+ if ( ";" == $line{$sl} ) {
+ $done = true;
+ $line = substr( $line, 0, $sl );
+ }
+
+ if ( "" != $cmd ) { $cmd .= " "; }
+ $cmd .= $line;
+
+ if ( $done ) {
+ $cmd = replacevars( $cmd );
+ if( $conn )
+ $res = mysql_query( $cmd, $conn );
+ else
+ $res = mysql_query( $cmd );
+
+ if ( false === $res ) {
+ print "Query \"{$cmd}\" failed.\n";
+ exit();
+ }
+
+ $cmd = "";
+ $done = false;
+ }
+ }
+ fclose( $fp );
+}
+
+
+function field_exists( $table, $field ) {
+ $fname = "Update script: field_exists";
+ $res = wfQuery( "DESCRIBE $table", $fname );
+ $found = false;
+
+ while ( $row = wfFetchObject( $res ) ) {
+ if ( $row->Field == $field ) {
+ $found = true;
+ break;
+ }
+ }
+ return $found;
+}
+
+
+function table_exists( $db ) {
+ global $wgDBname;
+ $res = mysql_list_tables( $wgDBname );
+ if( !$res ) {
+ echo "** " . mysql_error() . "\n";
+ return false;
+ }
+ for( $i = mysql_num_rows( $res ) - 1; $i--; $i > 0 ) {
+ if( mysql_tablename( $res, $i ) == $db ) return true;
+ }
+ return false;
+}
+
+function field_info( $table, $field ) {
+ $res = mysql_query( "SELECT * FROM $table LIMIT 1" );
+ $n = mysql_num_fields( $res );
+ for( $i = 0; $i < $n; $i++ ) {
+ $meta = mysql_fetch_field( $res, $i );
+ if( $field == $meta->name ) {
+ return $meta;
+ }
+ }
+ return false;
+}
+
+?>
<?
-if( !function_exists( "version_compare" ) ) {
- # version_compare was introduced in 4.1.0
- die( "Your PHP version is much too old; 4.0.x will _not_ work. 4.3.2 or higher is recommended. ABORTING.\n" );
-}
-if( version_compare( phpversion(), "4.3.2" ) < 0 ) {
- echo "WARNING: PHP 4.3.2 or higher is recommended. Older versions from 4.1.x up may work but are not actively supported.\n\n";
-}
-if( !ini_get( "register_globals" ) ) {
- echo "WARNING: register_globals is not on; MediaWiki currently relies on this option.\n\n";
-}
-
-if (!extension_loaded('mysql')) {
- if (!dl('mysql.so')) {
- print "Could not load MySQL driver! Please compile ".
- "php --with-mysql or install the mysql.so module.\n";
- exit;
- }
-}
# Install software and create new empty database.
#
+include( "./install-utils.inc" );
+install_version_checks();
+
if ( ! ( is_readable( "./LocalSettings.php" )
&& is_readable( "./AdminSettings.php" ) ) ) {
print "You must first create the files LocalSettings.php\n" .
if ( ! ( "Y" == $response{0} || "y" == $response{0} ) ) { exit(); }
}
-$wgCommandLineMode = true;
-umask( 000 );
-set_time_limit( 0 );
-
#
# Make the necessary directories
#
# Now do the actual database creation
#
print "Creating database...\n";
-dbsource( $rconn, "./maintenance/database.sql" );
+dbsource( "./maintenance/database.sql", $rconn );
mysql_select_db( $wgDBname, $rconn );
-dbsource( $rconn, "./maintenance/tables.sql" );
-dbsource( $rconn, "./maintenance/users.sql" );
-dbsource( $rconn, "./maintenance/initialdata.sql" );
-dbsource( $rconn, "./maintenance/interwiki.sql" );
+dbsource( "./maintenance/tables.sql", $rconn );
+dbsource( "./maintenance/users.sql", $rconn );
+dbsource( "./maintenance/initialdata.sql", $rconn );
+dbsource( "./maintenance/interwiki.sql", $rconn );
populatedata(); # Needs internationalized messages
print "Adding indexes...\n";
-dbsource( $rconn, "./maintenance/indexes.sql" );
+dbsource( "./maintenance/indexes.sql", $rconn );
print "Done.\nBrowse \"{$wgServer}{$wgScript}\" to test,\n" .
"or \"run WikiSuite -b -o\" in test suite.\n";
}
}
-function copyfile( $sdir, $name, $ddir, $perms = 0664 ) {
- global $wgInstallOwner, $wgInstallGroup;
-
- $d = "{$ddir}/{$name}";
- if ( copy( "{$sdir}/{$name}", $d ) ) {
- if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
- if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
- chmod( $d, $perms );
- # print "Copied \"{$name}\" to \"{$ddir}\".\n";
- } else {
- print "Failed to copy file \"{$name}\" to \"{$ddir}\".\n";
- exit();
- }
-}
-
-function copydirectory( $source, $dest ) {
- $handle = opendir( $source );
- while ( false !== ( $f = readdir( $handle ) ) ) {
- if ( "." == $f{0} ) continue;
- # Something made all my "CVSs" go lowercase :(
- if ( !strcasecmp( "CVS", $f ) ) continue;
- copyfile( $source, $f, $dest );
- }
-}
-
-function readconsole() {
- $fp = fopen( "php://stdin", "r" );
- $resp = trim( fgets( $fp, 1024 ) );
- fclose( $fp );
- return $resp;
-}
-
-#
-# Read and execute SQL commands from a file
-#
-function dbsource( $conn, $fname ) {
- $fp = fopen( $fname, "r" );
- if ( false === $fp ) {
- print "Could not open \"{$fname}\".\n";
- exit();
- }
-
- $cmd = "";
- $done = false;
-
- while ( ! feof( $fp ) ) {
- $line = trim( fgets( $fp, 1024 ) );
- $sl = strlen( $line ) - 1;
-
- if ( $sl < 0 ) { continue; }
- if ( "-" == $line{0} && "-" == $line{1} ) { continue; }
-
- if ( ";" == $line{$sl} ) {
- $done = true;
- $line = substr( $line, 0, $sl );
- }
-
- if ( "" != $cmd ) { $cmd .= " "; }
- $cmd .= $line;
-
- if ( $done ) {
- $cmd = replacevars( $cmd );
- $res = mysql_query( $cmd, $conn );
-
- if ( false === $res ) {
- print "Query \"{$cmd}\" failed.\n";
- exit();
- }
-
- $cmd = "";
- $done = false;
- }
- }
- fclose( $fp );
-}
-
-function replacevars( $ins ) {
- $varnames = array(
- "wgDBserver", "wgDBname", "wgDBintlname", "wgDBuser",
- "wgDBpassword", "wgDBsqluser", "wgDBsqlpassword",
- "wgDBadminuser", "wgDBadminpassword"
- );
-
- foreach ( $varnames as $var ) {
- global $$var;
- $ins = str_replace( '{$' . $var . '}', $$var, $ins );
- }
- return $ins;
-}
function populatedata() {
global $wgDBadminpassword;
<?
-if( !function_exists( "version_compare" ) ) {
- # version_compare was introduced in 4.1.0
- die( "Your PHP version is much too old; 4.0.x will _not_ work. 4.3.2 or higher is recommended. ABORTING.\n" );
-}
-if( version_compare( phpversion(), "4.3.2" ) < 0 ) {
- echo "WARNING: PHP 4.3.2 or higher is recommended. Older versions from 4.1.x up may work but are not actively supported.\n\n";
-}
-if( !ini_get( "register_globals" ) ) {
- echo "WARNING: register_globals is not on; MediaWiki currently relies on this option.\n\n";
-}
-
# Update already-installed software
#
+include( "./install-utils.inc" );
+install_version_checks();
+
if ( ! ( is_readable( "./LocalSettings.php" )
&& is_readable( "./AdminSettings.php" ) ) ) {
print "A copy of your installation's LocalSettings.php\n" .
include_once( "./LocalSettings.php" );
include_once( "./AdminSettings.php" );
+include( "$IP/Version.php" );
+
if ( $wgUseTeX && ( ! is_executable( "./math/texvc" ) ) ) {
print "To use math functions, you must first compile texvc by\n" .
"running \"make\" in the math directory.\n";
exit();
}
-umask( 000 );
-set_time_limit( 0 );
+#
+# Copy files into installation directories
+#
+do_update_files();
+
+$wgDBuser = $wgDBadminuser;
+$wgDBpassword = $wgDBadminpassword;
-include_once( "Version.php" );
include_once( "{$IP}/Setup.php" );
include_once( "./maintenance/InitialiseMessages.inc" );
$wgTitle = Title::newFromText( "Update script" );
-$wgCommandLineMode = true;
-$wgAlterSpecs = array();
-
-do_revision_updates();
-alter_ipblocks();
-initialiseMessages();
#
-# Run ALTER TABLE queries.
+# Check the database for things that need to be fixed...
#
-if ( count( $wgAlterSpecs ) ) {
+ print "Checking database for necessary updates...\n";
+
$rconn = mysql_connect( $wgDBserver, $wgDBadminuser, $wgDBadminpassword );
mysql_select_db( $wgDBname );
- print "\n";
- foreach ( $wgAlterSpecs as $table => $specs ) {
- $sql = "ALTER TABLE $table $specs";
- print "$sql;\n";
- $res = mysql_query( $sql, $rconn );
- if ( $res === false ) {
- print "MySQL error: " . mysql_error( $rconn ) . "\n";
- }
- }
- mysql_close( $rconn );
-}
-{ // Create linkscc if necessary
- $sql = "CREATE TABLE IF NOT EXISTS linkscc (".
- " lcc_pageid INT UNSIGNED NOT NULL UNIQUE KEY, ".
- " lcc_title VARCHAR(255) NOT NULL UNIQUE KEY,".
- " lcc_cacheobj MEDIUMBLOB NOT NULL)";
- // Should it be created as InnoDB?
- $rconn = mysql_connect( $wgDBserver, $wgDBadminuser, $wgDBadminpassword );
- mysql_select_db( $wgDBname );
- print "\n$sql;\n";
- $res = mysql_query( $sql, $rconn );
- if ( $res === false ) {
- print "MySQL error: " . mysql_error( $rconn ) . "\n";
- }
- mysql_close( $rconn );
-}
-
-
-
-
-
-#
-# Copy files into installation directories
-#
-print "Copying files...\n";
-
-copyfile( ".", "wiki.phtml", $IP );
-copyfile( ".", "redirect.phtml", $IP );
-copyfile( ".", "texvc.phtml", $IP );
-
-copydirectory( "./includes", $IP );
-copydirectory( "./stylesheets", $wgStyleSheetDirectory );
+ do_revision_updates();
+
+ do_ipblocks_update();
+ do_interwiki_update();
+ do_index_update();
+ do_linkscc_update();
-copyfile( "./images", "wiki.png", $wgUploadDirectory );
-copyfile( "./languages", "Language.php", $IP );
-copyfile( "./languages", "Language" . ucfirst( $wgLanguageCode ) . ".php", $IP );
+ initialiseMessages();
-$fp = fopen( $wgDebugLogFile, "w" );
-if ( false === $fp ) {
- print "Could not create log file \"{$wgDebugLogFile}\".\n";
- exit();
-}
-$d = date( "Y-m-d H:i:s" );
-fwrite( $fp, "Wiki debug log file created {$d}\n\n" );
-fclose( $fp );
-
-if ( $wgUseTeX ) {
- copyfile( "./math", "texvc", "{$IP}/math", 0775 );
- copyfile( "./math", "texvc_test", "{$IP}/math", 0775 );
- copyfile( "./math", "texvc_tex", "{$IP}/math", 0775 );
-}
-
-copyfile( ".", "Version.php", $IP );
+ mysql_close( $rconn );
print "Done.\n";
exit();
#
#
-function copyfile( $sdir, $name, $ddir, $perms = 0664 ) {
- global $wgInstallOwner, $wgInstallGroup;
-
- $d = "{$ddir}/{$name}";
- if ( copy( "{$sdir}/{$name}", $d ) ) {
- if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
- if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
- chmod( $d, $perms );
- # print "Copied \"{$name}\" to \"{$ddir}\".\n";
- } else {
- print "Failed to copy file \"{$name}\" to \"{$ddir}\".\n";
+function do_update_files() {
+ global $IP, $wgStyleSheetDirectory, $wgUploadDirectory, $wgLanguageCode, $wgDebugLogFile;
+ print "Copying files... ";
+
+ copyfile( ".", "wiki.phtml", $IP );
+ copyfile( ".", "redirect.phtml", $IP );
+ copyfile( ".", "texvc.phtml", $IP );
+
+ copydirectory( "./includes", $IP );
+ copydirectory( "./stylesheets", $wgStyleSheetDirectory );
+
+ copyfile( "./images", "wiki.png", $wgUploadDirectory );
+ copyfile( "./languages", "Language.php", $IP );
+ copyfile( "./languages", "Language" . ucfirst( $wgLanguageCode ) . ".php", $IP );
+
+ $fp = fopen( $wgDebugLogFile, "w" );
+ if ( false === $fp ) {
+ print "Could not create log file \"{$wgDebugLogFile}\".\n";
exit();
}
-}
-
-function copydirectory( $source, $dest ) {
- $handle = opendir( $source );
- while ( false !== ( $f = readdir( $handle ) ) ) {
- if ( "." == $f{0} ) continue;
- # Windows turned all my CVS->cvs :(
- if ( !strcasecmp ( "CVS", $f ) ) continue;
- copyfile( $source, $f, $dest );
+ $d = date( "Y-m-d H:i:s" );
+ fwrite( $fp, "Wiki debug log file created {$d}\n\n" );
+ fclose( $fp );
+
+ if ( $wgUseTeX ) {
+ copyfile( "./math", "texvc", "{$IP}/math", 0775 );
+ copyfile( "./math", "texvc_test", "{$IP}/math", 0775 );
+ copyfile( "./math", "texvc_tex", "{$IP}/math", 0775 );
}
-}
+
+ copyfile( ".", "Version.php", $IP );
-function readconsole() {
- $fp = fopen( "php://stdin", "r" );
- $resp = trim( fgets( $fp, 1024 ) );
- fclose( $fp );
- return $resp;
+ print "ok\n";
}
function do_revision_updates() {
global $wgSoftwareRevision;
- if ( $wgSoftwareRevision < 1001 ) { update_passwords(); }
+ if ( $wgSoftwareRevision < 1001 ) {
+ update_passwords();
+ }
}
function update_passwords() {
}
}
-function alter_ipblocks() {
- global $wgAlterSpecs;
-
+function do_ipblocks_update() {
if ( wfFieldExists( "ipblocks", "ipb_id" ) ) {
- return;
+ echo "...ipblocks table is up to date.\n";
+ } else {
+ echo "Updating ipblocks table... ";
+ dbsource( "maintenance/archives/patch-ipblocks.sql" );
+ echo "ok\n";
}
-
- if ( array_key_exists( "ipblocks", $wgAlterSpecs ) ) {
- $wgAlterSpecs["ipblocks"] .= ",";
+}
+
+
+function do_interwiki_update() {
+ # Check that interwiki table exists; if it doesn't source it
+ if( table_exists( "interwiki" ) ) {
+ echo "...already have interwiki table\n";
+ return true;
}
+ echo "Creating interwiki table: ";
+ dbsource( "maintenance/archives/patch-interwiki.sql" );
+ echo "ok\n";
+ echo "Adding default interwiki definitions: ";
+ dbsource( "maintenance/interwiki.sql" );
+ echo "ok\n";
+}
- $wgAlterSpecs["ipblocks"] .=
- "ADD ipb_auto tinyint(1) NOT NULL default '0', ".
- "ADD ipb_id int(8) NOT NULL auto_increment,".
- "ADD PRIMARY KEY (ipb_id)";
+function do_index_update() {
+ # Check that proper indexes are in place
+ $meta = field_info( "recentchanges", "rc_timestamp" );
+ if( $meta->multiple_key == 0 ) {
+ echo "Updating indexes to 20031107: ";
+ dbsource( "maintenance/archives/patch-indexes.sql" );
+ echo "ok\n";
+ return true;
+ }
+ echo "...indexes seem up to 20031107 standards\n";
+ return false;
}
+function do_linkscc_update() {
+ // Create linkscc if necessary
+ global $rconn;
+ if( table_exists( "linkscc" ) ) {
+ echo "...have linkscc table.\n";
+ } else {
+ echo "Adding linkscc table... ";
+ dbsource( "maintenance/archives/patch-linkscc.sql" );
+ echo "ok\n";
+ }
+}
+
+
?>