/[pub]/suikawiki/script/misc/plugins/link/map.wp2
Suika

Diff of /suikawiki/script/misc/plugins/link/map.wp2

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.9 by wakaba, Sat Mar 13 13:43:33 2004 UTC revision 1.12 by wakaba, Thu Apr 1 04:39:58 2004 UTC
# Line 16  Plugin: Line 16  Plugin:
16    @Date.RCS:    @Date.RCS:
17       $Date$       $Date$
18    @RequiredPlugin[list]:    @RequiredPlugin[list]:
19        Search
20      WikiLinking      WikiLinking
21        WikiNamespace
22    @Use:    @Use:
23      use Message::Util::Error;      use Message::Util::Error;
24      my $WIKILINKING;      my $WIKILINKING;
# Line 63  FormattingRule: Line 65  FormattingRule:
65      $list->set_attribute (class => 'm--recent-changes');      $list->set_attribute (class => 'm--recent-changes');
66            
67      __ATTRTEXT:%ns__;__ATTRTEXT:%recursive__;      __ATTRTEXT:%ns__;__ATTRTEXT:%recursive__;
     __ATTRTEXT:%n__;  
68      $p->{recursive} = 1 unless length $p->{recursive};      $p->{recursive} = 1 unless length $p->{recursive};
69      my $ns = $o->{wiki}->name ($p->{ns});      my $ns = $o->{wiki}->name ($p->{ns});
70      #$ns->append_component ('') unless $ns->[$#$ns] eq '';  
71      my $i = 0;      my @target = map  { try { [$_, $o->{wiki}->{db}->get (lastmodified => $_)] }
72      $p->{n} ||= 10;                          catch SuikaWiki::DB::Util::Error with {
73                              my $err = shift;
74                              $err->throw if $err->{-type} eq 'ERROR_REPORTED';
75                              [$_, undef]} }
76             $o->{wiki}->{db}->keys ('lastmodified',
77                                     -ns => $ns,
78                                     -type => 'key',
79                                     -recursive => $p->{recursive});
80        try {
81          my $nsmodified = $o->{wiki}->{db}->get (lastmodified => $ns);
82          push @target, [$ns, $nsmodified] if $nsmodified;
83        } catch SuikaWiki::DB::Util::Error with {
84          my $err = shift;
85          $err->throw if $err->{-type} eq 'ERROR_REPORTED';
86        };
87        @target = sort {$b->[1] <=> $a->[1]} @target;
88    
89        __ATTRTEXT:%start__;
90        __ATTRTEXT:%n__;
91        my $start = length $p->{start} ? $p->{start} :
92                    $o->{wiki}->{input}->parameter ('m--change--range-start') || 0;
93        $p->{n} = $o->{wiki}->{input}->parameter ('m--change--range-number')
94                     unless length $p->{n};
95        my $end = $p->{n} ? $start + $p->{n} - 1 : $start + 29;
96        $start = 0 if $start > $#target or $start < 0;
97        $end = $#target if $end < $start or $end > $#target;
98        $end = $start + 255 if $end > $start + 255;
99        local $o->{var}->{search__result} = {
100          min => 0,
101          max => $#target,
102          start => $start,
103          end => $end,
104          number => $p->{n} || 30,
105          query => $p->{query},
106          param_prefix => 'm--change',
107        };
108    
109      __ATTRTEXT:%template__;      __ATTRTEXT:%template__;
110      $p->{template} ||= $WIKIRESOURCE->get      $p->{template} ||= $WIKIRESOURCE->get
111          (name => 'Link:toWikiPage:SourceLabelLong:RecentChangeItem',          (name => 'Link:toWikiPage:SourceLabelLong:RecentChangeItem',
112           wiki => $o->{wiki}, o => $o);           wiki => $o->{wiki}, o => $o);
113      __ATTRTEXT:%mode__;      __ATTRTEXT:%mode__;
114      for (sort {$b->[1] <=> $a->[1]}  
115           map  { try { [$_, $o->{wiki}->{db}->get (lastmodified => $_)] }      for my $target (@target[$start..$end]) {
                 catch SuikaWiki::DB::Util::Error with {  
                   my $err = shift;  
                   $err->throw if $err->{-type} eq 'ERROR_REPORTED';  
                   [$_, undef]} }  
          $o->{wiki}->{db}->keys ('content',  
                                  -ns => $ns,  
                                  -type => 'key',  
                                  -recursive => $p->{recursive})) {  
       next unless $_->[0];  
       last if $i++ == $p->{n};  
         
116        $WIKILINKING->to_wikipage_in_html ({        $WIKILINKING->to_wikipage_in_html ({
117          label => $p->{template},          label => $p->{template},
118        } => {        } => {
119          base => $o->{wiki}->{var}->{page},          base => $o->{wiki}->{var}->{page},
120          page_name_relative => $o->{wiki}->name ($_->[0]),          page_name_relative => $o->{wiki}->name ($target->[0]),
121          wiki_mode => $p->{mode},          wiki_mode => $p->{mode},
122          _with_lm => 1,          _with_lm => 1,
123          page_lastmodified => $_->[1],          page_lastmodified => $target->[1],
124        }, {        }, {
125          o => $o,          o => $o,
126          parent => $list->append_new_node          parent => $list->append_new_node
# Line 104  FormattingRule: Line 130  FormattingRule:
130        });        });
131      }      }
132    
133        if ($list->count) {
134          $list->set_attribute (start => $start + 1);
135          __ATTRNODE:%post_list->{$p->{-parent}}__;
136        } else {
137          $p->{-parent}->remove_child_node ($list);
138        }
139    
140    ViewDefinition:
141      @Mode: m--change
142      @Condition:
143        @@http-method[list]:
144          GET
145          HEAD
146          POST
147      @Description:
148        @@@: Show recently changed WikiPages list
149        @@lang: en
150      @template:
151        @@http-status-code: 200
152        @@media-type: text/html
153        @@use-media-type-charset: 1
154        @@expires: %%list%%
155        @@body:
156            %html-document (
157              title => {%res (name => {Map:Change:WebPageTitle});}p,
158              link-meta => {%template (name => links);}p,
159              content => {
160                %block (
161                  id => tools1, class => tools,
162                  content => {%template (name => navbar);}p,
163                );
164                %section (
165                  title => {%res (name => {Map:Change:Title});}p,
166                  heading,
167                  id => WEBPAGE--M--CHANGE,
168                  content => {%recent-change-list (
169                    n => 50,
170                    ns => {%page-name;}p,
171                    post-list => {%search--result-navigation (
172                      fragment => WEBPAGE--M--CHANGE,
173                    );}p,
174                  );}p,
175                );
176                %block (
177                  id => footer,
178                  content => {%template (name => ws--footer);}p,
179                );
180              }p,
181            );
182    
183    
184  FormattingRule:  FormattingRule:
185    @Category[list]:    @Category[list]:
186      form-input      form-input
# Line 128  FormattingRule: Line 205  FormattingRule:
205                                   local_name => 'ul');                                   local_name => 'ul');
206            
207      __ATTRTEXT:%ns__;__ATTRTEXT:%recursive__;      __ATTRTEXT:%ns__;__ATTRTEXT:%recursive__;
     __ATTRTEXT:%n__;  
