This is the historical archive of the now-inactive 'grubstreet' list.
Discussion on OpenGuides development has now moved to OpenGuides-Dev. Discussion on The Open Guide to London now takes place on OpenGuides-London.

[grubstreet] Embedded indexes

[prev] [thread] [next] [lurker] [Date index for 2002/11/10]

From: Ivor Williams
Subject: [grubstreet] Embedded indexes
Date: 18:51 on 10 Nov 2002
----- Original Message -----
From: "Kate L Pugh" <kake@xxxxx.xx>
To: <grubstreet@xxxxxxx.xxxxx.xx>
Sent: 09 November 2002 13:55
Subject: Re: [grubstreet] Some thoughts from last night


> On Sat 09 Nov 2002, Ivor Williams <ivor.williams@xxxxxxx.xx.xx> wrote:
> > I've decided I want to completely rethink and revamp my index patch.
> >
> > I propose that the only way to get an index is to embed one in a
> > page. Also, the page containing the index will have full control of
> > how it is rendered.
>
> As just discussed on IRC:
>
> 13:50 <Kake> Ivor: I think that's too complicated.  How about just a macro
>       like the REDIRECT one - #INDEX [[Category Pubs]] - and leave the
>       display (number of levels etc) up to the admin to set in the config
>       section?
> 13:52 <ivorw> I'll think about that
> 13:52 <Kake> Do you want me to post that to the list?
> 13:52 <ivorw> Kake, yes please. That way I get a record of it
>
I now have something that will make an index where you put a #INDEX [[page]]. This is instead of the existing logic which had
special index pages. Now the only way to get one of my +indexes is to use #INDEX. The code is a lot cleaner too.

OK, I have a patch to usemod092, which REPLACES the existing wiki +index patch, i.e. take usemod092 from the distribution and apply
the patch. Please can someone put this on the wikibeta site http://the.earth.li/~kake/cgi-bin/wikibeta.pl - Thanks.

Ivor.

__PATCH FOLLOWS__
48c48
<   $UserGotoBar);
---
>   $UserGotoBar $IndexLevels);
86a87
> $IndexLevels = 3;
827c828
<   my ($id, $name) = @_;
---
>   my ($id, $name, $prefix) = @_;
850c851
<     return &GetPageLinkText($id, $name);
---
>     return &GetPageLinkText($id, $prefix.$name);
857c858
<   return $name . &GetEditLink($id,"?");
---
>   return $prefix . $name . &GetEditLink($id,"?");
1165a1167
>   $pageText =~ s/#INDEX\s+\[\[(.*)\]\]/&RenderIndex($1)/eg;
1205,1206c1207,1208
<       s/\[\[$FreeLinkPattern\|([^\]]+)\]\]/&StorePageOrEditLink($1, $2)/geo;
<       s/\[\[$FreeLinkPattern\]\]/&StorePageOrEditLink($1, "")/geo;
---
>       s/\[\[(\+)?$FreeLinkPattern\|([^\]]+)\]\]/&StorePageOrEditLink($2, $3, $1)/geo;
>       s/\[\[(\+)?$FreeLinkPattern\]\]/&StorePageOrEditLink($2, "", $1)/geo;
1441c1443
<   my ($page, $name) = @_;
---
>   my ($page, $name, $indexLink) = @_;
1450c1452
<   return &StoreRaw(&GetPageOrEditLink($page, $name));
---
>   return &StoreRaw(&GetPageOrEditLink($page, $name, $indexLink));
2915a2918,2932
> sub RenderIndex {
>   my $id = shift;
>   my $outstr = '';
>   my @PageList=&PageIndex(FreeToNormal($id));
>   foreach (@PageList) {
>     /(^|\+)([^+]+)$/;
>  my $pagename = $2;
>  my $depth = @{[/\+/g]};
>  next if !$depth or $depth > $IndexLevels;
>  $outstr .= '*' x $depth . "[[$pagename]]\n";
>   }
>   $outstr;
> }
>
>
3418a3436,3485
>
> sub IndexCrossRef {
>   my ($string,@pages) = @_;
>   my ($name, %found);
>   my (%appearsOn);
>
>   foreach $name (@pages) {
>     &OpenPage($name);
>     &OpenDefaultText();
>  my $txt = $Text{'text'};
>     my ($root) = ($name =~ m!^([^/]*)!);
>
>  $txt =~ s!<nowiki>.*?</nowiki>!!gs;
>  foreach my $refer ($txt =~ /\[\+(.+?)[|\]]/g) {
>   $refer = &FreeToNormal($refer);
>   $refer =~ s!^/!$root/!;
>   push @{$appearsOn{$refer}},$name;
>
>   $found{$name}++ if !$string
>     || $name eq $string
>     || $refer eq $string;
>  }
>   }
>   (\%appearsOn,\%found);
> }
>
> sub PageIndex {
>   my $string = shift;
>   my ($appears,$results) = &IndexCrossRef($string,&AllPagesList());
>   my $goAgain = 1;
>   while ($goAgain) {
>     $goAgain = 0;
>  foreach (my @k = keys %$results) {
>    my ($parent) = /([^+]+)$/;
>    foreach my $child (@{$appears->{$parent}}) {
>   next if /(^|\+)$child(\+|$)/;
>   next if $results->{$_.'+'.$child};
>   $results->{$_.'+'.$child} = 1;
>   $goAgain++;
>   }
>    }
>  }
>   foreach (my @k = keys %$results) {
>    while (/\+/g) {
>    delete $results->{$'};
>  }
>   }
>   sort keys %$results;
> }
>
3691c3758
<     } elsif (/^\=(?:\[\[)?([^]=]+)(?:\]\])?\=(?:\[\[)?([^]=]+)(?:\]\])?/) {
---
>     } elsif (/^\=(?:\[\[\+?)?([^]=]+)(?:\]\])?\=(?:\[\[)?([^]=]+)(?:\]\])?/) {
3693c3760
<     } elsif (/^\|(?:\[\[)?([^]|]+)(?:\]\])?\|(?:\[\[)?([^]|]+)(?:\]\])?/) {
---
>     } elsif (/^\|(?:\[\[\+?)?([^]|]+)(?:\]\])?\|(?:\[\[)?([^]|]+)(?:\]\])?/) {



-- 
grubstreet mailing list
http://london.openguides.org/old-list-archives/