Apache-MiniWiki

 view release on metacpan or  search on metacpan

MiniWiki.pm  view on Meta::CPAN

use Carp;
use CGI qw(:cgi);
use Date::Manip;
use File::stat;
use HTML::Entities;
use HTML::FromText;
use HTML::LinkExtor;
use HTML::Template;
use Rcs 1.04;

our ($VERSION, $datadir, $vroot, $authen, $template, $timediff, @templates, $uploads, $precaching);

$VERSION = 0.92;

# Global variables:
# $datadir:       # Directory where we store Wiki pages (full path)
# $vroot:         # The virtual root we're using (eg /wiki)
# $authen:        # Set to filename when using basic authentification
# $template:      # HTML::Template object
# $timediff:      # delta from GMT, eg:  -8 for PST, +4.5 for IST
# @templates:     # list of templates to use for other entry pages

MiniWiki.pm  view on Meta::CPAN

  my $r = shift;

  # Load configuration directives.
  $datadir = $r->dir_config('datadir') or
      return fatal_error($r, "PerlVar datadir must be set.");
  $vroot = $r->dir_config('vroot') or
      return fatal_error($r, "PerlVar vroot must be set.");
  $authen = $r->dir_config('authen') || -1;
  $timediff = $r->dir_config('timediff') || -8;
  @templates = $r->dir_config->get('templates');
  $uploads = $r->dir_config('uploads') || 'yes';
  $precaching = $r->dir_config('precaching') || 'no';

  # First strip the virtual root from the URI
  my $uri = &strip_virtual($r->uri);

  # trailing / away
  $datadir =~ s/(\/)$//g;

  # Load the template for this Wiki
  $template = &get_template($r);

MiniWiki.pm  view on Meta::CPAN

  my ($r, $uri) = @_;
  my $fileuri = uri_to_filename($uri);
  
  if ($r->method() ne "POST") {
    return fatal_error($r, "Invalid save, POST required.");
  }

  my $q = new CGI;

  my $text;
  # is this an uploaded binary file? If so, shlurp the data from
  # the file handle provided by CGI.pm.
  if (my $fh = $q->upload('text')) {
    local undef $/;
    $text = <$fh>;
  } else {
    $text = $q->param('text');
    $text =~ s/\r//g;
  }

  if ($q->param("Save") =~ /preview/i) {
    return &edit_function($r, $uri, $text);
  }

MiniWiki.pm  view on Meta::CPAN

	my $fileuri = $datadir . "/" . uri_to_filename($uri);
	my $thumburi = $datadir . "/THUMB_" . uri_to_filename($uri);
	
	my $file_mtime = stat($fileuri)->mtime;
		
	my ($subtype) = &is_img($uri);
	#$r->send_http_header("image/$subtype");

	if (-f $thumburi && stat($thumburi)->mtime > $file_mtime) {
		# if the thumbnail is newer then the big image,
		# then obviously a new one hasn't been uploaded. 
		# Don't call ImageMagick to check the size.
		# Use the existing thumb.
		return send_file($r, $thumburi);
	}

	use Image::Magick;
	my $image = Image::Magick->new;

	my ($width, $height, $size, $format) = $image->Ping($fileuri);

MiniWiki.pm  view on Meta::CPAN

  my $uri = $r->uri;
  unless ($uri =~ /\((edit|save|revert)\)/) {
    $r->set_handlers(PerlAuthenHandler => [\&OK]);
    $r->set_handlers(PerlAuthzHandler => [\&OK])
      if grep { lc($_->{requirement}) ne 'valid-user' } @{$r->requires};
  }

  return OK;
}

## is the link a binary upload?
## are file uploads enabled?
sub is_binary {
  my $uri = shift;
  return 0 if $uploads =~ /^n/i;
  return ($uri =~ /\.(.+)$/ && grep /$1/i, @binfmts);
}

