Apache-MiniWiki

 view release on metacpan or  search on metacpan

MANIFEST  view on Meta::CPAN

Makefile.PL
MANIFEST
README
MiniWiki.pm
example/template,v
example/index,v
example/edit,v
example/list,v
example/listchanges,v
test.pl
wiki.cgi

MiniWiki.pm  view on Meta::CPAN


*NOTE:* $text

Please hit the *back* button in your browser, and try again.
TEXT
  $newtext = &prettify($newtext);
    
  $template->param('vroot', $vroot || "no vroot");
  $template->param('title', $uri);
  $template->param('body', $newtext);
  $template->param('editlink', "$vroot/\(edit\)\/$uri");
  $template->param('loglink', "$vroot/\(log\)\/$uri");
  $template->param('pageurl', "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}$ENV{REQUEST_URI}");
  
  my $output = $template->output;
  
  $r->send_http_header('text/html');
  print $output;

  return $return;
}

MiniWiki.pm  view on Meta::CPAN

  # 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);
  }

  my $comment = $q->param('comment');
  my $user = $r->connection->user || "anonymous";

  chomp ($comment);
  $comment =~ s/^\s*//g if $comment;
  $comment =~ s/\s*$//g if $comment;

  if (length($text) < 5) {

MiniWiki.pm  view on Meta::CPAN


  open(OUT, '>', "${datadir}/${fileuri}");
  print OUT $text;
  close OUT;

  $file->ci('-u', "-w$user", "-m$comment") or confess $!;

  $uri = "index" if ($uri and $uri eq 'template');

  if (not &is_img($uri) and &is_binary($uri)) {
    return &edit_function($r, $uri, undef);
  } else { 
    return &view_function($r, $uri);
  }
}

# This function reverts a page back to the specified version if possible.
sub revert_function {
  my ($r, $uri, $revision) = @_;

  my $fileuri = uri_to_filename($uri);

MiniWiki.pm  view on Meta::CPAN

  if ($@) {
    return fatal_error($r, "Error reverting: $@");
  }

  my $newtext = "The page has been reverted to revision $revision.<p>";
  $newtext .= qq([<a href="${vroot}/${uri}">Return</a>]<p>);

  $template->param('vroot', $vroot);
  $template->param('title', $uri);
  $template->param('body', $newtext);
  $template->param('editlink', "$vroot/\(edit\)\/$uri");
  $template->param('loglink', "$vroot/\(log\)\/$uri");
  $template->param("lastmod", &get_lastmod("${datadir}/${fileuri},v"));

  $r->send_http_header('text/html');
  print $template->output;

  return OK;
}

sub revert_form {

MiniWiki.pm  view on Meta::CPAN

		 Really revert the page <b>$uri</b> to revision <b>$revision</b>?<br/>
		 <br/>
		 <input type=submit value=" Yes " name="submit_button">
		</fieldset>
		</form>
	);
  
	$template->param('vroot', $vroot);
	$template->param('title', $uri);
	$template->param('body', $formhtml);
	$template->param('editlink', "$vroot/\(edit\)\/$uri");
	$template->param('loglink', "$vroot/\(log\)\/$uri");
	$template->param("lastmod", &get_lastmod("${datadir}/${fileuri},v"));

	my $output = $template->output;
	$output =~ s/\n(\s*)\n(\s*)\n/\n\n/g;

	$r->send_http_header('text/html');
	print $output;

	return OK;
}

# The edit function checks out a page from RCS and provides a text
# area for the user where he or she can edit the content.
sub edit_function {
  my ($r, $uri, $preview_wikitext) = @_;

  my $fileuri = uri_to_filename($uri);
  
  my $q = new CGI;

  my $comment = $q->param("comment") || "";


  if (-f "${datadir}/${fileuri},v") {

MiniWiki.pm  view on Meta::CPAN

    $text .= "</textarea>"
  }
  
  $text .= qq(<p>Comment: <input type=text size=30 maxlength=60 name=comment value="$comment">&nbsp;);
  $text .= qq(<input type="submit" name="Save" value="Preview">\n);
  $text .= qq(<input type="submit" name="Save" value="Save"></fieldset></form>);

  $template->param('vroot', $vroot);
  $template->param('title', $uri);
  $template->param('body', $text);
  $template->param('editlink', "$vroot/\(edit\)\/$uri");
  $template->param('loglink', "$vroot/\(log\)\/$uri");
  $template->param("lastmod", &get_lastmod("${datadir}/${fileuri},v"));

  my $output = $template->output;
  $output =~ s/\n(\s*)\n(\s*)\n/\n\n/g;

  $r->send_http_header('text/html');
  print $output;

  return OK;

MiniWiki.pm  view on Meta::CPAN

		} else {
		  $pagedata = &get_file($cachefile);
		}
		$newtext .= $pagedata;
      }
    }
  
    $template->param('vroot', $vroot || "no vroot");
    $template->param('title', $uri);
    $template->param('body', $newtext);
    $template->param('editlink', "$vroot/\(edit\)\/$uri");
    $template->param('loglink', "$vroot/\(log\)\/$uri");
    $template->param('pageurl', "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}$ENV{REQUEST_URI}");
    $template->param("lastmod", &get_lastmod("${datadir}/${fileuri},v"));
  
    my $output = $template->output;
    $output =~ s/\n(\s*)\n(\s*)\n/\n\n/g;
  
    $r->send_http_header('text/html');
    print $output;
  }

