Index: pmwiki.php
===================================================================
--- pmwiki.php	(revision 2348)
+++ pmwiki.php	(working copy)
@@ -726,7 +726,7 @@
   if (!@$PCache[$pagename]['=pagetextvars']) {
     $pc = &$PCache[$pagename];
     $pc['=pagetextvars'] = 1;
-    $page = RetrieveAuthPage($pagename, 'read', false, READPAGE_CURRENT);
+    $page = RetrieveAuthPage($pagename, 'read', false, READPAGE_CURRENT, true);
     if ($page) {
       foreach((array)$PageTextVarPatterns as $pat) 
         if (preg_match_all($pat, @$page['text'], $match, PREG_SET_ORDER))
@@ -1029,11 +1029,14 @@
   return $out;
 }
 
-function RetrieveAuthPage($pagename, $level, $authprompt=true, $since=0) {
-  global $AuthFunction;
+function RetrieveAuthPage($pagename, $level, $authprompt=true, $since=0, $preview=false) {
+  global $AuthFunction, $EnablePreviewParse;
   SDV($AuthFunction,'PmWikiAuth');
-  if (!function_exists($AuthFunction)) return ReadPage($pagename, $since);
-  return $AuthFunction($pagename, $level, $authprompt, $since);
+  if (!function_exists($AuthFunction)) $page = ReadPage($pagename, $since);
+  else $page = $AuthFunction($pagename, $level, $authprompt, $since);
+  if($preview && IsEnabled($EnablePreviewParse, 1) && $pagename == @$_POST['n'] )
+    $page['text']=@$_POST['text'];
+  return $page;
 }
 
 function Abort($msg, $info='') {
@@ -1200,7 +1203,7 @@
 ##  in the pages given by $list, or in $pagename if $list is not specified.
 ##  The selected page is placed in the global $RASPageName variable.
 ##  The caller is responsible for calling Qualify() as needed.
-function RetrieveAuthSection($pagename, $pagesection, $list=NULL, $auth='read') {
+function RetrieveAuthSection($pagename, $pagesection, $list=NULL, $auth='read', $preview=false) {
   global $RASPageName;
   if ($pagesection{0} != '#')
     $list = array(MakePageName($pagename, $pagesection));
@@ -1208,7 +1211,7 @@
   foreach((array)$list as $t) {
     $t = FmtPageName($t, $pagename);
     if (!PageExists($t)) continue;
-    $tpage = RetrieveAuthPage($t, $auth, false, READPAGE_CURRENT);
+    $tpage = RetrieveAuthPage($t, $auth, false, READPAGE_CURRENT, $preview);
     if (!$tpage) continue;
     $text = TextSection($tpage['text'], $pagesection);
     if ($text !== false) { $RASPageName = $t; return $text; }
@@ -1232,7 +1235,7 @@
         if (isset($itext)) continue;
         $iname = MakePageName($pagename, $v);
         if (!$args['self'] && $iname == $pagename) continue;
-        $ipage = RetrieveAuthPage($iname, 'read', false, READPAGE_CURRENT);
+        $ipage = RetrieveAuthPage($iname, 'read', false, READPAGE_CURRENT, true);
         $itext = @$ipage['text'];
       }
       $itext = TextSection($itext, $v, array('anchors' => 1));
Index: scripts/pagelist.php
===================================================================
--- scripts/pagelist.php	(revision 2348)
+++ scripts/pagelist.php	(working copy)
@@ -563,7 +563,7 @@
   StopWatch("FPLTemplate begin");
   $template = @$opt['template'];
   if (!$template) $template = @$opt['fmt'];
-  $ttext = RetrieveAuthSection($pagename, $template, $FPLTemplatePageFmt);
+  $ttext = RetrieveAuthSection($pagename, $template, $FPLTemplatePageFmt, 'read', true);
   $ttext = PVSE(Qualify($RASPageName, $ttext));
 
   ##  save any escapes
Index: scripts/trails.php
===================================================================
--- scripts/trails.php	(revision 2348)
+++ scripts/trails.php	(working copy)
@@ -56,7 +56,7 @@
     $LinkWikiWords;
   if (preg_match('/^\\[\\[(.+?)(->|\\|)(.+?)\\]\\]$/', $trailname, $m)) 
     $trailname = ($m[2] == '|') ? $m[1] : $m[3];
-  $trailtext = RetrieveAuthSection($pagename, $trailname);
+  $trailtext = RetrieveAuthSection($pagename, $trailname, NULL, 'read', true);
   $trailname = $RASPageName;
   $trailtext = Qualify($trailname, $trailtext);
   $t = array();