Summary: Talk page for AlternateNamingScheme.
Maintainer: jr, MarcioRPS
Users: (View? / Edit)

This space is for User-contributed commentary and notes. Please include your name and a date along with your comment.


You might want to consider this carefully before implementing. There is no benefit if you join wiki words by default. There is probably significant benefit if you expect to disable wiki words and just use [[ ... ]] markup.

This recipe doesn't play properly with trails. The trails script uses the $AsSpacedFunction to space wiki words before building the list of trail stops. As discussed above, the AlternateNamingScheme uses 2 spacing functions: one to turn underscores in page names into spaces and one to space wiki words. PmWiki uses the same function for both tasks. PITS.00103 describes a proposed work-around.

This "recipe" doesn't seem to go along well with MarkupExtensions, probably because that plugin also redefines AsSpacedFunction? -- Arjen

If you have the MarkupExtensions enabled, please use spacenames.phpΔ (which omits some of the code already present from that script). -- jr
Here's what is supposed to happen. An example follows.
  1. WikiWords get spaced using the $SpaceWikiWords function, which extendmarkup.php sets to 'SpaceWikiWords' -- this is an enhanced version of PmWiki's AsSpaced function. If $SpaceWikiWords = 1, the text of links to WikiWords is spaced, eg Wiki Words. So if you disable this function, you will probably get an 'error undefined function' if $SpaceWikiWords = 1.
  2. Page Titles (the name above the page text) get spaced using the function ULAsSpaced -- it just turns underscores into spaces. PmWiki uses $AsSpacedFunction to space titles, so spacewikiwords.php includes a line to set $AsSpacedFunction = 'ULAsSpaced'. Notice that if we apply ULAsSpaced to a WikiWord, it will have no effect. That's why we need a separate $SpaceWikiWordsFunction.
  3. The reference to markup.php was a typing error.

Suppose I write [[Apple iTunes]] and [[Novell NetWare]]. The alternate naming scheme will create pages called Apple_iTunes and Novell_NetWare. The $AsSpacedFunction (ULAsSpaced) will cause the titles to display as Apple iTunes and Novell NetWare.

Suppose I now write a reference to SomePage. The $SpaceWikiWordsFunction will cause this to display as Some Page, if $SpaceWikiWords = 1. However, this will be treated as a reference to Some_Page, as if I had written [[Some Page]]. On the other hand, if $SpaceWikiWords = 0 (or $SpaceWikiWordsFunction = 'ULAsSpaced'), the link will display as SomePage, but still link to Some_Page.

The following settings achieve this:
$SpaceWikiWords = 1;
$AsSpacedFunction = 'ULAsSpaced';
$SpaceWikiWordsFunction = 'SpaceWikiWords';

FWIW: my advice is if you use the AlternateNamingScheme, disable WikiWords. - Google recognize hyphens as words' separators, not underscores. I am use space 2 hyphen replacing, but can be conflicts with real hyphens in pagenames.


The treatment of capitilization is inconsistent compared with WikiWords. For example:

  1. Search and Rescue? becomes Search_and_Rescue
  2. search and rescue? becomes Search_and_rescue
  3. Search And Rescue? becomes Search_And_Rescue


Capitalization is only enforced on the first word. This causes a confusion of pages on Unix (Linux) systems where filenames are case-sensitive and different capitilization is applied in the link text.

If you want consistent capitalization go to the function MakeULPageName() in spacewikiwords.php and replace the line:

  $name=ucfirst(str_replace(' ','_',trim(preg_replace("/[^$PageNameChars]+/",' ',$m[2]))));


  $m[2] = ucwords($m[2]);
$name=str_replace(' ','_',trim(preg_replace("/[^$PageNameChars]+/",' ',$m[2])));

This will for capital letters for the first letters of each word.

This works with trails okay. As the poster above said, it is probably better to use '-' hyphens rather than underscores '_' as not all search engines see underscores as spaces.

Hope this helps.

davidof - 07 September 2005

Error: I get the following error:

Fatal error: Call to undefined function wikilink() in *****/spacewikiwords.php on line 120

QUESTION: how is the modification to $MakePageNamePatterns supposed to be set?

If I insert the following in config.php

	$MakePageNamePatterns = array(
    "/'/" => '',			   # strip single-quotes
    "/[^$PageNameChars]+/" => ' ',         # convert everything else to space
    "/((^|[^-\\w])\\w)/e" => "strtoupper('$1')",
    "/ /" => '_');         # Convert spaces to underscores

I get this error:

Warning: Compilation failed: missing terminating ] for character class at offset 4 in /pmwiki.php on line 419

Many thanks HYPERGURU

I was having the same problem (only in linux, not in Windows). I solved removing the variable reference in the second rule, changing it to: (MarcioRPS February 07, 2006, at 01:47 AM)
    "/[^-[:alnum:]]+/" => ' ',         # convert everything else to space

QUESTION: Is there a way to make this work for groups as well?

I'm not very sure it does not allready work for groups, did you test??? Could you say exactly what's not working???

  • I'm quite confused by the amount of comments and information given above. Anyway, not dwelling too much into complicated side notes and suggestions, yet basing on the two recipes above + some other one found on some other page here (not in the Cookbook), I've created a solution which works perfectly (as for now) for me.
Solution's attributes:
  • Tested only with [[free links]] (I have $LinkWikiWords=0; - disabled - as by default since PmWiki 2.1 beta2)
  • Works for default ISO-8859-1 encoding, as well as for UTF-8 (see at the top of your PmWikiXx.XLPage)
  • Works with PmWiki.WikiTrails
  • Not tested with the Markdown recipe (probably won't work together in current shape, as this one changes the $AsSpacedFunction)
The solution I'm talking about is in file:
(installation as usually - copy the file to your cookbook directory, then in local/config.php add line of: include_once("$FarmD/cookbook/spacedTitles.php");)

What about the original question:

So... how do I get underscore_separated_names, all lower case, no capital letters?

Insert this code in config.php

$MakePageNamePatterns = array(
    "/'/" => '',						# strip single-quotes
    "/[^[:alnum:]_-\\s]+/" => '',				# convert non-alnums to spaces
    "/([\\w]+)/e" => "strtolower('$1')",			# make all lowercase
    "/\\s+/" => '_'						# convert spaces to underscores

$GroupPattern = '[\\w]*(?:-\\w+)*';
$NamePattern = '[\\w]*(?:-\\w+)*';

The downside of this is that all the pages in PmWiki and Site will no longer be found. I'm not sure how to get around this.Kathryn Andersen February 12, 2007, at 10:43 PM

I just did troll this recipe, I admit, but it was very messy and hard to understand. I over-valued a lone sugestion that was almost forgotten on the end of the page, but that was Pm's suggestion for the way to do that, so I divided the whole recipe in two, stating that there are two ways of acomplishing it, and I put the vast amount of comments in a block, to make things clearer...

Talk page for the AlternateNamingScheme recipe (users?).