[pmwiki-users] Help with recipe to make a static, blog-style, updates page

Selene Tan ashera at gmail.com
Mon Sep 18 02:50:42 CDT 2006

I started working on a recipe for a static, blog-style updates page,
since that's the main bit of blog functionality I want for PmWiki. I
adapted the code from PostRecentChanges, and I managed to get
something that will copy the full text of an edited page to the
updates page.

My problem is that when the script copies the text of the edited page,
it copies the previous version, rather than the most recent version
(the one that has just been posted).


I've included the recipe below:

<?php if (!defined('PmWiki')) exit();
/**  \brief Adds a static blog-style updates page to PmWiki
 *  This script adds a static blog-style updates page to pmwiki, using the
 *  same technique as for the RecentChanges pages. When a page is edited,
 *  the script puts a copy of the page on the Updates page.
 *  Copyright 2006 Selene Tan (ashera at gmail.com)
 *  You can redistribute and/or modify this file
 *  under the terms of the GNU General Public License as published
 *  by the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.

define(STATIC_UPDATES_PAGE, '0.1');

# Set default for max # of updates to show on the updates page
SDV($MaxUpdatesOnPage, 10);

# Set default for the name of the updates page
SDV($UpdatesPageName, "Updates");

# Add PostUpdates to the Edit Functions
$EditFunctions = array('EditTemplate', 'RestorePage', 'ReplaceOnSave',
    'SaveAttributes', 'PostPage', 'PostRecentChanges',
    'PostUpdates', 'PreviewPage');

# This is what will be added to Updates. Adapted from $RecentChangesFmt.
$UpdatesFmt = array(
  "\$SiteGroup.All{$UpdatesPageName}" =>

$CurrentTime $[by] $AuthorLink:
(:comment post block:)
"\$Group.{$UpdatesPageName}" =>

$CurrentTime $[by] $AuthorLink:
(:comment post block:)

# Function to post the updates.
# It inserts the full text of the updated page in an entry at the top
# of the Updates page, and keeps the number of entries at $MaxUpdatesOnPage
# Adapted from PostRecentChanges().
function PostUpdates($pagename,&$page,&$new) {
    global $IsPagePosted, $UpdatesFmt, $MaxUpdatesOnPage, $RCDelimPattern;

    if (!$IsPagePosted)

    foreach($UpdatesFmt as $upfmt=>$pgfmt) {
        # Replace the FULL_TEXT_HERE in $pgfmt with the actual text
        $pgfmt = str_replace("FULL_TEXT_HERE", $page['text'], $pgfmt);

        $upname = FmtPageName($upfmt,$pagename);
        if (!$upname)
        $pgtext = FmtPageName($pgfmt,$pagename);
        if (!$pgtext)

        if (@$seen[$upname]++)

        $uppage = ReadPage($upname);

        $upelim = preg_quote(preg_replace("/$RCDelimPattern.*$/",'

        # Put the update entry at the top of the text
        $uppage['text'] = "{$pgtext}\n{$uppage['text']}";

        # Split up the entries on the page into an array, and only keep
        # the $MaxUpdatesOnPage newest ones.
        if ($MaxUpdatesOnPage > 0)
            $uppage['text'] = implode("(:comment post block:)", array_slice(
                explode("(:comment post block:)", $uppage['text'],
$MaxUpdatesOnPage + 1), 0, $MaxUpdatesOnPage));

        WritePage($upname, $uppage);

#end recipe

More information about the pmwiki-users mailing list