Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

DotsInLinks

Summary: How to enable dots in wiki links
Version:
Status: Experimental
Maintainer: Petko
Categories: Administration Links

Questions answered by this recipe

In PmWiki links, dots are separators between a WikiGroup and a page in that group. So, [[Main.HomePage]] links to a page "HomePage" in a wikigroup "Main".

Is it possible have links like [[Franklin D. Roosevelt]], [[Harry S. Truman]], [[Richard M. Nixon]] to lead to pages in the current group?

See also this thread on the mailing list.

Description

Allow wiki links to the current group to contain dots.

Currently, the recipe only ignores "dot followed by a space" as a separator in pagenames (in wikilinks, wikitrails, pagelists, and other functions calling MakePageName). Links like [[Franklin D. Roosevelt]] will lead to a page [[FranklinDRoosevelt]] in the current wiki group.

A dot followed by another character is considered a Group.Page separator. Links like Main.WikiSandbox, where the dot is not followed by a space, will lead to an external wiki group.

Installation

Place the following code in config.php

function MakePageNameDot($basepage, $str) {
  global $PageNameChars, $PagePathFmt,
    $MakePageNamePatterns;
  SDV($PageNameChars,'-[:alnum:]');
  SDV($MakePageNamePatterns, array(
    "/'/" => '',                   # strip single-quotes
    "/[^$PageNameChars]+/" => ' ', # convert everything else to space
    '/((^|[^-\\w])\\w)/e' => "strtoupper('$1')",
    '/ /' => ''));
  $str = preg_replace('/[#?].*$/', '', $str);
  $m = preg_split('/\\/|\\.(?!\\s)/', $str);
  if (count($m)<1 || count($m)>2 || $m[0]=='') return '';
  ##  handle "Group.Name" conversions
  if (@$m[1] > '') {
    $group = preg_replace(array_keys($MakePageNamePatterns),
               array_values($MakePageNamePatterns), $m[0]);
    $name = preg_replace(array_keys($MakePageNamePatterns),
              array_values($MakePageNamePatterns), $m[1]);
    return "$group.$name";
  }
  $name = preg_replace(array_keys($MakePageNamePatterns),
            array_values($MakePageNamePatterns), $m[0]);
  $isgrouphome = count($m) > 1;
  foreach((array)$PagePathFmt as $pg) {
    if ($isgrouphome && strncmp($pg, '$1.', 3) !== 0) continue;
    $pn = FmtPageName(str_replace('$1', $name, $pg), $basepage);
    if (PageExists($pn)) return $pn;
  }
  if ($isgrouphome) {
    foreach((array)$PagePathFmt as $pg)
      if (strncmp($pg, '$1.', 3) == 0)
        return FmtPageName(str_replace('$1', $name, $pg), $basepage);
    return "$name.$name";
  }
  return preg_replace('/[^\\/\\.]+$/', $name, $basepage);
}
$MakePageNameFunction = 'MakePageNameDot';

Notes

See Also

  • New Group Warning -- Display a warning when a user is creating a page in a non-existent wiki group.
  • RecentChanges Deletion -- Allow authors to delete RecentChanges pages, there-by making it possible for authors to delete wiki groups.
  • NewPageBox Plus -- Adds customisable box plus button form for page creation

Contributors

  • Pm wrote the original MakePageName function, and suggested how to modify it.
  • Petko implemented this solution.

Comments

Edit - History - Print - Recent Changes - Search
Page last modified on July 16, 2008, at 09:02 AM