App-Phoebe
view release on metacpan or search on metacpan
lib/App/Phoebe/Oddmuse.pm view on Meta::CPAN
"alexschroeder.ch" => "Alex Schroeder",
"communitywiki.org" => "Community Wiki",
"emacswiki.org" => "Emacs Wiki",
"campaignwiki.org" => "Campaign Wiki", );
our %oddmuse_wiki_dirs = (
"alexschroeder.ch" => "/home/alex/alexschroeder",
"communitywiki.org" => "/home/alex/communitywiki",
"emacswiki.org" => "/home/alex/emacswiki",
"campaignwiki.org" => "/home/alex/campaignwiki", );
our %oddmuse_wiki_links = (
"communitywiki.org" => 1,
"campaignwiki.org" => 1, );
use App::Phoebe::Oddmuse;
=cut
package App::Phoebe::Oddmuse;
use App::Phoebe qw(@request_handlers @extensions @main_menu $server $log $full_url_regex
success result reserved_regex port gemini_link modified changes diff
colourize quote_html bogus_hash print_link decode_query);
use Mojo::UserAgent;
use Modern::Perl;
use MIME::Base64;
use URI::Escape;
use List::Util qw(uniq);
use File::Slurper qw(read_dir read_text write_text);
use Encode qw(encode_utf8 decode_utf8);
use DateTime::Format::ISO8601;
use utf8; # the source contains UTF-8 encoded strings
no warnings 'redefine';
# Oddmuse Wiki
our %oddmuse_wikis = (
"alexschroeder.ch" => "http://localhost:4023/wiki",
"communitywiki.org" => "http://localhost:4019/wiki",
"emacswiki.org" => "http://localhost:4002/wiki" );
our %oddmuse_wiki_names = (
"alexschroeder.ch" => "Alex Schroeder",
"communitywiki.org" => "Community Wiki",
"emacswiki.org" => "Emacs Wiki" );
our %oddmuse_wiki_dirs = (
"alexschroeder.ch" => "/home/alex/alexschroeder",
"communitywiki.org" => "/home/alex/communitywiki",
"emacswiki.org" => "/home/alex/emacswiki" );
# The Oddmuse wiki uses WikiLinks
our %oddmuse_wiki_links = ("communitywiki.org" => 1);
# The Oddmuse wiki uses a different token as the answer to a security question
# (i.e. not the Phoebe server token). This only works if the Oddmuse wiki has
# just one security question (or accepts the same answer for all questions).
our %oddmuse_wiki_tokens = (
"emacswiki.org" => "emacs" );
# Also allow percent encodedâ¦
our $oddmuse_namespace_regex = '[\p{Uppercase}\d][%\w_ Â ]*';
*oddmuse_old_space_regex = \&App::Phoebe::space_regex;
*App::Phoebe::space_regex = \&oddmuse_new_space_regex;
sub oddmuse_new_space_regex {
my $spaces = oddmuse_old_space_regex();
return "$spaces|$oddmuse_namespace_regex" if $spaces;
return $oddmuse_namespace_regex;
}
*oddmuse_old_space = \&App::Phoebe::space;
*App::Phoebe::space = \&oddmuse_new_space;
sub oddmuse_new_space {
my $stream = shift;
my $host = shift;
my $space = shift;
if (grep { $_ eq $host } keys %oddmuse_wikis) {
# Let Oddmuse handle namespaces
return $space;
}
return oddmuse_old_space($stream, $host, $space);
}
*oddmuse_old_save_page = \&App::Phoebe::save_page;
*App::Phoebe::save_page = \&oddmuse_new_save_page;
sub oddmuse_new_save_page {
my $stream = shift;
my $host = shift;
my $space = shift;
my $id = shift;
my $type = shift;
my $data = shift;
my $length = shift;
my $port = port($stream);
if (not grep { $_ eq $host } keys %oddmuse_wikis) {
return oddmuse_old_save_page($stream, $host, $space, $id, $type, $data, $length);
}
if ($type ne "text/plain") {
$data = "#FILE $type\n" . encode_base64($data);
} elsif (not utf8::decode($data)) {
$log->debug("The text is invalid UTF-8");
result($stream, "59", "The text is invalid UTF-8");
$stream->close_gracefully();
return;
}
my @tokens = @{$server->{wiki_token}};
push(@tokens, $oddmuse_wiki_tokens{$host}) if $oddmuse_wiki_tokens{$host};
my $token = pop(@tokens); # the oddmuse wiki token, preferrably
my $name = ref($stream->handle) eq 'IO::Socket::SSL' && $stream->handle->peer_certificate('cn') || "";
my $ua = Mojo::UserAgent->new;
my $tx = $ua->post(
$oddmuse_wikis{$host}
=> {'X-Forwarded-For' => $stream->handle->peerhost}
=> form => {
title => $id,
text => $data,
ns => $space,
( run in 2.121 seconds using v1.01-cache-2.11-cpan-99c4e6809bf )