Note: The recipes here are for PmWiki versions 0.6 and 1.0 only. For PmWiki 2.0 recipes, see Cookbook.


Display all the stops on a WikiTrail page in a form suitable for printing.


Attach:publish.tar.gz - latest version that works with PmWiki version 0.6

Requires PmWiki/PmWiki version 0.5.17 or above ( Broke with changes introduced in PmWiki/PmWiki versions 0.6.x). Now fixed in the latest release.

To support listing external links as endnotes, the script redefines the $FmtUrlLink function. If you have written a replacement for this function, you will need to align your customisation with this recipe.

Fix for 0.6.9 and above

Change lines 14-15 in publish.php from

  $HTMLHeaderFmt. = 
    "<link rel='stylesheet' href='\$ScriptDir/styles/print.css' type='text/css' />";


  $HTMLHeaderFmt[] = 
    "<link rel='stylesheet' href='\$ScriptDir/styles/print.css' type='text/css' />";

Replaced in the latest version to use a template and associated style sheet.

Fix for numbering

If there is an new depth more than one level

      if ($depth[$i]<$predepth) {
        for($j=$depth[$i];$j<$predepth;$j++)   $counter[$j] = 0;

Fixed in the latest version


The publish.php script adds an "?action=publish" option to wiki trail pages, which causes all the pages on the trail to be output in a form suitable for printing. WikiAdministrators will probably want to use this script as a guide for customizing their own publish functionality.

The author inserts the markup $Publish? on any trail page and this appears as a button labelled Publish. Or the author can put [[$Publish:PageName]] on any page to publish the specified page.

The steps performed by this script are:

  • define header and footer configuration variables
  • pick up all numbered or bulleted list items on the current page
    • if it's a trail stop reference, display the name of the page as a heading, then the text of the page
    • if it's not a trail stop reference, display the text of the item as a heading
    • use the list sequencing to assign a number to each entry (this would be 2.3)
  • modify the display of links to external sites to be in a form suitable for printing
  • simplify or eliminate the output of trail markup on the stop pages
  • include a GroupPrintHeader page if one exists, instead of a GroupHeader
  • include a GroupPrintFooter page if one exists, instead of a GroupFooter

To use this script, simply add

    <?php include_once("local/publish.php"); ?>

to your local.php configuration.

Still to do:

add radio buttons that let visitors choose between Screen (XHTML) and Print (PDF) formats.

could you also revise it to also publish lists that are created with the T*PageName (and related) mark ups? - (see IncludePara)

T*PageName markup now supported -- the original goal was to be consistent with the PmWiki core software, which doesn't treat T* markup as a trail reference. Authors can achieve the same effect by writing *PageName - [[para:PageName]]. This works as a trail reference and a Publish reference.

To see an example, visit and press Publish.


Publish.php didn't work when the URI looks like ?pagename=... the patch below fixes this (very crudely :-)

[chr@aussie local]$ cvs diff -u 
cvs diff: Diffing .
Index: publish.php
RCS file: /home/chr/repository/toc/local/publish.php,v
retrieving revision
diff -u -r1.1.1.1 publish.php
--- publish.php	7 Dec 2003 11:29:08 -0000
+++ publish.php	23 Dec 2003 16:45:41 -0000
@@ -58,6 +58,7 @@
 SDV($PublishPageNotFoundFmt,'Page \'\'$Tlink\'\' does not exist.');
 SDV($PublishTagFmt,"<form target='_blank' action='\$PageUrl' method='get'>
     <input type='hidden' name='action' value='publish' />
+    <input type='hidden' name='pagename' value='\$PageName' />
     <input type='checkbox' name='include' value='include' />$[Include this page]
     <input type='submit' value='$[Publish]' /></form>");
 -- Christian
The version uploaded on 5 January 2004 fixes this problem.
  • Suggestion: The way I use wiki-trails, I'd prefer not putting [[$Publish]] on the actual trail page. Instead, I'd prefer using markup like this: [[$Publish:TrailPage]] where TrailPage is the page to be published. Actually, if you did it this way, you could collect several 'Publish'-buttons on one page that produce different 'publications'. -- Christian.
The version uploaded on 5 January 2004 addresses this requirement.

Revision History

Released 7 August 2003

Revised 20 August: set $HTMLTitle and open publish view in a new window.

Revised 1 September 2003: combine with PrintablePage, use a better style sheet, and work better with WebMenu.

Revised 12 September 2003: add support for "T*PageName" markup (see IncludePara) and definition list (:PageName:) markup; fix a bug in page numbering.

Revised 1 October 2003: add support for [[include: ... ]] directives, list external links as endnotes, provide an Include this page checkbox.

Revised 30 October 2003: bring include handling into line with pmwiki.php

Revised 5 January 2004: print date last modified for each page (can be omitted using the [[$Publishnodate]] variant), add support for [[$Publish:PageName]]

Revised 25 May 2004: align with PmWiki version 0.6

See Also

  • PmWiki.CustomHeadersAndFooters
  • PrintablePage

Note: if you have downloaded and installed the WikiCalendar, you already have this latest version.


  • John Rankin

pmwiki-2.2.120 -- Last modified by {{jr}}

from IP: ip should be disabled by default for security reasons