source: trunk/lib/OpenGuides/Config.pm @ 962

Last change on this file since 962 was 962, checked in by kake, 15 years ago

Add config option to place content above navbar in HTML.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.6 KB
Line 
1package OpenGuides::Config;
2use strict;
3use warnings;
4
5use Carp qw( croak );
6use Config::Tiny;
7
8use base qw( Class::Accessor );
9my @variables = qw(
10   dbtype dbname dbuser dbpass dbport dbhost dbencoding
11   script_name install_directory script_url
12   custom_lib_path use_plucene indexing_directory enable_page_deletion
13   admin_pass stylesheet_url site_name navbar_on_home_page
14   recent_changes_on_home_page content_above_navbar_in_html home_name
15   site_desc default_city default_country contact_email
16   default_language http_charset ping_services
17   formatting_rules_node formatting_rules_link backlinks_in_title template_path
18   custom_template_path geo_handler ellipsoid gmaps_api_key centre_long
19   show_gmap_in_node_display
20   centre_lat default_gmaps_zoom default_gmaps_search_zoom force_wgs84
21   licence_name licence_url licence_info_url moderation_requires_password
22   enable_node_image enable_common_categories enable_common_locales
23);
24my @questions = map { $_ . "__qu" } @variables;
25OpenGuides::Config->mk_accessors( @variables );
26OpenGuides::Config->mk_accessors( @questions );
27
28=head1 NAME
29
30OpenGuides::Config - Handle OpenGuides configuration variables.
31
32=head1 DESCRIPTION
33
34Does config stuff for OpenGuides.  Distributed and installed as part of
35the OpenGuides project, not intended for independent installation.
36This documentation is probably only useful to OpenGuides developers.
37
38=head1 METHODS
39
40=over
41
42=item B<new>
43
44  my $config = OpenGuides::Config->new( file => "wiki.conf" );
45
46Initialises itself from the config file specified.  Variables which
47are not set in that file, and which have sensible defaults, will be
48initialised as described below in ACCESSORS; others will be given a
49value of C<undef>.
50
51  my $config = OpenGuides::Config->new( vars => { dbname => "foo" } );
52
53As above but gets variables from a supplied hashref instead.
54
55=cut
56
57sub new {
58    my $class = shift;
59    my $self = { };
60    bless $self, $class;
61    return $self->_init( @_ );
62}
63
64sub _init {
65    my ($self, %args) = @_;
66
67    # Here are the defaults for the variable values.
68    # Don't forget to add to INSTALL when changing these.
69    my %defaults = (
70                     dbtype => "postgres",
71                     script_name => "wiki.cgi",
72                     install_directory => "/usr/lib/cgi-bin/openguides/",
73                     use_plucene => 1,
74                     indexing_directory => "/usr/lib/cgi-bin/openguides/indexes/",
75                     enable_page_deletion => 0,
76                     moderation_requires_password => 1,
77                     admin_pass => "Change This!",
78                     enable_node_image => 1,
79                     enable_common_categories => 0,
80                     enable_common_locales => 0,
81                     ping_services => "",
82                     site_name => "Unconfigured OpenGuides site",
83                     navbar_on_home_page => 1,
84                     recent_changes_on_home_page => 1,
85                     content_above_navbar_in_html => 0,
86                     home_name => "Home",
87                     site_desc => "A default configuration of OpenGuides",
88                     default_city => "",
89                     default_country => "",
90                     default_language => "en",
91                     http_charset => "",
92                     formatting_rules_node => "Text Formatting Examples",
93                     formatting_rules_link => "http://openguides.org/page/text_formatting",
94                     backlinks_in_title => 0,
95                     geo_handler => 1,
96                     ellipsoid => "WGS-84",
97                     show_gmap_in_node_display => 1,
98                     centre_long => 0,
99                     centre_lat => 0,
100                     default_gmaps_zoom => 5,
101                     default_gmaps_search_zoom => 3,
102                     force_wgs84 => 0,
103                     licence_name => "",
104                     licence_url => "",
105                     licence_info_url => ""
106                   );
107
108    # See if we already have some config variables set.
109    my %stored;
110    if ( $args{file} ) {
111        my $read_config = Config::Tiny->read( $args{file} ) or
112            croak "Cannot read config file '$args{file}': $Config::Tiny::errstr";
113        %stored = %{$read_config->{_}};
114    } elsif ( $args{vars} ) {
115        %stored = %{ $args{vars} };
116    }
117
118    # Set all defaults first, then set the stored values.  This allows us
119    # to make sure that the stored values override the defaults yet be sure
120    # to set any variables which have stored values but not defaults.
121    foreach my $var ( keys %defaults ) {
122        $self->$var( $defaults{$var} );
123    }
124    foreach my $var ( keys %stored ) {
125        if ( $self->can( $var ) ) { # handle any garbage in file gracefully
126            $self->$var( $stored{$var} );
127        } else {
128            warn "Don't know what to do with variable '$var'";
129        }
130    }
131
132    # And the questions.
133    # Don't forget to add to INSTALL when changing these.
134    my %questions = (
135        dbtype => "What type of database do you want the site to run on?  postgres/mysql/sqlite",
136        dbname => "What's the name of the database that this site runs on?",
137        dbuser => "...the database user that can access that database?",
138        dbpass => "...the password that they use to access the database?",
139        dbhost => "...the machine that the database is hosted on? (blank if local)",
140        dbport => "...the port the database is listening on? (blank if default)",
141        dbencoding => "...the encoding that your database uses? (blank if default)",
142        script_name => "What do you want the script to be called?",
143        install_directory => "What directory should I install it in?",
144        template_path => "What directory should I install the templates in?",
145        custom_template_path => "Where should I look for custom templates?",
146        script_url => "What URL does the install directory map to?",
147        custom_lib_path => "Do you want me to munge a custom lib path into the scripts?  If so, enter it here.  Separate path entries with whitespace.",
148        use_plucene => "Do you want to use Plucene for searching? (recommended, but see Changes file before saying yes to this if you are upgrading)",
149        indexing_directory => "What directory can I use to store indexes in for searching? ***NOTE*** This directory must exist and be writeable by the user that your script will run as.  See README for more on this.",
150        enable_page_deletion => "Do you want to enable page deletion?",
151        moderation_requires_password => "Is the admin password required for moderating pages?",
152        admin_pass => "Please specify a password for the site admin.",
153        stylesheet_url => "What's the URL of the site's stylesheet?",
154        enable_node_image => "Should nodes be allowed to have an externally hosted image?",
155        enable_common_categories => "Do you want a common list of categories shown on all node pages?",
156        enable_common_locales => "Do you want a common list of locales shown on all node pages?",
157        ping_services => "Which services do you wish to ping whenever you write a page? Can be pingerati, geourl, or both",
158        site_name => "What's the site called? (should be unique)",
159        navbar_on_home_page => "Do you want the navigation bar included on the home page?",
160        recent_changes_on_home_page => "Do you want the ten most recent changes included on the home page?",
161        content_above_navbar_in_html => "Do you want the content to appear above the navbar in the HTML?",
162        home_name => "What should the home page of the wiki be called?",
163        site_desc => "How would you describe the site?",
164        default_city => "What city is the site based in?",
165        default_country => "What country is the site based in?",
166        contact_email => "Contact email address for the site administrator?",
167        default_language => "What language will the site be in? (Please give an ISO language code.)",
168        http_charset => "What character set should we put in the http headers? (This won't change the character set internally, just what it's reported as). Leave blank for none to be sent",
169        formatting_rules_node => "What's the name of the node or page to use for the text formatting rules link (this is by default an external document, but if you make formatting_rules_link empty, it will be a wiki node instead",
170        formatting_rules_link => "What URL do you want to use for the text formatting rules (leave blank to use a wiki node instead)?",
171        backlinks_in_title => "Make node titles link to node backlinks (C2 style)?",
172        ellipsoid => "Which ellipsoid do you want to use? (eg 'Airy', 'WGS-84')",
173        gmaps_api_key => "Do you have a Google Maps API key to use with this guide? If you enter it here the Google Maps functionality will be automatically enabled.",
174        centre_long => "What is the longitude of the centre point of a map to draw for your guide? (This question can be ignored if you aren't using Google Maps). You may paste in a Google Maps URL here (hint: copy URL from 'Link to this page')",
175        centre_lat => "What is the latitude of the centre point of a map to draw for your guide? (This question can be ignored if you aren't using Google Maps)",
176        default_gmaps_zoom => "What default zoom level shall we use for Google Maps? (This question can be ignored if you aren't using Google Maps)",
177        default_gmaps_search_zoom => "What default zoom level shall we use for Google Maps in the search results? (This question can be ignored if you aren't using Google Maps)",
178        show_gmap_in_node_display => "Would you like to display a Google Map on every node that has geodata? (This question can be ignored if you aren't using Google Maps)",
179        force_wgs84 => "Forcibly treat stored lat/long data as if they used the WGS84 ellipsoid?",
180        licence_name => "What licence will you use for the guide?",
181        licence_url => "What is the URL to your licence?",
182        licence_info_url => "What is the URL to your local page about your licensing policy?"
183    );
184
185    foreach my $var ( keys %questions ) {
186        my $method = $var . "__qu";
187        $self->$method( $questions{$var} );
188    }
189
190    return $self;
191}
192
193=back
194
195=head1 ACCESSORS
196
197Each of the accessors described below is read-write.  Additionally,
198for each of them, there is also a read-write accessor called, for
199example, C<dbname__qu>.  This will contain an English-language
200question suitable for asking for a value for that variable.  You
201shouldn't write to them, but this is not enforced.
202
203The defaults mentioned below are those which are applied when
204C<< ->new >> is called, to variables which are not supplied in
205the config file.
206
207=over
208
209=item * dbname
210
211=item * dbuser
212
213=item * dbpass
214
215=item * dbhost
216
217=item * dbport
218
219=item * dbencoding
220
221=item * script_name (default: C<wiki.cgi>)
222
223=item * install_directory (default: C</usr/lib/cgi-bin/openguides/>)
224
225=item * script_url (this is constrained to always end in C</>)
226
227=cut
228
229sub script_url {
230    my $self = shift;
231    # See perldoc Class::Accessor - can't just use SUPER.
232    my $url = $self->_script_url_accessor( @_ );
233    $url .= "/" unless $url =~ /\/$/;
234    return $url;
235}
236
237=item * custom_lib_path
238
239=item * use_plucene (default: true)
240
241=item * indexing_directory (default: C</usr/lib/cgi-bin/openguides/indexes>)
242
243=item * enable_page_deletion (default: false)
244
245=item * admin_pass (default: C<Change This!>)
246
247=item * stylesheet_url
248
249=item * site_name (default: C<Unconfigured OpenGuides site>)
250
251=item * navbar_on_home_page (default: true)
252
253=item * recent_changes_on_home_page (default: true)
254
255=item * content_above_navbar_in_html (default: false)
256
257=item * home_name (default: C<Home>)
258
259=item * site_desc (default: C<A default configuration of OpenGuides>)
260
261=item * default_city (default: C<London>)
262
263=item * default_country (default: C<United Kingdom>)
264
265=item * default_language (default: C<en>)
266
267=item * http_charset
268
269=item * contact_email
270
271=item * formatting_rules_node (default: C<Text Formatting Examples>)
272
273=item * formatting_rules_link (default: C<http://openguides.org/page/text_formatting>
274
275=item * backlinks_in_title (default: false)
276
277=item * geo_handler (default: C<1>)
278
279=item * ellipsoid (default: C<WGS-84>)
280
281=item * gmaps_api_key
282
283=item * centre_long
284
285=item * centre_lat
286
287=item * default_gmaps_zoom
288
289=item * default_gmaps_search_zoom
290
291=item * show_gmap_in_node_display
292
293=item * force_wgs84
294
295=item * licence_name
296
297=item * licence_url
298
299=item * licence_info_url
300
301=back
302
303=head1 AUTHOR
304
305The OpenGuides Project (openguides-dev@lists.openguides.org)
306
307=head1 COPYRIGHT
308
309     Copyright (C) 2004-2007 The OpenGuides Project.  All Rights Reserved.
310
311The OpenGuides distribution is free software; you can redistribute it
312and/or modify it under the same terms as Perl itself.
313
314=head1 SEE ALSO
315
316L<OpenGuides>
317
318=cut
319
3201;
Note: See TracBrowser for help on using the repository browser.