Log Message
Fixup whitespace
Enable email sending
Log:
Submitted by:
Reviewed by:
PR:
Modified Files
AxKit-XSP-Wiki/lib/AxKit/XSP
Index: Wiki.pm
===================================================================
RCS file: /home/cvs/AxKit-XSP-Wiki/lib/AxKit/XSP/Wiki.pm,v
retrieving revision 1.20
retrieving revision 1.21
diff -Llib/AxKit/XSP/Wiki.pm -Llib/AxKit/XSP/Wiki.pm -u -d -r1.20 -r1.21
--- lib/AxKit/XSP/Wiki.pm
+++ lib/AxKit/XSP/Wiki.pm
@@ -2,9 +2,11 @@
use strict;
-use Apache::AxKit::Language::XSP::TaglibHelper;
+#use Apache::AxKit::Language::XSP::TaglibHelper;
use AxKit::XSP::Wiki::Indexer;
-use vars qw($VERSION $NS @ISA @EXPORT_TAGLIB);
+use Net::SMTP;
+use POSIX qw(strftime);
+use vars qw($VERSION $NS @ISA @EXPORT_TAGLIB $EmailAlerts $EmailHost);
$VERSION = '0.06';
@@ -33,10 +35,10 @@
);
eval {
- $db->do('select * from Page, Formatter, History where 1 = 2');
+ $db->do('select * from Page, Formatter, History where 1 = 2');
};
if ($@) {
- create_db($db);
+ create_db($db);
}
return $db;
@@ -48,16 +50,16 @@
my $db = _mkdb($dbpath, $dbname);
if ($action eq 'edit') {
- return edit_page($db, $page);
+ return edit_page($db, $page);
}
elsif ($action eq 'history') {
- return show_history($db, $page);
+ return show_history($db, $page);
}
elsif ($action eq 'historypage') {
- return show_history_page($db, $page, $id);
+ return show_history_page($db, $page, $id);
}
if ($action eq 'view') {
- return view_page($db, $page);
+ return view_page($db, $page);
}
else {
warn("Unrecognised action. Falling back to 'view'");
@@ -140,23 +142,23 @@
my $output = '';
my $handler = XML::SAX::Writer->new(Output => \$output);
while ( my $row = $sth->fetch ) {
- # create the parser
- my $parser = $row->[1]->new(Handler => $handler);
- eval {
- $parser->parse_string($row->[0]);
- };
- if ($@) {
- $output = '<pod>
+ # create the parser
+ my $parser = $row->[1]->new(Handler => $handler);
+ eval {
+ $parser->parse_string($row->[0]);
+ };
+ if ($@) {
+ $output = '<pod>
<para>
Error parsing the page: ' . xml_escape($@) . '
</para>
</pod>
';
- }
- last;
+ }
+ last;
}
if (!$output) {
- $output = <<'EOT';
+ $output = <<'EOT';
<newpage/>
EOT
}
@@ -195,10 +197,10 @@
my $output = '<edit><text>';
my $formatter = get_default_formatter($db);
while ( my $row = $sth->fetch ) {
- # create the parser
- $output .= xml_escape($row->[0]);
- $formatter = $row->[1];
- last;
+ # create the parser
+ $output .= xml_escape($row->[0]);
+ $formatter = $row->[1];
+ last;
}
$sth->finish;
@@ -210,9 +212,9 @@
EOT
$sth->execute();
while (my $row = $sth->fetch) {
- $output .= '<texttype id="'. xml_escape($row->[0]) .
- ($formatter == $row->[0] ? '" selected="selected">' : '">') .
- xml_escape($row->[1]) . '</texttype>';
+ $output .= '<texttype id="'. xml_escape($row->[0]) .
+ ($formatter == $row->[0] ? '" selected="selected">' : '">') .
+ xml_escape($row->[1]) . '</texttype>';
}
$sth->finish;
@@ -321,28 +323,49 @@
# turn into arrayrefs
foreach ( qw( normal required excluded phrase ) )
{
- if ( $search{$_} )
- {
- $search{$_} = [ keys %{ $search{$_} } ]
- }
- else
- {
- $search{$_} = [];
- }
+ if ( $search{$_} )
+ {
+ $search{$_} = [ keys %{ $search{$_} } ]
+ }
+ else
+ {
+ $search{$_} = [];
+ }
}
return %search;
}
sub save_page {
- my ($dbpath, $dbname, $page, $contents, $texttype, $ip, $rss) = @_;
- $rss = [$rss, _mkrssheader($dbname)];
+ my ($dbpath, $dbname, $page, $contents, $texttype, $ip) = @_;
my $db = _mkdb($dbpath, $dbname);
- _save_page($db, $page, $contents, $texttype, $ip, $rss);
+ _save_page($db, $page, $contents, $texttype, $ip);
+ if ($EmailAlerts) {
+ my $host = $EmailHost || 'localhost';
+ my $smtp = Net::SMTP->new($host, Timeout => 10);
+ $smtp->mail('axkitwiki') || die "Wiki email alerts: MAIL
FROM:<axkitwiki> failed";
+ $smtp->to($EmailAlerts) || die "Wiki email alerts: RCPT
TO:<$EmailAlerts> failed";
+ $smtp->data() || die "Wiki email alerts: DATA failed";
+ my $date = strftime('%a, %d %b %Y %H:%M:%S %Z', localtime);
+
+ $smtp->datasend(<<"EOT");
+To: $EmailAlerts
+From: "AxKit Wiki" <axkitwiki>
+Subject: New Wiki Content at $page
+Date: $date
+
+Wiki content at $page:
+
+$contents
+
+EOT
+ $smtp->dataend();
+ $smtp->quit();
+ }
}
sub _save_page {
- my ($db, $page, $contents, $texttype, $ip, $rss) = @_;
+ my ($db, $page, $contents, $texttype, $ip) = @_;
# NB fix hard coded formatterid
my $last_modified = time;
local $db->{AutoCommit} = 0;
@@ -353,27 +376,6 @@
$db->do('INSERT INTO History (name, formatterid, content, modified,
ip_address)
VALUES (?, ?, ?, ?, ?)', {}, @row);
}
- else {
- # New page
- if ($rss->[0]) {
- use Fatal qw(open close);
- open(RSS, ">$rss->[0]");
- flock(RSS, 2); # lock ex
- print RSS $rss->[1];
- my $sth = $db->prepare('SELECT * FROM Page ORDER BY last_modified
DESC');
- $sth->execute;
- while (my $row = $sth->fetch) {
- print RSS <<"EOT";
-<item>
-<title>$row->[1]</title>
-</item>
-EOT
- }
- print RSS "</rdf:RDF>\n";
- flock(RSS, 8); # unlock
- close(RSS);
- }
- }
my $sth = $db->prepare(<<'EOT');
INSERT OR REPLACE INTO Page ( name, formatterid, content, last_modified,
ip_address )
VALUES ( ?, ?, ?, ?, ? )
@@ -396,48 +398,34 @@
my $output = '';
while ( my $row = $sth->fetch ) {
my $handler = AxKit::XSP::Wiki::Indexer->new(DB => $db, PageId =>
$row->[0]);
- # create the parser
- my $parser = $row->[2]->new(Handler => $handler);
- eval {
- $parser->parse_string($row->[1]);
- };
- if ($@) {
+ # create the parser
+ my $parser = $row->[2]->new(Handler => $handler);
+ eval {
+ $parser->parse_string($row->[1]);
+ };
+ if ($@) {
warn("Indexing failed");
- }
- last;
+ }
+ last;
}
}
-sub _mkrssheader {
- my ($dbname) = @_;
- return <<"EOT";
-<rdf:RDF
- xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
- xmlns:dc="http://purl.org/dc/elements/1.1/"
- xmlns="http://purl.org/rss/1.0/"
->
-
- <channel rdf:about="http://take23.org/view/$dbname">
- <title>$dbname</title>
- <link>http://take23.org/view/$dbname</link>
- <description>
- Take23 $dbname
- </description>
-
-EOT
-}
-
sub show_history {
my ($db, $page) = @_;
- my $sth = $db->prepare('SELECT * FROM History WHERE name = ? ORDER BY
modified DESC');
+ my $sth = $page ? $db->prepare('SELECT * FROM History WHERE name = ? ORDER
BY modified DESC LIMIT 50') :
+ $db->prepare('SELECT * FROM History ORDER BY modified
DESC LIMIT 50');
$sth->execute($page);
my $hist = '<history>';
+ my %h;
+ my $cols = $sth->{NAME_lc};
while (my $row = $sth->fetch) {
+ @[EMAIL PROTECTED] = @$row;
$hist .= '<entry>';
- $hist .= '<id>' . xml_escape($row->[0]) . '</id>';
- $hist .= '<modified>' . xml_escape(scalar gmtime($row->[4])) .
'</modified>';
- $hist .= '<ip-address>' . xml_escape($row->[5]) . '</ip-address>';
- $hist .= '<bytes>' . xml_escape(length($row->[3])) . '</bytes>';
+ $hist .= '<page>' . xml_escape($h{name}) . '</page>';
+ $hist .= '<id>' . xml_escape($h{id}) . '</id>';
+ $hist .= '<modified>' . xml_escape(scalar gmtime($h{modified})) .
'</modified>';
+ $hist .= '<ip-address>' . xml_escape($h{ip_address}) . '</ip-address>';
+ $hist .= '<bytes>' . xml_escape(length($h{content})) . '</bytes>';
$hist .= '</entry>';
}
$hist .= '</history>';
@@ -461,23 +449,23 @@
my ($ip, $modified);
while ( my $row = $sth->fetch ) {
($ip, $modified) = ($row->[2], scalar(gmtime($row->[3])));
- # create the parser
- my $parser = $row->[1]->new(Handler => $handler);
- eval {
- $parser->parse_string($row->[0]);
- };
- if ($@) {
- $output = '<pod>
+ # create the parser
+ my $parser = $row->[1]->new(Handler => $handler);
+ eval {
+ $parser->parse_string($row->[0]);
+ };
+ if ($@) {
+ $output = '<pod>
<para>
Error parsing the page: ' . xml_escape($@) . '
</para>
</pod>
';
- }
- last;
+ }
+ last;
}
if (!$output) {
- $output = <<'EOT';
+ $output = <<'EOT';
<pod>
<para>
Unable to find that history page, or unable to find formatter module
@@ -509,18 +497,18 @@
my ($db) = @_;
$db->do(q{
- create table Page (
- id INTEGER PRIMARY KEY,
- name NOT NULL,
- formatterid NOT NULL,
- content,
- last_modified,
+ create table Page (
+ id INTEGER PRIMARY KEY,
+ name NOT NULL,
+ formatterid NOT NULL,
+ content,
+ last_modified,
ip_address
- )
+ )
});
$db->do(q{
- create unique index Page_name on Page ( name )
- });
+ create unique index Page_name on Page ( name )
+ });
$db->do(q{
create table History (
id INTEGER PRIMARY KEY,
@@ -559,17 +547,17 @@
create unique index ContentIndex_idx on ContentIndex (page_id, word_id)
});
$db->do(q{
- create table Formatter ( id INTEGER PRIMARY KEY, module NOT NULL, name
NOT NULL)
- });
+ create table Formatter ( id INTEGER PRIMARY KEY, module NOT NULL, name
NOT NULL)
+ });
$db->do(q{
- insert into Formatter (module, name) values ('Pod::SAX', 'pod - plain
old documentation')
- });
+ insert into Formatter (module, name) values ('Pod::SAX', 'pod - plain
old documentation')
+ });
$db->do(q{
- insert into Formatter (module, name) values ('Text::WikiFormat::SAX',
'wiki text')
- });
+ insert into Formatter (module, name) values ('Text::WikiFormat::SAX',
'wiki text')
+ });
$db->do(q{
- insert into Formatter (module, name) values
('XML::LibXML::SAX::Parser', 'xml (freeform)')
- });
+ insert into Formatter (module, name) values
('XML::LibXML::SAX::Parser', 'xml (freeform)')
+ });
$db->commit;
}