|
Cookbook /
IncludeAbleSummary: How to include the current revision of a pmwiki page in another php page
Version:
Prerequisites: Last tested on PmWiki version: 2.0.6
Status:
Maintainer: Wesley Tanaka
Categories: Includes
QuestionHow do you include the current revision of a pmwiki page in another php page? AnswerLet's say I want to include the current content of a pmwiki page in a php page called viewplace.php 1) Patch pmwiki.php in one place, namely:changing the exit; on line 279 (version 2.0.6) to return; See PITS.00548 fixed in pmwiki v 2.0.12! 2) Add this php code to viewplace.php:<?php $_REQUEST['pagename'] = 'pmwiki page'; $cwd = getcwd(); chdir('wiki'); include 'pmwiki.php'; chdir($cwd); ?> 3) To your config.php, add something like:if (strpos($_SERVER['REQUEST_URI'], 'viewplace') !== FALSE || strpos($_SERVER['REQUEST_URI'], 'handleplacecomment') !== FALSE) { // Switch skin. This has to go first because stdconfig loads
// scripts/skins which loads the skin.
if (strpos($_SERVER['REQUEST_URI'], 'viewplace') !== FALSE)
$Skin = 'embed';
else if (strpos($_SERVER['REQUEST_URI'], 'handleplacecomment') !== FALSE)
$Skin = 'blank';
// process stdconfig. This has to go before clearing the
// HTTPHeaders because some headers are set from stdconfig itself.
include_once("} This code needs to be added after any other HTTPHeaders or Skin assignments in config.php. 4) Create an 'embed' skin with:<!--PageText--> in it. NotesReleasesCommentsIt's possible to add items to a pmwiki page without going to a pm wiki page by doing something like: if ($datathere) { // Necessary because if the pmwiki page exists, there's no way to make
// pmwiki.php not output anything. HandleBrowse has a hardcoded
// $PageText in HandleBrowseFmt.
$_REQUEST['pagename'] = 'Some.Pmwiki.Page.Or.Other.Which.Does.Not.Exist';
$cwd = getcwd();
chdir('../wiki');
include 'pmwiki.php';
$_REQUEST['pagename'] = 'PmwikiPage.To.Change';
$oldpage = RetrieveAuthPage($_REQUEST['pagename'], 'read');
$newpage = $oldpage;
$newpage['text'] .= "\n!!!" . 'comments go here';
PostPage($_REQUEST['pagename'], $oldpage, $newpage);
chdir($cwd);
header('Location: http://some.success.page/(approve links)');
} else { header("Location: http://some.error.page/(approve links)");
} By pointing _REQUEST['pagename'] to a pmwiki page that doesn't exist, and by applying the above patches as well, pmwiki.php doesn't generate any output, which allows you to set headers (e.g. redirect) after the pmwiki page has been updated. Be careful, because pmwiki appears to clear variables you may have set before it was included. I got around this by storing things in $_REQUEST. I'm also interested in plugging in the authentication mechanism for the rest of my website so that comments by logged in users will be treated and logged differently than comments from anonymous guests. I saw some reference to that on another page, but nothing specific yet. This seems like it could be used as a recipe to create includes which execute with the 'context' of the included page. This would mean that vars like {$Name} and {$Group} would get replaced with the values of the included page instead of the including page. - Martin Fick November 07, 2005, at 04:48 PM See AlsoContributors |