Index: /extensions/AdditionalPages/additional_page.php
===================================================================
--- /extensions/AdditionalPages/additional_page.php	(revision 9349)
+++ /extensions/AdditionalPages/additional_page.php	(revision 9350)
@@ -29,9 +29,6 @@
 $identifier = $page['ap_homepage'] ? $conf['AP']['homepage'] : $tokens[1];
 
-if (function_exists('get_extended_desc'))
-  add_event_handler('AP_render_content', 'get_extended_desc');
-
 // Retrieve page data
-$query = 'SELECT id, title , content, users, groups, level, permalink, standalone
+$query = 'SELECT id, title, lang, content, users, groups, level, permalink, standalone
 FROM ' . ADD_PAGES_TABLE . '
 ';
@@ -58,9 +55,16 @@
 if (!is_admin() or (!is_admin() xor $page['ap_homepage']))
 {
+  // authorized language
+  if (!empty($row['lang']) and $row['lang'] != $user['language'])
+  {
+    if ($page['ap_homepage'] and check_random_index_redirect()) return;
+    page_forbidden(l10n('You are not authorized to access the requested page'), make_index_url());
+  }
+
   // authorized level
   if ($user['level'] < $row['level'])
   {
     if ($page['ap_homepage'] and check_random_index_redirect()) return;
-    page_forbidden(l10n('You are not authorized to access the requested page'));
+    page_forbidden(l10n('You are not authorized to access the requested page'), make_index_url());
   }
 
@@ -72,5 +76,5 @@
     {
       if ($page['ap_homepage'] and check_random_index_redirect()) return;
-      page_forbidden(l10n('You are not authorized to access the requested page'));
+      page_forbidden(l10n('You are not authorized to access the requested page'), make_index_url());
     }
   }
@@ -88,5 +92,5 @@
     {
       if ($page['ap_homepage'] and check_random_index_redirect()) return;
-      page_forbidden(l10n('You are not authorized to access the requested page'));
+      page_forbidden(l10n('You are not authorized to access the requested page'), make_index_url());
     }
   }
@@ -106,5 +110,5 @@
   'id' => $row['id'],
   'permalink' => @$row['permalink'],
-  'title' => trigger_event('AP_render_content', $row['title']),
+  'title' => trigger_event('AP_render_title', $row['title']),
   'content' => trigger_event('AP_render_content', $row['content']),
 );
Index: /extensions/AdditionalPages/admin/add_page.inc.php
===================================================================
--- /extensions/AdditionalPages/admin/add_page.inc.php	(revision 9349)
+++ /extensions/AdditionalPages/admin/add_page.inc.php	(revision 9350)
@@ -13,4 +13,5 @@
     'title'      => '',
     'permalink'  => '',
+    'lang'       => 'ALL',
     'homepage'   => false,
     'standalone' => false,
@@ -51,5 +52,5 @@
   }
 
-  $language = $_POST['lang'] != 'ALL' ? '"'.$_POST['lang'].'"' : 'NULL';
+  $language = (empty($_POST['lang']) or $_POST['lang'] == 'ALL') ? 'NULL' : '"'.$_POST['lang'].'"';
   $group_access = !empty($_POST['groups']) ? '"'.implode(',', $_POST['groups']).'"' : 'NULL';
   $standalone = isset($_POST['standalone']) ? '"true"' : '"false"';
@@ -114,5 +115,5 @@
     mkgetdir($conf['local_data_dir'].'/additional_pages_backup', MKGETDIR_PROTECT_HTACCESS&~MKGETDIR_DIE_ON_ERROR);
     $sav_file = @fopen($conf['local_data_dir'].'/additional_pages_backup/' . $edited_page['id'] . '.txt', "w");
-    @fwrite($sav_file, "Title: ".$_POST['title']."\nPermalink: ".$_POST['permalink']."\nLanguage: ".$_POST['lang']."\n\n" . $_POST['ap_content']);
+    @fwrite($sav_file, "Title: ".stripslashes($_POST['title'])."\nPermalink: ".stripslashes($_POST['permalink'])."\n\n".stripslashes($_POST['ap_content']));
     @fclose($sav_file);
 
@@ -127,6 +128,6 @@
   $edited_page['title'] = stripslashes($_POST['title']);
   $edited_page['permalink'] = stripslashes($_POST['permalink']);
