#!/usr/bin/perl # TmNetWiki version 0.4 (September 11, 2002) # Copyright (C) 2002 Adam Brate # # Based on the GPLed UseModWiki 0.92 # Copyright (C) 2000-2001 Clifford A. Adams # or # Based on the GPLed AtisWiki 0.3 (C) 1998 Markus Denker # # ...which was based on # the LGPLed CVWiki CVS-patches (C) 1997 Peter Merel # and The Original WikiWikiWeb (C) Ward Cunningham # (code reused with permission) # Email and ThinLine options by Jim Mahoney # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the # Free Software Foundation, Inc. # 59 Temple Place, Suite 330 # Boston, MA 02111-1307 USA package Wiki::section; use strict; # needs subs Wiki::utility: GetParam # needs consts $Now, $ENV{REMOTE_ADDR} # needs vars %Section, %Page, $UserID use base 'Exporter'; use Wiki::consts; use Wiki::utility; #if ($^V and $^V gt v5.6.0) { # our @EXPORT; #else { use vars qw(@EXPORT); #} @EXPORT = qw( OpenNewSection OpenSection SaveSection ); sub OpenNewSection { my ($name, $data) = @_; my $section = {}; $section->{'name'} = $name; $section->{'version'} = 1; # Data format version $section->{'revision'} = 0; # Number of edited times $section->{'tscreate'} = $Now; # Set once at creation $section->{'ts'} = $Now; # Updated every edit $section->{'ip'} = $ENV{REMOTE_ADDR}; $section->{'host'} = ''; # Updated only for real edits (can be slow) $section->{'id'} = $UserID; $section->{'username'} = &GetParam("username", ""); $section->{'data'} = $data; $Page{$name} = join($Consts->{FS2}, %{$section}); # Replace with save? %Section = %{$section}; return $section; } sub OpenSection { my ($name) = @_; my $section = {}; if (!defined($Page{$name})) { $section = &OpenNewSection($name, ""); } else { %{$section} = split(/$Consts->{FS2}/, $Page{$name}, -1); } %Section = %{$section}; return $section; } sub SaveSection { my $section = shift; my ($name, $data) = @_; # print "Section: $section"; $section->{revision} += 1; # Number of edited times $section->{ts} = $Now; # Updated every edit $section->{ip} = $ENV{REMOTE_ADDR}; $section->{id} = $UserID; $section->{username} = &GetParam("username", ""); $section->{data} = $data; $Page{$name} = join($Consts->{FS2}, %{$section}); } 1;