Installer default content is now modular, and can pivot between starting with a blank site and installing a tutorial site.
authorDan
Wed, 15 Apr 2009 22:18:14 -0400
changeset 924 142a29b583f9
parent 923 9ef3ccac13de
child 925 173aef60c13c
Installer default content is now modular, and can pivot between starting with a blank site and installing a tutorial site.
install/includes/cli-core.php
install/includes/payload.php
install/includes/stages/install.php
install/includes/stages/website.php
install/schemas/mysql_stage2.sql
install/schemas/postgresql_stage2.sql
language/english/install.json
language/english/install/default-blank/Main_Page.txt
language/english/install/default-tutorial/Main_Page.txt
language/english/install/mainpage-default.wkt
--- a/install/includes/cli-core.php	Wed Apr 15 20:24:51 2009 -0400
+++ b/install/includes/cli-core.php	Wed Apr 15 22:18:14 2009 -0400
@@ -601,19 +601,6 @@
   installer_fail($lang->get('cli_err_schema_load'));
 }
 
-$wkt = ENANO_ROOT . "/language/{$languages[$lang_id]['dir']}/install/mainpage-default.wkt";
-if ( !file_exists( $wkt ) )
-{
-  if ( !$silent )
-    echo "\n";
-  installer_fail($lang->get('cli_err_mainpage_load'));
-}
-$wkt = @file_get_contents($wkt);
-if ( empty($wkt) )
-  return false;
-
-$wkt = $db->escape($wkt);
-
 $vars = array(
     'TABLE_PREFIX'         => table_prefix,
     'SITE_NAME'            => $db->escape($sitename),
@@ -629,7 +616,6 @@
     'REAL_NAME'            => '', // This has always been stubbed.
     'ADMIN_EMBED_PHP'      => strval(AUTH_DISALLOW),
     'UNIX_TIME'            => strval(time()),
-    'MAIN_PAGE_CONTENT'    => $wkt,
     'IP_ADDRESS'           => $_SERVER['REMOTE_ADDR']
   );
 
@@ -700,7 +686,11 @@
 if ( !$silent )
   echo parse_shellcolor_string($lang->get('cli_msg_ok')) . "\n";
 
+$_POST['username'] =& $user;
+$_POST['default_content_type'] = ( isset($start_with) ) ? $start_with : 'blank';
+
 run_installer_stage('importlang', 'importing_language', 'stg_language_setup', $lang->get('install_stg_importlang_body'));
+run_installer_stage('importcontent', 'importing_content', 'stg_add_content', $lang->get('install_stg_importcontent_body'));
 run_installer_stage('initlogs', 'initting_logs', 'stg_init_logs', $lang->get('install_stg_initlogs_body'));
 run_installer_stage('cleanup', 'cleaning_up', 'stg_aes_cleanup', $lang->get('install_stg_cleanup_body'), false);
 run_installer_stage('buildindex', 'initting_index', 'stg_build_index', $lang->get('install_stg_buildindex_body'));
--- a/install/includes/payload.php	Wed Apr 15 20:24:51 2009 -0400
+++ b/install/includes/payload.php	Wed Apr 15 22:18:14 2009 -0400
@@ -115,18 +115,6 @@
     return false;
   }
   
-  $wkt = ENANO_ROOT . "/language/{$languages[$lang_id]['dir']}/install/mainpage-default.wkt";
-  if ( !file_exists( $wkt ) )
-  {
-    echo '<div class="error-box">Error: could not locate wikitext for main page (' . $wkt . ')</div>';
-    return false;
-  }
-  $wkt = @file_get_contents($wkt);
-  if ( empty($wkt) )
-    return false;
-  
-  $wkt = $db->escape($wkt);
-  
   $vars = array(
       'TABLE_PREFIX'         => table_prefix,
       'SITE_NAME'            => $db->escape($_POST['site_name']),
@@ -143,7 +131,6 @@
       'REAL_NAME'            => '', // This has always been stubbed.
       'ADMIN_EMBED_PHP'      => strval(AUTH_DISALLOW),
       'UNIX_TIME'            => strval(time()),
-      'MAIN_PAGE_CONTENT'    => $wkt,
       'IP_ADDRESS'           => $db->escape($_SERVER['REMOTE_ADDR'])
     );
   
@@ -346,6 +333,93 @@
   return true;
 }
 
