#!/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::text; use strict; # needs subs Wiki::translate: T # Wiki::section: OpenNewSection, SaveSection # needs consts NewText, FS3 # needs vars %Text, %Page use base 'Exporter'; use Wiki::consts; use Wiki::translate; use Wiki::section; #if ($^V and $^V gt v5.6.0) { # our @EXPORT; #else { use vars qw(@EXPORT); #} @EXPORT=qw( OpenText OpenDefaultText SaveText SaveDefaultText ); sub OpenNewText; # OpenNewText opens both %Text and %Section sub OpenNewText { my ($name) = @_; # Name of text (usually "default") my $text = {}; my ($section,$textpage); # Later consider translation of new-page message? (per-user difference?) if ($NewText ne '') { $text->{'text'} = T($NewText); } else { $text->{'text'} = T('Describe the new page here.') . "\n"; } $text->{'text'} .= "\n" if (substr($text->{'text'}, -1, 1) ne "\n"); $text->{'minor'} = 0; # Default as major edit $text->{'newauthor'} = 1; # Default as new author $text->{'summary'} = ''; $section = &OpenNewSection("text_$name", join($Consts->{FS3}, %{$text})); %Text = %{$text}; $textpage = {section=>$section,text=>$text}; return $textpage; } # OpenText sets both %Text and %Section sub OpenText { my ($name) = @_; my $textpage; if (!defined($Page{"text_$name"})) { $textpage = &OpenNewText($name); } else { my ($textsection,$text); $textsection = &OpenSection("text_$name"); %{$text} = split(/$Consts->{FS3}/, $textsection->{'data'}, -1); $textpage = {section => $textsection, text => $text}; } %Text = %{$textpage->{text}}; return $textpage; } sub OpenDefaultText { return &OpenText('default'); } sub SaveDefaultText { my $textpage = shift; &SaveText($textpage,'default'); } sub SaveText { my $textpage = shift; my ($name) = @_; my %text = %{$textpage->{text}}; &SaveSection($textpage->{section},"text_$name", join($Consts->{FS3}, %text)); } 1;