[pmwiki-users] Pagelist default when there is no especific group

Petko Yotov 5ko at 5ko.fr
Wed Jan 31 03:27:36 CST 2018


On 30/01/2018 00:21, Carlos AB wrote:
> I'm using a nested wiki.d/{$Group}/{$FullName} pagestore on my wiki
> and I was trying to find ways to minimize the impact with pagelist
> when you have a wiki with a lot of pages.
> 
> The first thing I did to minimize impact, was to make sure the search
> form included a group option in every search with:
> 
> if($enableGroupSearchBox)
>   $SearchBoxOpt['group'] = PageVar($pagename, '$Group');

This line should be at the very bottom of config.php or in a $PostConfig 
function, see
   http://www.pmwiki.org/wiki/PmWiki/LocalCustomizations#configphp-order

Instead, you could simply use (:template default group={*$Group}:) in 
the pagelist template.


> I could not be sure how pagelist does the file list in both cases
> (nested, non-nested), to be certain that there is an improvement while
> using a nested wiki.d with pagelist.
> 
> I give in each "new PageStore", a method to access the files in
> wiki.d, but not certain if when I use a "group=" option inside
> pagelist, if it takes advantage of that by just listing and accessing
> the files inside the specified group in wiki.d and not all other
> nested groups inside wiki.d as well.

I assume when you say "nested" you mean the wiki.d directories (not a 
pagelist markup inside a pagelist template).

When you have different "PageStore" objects, PmWiki will scan them all 
when it needs the list of all pages (just the list of names, not any 
other information like titles or variables).

When PmWiki needs to open a file for reading, it will ask the PageStore 
objects one after another, in the order you have defined them in 
config.php, if they have MyGroup.MyPage. The first PageStore object that 
finds this page will return it and if there are more PageStores they 
will be not bothered.

When you define a PageStore object with variables like 
wiki.d/{$Group}/{$FullName} and then ask "is there a page 
MyGroup.MyPage", the PageStore only checks "is there a file 
wiki.d/MyGroup/MyGroup.MyPage" so it will only look in the 
wiki.d/MyGroup sub-directory, not in other subdirectories.

When you write a page, only the first PageStore object is used, that is 
usually $WikiDir. This way we can have documentation in wikilib.d but if 
you modify a page from the PmWiki or Site groups on your wiki, it will 
be saved in wiki.d and from now on only the file in wiki.d will be read 
and written.

> I also saw the code for the include markup and PageTextVars with the
> syntax to access variables in other pages, but looking at the code one
> can see the functions relative to each markup, that they open the new
> pages to access those variables using the nested method instantiated
> before for PageStore.

When you request pagevariables or pagetextvariables, or include portions 
of other pages, PmWiki needs to open their disk files for reading. But 
it only asks the minimal number of PageStore objects to check if they 
hold such a page.

The functions that do this in pmwiki.php are ReadPage, WritePage, 
PageExists and ListPages near or around line 1210.

So in your pagelists and from your wiki pages, you should never need to 
worry about files in wiki.d. BTW, a PageStore object could store pages 
not on the disk, but for example in a database, on a remote server, or 
in thin air (temporary session/RAM storage): you shouldn't worry about 
those too.

> I looked at the code because I had the wrong idea that I would have to
> catch each call to a new page with those markups and create a new
> PageStore for each.

This is not very clear. You shouldn't need to create wiki.d 
sub-directories: once you define one (not many) PageStore object with a 
directory defined as 'wiki.d/{$Group}/{$FullName}', it will work for all 
pages in all groups: it simply creates and deletes pages as needed, and 
it calculates the directory name and the filename from the {$Group} and 
{$FullName} variables.


> My other question would be why the initial behavior for pagelist is to
> list all pages in all groups according to the needle, instead of
> making it list just the pages inside the current group, if the option
> "group=" is not used. For searchresults, I believe the behavior is
> correct.

Both pagelist and searchresults are searching for all groups unless 
either (there is a group=ThisGroup argument in the markup or in the 
search field), or (you have (:template default 
group=SomeGroup,{*$Group}:) in the pagelist template), or (there is a 
request=1 argument in the markup and there is somehow a 
$_REQUEST['group'] variable, eg from a search form or from the url), or 
(you set some $SearchPatterns['xy'] and list=xy), or (set a default 
$MakePageListOpt['group'] or $SearchBoxOpt['group']).

Why is that so: I assume when this was implemented it was considered the 
best -- I still think it is.

If one option is not used, then this option should not be predefined. If 
there is no needle show all pages; if group= is not used show all 
groups; if name= is not used show all names; if link= is not used show 
pages linking or not linking to anywhere; if count= is not used show all 
pages instead of a portion of them. (The only exception is the order= 
option which defaults to order=name because without it the results may 
be ordered inconsistently between page reloads, especially bad if you 
also use count=21..30.)

Here is what I use on a group-centered 5800-page wiki where I want 
people to first search in their current group and in "Main", then at the 
bottom there is a link to search in all groups. If they type in the 
search field "group=*" or "/" then the search will not be limited to 
Main and the current group:

# in config.php:

if($action == 'search') {
   $group = preg_replace('/[.\\/].*$/', '', $pagename);
   $MakePageListOpt['group'] = "$group,Main";

   $tmp = trim(stripmagic(@$_REQUEST['q']));
   $tmpp = ParseArgs($tmp);

   $Conditions['showsearchall'] = ($tmp>'' && $tmp{0}!='/' && 
@$tmpp['group']=='') ? 'true':'false';
   $FmtPV['$SearchAllPath'] = '"/+'.urlencode($tmp).'"';
}

# in Site.Search, below (:searchresults:):

(:if showsearchall:)
%note% You have searched in a few sections of the site. \
[[{$ScriptUrl}/{*$Group}/{*$Name}?action=search&q={$SearchAllPath} 
|Search through the whole site]].%%
(:if:)

That one could also be placed in the default pagelist template.

Petko



More information about the pmwiki-users mailing list