-  $edited_page['lang'] = $_POST['lang'];
   $edited_page['content'] = stripslashes($_POST['ap_content']);
+  $edited_page['lang'] = !empty($_POST['lang']) ? $_POST['lang'] : 'ALL';
   $edited_page['groups'] = !empty($_POST['groups']) ? $_POST['groups'] : array();
   $edited_page['users'] = !empty($_POST['users']) ? $_POST['users'] :  array();
@@ -137,17 +138,18 @@
 
 // Language options
-$options['ALL'] = l10n('ap_all_lang');
-$selected = 'ALL';
-foreach (get_languages() as $language_code => $language_name)
-{
-  $options[$language_code] = $language_name;
-  if (isset($edited_page['lang']) and $edited_page['lang'] == $language_code)
-  {
-    $selected = $language_code;
-  }
-}
-$template->assign('lang', array(
-  'OPTIONS' => $options,
-  'SELECTED' => $selected));
+if ($conf['AP']['language_perm'])
+{
+  $languages = get_languages();
+  $options = array('ALL' => l10n('ap_all_lang'));
+  foreach ($languages as $language_code => $language_name)
+  {
+    $options[$language_code] = $language_name;
+  }
+  $template->assign(array(
+    'lang' => $options,
+    'selected_lang' => $edited_page['lang'],
+    )
+  );
+}
 
 // Groups options
Index: /extensions/AdditionalPages/admin/config.inc.php
===================================================================
--- /extensions/AdditionalPages/admin/config.inc.php	(revision 9349)
+++ /extensions/AdditionalPages/admin/config.inc.php	(revision 9350)
@@ -25,6 +25,10 @@
     pwg_query('UPDATE '.ADD_PAGES_TABLE.' SET groups = NULL;');
   }
+  if ($conf['AP']['language_perm'] and !isset($_POST['language_perm']))
+  {
+    pwg_query('UPDATE '.ADD_PAGES_TABLE.' SET lang = NULL;');
+  }
 
-  $params = array('show_home', 'group_perm', 'user_perm', 'level_perm');
+  $params = array('show_home', 'group_perm', 'user_perm', 'level_perm', 'language_perm');
 
   foreach ($params as $param)
Index: /extensions/AdditionalPages/admin/edit_page.inc.php
===================================================================
--- /extensions/AdditionalPages/admin/edit_page.inc.php	(revision 9349)
+++ /extensions/AdditionalPages/admin/edit_page.inc.php	(revision 9350)
@@ -34,5 +34,5 @@
 $edited_page['groups'] = !empty($edited_page['groups']) ? explode(',', $edited_page['groups']) : array();
 $edited_page['homepage'] = $conf['AP']['homepage'] == $edited_page['id'];
-$edited_page['standalone'] = ($edited_page['standalone'] == 'true');
+$edited_page['standalone'] = $edited_page['standalone'] == 'true';
 
 $template->assign('delete', true);
Index: /extensions/AdditionalPages/admin/manage.inc.php
===================================================================
--- /extensions/AdditionalPages/admin/manage.inc.php	(revision 9349)
+++ /extensions/AdditionalPages/admin/manage.inc.php	(revision 9350)
@@ -29,4 +29,9 @@
 }
 
+if (defined('EXTENDED_DESC_PATH'))
+{
+  add_event_handler('AP_render_title', 'get_user_language_desc');
+}
+
 $languages = get_languages();
 
@@ -43,4 +48,5 @@
   $row['U_DELETE'] = PHPWG_ROOT_PATH.'admin.php?page=plugin&amp;section='.AP_DIR.'%2Fadmin%2Fadmin.php&amp;tab=edit_page&amp;edit='.$row['id'].'&amp;delete=';
 
+  $row['title'] = trigger_event('AP_render_title', $row['title']);
   $row['language'] = @$languages[$row['lang']];
 
Index: /extensions/AdditionalPages/admin/template/add_page.tpl
===================================================================
--- /extensions/AdditionalPages/admin/template/add_page.tpl	(revision 9349)
+++ /extensions/AdditionalPages/admin/template/add_page.tpl	(revision 9350)
@@ -43,10 +43,12 @@
     </li>
 
+    {if isset($lang)}
     <li>
       <span class="property">
         <label for="lang">{'ap_page_lang'|@translate}</label>
       </span>