## is the link really an inline image?
## are file uploads enabled?
sub is_img {
  my $uri = shift;
  return 0 if $uploads =~ /^n/i;
  return ($uri =~ /\.(.+)$/ && grep /$1/i, @imgfmts);
}

1;

__END__

=head1 NAME

Apache::MiniWiki - Miniature Wiki for Apache

MiniWiki.pm  view on Meta::CPAN

=head1 DESCRIPTION

Apache::MiniWiki is a simplistic Wiki for Apache. It doesn't have 
much uses besides very simple installations where hardly any features
are needed. What is does support though is:

  - storage of Wiki pages in RCS
  - templates through HTML::Template
  - text to HTML conversion with HTML::FromText
  - basic authentication password changes
  - uploading of binary (pdf, doc, gz, zip, ps)
  - uploading of images (jpg, jpeg, gif, png)
  - automatic thumbnailing of large using ImageMagick
  - sub directories
  - view any revision of a page
  - revert back to any revision of the page
  - basic checks to keep search engine spiders from deleting 
    all the pages in the Wiki

=head1 DEPENDENCIES

This module requires these other modules:

MiniWiki.pm  view on Meta::CPAN

the default template for every page. Use the C<templates> variable to specify
more then one template:
  
  PerlAddVar templates fvlug linux

By doing this, pages that contain those words will use the matching template.
For example, the /your-wiki-vroot/LinuxDatabases page will then use the template-linux page,
instead of template. You will need to create the template by going to
/wiki/your-wiki-vroot/(edit)/template-<the_template> first.

(Optional) To disable file uploads such as binary attachments and inline images,
set uploads to no. By default it is yes. Note that inline images requires the
Image::Magick module to be installed for generating thumbnails.

  PerlAddVar uploads no

(Optional) Pre-caching can be done by a periodic (eg every 5 minutes) cronjob
to refresh the cached version of the .list* pages (see below) in the background,
rather then when Apache::Miniki discovers that the cache is old when a request is
done. To eanble:

  PerlAddVar precaching yes

If you create the pages 'list' or 'listchanges' or 'listlinks', the following will
automatically get appended to them:

README  view on Meta::CPAN


DESCRIPTION
    Apache::MiniWiki is a simplistic Wiki for Apache. It doesn't have much
    uses besides very simple installations where hardly any features are
    needed. What is does support though is:

      - storage of Wiki pages in RCS
      - templates through HTML::Template
      - text to HTML conversion with HTML::FromText
      - basic authentication password changes
      - uploading of binary (pdf, doc, gz, zip, ps)
      - uploading of images (jpg, jpeg, gif, png)
      - automatic thumbnailing of large using ImageMagick
      - sub directories
      - view any revision of a page
      - revert back to any revision of the page
      - basic checks to keep search engine spiders from deleting 
        all the pages in the Wiki

DEPENDENCIES
    This module requires these other modules:

README  view on Meta::CPAN

    variable to specify more then one template:

      PerlAddVar templates fvlug linux

    By doing this, pages that contain those words will use the matching
    template. For example, the /your-wiki-vroot/LinuxDatabases page will
    then use the template-linux page, instead of template. You will need to
    create the template by going to
    /wiki/your-wiki-vroot/(edit)/template-<the_template> first.

    (Optional) To disable file uploads such as binary attachments and inline
    images, set uploads to no. By default it is yes. Note that inline images
    requires the Image::Magick module to be installed for generating
    thumbnails.

      PerlAddVar uploads no

    (Optional) Pre-caching can be done by a periodic (eg every 5 minutes)
    cronjob to refresh the cached version of the .list* pages (see below) in
    the background, rather then when Apache::Miniki discovers that the cache
    is old when a request is done. To eanble:

      PerlAddVar precaching yes

    If you create the pages 'list' or 'listchanges' or 'listlinks', the
    following will automatically get appended to them:



( run in 0.898 second using v1.01-cache-2.11-cpan-b16cb0d3907 )