|
Cookbook /
AlternateNamingSchemeSummary: Use other naming schemes for PmWiki pages
Version:
Prerequisites:
Status:
Discussion: AlternateNamingScheme-Talk
QuestionIs it possible to use PmWiki with another naming scheme for the pages? For example, instead of CamelCaseNames using underscore_separated_names? AnswerYes. 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 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:
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 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 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. Notes
ReleasesSee Also
ContributorsCommentsSee discussion at AlternateNamingScheme-Talk |