Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

MarkupExpressionsExtensions

Summary: Adds math, threads, captcha, group counter, random number, attr reader, CSV formatter, server variables, source reader, etc.
Version: 2007-04-19
Prerequisites: Very latest version of PmWiki beta series or Pm's MarkupExpression recipe.
Status: Stable
Maintainer:

Questions answered by this recipe

Questions:
How can I do basic math calculations on a wiki page?
How can I add basic captcha capabilities to my wiki?
How can I tell how many pages there are in a group?
How can I get a thread number for some group?
How can I display a CSV list, nicely formatted?
How can I show markup from a page or section of a page?
How can I get server variable information from a visitor?
Answer:
Download and enable the mkexpext module: mkexpext.phpΔ
Note: Feel free to delete functions you don't want or just borrow one or two and add to a config page for a special need. Also note, these markups are all included in Acme's ZAP Toolbox. Do not use this recipe if you have that installed.

How it works:

Below are some of the extensions (and some page variables) that are available to you if you install this recipe.

{(count Group)}Number of pages in current group, or if specified another group. Use a | to begin a list of CSV excluded page names.
{(thread Group)}Thread for current group, or if specified another group. Highest number page in the group +1
{$Captcha}Random number between 10000 and 99999, all after instances on same page return the same number. Add two numbers if you want to change the range.
{(math '(2+3) * 7 /4')}Returns 8.75. Can take any basic math expression. Accepted characters configurable
{(wiki pagelist group=Main)}Changes to (:pagelist group=Main:) and executes. Can be stored in a hidden text variable. Default allowed directives include: table, tableend, cell, cellnr, include, if, pagelist, input, messages, redirect, title. Can also be configured to include ZAP forms.
{(source Group.Name#ID123)}Returns source code for that page, and that section if specified. Use the included (:textarea:) markup to prefill the source into a textarea. Put a + before Group.Name to eliminate trailing textarea.
{$IPAddress}Returns ip address of visitor. Other var's available include $ReturnLink (referrer link), $Browser, and $DomainName.
{(list '{$:mylist}' '[[~{item}]]^[[<<]]')}Converts the CSV text var mylist into a nicely formatted list of links to their profile pages. Can be configured however you want.
{$Keywords}Returns keywords for a page (to match $Title & $Description) and if authorized, the $PasswdEdit, $PasswdRead attributes for current page. Add a pagename parameter to return the attributes of a different page.
{(random 1 6)}Returns a random number between 1 and 6
{$Now}Returns current unix timestamp.

There may be some other things I left out...

As the markup expressions are all processed just after page and text variables, page and text variables can be used in them. Because it is processed just before conditionals and other directives, it can be used in them. Also, MarkupExpressions allow for nice chaining of these functions! Have fun...

Note: just fixed a bug in the wiki expression extension and fixed the authorization line in the source expression. 4/19/2007 Caveman

Contributors

  • Caveman Click here to learn more about the story behind this recipe...
  • Many others who have suggested countless ideas along the way.

Comments

Questions by HansB:
Responses by Caveman:

The count markup gives different results than Pm's pagelist fmt=count (PagelistCount). It may be because this recipe uses a hardcoded exclusion list, and so will not reflect custom exclusion lists as PmWiki allows. In any case Pagelistcount is more flexible and more accurate, so i am not sure why {(count)} is needed.

  • It may be more flexible, but this markup is much easier. Can be done on the fly for simple uses. Also within pagelist templates. Plus, it is not hardcoded. It's built on a SDV variable which can be reset as desired.

I am not sure what "Thread" means. Last page in a group of pages with numeric page names?

  • Yes, except it automatically adds +1, to give you the next thread.

Why is the {(pagelist group=Group)} markup needed, if all it does is to translate the normal syntax?

  • It can be stored in a hidden text variable and retrieved.

For some of these markups I wonder why the normal pmwiki pagevariable syntax {$VarName} is not used, as they are providing page variables.

  • Mostly so you don't have to mess with config files. Or to give more options.
  • On second thought you are right. Several have now been switched to page variables.

Here's another useful one:

 ##(str_replace) markup expression
 SDV($MarkupExpr['str_replace'], 'str_replace(explode(",",$args[0]), explode(",",$args[1]), $args[2])');

So given the page text variable

 (:text: You can't chew pizza all day.:)

The markup expression

 {(str_replace "pizza" "ooba" "{$:text}")}

returns the string

 You can't chew ooba all day.

And the more complex expression

 {(str_replace "chew","pizza","day" "eat","ooba","night" "{$:text}")}

performs multiple replacements and produces

 You can't eat ooba all night.

You can also replace an array with a string, allowing you to strip various unwanted characters (or words) from a variable:

 (:myname: Mary O'Meara-Malloy:)
 {(str_replace " ","'","-" "" {$:myname})}

produces

 MaryOMearaMalloy

Ben Stallings May 28, 2007, at 10:47 AM

I like the functionality this recipe offers. Unfortunately for me it caused action=attr to show incorrect settings (the worst case: one page's read authorizations appeared for other pages to which they did not apply). When I removed the recipe, the authorizations appeared correctly again.

- RandyB January 27, 2008 at 7:22 PM

as function ereg is deprecated in php 5.3.0 .
modify line 100
if (! ereg("^[0-9]+$", $n)) continue; to if (! preg_match("/^[0-9]+$/", $n)) continue;
might work.

- KPX? April 26, 2011, at 09:53 PM

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.

Edit - History - Print - Recent Changes - Search
Page last modified on September 10, 2011, at 11:42 AM