[pmwiki-users] How to include wiki page into php variable?

Patrick R. Michaud pmichaud at pobox.com
Mon Apr 10 08:25:09 CDT 2006


On Sun, Apr 09, 2006 at 10:07:57AM +0100, Octocias wrote:
>    Now that I can extract WikiCode, I find that I cannot insert it into a
>    page without being incorrectly translated. Logic tells me this could be
>    solved by correcting the "when" parameter in the markup function call, but
>    I have tried so many that I have to give up on trial and error and ask for
>    a definitive/intelligent solution.
> 
>    As a simple test, please see the following page:
> 
>    http://www.octocias.com/index.php?n=Private.TestA
> 
>    And here is the test code from my config.php :
> 
>    Markup('test', '<include', '/\\(:[t|T]est +(.+) *:\\)/e',
>    "QuickTest('$1')");
>    function QuickTest( $Source )
>    {
>      $page = ReadPage( "$Source", READPAGE_CURRENT );
>      $out  = $page['text'];
>      return $out;
>    }
> 
>    Can you help me solve this?


1.  Why not just use the existing (:include:) markup which does
    basically the same thing?

2.  But, in order to solve the above, keep in mind that there's
    a *bit* more that has to happen to process the text.  '<', '>',
    and '&' all have to be ampersand-encoded, blank lines have to
    be recognized, and markup processing has to be restarted with
    the first rule (in case the included text has any markups that
    need to be processed by rules already executed).  So, perhaps:

    function QuickTest( $Source )
    {
      # read the page
      $page = ReadPage( "$Source", READPAGE_CURRENT );
      $out  = $page['text'];
      # handle html special chars such as '<', '>', '&'
      $out = htmlspecialchars($out, ENT_NOQUOTES);
      # treat blank lines as <:vspace>
      $out = PVS($out);
      # restart markup rule sequence
      PRR();
      # return new text
      return $out;
    }


Pm


>    On 08/04/06, Patrick R. Michaud <pmichaud at pobox.com > wrote:
> 
>      On Sat, Apr 08, 2006 at 08:11:44PM +0100, Octocias wrote:
>      >    As a follow-up, I've tried to borrow code from the (:include:)
>      markup and
>      >    I did:
>      >
>      >    $out = PRR(IncludeText( 'Group.Pagename', ''));
>      >
>      >    .. without success.
>      >
>      >    Can you tell me if this is supposed to work or how to make it work?
> 
>      If you just want to read the text of another page, it's:
> 
>          $page = ReadPage('Group.Pagename', READPAGE_CURRENT);
>          $out = $page['text'];
> 
>      The READPAGE_CURRENT says that you're just interested in the
>      most recent version of the page (so you can avoid reading the
>      history).  If you want the history read also, omit the READPAGE_CURRENT.
> 
>      Note that this doesn't do any authorization checking for the page --
>      it reads it even if the current visitor isn't authorized to view
>      it.  To get the page only if the visitor has permission to see it,
>      then use:
> 
>          $page = RetrieveAuthPage('Group.Pagename', 'read', false,
>      READPAGE_CURRENT);
>          if (!$page) { ...can't read page... }
>          $out = $page['text'];
> 
>      Pm
> 
>    --
>    Octocias
>    http://www.octocias.com




More information about the pmwiki-users mailing list