208      $p->{recursive} = 1 unless length $p->{recursive};      $p->{recursive} = 1 unless length $p->{recursive};
209      my $ns = $o->{wiki}->name ($p->{ns});      my $ns = $o->{wiki}->name ($p->{ns});
210      #$ns->append_component ('') unless $ns->[$#$ns] eq '';  
211      my $i = 0;      my @target = sort {$a->[1] cmp $b->[1]}
212      $p->{n} ||= -1;             map {[$_, join "\t", @{$_}]} # make sort key
213               $o->{wiki}->{db}->keys ('content',
214                                       -ns => $ns,
215                                       -type => 'key',
216                                       -recursive => $p->{recursive});
217    
218        __ATTRTEXT:%start__;
219        __ATTRTEXT:%n__;
220        my $start = length $p->{start} ? $p->{start} :
221                    $o->{wiki}->{input}->parameter ('m--list--range-start') || 0;
222        $p->{n} = $o->{wiki}->{input}->parameter ('m--list--range-number')
223                     unless length $p->{n};
224        my $end = $p->{n} ? $start + $p->{n} - 1 : $start + 29;
225        $start = 0 if $start > $#target or $start < 0;
226        $end = $#target if $end < $start or $end > $#target;
227        $end = $start + 255 if $end > $start + 255;
228        local $o->{var}->{search__result} = {
229          min => 0,
230          max => $#target,
231          start => $start,
232          end => $end,
233          number => $p->{n} || 30,
234          query => $p->{query},
235          param_prefix => 'm--list',
236        };
237    
238      __ATTRTEXT:%template__;      __ATTRTEXT:%template__;
239      $p->{template} ||= $WIKIRESOURCE->get      $p->{template} ||= $WIKIRESOURCE->get
240          (name => 'Link:toWikiPage:SourceLabelLong:PageList',          (name => 'Link:toWikiPage:SourceLabelLong:PageList',
241           wiki => $o->{wiki}, o => $o);           wiki => $o->{wiki}, o => $o);
242      __ATTRTEXT:%match__; ## WARNING: This parameter might be dangerous!  
     my $reg = $p->{match} ? qr/$p->{match}/ : qr/./;  
