[pmwiki-devel] New adddeleteline2 redirect feature

Martin Fick mogulguy at yahoo.com
Mon Jan 1 01:10:31 CST 2007


Nils,

I have created a simple patch (it looks longer that it
really is) to the adddeleteline script which enables
automatic returns to submitting forms after adding
text to a page.  You can test a sample of this here:

http://www.theficks.name/test/adddeleteline/pmwiki.php?n=Redirect.Form

Along with some clever pagelists, a very cool use of
this feature is the ability to add text to every page
on a trail consecutively.  This can be usefull if you
want to create a trail and then add the trail markup
to each page on the trail without editing each page
individually!  You still have to step through each one
manually though, maybe something that some clever
javascript could take care of?  Although, it might be
a little unsafe to have something automatically update
all the pages at once?  You can see a sample of this
idea here:

http://www.theficks.name/test/adddeleteline/pmwiki.php?n=Redirect.TrailForm


I put the patch below inline, I can send you the
complete script offline if you want it.

I hope you might consider adding this feature to your
recipe.

Thanks, 

-Martin


*** adddeleteline2.php  Mon Jan  1 00:02:50 2007
--- adddeleteline2.redirect.php Sun Dec 31 19:59:55
2006
***************
*** 1,6 ****
  <?php

! $AdlVersion = '2.0.2, 3.10.2006';

  /*
     Adds markup to add lines using a form and delete
lines from a wiki page.
--- 1,6 ----
  <?php

! $AdlVersion = '2.0.2+redirect, 12.31.2006';

  /*
     Adds markup to add lines using a form and delete
lines from a wiki page.
***************
*** 28,36 ****
     CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE
     SOFTWARE.

!
     Code review (using htmlentities instead of
urlencode) by Martin Fick (2006)
!
   */


--- 28,47 ----
     CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE
     SOFTWARE.

!
     Code review (using htmlentities instead of
urlencode) by Martin Fick (2006)
!
!
!    New Features in this version:
!
!    This version adds a redirect feature which allows
a page to return to
!    the original form page immedeately after adding
text to a page.  To use
!    this feature, simply include a (potentially
hidden) parameter in your
!    form named: 'redirect_to' and set its value to
the page you want to
!    return to after adding text (probably
{$FullName}.)
!
!    After being redirected, the page variable
{$?redirect_from} will be set
!    to the page to which you have just added text to.
   */


***************
*** 62,67 ****
--- 73,83 ----
  Markup('adlform','directives','/\(:adl form
(.*?):\)/e',"Keep(AdlFormMarkup(\$pagename,PSS('$1')))");
  Markup('adlform2','<adlform','/\(:adl form (.*?)
target=(.*?):\)/e',"Keep(AdlFormMarkup(PSS('$2'),PSS('$
1')))");

+
Markup('adlreturn','<adlform','/\(:adl\s*return\s*:\)/e',
"Keep('          <input type=\'hidden\' value=
\'\$pagename\' name=\'redirect_to\'/>\n'
+ )");
+
+
Markup('redirect_from','begin','/{\\$\\?redirect_from}/e',
+        "''.\$_GET['redirect_from']");

  SDV($HTMLStylesFmt['adddeleteline2'],'
  .adldeletebutton {
***************
*** 79,87 ****
      if ($targetpagename=="") {
          $targetpagename = $pagename;
      }
-
-
-
      return FmtPageName("<form
class='adldeletebutton' action='{\$PageUrl}'
method='post'>
              <input type='hidden' name='n'
value='$targetpagename'>
              <input type='hidden' name='action'
value='deleteline'>
--- 95,100 ----
***************
*** 165,176 ****
--- 178,202 ----
      return AdlPost($newtext);
  }

+ function AdlRedirect($to) {
+     global $RedirectDelay;
+     SDV($RedirectDelay,0);
+     $url = FmtPageName('$PageUrl', $to);
+     $args = "?redirect_from=". $_REQUEST['n'];
+     header("Location: $url$args");
+     echo "<html><head>
+          <meta http-equiv='Refresh'
Content='$RedirectDelay; URL=$url$args' />
+         
<title>Redirect</title></head><body></body></html>";
+ }

  # Insert text into the wiki page
  $HandleActions['addline']='AdlHandleAddLine';
  function AdlHandleAddLine($pagename) {
      global $HandleActions,$action,$ScriptUrl;

+     $redirect = $_REQUEST['redirect_to'];
+     if($redirect)  AdlRedirect($redirect);
+
      $page = RetrieveAuthPage($pagename,"read");
      if (!$page) { Abort("?cannot edit $pagename"); }

***************
*** 215,218 ****
  }

  #
vi:shiftwidth=4:autoindent:softtabstop=4:expandtab:
- ?>
--- 241,243 ----


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the pmwiki-devel mailing list