PerGroupSubDirectories

Summary: Subdivide wiki.d into subdirectories according to page group
Version: n/a
Prerequisites: Last tested on PmWiki version: 2.2.0-beta63
Status:
Maintainer: Petko

Questions answered by this recipe

PmWiki.FlatFileAdvantages describes that it's possible to subdivide wiki.d/ into subdirectories according to page group.

  1. How is this done?
  2. Is there a straightforward way to convert an existing pmwiki to this mode, or is it best done with a new wiki?

Answer

Essentially, to get per-group subdirectories for pages one adds the following line to (farm)config.php:

    $WikiDir = new PageStore('wiki.d/{$Group}/{$FullName}');

Note : The last part of the path should be {$FullName} and not {$Name}.

Note : This should appear relatively early in config.php; in particular, if you are using AuthUser, it must appear before you include authuser.php. Otherwise, AuthUser doesn't find your Site.AuthUser page and it rejects all logins. It should also be used before you include any other script or recipe calling the function ResolvePageName(), and before Internationalizations' UTF-8 and/or XLPage(). In case of problems within wiki-farms, see these messages on the mailing list: [1] and [2].

Note : In international wikis, this code should appear before the call to the XLPage() function.

The admin must then move any existing page files in wiki.d/ into the appropriate per-group subdirectories and make sure that each per-group subdirectory has appropriate file permissions. Generally if the per-group subdirectories have the same ownership and permissions as wiki.d/ then things will work out okay (and of course PmWiki will create new directories with the correct permissions as needed).

A somewhat easier mechanism for migrating is to rename the wiki.d/ directory to "wiki-flat.d", then use the following in config.php:

    $WikiDir = new PageStore('wiki.d/{$Group}/{$FullName}');
    $WikiLibDirs = array( &$WikiDir,
      new PageStore('wiki-flat.d/$FullName'),
      new PageStore('$FarmD/wikilib.d/{$FullName}'));

This will cause PmWiki to continue to use any pages existing in wiki-flat.d/ (the old wiki.d/), but any newly created or edited pages are saved in the new wiki.d/ in per-group subdirectories. (If users try to delete a wiki page, the page will be deleted in the new group folder but not in the wiki-flat.d folder.)

Per-group sub-sub directories

Taken from the mailing list. If you plan to have a very big number of groups, you may wish to further sub-divide the wiki.d/ directory. You can split the $Group directories inside a directory named by its' first letter: like:

   Main.HomePage -> wiki.d/M/Main/Main.HomePage
   Site.SomePage -> wiki.d/S/Site/Site.SomePage

It is easily done by setting this in config.php:

   $FmtPV['$Group1'] = '$group[0]';
   $WikiDir = new PageStore('wiki.d/$Group1/$Group/$FullName');

("$Group1" here means "first letter of $Group".)

If you have lots of Groups, you may also wish to sub-divide the upload directories. It is easily done by adding after the previous code:

   $UploadPrefixFmt = '/$Group1/$Group';

For $UploadPrefixFmt see PmWiki.UploadsAdmin.

Notes and Comments

Couldn't we use the "apply-to-all-pages"-function together with a method that "re-saves" a page? That ought to save the page to the proper place.


I just did this to one of my sites, which has a lot of pages, and therefore has a really long directory listing. I use the following on wiki.d to create the new subdirectories in a temporary subdirectory:

#!/bin/sh
for i in `ls -1 *.* | awk -F'.' '{ print $1 }' | sort | uniq`; do 
  mkdir -p tmp/$i; 
done

And then, to move the files themselves, I did this:

#!/bin/sh
for i in `ls -1 *.*`; do
  d=`echo $i | awk -F. '{ print $1 }'`;
  mv $i tmp/$d
done

I was being extremely careful so I backed up wiki.d beforehand, and I did the above in two small steps. This may work all in one combined step if you are in a hurry (but, beware, I haven't tested it myself):

#!/bin/sh
for i in `ls -1 *.* | awk -F'.' '{ print $1 }' | sort | uniq`; do 
  mkdir -p tmp/$i; 
  mv $i.* tmp/$i;
done

-- Julian I. Kamil


Discussion

I tried putting $WikiDir = new PageStore('wiki.d/{$Group}/{$FullName}'); in local/config.php but it doesn't seem to have any effect. Did I do something wrong?

I've just tried the 'wiki.flat.d' markup documented above and it seemed to work fine on PmWiki 2.0.6. Upon checking the file system I noticed that .*.count files are still stored in the original location (wiki.d) even though all the new pages are correctly located in the respective directories. I know these are files internal to the working of PmWiki, I just thought it was odd. Do you think all is fine? Smc September 27, 2005, at 03:37 PM

I think this is a very good idea. But, I also feel this would be better implemented in the core. Should we be voting on this as a core feature? Ian MacGregor July 21, 2007

Works correctly using PmWiki: v-2.2.0beta63 and standard URLs after moving all files to appropriate sub-directories. I tested pagelists and search with standard URLs on PmWiki: v-2.2.0beta63 and v-2.1.27 with identical results for:

config.php:
   $FmtPV['$Group1'] = '$group[0]';
   $WikiDir = new PageStore('wiki.d/$Group1/$Group/$FullName');

[Group].[Page]?action=edit:

(:pagelist group=Main fmt=#title order=title:)

[Group].[Page]?action=browse:

  -- Search: [Main/]
 Nice! --jtankers

Hello. i am using $WikiDir = new PageStore('wiki.d/{$Group}/{$FullName}'); but i have a problem with http://www.pmwiki.org/wiki/Cookbook/CommentPageLink : In URL with cirillical char (sorry for my english) i have not normal link after click on "Discuss link". For exaple: i have page Home.english_char and i have discuss page Comment.Home-english_char

But i have page Home.cirillic_char and have discuss page : {Comment.HomeCirillic_charFullName}) without " - " and with " {} " !!!! Help me please.


Simple way to mass move wiki pages to a different wiki group

Somewhat related to this recipe .. recently I had to come up with a simple way to move a huge numbers of pages to different wiki groups. Here's what I did to achieve this.


#This renames ALL wiki pages with name $SRC.* in the current working directory to $DST.*
#The SRC and DST wiki groups can be specified below.

#change the next 2 lines to your old and new groups
SRC='News'
DST='Newsletter'


for x in `ls -d $SRC.* | sed 's/^.*\.//' `; do 
  mv $SRC.$x $DST.$x;
done
Note: See also WikiSh for other methods of achieving the same result

farhad November 18, 2009, at 11:59 AM, Grype Solutions

Under Windows I user Renamer for this.

  • rename wiki.d folders
  • rename files in wiki.d folder
  • rename uploads folder or move uploads files if necessary
simon November 18, 2009, at 04:41 PM

See Also

Contributors

  • Pm He posted this as an email in the discussion group.

User notes +3: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.