Index: inc/dbschema/db-schema.php
===================================================================
--- inc/dbschema/db-schema.php	(revision 1107)
+++ inc/dbschema/db-schema.php	(revision 1179)
@@ -4,5 +4,5 @@
 # This file is part of Dotclear 2.
 #
-# Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear
+# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
 # Licensed under the GPL version 2.0 license.
 # See LICENSE file or
@@ -29,4 +29,19 @@
 	
 	->primary('pk_blog','blog_id')
+	;
+
+$_s->category
+	->cat_id		('bigint',	0,	false)
+	->blog_id		('varchar',	32,	false)
+	->cat_title	('varchar',	255,	false)
+	->cat_url		('varchar',	255,	false)
+	->cat_desc	('text',		0,	true)
+	->cat_position	('integer',	0,	true,	0)
+	->cat_lft		('integer',	0,	true)
+	->cat_rgt		('integer',	0,	true)
+	
+	->primary('pk_category','cat_id')
+	
+	->unique('uk_cat_url','cat_url','blog_id')
 	;
 
@@ -87,8 +102,10 @@
 	->blog_id				('varchar',	32,	false)
 	->user_id				('varchar',	32,	false)
+	->cat_id				('bigint',	0,	true)
 	->post_dt				('timestamp',	0,	false,	'now()')
 	->post_tz				('varchar',	128,	false,	"'UTC'")
 	->post_creadt			('timestamp',	0,	false,	'now()')
 	->post_upddt			('timestamp',	0,	false,	'now()')
+	->post_password		('varchar',	32,	true,	null)
 	->post_type			('varchar',	32,	false,	"'post'")
 	->post_format			('varchar',	32,	false,	"'xhtml'")
@@ -106,4 +123,9 @@
 	->post_selected		('smallint',	0,	false,	0)
 	->post_position		('integer',	0,	false,	0)
+	->post_open_comment		('smallint',	0,	false,	0)
+	->post_open_tb			('smallint',	0,	false,	0)
+	->nb_comment			('integer',	0,	false,	0)
+	->nb_trackback			('integer',	0,	false,	0)
+	
 	->primary('pk_post','post_id')
 	
@@ -111,4 +133,27 @@
 	;
 
+$_s->media
+	->media_id		('bigint',	0,	false)
+	->user_id			('varchar',	32,	false)
+	->media_path		('varchar',	255,	false)
+	->media_title		('varchar',	255,	false)
+	->media_file		('varchar',	255,	false)
+	->media_dir		('varchar',	255,	false,	"'.'")
+	->media_meta		('text',		0,	true,	null)
+	->media_dt		('timestamp',	0,	false,	'now()')
+	->media_creadt		('timestamp',	0,	false,	'now()')
+	->media_upddt		('timestamp',	0,	false,	'now()')
+	->media_private	('smallint',	0,	false,	0)
+	
+	->primary('pk_media','media_id')
+	;
+
+$_s->post_media
+	->media_id	('bigint',	0,	false)
+	->post_id		('bigint',	0,	false)
+	->link_type		('varchar',	32,	false,	"'attachment'")
+	
+	->primary('pk_post_media','media_id','post_id','link_type')
+	;
 
 $_s->log
@@ -131,4 +176,32 @@
 	;
 
+$_s->ping
+	->post_id		('bigint',	0,	false)
+	->ping_url	('varchar',	255,	false)
+	->ping_dt		('timestamp',	0,	false,	'now()')
+	
+	->primary('pk_ping','post_id','ping_url')
+	;
+
+$_s->comment
+	->comment_id			('bigint',	0,	false)
+	->post_id				('bigint',	0,	false)
+	->comment_dt			('timestamp',	0,	false,	'now()')
+	->comment_tz			('varchar',	128,	false,	"'UTC'")
+	->comment_upddt		('timestamp',	0,	false,	'now()')
+	->comment_author		('varchar',	255,	true,	null)
+	->comment_email		('varchar',	255,	true,	null)
+	->comment_site			('varchar',	255,	true,	null)
+	->comment_content		('text',		0,	true)
+	->comment_words		('text',		0,	true,	null)
+	->comment_ip			('varchar',	39,	true,	null)
+	->comment_status		('smallint',	0,	true,	0)
+	->comment_spam_status	('varchar',	128,	true,	0)
+	->comment_spam_filter	('varchar',	32,	true,	null)
+	->comment_trackback		('smallint',	0,	false,	0)
+	
+	->primary('pk_comment','comment_id')
+	;
+
 $_s->meta
 	->meta_id		('varchar',	255,	false)
