Author: kake Date: 2008-05-01 20:53:01 +0100 (Thu, 01 May 2008) New Revision: 1158
Added: branches/new-install-process/bin/ branches/new-install-process/bin/openguides-install branches/new-install-process/bin/openguides-newpage-script branches/new-install-process/bin/openguides-preferences-script branches/new-install-process/bin/openguides-search-script branches/new-install-process/bin/openguides-wiki-script Removed: branches/new-install-process/newpage.cgi branches/new-install-process/preferences.cgi branches/new-install-process/search.cgi branches/new-install-process/wiki.cgi Modified: branches/new-install-process/Build.PL branches/new-install-process/MANIFEST branches/new-install-process/lib/OpenGuides/Config.pm Log: First bash at new install process - do not expect this commit to be bug-free.
Modified: branches/new-install-process/Build.PL =================================================================== --- branches/new-install-process/Build.PL 2008-05-01 19:24:56 UTC (rev 1157) +++ branches/new-install-process/Build.PL 2008-05-01 19:53:01 UTC (rev 1158) @@ -1,285 +1,56 @@ +use File::Copy; +use File::Spec; +use Module::Build; use strict; -use lib "lib"; -use Data::Dumper; -use Getopt::Long;
-eval { - require Config::Tiny; - # OpenGuides::Build and OpenGuides::Config both use Config::Tiny. - require OpenGuides::Build; - require OpenGuides::Config; -}; +# This magically subclasses Module::Build. We override the install action +# to install the template files for us. +my $class = Module::Build->subclass( + code => q{ + sub ACTION_install { + my $self = shift; + my $ret = $self->SUPER::ACTION_install(@_);
-die "Problem loading OpenGuides module or a missing module\n\n$@.\n" if $@; + # Slightly hacky. We require one of the modules that we just installed. + # then, we pull its path out of %INC, strip off the filename, and + # install the templates there. Well, they have to go _somewhere_, and + # perl doesn't have a good place for this stuff otherwise.
-my $force; + require OpenGuides or die; + my (undef, $path, undef) = File::Spec->splitpath($INC{'OpenGuides.pm'});
-GetOptions('force' => $force); + mkdir( File::Spec->catfile( $path, "OpenGuides" ) ); + die "Can't make template install folder: $!\n" unless (-d File::Spec->catfile( $path, "OpenGuides" ) );
-unless ($force) { - print <<EOF; + mkdir( File::Spec->catfile( $path, "OpenGuides", "templates" ) ); + die "Can't make template install folder: $!\n" unless (-d File::Spec->catfile( $path, "OpenGuides", "templates" ) );
-Beginning install process... if you already have an OpenGuides -configuration file and you don't want to have to type in all your config -parameters over again, abort this process now, copy that file to this -directory, and start again. + print "Installing templates to $path/OpenGuides/templates\n"; + opendir TEMPLATES, "templates" or die "Can't open template source folder: $!\n"; + for (grep { /.(tt)$/ } readdir(TEMPLATES)) { + print " installing template $_\n"; + File::Copy::copy( + File::Spec->catfile('templates', $_), + File::Spec->catfile( $path, "OpenGuides", "templates", $_ ) + ) or die "Error copying $_: $!\n";; + } + closedir(TEMPLATES);
-EOF - -my $continue = Module::Build->y_n("Continue with install?", "y"); -exit 0 unless $continue; -} - -my $existing_config_file = 'wiki.conf'; -my $existing_config; - -if (-f $existing_config_file) { - $existing_config = OpenGuides::Config->new(file => $existing_config_file); -} else { - print <<EOF; -No existing configuration file found; assuming this is a new install. -See the message above if this isn't correct. - -EOF - $existing_config = OpenGuides::Config->new(); -} - -my %yn_vars = map { $_ => 1 } - qw(use_plucene enable_page_deletion navbar_on_home_page backlinks_in_title - moderation_requires_password enable_node_image enable_common_categories - enable_common_locales recent_changes_on_home_page - random_page_omits_locales random_page_omits_categories - content_above_navbar_in_html show_gmap_in_node_display force_wgs84 - send_moderation_notifications); - -my $skip_config = $force ? 'y' : Module::Build->y_n("Skip OpenGuides configuration?", "n"); -if ( $skip_config ) { - print <<EOF; -=========================================================================== -Skipping OpenGuides configuration - any configuration options previously -saved will be used instead. You may tweak your configuration now by -editing the 'wiki.conf' file produced by this script. -=========================================================================== -EOF -} - -my @answers; - -# It is an ancient Configurer, and he chooseth one of three. -my $dbtype; -my $dbtype_qu = $existing_config->dbtype__qu; -if ( $skip_config ) { - $dbtype = $existing_config->dbtype; -} else { - until ( $dbtype ) { - my $def = $existing_config->dbtype; - $dbtype = Module::Build->prompt("\n$dbtype_qu", $def); - $dbtype = lc($dbtype); - $dbtype =~ s/^\s*//; - $dbtype =~ s/\s*$//; - unless ( $dbtype eq "postgres" or $dbtype eq "mysql" - or $dbtype eq "sqlite" ) { - undef $dbtype; - } + return $ret; } -} + }, +);
-# Check they have the relevant DBD driver installed. -my %drivers = ( postgres => "DBD::Pg", - mysql => "DBD::mysql", - sqlite => "DBD::SQLite", - ); -eval "require $drivers{$dbtype}"; -warn "$drivers{$dbtype} is needed to run a $dbtype database" if $@; - -push @answers, { question => $dbtype_qu, - variable => "dbtype", - value => $dbtype }; - -my $install_directory; # used to suggest template paths -my $use_plucene = 1; # keep track of this so we know what to put in prereqs -my $centre_lat = ''; # contains centre lat derived from Google Maps URL -foreach my $var ( qw( - dbname dbuser dbpass dbhost dbport script_name - install_directory template_path custom_template_path script_url - custom_lib_path use_plucene indexing_directory enable_page_deletion - admin_pass stylesheet_url site_name navbar_on_home_page - recent_changes_on_home_page random_page_omits_locales - random_page_omits_categories content_above_navbar_in_html home_name - site_desc default_city default_country contact_email default_language - formatting_rules_node backlinks_in_title gmaps_api_key centre_long - centre_lat show_gmap_in_node_display default_gmaps_zoom - default_gmaps_search_zoom force_wgs84 google_analytics_key - licence_name licence_url licence_info_url moderation_requires_password - enable_node_image enable_common_categories enable_common_locales - spam_detector_module host_checker_module static_path static_url - send_moderation_notifications - ) ) { - my $q_method = $var . "__qu"; - my $qu = $existing_config->$q_method; - my $type = $yn_vars{$var} ? "y_n" : ""; - my $def = $existing_config->$var; - my $val = $def; - - # Override dbname question for SQLite only. - if ( $dbtype eq "sqlite" and $var eq "dbname" ) { - $qu = "what's the full filename of the SQLite database this site runs on?"; - } - - if ( $dbtype eq "sqlite" and - ( $var eq "dbuser" or $var eq "dbpass" or $var eq "dbhost" or - $var eq "dbport") - ) { - print "$var not relevant for SQLite... skipping...\n" - unless $skip_config; - push @answers, { question => $qu, - variable => $var, - value => "not-used" }; - next; - } - - # We don't ask this for new installs as Search::InvertedIndex is - # deprecated - if ( $var eq "use_plucene" and $existing_config->$var == 1) { - print "Skipping question about plucene\n" - unless $skip_config; - push @answers, { question => $qu, - variable => $var, - value => 1 }; - next; - } - - # Make sensible suggestions for template paths if we don't already - # have them stored. Not really a default, but a useful hint/shortcut. - if ( $var eq "template_path" && !defined $existing_config->$var ) { - $def = $install_directory; - $def .= "/" unless $def =~ m|/$|; - $def .= "templates"; - } - if ( $var eq "custom_template_path" && !defined $existing_config->$var ) { - $def = $install_directory; - $def .= "/" unless $def =~ m|/$|; - $def .= "custom-templates"; - } - - # If a Google Maps URL was provided last time we know the centre_lat - if ( $var eq 'centre_lat' && $centre_lat ) { - $val = $centre_lat; - next; - } - - # Here is where we actually ask the questions. - unless ( $skip_config ) { - if ( $type eq "y_n" ) { - # may be stored as true/false integer value - if ( $def =~ /^\d+$/ ) { - $def = $def ? "y" : "n"; - } - $val = Module::Build->y_n("\n$qu ", $def); - } else { - $val = Module::Build->prompt("\n$qu ", $def); - } - } - - # Allow user to use a Google Maps URL rather than enter lat/long by hand. - # We assume centre_long is being asked for first; ensure so in big list above. - if ( $var eq 'centre_long' ) { - if ( $val =~ /ll=([-\d.]+),([-\d.]+)/ ) { - print "Got a Google Maps URL with centre long,lat: [$1, $2]\n"; - $val = $1; - $centre_lat = $2; - } - } - - # Store install_directory so we can use it to suggest template paths. - $install_directory = $val if $var eq "install_directory"; - - # Keep track of chosen search method so we know what to put in prereqs. - # From Module::Build docs: ->y_n returns a Perl boolean true or false. - $use_plucene = 1 if $var eq "use_plucene" and $val; - - # Make sure that script_url ends in a / - if ( $var eq "script_url" and $val !~ //$/ ) { - $val .= "/"; - } - - push @answers, { question => $qu, - variable => $var, - value => $val }; -} - -# Now deal with the geo stuff. -my $geo_handler; -my $geo_handler_qu = "Distance calculation methods available are:" - . "\n 1) British National Grid" - . "\n 2) Irish National Grid" - . "\n 3) UTM ellipsoid" - . "\nWhich would you like to use?"; - -if ( $skip_config ) { - # We default to GB National Grid for historical reasons. - $geo_handler = $existing_config->geo_handler; -} else { - my $choice; - until ( $choice ) { - my $def = $existing_config->geo_handler; - $choice = Module::Build->prompt("\n".$geo_handler_qu, $def); - $choice =~ s/^\s*//; - $choice =~ s/\s*$//; - unless ( $choice eq "1" or $choice eq "2" or $choice eq "3" ) { - undef $choice; - } - } - $geo_handler = $choice; -} - -$geo_handler_qu =~ s/\n//gs; -push @answers, { - question => $geo_handler_qu, - variable => "geo_handler", - value => $geo_handler, - }; - -if ( $geo_handler eq "3" ) { - my $qu = $existing_config->ellipsoid__qu; - my $ellipsoid; - if ( $skip_config ) { - $ellipsoid = $existing_config->ellipsoid; - } else { - my $def = $existing_config->ellipsoid; - $ellipsoid = Module::Build->prompt("\n".$qu, $def); - $ellipsoid =~ s/^\s*//; - $ellipsoid =~ s/\s*$//; - } - push @answers, { - question => $qu, - variable => "ellipsoid", - value => $ellipsoid, - }; -} - -# Create a user-friendly config file from answers to prompts. -open FILE, ">wiki.conf" or die "Can't open wiki.conf for writing: $!"; -foreach my $ans (@answers) { - print FILE "# $ans->{question}\n"; - print FILE "$ans->{variable} = $ans->{value}\n\n"; -} -close FILE or die "Can't close wiki.conf: $!"; - ##### ##### When updating the prereqs PLEASE REMEMBER to update PREREQUISITES. #####
-# We currently only support Plucene for new installs, but may support -# others in future -my $search_module = $use_plucene ? "Plucene" : "Search::InvertedIndex"; - # Create the build object. -my $build = OpenGuides::Build->new( +my $build = $class->new( sign => 1, dist_name => "OpenGuides", module_name => "OpenGuides", - dist_version_from => "wiki.cgi", + dist_version_from => "lib/OpenGuides.pm", license => "perl", requires => { 'Algorithm::Diff' => '0.13', # for sdiff @@ -297,16 +68,14 @@ 'Class::Accessor' => 0, 'Config::Tiny' => 0, 'Data::Dumper' => 0, - $drivers{$dbtype} => 0, 'File::Spec::Functions' => 0, 'File::Temp' => 0, - 'Geo::Coordinates::UTM' => 0, + 'Geo::Coordinates::UTM' => 0, 'Geography::NationalGrid' => 0, 'HTML::Entities' => 0, 'LWP::Simple' => 0, 'MIME::Lite' => 0, 'Parse::RecDescent' => 0, - $search_module => 0, 'POSIX' => 0, 'Template' => '2.15', # for hash.delete and string.remove vmethods 'Time::Piece' => 0, @@ -322,74 +91,22 @@ 'Wiki::Toolkit::Plugin::Ping' => 0, # for pinging external services 'Geo::HelmertTransform' => 0, # for correct WGS84 lat/long # when using grid systems + 'Plucene' => 0,
}, - dynamic_config => 1, - create_makefile_pl => "passthrough" + create_makefile_pl => "passthrough", + script_files => [ + "bin/openguides-install", + "bin/openguides-newpage-script", + "bin/openguides-preferences-script", + "bin/openguides-search-script", + "bin/openguides-wiki-script", + ], );
$build->add_to_cleanup( "t/indexes/" ); $build->add_to_cleanup( "t/node.db" ); $build->add_to_cleanup( "t/templates/tmp/" );
-# Tell OpenGuides::Build which additional scripts and templates to install. -$build->config_data( __extra_scripts => - [ "wiki.conf", "preferences.cgi", "search.cgi", - "newpage.cgi" ] ); -$build->config_data( __templates => [ - "admin_home.tt", - "admin_revert_user.tt", - "backlink_results.tt", - "banner.tt", - "blacklisted_host.tt", - "delete_confirm.tt", - "delete_done.tt", - "delete_password_wrong.tt", - "differences.tt", - "display_metadata.tt", - "edit_form.tt", - "edit_form_actions.tt", - "error.tt", - "footer.tt", - "header.tt", - "home_node.tt", - "map_index.tt", - "missing_metadata.tt", - "moderate_confirm.tt", - "moderate_password_wrong.tt", - "navbar.tt", - "navbar_categories.tt", - "navbar_locales.tt", - "navbar_help.tt", - "navbar_home_link.tt", - "navbar_options.tt", - "navbar_revision_info.tt", - "navbar_search.tt", - "navbar_this_page.tt", - "navbar_tools.tt", - "needing_moderation.tt", - "newpage.tt", - "node.tt", - "node_history.tt", - "node_image_fields.tt", - "node_photo_notes.tt", - "node_rdf.tt", - "openguides_information_boxes.tt", - "preferences.tt", - "random_page_failure.tt", - "rdf_index.tt", - "recent_changes.tt", - "search_results.tt", - "site_index.tt", - "search.tt", - "spam_detected.tt", - "userstats.tt", - "wanted_pages.tt" - ] ); - -$build->config_data( __static_files => [ - # XXX to be supplied when we have some - ] ); - # Finally write the build script. $build->create_build_script;
Modified: branches/new-install-process/MANIFEST =================================================================== --- branches/new-install-process/MANIFEST 2008-05-01 19:24:56 UTC (rev 1157) +++ branches/new-install-process/MANIFEST 2008-05-01 19:53:01 UTC (rev 1158) @@ -12,8 +12,12 @@ SIGNATURE TROUBLESHOOTING UPGRADING +bin/openguides-install +bin/openguides-newpage-script +bin/openguides-preferences-script +bin/openguides-search-script +bin/openguides-wiki-script examples/reindex.pl -lib/OpenGuides/Build.pm lib/OpenGuides/CGI.pm lib/OpenGuides/Config.pm lib/OpenGuides/Feed.pm @@ -23,9 +27,6 @@ lib/OpenGuides/Test.pm lib/OpenGuides/Utils.pm lib/OpenGuides.pm -newpage.cgi -preferences.cgi -search.cgi templates/admin_home.tt templates/admin_revert_user.tt templates/backlink_results.tt @@ -145,4 +146,3 @@ t/78_about.t t/79_host_blacklist.t t/templates/15_test.tt -wiki.cgi
Added: branches/new-install-process/bin/openguides-install =================================================================== --- branches/new-install-process/bin/openguides-install (rev 0) +++ branches/new-install-process/bin/openguides-install 2008-05-01 19:53:01 UTC (rev 1158) @@ -0,0 +1,545 @@ +#!/usr/bin/perl -w +use warnings; +use strict; +use Config::Tiny; +use ExtUtils::MM_Unix; # for fixing the shebang lines +use FindBin qw($Bin); +use File::Spec::Functions qw( catfile ); +use File::Copy; +use Getopt::Long; +use OpenGuides; # to get it into %INC for splitpath, below. +use OpenGuides::Config; +use Term::Prompt; + +# little utility function to find a script and make sure it's +x, etc. +sub find_script { + my $name = shift; + + # for preference, we find files in the same dir as us. Really handy + # for development. + my $file = catfile($Bin, $name); + + # It's not with me. Look in the path. + unless (-f $file) { chomp( $file = `which $name` ) } + + die "I can't find '$name' in $Bin or your path. Stopping.\n" + unless (-f $file); + die "I found '$name' at $file, but it's not executable. Stopping.\n" + unless (-x $file); + + return $file; +} + +sub show_help { + print qq( +To create an OpenGuides install, run + + openguides-install + +and answer the questions that it asks you. If you have an existing wiki.conf +file, then make sure it's in the current directory before you start. +); +} + +=head1 NAME + +openguides-install + +=head1 DESCRIPTION + +Creates an L<OpenGuides> install. + +=head1 USAGE + +To create an L<OpenGuides> install, run + + openguides-install + +and answer the questions that it asks you. If you have an existing +C<wiki.conf> file, then make sure it's in the current directory before you +start. + +To show this help, run + + openguides-install --help + +=cut + +my $show_help; +GetOptions( help => $show_help ); +if ( $show_help ) { + show_help(); + exit 0; +} + +# Map master copies of scripts to what they should be called. +my %targets; +foreach my $label ( qw( newpage preferences search wiki ) ) { + $targets{"$label.cgi"} = find_script( "openguides-$label-script" ); +} + +# The database setup script. +my $setup = find_script( "wiki-toolkit-setupdb" ); + +my $force; +GetOptions('force' => $force); +unless ($force) { + print "Beginning install process...\n"; + if ( ! -f "wiki.conf" ) { + print <<EOF; + +No existing configuration file found; assuming this is a new install. If you +already have an OpenGuides configuration file and you don't want to have to +type in all your config parameters over again, abort this process now, copy +that file to the current directory (and/or make sure you're in the directory +you intended to be in), and start again. + +EOF + } +} + +exit 0 unless prompt( "y", "Continue with install?", "y or n", "y" ); + +my $existing_config; + +if (-f "wiki.conf" ) { + $existing_config = OpenGuides::Config->new( file => "wiki.conf" ); +} else { + $existing_config = OpenGuides::Config->new(); +} + +my %yn_vars = map { $_ => 1 } + qw(use_plucene enable_page_deletion navbar_on_home_page backlinks_in_title + moderation_requires_password enable_node_image enable_common_categories + enable_common_locales recent_changes_on_home_page + random_page_omits_locales random_page_omits_categories + content_above_navbar_in_html show_gmap_in_node_display force_wgs84 + send_moderation_notifications); + +my $skip_config = $force ? 'y' + : prompt( "y", "Skip OpenGuides configuration?", + "y or n", "n" ); + +if ( $skip_config ) { + print <<EOF; +=========================================================================== +Skipping OpenGuides configuration - the wiki.conf in the current directory +will be used to select default configuration options. You may tweak your +configuration later by editing wiki.conf again after this script has had a +go at it. +=========================================================================== +EOF +} + +my @answers; + +# It is an ancient Configurer, and he chooseth one of three. +my $dbtype; +my $dbtype_qu = $existing_config->dbtype__qu; +if ( $skip_config ) { + $dbtype = $existing_config->dbtype; +} else { + my $default; + my @options = qw( postgres mysql sqlite ); + + foreach my $n ( ( 0 .. $#options ) ) { + if ( $options[$n] eq $existing_config->dbtype ) { + $default = $n + 1; # The +1 requirement might be a Term::Prompt bug + last; + } + } + + die "Invalid dbtype " . $existing_config->dbtype + unless $default; + + my $i = prompt( "m", { + prompt => "$dbtype_qu", + items => @options, + }, + undef, $default ); + $dbtype = $options[$i]; +} + +# Check they have the relevant DBD driver installed. +my %drivers = ( postgres => "DBD::Pg", + mysql => "DBD::mysql", + sqlite => "DBD::SQLite", + ); +eval "require $drivers{$dbtype}"; +warn "$drivers{$dbtype} is needed to run a $dbtype database" if $@; + +push @answers, { question => $dbtype_qu, + variable => "dbtype", + value => $dbtype }; + +my $install_directory; # used to suggest template paths +my $centre_lat = ''; # contains centre lat derived from Google Maps URL +my $script_name; # keep track of this for when we install the CGI scripts +my $template_path; # and this for when we install the templates +my $static_url; # and this for installing a stylesheet +my $static_path; # and this for printing a message when doing the above +my $install_stylesheet; # do we install a basic stylesheet or not +my $use_gmaps; # do we have a Google Maps API key, basically. + +# for setting up the database - shouldn't dbport be in here too? +my ( $dbname, $dbuser, $dbpass, $dbhost ) = ( "", "", "", "" ); + +my %is_gmaps_var = map { $_ => 1 } qw( centre_long centre_lat default_gmaps_zoom default_gmaps_search_zoom show_gmap_in_node_display ); + +foreach my $var ( qw( + dbname dbuser dbpass dbhost dbport script_name + install_directory template_path custom_template_path script_url + custom_lib_path use_plucene indexing_directory enable_page_deletion + admin_pass static_path static_url stylesheet_url + site_name navbar_on_home_page + recent_changes_on_home_page random_page_omits_locales + random_page_omits_categories content_above_navbar_in_html home_name + site_desc default_city default_country contact_email default_language + formatting_rules_node backlinks_in_title gmaps_api_key centre_long + centre_lat show_gmap_in_node_display default_gmaps_zoom + default_gmaps_search_zoom force_wgs84 google_analytics_key + licence_name licence_url licence_info_url moderation_requires_password + enable_node_image enable_common_categories enable_common_locales + spam_detector_module host_checker_module + send_moderation_notifications + ) ) { + my $q_method = $var . "__qu"; + my $qu = $existing_config->$q_method; + my $type = $yn_vars{$var} ? "y_n" : ""; + my $def = $existing_config->$var || ""; + my $val = $def; + + # Override dbname question for SQLite only. + if ( $dbtype eq "sqlite" and $var eq "dbname" ) { + $qu = "what's the full filename of the SQLite database this site runs on?"; + } + + if ( $dbtype eq "sqlite" and + ( $var eq "dbuser" or $var eq "dbpass" or $var eq "dbhost" or + $var eq "dbport") + ) { + print "$var not relevant for SQLite... skipping...\n" + unless $skip_config; + push @answers, { question => $qu, + variable => $var, + value => "not-used" }; + next; + } + + # Make sensible suggestions for template paths if we don't already + # have them stored. Not really a default, but a useful hint/shortcut. + if ( $var eq "template_path" && !defined $existing_config->$var ) { + $def = $install_directory; + $def .= "/" unless $def =~ m|/$|; + $def .= "templates"; + } + if ( $var eq "custom_template_path" && !defined $existing_config->$var ) { + $def = $install_directory; + $def .= "/" unless $def =~ m|/$|; + $def .= "custom-templates"; + } + + # If a Google Maps URL was provided last time we know the centre_lat + if ( $var eq 'centre_lat' && $centre_lat ) { + $val = $centre_lat; + next; + } + + # Term::Prompt doesn't like blank answers, so we ask a yes-no question + # about munging in a lib path before we actually ask for the path. Most + # people will want to say "no" to this option, anyway. The $def variable + # will either be blank (no munging) or will contain the required path(s). + unless ( $skip_config ) { + if ( $var eq "custom_lib_path" ) { + my $yn_def = $def ? "y" : "n"; + my $munge = prompt( "y", $qu, + "if you don't understand this question, answer "n"", $yn_def ); + if ( $munge ) { + $val = prompt( "x", "Please enter your lib path here. " + . "Separate path entries with whitespace.", + "", $def ); + } else { + $val = ""; + } + push @answers, { question => $qu, + variable => $var, + value => $val }; + next; + } + } + + # Skip Google Maps questions if we have no API key. + if ( $is_gmaps_var{$var} && !$use_gmaps ) { + next; + } + + # Again, because Term::Prompt doesn't like blank answers. + unless ( $skip_config ) { + if ( $var eq "google_analytics_key" + || $var eq "gmaps_api_key" + || $var eq "spam_detector_module" + || $var eq "host_checker_module" ) { + my $yn_def = $def ? "y" : "n"; + my $do_it = prompt( "y", $qu, + "if you don't understand this question, answer "n"", + $yn_def ); + if ( $do_it ) { + $val = prompt( "x", "Please enter it here", "", $def ); + } else { + $val = ""; + } + # Keep track of whether they have a GMaps API key as if they don't + # then we can skip some later questions. + if ( $var eq "gmaps_api_key" ) { + $use_gmaps = $do_it; + } + push @answers, { question => $qu, + variable => $var, + value => $val }; + next; + } + } + + # They have the option of using their own stylesheet, or having us install + # one for them. NOTE: we don't reinstall the stylesheet if things change, + # this is a one-off. The $def variable will either be blank (if this is + # a fresh install) or will contain the stylesheet URL. + if ( $var eq "stylesheet_url" && !$skip_config ) { + my $yn_def = $def ? "y" : "n"; + $install_stylesheet = prompt( "y", + "Would you like to have a basic stylesheet installed for you?", + "y or n", $yn_def ); + if ( $install_stylesheet ) { + # just install the stylesheet in the static content + print "OK, will install style.css in $static_path\n"; + $val = $static_url . "style.css"; + push @answers, { question => $qu, + variable => $var, + value => $val }; + next; + } + } + + # Here is where we actually ask the questions. + unless ( $skip_config ) { + if ( $type eq "y_n" ) { + # may be stored as true/false integer value + if ( $def =~ /^\d+$/ ) { + $def = $def ? "y" : "n"; + } + $val = prompt( "y", $qu, "y or n", $def ); + } else { + $val = prompt( "x", $qu, "", $def ); + } + } + + # Plucene is currently the recommended search backend as it seems to have + # fewer bugs than the other options. + if ( $var eq "use_plucene" && $val ) { + eval "require Plucene"; + if ( $@ ) { + print "\n***NOTE*** Plucene not found - you will need to install " + . "it before running this\nOpenGuides instance.\n\n"; + } + } + + # Allow user to use a Google Maps URL rather than enter lat/long by hand. + # Assume centre_long is being asked for first; ensure so in big list above. + if ( $var eq 'centre_long' ) { + if ( $val =~ /ll=([-\d.]+),([-\d.]+)/ ) { + print "Got a Google Maps URL with centre long,lat: [$1, $2]\n"; + $val = $1; + $centre_lat = $2; + } + } + + # Make sure that script_url and static_url both end in a / + if ( $var eq "script_url" || $var eq "static_url" ) { + if ( $val !~ //$/ ) { + $val .= "/"; + } + } + + # Store install_directory so we can use it to suggest template paths. + $install_directory = $val if $var eq "install_directory"; + + # And the static content URL (for stylesheet installation default). + $static_url = $val if $var eq "static_url"; + $static_path = $val if $var eq "static_path"; + + # Store the script name and template path for use lower down. + $script_name = $val if $var eq "script_name"; + if ( $var eq "template_path" ) { + $template_path = $val; + } + + # Store database vars for setting up the DB. + if ( $var eq "dbname" ) { + $dbname = $val; + } + if ( $var eq "dbuser" ) { + $dbuser = $val; + } + if ( $var eq "dbpass" ) { + $dbpass = $val; + } + if ( $var eq "dbhost" ) { + $dbhost = $val; + } + + push @answers, { question => $qu, + variable => $var, + value => $val }; +} + +# Now deal with the geo stuff. +my $geo_handler; +my $geo_handler_qu = "How would you like to calculate distances?"; + +if ( $skip_config ) { + # We default to GB National Grid for historical reasons. + $geo_handler = $existing_config->geo_handler; +} else { + my $default = $existing_config->geo_handler; + my @options = ( "British National Grid", + "Irish National Grid", + "UTM ellipsoid" ); + $geo_handler = prompt( "m", { + prompt => $geo_handler_qu, + items => @options, + return_base => 1, + }, + "1, 2, or 3", $default ); +} + +push @answers, { + question => $geo_handler_qu, + variable => "geo_handler", + value => $geo_handler, + }; + +if ( $geo_handler eq "3" ) { + my $qu = $existing_config->ellipsoid__qu; + my $ellipsoid; + if ( $skip_config ) { + $ellipsoid = $existing_config->ellipsoid; + } else { + my $def = $existing_config->ellipsoid; + $ellipsoid = prompt( "x", $qu, undef, $def ); + $ellipsoid =~ s/^\s*//; + $ellipsoid =~ s/\s*$//; + } + push @answers, { + question => $qu, + variable => "ellipsoid", + value => $ellipsoid, + }; +} + +# Create a user-friendly config file from answers to prompts. +open FILE, ">wiki.conf" or die "Can't open wiki.conf for writing: $!"; +foreach my $ans (@answers) { + print FILE "# $ans->{question}\n"; + print FILE "$ans->{variable} = $ans->{value}\n\n"; +} +close FILE or die "Can't close wiki.conf: $!"; + +# Find the templates from where we stored them when we installed OpenGuides. +#use Data::Dumper; print Dumper %INC; +my (undef, $path, undef) = File::Spec->splitpath($INC{'OpenGuides.pm'}); +my $templates = File::Spec->catfile( $path, "OpenGuides", "templates" ); +die "Can't find OpenGuides templates in '$path'" + unless (-d $templates); + +# Munge %targets to account for what they want the main script to be called. +if ( $script_name ne "wiki.cgi" ) { + $targets{$script_name} = $targets{"wiki.cgi"}; + delete $targets{"wiki.cgi"}; +} + +# Install! +print "Installing OpenGuides...\n"; + +print " installing cgi scripts\n"; +foreach my $target ( keys %targets ) { + my $dest = File::Spec->catfile( $install_directory, $target ); + copy( $targets{$target}, $dest) + or die "Can't install $target to $dest - $!\n"; + # The below throws spurious warnings (EU::MM 6.44) because our shebang + # lines have no options. I don't understand why this didn't happen with + # Module::Build->fix_shebang_line though. + ExtUtils::MM_Unix->fixin( $dest ); + chmod( 0755, $dest ) + or die "Can't make $dest executable - $!\n"; +} + +print " installing wiki.conf\n"; +copy( "wiki.conf", $install_directory ) + or die "Can't install wiki.conf in $install_directory - $!\n"; +#chmod( 0600, File::Spec->catfile( $install_directory, "wiki.conf" ) ) +# or die "Can't read-protect wiki.conf in $install_directory: $!\n"; + +my $mentionswikidotconf = 0; +my $htaccess = File::Spec->catfile( $install_directory, ".htaccess" ); +print "Trying to ensure that wiki.conf is protected by .htaccess...\n"; +if ( -f $htaccess ) { + if ( open HTACCESS, $htaccess ) { + while ( <HTACCESS> ) { + if ( /wiki.conf/ ) { + $mentionswikidotconf = 1; + } + } + close HTACCESS; + } else { + warn "Couldn't open $htaccess for reading: $!"; + } +} + +if ( $mentionswikidotconf ) { + print ".htaccess appears to already mention wiki.conf.\n"; +} else { + if ( open HTACCESS, ">>$htaccess" ) { + print HTACCESS "# Added by openguides-install script\n"; + print HTACCESS "<Files wiki.conf>\ndeny from all\n</Files>\n"; + close HTACCESS; + print "apparent success. You should check that this is working!\n"; + } else { + warn "Couldn't open $htaccess for writing: $!"; + } +} + +print " Installing templates to $template_path...\n"; +unless ( -d $template_path ) { + mkdir $template_path or die "Can't make template dir: $!"; +} +opendir TEMPLATES, $templates or die "Can't open template source folder: $!\n"; +for (grep { /(.tt)$/ } readdir(TEMPLATES)) { + File::Copy::copy( + File::Spec->catfile($templates, $_), + File::Spec->catfile($template_path, $_ ) + ) or die "Error copying $_: $!\n"; +} +closedir(TEMPLATES); + +print " setting up DB\n"; + +my %setup_modules = ( postgres => "Wiki::Toolkit::Setup::Pg", + mysql => "Wiki::Toolkit::Setup::MySQL", + sqlite => "Wiki::Toolkit::Setup::SQLite", + ); + +my $class = $setup_modules{$dbtype}; +eval "require $class"; +if ( $@ ) { + print "Couldn't 'use' $class: $@\n"; + exit 1; +} + +{ + no strict 'refs'; + &{$class."::setup"}($dbname, $dbuser, $dbpass, $dbhost); +} + +print "Installation complete.\n"; + +
Property changes on: branches/new-install-process/bin/openguides-install ___________________________________________________________________ Name: svn:executable + *
Added: branches/new-install-process/bin/openguides-newpage-script =================================================================== --- branches/new-install-process/bin/openguides-newpage-script (rev 0) +++ branches/new-install-process/bin/openguides-newpage-script 2008-05-01 19:53:01 UTC (rev 1158) @@ -0,0 +1,91 @@ +#!/usr/local/bin/perl + +use warnings; +use strict; + +use CGI; +use OpenGuides::Config; +use OpenGuides::Template; +use OpenGuides::Utils; +use URI::Escape; + +my @badchars = qw( & ? _ ); +push @badchars, '#'; # Avoid warning about possible comments in qw() + +my $q = CGI->new; +my $config_file = $ENV{OPENGUIDES_CONFIG_FILE} || "wiki.conf"; +my $config = OpenGuides::Config->new( file => $config_file ); +my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); + +my $pagename = $q->param("pagename") || ""; +$pagename =~ s/^\s*//; +$pagename =~ s/\s*$//; + +my $action = $q->param("action") || ""; + +if ( $action eq "makepage" ) { + make_page(); +} else { + show_form(); +} + +sub show_form { + print OpenGuides::Template->output( wiki => $wiki, + config => $config, + template => "newpage.tt", + vars => { + not_editable => 1, + not_deletable => 1, + deter_robots => 1, + disallowed_chars => @badchars, + pagename => $pagename } + ); +} + +sub make_page { + # Ensure pagename not blank. + unless ( $pagename ) { + print OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "error.tt", + vars => { not_editable => 1, + not_deletable => 1, + deter_robots => 1, + message => "Please enter a page name!", + return_url => "newpage.cgi" } ); + return 0; + } + + # Ensure pagename valid. + my %badhash = map { $_ => 1 } @badchars; + my @naughty; + foreach my $i ( 0 .. (length $pagename) - 1 ) { + my $char = substr( $pagename, $i, 1 ); + push @naughty, $char if $badhash{$char}; + } + if ( scalar @naughty ) { + my $message = "Page name $pagename contains disallowed characters"; + print OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "error.tt", + vars => { + pagename => $pagename, + not_editable => 1, + not_deletable => 1, + deter_robots => 1, + message => $message, + return_url => "newpage.cgi?pagename=" . uri_escape($pagename) + } + ); + return 0; + } + + # Hurrah, we're OK. + my $node_param = $wiki->formatter->node_name_to_node_param($pagename); + print "Location: ".$config->script_url.$config->script_name."?action=edit;id=$node_param\n\n"; + return 0; +} + +
Property changes on: branches/new-install-process/bin/openguides-newpage-script ___________________________________________________________________ Name: svn:executable + *
Added: branches/new-install-process/bin/openguides-preferences-script =================================================================== --- branches/new-install-process/bin/openguides-preferences-script (rev 0) +++ branches/new-install-process/bin/openguides-preferences-script 2008-05-01 19:53:01 UTC (rev 1158) @@ -0,0 +1,61 @@ +#!/usr/bin/perl + +use warnings; +use strict; + +use CGI; +use OpenGuides::Config; +use OpenGuides::CGI; +use OpenGuides::Utils; +use OpenGuides::Template; + +my $config_file = $ENV{OPENGUIDES_CONFIG_FILE} || "wiki.conf"; +my $config = OpenGuides::Config->new( file => $config_file ); +my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); +my $cgi = CGI->new(); +my $action = $cgi->param('action') || ''; + +if ( $action eq "set_preferences" ) { + set_preferences(); +} else { + show_form(); +} + +sub set_preferences { + my %prefs = OpenGuides::CGI->get_prefs_from_hash( $cgi->Vars ); + my $prefs_cookie = OpenGuides::CGI->make_prefs_cookie( + config => $config, + %prefs, + ); + my @cookies = ( $prefs_cookie ); + # If they've asked not to have their recent changes visits tracked, + # clear any existing recentchanges cookie. + if ( ! $prefs{track_recent_changes_views} ) { + my $rc_cookie = OpenGuides::CGI->make_recent_changes_cookie( + config => $config, + clear_cookie => 1, + ); + push @cookies, $rc_cookie; + } + print OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "preferences.tt", + cookies => @cookies, + vars => { + not_editable => 1, + } + ); +} + +sub show_form { + print OpenGuides::Template->output( + wiki => $wiki, + config => $config, + template => "preferences.tt", + vars => { + not_editable => 1, + show_form => 1 + } + ); +}
Property changes on: branches/new-install-process/bin/openguides-preferences-script ___________________________________________________________________ Name: svn:executable + *
Added: branches/new-install-process/bin/openguides-search-script =================================================================== --- branches/new-install-process/bin/openguides-search-script (rev 0) +++ branches/new-install-process/bin/openguides-search-script 2008-05-01 19:53:01 UTC (rev 1158) @@ -0,0 +1,14 @@ +#!/usr/local/bin/perl + +use warnings; +use strict; + +use CGI; +use OpenGuides::Config; +use OpenGuides::Search; + +my $config_file = $ENV{OPENGUIDES_CONFIG_FILE} || "wiki.conf"; +my $config = OpenGuides::Config->new( file => $config_file ); +my $search = OpenGuides::Search->new( config => $config ); +my %vars = CGI::Vars(); +$search->run( vars => %vars );
Property changes on: branches/new-install-process/bin/openguides-search-script ___________________________________________________________________ Name: svn:executable + *
Added: branches/new-install-process/bin/openguides-wiki-script =================================================================== --- branches/new-install-process/bin/openguides-wiki-script (rev 0) +++ branches/new-install-process/bin/openguides-wiki-script 2008-05-01 19:53:01 UTC (rev 1158) @@ -0,0 +1,375 @@ +#!/usr/local/bin/perl + +use strict; +use warnings; + +use vars qw( $VERSION ); +$VERSION = '0.61'; + +use CGI qw/:standard/; +use CGI::Carp qw(croak); +use Wiki::Toolkit; +use Geography::NationalGrid; +use Geography::NationalGrid::GB; +use OpenGuides; +use OpenGuides::CGI; +use OpenGuides::Config; +use OpenGuides::RDF; +use OpenGuides::Utils; +use OpenGuides::Template; +use Time::Piece; +use URI::Escape; + +my $config_file = $ENV{OPENGUIDES_CONFIG_FILE} || "wiki.conf"; +my $config = OpenGuides::Config->new( file => $config_file ); + +my $script_name = $config->script_name; +my $script_url = $config->script_url; + +my ($guide, $wiki, $formatter, $q); +eval { + $guide = OpenGuides->new( config => $config ); + $wiki = $guide->wiki; + $formatter = $wiki->formatter; + + # Get CGI object, find out what to do. + $q = CGI->new; + + # Note $q->param('keywords') gives you the entire param string. + # We need this to do URLs like foo.com/wiki.cgi?This_Page + my $node = $q->param('id') || $q->param('title') || $q->param('keywords') || ''; + $node = $formatter->node_param_to_node_name( $node ); + + # If we did a post, then CGI->param probably hasn't fully de-escaped, + # in the same way as a get would've done + my $request_method = $q->request_method() || ''; + if($request_method eq 'POST') { + $node = uri_unescape($node); + } + + # Grab our common parameters + my $action = $q->param('action') || 'display'; + my $commit = $q->param('Save') || 0; + my $preview = $q->param('preview') || 0; + my $search_terms = $q->param('terms') || $q->param('search') || ''; + my $format = $q->param('format') || ''; + my $oldid = $q->param('oldid') || ''; + + # Alternative method of calling search, supported by usemod. + $action = 'search' if $q->param("search"); + + if ($commit) { + $guide->commit_node( + id => $node, + cgi_obj => $q, + ); + } elsif ($preview) { + $guide->preview_edit( + id => $node, + cgi_obj => $q, + ); + } elsif ($action eq 'edit') { + $guide->display_edit_form( id => $node ); + } elsif ($action eq 'search') { + do_search($search_terms); + } elsif ($action eq 'show_backlinks') { + $guide->show_backlinks( id => $node ); + } elsif ($action eq 'show_wanted_pages') { + show_wanted_pages(); + } elsif ($action eq 'show_needing_moderation') { + show_needing_moderation(); + } elsif ($action eq 'index') { + $guide->show_index( + type => $q->param("index_type") || "Full", + value => $q->param("index_value") || "", + format => $format, + ); + } elsif ($action eq 'random') { + print $guide->display_random_page( + category => $q->param( "category" ) || "", + locale => $q->param( "locale" ) || "", + ); + } elsif ($action eq 'find_within_distance') { + $guide->find_within_distance( + id => $node, + metres => $q->param("distance_in_metres") + ); + } elsif ( $action eq 'admin' ) { + $guide->display_admin_interface( + moderation_completed => $q->param("moderation"), + ); + } elsif ( $action eq 'revert_user' ) { + $guide->revert_user_interface( + username => $q->param("username") || "", + host => $q->param("host") || "", + password => $q->param("password") || "", + ); + } elsif ( $action eq 'show_missing_metadata' ) { + $guide->show_missing_metadata( + metadata_type => $q->param("metadata_type") || "", + metadata_value => $q->param("metadata_value") || "", + exclude_locales => $q->param("exclude_locales") || "", + exclude_categories => $q->param("exclude_categories") || "" + ); + } elsif ( $action eq 'set_moderation' ) { + $guide->set_node_moderation( + id => $node, + password => $q->param("password") || "", + moderation_flag => $q->param("moderation_flag") || "", + ); + } elsif ( $action eq 'moderate' ) { + $guide->moderate_node( + id => $node, + version => $q->param("version") || "", + password => $q->param("password") || "", + ); + } elsif ( $action eq 'delete' + and ( lc($config->enable_page_deletion) eq "y" + or $config->enable_page_deletion eq "1" ) + ) { + $guide->delete_node( + id => $node, + version => $q->param("version") || "", + password => $q->param("password") || "", + ); + } elsif ($action eq 'userstats') { + show_userstats( + username => $q->param("username") || "", + host => $q->param("host") || "", + ); + } elsif ($action eq 'list_all_versions') { + if($format && ($format eq "rss" || $format eq "atom")) { + my %args = ( + feed_type => $format, + feed_listing => 'node_all_versions', + name => $node + ); + $guide->display_feed( %args ); + } else { + $guide->list_all_versions( id => $node ); + } + } elsif ($action eq 'rc') { + if ($format && $format eq 'rss') { + my $feed = $q->param("feed"); + if ( !defined $feed or $feed eq "recent_changes" ) { + my %args = map { $_ => ( $q->param($_) || "" ) } + qw( feed items days ignore_minor_edits username + category locale ); + $args{feed_type} = 'rss'; + $args{feed_listing} = 'recent_changes'; + $guide->display_feed( %args ); + } elsif ( $feed eq "chef_dan" ) { + display_node_rdf( node => $node ); + } else { + croak "Unknown RSS feed type '$feed'"; + } + } elsif ($format && $format eq 'atom') { + my %args = map { $_ => ( $q->param($_) || "" ) } + qw( feed items days ignore_minor_edits username + category locale ); + $args{feed_type} = 'atom'; + $args{feed_listing} = 'recent_changes'; + $guide->display_feed( %args ); + } else { + $guide->display_node( id => 'RecentChanges' ); + } + } elsif ($action eq 'rss') { + my $redir_target = $script_url . $script_name . '?action=rc;format=rss'; + my %args = map { $_ => ( $q->param($_) || "" ) } + qw( feed items days ignore_minor_edits username + category locale ); + foreach my $arg (sort keys %args) { + if ($args{$arg} ne "") { + $redir_target .= ";$arg=$args{$arg}"; + } + } + print $q->redirect( $redir_target ); + } elsif ($action eq 'about') { + $guide->display_about(format => $format); + } elsif ($action eq 'display') { + if ( $format and $format eq "rdf" ) { + display_node_rdf( node => $node ); + } elsif ( $format and $format eq 'raw' ) { + $guide->display_node( + id => $node, + format => 'raw', + ); + } else { + my $version = $q->param("version"); + my $other_ver = $q->param("diffversion"); + if ( $other_ver ) { + $guide->display_diffs( + id => $node, + version => $version, + other_version => $other_ver, + ); + } else { + my $redirect; + + if ((defined $q->param("redirect")) && ($q->param("redirect") == 0)) { + $redirect = 0; + } else { + $redirect = 1; + } + + $guide->display_node( + id => $node, + version => $version, + oldid => $oldid, + redirect => $redirect, + ); + } + } + } else { + # Fallback: redirect to the display page, preserving all vars + # except for the action, which we override. + # Note: $q->Vars needs munging if we need to support any + # multi-valued params + my $params = $q->Vars; + $params->{'action'} = 'display'; + my $redir_target = $script_url . $script_name . '?'; + my @args = map { "$_=" . $params->{$_} } keys %{$params}; + $redir_target .= join ';', @args; + + print $q->redirect( + -uri => $redir_target, + -status => 303 + ); + } + +}; + +if ($@) { + my $error = $@; + warn $error; + print $q->header; + my $contact_email = $config->contact_email; + print qq(<html><head><title>ERROR</title></head><body> + <p>Sorry! Something went wrong. Please contact the + Wiki administrator at + <a href="mailto:$contact_email">$contact_email</a> and quote + the following error message:</p><blockquote>) + . $q->escapeHTML($error) + . qq(</blockquote><p><a href="$script_name">Return to the Wiki home page</a> + </body></html>); +} + +############################ subroutines ################################### + +sub show_userstats { + my %args = @_; + my ($username, $host) = @args{ qw( username host ) }; + croak "No username or host supplied to show_userstats" + unless $username or $host; + my %criteria = ( last_n_changes => 5 ); + $criteria{metadata_was} = $username ? { username => $username } + : { host => $host }; + my @nodes = $wiki->list_recent_changes( %criteria ); + @nodes = map { {name => $q->escapeHTML($_->{name}), + last_modified => $q->escapeHTML($_->{last_modified}), + comment => OpenGuides::Utils::parse_change_comment( + $q->escapeHTML($_->{metadata}{comment}[0]), + $script_url . '?', + ), + url => "$script_name?" + . $q->escape($formatter->node_name_to_node_param($_->{name})) } + } @nodes; + my %tt_vars = ( last_five_nodes => @nodes, + username => $username, + username_param => $wiki->formatter->node_name_to_node_param($username), + host => $host, + ); + process_template("userstats.tt", "", %tt_vars); +} + +sub get_cookie { + my $pref_name = shift or return ""; + my %cookie_data = OpenGuides::CGI->get_prefs_from_cookie(config=>$config); + return $cookie_data{$pref_name}; +} + +sub display_node_rdf { + my %args = @_; + my $rdf_writer = OpenGuides::RDF->new( wiki => $wiki, + config => $config ); + print "Content-type: application/rdf+xml\n\n"; + print $rdf_writer->emit_rdfxml( node => $args{node} ); +} + +sub process_template { + my ($template, $node, $vars, $conf, $omit_header) = @_; + + my %output_conf = ( wiki => $wiki, + config => $config, + node => $node, + template => $template, + vars => $vars + ); + $output_conf{noheaders} = 1 if $omit_header; # defaults otherwise + print OpenGuides::Template->output( %output_conf ); +} + + +sub do_search { + my $terms = shift; + my %finds = $wiki->search_nodes($terms); +# my @sorted = sort { $finds{$a} cmp $finds{$b} } keys %finds; + my @sorted = sort keys %finds; + my @results = map { + { url => $q->escape($formatter->node_name_to_node_param($_)), + title => $q->escapeHTML($_) + } } @sorted; + my %tt_vars = ( results => @results, + num_results => scalar @results, + not_editable => 1, + search_terms => $q->escapeHTML($terms) ); + process_template("search_results.tt", "", %tt_vars); +} + +sub show_wanted_pages { + my @dangling = $wiki->list_dangling_links; + my @wanted; + my %backlinks_count; + foreach my $node_name (@dangling) { + $backlinks_count{$node_name} = scalar($wiki->list_backlinks( node => $node_name )); + } + foreach my $node_name (sort { $backlinks_count{$b} <=> $backlinks_count{$a} } @dangling) { + my $node_param = + uri_escape($formatter->node_name_to_node_param($node_name)); + push @wanted, { + name => $q->escapeHTML($node_name), + edit_link => $script_url . uri_escape($script_name) + . "?action=edit;id=$node_param", + backlink_link => $script_url . uri_escape($script_name) + . "?action=show_backlinks;id=$node_param", + backlinks_count => $backlinks_count{$node_name} + }; + } + process_template( "wanted_pages.tt", + "", + { not_editable => 1, + not_deletable => 1, + deter_robots => 1, + wanted => @wanted } ); +} + +sub show_needing_moderation { + my @nodes = $wiki->list_unmoderated_nodes; + + # Build the moderate links + foreach my $node (@nodes) { + my $node_param = + uri_escape($formatter->node_name_to_node_param($node->{'name'})); + $node->{'moderate_url'} = $script_name . "?action=moderate;id=".$node_param.";version=".$node->{'version'}; + $node->{'view_url'} = $script_name . "?id=".$node_param.";version=".$node->{'version'}; + $node->{'diff_url'} = $script_name . "?id=".$node_param.";version=".$node->{'moderated_version'}.";diffversion=".$node->{'version'}; + $node->{'delete_url'} = $script_name . "?action=delete;version=".$node->{'version'}.";id=".$node_param; + } + + process_template( "needing_moderation.tt", + "", + { not_editable => 1, + not_deletable => 1, + deter_robots => 1, + nodes => @nodes } ); +}
Property changes on: branches/new-install-process/bin/openguides-wiki-script ___________________________________________________________________ Name: svn:executable + *
Modified: branches/new-install-process/lib/OpenGuides/Config.pm =================================================================== --- branches/new-install-process/lib/OpenGuides/Config.pm 2008-05-01 19:24:56 UTC (rev 1157) +++ branches/new-install-process/lib/OpenGuides/Config.pm 2008-05-01 19:53:01 UTC (rev 1158) @@ -73,7 +73,7 @@ # Here are the defaults for the variable values. # Don't forget to add to INSTALL when changing these. my %defaults = ( - dbtype => "postgres", + dbtype => "sqlite", script_name => "wiki.cgi", install_directory => "/usr/lib/cgi-bin/openguides/", use_plucene => 1, @@ -156,7 +156,7 @@ template_path => "What directory should I install the templates in?", custom_template_path => "Where should I look for custom templates?", script_url => "What URL does the install directory map to?", - 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.", + custom_lib_path => "Do you want me to munge a custom lib path into the scripts?", use_plucene => "Do you want to use Plucene for searching? (recommended, but see Changes file before saying yes to this if you are upgrading)", 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.", enable_page_deletion => "Do you want to enable page deletion?", @@ -175,7 +175,7 @@ content_above_navbar_in_html => "Do you want the content to appear above the navbar in the HTML?", home_name => "What should the home page of the wiki be called?", site_desc => "How would you describe the site?", - default_city => "What city is the site based in?", + default_city => "What city (or village, or town, or county, etc) is the site based in?", default_country => "What country is the site based in?", contact_email => "Contact email address for the site administrator?", default_language => "What language will the site be in? (Please give an ISO language code.)", @@ -184,19 +184,19 @@ formatting_rules_link => "What URL do you want to use for the text formatting rules (leave blank to use a wiki node instead)?", backlinks_in_title => "Make node titles link to node backlinks (C2 style)?", ellipsoid => "Which ellipsoid do you want to use? (eg 'Airy', 'WGS-84')", - 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.", - 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')", - 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)", - 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)", - 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)", - 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)", + gmaps_api_key => "Do you have a Google Maps API key to use with this guide?", + centre_long => "What is the longitude of the centre point of a map to draw for your guide? You may paste in a Google Maps URL here (hint: copy URL from 'Link to this page')", + centre_lat => "What is the latitude of the centre point of a map to draw for your guide?", + default_gmaps_zoom => "What default zoom level shall we use for Google Maps?", + default_gmaps_search_zoom => "What default zoom level shall we use for Google Maps in the search results?", + show_gmap_in_node_display => "Would you like to display a Google Map on every node that has geodata?", force_wgs84 => "Forcibly treat stored lat/long data as if they used the WGS84 ellipsoid?", - google_analytics_key => "Do you have a Google Analytics key to use with this guide? If you enter it here, then Google Analytics functionality will be automatically enabled.", + google_analytics_key => "Do you have a Google Analytics key to use with this guide?", licence_name => "What licence will you use for the guide?", licence_url => "What is the URL to your licence?", licence_info_url => "What is the URL to your local page about your licensing policy?", - spam_detector_module => "What module would you like to use for spam detection? (optional)", - host_checker_module => "What module would you like to use to run an IP blacklist? (optional)", + spam_detector_module => "Do you have a module to use for spam detection?", + host_checker_module => "Do you have a module for running an IP blacklist?", static_path => "What directory should we install static content (CSS, images, javascript) to?", static_url => "What is the URL corresponding to the static content?", send_moderation_notifications => "Should we send email notifications when a moderated node is edited?"
Deleted: branches/new-install-process/newpage.cgi =================================================================== --- branches/new-install-process/newpage.cgi 2008-05-01 19:24:56 UTC (rev 1157) +++ branches/new-install-process/newpage.cgi 2008-05-01 19:53:01 UTC (rev 1158) @@ -1,91 +0,0 @@ -#!/usr/local/bin/perl - -use warnings; -use strict; - -use CGI; -use OpenGuides::Config; -use OpenGuides::Template; -use OpenGuides::Utils; -use URI::Escape; - -my @badchars = qw( & ? _ ); -push @badchars, '#'; # Avoid warning about possible comments in qw() - -my $q = CGI->new; -my $config_file = $ENV{OPENGUIDES_CONFIG_FILE} || "wiki.conf"; -my $config = OpenGuides::Config->new( file => $config_file ); -my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); - -my $pagename = $q->param("pagename") || ""; -$pagename =~ s/^\s*//; -$pagename =~ s/\s*$//; - -my $action = $q->param("action") || ""; - -if ( $action eq "makepage" ) { - make_page(); -} else { - show_form(); -} - -sub show_form { - print OpenGuides::Template->output( wiki => $wiki, - config => $config, - template => "newpage.tt", - vars => { - not_editable => 1, - not_deletable => 1, - deter_robots => 1, - disallowed_chars => @badchars, - pagename => $pagename } - ); -} - -sub make_page { - # Ensure pagename not blank. - unless ( $pagename ) { - print OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "error.tt", - vars => { not_editable => 1, - not_deletable => 1, - deter_robots => 1, - message => "Please enter a page name!", - return_url => "newpage.cgi" } ); - return 0; - } - - # Ensure pagename valid. - my %badhash = map { $_ => 1 } @badchars; - my @naughty; - foreach my $i ( 0 .. (length $pagename) - 1 ) { - my $char = substr( $pagename, $i, 1 ); - push @naughty, $char if $badhash{$char}; - } - if ( scalar @naughty ) { - my $message = "Page name $pagename contains disallowed characters"; - print OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "error.tt", - vars => { - pagename => $pagename, - not_editable => 1, - not_deletable => 1, - deter_robots => 1, - message => $message, - return_url => "newpage.cgi?pagename=" . uri_escape($pagename) - } - ); - return 0; - } - - # Hurrah, we're OK. - my $node_param = $wiki->formatter->node_name_to_node_param($pagename); - print "Location: ".$config->script_url.$config->script_name."?action=edit;id=$node_param\n\n"; - return 0; -} - -
Deleted: branches/new-install-process/preferences.cgi =================================================================== --- branches/new-install-process/preferences.cgi 2008-05-01 19:24:56 UTC (rev 1157) +++ branches/new-install-process/preferences.cgi 2008-05-01 19:53:01 UTC (rev 1158) @@ -1,61 +0,0 @@ -#!/usr/bin/perl - -use warnings; -use strict; - -use CGI; -use OpenGuides::Config; -use OpenGuides::CGI; -use OpenGuides::Utils; -use OpenGuides::Template; - -my $config_file = $ENV{OPENGUIDES_CONFIG_FILE} || "wiki.conf"; -my $config = OpenGuides::Config->new( file => $config_file ); -my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); -my $cgi = CGI->new(); -my $action = $cgi->param('action') || ''; - -if ( $action eq "set_preferences" ) { - set_preferences(); -} else { - show_form(); -} - -sub set_preferences { - my %prefs = OpenGuides::CGI->get_prefs_from_hash( $cgi->Vars ); - my $prefs_cookie = OpenGuides::CGI->make_prefs_cookie( - config => $config, - %prefs, - ); - my @cookies = ( $prefs_cookie ); - # If they've asked not to have their recent changes visits tracked, - # clear any existing recentchanges cookie. - if ( ! $prefs{track_recent_changes_views} ) { - my $rc_cookie = OpenGuides::CGI->make_recent_changes_cookie( - config => $config, - clear_cookie => 1, - ); - push @cookies, $rc_cookie; - } - print OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "preferences.tt", - cookies => @cookies, - vars => { - not_editable => 1, - } - ); -} - -sub show_form { - print OpenGuides::Template->output( - wiki => $wiki, - config => $config, - template => "preferences.tt", - vars => { - not_editable => 1, - show_form => 1 - } - ); -}
Deleted: branches/new-install-process/search.cgi =================================================================== --- branches/new-install-process/search.cgi 2008-05-01 19:24:56 UTC (rev 1157) +++ branches/new-install-process/search.cgi 2008-05-01 19:53:01 UTC (rev 1158) @@ -1,14 +0,0 @@ -#!/usr/local/bin/perl - -use warnings; -use strict; - -use CGI; -use OpenGuides::Config; -use OpenGuides::Search; - -my $config_file = $ENV{OPENGUIDES_CONFIG_FILE} || "wiki.conf"; -my $config = OpenGuides::Config->new( file => $config_file ); -my $search = OpenGuides::Search->new( config => $config ); -my %vars = CGI::Vars(); -$search->run( vars => %vars );
Deleted: branches/new-install-process/wiki.cgi =================================================================== --- branches/new-install-process/wiki.cgi 2008-05-01 19:24:56 UTC (rev 1157) +++ branches/new-install-process/wiki.cgi 2008-05-01 19:53:01 UTC (rev 1158) @@ -1,375 +0,0 @@ -#!/usr/local/bin/perl - -use strict; -use warnings; - -use vars qw( $VERSION ); -$VERSION = '0.61'; - -use CGI qw/:standard/; -use CGI::Carp qw(croak); -use Wiki::Toolkit; -use Geography::NationalGrid; -use Geography::NationalGrid::GB; -use OpenGuides; -use OpenGuides::CGI; -use OpenGuides::Config; -use OpenGuides::RDF; -use OpenGuides::Utils; -use OpenGuides::Template; -use Time::Piece; -use URI::Escape; - -my $config_file = $ENV{OPENGUIDES_CONFIG_FILE} || "wiki.conf"; -my $config = OpenGuides::Config->new( file => $config_file ); - -my $script_name = $config->script_name; -my $script_url = $config->script_url; - -my ($guide, $wiki, $formatter, $q); -eval { - $guide = OpenGuides->new( config => $config ); - $wiki = $guide->wiki; - $formatter = $wiki->formatter; - - # Get CGI object, find out what to do. - $q = CGI->new; - - # Note $q->param('keywords') gives you the entire param string. - # We need this to do URLs like foo.com/wiki.cgi?This_Page - my $node = $q->param('id') || $q->param('title') || $q->param('keywords') || ''; - $node = $formatter->node_param_to_node_name( $node ); - - # If we did a post, then CGI->param probably hasn't fully de-escaped, - # in the same way as a get would've done - my $request_method = $q->request_method() || ''; - if($request_method eq 'POST') { - $node = uri_unescape($node); - } - - # Grab our common parameters - my $action = $q->param('action') || 'display'; - my $commit = $q->param('Save') || 0; - my $preview = $q->param('preview') || 0; - my $search_terms = $q->param('terms') || $q->param('search') || ''; - my $format = $q->param('format') || ''; - my $oldid = $q->param('oldid') || ''; - - # Alternative method of calling search, supported by usemod. - $action = 'search' if $q->param("search"); - - if ($commit) { - $guide->commit_node( - id => $node, - cgi_obj => $q, - ); - } elsif ($preview) { - $guide->preview_edit( - id => $node, - cgi_obj => $q, - ); - } elsif ($action eq 'edit') { - $guide->display_edit_form( id => $node ); - } elsif ($action eq 'search') { - do_search($search_terms); - } elsif ($action eq 'show_backlinks') { - $guide->show_backlinks( id => $node ); - } elsif ($action eq 'show_wanted_pages') { - show_wanted_pages(); - } elsif ($action eq 'show_needing_moderation') { - show_needing_moderation(); - } elsif ($action eq 'index') { - $guide->show_index( - type => $q->param("index_type") || "Full", - value => $q->param("index_value") || "", - format => $format, - ); - } elsif ($action eq 'random') { - print $guide->display_random_page( - category => $q->param( "category" ) || "", - locale => $q->param( "locale" ) || "", - ); - } elsif ($action eq 'find_within_distance') { - $guide->find_within_distance( - id => $node, - metres => $q->param("distance_in_metres") - ); - } elsif ( $action eq 'admin' ) { - $guide->display_admin_interface( - moderation_completed => $q->param("moderation"), - ); - } elsif ( $action eq 'revert_user' ) { - $guide->revert_user_interface( - username => $q->param("username") || "", - host => $q->param("host") || "", - password => $q->param("password") || "", - ); - } elsif ( $action eq 'show_missing_metadata' ) { - $guide->show_missing_metadata( - metadata_type => $q->param("metadata_type") || "", - metadata_value => $q->param("metadata_value") || "", - exclude_locales => $q->param("exclude_locales") || "", - exclude_categories => $q->param("exclude_categories") || "" - ); - } elsif ( $action eq 'set_moderation' ) { - $guide->set_node_moderation( - id => $node, - password => $q->param("password") || "", - moderation_flag => $q->param("moderation_flag") || "", - ); - } elsif ( $action eq 'moderate' ) { - $guide->moderate_node( - id => $node, - version => $q->param("version") || "", - password => $q->param("password") || "", - ); - } elsif ( $action eq 'delete' - and ( lc($config->enable_page_deletion) eq "y" - or $config->enable_page_deletion eq "1" ) - ) { - $guide->delete_node( - id => $node, - version => $q->param("version") || "", - password => $q->param("password") || "", - ); - } elsif ($action eq 'userstats') { - show_userstats( - username => $q->param("username") || "", - host => $q->param("host") || "", - ); - } elsif ($action eq 'list_all_versions') { - if($format && ($format eq "rss" || $format eq "atom")) { - my %args = ( - feed_type => $format, - feed_listing => 'node_all_versions', - name => $node - ); - $guide->display_feed( %args ); - } else { - $guide->list_all_versions( id => $node ); - } - } elsif ($action eq 'rc') { - if ($format && $format eq 'rss') { - my $feed = $q->param("feed"); - if ( !defined $feed or $feed eq "recent_changes" ) { - my %args = map { $_ => ( $q->param($_) || "" ) } - qw( feed items days ignore_minor_edits username - category locale ); - $args{feed_type} = 'rss'; - $args{feed_listing} = 'recent_changes'; - $guide->display_feed( %args ); - } elsif ( $feed eq "chef_dan" ) { - display_node_rdf( node => $node ); - } else { - croak "Unknown RSS feed type '$feed'"; - } - } elsif ($format && $format eq 'atom') { - my %args = map { $_ => ( $q->param($_) || "" ) } - qw( feed items days ignore_minor_edits username - category locale ); - $args{feed_type} = 'atom'; - $args{feed_listing} = 'recent_changes'; - $guide->display_feed( %args ); - } else { - $guide->display_node( id => 'RecentChanges' ); - } - } elsif ($action eq 'rss') { - my $redir_target = $script_url . $script_name . '?action=rc;format=rss'; - my %args = map { $_ => ( $q->param($_) || "" ) } - qw( feed items days ignore_minor_edits username - category locale ); - foreach my $arg (sort keys %args) { - if ($args{$arg} ne "") { - $redir_target .= ";$arg=$args{$arg}"; - } - } - print $q->redirect( $redir_target ); - } elsif ($action eq 'about') { - $guide->display_about(format => $format); - } elsif ($action eq 'display') { - if ( $format and $format eq "rdf" ) { - display_node_rdf( node => $node ); - } elsif ( $format and $format eq 'raw' ) { - $guide->display_node( - id => $node, - format => 'raw', - ); - } else { - my $version = $q->param("version"); - my $other_ver = $q->param("diffversion"); - if ( $other_ver ) { - $guide->display_diffs( - id => $node, - version => $version, - other_version => $other_ver, - ); - } else { - my $redirect; - - if ((defined $q->param("redirect")) && ($q->param("redirect") == 0)) { - $redirect = 0; - } else { - $redirect = 1; - } - - $guide->display_node( - id => $node, - version => $version, - oldid => $oldid, - redirect => $redirect, - ); - } - } - } else { - # Fallback: redirect to the display page, preserving all vars - # except for the action, which we override. - # Note: $q->Vars needs munging if we need to support any - # multi-valued params - my $params = $q->Vars; - $params->{'action'} = 'display'; - my $redir_target = $script_url . $script_name . '?'; - my @args = map { "$_=" . $params->{$_} } keys %{$params}; - $redir_target .= join ';', @args; - - print $q->redirect( - -uri => $redir_target, - -status => 303 - ); - } - -}; - -if ($@) { - my $error = $@; - warn $error; - print $q->header; - my $contact_email = $config->contact_email; - print qq(<html><head><title>ERROR</title></head><body> - <p>Sorry! Something went wrong. Please contact the - Wiki administrator at - <a href="mailto:$contact_email">$contact_email</a> and quote - the following error message:</p><blockquote>) - . $q->escapeHTML($error) - . qq(</blockquote><p><a href="$script_name">Return to the Wiki home page</a> - </body></html>); -} - -############################ subroutines ################################### - -sub show_userstats { - my %args = @_; - my ($username, $host) = @args{ qw( username host ) }; - croak "No username or host supplied to show_userstats" - unless $username or $host; - my %criteria = ( last_n_changes => 5 ); - $criteria{metadata_was} = $username ? { username => $username } - : { host => $host }; - my @nodes = $wiki->list_recent_changes( %criteria ); - @nodes = map { {name => $q->escapeHTML($_->{name}), - last_modified => $q->escapeHTML($_->{last_modified}), - comment => OpenGuides::Utils::parse_change_comment( - $q->escapeHTML($_->{metadata}{comment}[0]), - $script_url . '?', - ), - url => "$script_name?" - . $q->escape($formatter->node_name_to_node_param($_->{name})) } - } @nodes; - my %tt_vars = ( last_five_nodes => @nodes, - username => $username, - username_param => $wiki->formatter->node_name_to_node_param($username), - host => $host, - ); - process_template("userstats.tt", "", %tt_vars); -} - -sub get_cookie { - my $pref_name = shift or return ""; - my %cookie_data = OpenGuides::CGI->get_prefs_from_cookie(config=>$config); - return $cookie_data{$pref_name}; -} - -sub display_node_rdf { - my %args = @_; - my $rdf_writer = OpenGuides::RDF->new( wiki => $wiki, - config => $config ); - print "Content-type: application/rdf+xml\n\n"; - print $rdf_writer->emit_rdfxml( node => $args{node} ); -} - -sub process_template { - my ($template, $node, $vars, $conf, $omit_header) = @_; - - my %output_conf = ( wiki => $wiki, - config => $config, - node => $node, - template => $template, - vars => $vars - ); - $output_conf{noheaders} = 1 if $omit_header; # defaults otherwise - print OpenGuides::Template->output( %output_conf ); -} - - -sub do_search { - my $terms = shift; - my %finds = $wiki->search_nodes($terms); -# my @sorted = sort { $finds{$a} cmp $finds{$b} } keys %finds; - my @sorted = sort keys %finds; - my @results = map { - { url => $q->escape($formatter->node_name_to_node_param($_)), - title => $q->escapeHTML($_) - } } @sorted; - my %tt_vars = ( results => @results, - num_results => scalar @results, - not_editable => 1, - search_terms => $q->escapeHTML($terms) ); - process_template("search_results.tt", "", %tt_vars); -} - -sub show_wanted_pages { - my @dangling = $wiki->list_dangling_links; - my @wanted; - my %backlinks_count; - foreach my $node_name (@dangling) { - $backlinks_count{$node_name} = scalar($wiki->list_backlinks( node => $node_name )); - } - foreach my $node_name (sort { $backlinks_count{$b} <=> $backlinks_count{$a} } @dangling) { - my $node_param = - uri_escape($formatter->node_name_to_node_param($node_name)); - push @wanted, { - name => $q->escapeHTML($node_name), - edit_link => $script_url . uri_escape($script_name) - . "?action=edit;id=$node_param", - backlink_link => $script_url . uri_escape($script_name) - . "?action=show_backlinks;id=$node_param", - backlinks_count => $backlinks_count{$node_name} - }; - } - process_template( "wanted_pages.tt", - "", - { not_editable => 1, - not_deletable => 1, - deter_robots => 1, - wanted => @wanted } ); -} - -sub show_needing_moderation { - my @nodes = $wiki->list_unmoderated_nodes; - - # Build the moderate links - foreach my $node (@nodes) { - my $node_param = - uri_escape($formatter->node_name_to_node_param($node->{'name'})); - $node->{'moderate_url'} = $script_name . "?action=moderate;id=".$node_param.";version=".$node->{'version'}; - $node->{'view_url'} = $script_name . "?id=".$node_param.";version=".$node->{'version'}; - $node->{'diff_url'} = $script_name . "?id=".$node_param.";version=".$node->{'moderated_version'}.";diffversion=".$node->{'version'}; - $node->{'delete_url'} = $script_name . "?action=delete;version=".$node->{'version'}.";id=".$node_param; - } - - process_template( "needing_moderation.tt", - "", - { not_editable => 1, - not_deletable => 1, - deter_robots => 1, - nodes => @nodes } ); -}
openguides-commits@lists.openguides.org