MiniWiki.pm  view on Meta::CPAN


# write the given data to the given filename
sub put_file($$) {
  my ($filename, $data) = @_;

  open (OUT, "> $filename") || die $!;
  print OUT $data;
  close(OUT);
}

# returns the name of the last page that was editted in the wiki
sub get_lastchanged {
  open (CMD, "cd ${datadir}; /bin/ls -1at *,v | head -1 |") || die $!;
  my $filename = <CMD>;
  close (CMD);
	$filename =~ s/\t|\r|\n//g;
	$filename =~ s/ $//g;
	$filename =~ s/^ //g;
  return $filename;
}

MiniWiki.pm  view on Meta::CPAN


    if (-f "${datadir}/$tmppath,v") {
      my $link;
      if (is_img($rawname)) {
        $link = qq{<a href="$vroot/$rawname"><img src="$vroot/(thumb)$rawname" alt="$desc"></a>};
	  }
      else {
        $link = qq{<a href="$vroot/$rawname">$desc</a>};
      }
      if (is_binary($rawname) || is_img($rawname)) {
        $link .= qq { <sup><a href="$vroot/(edit)$rawname">[E]</a></sup>};
      }
      $newtext =~ s/\[\[[^\]]*\]\]/$link/;
    } else {
      $tmplink = "$desc <a href=\"${vroot}\/(edit)/${rawname}\"><sup>?<\/sup><\/a>";
      $newtext =~ s/\[\[[^\]]*\]\]/$tmplink/;
    }
    }
    $newtext =~ s/\\\[\\\[/\[\[/g;
  
    $newtext =~ s/-{3,}/<hr\/>/g;

    return $newtext;
}

MiniWiki.pm  view on Meta::CPAN

    return fatal_error($r, "Diff failed for $uri: $@");
  }
  $diffbody = "<p id='title'>Differences</p>" 
  			 . text2html($diffbody, lines=>1);
  
  $diffbody .= &diff_form($uri);

  $template->param('vroot', $vroot);
  $template->param('title', $uri);
  $template->param('body', $diffbody);
  $template->param('editlink', "$vroot/\(edit\)\/$uri");
  $template->param('loglink', "$vroot/\(log\)\/$uri");
  $template->param("lastmod", &get_lastmod("${datadir}/${uri},v"));

  $r->send_http_header('text/html');
  print $template->output;

  return OK;
}

# This function dumps out the log list for the file, so that the user can view

MiniWiki.pm  view on Meta::CPAN

      $line .= "<br/>";
    }
    $logbody .= "$line";
  }

  $logbody .= &diff_form($uri);

  $template->param('vroot', $vroot);
  $template->param('title', $uri);
  $template->param('body', $logbody);
  $template->param('editlink', "$vroot/\(edit\)\/$uri");
  $template->param('loglink', "$vroot/\(log\)\/$uri");
  $template->param("lastmod", &get_lastmod("${datadir}/${fileuri},v"));

  $r->send_http_header('text/html');
  print $template->output;

  return OK;
}

# this function creates a thumbnail on the fly for the given uri.

MiniWiki.pm  view on Meta::CPAN

    my $template_text = <<END_TEMPLATE;
