wiki.pl: Port some fixes from upstream
[Orgmuse.git] / wanted.pl
blobf7f9cf60358feb7288f33cedcb7d70c31a13631c
1 #!/usr/bin/perl
2 # Wanted Pages for Oddmuse Wikis
3 # Copyright (C) 2004 Alex Schroeder <alex@emacswiki.org>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the
17 # Free Software Foundation, Inc.
18 # 59 Temple Place, Suite 330
19 # Boston, MA 02111-1307 USA
21 use CGI qw/:standard/;
22 use CGI::Carp qw(fatalsToBrowser);
23 use LWP::UserAgent;
25 if (not param('url')) {
26 print header(),
27 start_html('Wanted Pages'),
28 h1('Wanted Pages'),
29 p('$Id: wanted.pl,v 1.3 2004/03/21 00:33:58 as Exp $'),
30 p('Returns a list of wanted pages based on a dot-file.'),
31 start_form(-method=>'GET'),
32 p('URL for dot-file: ', textfield('url'), br(),
33 'Example: http://www.emacswiki.org/cgi-bin/alex?action=links;raw=1'),
34 p('URL for list of nodes: ', textfield('nodes'), br(),
35 'Example: http://www.emacswiki.org/cgi-bin/alex?action=index;raw=1;near=1'),
36 p(submit()),
37 end_form(),
38 end_html();
39 exit;
42 print header(-type=>'text/plain; charset=UTF-8');
43 $ua = LWP::UserAgent->new;
44 $request = HTTP::Request->new('GET', param('url'));
45 $response = $ua->request($request);
46 $data = $response->content;
48 while ($data =~ m/"(.*?)" -> "(.*?)"/g) {
49 $page{$1} = 1;
50 $link{$2} = 1;
53 $request = HTTP::Request->new('GET', param('nodes'));
54 $response = $ua->request($request);
55 $data = $response->content;
57 foreach $pg (split(/\n/, $data)) {
58 $pg =~ s/_/ /g;
59 $page{$pg} = 1 if $pg;
62 foreach $link (sort keys %link) {
63 print $link, "\n" unless $page{$link};