+function stg_add_content()
+{
+  global $db, $session, $paths, $template, $plugins; // Common objects
+  global $cache;
+  
+  global $languages;
+  global $lang_id;
+  $lang_info =& $languages[$lang_id];
+  if ( !is_array($lang_info) )
+    return false;
+  
+  if ( $_POST['default_content_type'] === 'tutorial' )
+  {
+    $dir = ENANO_ROOT . "/language/{$lang_info['dir']}/install/default-tutorial";
+  }
+  else
+  {
+    $dir = ENANO_ROOT . "/language/{$lang_info['dir']}/install/default-blank";
+  }
+  
+  if ( !$dr = @opendir($dir) )
+    return false;
+  
+  while ( $dh = @readdir($dr) )
+  {
+    if ( !preg_match('/\.txt$/', $dh) )
+      continue;
+    
+    $page_contents = @file_get_contents("$dir/$dh");
+    if ( empty($page_contents) )
+      return false;
+    
+    $page_name = preg_replace('/\.txt$/', '', $dh);
+    
+    if ( !install_primitive_page_creator($page_name, 'Article', $page_contents) )
+      return false;
+  }
+  
+  closedir($dr);
+  
+  $cache->purge('page_meta');
+  
+  return true;
+}
+
+function install_primitive_page_creator($page_id, $namespace, $content)
+{
+  global $db, $session, $paths, $template, $plugins; // Common objects
+  
+  $page_title = $db->escape(str_replace('_', ' ', dirtify_page_id($page_id)));
+  $author = $db->escape($_POST['username']);
+  $page_id = $db->escape($page_id);
+  $namespace = $db->escape($namespace);
+  // yes, we do probably want strip_all_php ON.
+  $content = RenderMan::preprocess_text($content, true, true);
+  $now = time();
+  
+  // query 1: logs
+  $q = $db->sql_query('INSERT INTO ' . table_prefix . "logs(time_id, date_string, log_type, action, page_id, namespace, author, page_text) VALUES\n"
+                    . "  ( $now, 'DEPRECATED', 'page', 'edit', '$page_id', '$namespace', '$author', '$content');");
+  if ( !$q )
+  {
+    echo $db->get_error();
+    return false;
+  }
+  
+  // query 2: page_text
+  $q = $db->sql_query('INSERT INTO ' . table_prefix . "page_text(page_id, namespace, page_text) VALUES\n"
+                    . "  ( '$page_id', '$namespace', '$content');");
+  if ( !$q )
+  {
+    echo $db->get_error();
+    return false;
+  }
+  
+  // query 3: pages
+  $q = $db->sql_query('INSERT INTO ' . table_prefix . "pages(page_order, name, urlname, namespace, special, visible, comments_on, protected, delvotes, delvote_ips) VALUES\n"
+                    . "  (NULL, '$page_title', '$page_id', '$namespace', 0, 1, 1, 1, 0, '');");
+  if ( !$q )
+  {
+    echo $db->get_error();
+    return false;
+  }
+  
+  return true;
+}
+
 function stg_init_logs()
 {
   global $db, $session, $paths, $template, $plugins; // Common objects
--- a/install/includes/stages/install.php	Wed Apr 15 20:24:51 2009 -0400
+++ b/install/includes/stages/install.php	Wed Apr 15 22:18:14 2009 -0400
@@ -108,6 +108,9 @@
 error_reporting(E_ALL | E_STRICT);
 run_installer_stage('importlang', $lang->get('install_stg_importlang_title'), 'stg_language_setup', $lang->get('install_stg_importlang_body'));
 
+// Pull in default content
+run_installer_stage('importcontent', $lang->get('install_stg_importcontent_title'), 'stg_add_content', $lang->get('install_stg_importcontent_body'));
+
 // Init logs
 run_installer_stage('initlogs', $lang->get('install_stg_initlogs_title'), 'stg_init_logs', $lang->get('install_stg_initlogs_body'));
 
--- a/install/includes/stages/website.php	Wed Apr 15 20:24:51 2009 -0400
+++ b/install/includes/stages/website.php	Wed Apr 15 22:18:14 2009 -0400
@@ -225,6 +225,41 @@
     </tr>
     
     <tr>
+      <td>
+        <b><?php echo $lang->get('website_field_startwith'); ?></b>
+      </td>
+      <td>
+      
+        <table border="0">
+          <tr>
+            <td>
+      
+              <label>
+                <input type="radio" name="default_content_type" value="blank" checked="checked" tabindex="4" />
+                <?php echo $lang->get('website_field_startwith_blank'); ?>
+              </label>
+              <span class="fieldtip" id="hint_default_content_type_blank">
+                <p><?php echo $lang->get('website_field_startwith_blank_hint'); ?></p>
+              </span>
+              
+              <br />
+              
+              <label>
+                <input type="radio" name="default_content_type" value="tutorial" tabindex="4" />
+                <?php echo $lang->get('website_field_startwith_tutorial'); ?>
+              </label>
+              <span class="fieldtip" id="hint_default_content_type_tutorial">
+                <p><?php echo $lang->get('website_field_startwith_tutorial_hint'); ?></p>
+              </span>
+              
+            </td>
+          </tr>
+        </table>
+        
+      </td>
+    </tr>
+    
+    <tr>
       <td valign="top">
         <b><?php echo $lang->get('website_field_urlscheme'); ?></b><br />
         <?php echo $lang->get('website_field_urlscheme_hint'); ?>
@@ -234,7 +269,7 @@
         <table border="0" cellpadding="10" cellspacing="0">
           <tr>
             <td valign="top">
-              <input type="radio" name="url_scheme" value="standard" id="url_radio_standard" tabindex="5" />
+              <input type="radio" name="url_scheme" value="standard" id="url_radio_standard" tabindex="6" />
             </td>
             <td>
               <label for="url_radio_standard">
@@ -251,7 +286,7 @@
         <table border="0" cellpadding="10" cellspacing="0">
           <tr>
             <td valign="top">
-              <input type="radio" checked="checked" name="url_scheme" value="shortened" id="url_radio_shortened" tabindex="5" />
+              <input type="radio" checked="checked" name="url_scheme" value="shortened" id="url_radio_shortened" tabindex="6" />
             </td>
             <td>
               <label for="url_radio_shortened">
@@ -268,7 +303,7 @@
         <table border="0" cellpadding="10" cellspacing="0">
           <tr>
             <td valign="top">
-              <input type="radio" name="url_scheme" value="rewrite" id="url_radio_rewrite" tabindex="5" />
+              <input type="radio" name="url_scheme" value="rewrite" id="url_radio_rewrite" tabindex="6" />
             </td>
             <td>
               <label for="url_radio_rewrite">
@@ -285,7 +320,7 @@
         <table border="0" cellpadding="10" cellspacing="0">
           <tr>
             <td valign="top">
-              <input type="radio" name="url_scheme" value="tiny" id="url_radio_tiny" tabindex="5" />
+              <input type="radio" name="url_scheme" value="tiny" id="url_radio_tiny" tabindex="6" />
             </td>
             <td>
               <label for="url_radio_tiny">
@@ -300,7 +335,7 @@
         </table>
         
         <p>
-          <a href="#mrw_scan" onclick="ajaxMrwTest(); return false;" tabindex="4"><?php echo $lang->get('website_btn_urlscheme_detect'); ?></a>
+          <a href="#mrw_scan" onclick="ajaxMrwTest(); return false;" tabindex="5"><?php echo $lang->get('website_btn_urlscheme_detect'); ?></a>
         </p>
         
         <div id="mrw_report"></div>
@@ -311,7 +346,7 @@
   </table>
   
   <div style="text-align: center;">
-    <input type="submit" name="_cont" value="<?php echo $lang->get('meta_btn_continue'); ?>" tabindex="6" />
+    <input type="submit" name="_cont" value="<?php echo $lang->get('meta_btn_continue'); ?>" tabindex="7" />
   </div>
   
 </form>
--- a/install/schemas/mysql_stage2.sql	Wed Apr 15 20:24:51 2009 -0400
+++ b/install/schemas/mysql_stage2.sql	Wed Apr 15 22:18:14 2009 -0400
@@ -360,15 +360,6 @@
   ('theme_default', 'enanium'),
   ('enano_version', '{{VERSION}}');
 
-INSERT INTO {{TABLE_PREFIX}}page_text(page_id, namespace, page_text, char_tag) VALUES
-  ('Main_Page', 'Article', '{{MAIN_PAGE_CONTENT}}', '');
-  
-INSERT INTO {{TABLE_PREFIX}}logs(time_id, date_string, log_type, action, page_id, namespace, author, page_text) VALUES
-  ({{UNIX_TIME}}, 'DEPRECATED', 'page', 'edit', 'Main_Page', 'Article', '{{ADMIN_USER}}', '{{MAIN_PAGE_CONTENT}}');
-
-INSERT INTO {{TABLE_PREFIX}}pages(page_order, name, urlname, namespace, special, visible, comments_on, protected, delvotes, delvote_ips) VALUES
-  (NULL, 'Main Page', 'Main_Page', 'Article', 0, 1, 1, 1, 0, '');
-
 INSERT INTO {{TABLE_PREFIX}}themes(theme_id, theme_name, theme_order, default_style, enabled) VALUES
   ('enanium', 'Enanium', 1, 'babygrand.css', 1),
   ('oxygen', 'Oxygen', 2, 'bleu.css', 1),
--- a/install/schemas/postgresql_stage2.sql	Wed Apr 15 20:24:51 2009 -0400
+++ b/install/schemas/postgresql_stage2.sql	Wed Apr 15 22:18:14 2009 -0400
@@ -365,15 +365,6 @@
   ('theme_default', 'enanium'),
   ('enano_version', '{{VERSION}}');
 
-INSERT INTO {{TABLE_PREFIX}}page_text(page_id, namespace, page_text, char_tag) VALUES
-  ('Main_Page', 'Article', '{{MAIN_PAGE_CONTENT}}', '');
-  
-INSERT INTO {{TABLE_PREFIX}}logs(time_id, date_string, log_type, action, page_id, namespace, author, page_text) VALUES
-  ({{UNIX_TIME}}, 'DEPRECATED', 'page', 'edit', 'Main_Page', 'Article', '{{ADMIN_USER}}', '{{MAIN_PAGE_CONTENT}}');
-
-INSERT INTO {{TABLE_PREFIX}}pages(page_order, name, urlname, namespace, special, visible, comments_on, protected, delvotes, delvote_ips) VALUES
-  (NULL, 'Main Page', 'Main_Page', 'Article', 0, 1, 1, 1, 0, '');
-
 INSERT INTO {{TABLE_PREFIX}}themes(theme_id, theme_name, theme_order, default_style, enabled) VALUES
   ('enanium', 'Enanium', 1, 'babygrand.css', 1),
   ('oxygen', 'Oxygen', 2, 'bleu.css', 1),
--- a/language/english/install.json	Wed Apr 15 20:24:51 2009 -0400
+++ b/language/english/install.json	Wed Apr 15 22:18:14 2009 -0400
@@ -262,6 +262,11 @@
       field_desc_hint: 'Here you should enter a very short description of your site. Sometimes this is a slogan or, depending on the theme you\'ve chosen, a set of keywords that can go into a META description tag.',
       field_copyright: 'Copyright info',
       field_copyright_hint: 'The text you enter here will be shown at the bottom of most pages. Typically this is where a copyright notice would go. Keep it short and sweet; you can use <a href="http://docs.enanocms.org/Help:3.1">internal links</a> to link to project pages you\'ll create later.',
+      field_startwith: 'Start with:',
+      field_startwith_blank: 'A blank site with only a main page',
+      field_startwith_blank_hint: 'This is best if you\'ve worked with Enano or other wiki software before and for production installations. It installs one page which you can edit to immediately get started on your site.',
+      field_startwith_tutorial: 'The Enano tutorial suite',
+      field_startwith_tutorial_hint: 'This option installs several tutorial pages that help you to get started quickly if you\'re new to Enano.',
       field_urlscheme: 'URL formatting',
       field_urlscheme_hint: 'This lets you choose how URLs within your site will be formatted. If the setting you pick doesn\'t work, you can change it by editing config.php after installation.',
       field_urlscheme_lbl_example: 'Example:',
@@ -334,6 +339,8 @@
       stg_startapi_body: 'The Enano API could not be started. This is an error that should never occur; please contact the Enano team for support.',
       stg_importlang_title: 'Import default language',
       stg_importlang_body: 'Enano couldn\'t import the English language file.',
+      stg_importcontent_title: 'Import default content',
+      stg_importcontent_body: 'Enano couldn\'t import the default site content.',
       stg_initlogs_title: 'Initialize logs',
       stg_initlogs_body: '<b>The session manager denied the request to flush logs for the main page.</b><br />
                            While under most circumstances you can still <a href="install.php?mode=finish">finish the installation</a>, you should be aware that some servers cannot
@@ -482,6 +489,7 @@
       msg_writing_config: '<c 1>Generating config file...</c>',
       msg_starting_api: '<c 1>Starting up the Enano API...</c>',
       msg_importing_language: '<c 1>Importing default language...</c>',
+      msg_importing_content: '<c 1>Installing default content...</c>',
       msg_initting_logs: '<c 1>Initializing logs...</c>',
       msg_cleaning_up: '<c 1>Removing temporary data...</c>',
       msg_initting_index: '<c 1>Initializing search index...</c>',
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/language/english/install/default-blank/Main_Page.txt	Wed Apr 15 22:18:14 2009 -0400
@@ -0,0 +1,17 @@
+=== Thanks for helping to test Enano. ===
+
+If you're reading this, you just installed the beta version of [http://enanocms.org/Caoineag Enano 1.2.0], the next-generation release of Enano. Congratulations!
+
+If you find any bugs, we'd really like it if you let us know either via the [http://forum.enanocms.org/ forum] or [irc://irc.freenode.net/#enano IRC]. Enano's a big project, so tracking down bugs is hard and we need your help to do it.
+
+=== Support (or lack thereof) ===
+
+Because this is a beta release, we can't provide any mainstream support for you. We can publish workarounds for bugs, but we can't help you figure out why a plugin doesn't work or why your server's generating a 403 error. If you need help getting started with Enano, use [http://enanocms.org/download?series=1.0 a stable release].
+
+=== New to Enano? ===
+
+To edit this front page, click the Log In button to the left, enter the credentials you provided during the installation, and click the Edit This Page button that appears on the blue toolbar just above this text. You can also [http://docs.enanocms.org/Help:2.4 learn more] about editing pages.
+
+To create more pages, use the Create a Page button to the left. If you enabled wiki mode, you don't have to log in first, however your IP address will be shown in the page history.
+
+Visit the [http://docs.enanocms.org/Help:Contents Enano documentation project website] to learn more about administering your site effectively and keeping things secure.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/language/english/install/default-tutorial/Main_Page.txt	Wed Apr 15 22:18:14 2009 -0400
@@ -0,0 +1,13 @@
+=== Thanks for helping to test Enano. ===
+
+If you're reading this, you just installed the beta version of [http://enanocms.org/Caoineag Enano 1.2.0], the next-generation release of Enano. Congratulations!
+
+If you find any bugs, we'd really like it if you let us know either via the [http://forum.enanocms.org/ forum] or [irc://irc.freenode.net/#enano IRC]. Enano's a big project, so tracking down bugs is hard and we need your help to do it.
+
+=== Support (or lack thereof) ===
+
+Because this is a beta release, we can't provide any mainstream support for you. We can publish workarounds for bugs, but we can't help you figure out why a plugin doesn't work or why your server's generating a 403 error. If you need help getting started with Enano, use [http://enanocms.org/download?series=1.0 a stable release].
+
+=== Take the Enano tutorial ===
+
+Enano is tremendously easy to get started with. The first thing you should do is use the username and password you entered when you installed Enano to [[Special:Login/Creating_and_editing_pages|log in to start the tutorial]]. You'll learn how to create and edit pages, set up basic security settings, install plugins, and much more.
--- a/language/english/install/mainpage-default.wkt	Wed Apr 15 20:24:51 2009 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,17 +0,0 @@
-=== Thanks for helping to test Enano. ===
-
-If you're reading this, you just installed the beta version of [http://enanocms.org/Caoineag Enano 1.2.0], the next-generation release of Enano. Congratulations!
-
-If you find any bugs, we'd really like it if you let us know either via the [http://forum.enanocms.org/ forum] or [irc://irc.freenode.net/#enano IRC]. Enano's a big project, so tracking down bugs is hard and we need your help to do it.
-
-=== Support (or lack thereof) ===
-
-Because this is a beta release, we can't provide any mainstream support for you. We can publish workarounds for bugs, but we can't help you figure out why a plugin doesn't work or why your server's generating a 403 error. If you need help getting started with Enano, use [http://enanocms.org/download?series=1.0 a stable release].
-
-=== New to Enano? ===
-
-To edit this front page, click the Log In button to the left, enter the credentials you provided during the installation, and click the Edit This Page button that appears on the blue toolbar just above this text. You can also [http://docs.enanocms.org/Help:2.4 learn more] about editing pages.
-
-To create more pages, use the Create a Page button to the left. If you enabled wiki mode, you don't have to log in first, however your IP address will be shown in the page history.
-
-Visit the [http://docs.enanocms.org/Help:Contents Enano documentation project website] to learn more about administering your site effectively and keeping things secure.