-      {html_options name=lang id=lang options=$lang.OPTIONS selected=$lang.SELECTED}
+      {html_options name=lang id=lang options=$lang selected=$selected_lang}
     </li>
+    {/if}
 
     <li style="margin-top:15px;">
Index: /extensions/AdditionalPages/admin/template/config.tpl
===================================================================
--- /extensions/AdditionalPages/admin/template/config.tpl	(revision 9349)
+++ /extensions/AdditionalPages/admin/template/config.tpl	(revision 9350)
@@ -56,4 +56,11 @@
       </label>
     </li>
+
+    <li>
+      <label>
+        <span class="property">{'ap_language_perm'|@translate}</span>
+        <input type="checkbox" name="language_perm" id="language_perm" value="on" {if $ap_conf.language_perm}checked="checked"{/if}/>
+      </label>
+    </li>
   </ul>
 </fieldset>
Index: /extensions/AdditionalPages/admin/upgrade.inc.php
===================================================================
--- /extensions/AdditionalPages/admin/upgrade.inc.php	(revision 9349)
+++ /extensions/AdditionalPages/admin/upgrade.inc.php	(revision 9350)
@@ -133,3 +133,17 @@
 }
 
+if (!isset($conf['AP']['language_perm']))
+{
+  $query = '
+SELECT id
+FROM '.$prefixeTable.'additionalpages
+WHERE lang IS NOT NULL
+;';
+  $ids = array_from_query($query, 'id');
+
+  $conf['AP']['language_perm'] = !empty($ids);
+
+  conf_update_param('additional_pages', pwg_db_real_escape_string(serialize($conf['AP'])));  
+}
+
 ?>
Index: /extensions/AdditionalPages/language/ar_SA/plugin.lang.php
===================================================================
--- /extensions/AdditionalPages/language/ar_SA/plugin.lang.php	(revision 9349)
+++ /extensions/AdditionalPages/language/ar_SA/plugin.lang.php	(revision 9350)
@@ -46,4 +46,5 @@
 /*TODO*/$lang['ap_permalink_already_used'] = 'Permalink %s is already used by page %s';
 /*TODO*/$lang['ap_level_perm'] = 'by privacy level';
+/*TODO*/$lang['ap_language_perm'] = 'by language';
 
 ?>
Index: /extensions/AdditionalPages/language/cs_CZ/plugin.lang.php
===================================================================
--- /extensions/AdditionalPages/language/cs_CZ/plugin.lang.php	(revision 9349)
+++ /extensions/AdditionalPages/language/cs_CZ/plugin.lang.php	(revision 9350)
@@ -46,4 +46,5 @@
 /*TODO*/$lang['ap_permalink_already_used'] = 'Permalink %s is already used by page %s';
 /*TODO*/$lang['ap_level_perm'] = 'by privacy level';
+/*TODO*/$lang['ap_language_perm'] = 'by language';
 
 ?>
Index: /extensions/AdditionalPages/language/de_DE/plugin.lang.php
===================================================================
--- /extensions/AdditionalPages/language/de_DE/plugin.lang.php	(revision 9349)
+++ /extensions/AdditionalPages/language/de_DE/plugin.lang.php	(revision 9350)
@@ -46,4 +46,5 @@
 /*TODO*/$lang['ap_permalink_already_used'] = 'Permalink %s is already used by page %s';
 /*TODO*/$lang['ap_level_perm'] = 'by privacy level';
+/*TODO*/$lang['ap_language_perm'] = 'by language';
 
 ?>
Index: /extensions/AdditionalPages/language/en_UK/plugin.lang.php
===================================================================
--- /extensions/AdditionalPages/language/en_UK/plugin.lang.php	(revision 9349)
+++ /extensions/AdditionalPages/language/en_UK/plugin.lang.php	(revision 9350)
@@ -46,4 +46,5 @@
 $lang['ap_permalink_already_used'] = 'Permalink %s is already used by page %s';
 $lang['ap_level_perm'] = 'by privacy level';
+$lang['ap_language_perm'] = 'by language';
 
 ?>
Index: /extensions/AdditionalPages/language/es_ES/plugin.lang.php
===================================================================
--- /extensions/AdditionalPages/language/es_ES/plugin.lang.php	(revision 9349)
+++ /extensions/AdditionalPages/language/es_ES/plugin.lang.php	(revision 9350)
@@ -46,4 +46,5 @@
 $lang['ap_permalink_already_used'] = 'El enlace permanente% s ya está siendo utilizado por la página% s';
 $lang['ap_level_perm'] = 'por nivel de confidencialidad';