243      __ATTRTEXT:%mode__;      __ATTRTEXT:%mode__;
244      try {      try {
245        for (sort {$a->[1] cmp $b->[1]}        for (@target[$start..$end]) {
            grep {$_->[1] =~ /$reg/}  
            map {[$_, join '//', @{$_}]} # make sort key  
            $o->{wiki}->{db}->keys ('content',  
                                    -ns => $ns,  
                                    -type => 'key',  
                                    -recursive => $p->{recursive})) {  
         last if $i++ == $p->{n};  
           
246          $WIKILINKING->to_wikipage_in_html ({          $WIKILINKING->to_wikipage_in_html ({
247            label => $p->{template},            label => $p->{template},
248          } => {          } => {
# Line 169  FormattingRule: Line 261  FormattingRule:
261        my $err = shift;        my $err = shift;
262        $err->throw if $err->{-type} eq 'ERROR_REPORTED';        $err->throw if $err->{-type} eq 'ERROR_REPORTED';
263      };      };
     $p->{-parent}->remove_child_node ($list) unless $list->count;  
264    
265  FormattingRule:      if ($list->count) {
266    @Category[list]:        $list->set_attribute (start => $start + 1);
267      form-input        __ATTRNODE:%post_list->{$p->{-parent}}__;
     view  
     view-resource  
   @Name: search-result  
   @Formatting:  
     __ATTRTEXT:%key__;  
     $p->{key} ||= $o->{wiki}->{var}->{page}->stringify (wiki => $o->{wiki});  
     __ATTRTEXT:%case_sensible__;  
     my $word = $p->{case_sensible} ? $p->{key} : lc $p->{key};  
     my @r;  
     my $sr = $o->{wiki}->{db}->get (m__search_result => [$word]);  
     unless ($sr) {  
       for my $page ($o->{wiki}->{db}->keys ('content')) {  
         my $content;  
         try {  
           $content = $o->{wiki}->{db}->get (content => $page);  
         } catch SuikaWiki::DB::Util::Error with {  
           my $err = shift;  
           $err->throw if $err->{-type} eq 'ERROR_REPORTED';  
           $content = undef;  
         };  
         $content = $p->{case_sensitive} ? $content : lc $content;  
         $content =~ s/^[^\x0A\x0D]+[\x0D\x0A]+//s;  
         $page = $o->{wiki}->name ($page);  
         my $n_page = $page->stringify (wiki => $o->{wiki});  
         $n_page = lc $n_page unless $p->{case_sensible};  
         if (index ($n_page, $word) > -1) {  
                my $c = $content =~ s/\Q$word\E//g;  
                 push @r, [$page, $c+20];  
               } elsif (index ($word, $n_page) > -1) {  
                 my $c = $content =~ s/\Q$word\E//g;  
                 push @r, [$page, $c+10];  
               } elsif (my $c = $content =~ s/\Q$word\E//g) {  
                 push @r, [$page, $c];  
               }  
       }  
       @r = sort {$b->[1] <=> $a->[1] || $a->[0] cmp $b->[0]} @r;  
       $sr = join "\x1E",  
             map {$_->[0]->stringify (wiki => $o->{wiki}, delimiter => "\x1D")  
                  ."\x1F".$_->[1]} @r;  
       $o->{wiki}->{db}->set (m__search_result => [$word] => $sr);  
 ## TODO: Cache & case-sensitivility  
268      } else {      } else {
269        @r = map {[$o->{wiki}->name ($_->[0], delimiter_reg => qr/\x1D/), $_->[1]]}        $p->{-parent}->remove_child_node ($list);
            map {[split /\x1F/, $_, 2]} split /\x1E/, $sr;  
270      }      }
271        return unless @r;  
       my $list = $p->{-parent}->append_new_node  
                                 (type => '#element',  
                                  namespace_uri => $NS_XHTML1,  
                                  local_name => 'ol');  
       __ATTRTEXT:%template__;  
       $p->{template} ||= $WIKIRESOURCE->get  
           (name => 'Link:toWikiPage:SourceLabelLong:SearchResult',  
            wiki => $o->{wiki}, o => $o);  
       for (@r) {  
         $WIKILINKING->to_wikipage_in_html ({  
           label => $p->{template},  
         } => {  
           base => $o->{wiki}->{var}->{page},  
           page_name_relative => $_->[0],  
           wiki_mode => $p->{mode},  
         }, {  
           o => $o,  
           parent => $list->append_new_node  
                           (type => '#element',  
                            namespace_uri => $NS_XHTML1,  
                            local_name => 'li'),  
           -m__weight => $_->[1],  
         });  
       }  
272    
273  FormattingRule:  FormattingRule:
274    @Category[list]:    @Category[list]:
# Line 266  ViewFragment: Line 291  ViewFragment:
291                       ns       => {%page-name;}p, recursive => 0,                       ns       => {%page-name;}p, recursive => 0,
292                       type     => both,                       type     => both,
293                       template => {%resource-as-plain-text (name => {Children:Item});}p,                       template => {%resource-as-plain-text (name => {Children:Item});}p,
294                         post-list => {%search--result-navigation (
295                           fragment => children,
296                         );}p,
297                     );}p,                     );}p,
298      );      );
299          %section (  
300            id => see-also,  ViewFragment:
301            title => {%res(name=>SeeAlso);}p, heading,    @Name: navbar
302            content => {%search-result;}p,    @Order: 21
303          );    @Formatting:
304        %link-to-wikipage (
305          page => {%ns--root-wikiname;}p,
306          mode => m--change,
307          label => {%link-to-it (
308            label => {%res (name => GoToRecentChanges);}p,
309            description => {%res (name => GoToRecentChangesLong);}p,
310          );},
311          rel => news,
312        );
313    
314    ViewFragment:
315      @Name: links
316      @Formatting:
317        %link-to-wikipage (
318          page => {%ns--root-wikiname;}p,
319          rel => news,
320          mode => m--change,
321          label => {%html-link (
322                      description => {%res(name=>GoToRecentChangesLink);}p,
323                    );},
324        );
325        %link-to-wikipage (
326          page => {%ns-page-path-name;}p,
327          rel => news,
328          mode => m--change,
329          label => {%html-link (
330            description => {%res(name=> {Map:Change:Link:Parent:Description});}p,
331          );},
332        );
333        %link-to-wikipage (
334          rel => news,
335          mode => m--change,
336          label => {%html-link (
337            description => {%res(name=> {Map:Change:Link:Local:Description});}p,
338          );},
339        );
340    
341  Resource:  Resource:
342    @Children:Title:    @Children:Title:
# Line 300  Resource: Line 364  Resource:
364        description=>{%page-name(absolute);}p,        description=>{%page-name(absolute);}p,
365      );      );
366      %span(class=>headline,content=>{%page-headline;}p);      %span(class=>headline,content=>{%page-headline;}p);
   
 ## TODO: Make recent-changes page name customizable  
 ViewFragment:  
   @Name: navbar  
   @Order: 21  
   @Formatting:  
     %link-to-wikipage (  
       page => {RecentChanges},  
       label => {%link-to-it (  
         label => {%res (name => GoToRecentChanges);}p,  
         description => {%res (name => GoToRecentChangesLong);}p,  
       );},  
       rel => news,  
     );  
   
 ## TODO:  
 ViewFragment:  
   @Name: links  
   @Formatting:  
     %link-to-wikipage (  
       page => {RecentChanges},  
       rel => news,  
       label => {%html-link (  
                   description => {%res(name=>GoToRecentChangesLink);}p,  
                 );},  
     );  
   
 Resource:  
367    @GoToRecentChanges:    @GoToRecentChanges:
368      @@@: Recent      @@@: Recent
369      @@lang: en      @@lang: en
# Line 337  Resource: Line 373  Resource:
373    @GoToRecentChangesLong:    @GoToRecentChangesLong:
374      @@@: Review recently modified WikiPages list      @@@: Review recently modified WikiPages list
375      @@lang: en      @@lang: en
376      @Map:Change:Link:Local:Description:
377        @@@: List of recently modified WikiPages in this namespace (%page-name;)
378        @@lang: en
379      @Map:Change:Link:Parent:Description:
380        @@@:
381          List of recently modified WikiPages in parent namespace
382          (%ns-page-path-name;)
383        @@lang: en
384      @Map:Change:Title:
385        @@@: Recent Changes
386        @@lang: en
387      @Map:Change:WebPageTitle:
388        @@@: Recent Changes (%page-name;)
389        @@lang: en
390      
391    
392    

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.12

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24