Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

JjsCMS

administrators

Summary: Save wiki pages as html
Version: 1.4beta3
Prerequisites:
Status:
Maintainer: jjs
Categories: CMS

Question

How can I use PmWiki as a CMS

  • without revealing that the pages come from a wiki
  • although my server is slow - too slow for PmWiki serving to everyone
  • even if I don't fully trust PmWiki s security?

Or

  • How can I create a static copy of all pages of my PmWiki?

Answer

Use jjscms. It saves a modified copy of every page into a specified directory. Since version 1.4beta1 this is done for action=jjscmspublish. Modifications include URL-rewriting (to match the new page location) and removal of "confidential" parts of the template like the edit bar.

How it works

jjscms.php uses php's output buffering feature to capture complete pmwiki pages. An in-memory copy of the captured page is filtered with some regexps and saved to a file. Then the original captured page is presented to the user.

The static pages can be served by a webserver without php, or served by a custom script that could even do further "magic".

Usage

Copy jjscms1_4beta3.phpΔ into your cookbook dir.

Add to local/config.php:

  require_once($FarmD . '/cookbook/jjscms1_4beta3.php');  

add to Site.PageActions:

  * %item rel=nofollow class=edit%[[{$FullName}?action=jjscmspublish | $[Publish] ]]

Since 1.4beta3 no further configuration should be needed to get it working.

Advanced configuration

By default jjscms will save all published pages in the published subdir of your wiki. The $PubDir and $UploadDir folders are shared between public (static) and private (editable) version of the wiki.

Depending on how you plan to separate the cms from its output and restrict pmwiki usage via htaccess, you may have to alter the directory structure of the wiki and set the $JJSCMS.., $UploadDir, $UploadUrlFmt configuration variables accordingly. Finding the correct url and path info can be a bit tricky.

You could also secure the wiki dir by .htaccess and write a script to serve all files from there (Attachments and Skin files).

Configuration Variables

$JJSCMSPublishDir
Directory where the static (public) version of the pages will be written to
Default: 'published'
$JJSCMSPublishUrl
URL prefix to be used in all local links in public version of the page.
Should either point to place where the server is serving $PublishDir, or to a skript that takes <Group>.<Page>.html as parameter
Default: ''
$JJSCMSAttachUrl
Attachment url as used in the wiki
Default: 'uploads/'
$JJSCMSPublishAttachUrl
Point to pmwikis shared upload dir
Default: 'uploads'
$JJSCMSPublishPubDirUrl
Point to pmwikis shared pub dir (mainly needed for skins)
Default: '../pub/'
$JJSCMSPrivateSection
Anything enclosed by <!-- $JJSCMSPrivateSection --> <!-- /$JJSCMSPrivateSection --> in your template will only show up in the private (editable) version of the page.
Default: 'dontpublish'
$JJSCMSPublicSection
Anything enclosed by <!-- $JJSCMSPublicSection --> <!-- /$JJSCMSPublicSection --> in your template will only show up in the public (static) version of the page.
Default: 'dontedit'

Password Protection

Action jjscmspublish can be password protected. Look at the GroupAttributes page. In 1.4beta1 the default password is empty!

Defining what pages may be published

If JJSApprovePage is installed, jjscms will only publish a page if it is in approved state.

Skin / Template changes

You probably have to alter your skins .tmpl file so that the stylesheet-url works from pmwiki as well as in the static version.

To completely remove the edit bar from the static version, add the comment pairs from above around the edit bar section in your skins .tmpl file.

Using a different Skin for publishing

To use the "print" skin for publishing add

$ActionSkin['jjscmspublish'] = 'print';

to your local/config.php

Script

Here's a sample script for serving the static pages. You can name it index.php and put it in the main directory of your site.

It assumes the static pages to reside in ./published

Attachments and skin files must be accessible from their original location.

