Fix toolbar scrolling bug in Mozilla, toolbar can now be safely and fully
[lhc/web/wiklou.git] / update.php
index b3c04ee..fb954f4 100644 (file)
@@ -1,21 +1,12 @@
-<?
-
-
-/*
-
-  TODO: Links cache will be very unhappy without a table like this //e23
-
-       CREATE TABLE linkscc (lcc_pageid INT UNSIGNED NOT NULL UNIQUE KEY,
-                             lcc_title VARCHAR(255) NOT NULL UNIQUE KEY,
-                             lcc_cacheobj MEDIUMBLOB NOT NULL);
-
-*/
-
-
+<?php
 
 # Update already-installed software
 #
 
+include( "./install-utils.inc" );
+include_once( "./maintenance/updaters.inc" );
+install_version_checks();
+
 if ( ! ( is_readable( "./LocalSettings.php" )
   && is_readable( "./AdminSettings.php" ) ) ) {
        print "A copy of your installation's LocalSettings.php\n" .
@@ -27,78 +18,55 @@ $IP = "./includes";
 include_once( "./LocalSettings.php" );
 include_once( "./AdminSettings.php" );
 
+include( "$IP/Version.php" );
+
+if( $wgSitename == "MediaWiki" ) {
+       die( "You must set the site name in \$wgSitename before installation.\n\n" );
+}
+
 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.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 ) ) {
-       $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 );
-}
+print "Checking database for necessary updates...\n";
 
+$wgDatabase = Database::newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname, 
+       1, false, true, false);
+if ( !$wgDatabase->isOpen() ) {
+       print "Unable to connect to database: " . $wgDatabase->lastError() . "\n";
+       exit();
+}
 
-#
-# 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();
 
-copyfile( "./images", "wiki.png", $wgUploadDirectory );
-copyfile( "./languages", "Language.php", $IP );
-copyfile( "./languages", "Language" . ucfirst( $wgLanguageCode ) . ".php", $IP );
+do_ipblocks_update();
+do_interwiki_update();
+do_index_update();
+do_linkscc_update();
+do_hitcounter_update();
+do_recentchanges_update();
 
-$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 );
-}
+initialiseMessages();
 
-copyfile( ".", "Version.php", $IP );
+$wgDatabase->close();
 
 print "Done.\n";
 exit();
@@ -107,97 +75,64 @@ 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";
-               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 );
-       }
-}
-
-function readconsole() {
-       $fp = fopen( "php://stdin", "r" );
-       $resp = trim( fgets( $fp ) );
-       fclose( $fp );
-       return $resp;
-}
-
-function do_revision_updates() {
-       global $wgSoftwareRevision;
-       if ( $wgSoftwareRevision < 1001 ) { update_passwords(); }
-}
-
-function update_passwords() {
-       $fname = "Update script: update_passwords()";
-       print "\nIt appears that you need to update the user passwords in your\n" .
-         "database. If you have already done this (if you've run this update\n" .
-         "script once before, for example), doing so again will make all your\n" .
-         "user accounts inaccessible, so be sure you only do this once.\n" .
-         "Update user passwords? (yes/no) ";
-
-       $resp = readconsole();
-    if ( ! ( "Y" == $resp{0} || "y" == $resp{0} ) ) { return; }
-
-       $sql = "SELECT user_id,user_password FROM user";
-       $source = wfQuery( $sql, DB_READ, fname );
-
-       while ( $row = mysql_fetch_object( $source ) ) {
-               $id = $row->user_id;
-               $oldpass = $row->user_password;
-               $newpass = md5( "{$id}-{$oldpass}" );
-
-               $sql = "UPDATE user SET user_password='{$newpass}' " .
-                 "WHERE user_id={$id}";
-               wfQuery( $sql, DB_WRITE, $fname );
-       }
-}
-
-function alter_ipblocks() {
-       global $wgAlterSpecs;
+function do_update_files() {
+       global $IP, $wgStyleSheetDirectory, $wgUploadDirectory, $wgLanguageCode, $wgDebugLogFile;
+       print "Copying files... ";
        
-       if ( field_exists( "ipblocks", "ipb_id" ) ) {
-               return;
-       }
+       copyfile( ".", "LocalSettings.php", $IP );
+       copyfile( ".", "index.php", $IP );
+       copyfile( ".", "redirect.php", $IP );
+       # compatibility with older versions, can be removed in a year or so
+       # (written in Feb 2004)
+       copyfile( ".", "wiki.phtml", $IP );
+       copyfile( ".", "redirect.phtml", $IP );
        
-       if ( array_key_exists( "ipblocks", $wgAlterSpecs ) ) {
-               $wgAlterSpecs["ipblocks"] .= ",";
-       }
-
-       $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 field_exists( $table, $field ) {
-       $fname = "Update script: field_exists";
-       $res = wfQuery( "DESCRIBE $table", DB_READ, $fname );
-       $found = false;
+       copydirectory( "./includes", $IP );
+       copydirectory( "./stylesheets", $wgStyleSheetDirectory );
        
-       while ( $row = wfFetchObject( $res ) ) {
-               if ( $row->Field == $field ) {
-                       $found = true;
-                       break;
+       copyfile( "./images", "wiki.png", $wgUploadDirectory );
+       copyfile( "./images", "button_bold.png", $wgUploadDirectory );
+       copyfile( "./images", "button_extlink.png", $wgUploadDirectory );
+       copyfile( "./images", "button_headline.png", $wgUploadDirectory );
+       copyfile( "./images", "button_hr.png", $wgUploadDirectory );
+       copyfile( "./images", "button_image.png", $wgUploadDirectory );
+       copyfile( "./images", "button_italic.png", $wgUploadDirectory );
+       copyfile( "./images", "button_link.png", $wgUploadDirectory );
+       copyfile( "./images", "button_math.png", $wgUploadDirectory );
+       copyfile( "./images", "button_media.png", $wgUploadDirectory );
+       copyfile( "./images", "button_nowiki.png", $wgUploadDirectory );
+       copyfile( "./images", "button_sig.png", $wgUploadDirectory );
+       copyfile( "./images", "button_template.png", $wgUploadDirectory );
+       copyfile( "./images", "magnify-clip.png", $wgUploadDirectory );
+       copyfile( "./images", "Arr_.png", $wgUploadDirectory );
+       copyfile( "./images", "Arr_r.png", $wgUploadDirectory );
+       copyfile( "./images", "Arr_d.png", $wgUploadDirectory );
+       copyfile( "./images", "Arr_l.png", $wgUploadDirectory );
+
+       copyfile( "./languages", "Language.php", $IP );
+       copyfile( "./languages", "LanguageUtf8.php", $IP );
+       copyfile( "./languages", "Language" . ucfirst( $wgLanguageCode ) . ".php", $IP );
+       
+       if( !empty( $wgDebugLogFile ) ) {
+               $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 );
        }
-       return $found;
+       
+       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 );
+
+       print "ok\n";
 }
 
 ?>