@@ -152,10 +225,18 @@
 /* References indexes
 -------------------------------------------------------- */
+$_s->category->index	('idx_category_blog_id',			'btree',	'blog_id');
+$_s->category->index	('idx_category_cat_lft_blog_id',	'btree',	'blog_id', 'cat_lft');
+$_s->category->index	('idx_category_cat_rgt_blog_id',	'btree',	'blog_id', 'cat_rgt');
 $_s->setting->index		('idx_setting_blog_id',			'btree',	'blog_id');
 $_s->user->index		('idx_user_user_default_blog',	'btree',	'user_default_blog');
 $_s->permissions->index	('idx_permissions_blog_id',		'btree',	'blog_id');
+$_s->post->index		('idx_post_cat_id',				'btree',	'cat_id');
 $_s->post->index		('idx_post_user_id',			'btree',	'user_id');
 $_s->post->index		('idx_post_blog_id',			'btree',	'blog_id');
+$_s->media->index		('idx_media_user_id',			'btree',	'user_id');
+$_s->post_media->index	('idx_post_media_post_id',		'btree',	'post_id');
+$_s->post_media->index	('idx_post_media_media_id',		'btree',	'media_id');
 $_s->log->index		('idx_log_user_id',				'btree',	'user_id');
+$_s->comment->index		('idx_comment_post_id',			'btree',	'post_id');
 $_s->meta->index		('idx_meta_post_id',	'btree','post_id');
 $_s->meta->index		('idx_meta_meta_type',	'btree','meta_type');
@@ -164,4 +245,5 @@
 /* Performance indexes
 -------------------------------------------------------- */
+$_s->comment->index		('idx_comment_post_id_dt_status',	'btree',	'post_id', 'comment_dt', 'comment_status');
 $_s->post->index		('idx_post_post_dt',			'btree',	'post_dt');
 $_s->post->index		('idx_post_post_dt_post_id',		'btree',	'post_dt','post_id');
@@ -173,10 +255,17 @@
 /* Foreign keys
 -------------------------------------------------------- */
+$_s->category->reference('fk_category_blog','blog_id','blog','blog_id','cascade','cascade');
 $_s->setting->reference('fk_setting_blog','blog_id','blog','blog_id','cascade','cascade');
 $_s->user->reference('fk_user_default_blog','user_default_blog','blog','blog_id','cascade','set null');
 $_s->permissions->reference('fk_permissions_blog','blog_id','blog','blog_id','cascade','cascade');
 $_s->permissions->reference('fk_permissions_user','user_id','user','user_id','cascade','cascade');
+$_s->post->reference('fk_post_category','cat_id','category','cat_id','cascade','set null');
 $_s->post->reference('fk_post_user','user_id','user','user_id','cascade','cascade');
 $_s->post->reference('fk_post_blog','blog_id','blog','blog_id','cascade','cascade');
+$_s->media->reference('fk_media_user','user_id','user','user_id','cascade','cascade');
+$_s->post_media->reference('fk_media','media_id','media','media_id','cascade','cascade');
+$_s->post_media->reference('fk_media_post','post_id','post','post_id','cascade','cascade');
+$_s->ping->reference('fk_ping_post','post_id','post','post_id','cascade','cascade');
+$_s->comment->reference('fk_comment_post','post_id','post','post_id','cascade','cascade');
 $_s->log->reference('fk_log_blog','blog_id','blog','blog_id','cascade','set null');
 $_s->meta->reference('fk_meta_post','post_id','post','post_id','cascade','cascade');
@@ -188,4 +277,5 @@
 {
 	$_s->setting->index		('idx_setting_blog_id_null',	'btree',	'(blog_id IS NULL)');
+	$_s->media->index		('idx_media_media_path',		'btree',	'media_path', 'media_dir');
 	$_s->pref->index		('idx_pref_user_id_null',		'btree',	'(user_id IS NULL)');
 }
