AlternateNamingScheme
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
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). $SpaceWikiWords
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:
- upshift the first letter (names must start with an upper case letter or number)
- turn spaces into underscores
- an alternate
AsSpaced()
function changes underscores into spaces - a new
SpaceWikiWords()
function spaces wiki words on entry - an alternate
MakePageName()
function applies the algorithm to names (the$Name
, not the$Group
) - expand the list of likely homonyms in
$PagePathFmt
- use the
$Title
instead of the$Name
inRecentChanges
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
to '$DefaultName
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");
Second case (the freeform way)
The PmWiki naming scheme is governed by a variable named
. Actually, Patrick suggested this approach.
$MakePageNamePatterns
The default declaration of said variable is:
$MakePageNamePatterns = array( "/'/" => '', # strip single-quotes "/[^$PageNameChars]+/" => ' ', # convert everything else to space '/((^|[^-\\w])\\w)/' => 'cb_toupper', # capitalize words "/\\s+/" => '_');
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)/" => 'cb_toupper', # 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. See UnaccentUTF8 for case-insensitive and accent-insensitive page searches, great for international wikis!
Notes
Dash-Pagenames can provide dash-separated all-lower-case pagenames, and still keep the original pagename functionalty for groups 'PmWiki', 'Site' and 'SiteAdmin' (so not to break things).
The script makes use of an alternate version for
to create page names with dashes/hyphens, and an alternate version of function $MakePageNamePatterns
MakePageName()
, which enables automatic switching between the original $MakePageNamePatterns
and the patterns for dashed-spaced names, for all others groups. It is aimed primarily for UTF-8 enabled international wikis. - HansB
- 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
See Also
- Dash-Pagenames - URLs and page names with dashes for word spacing, UTF-8 friendly
- PerGroupSubDirectories
- ISO8859MakePageNamePatterns - How to convert ISO 8859 character input for page names to unaccented ASCII equivalents
- Router - Router should make it possible to define your URLs however you like, forwarding on to PmWiki default filenames.
Contributors
Comments
See discussion at AlternateNamingScheme-Talk