| 1 | # PurpleWiki::Config.pm | ||||||||||||
| 2 | # vi:ai:sm:et:sw=4:ts=4 | ||||||||||||
| 3 | # | ||||||||||||
| 4 | # $Id: Config.pm 469 2004-08-09 05:08:03Z eekim $ | ||||||||||||
| 5 | # | ||||||||||||
| 6 | # Copyright (c) Blue Oxen Associates 2002-2004. All rights reserved. | ||||||||||||
| 7 | # | ||||||||||||
| 8 | # This file is part of PurpleWiki. PurpleWiki is derived from: | ||||||||||||
| 9 | # | ||||||||||||
| 10 | # UseModWiki v0.92 (c) Clifford A. Adams 2000-2001 | ||||||||||||
| 11 | # AtisWiki v0.3 (c) Markus Denker 1998 | ||||||||||||
| 12 | # CVWiki CVS-patches (c) Peter Merel 1997 | ||||||||||||
| 13 | # The Original WikiWikiWeb (c) Ward Cunningham | ||||||||||||
| 14 | # | ||||||||||||
| 15 | # PurpleWiki is free software; you can redistribute it and/or modify | ||||||||||||
| 16 | # it under the terms of the GNU General Public License as published by | ||||||||||||
| 17 | # the Free Software Foundation; either version 2 of the License, or | ||||||||||||
| 18 | # (at your option) any later version. | ||||||||||||
| 19 | # | ||||||||||||
| 20 | # This program is distributed in the hope that it will be useful, | ||||||||||||
| 21 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||
| 22 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||
| 23 | # GNU General Public License for more details. | ||||||||||||
| 24 | # | ||||||||||||
| 25 | # You should have received a copy of the GNU General Public License | ||||||||||||
| 26 | # along with this program; if not, write to the | ||||||||||||
| 27 | # Free Software Foundation, Inc. | ||||||||||||
| 28 | # 59 Temple Place, Suite 330 | ||||||||||||
| 29 | # Boston, MA 02111-1307 USA | ||||||||||||
| 30 | |||||||||||||
| 31 | package PurpleWiki::Config; | ||||||||||||
| 32 | |||||||||||||
| 33 | # PurpleWiki Configuration | ||||||||||||
| 34 | |||||||||||||
| 35 | # $Id: Config.pm 469 2004-08-09 05:08:03Z eekim $ | ||||||||||||
| 36 | |||||||||||||
| 37 | 18 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 38 | 18 | ▶ | use AppConfig; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 39 | 18 | ▶ | use PurpleWiki::Singleton; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 40 | 18 | ▶ | use base qw(PurpleWiki::Singleton); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 41 | |||||||||||||
| 42 | 18 | our $VERSION; | |||||||||||
| 43 | 18 | $VERSION = sprintf("%d", q$Id: Config.pm 469 2004-08-09 05:08:03Z eekim $ =~ /\s(\d+)\s/); | |||||||||||
| 44 | |||||||||||||
| 45 | # Field separators that delimit page storage | ||||||||||||
| 46 | 18 | my $FS = "\xb3"; # The FS character is a superscript "3" | |||||||||||
| 47 | 18 | my $FS1 = $FS . "1"; # The FS values are used to separate fields | |||||||||||
| 48 | 18 | my $FS2 = $FS . "2"; # in stored hashtables and other data structures. | |||||||||||
| 49 | 18 | my $FS3 = $FS . "3"; # The FS character is not allowed in user data. | |||||||||||
| 50 | |||||||||||||
| 51 | # Boolean Flags used in config file. We need to be able to | ||||||||||||
| 52 | # inject them into the config. | ||||||||||||
| 53 | # FIXME: AppConfig apparently requires definition of config file | ||||||||||||
| 54 | # variable outside the config file. That's painful. | ||||||||||||
| 55 | 18 | my @BOOLEAN_CONFIGS = qw( UseSubpage EditAllowed UseDiff FreeLinks | |||||||||||
| 56 | WikiLinks RunCGI RecentTop UseDiffLog KeepMajor KeepAuthor | ||||||||||||
| 57 | BracketText UseAmPm FreeUpper ShowEdits NonEnglish | ||||||||||||
| 58 | SimpleLinks ShowNid UseINames LoginToEdit CreateLinkBefore); | ||||||||||||
| 59 | 18 | my @SCALAR_CONFIGS = qw( DataDir ScriptName SiteName HomePage RCName | |||||||||||
| 60 | FullUrl ScriptTZ RcDefault KeepDays CreateLinkText | ||||||||||||
| 61 | HttpCharset MaxPost PageDir UserDir KeepDir TempDir LockDir | ||||||||||||
| 62 | InterFile RcFile RcOldFile TemplateDir MovableTypeDirectory | ||||||||||||
| 63 | ArtsDirectory GoogleWSDL GoogleKey HttpUser HttpPass Umask | ||||||||||||
| 64 | LocalSequenceDir RemoteSequenceURL ScriptDir TemplateDriver | ||||||||||||
| 65 | ServiceProviderName ServiceProviderKey ReturnUrl); | ||||||||||||
| 66 | 18 | my @LIST_CONFIGS = qw( RcDays SearchModule MovableTypeBlogID IrcLogConfig); | |||||||||||
| 67 | |||||||||||||
| 68 | # Sets up the strings and regular expressions for matching | ||||||||||||
| 69 | |||||||||||||
| 70 | # Creates a new PurpleWiki::Config object | ||||||||||||
| 71 | # | ||||||||||||
| 72 | # FIXME: the OO is done here in expectation | ||||||||||||
| 73 | # of eventually wanting or needing some kind | ||||||||||||
| 74 | # of access control or other intercessionary methods | ||||||||||||
| 75 | # between the PurpleWiki and the AppConfig stuff. | ||||||||||||
| 76 | 2 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||
| 77 | 2 | my $class = shift; | |||||||||||
| 78 | 2 | ▶ | my $directory = shift || die "you must provide a config directory"; | ||||||||||
|
Condition50%1/2
shift() || die('you must provide a config directory')
MC/DC0%0/1
shift() || die('you must provide a config directory')
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 79 | 2 | my $self = {}; | |||||||||||
| 80 | 2 | bless ($self, $class); | |||||||||||
| 81 | |||||||||||||
| 82 | 2 | $self->_init($directory); | |||||||||||
| 83 | 2 | $class->setInstance($self); | |||||||||||
| 84 | 2 | return $self; | |||||||||||
| 85 | } | ||||||||||||
| 86 | |||||||||||||
| 87 | 2 | ▶ | sub _init { | ||||||||||
|
Subroutine
_init: called CC=3 SCAR=11.1
| |||||||||||||
| 88 | 2 | my $self = shift; | |||||||||||
| 89 | 2 | my $directory = shift; | |||||||||||
| 90 | 2 | my $file = "$directory/config"; | |||||||||||
| 91 | |||||||||||||
| 92 | 2 | $self->{AppConfig} = AppConfig->new({ | |||||||||||
| 93 | CREATE => 1, | ||||||||||||
| 94 | GLOBAL => { | ||||||||||||
| 95 | EXPAND => AppConfig::EXPAND_VAR, | ||||||||||||
| 96 | }, | ||||||||||||
| 97 | }); | ||||||||||||
| 98 | |||||||||||||
| 99 | # set the types of config variables | ||||||||||||
| 100 | 2 | $self->_initConfig(); | |||||||||||
| 101 | |||||||||||||
| 102 | # set the DataDir variable, it needs to come first | ||||||||||||
| 103 | # because it is expanded in the file | ||||||||||||
| 104 | 2 | $self->{AppConfig}->set('DataDir', $directory); | |||||||||||
| 105 | |||||||||||||
| 106 | 2 | ▶ | $self->{AppConfig}->file($file) || die "unable to parse config file"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 107 | 2 | $self->_initLinkPatterns(); | |||||||||||
| 108 | |||||||||||||
| 109 | # set the File Separators | ||||||||||||
| 110 | 2 | $self->{AppConfig}->set('FS', $FS); | |||||||||||
| 111 | 2 | $self->{AppConfig}->set('FS1', $FS1); | |||||||||||
| 112 | 2 | $self->{AppConfig}->set('FS2', $FS2); | |||||||||||
| 113 | 2 | $self->{AppConfig}->set('FS3', $FS3); | |||||||||||
| 114 | |||||||||||||
| 115 | # make sure LocalSequenceDir is set to DataDir if it | ||||||||||||
| 116 | # wasn't already set | ||||||||||||
| 117 | 2 | ▶ | if (!defined($self->{AppConfig}->get('LocalSequenceDir'))) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 118 | $self->{AppConfig}->set('LocalSequenceDir', | ||||||||||||
| 119 | 0 | $self->{AppConfig}->get('DataDir')); | |||||||||||
| 120 | } | ||||||||||||
| 121 | |||||||||||||
| 122 | 2 | return $self; | |||||||||||
| 123 | } | ||||||||||||
| 124 | |||||||||||||
| 125 | 2 | ▶ | sub _initConfig { | ||||||||||
|
Subroutine
_initConfig: called CC=4 SCAR=13.9
| |||||||||||||
| 126 | 2 | my $self = shift; | |||||||||||
| 127 | |||||||||||||
| 128 | 2 | foreach my $var (@BOOLEAN_CONFIGS) { | |||||||||||
| 129 | 40 | $self->{AppConfig}->define($var, { | |||||||||||
| 130 | ARGCOUNT => AppConfig::ARGCOUNT_NONE, | ||||||||||||
| 131 | }); | ||||||||||||
| 132 | } | ||||||||||||
| 133 | |||||||||||||
| 134 | 2 | foreach my $var (@SCALAR_CONFIGS) { | |||||||||||
| 135 | 70 | $self->{AppConfig}->define($var, { | |||||||||||
| 136 | ARGCOUNT => AppConfig::ARGCOUNT_ONE, | ||||||||||||
| 137 | }); | ||||||||||||
| 138 | } | ||||||||||||
| 139 | |||||||||||||
| 140 | 2 | foreach my $var (@LIST_CONFIGS) { | |||||||||||
| 141 | 8 | $self->{AppConfig}->define($var, { | |||||||||||
| 142 | ARGCOUNT => AppConfig::ARGCOUNT_LIST, | ||||||||||||
| 143 | }); | ||||||||||||
| 144 | } | ||||||||||||
| 145 | |||||||||||||
| 146 | 2 | return $self; | |||||||||||
| 147 | } | ||||||||||||
| 148 | |||||||||||||
| 149 | # Autoload passthrough to AppConfig, see comments on new() | ||||||||||||
| 150 | # for reasons why. | ||||||||||||
| 151 | 18 | ▶ | sub AUTOLOAD { | ||||||||||
|
Subroutine
AUTOLOAD: called CC=2 SCAR=7.0
| |||||||||||||
| 152 | 18 | my $self = shift; | |||||||||||
| 153 | 18 | my $auto = our $AUTOLOAD; | |||||||||||
| 154 | 18 | $auto =~ s/^PurpleWiki::Config:://; | |||||||||||
| 155 | 18 | ▶ | return if $auto eq 'DESTROY'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 156 | 18 | return $self->{AppConfig}->get($auto); | |||||||||||
| 157 | } | ||||||||||||
| 158 | |||||||||||||
| 159 | # Creates the strings and regular expressions used for | ||||||||||||
| 160 | # link matching. | ||||||||||||
| 161 | # | ||||||||||||
| 162 | # FIXME: with the parsers in place these are really | ||||||||||||
| 163 | # only used for checking to see if an incoming request | ||||||||||||
| 164 | # is kosher, which makes these a bit redundant. The | ||||||||||||
| 165 | # fat has been trimmed but it still leaves a fair | ||||||||||||
| 166 | # piece. | ||||||||||||
| 167 | 2 | ▶ | sub _initLinkPatterns { | ||||||||||
|
Subroutine
_initLinkPatterns: called CC=7 SCAR=20.5
| |||||||||||||
| 168 | 2 | my $self = shift; | |||||||||||
| 169 | 2 | my $LinkPattern; | |||||||||||
| 170 | my $FreeLinkPattern; | ||||||||||||
| 171 | |||||||||||||
| 172 | 2 | my ($UpperLetter, $LowerLetter, $AnyLetter, $LpA, $LpB, $QDelim); | |||||||||||
| 173 | |||||||||||||
| 174 | 2 | $UpperLetter = "[A-Z"; | |||||||||||
| 175 | 2 | $LowerLetter = "[a-z"; | |||||||||||
| 176 | 2 | $AnyLetter = "[A-Za-z"; | |||||||||||
| 177 | |||||||||||||
| 178 | 2 | ▶ | if ($self->NonEnglish) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 179 | 0 | $UpperLetter .= "\xc0-\xde"; | |||||||||||
| 180 | 0 | $LowerLetter .= "\xdf-\xff"; | |||||||||||
| 181 | 0 | $AnyLetter .= "\xc0-\xff"; | |||||||||||
| 182 | } | ||||||||||||
| 183 | |||||||||||||
| 184 | 2 | ▶ | if (!$self->SimpleLinks) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 185 | 2 | $AnyLetter .= "_0-9"; | |||||||||||
| 186 | } | ||||||||||||
| 187 | 2 | $UpperLetter .= "]"; $LowerLetter .= "]"; $AnyLetter .= "]"; | |||||||||||
| 188 | |||||||||||||
| 189 | # Main link pattern: lowercase between uppercase, then anything | ||||||||||||
| 190 | 2 | $LpA = $UpperLetter . "+" . $LowerLetter . "+" . $UpperLetter | |||||||||||
| 191 | . $AnyLetter . "*"; | ||||||||||||
| 192 | # Optional subpage link pattern: uppercase, lowercase, then anything | ||||||||||||
| 193 | 2 | $LpB = $UpperLetter . "+" . $LowerLetter . "+" . $AnyLetter . "*"; | |||||||||||
| 194 | |||||||||||||
| 195 | 2 | ▶ | if ($self->UseSubpage) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 196 | # Loose pattern: If subpage is used, subpage may be simple name | ||||||||||||
| 197 | 2 | $LinkPattern = "((?:(?:$LpA)?\\/$LpB)|$LpA)"; | |||||||||||
| 198 | # Strict pattern: both sides must be the main LinkPattern | ||||||||||||
| 199 | # $LinkPattern = "((?:(?:$LpA)?\\/)?$LpA)"; | ||||||||||||
| 200 | } else { | ||||||||||||
| 201 | 0 | $LinkPattern = "($LpA)"; | |||||||||||
| 202 | } | ||||||||||||
| 203 | |||||||||||||
| 204 | 2 | $QDelim = '(?:"")?'; # Optional quote delimiter (not in output) | |||||||||||
| 205 | 2 | $LinkPattern .= $QDelim; | |||||||||||
| 206 | |||||||||||||
| 207 | 2 | ▶ | if ($self->FreeLinks) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 208 | # Note: the - character must be first in $AnyLetter definition | ||||||||||||
| 209 | 2 | ▶ | if ($self->NonEnglish) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 210 | 0 | $AnyLetter = "[-,.()' _0-9A-Za-z\xc0-\xff]"; | |||||||||||
| 211 | } else { | ||||||||||||
| 212 | 2 | $AnyLetter = "[-,.()' _0-9A-Za-z]"; | |||||||||||
| 213 | } | ||||||||||||
| 214 | } | ||||||||||||
| 215 | |||||||||||||
| 216 | 2 | $FreeLinkPattern = "($AnyLetter+)"; | |||||||||||
| 217 | |||||||||||||
| 218 | 2 | ▶ | if ($self->UseSubpage) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 219 | 2 | $FreeLinkPattern = "((?:(?:$AnyLetter+)?\\/)?$AnyLetter+)"; | |||||||||||
| 220 | } | ||||||||||||
| 221 | 2 | $FreeLinkPattern .= $QDelim; | |||||||||||
| 222 | |||||||||||||
| 223 | 2 | $self->{AppConfig}->set('FreeLinkPattern', $FreeLinkPattern); | |||||||||||
| 224 | 2 | $self->{AppConfig}->set('LinkPattern', $LinkPattern); | |||||||||||
| 225 | |||||||||||||
| 226 | } | ||||||||||||
| 227 | |||||||||||||
| 228 | |||||||||||||
| 229 | 18 | 1; | |||||||||||
| 230 | __END__ | ||||||||||||