Index: inc/dbschema/upgrade-cli.php
===================================================================
--- inc/dbschema/upgrade-cli.php	(revision 838)
+++ inc/dbschema/upgrade-cli.php	(revision 1179)
@@ -5,5 +5,5 @@
 # This file is part of Dotclear 2.
 #
-# Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear
+# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
 # Licensed under the GPL version 2.0 license.
 # See LICENSE file or
Index: inc/dbschema/upgrade.php
===================================================================
--- inc/dbschema/upgrade.php	(revision 1107)
+++ inc/dbschema/upgrade.php	(revision 1179)
@@ -4,5 +4,5 @@
 # This file is part of Dotclear 2.
 #
-# Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear
+# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
 # Licensed under the GPL version 2.0 license.
 # See LICENSE file or
@@ -41,9 +41,9 @@
 			{
 				$strReq = 'SELECT media_id, media_file FROM '.$core->prefix.'media ';
-				$medias = $core->con->select($strReq);
-				foreach ($medias as $m) {
+				$rs_m = $core->con->select($strReq);
+				while($rs_m->fetch()) {
 					$cur = $core->con->openCursor($core->prefix.'media');
-					$cur->media_dir = dirname($m->media_file);
-					$cur->update('WHERE media_id = '.(integer) $m->media_id);
+					$cur->media_dir = dirname($rs_m->media_file);
+					$cur->update('WHERE media_id = '.(integer) $rs_m->media_id);
 				}
 			}
@@ -61,4 +61,29 @@
 			}
 			
+			if (version_compare($version,'2.1-alpha2-r2383','<'))
+			{
+				$schema = dbSchema::init($core->con);
+				$schema->dropUnique($core->prefix.'category',$core->prefix.'uk_cat_title');
+				
+				# Reindex categories
+				$rs = $core->con->select(
+					'SELECT cat_id, cat_title, blog_id '.
+					'FROM '.$core->prefix.'category '.
+					'ORDER BY blog_id ASC , cat_position ASC '
+				);
+				$cat_blog = $rs->blog_id;
+				$i = 2;
+				while ($rs->fetch()) {
+					if ($cat_blog != $rs->blog_id) {
+						$i = 2;
+					}
+					$core->con->execute(
+						'UPDATE '.$core->prefix.'category SET '
+						.'cat_lft = '.($i++).', cat_rgt = '.($i++).' '.
+						'WHERE cat_id = '.(integer) $rs->cat_id
+					);
+					$cat_blog = $rs->blog_id;
+				}
+			}
 			
 			if (version_compare($version,'2.1.6','<='))
@@ -106,13 +131,13 @@
 					'WHERE (setting_id = \'widgets_nav\' OR setting_id = \'widgets_extra\') '.
 					'AND setting_ns = \'widgets\';';
-				$settings = $core->con->select($sqlstr);
-				foreach ($settings as $s) {
-					$widgetsettings = base64_decode($s->setting_value);
+				$rs = $core->con->select($sqlstr);
+				while ($rs->fetch()) {
+					$widgetsettings = base64_decode($rs->setting_value);
 					$widgetsettings = str_replace ('s:11:"tplMetadata"','s:7:"tplTags"',$widgetsettings);
 					$cur = $core->con->openCursor($core->prefix.'setting');
 					$cur->setting_value = base64_encode($widgetsettings);
-					$sqlstr = 'WHERE setting_id = \''.$s->setting_id.'\' AND setting_ns = \'widgets\' '.
+					$sqlstr = 'WHERE setting_id = \''.$rs->setting_id.'\' AND setting_ns = \'widgets\' '.
 					'AND blog_id ' .
-					($s->blog_id == NULL ? 'is NULL' : '= \''.$core->con->escape($s->blog_id).'\'');
+					($rs->blog_id == NULL ? 'is NULL' : '= \''.$core->con->escape($rs->blog_id).'\'');
 					$cur->update($sqlstr);
 				}
@@ -129,4 +154,7 @@
 				$init_fav['posts'] = array('posts','Entries','posts.php',
 					'images/menu/entries.png','images/menu/entries-b.png',
+					'usage,contentadmin',null,null);
+				$init_fav['comments'] = array('comments','Comments','comments.php',
+					'images/menu/comments.png','images/menu/comments-b.png',
 					'usage,contentadmin',null,null);
 				$init_fav['prefs'] = array('prefs','My preferences','preferences.php',
