DotsInLinks

Summary: How to enable dots in wiki links
Version: 20131004
Status: Experimental
Maintainer: Petko
Discussion: DotsInLinks-Talk?
License: GPL2+

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 for PmWiki versions 2.2.57 and newer

$MakePageNameSplitPattern =  '/\\/|\\.(?!\\s)/';

No need to add the function MakePageNameDot() as before.

Note: only this version will be compatible with PHP 7.2 (as soon as the PmWiki core becomes compatible).

Installation for PmWiki version 2.2.56

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)/' => PCCF("return strtoupper(\$m[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 = PPRA($MakePageNamePatterns, $m[0]);
    $name = PPRA($MakePageNamePatterns, $m[1]);
    return "$group.$name";
  }
  $name = PPRA($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';

Installation for PmWiki versions 2.2.55 and older

(Warning! This might not work in php 7.2 . )
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-existing 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

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.