| 2 | 
           ddelon | 
           1 | 
           <?php
  | 
        
        
            | 
            | 
           2 | 
           /*
  | 
        
        
            | 
            | 
           3 | 
           install.php
  | 
        
        
            | 
            | 
           4 | 
           Copyright (c) 2002, Hendrik Mans <hendrik@mans.de>
  | 
        
        
            | 
            | 
           5 | 
           Copyright 2002, 2003 David DELON
  | 
        
        
            | 
            | 
           6 | 
           Copyright 2002, 2003 Patrick PAUL
  | 
        
        
            | 
            | 
           7 | 
           Copyright  2003  Eric FELDSTEIN
  | 
        
        
            | 
            | 
           8 | 
           All rights reserved.
  | 
        
        
            | 
            | 
           9 | 
           Redistribution and use in source and binary forms, with or without
  | 
        
        
            | 
            | 
           10 | 
           modification, are permitted provided that the following conditions
  | 
        
        
            | 
            | 
           11 | 
           are met:
  | 
        
        
            | 
            | 
           12 | 
           1. Redistributions of source code must retain the above copyright
  | 
        
        
            | 
            | 
           13 | 
           notice, this list of conditions and the following disclaimer.
  | 
        
        
            | 
            | 
           14 | 
           2. Redistributions in binary form must reproduce the above copyright
  | 
        
        
            | 
            | 
           15 | 
           notice, this list of conditions and the following disclaimer in the
  | 
        
        
            | 
            | 
           16 | 
           documentation and/or other materials provided with the distribution.
  | 
        
        
            | 
            | 
           17 | 
           3. The name of the author may not be used to endorse or promote products
  | 
        
        
            | 
            | 
           18 | 
           derived from this software without specific prior written permission.
  | 
        
        
            | 
            | 
           19 | 
              | 
        
        
            | 
            | 
           20 | 
           THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  | 
        
        
            | 
            | 
           21 | 
           IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  | 
        
        
            | 
            | 
           22 | 
           OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  | 
        
        
            | 
            | 
           23 | 
           IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  | 
        
        
            | 
            | 
           24 | 
           INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  | 
        
        
            | 
            | 
           25 | 
           NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  | 
        
        
            | 
            | 
           26 | 
           DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  | 
        
        
            | 
            | 
           27 | 
           THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  | 
        
        
            | 
            | 
           28 | 
           (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  | 
        
        
            | 
            | 
           29 | 
           THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  | 
        
        
            | 
            | 
           30 | 
           */
  | 
        
        
            | 
            | 
           31 | 
              | 
        
        
            | 
            | 
           32 | 
           // fetch configuration
  | 
        
        
            | 
            | 
           33 | 
           $config = $_POST["config"];
  | 
        
        
            | 
            | 
           34 | 
              | 
        
        
            | 
            | 
           35 | 
           // test configuration
  | 
        
        
            | 
            | 
           36 | 
           echo "<b>Test de la configuration</b><br>\n";
  | 
        
        
            | 
            | 
           37 | 
           test("Test connexion MySQL ...", $dblink = @mysql_connect($config["mysql_host"], $config["mysql_user"], $config["mysql_password"]));
  | 
        
        
            | 
            | 
           38 | 
           test("Recherche base de données ...", @mysql_select_db($config["mysql_database"], $dblink), "La base de données que vous avez choisie n'existe pas, vous devez la créer avant d'installer WikiNi !");
  | 
        
        
            | 
            | 
           39 | 
           echo "<br>\n" ;
  | 
        
        
            | 
            | 
           40 | 
              | 
        
        
            | 
            | 
           41 | 
           // do installation stuff
  | 
        
        
            | 
            | 
           42 | 
           if (!$version = trim($wakkaConfig["wikini_version"])) $version = "0";
  | 
        
        
            | 
            | 
           43 | 
           switch ($version)
  | 
        
        
            | 
            | 
           44 | 
           {
  | 
        
        
            | 
            | 
           45 | 
           // new installation
  | 
        
        
            | 
            | 
           46 | 
           case "0":
  | 
        
        
            | 
            | 
           47 | 
           	echo "<b>Installation</b><br>\n";
  | 
        
        
            | 
            | 
           48 | 
           	test("Creation table page...",
  | 
        
        
            | 
            | 
           49 | 
           		@mysql_query(
  | 
        
        
            | 
            | 
           50 | 
           			"CREATE TABLE ".$config["table_prefix"]."pages (".
  | 
        
        
            | 
            | 
           51 | 
             			"id int(10) unsigned NOT NULL auto_increment,".
  | 
        
        
            | 
            | 
           52 | 
             			"tag varchar(50) NOT NULL default '',".
  | 
        
        
            | 
            | 
           53 | 
             			"time datetime NOT NULL default '0000-00-00 00:00:00',".
  | 
        
        
            | 
            | 
           54 | 
             			"body text NOT NULL,".
  | 
        
        
            | 
            | 
           55 | 
             			"body_r text NOT NULL,".
  | 
        
        
            | 
            | 
           56 | 
             			"owner varchar(50) NOT NULL default '',".
  | 
        
        
            | 
            | 
           57 | 
             			"user varchar(50) NOT NULL default '',".
  | 
        
        
            | 
            | 
           58 | 
             			"latest enum('Y','N') NOT NULL default 'N',".
  | 
        
        
            | 
            | 
           59 | 
             			"handler varchar(30) NOT NULL default 'page',".
  | 
        
        
            | 
            | 
           60 | 
             			"comment_on varchar(50) NOT NULL default '',".
  | 
        
        
            | 
            | 
           61 | 
             			"PRIMARY KEY  (id),".
  | 
        
        
            | 
            | 
           62 | 
             			"FULLTEXT KEY tag (tag,body),".
  | 
        
        
            | 
            | 
           63 | 
             			"KEY idx_tag (tag),".
  | 
        
        
            | 
            | 
           64 | 
             			"KEY idx_time (time),".
  | 
        
        
            | 
            | 
           65 | 
             			"KEY idx_latest (latest),".
  | 
        
        
            | 
            | 
           66 | 
             			"KEY idx_comment_on (comment_on)".
  | 
        
        
            | 
            | 
           67 | 
           			") TYPE=MyISAM;", $dblink), "Déjà créée ?", 0);
  | 
        
        
            | 
            | 
           68 | 
           	test("Creation table ACL ...",
  | 
        
        
            | 
            | 
           69 | 
           		@mysql_query(
  | 
        
        
            | 
            | 
           70 | 
           			"CREATE TABLE ".$config["table_prefix"]."acls (".
  | 
        
        
            | 
            | 
           71 | 
             			"page_tag varchar(50) NOT NULL default '',".
  | 
        
        
            | 
            | 
           72 | 
           			"privilege varchar(20) NOT NULL default '',".
  | 
        
        
            | 
            | 
           73 | 
             			"list text NOT NULL,".
  | 
        
        
            | 
            | 
           74 | 
            			"PRIMARY KEY  (page_tag,privilege)".
  | 
        
        
            | 
            | 
           75 | 
           			") TYPE=MyISAM", $dblink), "Déjà créée ?", 0);
  | 
        
        
            | 
            | 
           76 | 
           	test("Creation table link ...",
  | 
        
        
            | 
            | 
           77 | 
           		@mysql_query(
  | 
        
        
            | 
            | 
           78 | 
           			"CREATE TABLE ".$config["table_prefix"]."links (".
  | 
        
        
            | 
            | 
           79 | 
           			"from_tag char(50) NOT NULL default '',".
  | 
        
        
            | 
            | 
           80 | 
             			"to_tag char(50) NOT NULL default '',".
  | 
        
        
            | 
            | 
           81 | 
             			"UNIQUE KEY from_tag (from_tag,to_tag),".
  | 
        
        
            | 
            | 
           82 | 
             			"KEY idx_from (from_tag),".
  | 
        
        
            | 
            | 
           83 | 
             			"KEY idx_to (to_tag)".
  | 
        
        
            | 
            | 
           84 | 
           			") TYPE=MyISAM", $dblink), "Déjà créée ?", 0);
  | 
        
        
            | 
            | 
           85 | 
           	test("Creation table referrer ...",
  | 
        
        
            | 
            | 
           86 | 
           		@mysql_query(
  | 
        
        
            | 
            | 
           87 | 
           			"CREATE TABLE ".$config["table_prefix"]."referrers (".
  | 
        
        
            | 
            | 
           88 | 
             			"page_tag char(50) NOT NULL default '',".
  | 
        
        
            | 
            | 
           89 | 
             			"referrer char(150) NOT NULL default '',".
  | 
        
        
            | 
            | 
           90 | 
             			"time datetime NOT NULL default '0000-00-00 00:00:00',".
  | 
        
        
            | 
            | 
           91 | 
             			"KEY idx_page_tag (page_tag),".
  | 
        
        
            | 
            | 
           92 | 
             			"KEY idx_time (time)".
  | 
        
        
            | 
            | 
           93 | 
           			") TYPE=MyISAM", $dblink), "Déjà créée ?", 0);
  | 
        
        
            | 
            | 
           94 | 
           	test("Creation table user ...",
  | 
        
        
            | 
            | 
           95 | 
           		@mysql_query(
  | 
        
        
            | 
            | 
           96 | 
           			"CREATE TABLE ".$config["table_prefix"]."users (".
  | 
        
        
            | 
            | 
           97 | 
             			"name varchar(80) NOT NULL default '',".
  | 
        
        
            | 
            | 
           98 | 
             			"password varchar(32) NOT NULL default '',".
  | 
        
        
            | 
            | 
           99 | 
             			"email varchar(50) NOT NULL default '',".
  | 
        
        
            | 
            | 
           100 | 
             			"motto text NOT NULL,".
  | 
        
        
            | 
            | 
           101 | 
             			"revisioncount int(10) unsigned NOT NULL default '20',".
  | 
        
        
            | 
            | 
           102 | 
             			"changescount int(10) unsigned NOT NULL default '50',".
  | 
        
        
            | 
            | 
           103 | 
             			"doubleclickedit enum('Y','N') NOT NULL default 'Y',".
  | 
        
        
            | 
            | 
           104 | 
             			"signuptime datetime NOT NULL default '0000-00-00 00:00:00',".
  | 
        
        
            | 
            | 
           105 | 
             			"show_comments enum('Y','N') NOT NULL default 'N',".
  | 
        
        
            | 
            | 
           106 | 
             			"PRIMARY KEY  (name),".
  | 
        
        
            | 
            | 
           107 | 
             			"KEY idx_name (name),".
  | 
        
        
            | 
            | 
           108 | 
             			"KEY idx_signuptime (signuptime)".
  | 
        
        
            | 
            | 
           109 | 
           			") TYPE=MyISAM", $dblink), "Déjà créée ?", 0);
  | 
        
        
            | 
            | 
           110 | 
           	//insertion des pages de documentation et des pages standards
  | 
        
        
            | 
            | 
           111 | 
           	$d = dir("setup/doc/");
  | 
        
        
            | 
            | 
           112 | 
           	while ($doc = $d->read()){
  | 
        
        
            | 
            | 
           113 | 
           		if ($doc != "." && $doc != ".." && !is_dir($doc)){
  | 
        
        
            | 
            | 
           114 | 
           			$pagecontent = implode ('', file("setup/doc/$doc"));
  | 
        
        
            | 
            | 
           115 | 
           			if ($doc=='_root_page.txt'){
  | 
        
        
            | 
            | 
           116 | 
           				$pagename = $config["root_page"];
  | 
        
        
            | 
            | 
           117 | 
           			}else{
  | 
        
        
            | 
            | 
           118 | 
           				$pagename = substr($doc,0,strpos($doc,'.txt'));
  | 
        
        
            | 
            | 
           119 | 
           			}
  | 
        
        
            | 
            | 
           120 | 
              | 
        
        
            | 
            | 
           121 | 
           			$sql = "Select tag from ".$config["table_prefix"]."pages where tag='$pagename'";
  | 
        
        
            | 
            | 
           122 | 
              | 
        
        
            | 
            | 
           123 | 
           			// Insert documentation page if not present (a previous failed installation ?)
  | 
        
        
            | 
            | 
           124 | 
           			if (($r=@mysql_query($sql, $dblink)) && (mysql_num_rows($r)==0)) {
  | 
        
        
            | 
            | 
           125 | 
              | 
        
        
            | 
            | 
           126 | 
           				$sql = "Insert into ".$config["table_prefix"]."pages ".
  | 
        
        
            | 
            | 
           127 | 
           				"set tag = '$pagename', ".
  | 
        
        
            | 
            | 
           128 | 
           				"body = '".mysql_escape_string($pagecontent)."', ".
  | 
        
        
            | 
            | 
           129 | 
           				"user = 'WikiNiInstaller', ".
  | 
        
        
            | 
            | 
           130 | 
           				"time = now(), ".
  | 
        
        
            | 
            | 
           131 | 
           				"latest = 'Y'";
  | 
        
        
            | 
            | 
           132 | 
              | 
        
        
            | 
            | 
           133 | 
           				test("Insertion de la page $pagename ...", @mysql_query($sql, $dblink),"?",0);
  | 
        
        
            | 
            | 
           134 | 
              | 
        
        
            | 
            | 
           135 | 
           				// update table_links
  | 
        
        
            | 
            | 
           136 | 
           				$wiki = new Wiki($config);
  | 
        
        
            | 
            | 
           137 | 
           				$wiki->SetPage($wiki->LoadPage($pagename,"",0));
  | 
        
        
            | 
            | 
           138 | 
           				$wiki->ClearLinkTable();
  | 
        
        
            | 
            | 
           139 | 
           				$wiki->StartLinkTracking();
  | 
        
        
            | 
            | 
           140 | 
           				$wiki->TrackLinkTo($pagename);
  | 
        
        
            | 
            | 
           141 | 
           				$dummy = $wiki->Header();
  | 
        
        
            | 
            | 
           142 | 
           				$dummy .= $wiki->Format($pagecontent);
  | 
        
        
            | 
            | 
           143 | 
           				$dummy .= $wiki->Footer();
  | 
        
        
            | 
            | 
           144 | 
           				$wiki->StopLinkTracking();
  | 
        
        
            | 
            | 
           145 | 
           				$wiki->WriteLinkTable();
  | 
        
        
            | 
            | 
           146 | 
           				$wiki->ClearLinkTable();
  | 
        
        
            | 
            | 
           147 | 
           			}
  | 
        
        
            | 
            | 
           148 | 
           			else
  | 
        
        
            | 
            | 
           149 | 
           			{
  | 
        
        
            | 
            | 
           150 | 
           				test("Insertion de la page $pagename ...", 0 ,"Existe déjà.",0);
  | 
        
        
            | 
            | 
           151 | 
           			}
  | 
        
        
            | 
            | 
           152 | 
              | 
        
        
            | 
            | 
           153 | 
           		}
  | 
        
        
            | 
            | 
           154 | 
           	}
  | 
        
        
            | 
            | 
           155 | 
           	break;
  | 
        
        
            | 
            | 
           156 | 
              | 
        
        
            | 
            | 
           157 | 
           	// The funny upgrading stuff. Make sure these are in order! //
  | 
        
        
            | 
            | 
           158 | 
           case "0.1":
  | 
        
        
            | 
            | 
           159 | 
           	echo "<b>En cours de mise à jour de WikiNi 0.1</b><br>\n";
  | 
        
        
            | 
            | 
           160 | 
           	test("Just very slightly altering the pages table...",
  | 
        
        
            | 
            | 
           161 | 
           		@mysql_query("alter table ".$config["table_prefix"]."pages add body_r text not null default '' after body", $dblink), "Already done? Hmm!", 0);
  | 
        
        
            | 
            | 
           162 | 
           	test("Claiming all your base...", 1);
  | 
        
        
            | 
            | 
           163 | 
           }
  | 
        
        
            | 
            | 
           164 | 
              | 
        
        
            | 
            | 
           165 | 
           ?>
  | 
        
        
            | 
            | 
           166 | 
              | 
        
        
            | 
            | 
           167 | 
           <p>
  | 
        
        
            | 
            | 
           168 | 
           A l'étape suivante, le programme d'installation va essayer
  | 
        
        
            | 
            | 
           169 | 
           d'écrire le fichier de configuration <tt><?php echo  $wakkaConfigLocation ?></tt>.
  | 
        
        
            | 
            | 
           170 | 
           Assurez vous que le serveur web a bien le droit d'écrire dans ce fichier, sinon vous devrez le modifier manuellement.  </p>
  | 
        
        
            | 
            | 
           171 | 
              | 
        
        
            | 
            | 
           172 | 
           <form action="<?php echo  myLocation(); ?>?installAction=writeconfig" method="POST">
  | 
        
        
            | 
            | 
           173 | 
           <input type="hidden" name="config" value="<?php echo  htmlentities(serialize($config)) ?>">
  | 
        
        
            | 
            | 
           174 | 
           <input type="submit" value="Continuer">
  | 
        
        
            | 
            | 
           175 | 
           </form>
  |