App-phoebe
view release on metacpan or search on metacpan
lib/App/Phoebe/Oddmuse.pm view on Meta::CPAN
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <https://www.gnu.org/licenses/>.
=encoding utf8
=head1 NAME
App::Phoebe::Oddmuse - act as a Gemini proxy for an Oddmuse wiki
=head1 DESCRIPTION
This extension allows you to serve files from an Oddmuse wiki instead of a real
Phoebe wiki directory.
The tricky part is that most Oddmuse wikis don't use Gemini markup (âgemtextâ)
and therefore care is required. The extension tries to transmogrify typical
Oddmuse markup (based on my own wikis) to Gemini.
Here's one way to configure it. I use Apache as my proxy server and have
multiple Oddmuse wikis running on the same machine, each only serving
C<localhost>. I need to recreate some of the Apache configuration, here.
package App::Phoebe::Oddmuse;
our %oddmuse_wikis = (
"alexschroeder.ch" => "http://localhost:4023/wiki",
"communitywiki.org" => "http://localhost:4019/wiki",
"emacswiki.org" => "http://localhost:4002/wiki",
"campaignwiki.org" => "http://localhost:4004/wiki", );
our %oddmuse_wiki_names = (
"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);
use Mojo::UserAgent;
use Modern::Perl;
use MIME::Base64;
use URI::Escape;
use List::Util qw(uniq);
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" );
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;
( run in 0.700 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )