Index: /extensions/AdditionalPages/admin/add_page.inc.php
===================================================================
--- /extensions/AdditionalPages/admin/add_page.inc.php	(revision 9274)
+++ /extensions/AdditionalPages/admin/add_page.inc.php	(revision 9275)
@@ -20,12 +20,7 @@
   if (!empty($_POST['permalink']))
   {
-    $permalink = $_POST['permalink'];
-    $sanitized_permalink = preg_replace( '#[^a-zA-Z0-9_/-]#', '' ,$permalink);
-    $sanitized_permalink = trim($sanitized_permalink, '/');
-    $sanitized_permalink = str_replace('//', '/', $sanitized_permalink);
-    if ( $sanitized_permalink != $permalink or preg_match( '#^(\d)+(-.*)?$#', $permalink) )
-    {
-      array_push($page['errors'], l10n('The permalink name must be composed of a-z, A-Z, 0-9, "-", "_" or "/". It must not be numeric or start with number followed by "-"'));
-    }
+    $permalink = trim($_POST['permalink'], ' /');
+    $permalink = str_replace(array(' ', '/'), '_',$permalink);
+
     $query ='
 SELECT id FROM '.ADD_PAGES_TABLE.'
@@ -47,6 +42,11 @@
   $language = $_POST['lang'] != 'ALL' ? '"'.$_POST['lang'].'"' : 'NULL';
   $group_access = !empty($_POST['groups']) ? '"'.implode(',', $_POST['groups']).'"' : 'NULL';
-  $user_access = !empty($_POST['users']) ? '"'.implode(',', $_POST['users']).'"' : 'NULL';
   $standalone = isset($_POST['standalone']) ? '"true"' : '"false"';
+
+  $user_access = 'NULL';
+  if ($conf['additional_pages']['user_perm'])
+  {
+    $user_access = !empty($_POST['users']) ? '"'.implode(',', $_POST['users']).'"' : '"admin"';
+  }
 
   if (empty($page['errors']))
@@ -106,4 +106,5 @@
   $edited_page['title'] = stripslashes($_POST['title']);
   $edited_page['permalink'] = $_POST['permalink'];
+  $edited_page['lang'] = $_POST['lang'];
   $edited_page['content'] = stripslashes($_POST['ap_content']);
   $edited_page['groups'] = !empty($_POST['groups']) ? trim($group_access, '"') : '';
@@ -139,13 +140,16 @@
 if ($conf['additional_pages']['user_perm'])
 {
-  if (isset($_GET['edit']))
-	  $selected_users = isset($edited_page['users']) ? explode(',', $edited_page['users']) : array();
-  else
-    $selected_users = array('guest', 'generic', 'normal');
+  $selected_users = array('guest', 'generic', 'normal');
+  if (isset($_GET['edit']) and isset($edited_page['users']))
+  {
+    $selected_users = explode(',', $edited_page['users']);
+  }
 
 	$template->assign('user_perm', array(
-    'GUEST' => (in_array('guest', $selected_users) ? 'checked="checked"' : ''),
-		'GENERIC' => (in_array('generic', $selected_users) ? 'checked="checked"' : ''),
-		'NORMAL' => (in_array('normal', $selected_users) ? 'checked="checked"' : '')));
+      'GUEST' => in_array('guest', $selected_users) ? 'checked="checked"' : '',
+      'GENERIC' => in_array('generic', $selected_users) ? 'checked="checked"' : '',
+      'NORMAL' => in_array('normal', $selected_users) ? 'checked="checked"' : ''
+    )
+  );
 }
 
Index: /extensions/AdditionalPages/admin/config.inc.php
===================================================================
--- /extensions/AdditionalPages/admin/config.inc.php	(revision 9274)
+++ /extensions/AdditionalPages/admin/config.inc.php	(revision 9275)
@@ -8,4 +8,17 @@
 if (isset($_POST['submit']))
 {
+  if (!$conf['additional_pages']['user_perm'] and isset($_POST['user_perm']))
+  {
+    pwg_query('UPDATE '.ADD_PAGES_TABLE.' SET users = "guest,generic,normal" WHERE users IS NULL;');
+  }
+  if ($conf['additional_pages']['user_perm'] and !isset($_POST['user_perm']))
+  {
+    pwg_query('UPDATE '.ADD_PAGES_TABLE.' SET users = NULL;');
+  }
+  if ($conf['additional_pages']['group_perm'] and !isset($_POST['group_perm']))
+  {
+    pwg_query('UPDATE '.ADD_PAGES_TABLE.' SET groups = NULL;');
+  }
+
   $params = array('show_home', 'group_perm', 'user_perm');
 
Index: tensions/AdditionalPages/admin/parse_bbcode.php
===================================================================
--- /extensions/AdditionalPages/admin/parse_bbcode.php	(revision 9274)
+++ 	(revision )
@@ -1,165 +1,0 @@
-<?php
-
-if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
-
-global $lang, $conf;
-
-include(get_language_filepath('plugin.lang.php', AP_PATH));
-
-function ap_CheckTags($str){
-	//array of known tags
-	$known = array('p','b','i','u','s','center','right','ol','ul','li','quote', 'img','url','email','color', 'size');
-	//storage stack
-	$tags = array();
-	
-	for ($pos = 0; $pos<strlen($str); $pos++)
-	{
-		if ($str{$pos} == '[')
-			{
-			$end_pos = strpos($str, ']', $pos);
-			$tag = substr($str, ++$pos, $end_pos-$pos);
-			//deals with tags which contains arguments (ie quote)
-			if ( ($equal_pos = strpos($tag, '=', 0)) !== FALSE)
-				$tag = substr($tag, 0, $equal_pos);
-			//check whether we have a defined tag or not.
-			if (in_array(strtolower($tag),$known) || in_array(strtolower(substr($tag,1)),$known))
-				{
-			//closing tag
-			if ($tag{0} == '/')
-				{
-					//cleaned tag
-					$tag = substr($tag, 1);		
-					$before_tag = substr($str, 0, $pos-1);
-					$after_tag = substr($str, $end_pos+1);	
-					//pop stack
-					while (($temp = array_pop($tags)))
-							{
-							if ($temp != $tag)
-								$before_tag.='[/'.$temp.']';
-							else 
-								{
-								$before_tag.='[/'.$tag.']';
-								break;
-								}
-
-							}
-					$end_pos += strlen($before_tag)+strlen($after_tag)-strlen($str);
-					$str = $before_tag.$after_tag;
-				}
-			else 
-				{ // push stack
-				array_push($tags,$tag);
-				}
-			}
-		$pos = $end_pos;	
-		}
-	}
-	// empty stack and closing tags
-	while ($temp = array_pop($tags))
-		{		
-		$str.='[/'.$temp.']';
-		}
-
-	return $str;
-}
-
-function ap_parse_bbcode($comment)
-{
-	$comment = nl2br($comment);
-	$comment = ap_CheckTags($comment);
-			
-	$patterns = array();
-	$replacements = array();
-	
-	//Paragraph
-	$patterns[] = '#\[p\](.*?)\[/p\]#is';
-	$replacements[] = '<p>\\1</p>';
-    // Bold
-	$patterns[] = '#\[b\](.*?)\[/b\]#is';
-	$replacements[] = '<strong>\\1</strong>';
-	//Italic
-	$patterns[] = '#\[i\](.*?)\[/i\]#is';
-	$replacements[] = '<em>\\1</em>';
-	//Underline	
-	$patterns[] = '#\[u\](.*?)\[\/u\]#is';
-	$replacements[] = '<u>\\1</u>';
-	//Strikethrough
-	$patterns[] = '#\[s\](.*?)\[/s\]#is';
-	$replacements[] = '<del>\\1</del>';
-	//Center
-	$patterns[] = '#\[center\](.*?)\[/center\]#is';
-	$replacements[] = '</p><div align="center"><p>\\1</p></div><p>';
-	//Right
-	$patterns[] = '#\[right\](.*?)\[/right\]#is';
-	$replacements[] = '</p><div align="right"><p>\\1</p></div><p>';
-	//Olist
-	$patterns[] = '#\[ol\](.*?)\[/ol\]#is';
-	$replacements[] = '<ol>\\1</ol>';
-	//Ulist
-	$patterns[] = '#\[ul\](.*?)\[/ul\]#is';
-	$replacements[] = '<ul>\\1</ul>';
-	//List
-	$patterns[] = '#\[li\](.*?)\[/li\]#is';
-	$replacements[] = '<li>\\1</li>';
-	// Quotes
-	$patterns[] = "#\[quote\](.*?)\[/quote\]#is";
-	$replacements[] = '</p><blockquote><span style="font-size: 11px; line-height: normal">\\1</span></blockquote><p>';
-	//Quotes with "user"
-	$patterns[] = "#\[quote=&quot;(.*?)&quot;\](.*?)\[/quote\]#is";
-	$replacements[] = '</p><blockquote><span style="font-size: 11px; line-height: normal"><b>\\1 : </b><br/>\\2</span></blockquote><p>';
-	//Quotes with user
-	$patterns[] = "#\[quote=(.*?)\](.*?)\[/quote\]#is";
-	$replacements[] = '</p><blockquote><span style="font-size: 11px; line-height: normal"><b>\\1 : </b><br/>\\2</span></blockquote><p>';
-	//Images
-	$patterns[] = "#\[img\](.*?)\[/img\]#si";
-	$replacements[] = "<img src='\\1' alt='' />";
-	//[url]xxxx://www.zzzz.yyy[/url]
-	$patterns[] = "#\[url\]([\w]+?://[^ \"\n\r\t<]*?)\[/url\]#is"; 
-	$replacements[] = '<a href="\\1" target="_blank">\\1</a>'; 
-	//[url]www.zzzzz.yyy[/url]
-	$patterns[] = "#\[url\]((www|ftp)\.[^ \"\n\r\t<]*?)\[/url\]#is"; 
-	$replacements[] = '<a href="http://\\1" target="_blank">\\1</a>'; 
-	//[url=xxxx://www.zzzzz.yyy]ZzZzZ[/url] /*No I ain't sleeping yet*/
-	$patterns[] = "#\[url=([\w]+?://[^ \"\n\r\t<]*?)\](.*?)\[/url\]#is"; 
-	$replacements[] = '<a href="\\1" target="_blank">\\2</a>'; 
-	// [url=www.zzzzz.yyy]zZzZz[/url] /*But I'm thinking about*/
-	$patterns[] = "#\[url=((www|ftp)\.[^ \"\n\r\t<]*?)\](.*?)\[/url\]#is"; 
-	$replacements[] = '<a href="http://\\1" target="_blank">\\2</a>'; 
-	// [url="www.zzzzz.yyy"]zZzZz[/url]   /* It's nearly 2 am now */
-	$patterns[] = "#\[url=&quot;((www|ftp)\.[^ \n\r\t<]*?)&quot;\](.*?)\[/url\]#is";
-	$replacements[] = '<a href="http://\\1" target="_blank">\\3</a>';
-	//[url="http://www.zzzzz.yyy"]zZzZz[/url] /*I really dislike commenting code*/
-	$patterns[] = "#\[url=&quot;([\w]+?://[^ \n\r\t<]*?)&quot;\](.*?)\[/url\]#is";
-	$replacements[] = '<a href="\\1" target="_blank">\\2</a>';
-	//[email]samvure@gmail.com[/email]
-	$patterns[] = "#\[email\]([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\[/email\]#is";
-	$replacements[] = '<a href="mailto:\\1">\\1</a>';
-	//Size
-	$patterns[] = "#\[size=([1-2]?[0-9])\](.*?)\[/size\]#si";
-	$replacements[] = '<span style="font-size: \\1px; line-height: normal">\\2</span>';
-	//Colours
-	$patterns[] = "#\[color=(\#[0-9A-F]{6}|[a-z]+)\](.*?)\[/color\]#si";
-	$replacements[] = '<span style="color: \\1">\\2</span>';
-	
-	$comment = preg_replace($patterns, $replacements, $comment);
-		
-	return $comment;
-}
-
-// Traitement des pages
-$result= pwg_query('SELECT id, text FROM ' . ADD_PAGES_TABLE);
-while ($row = mysql_fetch_assoc($result)) {
-	$text = ap_parse_bbcode($row['text']);
-	pwg_query('UPDATE ' . ADD_PAGES_TABLE . ' SET text="' . addslashes($text) . '" WHERE id=' . $row['id'] . ' LIMIT 1');
-}
-
-// Mise à jour de la configuration
-$ap_conf = explode ("," , $conf['additional_pages']);
-if (isset($ap_conf[5])) {
-	$ap_conf[5] = '';
-	pwg_query('UPDATE ' . CONFIG_TABLE . ' SET value="' . implode ("," , $ap_conf) . '" WHERE param="additional_pages" LIMIT 1');
-}
-
-redirect(str_replace('&amp;', '&', get_admin_plugin_menu_link(AP_PATH . 'admin/admin.php')), l10n('ap_convert_bbcode_ok'), 3);
-
-?>
Index: /extensions/AdditionalPages/admin/template/add_page.tpl
===================================================================
--- /extensions/AdditionalPages/admin/template/add_page.tpl	(revision 9274)
+++ /extensions/AdditionalPages/admin/template/add_page.tpl	(revision 9275)
@@ -1,2 +1,3 @@
+{known_script id="jquery" src=$ROOT_URL|@cat:"themes/default/js/jquery.packed.js"}
 {html_head}{literal}
 <script type="text/javascript">
Index: /extensions/AdditionalPages/admin/template/config.tpl
===================================================================
--- /extensions/AdditionalPages/admin/template/config.tpl	(revision 9274)
+++ /extensions/AdditionalPages/admin/template/config.tpl	(revision 9275)
@@ -1,2 +1,3 @@
+{known_script id="jquery" src=$ROOT_URL|@cat:"themes/default/js/jquery.packed.js"}
 {html_head}
 <script type="text/javascript">
Index: /extensions/AdditionalPages/admin/upgrade_from_21.php
===================================================================
--- /extensions/AdditionalPages/admin/upgrade_from_21.php	(revision 9274)
+++ /extensions/AdditionalPages/admin/upgrade_from_21.php	(revision 9275)
@@ -4,4 +4,7 @@
 
 global $prefixeTable, $conf;
+
+load_conf_from_db('param = "additional_pages"');
+$old_conf = explode ("," , $conf['additional_pages']);
 
 $query = 'ALTER TABLE ' . $prefixeTable . 'additionalpages
@@ -28,15 +31,15 @@
   $authorized_groups = 'NULL';
 
-  if (strpos($title , '/user_id='))
+  if ($old_conf[7] == 'on' and strpos($title , '/user_id='))
   {
     $array = explode('/user_id=' , $title);
     $title = $array[0];
-    $authorized_users = '"'.$array[1].'"';
+    $authorized_users = !empty($array[1]) ? '"'.$array[1].'"' : '"admin"';
   }
-  if (strpos($title , '/group_id='))
+  if ($old_conf[6] == 'on' and strpos($title , '/group_id='))
   {
     $array = explode('/group_id=' , $title);
     $title = $array[0];
-    $authorized_groups = '"'.$array[1].'"';
+    $authorized_groups = !empty($array[1]) ? '"'.$array[1].'"' : 'NULL';
   }
 
@@ -60,7 +63,4 @@
   pwg_query($query);
 }
-
-load_conf_from_db('param = "additional_pages"');
-$old_conf = explode ("," , $conf['additional_pages']);
 
 if ($old_conf[1] == 'off')
Index: /extensions/AdditionalPages/index_menu.php
===================================================================
--- /extensions/AdditionalPages/index_menu.php	(revision 9274)
+++ /extensions/AdditionalPages/index_menu.php	(revision 9275)
@@ -48,32 +48,27 @@
     while ($row = mysql_fetch_assoc($result))
     {
-      if ($row['pos'] != '0' or is_admin())
+      $authorized_users = array();
+      $authorized_groups = array();
+      if (!empty($row['users']))
       {
-        $authorized_users = array();
-        $authorized_groups = array();
-        if (!empty($row['users']))
+        $authorized_users = explode(',', $row['users']);
+      }
+      if (!empty($row['groups']))
+      {
+        $auth = explode(',', $row['groups']);
+        $authorized_groups = array_intersect($groups, $auth);
+      }
+      if (is_admin() or (
+        (!$conf['additional_pages']['group_perm'] or empty($row['groups']) or !empty($authorized_groups)) and
+        (!$conf['additional_pages']['user_perm'] or empty($row['users']) or in_array($user['status'], $authorized_users))))
+      {
+        $url = make_index_url();
+        if ($row['id'] != $conf['additional_pages']['homepage'])
         {
-          $authorized_users = explode(',', $row['users']);
+          $url .= '/page/'.(isset($row['permalink']) ? $row['permalink'] : $row['id']);
         }
-        if (!empty($row['groups']))
-        {
-          $auth = explode(',', $row['groups']);
-          $authorized_groups = array_intersect($groups, $auth);
-        }
-        if (is_admin() or (
-          (!$conf['additional_pages']['group_perm'] or empty($row['groups']) or !empty($authorized_groups)) and
-          (!$conf['additional_pages']['user_perm'] or empty($row['users']) or in_array($user['status'], $authorized_users))))
-        {
-          $url = make_index_url();
-          if ($row['id'] != $conf['additional_pages']['homepage'])
-          {
-            $url .= '/page/'.(isset($row['permalink']) ? $row['permalink'] : $row['id']);
-          }
-          array_push($data, array(
-            'URL' => $url,
-            'LABEL' => $row['title']));
-        }
-        unset($authorized_groups);
-        unset($authorized_users);
+        array_push($data, array(
+          'URL' => $url,
+          'LABEL' => $row['title']));
       }
     }