+/*TODO*/$lang['ap_language_perm'] = 'by language';
 
 ?>
Index: /extensions/AdditionalPages/language/fr_FR/plugin.lang.php
===================================================================
--- /extensions/AdditionalPages/language/fr_FR/plugin.lang.php	(revision 9349)
+++ /extensions/AdditionalPages/language/fr_FR/plugin.lang.php	(revision 9350)
@@ -46,4 +46,5 @@
 $lang['ap_permalink_already_used'] = 'Le lien permanent %s est déja utilisé par la page %s';
 $lang['ap_level_perm'] = 'par niveau de confidentialité';
+$lang['ap_language_perm'] = 'par langue';
 
 ?>
Index: /extensions/AdditionalPages/language/hu_HU/plugin.lang.php
===================================================================
--- /extensions/AdditionalPages/language/hu_HU/plugin.lang.php	(revision 9349)
+++ /extensions/AdditionalPages/language/hu_HU/plugin.lang.php	(revision 9350)
@@ -46,4 +46,5 @@
 /*TODO*/$lang['ap_permalink_already_used'] = 'Permalink %s is already used by page %s';
 /*TODO*/$lang['ap_level_perm'] = 'by privacy level';
+/*TODO*/$lang['ap_language_perm'] = 'by language';
 
 ?>
Index: /extensions/AdditionalPages/language/it_IT/plugin.lang.php
===================================================================
--- /extensions/AdditionalPages/language/it_IT/plugin.lang.php	(revision 9349)
+++ /extensions/AdditionalPages/language/it_IT/plugin.lang.php	(revision 9350)
@@ -46,5 +46,5 @@
 $lang['ap_permalink_already_used'] = 'Permalink %s è già utilizzato da pagina %s';
 /*TODO*/$lang['ap_level_perm'] = 'by privacy level';
-
+/*TODO*/$lang['ap_language_perm'] = 'by language';
 
 ?>
Index: /extensions/AdditionalPages/language/lv_LV/plugin.lang.php
===================================================================
--- /extensions/AdditionalPages/language/lv_LV/plugin.lang.php	(revision 9349)
+++ /extensions/AdditionalPages/language/lv_LV/plugin.lang.php	(revision 9350)
@@ -46,4 +46,5 @@
 $lang['ap_permalink_already_used'] = 'Pastāvīgo saiti %s jau lieto %s lapa';
 $lang['ap_level_perm'] = 'ar konfidencialitātes līmeni';
+/*TODO*/$lang['ap_language_perm'] = 'by language';
 
 ?>
Index: /extensions/AdditionalPages/language/nl_NL/plugin.lang.php
===================================================================
--- /extensions/AdditionalPages/language/nl_NL/plugin.lang.php	(revision 9349)
+++ /extensions/AdditionalPages/language/nl_NL/plugin.lang.php	(revision 9350)
@@ -46,4 +46,5 @@
 $lang['ap_permalink_already_used'] = 'De permalink %s wordt al gebruikt door pagina %s';
 $lang['ap_level_perm'] = 'op privacy nivo';
+/*TODO*/$lang['ap_language_perm'] = 'by language';
 
 ?>
Index: /extensions/AdditionalPages/language/no_NO/plugin.lang.php
===================================================================
--- /extensions/AdditionalPages/language/no_NO/plugin.lang.php	(revision 9349)
+++ /extensions/AdditionalPages/language/no_NO/plugin.lang.php	(revision 9350)
@@ -46,4 +46,5 @@
 $lang['ap_permalink_already_used'] = 'Permalink %s er allerede I bruk av side %s';
 $lang['ap_level_perm'] = 'av privat nivå';
+/*TODO*/$lang['ap_language_perm'] = 'by language';
 
 ?>
Index: /extensions/AdditionalPages/language/pl_PL/plugin.lang.php
===================================================================
--- /extensions/AdditionalPages/language/pl_PL/plugin.lang.php	(revision 9349)
+++ /extensions/AdditionalPages/language/pl_PL/plugin.lang.php	(revision 9350)
@@ -46,4 +46,5 @@
 $lang['ap_permalink_already_used'] = 'Link permanentny %s jest już używane przez stronę %s';
 $lang['ap_level_perm'] = 'po poziomie prywatności';