<html>
<head><title>Default Wiki: <TMPL_VAR NAME=title></title></head>
<body>
<TMPL_VAR NAME=BODY>
<p>
<hr/>
<i>This is a default template. For a full example of wiki pages, 
use those provided in the Apache::MiniWiki distribution.</i>
<hr/>
[<a href="<TMPL_VAR NAME=editlink>">Edit</a> | 
<a href="<TMPL_VAR NAME=loglink>">Archive</a> |
<a href="<TMPL_VAR NAME=vroot>/">Home</a> ]
<br/><br/>
Last Modified: <TMPL_VAR NAME="lastmod">
</body></html>
END_TEMPLATE
  
    return HTML::Template->new(
      scalarref => \$template_text, die_on_bad_params => 0
    );

MiniWiki.pm  view on Meta::CPAN


		$parser->parse($newtext);
		$total_bytes += length($newtext);

		my (@links) = $parser->links;
		my $ul_id = "links_${rawname}";
		$ul_id =~ s/(\.| )//g; 
		$spanhtml .= qq|<ul id="$ul_id" style="display:none">\n|;
		foreach my $link (@links) {
			my $href = $link->[2];
			next if ($href =~ /\(edit\)|template-/i or $href eq "${vroot}/template");
			next if ($href eq "http://"); # not real
			if ($href =~ /^${vroot}/) {
				next if (!-f &strip_virtual($href));
				$href = "#" . &strip_virtual($href);
				$total_in++;
			} else {
				# encode ?, &, etc for XHTML1.1 validator
				$href = &encode_entities($href);
				$total_out++;
			}

MiniWiki.pm  view on Meta::CPAN


	finish:

	$changes .= "<br/>\n";
	$changes .= "Current date: <b>" . `/bin/date` . "</b><br/>\n";

	return $changes;
}

