|
Cookbook /
AlternateNamingSchemeSummary: Use other naming schemes for PmWiki pages
Version:
Prerequisites:
Status:
Categories: Administration Links
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");
DiscussionYou 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 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.
Suppose I write Suppose I now write a reference to SomePage. The $SpaceWikiWordsFunction will cause this to display as Some Page, if The following settings achieve this: 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. The treatment of capitilization is inconsistent compared with WikiWords. For example:
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]); 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 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. DiscussionQUESTION: how is the modification to 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
"/[^-[: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? :)
Solution's attributes:
The solution I'm talking about is in file:
Download: spacedTitles.phpΔ
(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:
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 NotesI 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...
ReleasesWho is counting??? CommentsSee Also
Contributors |