The $JJSCMSPublishUrl should read index.php?showcmspage=

  
  <?php
  if (isset($_REQUEST['showcmspage'])) 
  {
    $cmspage =   preg_replace('/([[:alnum:]])\.html/s','$1.html',trim($_REQUEST['showcmspage']));
    @readfile('published/' . $cmspage);
    return;
  }
  else
  {
    @readfile('published/Main.HomePage.html');
    return;
  }
  ?>

2006-03-18 Jens Schiffler

Notes and Comments

The newest the latest. And please don't forget to end by date and name. Thanks)

Sidebar and other included content not updated

When you've edited a page that is referenced inside the template or from any other wiki page, (eg. the Sidebar) then you must browse to all referencing pages in order to update their static copy. There's no magic "make" like functionality implemented.

JJSIterator presents a workaround:

Install jjsiterator and using an url like

http://.../pmwiki?jjsiterator=0&action=jjscmspublish

your browser will visit all pages in your wiki thereby refreshing the jjscms cache.

Patch to skins.php

Using a shared pub dir above the pmwiki dir requires a small patch to scripts/skins.php:

  foreach((array)$skin as $s) {
    $sd = FmtPageName("pub/skins/$s", $pagename);
    if (is_dir($sd))
      { $Skin=$s; $SkinDirUrl="$PubDirUrl/skins/$Skin"; break; }
    $sd = FmtPageName("$FarmD/pub/skins/$s", $pagename);
    if (is_dir($sd))
      { $Skin=$s; $SkinDirUrl="$FarmPubDirUrl/skins/$Skin"; break; }
  # BEGIN JJS 2005-04-04
  global $PubDir;
   $sd = FmtPageName("$PubDir/skins/$s", $pagename);
    if (is_dir($sd))
      { $Skin=$s; $SkinDirUrl="$PubDirUrl/skins/$Skin"; break; }
  # END JJS 2005-04-04
  }

Cannot modify header information

I tried to use JjsCMS with PmWiki 2.1.beta17 and got this warning:

require_once('pmwiki/cookbook/jjscms.php');

Warning: Cannot modify header information - headers already sent by (output started at public_html/pmwiki/local/config.php:2) in public_html/pmwiki/pmwiki.php on line 769

Nothing is output in the public static directory defined by $PublishDir.

[Edit 2006-02-04] Oops, I didn't have <?php if (!defined('PmWiki')) exit(); in config.php. After fixing this, I still got no output though.

JustAGuest, 2006-01-03

There is a bug in 1.0. Please try version 1.1. If it still doesn't work please use the mailing list or contact me.

Jens, 2006-01-20

Any explicit explanation for this recipe?

Tried to use this recipe as instructed above and got just blank pages. Explicit instructions would be highly appreciated.

Sichendra, 2006-03-02

I'm working on a better explanation, including a full sample setup. jjscms1_2.php with improved url rewriting code will be released shortly.

Jens, 2006-03-05

Eagerly look forward to it. Any specific date of release? And I would love to know whether the new release will be compatible with all other recipes? Thanks, Jens.

Sichendra, 2006-03-06

Due to the way it works, jjscms should not break pmwiki with most recipes. It is however not aware of any access restrictions! Even password protected pages will be copied to the publish directory.

Jens, 2006-03-06

Still working on the next release. Major changes: Copy is only written on demand (action=jjscmspublish). New features are: Password protection for publishing and an approval mechanism (also password protected) using custom PageAttributes.

Jens, 2006-03-13

Versions

date of publication : 2005-09-10 : jjscms - version 1.0

date of publication : 2006-01-20 : jjscms - version 1.0

date of publication : 2006-03-18 : jjscms - version 1.4beta1

date of publication : 2006-03-19 : jjscms - version 1.4beta2

date of publication : 2006-03-21 : jjscms - version 1.4beta3

  • This recipe was last tested on PmWiki version: 2.1.3
  • This recipe requires at least PmWiki version: 2.1.beta1

See Also

JJSApprovePage

Contributors


Category: CMS
Edit - History - Print - Recent Changes - Search
Page last modified on April 24, 2008, at 07:01 AM