# If enabled as a PerlAccessHandler, allows public viewing of
# a Wiki, but leaves existing authentication in place for editing
# content.
sub access_handler {
  my $r = shift;

  return OK unless $r->some_auth_required;

  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?

MiniWiki.pm  view on Meta::CPAN

     PerlAddVar authen "/home/foo/db/htpasswd"
     SetHandler perl-script
     PerlHandler Apache::MiniWiki

     AuthType Basic
     AuthName "Sample Wiki"
     AuthUserFile /home/foo/db/htpasswd 
     Require valid-user
  </Location>

  Public can read, but need password to edit/save/revert a page:
  
  <Location /wiki>
     PerlAddVar datadir "/home/foo/db/wiki/"
     PerlAddVar vroot "/wiki"
     PerlAddVar authen "/home/foo/db/htpasswd"
     SetHandler perl-script
     PerlHandler Apache::MiniWiki

     Require valid-user # or group foo or whatever you want
     PerlAccessHandler Apache::MiniWiki::access_handler

MiniWiki.pm  view on Meta::CPAN

  </Location>

=head1 CONFIGURATION

If you want to use your own template for MiniWiki, you should place the
template in the RCS file template,v in the C<datadir>. Upon execution,
MiniWiki will check out this template and use it. If you make any
modifications to the RCS file, a new version will be checked out.

You can modify the template from within MiniWiki by visiting the URL
http://your.server.name/your-wiki-vroot/(edit)/template

If you don't install a template, a default one will be used.

The C<datadir> variable defines where in the filesystem that the RCS
files that MiniWiki uses should be stored. This is also where MiniWiki
looks for a template to use.

The C<vroot> should match the virtual directory that MiniWiki runs under.

If this variable is set, it should point to a standard htpasswd file

MiniWiki.pm  view on Meta::CPAN


(Optional) By default, only the template called template is used. This becomes 
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

MiniWiki.pm  view on Meta::CPAN


These variables are passed by Apache::MiniWiki to HTML::Template:

  vroot:
    virtual root of the wiki installation. E.g.
	  /wiki
  title:
    the title of a page. Comes from the first line of text.
  body:
    HTMLified version of a wiki page
  editlink:
    Link to the edit page. E.g.:
	  http://www.nyetwork.org/wiki/(edit)/MiniWiki
  loglink:
    Link to the Archive page. e.g.:
	  http://www.nyetwork.org/wiki/(log)/MiniWiki
  pageurl:
    Fully qualified link to the page based on the last request, e.g.:
	  http://nyetwork.org:80/wiki/MiniWiki
  lastmod:
    date the page was last changed, e.g.:
	  March 18, 2003 4:25 PM

MiniWiki.pm  view on Meta::CPAN


Spiders for search engines (Google, OpenFind, etc) love the 
bounty of links found in a Wiki. Unfortunely, they also follow
the Archive, Changes, View, and Revert links. This not only
adds to the load on your webserver, but there is a very high
chance that pages will get rolled back as the spider
goes in circles following links. This has happened! Add
these links to your robots.txt so that robots can
only view the actual current pages:

Disallow: /wiki/(edit)/
Disallow: /wiki/(log)/
Disallow: /wiki/(revert)/
Disallow: /wiki/(save)/
Disallow: /wiki/(view)/
Disallow: /wiki/lastchanges

See http://www.nyetwork.org/wiki for an example of 
this module in active use.

=head1 HOME PAGE

README  view on Meta::CPAN

         PerlAddVar authen "/home/foo/db/htpasswd"
         SetHandler perl-script
         PerlHandler Apache::MiniWiki

         AuthType Basic
         AuthName "Sample Wiki"
         AuthUserFile /home/foo/db/htpasswd 
         Require valid-user
      </Location>

      Public can read, but need password to edit/save/revert a page:
  
      <Location /wiki>
         PerlAddVar datadir "/home/foo/db/wiki/"
         PerlAddVar vroot "/wiki"
         PerlAddVar authen "/home/foo/db/htpasswd"
         SetHandler perl-script
         PerlHandler Apache::MiniWiki

         Require valid-user # or group foo or whatever you want
         PerlAccessHandler Apache::MiniWiki::access_handler

README  view on Meta::CPAN

        Options ExecCGI
      </Location>

CONFIGURATION
    If you want to use your own template for MiniWiki, you should place the
    template in the RCS file template,v in the "datadir". Upon execution,
    MiniWiki will check out this template and use it. If you make any
    modifications to the RCS file, a new version will be checked out.

    You can modify the template from within MiniWiki by visiting the URL
    http://your.server.name/your-wiki-vroot/(edit)/template

    If you don't install a template, a default one will be used.

    The "datadir" variable defines where in the filesystem that the RCS
    files that MiniWiki uses should be stored. This is also where MiniWiki
    looks for a template to use.

    The "vroot" should match the virtual directory that MiniWiki runs under.

    If this variable is set, it should point to a standard htpasswd file

README  view on Meta::CPAN

    (Optional) By default, only the template called template is used. This
    becomes the default template for every page. Use the "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

README  view on Meta::CPAN

TEMPLATE VARIABLES
    These variables are passed by Apache::MiniWiki to HTML::Template:

      vroot:
        virtual root of the wiki installation. E.g.
              /wiki
      title:
        the title of a page. Comes from the first line of text.
      body:
        HTMLified version of a wiki page
      editlink:
        Link to the edit page. E.g.:
              http://www.nyetwork.org/wiki/(edit)/MiniWiki
      loglink:
        Link to the Archive page. e.g.:
              http://www.nyetwork.org/wiki/(log)/MiniWiki
      pageurl:
        Fully qualified link to the page based on the last request, e.g.:
              http://nyetwork.org:80/wiki/MiniWiki
      lastmod:
        date the page was last changed, e.g.:
              March 18, 2003 4:25 PM

SEARCH ENGINES
    Spiders for search engines (Google, OpenFind, etc) love the bounty of
    links found in a Wiki. Unfortunely, they also follow the Archive,
    Changes, View, and Revert links. This not only adds to the load on your
    webserver, but there is a very high chance that pages will get rolled
    back as the spider goes in circles following links. This has happened!
    Add these links to your robots.txt so that robots can only view the
    actual current pages:

    Disallow: /wiki/(edit)/ Disallow: /wiki/(log)/ Disallow: /wiki/(revert)/
    Disallow: /wiki/(save)/ Disallow: /wiki/(view)/ Disallow:
    /wiki/lastchanges

    See http://www.nyetwork.org/wiki for an example of this module in active
    use.

HOME PAGE
    http://www.nyetwork.org/wiki/MiniWiki

AUTHORS

conf/httpd-perl-startup.pl  view on Meta::CPAN

  %wikis = (
    'wiki-name' => {
      _title => 'Wiki Title',
      _uri => '/wiki-uri',
      _public => 0|1
    }
  )

All the keys are optional. If _public is 0, the Wiki will be
password-protected. If 1, it will use Apache::MiniWiki::access_handler,
which allows public viewing, and requires a password to edit
(not entirely Wiki-nature, I know).

=cut
my %wikis = (
	'lit-review' => {
		_title => "Concept Formation Annotated Bibliography",
  	_public => 0
	},
	'perl-ai' => {
		_title => "AI-Perl Resources Page",

example/edit,v  view on Meta::CPAN

@


1.2
log
@*** empty log message ***
@
text
@Writing pages

Writing and creating pages is simple. If you see a page that you wish to change, just press the "Edit" link. You will then receive a page where you can edit the information. When you subsequently press "Submit", having done your changes, the page is ...

Instead of using regular HTML code, all content is written as plain text which is formatted into HTML when viewed. 

The following is true for all pages:

 * The first line on any page will always become a header
 * If you wish to link to other pages, you can write links like this: \[\[Pagename|Description]]. For example, to make a link to the main page (index), you can write: \[\[index|Main page]].
 * You can create *bold* or _underlined_ text by putting * or _ on both sides of a text.
 * Unnumbered lists (like this) is written by putting *, in front of all rows.
 * Numbered lists are written by putting a number (1, 2, 3...) in front of every row.

example/index,v  view on Meta::CPAN


1.3
log
@added a note
@
text
@Welcome

Welcome to your first Apache::MiniWiki installation. This installation doesn't
contain very much and is waiting for you to add content to it. You can start
by modifying the [[template]] page, or perhaps take a look at how to [[edit]]
pages.

If you wish, you can also create your own [[playground]] by clicking on the
questionmark after the word playground to create that missing page.

See the provided documentation for further information on customizing your MiniWiki install. For an example of a working MiniWiki site, see http://www.nyetwork.org/wiki/@


1.2
log

example/template,v  view on Meta::CPAN


<body bgcolor="black">

<TABLE border=1 align=center width="100%" bgcolor="#eaeaea" cellpadding=2 cellspacing=0>
<tr>
 <td valign=top align=right bgcolor="#c8d2dc">
   <a href="<TMPL_VAR NAME=vroot>/">Home</a>,
   <a href="<TMPL_VAR NAME=vroot>/list">Pages</a>,
   <a href="<TMPL_VAR NAME=vroot>/listlinks">Links</a>,
   <a href="<TMPL_VAR NAME=vroot>/listchanges">Changes</a>,
   <a href="<TMPL_VAR NAME=vroot>/edit">Help</a>,
   <a href="<TMPL_VAR NAME=loglink>">Archive</a>,
   <a href="<TMPL_VAR NAME=vroot>/(newpassword)">Password<sup>1</sup></a>,
   <a href="<TMPL_VAR NAME=editlink>">Edit</a>
 </td>
</tr>
<tr>
 <td align=left valign=top>
  <TMPL_VAR NAME=BODY> 
<p><hr>
<sup>1</sup>This will only work if authentification is enabled in
Apache::MiniWiki. See the POD documentation, or the manual page for
more information.
 </td>
</tr>
<tr>
 <td valign=top align=right bgcolor="#c8d2dc">
   <a href="<TMPL_VAR NAME=vroot>/">Home</a>,
   <a href="<TMPL_VAR NAME=vroot>/Main">Map</a>,
   <a href="<TMPL_VAR NAME=vroot>/list">Pages</a>,
   <a href="<TMPL_VAR NAME=vroot>/listlinks">Links</a>,
   <a href="<TMPL_VAR NAME=vroot>/listchanges">Changes</a>,
   <a href="<TMPL_VAR NAME=vroot>/edit">Help</a>,
   <a href="<TMPL_VAR NAME=loglink>">Archive</a>,
   <a href="<TMPL_VAR NAME=vroot>/(newpassword)">Password<sup>1</sup></a>,
   <a href="<TMPL_VAR NAME=editlink>">Edit</a>
 </td>
</tr>
</TABLE>
<br><div align="right"><span style="bgcolor:black; color:white; font-weight:bold">
Last Modified: <TMPL_VAR NAME=lastmod></span></div>
</body></html>
@


1.8

example/template,v  view on Meta::CPAN

1.1
log
@Initial revision
@
text
@d2 51
a52 11
  <html>
    <head><title>Example MiniWiki</title></head>
    <body>
     [<a href="<TMPL_VAR NAME=editlink>">Edit</a>|<a href="/wiki/(newpassword)">Change Password<sup>1</sup></a>]<br>
<TMPL_VAR NAME=BODY>
<p><hr>
<sup>1</sup>This will only work if authentification is enabled in
Apache::MiniWiki. See the POD documentation, or the manual page for
more information.
    </body>
  </html>
@



( run in 0.647 second using v1.01-cache-2.11-cpan-de7293f3b23 )