[pmwiki-users] Page RSS print without wiki print

Petko Yotov 5ko at 5ko.fr
Sun Jan 11 22:40:56 CST 2009

On Monday 12 January 2009 04:59:18 Daniel Roesler wrote:
> Howdy all,


> I have a few questions about the order that PmWiki processes things.
> I'm trying to write a recipe that creates simple RSS feeds for pages
> detailing their revision history. Basically, my local config.php file
> looks like:
> if ($action == "pagerss") {
> ...
> // rssxml = parsed history (from the actual page files)
> ...
> print(rssxml);
> }
> First, how can I print the RSS xml that my recipe creates without
> printing the rest of the wiki? Is there a variable that sets whether
> or not the actual wiki page prints?

Use $HandleActions['pagerss'] = 'YourFunction';

function YourFunction($pagename, $auth='read')
  global $WikiDir, $FeedStartFmt, $FeedEndFmt;

  # get page content and full page history
  $page = RetrieveAuthPage($pagename, $auth, true);
  if(!$page) Abort("? Not enough permissions to read feed.");

  ### to see what is $page, uncomment next line:
  ### echo '<pre>'; print_r($page); exit;

  # $rssxml = parsed history from the $page array, not from the actual file

  # instruct the browser that it is a feed
  header("Content-type: text/xml; charset=$Charset");

  # $FeedStartFmt contains "<?xml version=\"1.0\" encoding=\"$Charset\"?".">"
  PrintFmt($pagename, $FeedStartFmt, $rssxml, $FeedEndFmt);


See how the scripts/feeds.php is written and you can learn/start from a 
tweaked version of this file (copy it to your /cookbook/ directory first, 
then change all function names).

> Second, how do I incorporate other PmWiki variables into the function,
> such as $WikiDir and $Namespaced? In pmwiki.php, the local config.php
> file is loaded before any default variables (besides several like
> $pagename and $FarmD) are set. How can I set these default variables
> before running this recipe?

The $HandleActions method will call the function after all variables are set.

Note that you should probably get the page history in the $page array as I 
wrote above, and not from parsing the actual files : first it is easier, 
second a wiki may use a PageStore class that is not plaintext files 
(CompressedPageStore, SQLite, MySQL...).

I would suggest getting some existing recipes (feeds.php and other), learn 
from them, reuse their code, tinker, test, start again. 


More information about the pmwiki-users mailing list