Wikiwig PHP Cross Reference Collaborative Wikis

Source: /_wk/setup/index.php - 283 lines - 10586 bytes - Summary - Text - Print

   1  <?php
   2    if(function_exists('error_reporting'))
   3      @error_reporting(E_ALL);
   4    if (!isset($_SESSION)) {
   5      session_start();
   6    }
   7  
   8    require_once  '../lib/Wiki_DB.php';
   9    require_once  '../lib/Wiki.php';
  10    require_once  '../lib/Wiki_User.php';
  11    require_once  '../lib/Wiki_PageDir.php';
  12    require_once  '../compat.php';
  13    define('WK_VERSION','5.01 alpha');
  14    define('WK_SYSTEM_DIR','_wk');
  15  
  16    // Detecting Path of the wiki and HTTP Path
  17    $current_path = str_replace("\\","/",__FILE__);
  18    $wkPath = substr($current_path, 0, strpos($current_path, WK_SYSTEM_DIR.'/'));
  19    define('WK_PATH',$wkPath);
  20    $current_url = $_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'];
  21    // there have been reports of getting // within the detected url. Make sure that doesn't happen
  22    while (strpos("//", $current_url) !== false) {
  23      $current_url = str_replace("//", "/", $current_url);
  24    }
  25    $current_url = 'http://'. $current_url;
  26    $wkHTTPPath = substr($current_url, 0, strpos($current_url, WK_SYSTEM_DIR.'/'));
  27    define('WK_HTTPPATH',$wkHTTPPath);
  28    global $WK;
  29  
  30    $user = false;
  31  
  32    // Attempt to load older config file
  33    if(@is_file('../wk_config.php')){
  34      require_once '../wk_config.php';
  35      require_once  'configuration_compat.php';
  36  
  37      // This either gets us a registered user or a guest
  38      $user = Wiki_User::currentUser();
  39  
  40      if (!$user->privileged() ) {
  41        Wiki_User::logout();
  42        // require_once '../wk_identification_admin.php';
  43        // $_SERVER['HTTP_REFERER'] = $current_url;
  44        if (isset($WK['wkHTTPSPath'])) {
  45          $redirection_url = $WK['wkHTTPSPath'] . WK_SYSTEM_DIR . '/wk_identification_admin.php?' . $_SERVER['PHP_SELF'];
  46        } else {
  47          $redirection_url = WK_HTTPPATH . WK_SYSTEM_DIR . '/wk_identification_admin.php?' . $_SERVER['PHP_SELF'];
  48        }
  49        header("Location: ".$redirection_url);
  50        exit;
  51      }
  52      if (!defined('WK_INSTALLED')) {
  53        @define('WK_INSTALLED',true); // already installed, update process
  54      }
  55    }
  56  
  57    // defining the language used
  58    if (isset($_POST['lang'])) {
  59      $WK['lang'] = $_POST['lang'];
  60    } elseif (isset($_GET['lang'])) {
  61      $WK['lang'] = $_GET['lang'];
  62    } elseif (!isset($WK['lang'])) {
  63      $WK['lang'] = 'fr';
  64      if ( isset( $_SERVER["HTTP_ACCEPT_LANGUAGE"] ) ) {
  65        $l = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
  66        if (strpos($l, "en-") == 0) {
  67          $WK['lang'] = 'en';
  68        } else if (strpos($l, "de-") == 0) {
  69          $WK['lang'] = 'de';
  70        } else if (strpos($l, "fr-") == 0) {
  71          $WK['lang'] = 'fr';
  72        }
  73      }
  74    }
  75    switch ($WK['lang']) {
  76      case 'fr':
  77      case 'de':
  78      case 'en':
  79        break;
  80      default: $WK['lang'] = 'fr'; // use default french
  81  
  82    }
  83  
  84    $file_lang = dirname(__FILE__).'/lang/'.$WK['lang'].'.php';
  85  
  86  
  87    if(!@is_file($file_lang)){ // language not available
  88      $WK['lang'] = 'fr'; // use default french
  89      require_once dirname(__FILE__).'/lang/'.$WK['lang'].'.php';
  90    } else // retrieves language defs
  91      require_once $file_lang;
  92  
  93    require_once  'setup.functions.inc.php';
  94  
  95  
  96    if (!isset($_POST['installAction'])) {
  97      $_POST['installAction'] = '';
  98    }
  99  
 100    if(defined('WK_INSTALLED')) {
 101      $page_title = WK_CONF_TITLE_UPDATE;
 102    } else {
 103      $page_title = WK_CONF_TITLE_INSTALL;
 104    }
 105  
 106    switch ($_POST['installAction']) {
 107      case 'check':
 108        $page_content = '';
 109        // Used to just overwrite $WK, now we overlay it. This lets config_compat
 110        // code create derived variables that don't exist in the tpl file and not
 111        // have them destroyed by overwriting the WK array.
 112        foreach($_POST as $key => $val){
 113          $WK[$key] = $val;
 114        }
 115  
 116        // Checking the configuration parameters
 117        $check_res = setup_checkConfiguration();
 118        if (is_array($check_res)) { //errors
 119          $page_content.= WK_CONF_ERRORS_CONF . '<br /><br />';
 120          $page_content.= '<span style="color: #FF0000">- ' . implode('<br />- ', $check_res) . '</span><br /><br />';
 121          $page_content.= setup_sprintConfigTemplate(setup_parseTemplate(dirname(__FILE__).'/installation_page.tpl.php'), $_POST, true);
 122          break;
 123        }  
 124        // configuration seems ok
 125  
 126        // Test if db is installed here since
 127        $db_already_installed = is_DB_installed();
 128        // Could be an upgrade where dir/history don't exist but user does
 129        $user_db_exists = is_any_user_DB_installed();
 130  
 131        // Installing the database
 132        if ($db_already_installed) {
 133          $page_content.= sprintf(WK_CONF_DB_ALREADY_INSTALLED,$_POST['dbName']).'<br/>';
 134          $admin = Wiki_User::currentUser();
 135        } else {
 136  
 137          $install_db_res = setup_installDatabase();
 138          if (is_array($install_db_res)) {
 139            $page_content.= WK_CONF_ERRORS_INSTALL . '<br /><br />';
 140            $page_content.= '<span style="color: #FF0000">- ' . implode('<br />', $install_db_res) . '</span><br /><br />';
 141            $page_content.= setup_sprintConfigTemplate(setup_parseTemplate(dirname(__FILE__).'/installation_page.tpl.php'), $_POST, true);
 142            break;
 143          }
 144          if($install_db_res === false) {
 145            $page_content.= WK_CONF_ERRORS_INSTALL . '<br /><br />';
 146            $page_content.= '<span style="color: #FF0000">- ' . WK_CONF_ERR_DB_INSTALL . '</span><br /><br />';
 147            break;
 148          }
 149  
 150          $page_content.= sprintf(WK_CONF_DB_INSTALLED,$_POST['dbName']).'<br/>';
 151        }
 152  
 153        // Writing the Configuration
 154        $write_conf_res = setup_updateConfiguration();
 155        if (is_array($write_conf_res)) {
 156          $page_content.= WK_CONF_ERRORS_INSTALL . '<br /><br />';
 157          $page_content.= '<span style="color: #FF0000">- ' . implode('<br />', $write_conf_res) . '</span><br /><br />';
 158          $page_content.= setup_sprintConfigTemplate(setup_parseTemplate(dirname(__FILE__).'/installation_page.tpl.php'), $_POST, true);
 159          break;
 160        }
 161  
 162        if (!$user_db_exists) {
 163          // Now install the admin account
 164          $admin = new Wiki_User();
 165          // Create a privileged user
 166          $admin->fillin($_POST['adminLogin'], md5($_POST['adminPass']), $_POST['adminMail'], true);
 167          // Install in database
 168          $res = $admin->insert();
 169          if ($res !== true) {
 170            $page_content.= WK_CONF_ERRORS_INSTALL . '<br /><br />';
 171            if (is_array($res)) {
 172              $page_content.= '<span style="color: #FF0000">- ' . implode('<br />', $res) . '</span><br /><br />';
 173            } else {
 174              $page_content.= '<span style="color: #FF0000">- ' . $res . '</span><br /><br />';
 175            }
 176            break;
 177          }
 178          // Log in the admin
 179          $admin->login();
 180        }
 181  
 182  
 183        $page_content.= WK_CONF_UPDATED.'<br/><br/>';
 184        // configuration updated
 185        $page_content.= sprintf(WK_CONF_SAVED_SUCCESSFUL, WK_HTTPPATH);
 186        if(!defined('WK_INSTALLED')) {
 187          $page_content.= sprintf(WK_CONF_SAVED_SUCCESSFUL2, $_POST['adminLogin'], $_POST['adminPass']).'<br/><br/>';
 188        }
 189          
 190        // Attempt to write the home page file
 191        // if wikiwig was not not previously installed
 192        if(!defined('WK_INSTALLED') || !@is_file(WK_PATH.'index.html')) {
 193          //echo WK_PATH.'index.html';
 194          Wiki::createPage('', "index", HOMEPAGE_CONTENT, $_POST['wkName'] );
 195              
 196        } else {
 197          // indicates to the user that he should launch the parsing of the wiki
 198          $page_content.= '<strong>'.sprintf(WK_CONF_UPGRADE_MSG,'../wk_admin.php','../wk_admin.php?action=parseall').'</strong><br/><br/>';
 199        }
 200        if (!defined('WK_INSTALLED')) {
 201          @define('WK_INSTALLED',true); // already installed, update process
 202        }
 203  
 204          
 205       break;
 206  
 207      default:
 208        /*  Is wikiwig already installed=  */
 209        if (defined('WK_INSTALLED')) {
 210          $from = &$WK;
 211        } else {
 212          $from = false;
 213        }
 214        $page_content = setup_parseTemplate(dirname(__FILE__).'/installation_page.tpl.php');
 215          
 216        /* COMMENTAIRE 
 217         * janvier 2006
 218         * si l'admin est déjà enregistré dans la base il faut aller le chercher
 219         *  et le remplasser dans l'affichage du config
 220         *  sinon, laisser la config comme avant.
 221         */
 222  
 223        // Babelfish was kind of useless on the translation above but I think it
 224        // says that is no database has been configured yet that the query fails
 225        // and it is was commented out. Now we try and determine if a db has
 226        // been configured first. fatcatair 2007
 227        $dbType = Wiki::getConfig('dbType');
 228        if ($dbType) {
 229          if (defined('WK_INSTALLED')) {
 230            for ($i = sizeof($page_content['categories']['WK_CONF_GENERAL']) - 1;  $i >= 0; $i--){
 231              $name = $page_content['categories']['WK_CONF_GENERAL'][$i]['name'];
 232              if ($name=="adminLogin" || $name=="adminPass" || $name=="adminMail") {
 233                array_splice($page_content['categories']['WK_CONF_GENERAL'], $i, 1);
 234              }
 235            }
 236            $page_content = setup_sprintConfigTemplate($page_content, $from);
 237          } else {
 238           $page_content = setup_sprintConfigTemplate(setup_parseTemplate(dirname(__FILE__).'/installation_page.tpl.php'), $from);
 239          }
 240        } else {
 241          $page_content = setup_sprintConfigTemplate(setup_parseTemplate(dirname(__FILE__).'/installation_page.tpl.php'), $from);
 242        }
 243    }
 244  
 245  ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 246  <html>
 247    <head>
 248      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
 249      <title><?php echo WK_CONF_TITLE; ?></title>
 250      <link href="../wk_style.css" rel="stylesheet" type="text/css" />
 251  
 252    </head>
 253  
 254    <body class="actions">
 255      <div id="header"><?php echo WK_CONF_TITLE; ?></div>
 256      <div id="results">
 257        <span class="errors">
 258                   
 259        </span>
 260        <span class="message">
 261                   
 262        </span>
 263      </div>
 264      <div id="content">
 265        <h1><?php echo $page_title; ?></h1>
 266        <?php print_r($page_content); ?> 
 267      </div>
 268  <?php
 269      if(empty($_POST['installAction'])) {
 270  ?>
 271        <div id="flags" style="position:absolute;right:50px;top:60px;">
 272      <a href="?lang=fr" title="Version Fran&ccedil;aise"><img src="../images/flag-french.gif" alt="Version Fran&ccedil;aise" /></a>
 273      <a href="?lang=en" title="English Version"><img src="../images/flag-english.gif" alt="English Version" /></a>
 274      <a href="?lang=de" title="German Version"><img src="../images/flag-german.gif" alt="German Version" /></a>
 275        </div>
 276  <?php
 277      }
 278  ?> 
 279      <div style="position:absolute;right:30px;top:30px;">
 280        <a href="../wk_admin.php"><?php echo WK_CONF_LABEL_LINK_ADMIN; ?></a>&nbsp;|&nbsp;<a href='../../index.html'><?php echo WK_CONF_LABEL_GO_WIKI; ?></a>
 281      </div>
 282    </body>
 283  </html>

title

Description

title

Description

title

Description

title

title

Body