In development, doesn't work currently
[lhc/web/wiklou.git] / install.php
index 6355cd6..4aef3d8 100644 (file)
@@ -1,4 +1,4 @@
-<?
+<?php
 
 # Install software and create new empty database.
 #
@@ -48,15 +48,28 @@ print "Copying files...\n";
 
 copyfile( ".", "LocalSettings.php", $IP );
 copyfile( ".", "Version.php", $IP );
-copyfile( ".", "wiki.phtml", $IP );
-copyfile( ".", "redirect.phtml", $IP );
-copyfile( ".", "texvc.phtml", $IP );
+copyfileto( ".", "wiki.phtml", $IP, "wiki.$wgScriptExtension" );
+copyfileto( ".", "redirect.phtml", $IP, "redirect.$wgScriptExtension" );
 
 copydirectory( "./includes", $IP );
 copydirectory( "./stylesheets", $wgStyleSheetDirectory );
 
 copyfile( "./images", "wiki.png", $wgUploadDirectory );
+copyfile( "./images", "button_bold.gif", $wgUploadDirectory );
+copyfile( "./images", "button_extlink.gif", $wgUploadDirectory );
+copyfile( "./images", "button_headline.gif", $wgUploadDirectory );
+copyfile( "./images", "button_hr.gif", $wgUploadDirectory );
+copyfile( "./images", "button_image.gif", $wgUploadDirectory );
+copyfile( "./images", "button_italic.gif", $wgUploadDirectory );
+copyfile( "./images", "button_link.gif", $wgUploadDirectory );
+copyfile( "./images", "button_math.gif", $wgUploadDirectory );
+copyfile( "./images", "button_media.gif", $wgUploadDirectory );
+copyfile( "./images", "button_nowiki.gif", $wgUploadDirectory );
+copyfile( "./images", "button_sig.gif", $wgUploadDirectory );
+copyfile( "./images", "button_template.gif", $wgUploadDirectory );
+
 copyfile( "./languages", "Language.php", $IP );
+copyfile( "./languages", "LanguageUtf8.php", $IP );
 copyfile( "./languages", "Language" . ucfirst( $wgLanguageCode ) . ".php", $IP );
 
 if ( $wgDebugLogFile ) {
@@ -83,44 +96,47 @@ 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( "./maintenance/database.sql", $rconn );
+dbsource( "./maintenance/database.sql", $wgDatabase );
 
-mysql_select_db( $wgDBname, $rconn );
-dbsource( "./maintenance/tables.sql", $rconn );
-dbsource( "./maintenance/users.sql", $rconn );
-dbsource( "./maintenance/initialdata.sql", $rconn );
-dbsource( "./maintenance/interwiki.sql", $rconn );
+$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( "./maintenance/indexes.sql", $rconn );
+dbsource( "./maintenance/indexes.sql", $wgDatabase );
 
 print "Done.\nBrowse \"{$wgServer}{$wgScript}\" to test.\n";
 exit();
@@ -147,33 +163,62 @@ function makedirectory( $d ) {
 
 
 function populatedata() {
-       global $wgDBadminpassword;
+       global $wgDBadminpassword, $wgDatabase;
        $fname = "Installation script: populatedata()";
 
        $sql = "DELETE FROM site_stats";
-       wfQuery( $sql, DB_WRITE, $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, DB_WRITE, $fname );
+       $wgDatabase->query( $sql, $fname );
 
        $sql = "DELETE FROM user";
-       wfQuery( $sql, DB_WRITE, $fname );
-
-       $u = User::newFromName( "WikiSysop" );
-       if ( 0 == $u->idForName() ) {
-               $u->addToDatabase();
-               $u->setPassword( $wgDBadminpassword );
-               $u->addRight( "sysop" );
-               $u->saveSettings();
+       $wgDatabase->query( $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";
+               }
        }
-       $u = User::newFromName( "WikiDeveloper" );
-       if ( 0 == $u->idForName() ) {
-               $u->addToDatabase();
-               $u->setPassword( $wgDBadminpassword );
-               $u->addRight( "sysop" );
-               $u->addRight( "developer" );
-               $u->saveSettings();
+       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();
@@ -181,7 +226,7 @@ function populatedata() {
        $dlp = addslashes( wfMsgNoDB( "dellogpage" ) );
 
        $sql = "DELETE FROM cur";
-       wfQuery( $sql, DB_WRITE, $fname );
+       $wgDatabase->query( $sql, $fname );
 
        $now = wfTimestampNow();
        $won = wfInvertTimestamp( $now );
@@ -189,19 +234,19 @@ function populatedata() {
        $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
          "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) VALUES ({$wns},'{$ulp}','" .
          wfStrencode( wfMsg( "uploadlogpagetext" ) ) . "','sysop','$now','$won','$now')";
-       wfQuery( $sql, DB_WRITE, $fname );
+       $wgDatabase->query( $sql, $fname );
 
        $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
          "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) VALUES ({$wns},'{$dlp}','" .
          wfStrencode( wfMsg( "dellogpagetext" ) ) . "','sysop','$now','$won','$now')";
-       wfQuery( $sql, DB_WRITE, $fname );
+       $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')";
-       wfQuery( $sql, DB_WRITE, $fname );
+       $wgDatabase->query( $sql, $fname );
        
        initialiseMessages();
 }