[pmwiki-users] Sub-dividing page files into sub-folders within each Group folder

Petko Yotov 5ko at 5ko.fr
Tue Dec 20 18:15:32 CST 2011

On Monday 19 December 2011 15:36:56, kirpi at kirpi.it wrote :
> > One "natural" approach [...] would be to further sub-divide
> > page files into sub-folders within each group, creating and handling
> > sub-directories named by pages first letter, like in
> >   Main.HomePage -> wiki.d/Main/H/Main.HomePage
> >   Main.SomePage -> wiki.d/Main/S/Main.SomePage
> >   Site.SomePage -> wiki.d/Site/S/Site.SomePage
> It seems that setting:
>    $FmtPV['$Name1'] = '$name{0}';
>    $WikiDir = new PageStore('wiki.d/$Group/$Name1/$FullName');

This should work for pages starting with A-Z letters, but not for those 
starting with an international character in UTF-8 which will become the 
default encoding in the future.

The following code should work better with international characters both in 
UTF-8 or not, with PmWiki version 2.2.34 or newer:

  $FmtPV['$Name1'] = 
   'function_exists("utf8string") ? utf8string($name, 0, 1) : $name{0}';

The same applies to the $Group1 variable in the documentation.

>    $UploadPrefixFmt = '/$Group/$Name1';

With this setting, the Attach:file.ext will only display files uploaded to 
pages starting with the same letter. For files uploaded to other pages, you'll 
need to use Attach:Group.OtherPage/file.ext.

> allows to store pages and file uploads un sub-subfolders, the way I
> previously described.
> My impression is positive, but...
> Would it be a safe move? Would there be more issues to take care of?
> Would, in other words, all work fine as usual, and would the wiki
> handle things smooth, or some problem may arise which can be foreseen,
> please?

If you change the $WikiDir variable like you did above, for an existing wiki 
with pages, some existing pages may become invisible. You'll need to either 
move the files from wiki.d into the new subdirectories, or have a special 
setting for the $WikiLibDirs array, which would include all your previous 

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

  $WikiLibDirs = array( &$WikiDir,
    new PageStore('wiki.d/{$Group}/{$FullName}'),   # previous per-group subd.
    new PageStore('wiki.d/{$FullName}'),            # default PmWiki per-site
    new PageStore('$FarmD/wikilib.d/{$FullName}')); # default documentation

(Don't include a line if you don't have files in that directory.)

Again, this code should be placed early in config.php, before AuthUser and 
before calls to XLPage() or any other core function dealing with files 
(RetrieveAuthPage, ReadPage, PageVar, PageTextVar, CondAuth, probably others).

When you edit an existing page, it will be copied with its full history to the 
new per-letter subdirectory. Just note that you can normally delete pages only 
from the $WikiDir directory, that is the latest setting. In order to delete a 
page from the other directories, do it via FTP or SSH.

May I also add that this is a unique and complex setting which was not really 
tested. Some errors may appear, with pmwiki or with recipes, and it may be 
difficult to find help. As others suggested, I'd probably prefer to move to a 
better hosting provider rather than use such contortions.

Also, a future upgrade to UTF-8 of a wiki with wiki.d subdirectories will be 
more complex than what I thought.


More information about the pmwiki-users mailing list