GIMP source image for the arrows
[lhc/web/wiklou.git] / install.php
index d79578b..b84252c 100644 (file)
@@ -1,8 +1,11 @@
-<?
+<?php
 
 # 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" .
@@ -14,6 +17,11 @@ if ( ! ( is_readable( "./LocalSettings.php" )
 $DP = "./includes";
 include_once( "./LocalSettings.php" );
 include_once( "./AdminSettings.php" );
+include_once( "./maintenance/InitialiseMessages.inc" );
+
+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" .
@@ -31,10 +39,6 @@ if ( is_file( "{$IP}/Version.php" ) ) {
        if ( ! ( "Y" == $response{0} || "y" == $response{0} ) ) { exit(); }
 }
 
-$wgCommandLineMode = true;
-umask( 000 );
-set_time_limit( 0 );
-
 #
 # Make the necessary directories
 #
@@ -48,25 +52,46 @@ print "Copying files...\n";
 
 copyfile( ".", "LocalSettings.php", $IP );
 copyfile( ".", "Version.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 );
-copyfile( ".", "texvc.phtml", $IP );
 
 copydirectory( "./includes", $IP );
-copydirectory( "./stylesheets", $wgStyleSheetsDirectory );
+copydirectory( "./stylesheets", $wgStyleSheetDirectory );
 
 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( "./languages", "Language.php", $IP );
+copyfile( "./languages", "LanguageUtf8.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();
+if ( $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 );
 }
-$d = date( "Y-m-d H:i:s" );
-fwrite( $fp, "Wiki debug log file created {$d}\n\n" );
-fclose( $fp );
 
 if ( $wgUseTeX ) {
        makedirectory( "{$IP}/math" );
@@ -81,46 +106,49 @@ copyfile( ".", "Version.php", $IP );
 #
 # Make and initialize database
 #
-print "\n* * *\nWarning! This script will completely erase the\n" .
+print "\n* * *\nWarning! This script will completely erase any\n" .
   "existing database \"{$wgDBname}\" and all its contents.\n" .
   "Are you sure you want to do this? (yes/no) ";
 
 $response = readconsole();
 if ( ! ( "Y" == $response{0} || "y" == $response{0} ) ) { exit(); }
 
-print "\nYou should have already created a root password for the database.\n" .
-  "Enter the root password here: ";
-
-$rootpw = readconsole();
-
-$rconn = mysql_connect( $wgDBserver, "root", $rootpw );
-if ( false === $rconn ) {
-       print "Could not connect to database on \"{$wgDBserver}\" as root.\n";
-       exit();
-}
+print "Please enter your root password for the database server now.\n";
+print "It is used to do the following:\n";
+print "1) Create the database\n";
+print "2) Create the users specified in AdminSettings.php and LocalSettings.php\n\n";
+print "You do not need to create any user accounts yourself!\n\n";
+print "MySQL root password (typing will be visible): ";
+$rootpw=readconsole();
 
 # Include rest of code to get things like internationalized messages.
 #
 include_once( "{$IP}/Setup.php" );
 $wgTitle = Title::newFromText( "Installation script" );
 
+$wgDatabase = Database::newFromParams( $wgDBserver, "root", $rootpw, "", 1 );
+if ( !$wgDatabase->isOpen() ) {
+       print "Could not connect to database on \"{$wgDBserver}\" as root.\n";
+       exit();
+}
+
 # Now do the actual database creation
 #
 print "Creating database...\n";
-dbsource( $rconn, "./maintenance/database.sql" );
+dbsource( "./maintenance/database.sql", $wgDatabase );
 
-mysql_select_db( $wgDBname, $rconn );
-dbsource( $rconn, "./maintenance/tables.sql" );
-dbsource( $rconn, "./maintenance/users.sql" );
-dbsource( $rconn, "./maintenance/initialdata.sql" );
+$wgDatabase->selectDB( $wgDBname );
+dbsource( "./maintenance/tables.sql", $wgDatabase );
+dbsource( "./maintenance/users.sql", $wgDatabase );
+dbsource( "./maintenance/initialdata.sql", $wgDatabase );
+dbsource( "./maintenance/interwiki.sql", $wgDatabase );
 
 populatedata(); # Needs internationalized messages
 
 print "Adding indexes...\n";
-dbsource( $rconn, "./maintenance/indexes.sql" );
+dbsource( "./maintenance/indexes.sql", $wgDatabase );
 
-print "Done.\nBrowse \"{$wgServer}{$wgScript}\" to test,\n" .
-  "or \"run WikiSuite -b -o\" in test suite.\n";
+print "Done.\nBrowse \"{$wgServer}{$wgScript}\" to test.\n";
 exit();
 
 #
@@ -143,136 +171,94 @@ function makedirectory( $d ) {
        }
 }
 
-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;
-               if ( "CVS" == $f ) continue;
-               copyfile( $source, $f, $dest );
-       }
-}
-
-function readconsole() {
-       $fp = fopen( "php://stdin", "r" );
-       $resp = trim( fgets( $fp ) );
-       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 ) );
-               $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;
+       global $wgDBadminpassword, $wgDatabase;
        $fname = "Installation script: populatedata()";
 
        $sql = "DELETE FROM site_stats";