+/*TODO*/$lang['ap_language_perm'] = 'by language';
 
 ?>
Index: /extensions/AdditionalPages/language/ru_RU/plugin.lang.php
===================================================================
--- /extensions/AdditionalPages/language/ru_RU/plugin.lang.php	(revision 9349)
+++ /extensions/AdditionalPages/language/ru_RU/plugin.lang.php	(revision 9350)
@@ -46,4 +46,5 @@
 $lang['ap_permalink_already_used'] = 'Постоянная ссылка %s уже используется страницей %s';
 $lang['ap_level_perm'] = 'по уровню доступа';
+/*TODO*/$lang['ap_language_perm'] = 'by language';
 
 ?>
Index: /extensions/AdditionalPages/language/sk_SK/plugin.lang.php
===================================================================
--- /extensions/AdditionalPages/language/sk_SK/plugin.lang.php	(revision 9349)
+++ /extensions/AdditionalPages/language/sk_SK/plugin.lang.php	(revision 9350)
@@ -46,4 +46,5 @@
 $lang['ap_permalink_already_used'] = 'Trvalý link %s je stále používaný stránkou %s'; 
 $lang['ap_level_perm'] = 'pri súkromnej úrovni';
+/*TODO*/$lang['ap_language_perm'] = 'by language';
 
 ?>
Index: /extensions/AdditionalPages/language/sv_SE/plugin.lang.php
===================================================================
--- /extensions/AdditionalPages/language/sv_SE/plugin.lang.php	(revision 9349)
+++ /extensions/AdditionalPages/language/sv_SE/plugin.lang.php	(revision 9350)
@@ -46,4 +46,5 @@
 $lang['ap_permalink_already_used'] = 'Permalänk %s används redan av sidan %s';
 $lang['ap_level_perm'] = 'enligt säkerhets nivå';
+/*TODO*/$lang['ap_language_perm'] = 'by language';
 
 ?>
Index: /extensions/AdditionalPages/language/tr_TR/plugin.lang.php
===================================================================
--- /extensions/AdditionalPages/language/tr_TR/plugin.lang.php	(revision 9349)
+++ /extensions/AdditionalPages/language/tr_TR/plugin.lang.php	(revision 9350)
@@ -46,4 +46,5 @@
 $lang['ap_permalink_already_used'] = 'Kalıcı bağlantı %s zaten sayfa %s tarafından kullanılıyor';
 $lang['ap_level_perm'] = 'gizlilik seviyesine göre';
+/*TODO*/$lang['ap_language_perm'] = 'by language';
 
 ?>
Index: /extensions/AdditionalPages/main.inc.php
===================================================================
--- /extensions/AdditionalPages/main.inc.php	(revision 9349)
+++ /extensions/AdditionalPages/main.inc.php	(revision 9350)
@@ -20,5 +20,5 @@
 
 // Need upgrade?
-if (!isset($conf['AP']['level_perm']))
+if (!isset($conf['AP']['language_perm']))
   include(AP_PATH.'admin/upgrade.inc.php');
 
@@ -43,4 +43,10 @@
 {
   global $tokens, $conf, $page;
+
+  if (defined('EXTENDED_DESC_PATH'))
+  {
+    add_event_handler('AP_render_content', 'get_extended_desc');
+    add_event_handler('AP_render_title', 'get_user_language_desc');
+  }
 
   $page['ap_homepage'] = (count($tokens) == 1 and empty($tokens[0]));
@@ -85,5 +91,5 @@
     {
       $url = make_index_url().'/page/'.(isset($row['permalink']) ? $row['permalink'] : $row['id']);
-      array_push($data, array('URL' => $url, 'LABEL' => $row['title']));
+      array_push($data, array('URL' => $url, 'LABEL' => trigger_event('AP_render_title', $row['title'])));
     }
 
Index: /extensions/AdditionalPages/maintain.inc.php
===================================================================
--- /extensions/AdditionalPages/maintain.inc.php	(revision 9349)
+++ /extensions/AdditionalPages/maintain.inc.php	(revision 9350)
@@ -39,4 +39,5 @@
       'group_perm' => false,
       'user_perm' => false,
+      'language_perm' => false,
       'homepage' => null,
     );
