| 1 | # PurpleWiki::NidHandler.pm | ||
| 2 | # vi:ai:sw=4:ts=4:et:sm | ||
| 3 | # | ||
| 4 | # $Id: NidHandler.pm 465 2004-08-09 02:00:02Z cdent $ | ||
| 5 | # | ||
| 6 | # Copyright (c) Blue Oxen Associates 2002-2003. All rights reserved. | ||
| 7 | # | ||
| 8 | # This file is part of PurpleWiki. PurpleWiki is derived from: | ||
| 9 | # | ||
| 10 | # UseModWiki v0.92 (c) Clifford A. Adams 2000-2001 | ||
| 11 | # AtisWiki v0.3 (c) Markus Denker 1998 | ||
| 12 | # CVWiki CVS-patches (c) Peter Merel 1997 | ||
| 13 | # The Original WikiWikiWeb (c) Ward Cunningham | ||
| 14 | # | ||
| 15 | # PurpleWiki is free software; you can redistribute it and/or modify | ||
| 16 | # it under the terms of the GNU General Public License as published by | ||
| 17 | # the Free Software Foundation; either version 2 of the License, or | ||
| 18 | # (at your option) any later version. | ||
| 19 | # | ||
| 20 | # This program is distributed in the hope that it will be useful, | ||
| 21 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 22 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 23 | # GNU General Public License for more details. | ||
| 24 | # | ||
| 25 | # You should have received a copy of the GNU General Public License | ||
| 26 | # along with this program; if not, write to the | ||
| 27 | # Free Software Foundation, Inc. | ||
| 28 | # 59 Temple Place, Suite 330 | ||
| 29 | # Boston, MA 02111-1307 USA | ||
| 30 | |||
| 31 | package PurpleWiki::NidHandler; | ||
| 32 | |||
| 33 | use strict; | ||
| 34 | use PurpleWiki::Config; | ||
| 35 | use PurpleWiki::Sequence; | ||
| 36 | use CGI; | ||
| 37 | |||
| 38 | our $VERSION; | ||
| 39 | $VERSION = sprintf("%d", q$Id: NidHandler.pm 465 2004-08-09 02:00:02Z cdent $ =~ /\s(\d+)\s/); | ||
| 40 | |||
| 41 | my $purpleConfig = new PurpleWiki::Config($ENV{WIKIDB}); | ||
| 42 | |||
| 43 | sub handler { | ||
| 44 | my $r = shift; | ||
| 45 | my $pathInfo; | ||
| 46 | my $queryString = ''; | ||
| 47 | my $count; | ||
| 48 | my $url; | ||
| 49 | my $nid; | ||
| 50 | |||
| 51 | my $cgi = new CGI; | ||
| 52 | |||
| 53 | |||
| 54 | $r->print($cgi->header(-type => 'text/plain')); | ||
| 55 | |||
| 56 | $queryString = $cgi->query_string(); | ||
| 57 | $pathInfo = $cgi->path_info(); | ||
| 58 | $pathInfo =~ s/^\///; | ||
| 59 | ($count, $url) = split('/', $pathInfo, 2); | ||
| 60 | |||
| 61 | # put the double slash back in the url after the protocol | ||
| 62 | # FIXME: do encoding of the passed url? | ||
| 63 | $url =~ s/^(\w+:\/)(?!\/)/$1\//; | ||
| 64 | |||
| 65 | $queryString = '?' . $queryString if length($queryString); | ||
| 66 | |||
| 67 | if (!defined($url)) { | ||
| 68 | $nid = $count; | ||
| 69 | _getURL($r, $purpleConfig, $nid); | ||
| 70 | } else { | ||
| 71 | $count = 1 if (!length($count)); | ||
| 72 | _getNIDs($r, $purpleConfig, $count, "$url$queryString"); | ||
| 73 | } | ||
| 74 | |||
| 75 | # FIXME: need to be better disciplined in returning | ||
| 76 | return; | ||
| 77 | |||
| 78 | } | ||
| 79 | |||
| 80 | sub _getURL { | ||
| 81 | my $r = shift; | ||
| 82 | my $purpleConfig = shift; | ||
| 83 | my $nid = shift; | ||
| 84 | |||
| 85 | # never pass remote sequence here, or you just get a big mess | ||
| 86 | my $sequence = new PurpleWiki::Sequence($purpleConfig->DataDir()); | ||
| 87 | |||
| 88 | $r->print($sequence->getURL($nid)); | ||
| 89 | } | ||
| 90 | |||
| 91 | sub _getNIDs { | ||
| 92 | my $r = shift; | ||
| 93 | my $purpleConfig = shift; | ||
| 94 | my $count = shift; | ||
| 95 | my $url = shift; | ||
| 96 | |||
| 97 | my $sequence = new PurpleWiki::Sequence($purpleConfig->DataDir()); | ||
| 98 | |||
| 99 | while ($count-- > 0) { | ||
| 100 | $r->print($sequence->getNext($url), "\n"); | ||
| 101 | } | ||
| 102 | } | ||
| 103 | |||
| 104 | 1; | ||
| 105 | |||
| 106 | |||
| 107 | __END__ |