#!/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::init; use strict; use base 'Exporter'; use Wiki::consts; use vars qw(@EXPORT); @EXPORT = qw( DoWikiConfig ); # == Configuration ===================================================== $DataDir = "/home/tmnet/data/tmnetdb"; # Main wiki directory $UseConfig = 1; # 1 = use config file, 0 = do not look for config # Default configuration (used if UseConfig is 0) $CookieName = "Wiki"; # Name for this wiki (for multi-wiki sites) $SiteName = "Wiki"; # Name of site (used for titles) $HomePage = "HomePage"; # Home page (change space to _) $RCName = "RecentChanges"; # Name of changes page (change space to _) $UsersName = "TheUsers"; # Name of users page (change space to _) $TalkName = "Talk"; # Name of talk pages $LogoUrl = "/wiki.gif"; # URL for site logo ("" for no logo) $ENV{PATH} = "/usr/bin/"; # Path used to find "diff" $ScriptTZ = ""; # Local time zone ("" means do not print) $RcDefault = 30; # Default number of RecentChanges days @RcDays = qw(1 3 7 30 90); # Days for links on RecentChanges $KeepDays = 14; # Days to keep old revisions $SiteBase = ""; # Full URL for header $FullUrl = ""; # Set if the auto-detected URL is wrong $RedirType = 1; # 1 = CGI.pm, 2 = script, 3 = no redirect $AdminPass = ""; # Set to non-blank to enable password(s) $EditPass = ""; # Like AdminPass, but for editing only $StyleSheet = ""; # URL for CSS stylesheet (like "/wiki.css") $NotFoundPg = ""; # Page for not-found links ("" for blank pg) $EmailFrom = "Wiki"; # Text for "From: " field of email notes. $SendMail = "/usr/sbin/sendmail"; # Full path to sendmail executable $FooterNote = ""; # HTML for bottom of every page $EditNote = ""; # HTML notice above buttons on edit page $MaxPost = 1024 * 210; # Maximum 210K posts (about 200K for pages) $NewText = ""; # New page text ("" for default message) $HttpCharset = ""; # Charset for pages, like "iso-8859-2" $UserGotoBar = ""; # HTML added to end of goto bar $AmznAccount = ""; # Amazon.com associate account %Areas = (); # Areas; should be in db, not heret $DefaultArea = ""; # Major options: $UseSubpage = 1; # 1 = use subpages, 0 = do not use subpages $UseTalk = 0; # 1 = use talkpages 0 = no talkpages # UseTalk requires subpages! $UseCache = 0; # 1 = cache HTML pages, 0 = generate every page $EditAllowed = 1; # 1 = editing allowed, 0 = read-only $RawHtml = 0; # 1 = allow tag, 0 = no raw HTML in pages $HtmlTags = 0; # 1 = "unsafe" HTML tags, 0 = only minimal tags $UseDiff = 1; # 1 = use diff features, 0 = do not use diff $FreeLinks = 1; # 1 = use [[word]] links, 0 = LinkPattern only $WikiLinks = 1; # 1 = use LinkPattern, 0 = use [[word]] only $AdminDelete = 1; # 1 = Admin only page, 0 = Editor can delete pages $RunCGI = 1; # 1 = Run script as CGI, 0 = Load but do not run $EmailNotify = 0; # 1 = use email notices, 0 = no email on changes $EmbedWiki = 0; # 1 = no headers/footers, 0 = normal wiki pages $ForceSummary= 0; # 1 = major edit summary, 0 = no summary required # Minor options: $LogoLeft = 0; # 1 = logo on left, 0 = logo on right $RecentTop = 1; # 1 = recent on top, 0 = recent on bottom $UseDiffLog = 1; # 1 = save diffs to log, 0 = do not save diffs $KeepMajor = 1; # 1 = keep major rev, 0 = expire all revisions $KeepAuthor = 1; # 1 = keep author rev, 0 = expire all revisions $ShowEdits = 0; # 1 = show minor edits, 0 = hide edits by default $HtmlLinks = 0; # 1 = allow A HREF links, 0 = no raw HTML links $SimpleLinks = 0; # 1 = only letters, 0 = allow _ and numbers $NonEnglish = 0; # 1 = extra link chars, 0 = only A-Za-z chars $ThinLine = 0; # 1 = fancy
tags, 0 = classic wiki
$BracketText = 1; # 1 = allow [URL text], 0 = no link descriptions $UseAmPm = 1; # 1 = use am/pm in times, 0 = use 24-hour times $UseIndex = 0; # 1 = use index file, 0 = slow/reliable method $UseHeadings = 1; # 1 = allow = h1 text =, 0 = no header formatting $NetworkFile = 1; # 1 = allow remote file:, 0 = no file:// links $BracketWiki = 0; # 1 = [WikiLnk txt] link, 0 = no local descriptions $UseLookup = 1; # 1 = lookup host names, 0 = skip lookup (IP only) $FreeUpper = 1; # 1 = force upper case, 0 = do not force case $FastGlob = 1; # 1 = new faster code, 0 = old compatible code $XSearchDisp = 0; # 1 = expanded results 0 = just search hits $ShowLinks = 1; # 1 = all see WikiLnk? 0 = only editors see WikiLnk? # HTML tag lists, enabled if $HtmlTags is set. # Scripting is currently possible with these tags, # so they are *not* particularly "safe". # Tags that must be in ... pairs: @HtmlPairs = qw(b i u font big small sub sup h1 h2 h3 h4 h5 h6 cite code em s strike strong tt var div center blockquote ol ul dl table caption style); # Single tags (that do not require a closing /tag) @HtmlSingle = qw(br p hr li dt dd tr td th); @HtmlPairs = (@HtmlPairs, @HtmlSingle); # All singles can also be pairs # == You should not have to change anything below this line. ============= $IndentLimit = 20; # Maximum depth of nested lists $PageDir = "$DataDir/page"; # Stores page data $HtmlDir = "$DataDir/html"; # Stores HTML versions $UserDir = "$DataDir/user"; # Stores user data $KeepDir = "$DataDir/keep"; # Stores kept (old) page data $TempDir = "$DataDir/temp"; # Temporary files and locks $TemplateDir = "$DataDir/template"; # Templates $LockDir = "$TempDir/lock"; # DB is locked if this exists $InterFile = "$DataDir/intermap"; # Interwiki site->url map $RcFile = "$DataDir/rclog"; # New RecentChanges logfile $RcOldFile = "$DataDir/oldrclog"; # Old RecentChanges logfile $IndexFile = "$DataDir/pageidx"; # List of all pages $QuoteFile = "$DataDir/quotes"; # List of quotations, an add-on sub DoWikiConfig { my $datadir = shift; $DataDir = $datadir if $datadir; if ($UseConfig && (-f "$DataDir/config")) { do "$DataDir/config"; # Later consider error checking? } &InitLinkPatterns(); $Consts = { DataDir => $DataDir, UseConfig => $UseConfig, CookieName => $CookieName, SiteName => $SiteName, HomePage => $HomePage, RCName => $RCName, UsersName => $UsersName, TalkName => $TalkName, LogoUrl => $LogoUrl, ScriptTZ => $ScriptTZ, RcDefault => $RcDefault, RcDays => \@RcDays, KeepDays => $KeepDays, SiteBase => $SiteBase, FullUrl => $FullUrl, RedirType => $RedirType, AdminPass => $AdminPass, EditPass => $EditPass, StyleSheet => $StyleSheet, NotFoundPg => $NotFoundPg, EmailFrom => $EmailFrom, SendMail => $SendMail, FooterNote => $FooterNote, EditNote => $EditNote, MaxPost => $MaxPost, NewText => $NewText, HttpCharset => $HttpCharset, UserGotoBar => $UserGotoBar, UseSubpage => $UseSubpage, UseTalk => $UseTalk, UseCache => $UseCache, EditAllowed => $EditAllowed, RawHtml => $RawHtml, HtmlTags => $HtmlTags, UseDiff => $UseDiff, FreeLinks => $FreeLinks, WikiLinks => $WikiLinks, AdminDelete => $AdminDelete, RunCGI => $RunCGI, EmailNotify => $EmailNotify, EmbedWiki => $EmbedWiki, ForceSummary => $ForceSummary, LogoLeft => $LogoLeft, RecentTop => $RecentTop, UseDiffLog => $UseDiffLog, KeepMajor => $KeepMajor, KeepAuthor => $KeepAuthor, ShowEdits => $ShowEdits, HtmlLinks => $HtmlLinks, SimpleLinks => $SimpleLinks, NonEnglish => $NonEnglish, ThinLine => $ThinLine, BracketText => $BracketText, UseAmPm => $UseAmPm, UseIndex => $UseIndex, UseHeadings => $UseHeadings, NetworkFile => $NetworkFile, BracketWiki => $BracketWiki, UseLookup => $UseLookup, FreeUpper => $FreeUpper, FastGlob => $FastGlob, XSearchDisp => $XSearchDisp, ShowLinks => $ShowLinks, HtmlSingle => \@HtmlSingle, HtmlPairs => \@HtmlPairs, IndentLimit => $IndentLimit, PageDir => $PageDir, HtmlDir => $HtmlDir, UserDir => $UserDir, KeepDir => $KeepDir, TempDir => $TempDir, LockDir => $LockDir, InterFile => $InterFile, RcFile => $RcFile, RcOldFile => $RcOldFile, IndexFile => $IndexFile, QuoteFile => $QuoteFile, FS => $FS, FS1 => $FS1, FS2 => $FS2, FS3 => $FS3, LinkPattern => $LinkPattern, FreeLinkPattern => $FreeLinkPattern, InterLinkPattern => $InterLinkPattern, InterSitePattern => $InterSitePattern, UrlProtocols => $UrlProtocols, UrlPattern => $UrlPattern, ImageExtensions => $ImageExtensions, RFCPattern => $RFCPattern, ISBNPattern => $ISBNPattern, AmznAccount => $AmznAccount, Areas => \%Areas, DefaultArea => $DefaultArea, } } # == Common and cache-browsing code ==================================== sub InitLinkPatterns { my ($UpperLetter, $LowerLetter, $AnyLetter, $LpA, $LpB, $QDelim); # Field separators are used in the URL-style patterns below. $FS = "\xb3"; # The FS character is a superscript "3" $FS1 = $FS . "1"; # The FS values are used to separate fields $FS2 = $FS . "2"; # in stored hashtables and other data structures. $FS3 = $FS . "3"; # The FS character is not allowed in user data. $UpperLetter = "[A-Z"; $LowerLetter = "[a-z"; $AnyLetter = "[A-Za-z"; if ($NonEnglish) { $UpperLetter .= "\xc0-\xde"; $LowerLetter .= "\xdf-\xff"; $AnyLetter .= "\xc0-\xff"; } if (!$SimpleLinks) { $AnyLetter .= ">_0-9"; } $UpperLetter .= "]"; $LowerLetter .= "]"; $AnyLetter .= "]"; # Main link pattern: lowercase between uppercase, then anything $LpA = $UpperLetter . "+" . $LowerLetter . "+" . $UpperLetter . $AnyLetter . "*"; # Optional subpage link pattern: uppercase, lowercase, then anything $LpB = $UpperLetter . "+" . $LowerLetter . "+" . $AnyLetter . "*"; if ($UseSubpage) { # Loose pattern: If subpage is used, subpage may be simple name # $LinkPattern = "((?:(?:$LpA)?(?:\\/$LpB)+)|$LpA)"; $LinkPattern = "((?:(?:$LpA)?\\/$LpB)|$LpA)"; # Strict pattern: both sides must be the main LinkPattern # $LinkPattern = "((?:(?:$LpA)?\\/)?$LpA)"; } else { $LinkPattern = "($LpA)"; } $QDelim = '(?:"")?'; # Optional quote delimiter (not in output) $LinkPattern .= $QDelim; # Inter-site convention: sites must start with uppercase letter # (Uppercase letter avoids confusion with URLs) $InterSitePattern = $UpperLetter . $AnyLetter . "+"; $InterLinkPattern = "((?:$InterSitePattern:[^\\]\\s\"<>$FS]+)$QDelim)"; if ($FreeLinks) { # Note: the - character must be first in $AnyLetter definition if ($NonEnglish) { $AnyLetter = "[-,.()>' _0-9A-Za-z\xc0-\xff]"; } else { $AnyLetter = "[-,.()>' _0-9A-Za-z]"; } } $FreeLinkPattern = "($AnyLetter+)"; if ($UseSubpage) { # $FreeLinkPattern = "((?:(?:$AnyLetter+)?(?:\\/$AnyLetter+)+)|$AnyLetter+)"; $FreeLinkPattern = "((?:(?:$AnyLetter+)?\\/)?$AnyLetter+)"; } $FreeLinkPattern .= $QDelim; # Url-style links are delimited by one of: # 1. Whitespace (kept in output) # 2. Left or right angle-bracket (< or >) (kept in output) # 3. Right square-bracket (]) (kept in output) # 4. A single double-quote (") (kept in output) # 5. A $FS (field separator) character (kept in output) # 6. A double double-quote ("") (removed from output) $UrlProtocols = "http|https|ftp|afs|news|nntp|mid|cid|mailto|wais|" . "prospero|telnet|gopher"; $UrlProtocols .= '|file' if $NetworkFile; $UrlPattern = "((?:(?:$UrlProtocols):[^\\]\\s\"<>$FS]+)$QDelim)"; $ImageExtensions = "(gif|jpg|png|bmp|jpeg)"; $RFCPattern = "RFC\\s?(\\d+)"; $ISBNPattern = "(ISBN|ASIN):?([0-9- xX]{10,})"; } 1;