-       wfQuery( $sql, $fname );
+       $wgDatabase->query( $sql, $fname );
 
        $sql = "INSERT INTO site_stats (ss_row_id,ss_total_views," .
                "ss_total_edits,ss_good_articles) VALUES (1,0,0,0)";
-       wfQuery( $sql, $fname );
+       $wgDatabase->query( $sql, $fname );
 
        $sql = "DELETE FROM user";
-       wfQuery( $sql, $fname );
+       $wgDatabase->query( $sql, $fname );
 
-       $sql = "INSERT INTO user (user_name, user_password, user_rights)" .
-         "VALUES ('WikiSysop','" . User::encryptPassword( $wgDBadminpassword ) .
-         "','sysop'),('WikiDeveloper','" . User::encryptPassword(
-         $wgDBadminpassword ) . "','sysop,developer')";
-       wfQuery( $sql, $fname );
+       print "Do you want to create a sysop account? A sysop can protect,\n";
+       print "delete and undelete pages and ban users. Recomended. [Y/n] ";
+       $response = readconsole();
+       if(strtolower($response)!="n") {
+               print "Enter the username [Sysop]: ";
+               $sysop_user=readconsole();
+               if(!$sysop_user) { $sysop_user="Sysop"; }
+               while(!$sysop_password) {
+                       print "Enter the password: ";
+                       $sysop_password=readconsole();
+               }
+               $u = User::newFromName( $sysop_user );
+               if ( 0 == $u->idForName() ) {
+                       $u->addToDatabase();
+                       $u->setPassword( $sysop_password );
+                       $u->addRight( "sysop" );
+                       $u->saveSettings();
+               } else {
+                       print "Could not create user - already exists!\n";
+               }
+       }
+       print "Do you want to create a sysop+developer account? A developer\n";
+       print "can switch the database to read-only mode and run any type of\n";
+       print "query through a web interface. [Y/n] ";
+       $response=readconsole();
+       if(strtolower($response)!="n") {
+               print "Enter the username [Developer]: ";
+               $developer_user=readconsole();
+               if(!$developer_user) { $developer_user="Developer"; }
+               while (!$developer_password) {
+                       print "Enter the password: ";
+                       $developer_password=readconsole();
+               }               
+               $u = User::newFromName( $developer_user );
+               if ( 0 == $u->idForName() ) {
+                       $u->addToDatabase();
+                       $u->setPassword( $developer_password );
+                       $u->addRight( "sysop" );
+                       $u->addRight( "developer" );
+                       $u->saveSettings();
+               } else {
+                       print "Could not create user - already exists!\n";
+               }
+       }
        
        $wns = Namespace::getWikipedia();
-       $ulp = addslashes( wfMsg( "uploadlogpage" ) );
-       $dlp = addslashes( wfMsg( "dellogpage" ) );
+       $ulp = addslashes( wfMsgNoDB( "uploadlogpage" ) );
+       $dlp = addslashes( wfMsgNoDB( "dellogpage" ) );
 
        $sql = "DELETE FROM cur";
-       wfQuery( $sql, $fname );
+       $wgDatabase->query( $sql, $fname );
 
+       $now = wfTimestampNow();
+       $won = wfInvertTimestamp( $now );
+       
        $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
-         "cur_restrictions) VALUES ({$wns},'{$ulp}','" .
-         wfStrencode( wfMsg( "uploadlogpagetext" ) ) . "','sysop')";
-       wfQuery( $sql );
+         "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) VALUES ({$wns},'{$ulp}','" .
+         wfStrencode( wfMsg( "uploadlogpagetext" ) ) . "','sysop','$now','$won','$now')";
+       $wgDatabase->query( $sql, $fname );
 
        $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
-         "cur_restrictions) VALUES ({$wns},'{$dlp}','" .
-         wfStrencode( wfMsg( "dellogpagetext" ) ) . "','sysop')";
-       wfQuery( $sql );
-
-       $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text) " .
-         "VALUES (0,'" . wfStrencode( wfMsg( "mainpage" ) ) . "','" .
-         wfStrencode( wfMsg( "mainpagetext" ) ) . "')";
-       wfQuery( $sql );
+         "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) VALUES ({$wns},'{$dlp}','" .
+         wfStrencode( wfMsg( "dellogpagetext" ) ) . "','sysop','$now','$won','$now')";
+       $wgDatabase->query( $sql, $fname );
+       
+       $titleobj = Title::newFromText( wfMsgNoDB( "mainpage" ) );
+       $title = $titleobj->getDBkey();
+       $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text,cur_timestamp,inverse_timestamp,cur_touched) " .
+         "VALUES (0,'$title','" .
+         wfStrencode( wfMsg( "mainpagetext" ) ) . "','$now','$won','$now')";
+       $wgDatabase->query( $sql, $fname );
+       
+       initialiseMessages();
 }
 
 ?>