Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

AlternateNamingScheme

Summary: Use other naming schemes for PmWiki pages
Version:
Prerequisites:
Status:
Maintainer: jr, MarcioRPS
Categories: Administration Links

Question

Is it possible to use PmWiki with another naming scheme for the pages? For example, instead of CamelCaseNames using underscore_separated_names?

Answer

Yes. PmWiki is structured in such a way that it is relatively easy to make very drastic changes to its behavior.

The most popular alternative naming scheme is using underscores to separate the words of page names. But this is not by any means the only possibility. Two solutions are offered here.

First Case (the packaged solution)

Alternative scheme for wikiword spacing, using underscores to represent spaces in page names.

For sites where the administrator wants to set $SpaceWikiWords to true some common problems arise. For example, those pages are not quite right: War and Peace?, Novell NetWare?, Apple iTunes?, James McGregor?, Community of Practice?. References are fine, but the spaced page names may not be (War And Peace, Novell Net Ware, Apple I Tunes, James Mc Gregor, Community Of Practice). There are 2 issues: inappropriate spacing and inappropriate capitalisation.

This first bundled solution tries to enhance the power of the current AsSpaced function. From an author's perspective, using [[ ... ]] markup gives you the page name you ask for; only the first letter gets capitalised and spacing is preserved as entered. The script implements the following alternative page naming algorithm:

  1. upshift the first letter (names must start with an upper case letter or number)
  2. turn spaces into underscores
  3. an alternate AsSpaced function changes underscores into spaces
  4. a new SpaceWikiWords function spaces wiki words on entry
  5. an alternate MakePageName function applies the algorithm to names (the $Name, not the $Group)
  6. expand the list of likely homonyms in $PagePathFmt
  7. use the $Title instead of the $Name in RecentChanges and search results

It is fairly liberal in its treatment of wiki words, looking to see if Wiki_Word and then WikiWord exist. NewPage becomes New_Page by default, but an author can always prevent spaces by writing [[NewPage]] if appropriate (for example FileMaker?. It sets the $DefaultName to 'Home_Page' but will still find Main.HomePage correctly.

So, on with the files:

spacewikiwords.phpΔ -- download the file and add the following line to local/config.php
  include_once("local/spacewikiwords.php");

Discussion

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.

http://forums.seochat.com/showthread.php?p=50891&highlight=underscores+hyphens#post50891 - Google recognize hyphens as words' separators, not underscores. I am use space 2 hyphen replacing, but can be conflicts with real hyphens in pagenames.

samlowry

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

etc.

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]))));

with

  $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

Second case (the freeform way)

The PmWiki naming scheme is governed by a variable named $MakePageNamePatterns. Actually, Patrick suggested this approach.

The default declaration of said variable is:

$MakePageNamePatterns = array(
    "/'/" => '',                           # strip single-quotes
    "/[^$PageNameChars]+/" => ' ',         # convert non-alnums to spaces
    "/((^|[^-\\w])\\w)/e" 
      => "strtoupper('$1')",               # initial caps after spaces
    "/ /" => ''                            # strip spaces
);

Those are regular expressions that are aplied to the text inside [[ ]] freelink markups. You have to change it to suit your ideas of how pages should be named. As you might have noticed, regular expressions are very powerfull, and almost anything could be done this way.

To separate words in pagenames with underscores, you would have to change the last of those 4 rules to:

    "/\\s+/" => '_'                        # Convert spaces to underscores

Thus, Documentation index becomes "Documentation_Index".

The third rule (the one with strtoupper function) is responsible for the automatic up-casing of letters. If you want to upcase only the first letter of the pagename (so that Documentation index becomes "Documentation_index"), you could do:

    "/(^\\w)/e" => "strtoupper('$1')",     # initial caps

(Beware, if you do NOT uppercase the first letter of your pagenames, the wiki will stop recognizing them as files, and you will need to alter the variables:

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

If the wiki can then do a case-insensitive search for the corresponding page file, this should go a long way.

Discussion

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')",
    "/ /" => '_');

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???

Third solution? :)

  • 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?

Answer:
  1. Download spacedTitles.phpΔ
  2. put it in 'cookbook' directory
  3. enable it in your wiki - add following line to 'local/config.php':
include_once("$FarmD/cookbook/spacedTitles.php");

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

Notes

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...

  • This recipe was last tested on PmWiki version:
  • This recipe requires at least PmWiki version: and (any other recipes)
  • This recipe, version...... was installed here the...(date)

Releases

Who is counting???

Comments

See Also

Contributors

Edit - History - Print - Recent Changes - Search
Page last modified on August 01, 2008, at 03:28 AM