Author: dom Date: 2005-07-24 01:41:54 +0100 (Sun, 24 Jul 2005) New Revision: 671
Added: tags/rel0_49/ tags/rel0_49/Changes tags/rel0_49/PREREQUISITES tags/rel0_49/lib/OpenGuides.pm tags/rel0_49/wiki.cgi Removed: tags/rel0_48/ tags/rel0_49/Changes tags/rel0_49/PREREQUISITES tags/rel0_49/lib/OpenGuides.pm tags/rel0_49/wiki.cgi Log: fix up release tags
Copied: tags/rel0_49 (from rev 666, trunk)
Deleted: tags/rel0_49/Changes =================================================================== --- trunk/Changes 2005-07-23 02:01:06 UTC (rev 666) +++ tags/rel0_49/Changes 2005-07-24 00:41:54 UTC (rev 671) @@ -1,490 +0,0 @@ -0.48 22 July 2005 - RDF enhancements: - Removed redundant "id" parameter specification from dc:source in - rdf:Description in RDF node listings. - Fixed bug that was causing all nodes to be flagged as a - geo:SpatialThing whether they were or not. - Ensured that ampersands and greater/less than symbols were properly - escaped so as not to be XML-toxic. - Added geo:lat, geo:long and RSS link attributes to items in - category/locale listings to facilitate integration with mapping - applications. - Added owl:sameAs property to RDF output for nodes that are redirects - to other nodes. - RSS feed now has correct timestamp (matching most recent item) and - matching Last-Modified HTTP header. - Reorder navigation bar to provide more logical groupings. - Add "format=plain" option for all-nodes index listing and associated - template plain_index.tt. - New message to appear on pages when you have been redirected - informing you of the fact. - Stop showing potentially very long map URLs in metadata section of - node display. - Replace ugly obliques in display of categories and locales with more - natural commas; change "locale" to "locales" in label. - Replace <label> tags in display_metadata.tt with <span - class="metadata_label">. - Wanted pages listing now displays, and sorts by, the number of nodes - pointing to each node. - Prevent redirect loops. - Add _ to the list of forbidden characters in node names. - -0.47 15 January 2005 - Fixed bug with list_all_versions for nodes with only one version. - Extended config changes to examples/reindex.pl (thanks jimbo). - Now require CGI::Wiki 0.62 to fix bug with deleting versions. - Try to ensure that a .htaccess file protecting wiki.conf is installed. - Allow for external URLs for Text Formatting help. - Home node recent changes box now flags new entries. - Made default city and country be blank; specify them if you want them. - Missing PREREQUISITE on Plucene added. - Added CSS id "maincontent" to exclude the navbar and footer. Misc - template tidying including removing old layout tables. - -0.46 21 December 2004 - Minor bug fixes: remove bogus edit link on index listings, - add missing default behaviour for geolocation - Update supersearch help text URL. - Add nofollow to robots meta tag. - Added new CSS class "node_name" for inline non-hyperlink references - to node names - see README.CSS for details. - Fix bug with diff display on nodes containing macros. - Fixed distance search paging bug. - Fixed bug that allowed autocreation of locales and categories with - trailing spaces in the name. - Config management refactoring. This should not result in any - user-visible changes, apart from introducing a new dependency on - Class::Accessor. - Make it clearer in documentation that overriding factory templates - is a risky activity. - Update feedback details and include URL of RT queue. - Add missing tests to MANIFEST so they are included with the - distribution. - -0.45 1 December 2004 - Made the geolocation stuff work worldwide. Squeeeeeee! - You can now choose between doing your distance calculations with - the British National Grid, the Irish National Grid, or a UTM - ellipsoid. If you wish to use anything other than the British - National Grid and you have pre-existing location data then you - will need to save an edit of each node with location data before - distance searches will work. - In less exciting news: - Fixed bug relating to lat/long representation. - Removed debugging warn accidentally left in last release. - Fixed some HTML validation errors. - -0.44 17 November 2004 - Remove all traces of display_categories, which was obsoleted but - not completely removed before. - Improved the efficiency of the search. - Fixed a couple of minor bugs in the search - note that node.tt - and supersearch.tt have changed. - Change the default indexer for new installs to Plucene. - Only run certain search-related tests if Plucene is installed. - -0.43 21 October 2004 - Fix broken navbar changes that crept into last release. - -0.42 20 October 2004 - Handle distance searching with OpenGuides::Supersearch instead of - find_within_distance action. - Fixed bug with paging on distance-only search (reported by Bob Walker). - Improved encapsulation in OpenGuides::Supersearch - accessors. - *INCOMPATIBLE CHANGE* Custom templates are now stored in - user-definable path, and their names are prefixed with custom_. - This only affects you if you have used the custom template support - introduced in 0.41. - Replace use of CGI::Wiki::Plugin::Geocache with improved node.tt. - -0.41 21 September 2004 - Added backlinks link to navbar. - Added some anti-robot tags to certain pages. - Fixed bug in install procedure - blank script_name should now get - installed as index.cgi - Added option of munging in custom lib paths on install. - Added option of custom templates for footer, license warning - on edit form, banner at top of page (see CUSTOMISATION file - for details). - Added new macro - used as eg @INDEX_LIST [[Locale Fulham]] - Also fixed the RSS reader macro - use this as eg - @RSS http://london.openguides.org/?action=rss;username=Kake - More semantic markup for metadata display - see README.CSS - -0.40 18 September 2004 - Recent Changes now shows changes in the past 24 hours, past week, - past fortnight, and past 30 days. - New preferences option to allow Recent Changes visit tracking. - Preferences now has an option for when your prefs expire. - Navbar added to diff and history pages. - The "omit help links" preference now actually works. - Set some pages to non-editable and non-deletable that should have been. - Recent Changes RSS fixed so "wiki:importance" is set correctly. - New "ignore_minor_edits" option for Recent Changes RSS. - Added RSS feeds for contributors, locales and categories. - -0.39 15 September 2004 - Split commit_node out into OpenGuides.pm in preparation for spam filter - Added option of using Plucene for searching. If you want to do this - (and it is recommended over the default of Search::InvertedIndex) - you will need to do two things: - - either delete your old indexes (they're just files in the index - directory) or use a different index directory - - reindex your entire wiki (see reindex.pl in the examples/ - directory of this distribution) - -0.38 26 July 2004 - Major improvements to the search result ordering (thanks to - Steve Jolly, Bob Walker and Billy Abbott for test cases). - -0.37 23 July 2004 - Fixed bug in diff view - the versions are the right way round now... - Fixed bug with links in historic view. Require CGI.pm 2.92 to - avoid escapeHTML bug. - -0.36 13 July 2004 - Added diff link to node template. - Fixed case sensitivity bug in index node autocreation. - Fixed bug with node history comments not being HTML-escaped. - -0.35 25 June 2004 - Forgot to add version prerequisite on CGI::Wiki. Don't use 0.34, - use this. - -0.34 25 June 2004 - Add facility to delete only certain revisions of a page - access - this from the node history page. - -0.33 20 June 2004 - Improve node history page to allow diffing between each version and - the previous one or the current one. - Test overhauls - you don't need to run the configuration step in - order to run the tests now, but you do need to have DBD::SQLite - for most of them. - Fixed template bug in display_metadata.tt that was stopping map - links being displayed for nodes with no address data (spotted - by Steve Jolly). - Removed inline style from recent_changes.tt. You will need to add - the styles table#recentchanges, td.recentchanges_meta, - td.recentchanges_user, td.recentchanges_node_name and - td.recentchanges_comment to your stylesheets. - td#map changed to td#map_link in edit_conflict.tt. - Added searching by distance from an arbitrary point (click on - Advanced Search). - Internal rejigging - extracted some methods from wiki.cgi to - OpenGuides.pm. - Added new preference for default edit type. - Reinstate apparently lost change from 0.26 to show IP rather than - "Anonymous" in RecentChanges. - More informative <title> tags for non-node (e.g. node version - history) pages. - -0.32 7 June 2004 - Change auto-creating behaviour of index nodes (categories and - locales): instead of being created on access they are created - when the referring node is committed. This fixes compliance with - RFC 2616 section 9.1.1 and prevents corrupted index nodes being - created accidentally. - -0.31 09 May 2004 - Created a new macro to allow the embedding of RSS feeds into - pages, using CGI::Wiki::Plugin::RSS::Reader. This allows you - to do this to produce a list of up to ten hyperlinks: - @RSS [http://example.com/example.rss] - - Numerous template tweaks to comply with the W3C's Web Content - Accessibility Guidelines (http://www.w3.org/TR/WAI-WEBCONTENT/): - - summaries for all HTML tables - - labels for all form input elements and some textual additions - to templates, such as '/' separators between navbar items, - because the guidelines specify links should not only be - separated by whitespace. If you don't want these to appear, - put the following in your stylesheet and they'll be hidden by - CSS (but will still appear for people using textual browsers or - screen readers): ".hidden { display: none }". - - the "lang" element (a two-letter code identifying the language - you're writing pages in) will now be added to the <html> tag on - all pages; a new question has been added to the configuration - script to ask for it and it will be stored in wiki.conf. - *** YOU WILL NEED TO RUN BUILD.PL AGAIN. *** - *** Remember to keep a backup copy of your old wiki.conf! *** - - Improved navigation for search results (next and previous n hits). - Removed underscores from page names in search results. - - Overhauled RDF output. Changes: - - everything is no longer classified as a restaurant(!) - - empty tags are no longer generated - - show categories, locales and OS x/y coords in invididual - node RDF view - - switch to W3C contact namespace for addressing data - - move homepage tag out of wiki metadata - - remove nonexistent "gs:" namespace from category indices - - logical structure improvements (subjects of pages are now - identified as spatial things if they are, or are RDF - descriptions if they're not, instead of being anonymous - FOAF topics) - - include city and country in RDF only for spatial things. - - Fixed bug that prevented automatic database initialization on - SQLite databases. - - Doc fix for private installations. - - Removed the following characters from the list of forbidden ones in - node names in newpage.cgi (a restriction which dates from all the way - back when we were using UseModWiki): " ! $ ^ ~ @ [ ] { } - - Removed newlines from output of search box macro. - - Reimplemented diffing using CGI::Wiki::Plugin::Diff as it seems the - change in 0.30 got lost. Removed OpenGuides::Diff.pm as we should not - be distributing it. - -0.30 29 December 2003 - Added method to allow admins to delete nodes. You will need to - explicitly enable this option in your wiki.conf, since it brings - with it the risk of accidental data loss. - - Major overhaul of templates - added numerous style hooks. See - examples/ for two stylesheet designs that take advantage of these. - Added new banner template for page headers. Also ensured presence - of navigation bar is consistent. - *** INCOMPATIBLE CHANGE: *** The navbar class in the stylesheet - has been renamed to, unsurprisingly, "navbar", for consistency - (from "toolbar"). *** YOU WILL NEED TO REWRITE YOUR STYLESHEET. *** - You are advised to create a duplicate wiki.cgi that reads its data - from your database but its stylesheet and templates from the new - ones in order to test them *before* deploying them. - - Added "FAQ", "How To Get Started" and "Wiki Etiquette" to the - navigation, under "Help" - these won't exist unless you create them - on your site, so at first the links serve as examples of - documentation you can provide. - - Modified preferences.cgi so that all the help links in the navbar - can be hidden, not just the text formatting link. - - Fixed some HTML validation bugs. - - Added multiple install and pretty URL notes to INSTALL. - - Removed pubcrawl stuff from distro for now - it doesn't really work. - - Changed to use CGI::Wiki::Plugin::Diff instead of OpenGuides::Diff. - -0.29 8 November 2003 - Expanded section in TROUBLESHOOTING about permissions problems. - - Diff.pm now absorbs trailing punctuation and spaces into words - it is diffing (to give less blocky results). - - SuperSearch.pm change NOT to use '-' instead of '!'. - -0.28 1 November 2003 - Allow running sites on SQLite databases. - - Fixed bug with navbar prompt in Build.PL (CPAN RT #3894). - Junked OpenGuides::Config completely to avoid database password - leakage, and easier install (CPAN RT #3916). - -0.27 1 November 2003 - Fixed bug with category/locale indexing - no longer case-sensitive. - - Fixed bug that had the supersearch results page offering an edit link. - - Revamp of search syntax to make the SuperSearch UI much more like - Google and Alta Vista. See the POD of SuperSearch.pm for details. - -0.26 9 October 2003 - Modified TROUBLESHOOTING to reflect the correct invocation for - Module::Build to install into a private directory. - - Show IP address for anonymous edits. - - Changed CGI.pm version dependency for Dom (CPAN bug #3895). - - Added check to OpenGuides::SuperSearch to stop it trying to - retrieve a nonexistent node when the search indexes have screwed up. - -0.25 23 September 2003 - Applied recent changes fix to front page feed as well. - - Search box now searches categories and locales as well as title and - body - so for example a search on "holborn & pubs" will DTRT. - - NOT and phrase search tests were passing even though they shouldn't - have been - skip them for now. - -0.24 8 September 2003 - Fix to recent changes so minor changes don't mask major ones. - - Fixed supersearch.cgi to use a template instead of CGI.pm to avoid - weird errors, also turned it into a module and added tests. - Strip whitespace from OS co-ords before storing in database. - -0.23 4 August 2003 - Removed the "POST_CHOMP" option as it was messing up textareas, added - a test to make sure this doesn't reoccur. - -0.22 4 August 2003 - Fixed bug with usernames containing spaces in recent changes/userstats. - - Try out create_makefile_pl => "passthrough" in Build.PL - - Minor fixes to tests to make them work with newest UseMod formatter. - - Prevented "Edit this page" from showing up on category indexes. - - Set TT "POST_CHOMP" option to strip unnecessary newlines from HTML. - - Fixed CPAN bug #3085 - quotes in change summary box. - - Added openguides_version template variable and added it to page - footer (CPAN request 3110). - -0.21 17 July 2003 - We no longer autogenerate a Makefile.PL, since it doesn't pick up - all the questions that need to be asked. Sorry. Use Module::Build - as detailed in INSTALL, since you won't be able to get the right - version of Text::WikiFormat installed without it in any case. - - Added version number to CGI.pm prereq as Alex McLintock hit a - version that didn't have unescape. - - Added a link on RecentChanges to the RSS version, and put an - autodiscovery tag for the RSS in the head section. - - Changed diff feature to hide checksums, which aren't necessary for - the user to see. Fixed a minor bug in the node history template so - that the diff links compare the selected version against the previous - one, not the original one every time. - -0.20 10 July 2003 - Fixed all the email addresses to openguides-dev@openguides.org. - -0.19 10 July 2003 - Extra checks that script_url ends in a '/'. - - Fixed small bug with edit conflict form - map link field was missing. - - Moved "content" div in a couple of templates to fix incorrect nesting. - - @INDEX_LINK macros now have optional title text like so: - @INDEX_LINK [[Category Pubs|Pubs]] - - Added preferences option for including or excluding text formatting - rules link in navbar. Enable this by setting text_formatting_node - in your config file. - - Added config option for including the navbar on the home page. - - Implemented minor edits. - - Fixed cookie to persist beyond session. - -0.18 16 June 2003 - Added a Makefile.PL as well as a Build.PL, for CPAN.pm users. - -0.17 15 June 2003 - Fixed OpenGuides::Utils to take note of dbhost. - - Added example stylesheet provided by the OxfordGuide team. - -0.16 26 May 2003 - Ivor fixed OpenGuides::Diff to diff by word instead of by character. - - Fixed edit conflict up so it works nicely when you click the - Save button as well as the Preview one. - - Added preferences option of displaying lat/long as deg-min-sec - instead of decimal (requested by James). - -0.15 18 May 2003 - Added Algorithm::Diff version dependency to prereqs, fixed bug - with preferences.cgi and blank script_name, fixed REDIRECT bug. - -0.14 17 May 2003 - Added "Wanted Pages" link to navbar, thanks to Simon Cozens for - the idea. - - Fixed many bugs noticed by Dominic Hargreaves and other Oxonians. - Many thanks to Dominic for making an Oxford OpenGuides install for - us to find bugs in. - -0.13 17 May 2003 - Added some more stylesheet hooks. - - Tweaked OpenGuides::Diff to make it testable, added a start at tests. - - Lat and long now stored to only 6dp instead of millions. - - Added edit field for map link. - -0.12 14 May 2003 - Added OpenGuides::CGI to manage cookies and things, used this to - do more code tidying. Added edit box position option to preferences. - -0.11 14 May 2003 - Added newpage.cgi for an easy way to create new pages. - - Took loads of repeated code (for extracting and packaging metadata - variables) out of wiki.cgi into OpenGuides::Template. - -0.10 11 May 2003 - Added OpenGuides::Diff to provide nice diff output between - node versions. - - Added OpenGuides::Template to handle Template Toolkit stuff in a - more testable and reusable way than just bunging it in wiki.cgi. - -0.09 10 May 2003 - Added OpenGuides::UK::PubCrawl and pubcrawl.cgi as a start at a - pub crawl generator. - - Added OpenGuides::Utils to make it easier to write little standalone - scripts like supersearch.cgi, pubcrawl. cgi, etc. Made wiki.cgi and - supersearch.cgi use it, and lost loads of duplicated code in the - process, hurrah. - -0.08 3 May 2003 - Added fuzzy matching capability - - action=index;index_type=fuzzy_title_match;index_value=hollborne - Someone needs to write a nice search box interface for this. - - Fixed edit_conflict template and preview method to cope with stale - checksum - passes through all the metadata properly now and offers - a side by side comparison of what you input and what is stored. - - RDF output for node is now encoding-agnostic (used to have UTF-8 - hardcoded). Also is now called as wiki.cgi?id=Node_Name;format=rdf - -0.07 3 May 2003 - Require CGI::Wiki 0.32 to avoid bug (again a Bob find!) where - committing a node with metadata but no content would die. - - Auto-created category/locale stub pages now added to Category Category - or Category Locales as appropriate. - - Added a couple of extra allowed HTML tags to cater for existing - grubstreet data. - - Fixed bug in OpenGuides::RDF - it used to die if called on a - nonexistent node, now it returns stuff with a wiki:version of 0. - -0.06 2 May 2003 - Fixed supersearch.cgi so it works with MySQL as well as Postgres - (thanks again to Bob for finding the bug). - -0.05 2 May 2003 - Redid the script and template installation so the script does - actually get called what you said it should be (code copied - somewhat from Siesta::Build). - - Fixed the support for non-local databases/IDENT authentication. - I think. - - Fixed the hardcoded 'wiki.cgi' in some of the templates (thanks Bob). - -0.04 29 April 2003 - First public release.
Copied: tags/rel0_49/Changes (from rev 670, trunk/Changes)
Deleted: tags/rel0_49/PREREQUISITES =================================================================== --- trunk/PREREQUISITES 2005-07-23 02:01:06 UTC (rev 666) +++ tags/rel0_49/PREREQUISITES 2005-07-24 00:41:54 UTC (rev 671) @@ -1,46 +0,0 @@ -Modules required by OpenGuides 0.48 -=================================== - -Algorithm::Diff (version 0.13 or later) -CGI (version 2.92 or later) -CGI::Carp -CGI::Cookie -CGI::Wiki (version 0.62 or later) -CGI::Wiki::Formatter::UseMod (version 0.16 or later) -CGI::Wiki::Plugin::Categoriser -CGI::Wiki::Plugin::Diff (version 0.07 or later) -CGI::Wiki::Plugin::Locator::Grid (version 0.02 or later) -CGI::Wiki::Plugin::RSS::ModWiki (version 0.072 or later) -CGI::Wiki::Plugin::RSS::Reader (version 1.3 or later) -Class::Accessor -Config::Tiny -Data::Dumper -( - DBD::Pg - -- or -- - DBD::mysql - -- or -- - DBD::SQLite -) -File::Spec::Functions -File::Temp -( - Geography::NationalGrid::GB - -- or -- - Geography::NationalGrid::IE - -- or -- - Geo::Coordinates::UTM -) -LWP::Simple -Module::Build (version 0.18 or later) -Parse::RecDescent -( - Plucene - -- or -- - Search::InvertedIndex -) -Template -Test::MockObject (version 0.07 or later) -Time::Piece -URI::Escape -XML::RSS
Copied: tags/rel0_49/PREREQUISITES (from rev 670, trunk/PREREQUISITES)
Deleted: tags/rel0_49/lib/OpenGuides.pm =================================================================== --- trunk/lib/OpenGuides.pm 2005-07-23 02:01:06 UTC (rev 666) +++ tags/rel0_49/lib/OpenGuides.pm 2005-07-24 00:41:54 UTC (rev 671) @@ -1,935 +0,0 @@ -package OpenGuides; -use strict; - -use Carp "croak"; -use CGI; -use CGI::Wiki::Plugin::Diff; -use CGI::Wiki::Plugin::Locator::Grid; -use OpenGuides::CGI; -use OpenGuides::Template; -use OpenGuides::Utils; -use Time::Piece; -use URI::Escape; - -use vars qw( $VERSION ); - -$VERSION = '0.48'; - -=head1 NAME - -OpenGuides - A complete web application for managing a collaboratively-written guide to a city or town. - -=head1 DESCRIPTION - -The OpenGuides software provides the framework for a collaboratively-written -city guide. It is similar to a wiki but provides somewhat more structured -data storage allowing you to annotate wiki pages with information such as -category, location, and much more. It provides searching facilities -including "find me everything within a certain distance of this place". -Every page includes a link to a machine-readable (RDF) version of the page. - -=head1 METHODS - -=over - -=item B<new> - - my $config = OpenGuides::Config->new( file => "wiki.conf" ); - my $guide = OpenGuides->new( config => $config ); - -=cut - -sub new { - my ($class, %args) = @_; - my $self = {}; - bless $self, $class; - my $wiki = OpenGuides::Utils->make_wiki_object( config => $args{config} ); - $self->{wiki} = $wiki; - $self->{config} = $args{config}; - my $geo_handler = $self->config->geo_handler; - my $locator; - if ( $geo_handler == 1 ) { - $locator = CGI::Wiki::Plugin::Locator::Grid->new( - x => "os_x", y => "os_y" ); - } elsif ( $geo_handler == 2 ) { - $locator = CGI::Wiki::Plugin::Locator::Grid->new( - x => "osie_x", y => "osie_y" ); - } else { - $locator = CGI::Wiki::Plugin::Locator::Grid->new( - x => "easting", y => "northing" ); - } - $wiki->register_plugin( plugin => $locator ); - $self->{locator} = $locator; - my $differ = CGI::Wiki::Plugin::Diff->new; - $wiki->register_plugin( plugin => $differ ); - $self->{differ} = $differ; - return $self; -} - -=item B<wiki> - -An accessor, returns the underlying LCGI::Wiki object. - -=cut - -sub wiki { - my $self = shift; - return $self->{wiki}; -} - -=item B<config> - -An accessor, returns the underlying LOpenGuides::Config object. - -=cut - -sub config { - my $self = shift; - return $self->{config}; -} - -=item B<locator> - -An accessor, returns the underlying LCGI::Wiki::Plugin::Locator::UK object. - -=cut - -sub locator { - my $self = shift; - return $self->{locator}; -} - -=item B<differ> - -An accessor, returns the underlying LCGI::Wiki::Plugin::Diff object. - -=cut - -sub differ { - my $self = shift; - return $self->{differ}; -} - -=item B<display_node> - - # Print node to STDOUT. - $guide->display_node( - id => "Calthorpe Arms", - version => 2, - ); - - # Or return output as a string (useful for writing tests). - $guide->display_node( - id => "Calthorpe Arms", - return_output => 1, - ); - - # Or return the hash of variables that will be passed to the template - # (not including those set additionally by OpenGuides::Template). - $guide->display_node( - id => "Calthorpe Arms", - return_tt_vars => 1, - ); - -If C<version> is omitted then the latest version will be displayed. - -=cut - -sub display_node { - my ($self, %args) = @_; - my $return_output = $args{return_output} || 0; - my $version = $args{version}; - my $id = $args{id} || $self->config->home_name; - my $wiki = $self->wiki; - my $config = $self->config; - my $oldid = $args{oldid} || ''; - - my %tt_vars; - - if ( $id =~ /^(Category|Locale) (.*)$/ ) { - my $type = $1; - $tt_vars{is_indexable_node} = 1; - $tt_vars{index_type} = lc($type); - $tt_vars{index_value} = $2; - $tt_vars{"rss_".lc($type)."_url"} = - $config->script_name . "?action=rss;" - . lc($type) . "=" . lc(CGI->escape($2)); - } - - my %current_data = $wiki->retrieve_node( $id ); - my $current_version = $current_data{version}; - undef $version if ($version && $version == $current_version); - my %criteria = ( name => $id ); - $criteria{version} = $version if $version;#retrieve_node default is current - - my %node_data = $wiki->retrieve_node( %criteria ); - my $raw = $node_data{content}; - if ( $raw =~ /^#REDIRECT\s+(.+?)\s*$/ ) { - my $redirect = $1; - # Strip off enclosing [[ ]] in case this is an extended link. - $redirect =~ s/^[[//; - $redirect =~ s/]]\s*$//; - # See if this is a valid node, if not then just show the page as-is. - - # Avoid loops by not generating redirects to the same node or the - # previous node. - if ( $wiki->node_exists($redirect) && $redirect ne $id && $redirect ne $oldid ) { - my $output = $self->redirect_to_node($redirect, $id); - return $output if $return_output; - print $output; - exit 0; - } - } - my $content = $wiki->format($raw); - my $modified = $node_data{last_modified}; - my %metadata = %{$node_data{metadata}}; - - my %metadata_vars = OpenGuides::Template->extract_metadata_vars( - wiki => $wiki, - config => $config, - metadata => $node_data{metadata} ); - - %tt_vars = ( - %tt_vars, - %metadata_vars, - content => $content, - last_modified => $modified, - version => $node_data{version}, - node => $id, - language => $config->default_language, - oldid => $oldid, - ); - - # We've undef'ed $version above if this is the current version. - $tt_vars{current} = 1 unless $version; - - if ($id eq "RecentChanges") { - my $minor_edits = $self->get_cookie( "show_minor_edits_in_rc" ); - my %recent_changes; - my $q = CGI->new; - my $since = $q->param("since"); - if ( $since ) { - $tt_vars{since} = $since; - my $t = localtime($since); # overloaded by Time::Piece - $tt_vars{since_string} = $t->strftime; - my %criteria = ( since => $since ); - $criteria{metadata_was} = { edit_type => "Normal edit" } - unless $minor_edits; - my @rc = $self->{wiki}->list_recent_changes( %criteria ); - - @rc = map { - { - name => CGI->escapeHTML($_->{name}), - last_modified => CGI->escapeHTML($_->{last_modified}), - version => CGI->escapeHTML($_->{version}), - comment => CGI->escapeHTML($_->{metadata}{comment}[0]), - username => CGI->escapeHTML($_->{metadata}{username}[0]), - host => CGI->escapeHTML($_->{metadata}{host}[0]), - username_param => CGI->escape($_->{metadata}{username}[0]), - edit_type => CGI->escapeHTML($_->{metadata}{edit_type}[0]), - url => $config->script_name . "?" - . CGI->escape($wiki->formatter->node_name_to_node_param($_->{name})), - } - } @rc; - if ( scalar @rc ) { - $recent_changes{since} = @rc; - } - } else { - for my $days ( [0, 1], [1, 7], [7, 14], [14, 30] ) { - my %criteria = ( between_days => $days ); - $criteria{metadata_was} = { edit_type => "Normal edit" } - unless $minor_edits; - my @rc = $self->{wiki}->list_recent_changes( %criteria ); - - @rc = map { - { - name => CGI->escapeHTML($_->{name}), - last_modified => CGI->escapeHTML($_->{last_modified}), - version => CGI->escapeHTML($_->{version}), - comment => CGI->escapeHTML($_->{metadata}{comment}[0]), - username => CGI->escapeHTML($_->{metadata}{username}[0]), - host => CGI->escapeHTML($_->{metadata}{host}[0]), - username_param => CGI->escape($_->{metadata}{username}[0]), - edit_type => CGI->escapeHTML($_->{metadata}{edit_type}[0]), - url => $config->script_name . "?" - . CGI->escape($wiki->formatter->node_name_to_node_param($_->{name})), - } - } @rc; - if ( scalar @rc ) { - $recent_changes{$days->[1]} = @rc; - } - } - } - $tt_vars{recent_changes} = %recent_changes; - my %processing_args = ( - id => $id, - template => "recent_changes.tt", - tt_vars => %tt_vars, - ); - if ( !$since && $self->get_cookie("track_recent_changes_views") ) { - my $cookie = - OpenGuides::CGI->make_recent_changes_cookie(config => $config ); - $processing_args{cookies} = $cookie; - $tt_vars{last_viewed} = OpenGuides::CGI->get_last_recent_changes_visit_from_cookie( config => $config ); - } - return %tt_vars if $args{return_tt_vars}; - my $output = $self->process_template( %processing_args ); - return $output if $return_output; - print $output; - } elsif ( $id eq $self->config->home_name ) { - my @recent = $wiki->list_recent_changes( - last_n_changes => 10, - metadata_was => { edit_type => "Normal edit" }, - ); - @recent = map { {name => CGI->escapeHTML($_->{name}), - last_modified => CGI->escapeHTML($_->{last_modified}), - version => CGI->escapeHTML($_->{version}), - comment => CGI->escapeHTML($_->{metadata}{comment}[0]), - username => CGI->escapeHTML($_->{metadata}{username}[0]), - url => $config->script_name . "?" - . CGI->escape($wiki->formatter->node_name_to_node_param($_->{name})) } - } @recent; - $tt_vars{recent_changes} = @recent; - return %tt_vars if $args{return_tt_vars}; - my $output = $self->process_template( - id => $id, - template => "home_node.tt", - tt_vars => %tt_vars, - ); - return $output if $return_output; - print $output; - } else { - return %tt_vars if $args{return_tt_vars}; - my $output = $self->process_template( - id => $id, - template => "node.tt", - tt_vars => %tt_vars, - ); - return $output if $return_output; - print $output; - } -} - -=item B<display_diffs> - - $guide->display_diffs( - id => "Home Page", - version => 6, - other_version => 5, - ); - - # Or return output as a string (useful for writing tests). - my $output = $guide->display_diffs( - id => "Home Page", - version => 6, - other_version => 5, - return_output => 1, - ); - - # Or return the hash of variables that will be passed to the template - # (not including those set additionally by OpenGuides::Template). - my %vars = $guide->display_diffs( - id => "Home Page", - version => 6, - other_version => 5, - return_tt_vars => 1, - ); - -=cut - -sub display_diffs { - my ($self, %args) = @_; - my %diff_vars = $self->differ->differences( - node => $args{id}, - left_version => $args{version}, - right_version => $args{other_version}, - ); - $diff_vars{not_deletable} = 1; - $diff_vars{not_editable} = 1; - $diff_vars{deter_robots} = 1; - return %diff_vars if $args{return_tt_vars}; - my $output = $self->process_template( - id => $args{id}, - template => "differences.tt", - tt_vars => %diff_vars - ); - return $output if $args{return_output}; - print $output; -} - -=item B<find_within_distance> - - $guide->find_within_distance( - id => $node, - metres => $q->param("distance_in_metres") - ); - -=cut - -sub find_within_distance { - my ($self, %args) = @_; - my $node = $args{id}; - my $metres = $args{metres}; - my %data = $self->wiki->retrieve_node( $node ); - my $lat = $data{metadata}{latitude}[0]; - my $long = $data{metadata}{longitude}[0]; - my $script_url = $self->config->script_url; - print CGI->redirect( $script_url . "supersearch.cgi?lat=$lat;long=$long;distance_in_metres=$metres" ); -} - -=item B<show_backlinks> - - $guide->show_backlinks( id => "Calthorpe Arms" ); - -As with other methods, parameters C<return_tt_vars> and -C<return_output> can be used to return these things instead of -printing the output to STDOUT. - -=cut - -sub show_backlinks { - my ($self, %args) = @_; - my $wiki = $self->wiki; - my $formatter = $wiki->formatter; - - my @backlinks = $wiki->list_backlinks( node => $args{id} ); - my @results = map { - { url => CGI->escape($formatter->node_name_to_node_param($_)), - title => CGI->escapeHTML($_) - } } sort @backlinks; - my %tt_vars = ( results => @results, - num_results => scalar @results, - not_deletable => 1, - deter_robots => 1, - not_editable => 1 ); - return %tt_vars if $args{return_tt_vars}; - my $output = OpenGuides::Template->output( - node => $args{id}, - wiki => $wiki, - config => $self->config, - template=>"backlink_results.tt", - vars => %tt_vars, - ); - return $output if $args{return_output}; - print $output; -} - -=item B<show_index> - - $guide->show_index( - type => "category", - value => "pubs", - ); - - # RDF version. - $guide->show_index( - type => "locale", - value => "Holborn", - format => "rdf", - ); - - # Or return output as a string (useful for writing tests). - $guide->show_index( - type => "category", - value => "pubs", - return_output => 1, - ); - -=cut - -sub show_index { - my ($self, %args) = @_; - my $wiki = $self->wiki; - my $formatter = $wiki->formatter; - my %tt_vars; - my @selnodes; - - if ( $args{type} and $args{value} ) { - if ( $args{type} eq "fuzzy_title_match" ) { - my %finds = $wiki->fuzzy_title_match( $args{value} ); - @selnodes = sort { $finds{$a} <=> $finds{$b} } keys %finds; - $tt_vars{criterion} = { - type => $args{type}, # for RDF version - value => $args{value}, # for RDF version - name => CGI->escapeHTML("Fuzzy Title Match on '$args{value}'") - }; - $tt_vars{not_editable} = 1; - } else { - @selnodes = $wiki->list_nodes_by_metadata( - metadata_type => $args{type}, - metadata_value => $args{value}, - ignore_case => 1 - ); - my $name = ucfirst($args{type}) . " $args{value}" ; - my $url = $self->config->script_name - . "?" - . ucfirst( $args{type} ) - . "_" - . uri_escape( - $formatter->node_name_to_node_param($args{value}) - ); - $tt_vars{criterion} = { - type => $args{type}, - value => $args{value}, # for RDF version - name => CGI->escapeHTML( $name ), - url => $url - }; - $tt_vars{not_editable} = 1; - } - } else { - @selnodes = $wiki->list_all_nodes(); - } - - my @nodes = map { { name => $_, - node_data => { $wiki->retrieve_node( name => $_ ) }, - param => $formatter->node_name_to_node_param($_) } - } sort @selnodes; - - $tt_vars{nodes} = @nodes; - - my ($template, %conf); - - if ( $args{format} ) - { - if ( $args{format} eq "rdf" ) - { - $template = "rdf_index.tt"; - $conf{content_type} = "text/plain"; - } - elsif ( $args{format} eq "plain" ) - { - $template = "plain_index.tt"; - $conf{content_type} = "text/plain"; - } - } - else - { - $template = "site_index.tt"; - } - - %conf = ( - %conf, - node => "$args{type} index", # KLUDGE - template => $template, - tt_vars => %tt_vars, - ); - - my $output = $self->process_template( %conf ); - return $output if $args{return_output}; - print $output; -} - -=item B<list_all_versions> - - $guide->list_all_versions ( id => "Home Page" ); - - # Or return output as a string (useful for writing tests). - $guide->list_all_versions ( - id => "Home Page", - return_output => 1, - ); - - # Or return the hash of variables that will be passed to the template - # (not including those set additionally by OpenGuides::Template). - $guide->list_all_versions ( - id => "Home Page", - return_tt_vars => 1, - ); - -=cut - -sub list_all_versions { - my ($self, %args) = @_; - my $return_output = $args{return_output} || 0; - my $node = $args{id}; - my %curr_data = $self->wiki->retrieve_node($node); - my $curr_version = $curr_data{version}; - my @history; - for my $version ( 1 .. $curr_version ) { - my %node_data = $self->wiki->retrieve_node( name => $node, - version => $version ); - # $node_data{version} will be zero if this version was deleted. - push @history, { - version => CGI->escapeHTML( $version ), - modified => CGI->escapeHTML( $node_data{last_modified} ), - username => CGI->escapeHTML( $node_data{metadata}{username}[0] ), - comment => CGI->escapeHTML( $node_data{metadata}{comment}[0] ), - } if $node_data{version}; - } - @history = reverse @history; - my %tt_vars = ( node => $node, - version => $curr_version, - not_deletable => 1, - not_editable => 1, - deter_robots => 1, - history => @history ); - return %tt_vars if $args{return_tt_vars}; - my $output = $self->process_template( - id => $node, - template => "node_history.tt", - tt_vars => %tt_vars, - ); - return $output if $return_output; - print $output; -} - -=item B<display_rss> - - # Last ten non-minor edits to Hammersmith pages. - $guide->display_rss( - items => 10, - ignore_minor_edits => 1, - locale => "Hammersmith", - ); - - # All edits bob has made to pub pages in the last week. - $guide->display_rss( - days => 7, - username => "bob", - category => "Pubs", - ); - -As with other methods, the C<return_output> parameter can be used to -return the output instead of printing it to STDOUT. - -=cut - -sub display_rss { - my ($self, %args) = @_; - - my $return_output = $args{return_output} ? 1 : 0; - - my $items = $args{items} || ""; - my $days = $args{days} || ""; - my $ignore_minor_edits = $args{ignore_minor_edits} ? 1 : 0; - my $username = $args{username} || ""; - my $category = $args{category} || ""; - my $locale = $args{locale} || ""; - my %criteria = ( - items => $items, - days => $days, - ignore_minor_edits => $ignore_minor_edits, - ); - my %filter; - $filter{username} = $username if $username; - $filter{category} = $category if $category; - $filter{locale} = $locale if $locale; - if ( scalar keys %filter ) { - $criteria{filter_on_metadata} = %filter; - } - - my $rdf_writer = OpenGuides::RDF->new( wiki => $self->wiki, - config => $self->config ); - my $output = "Content-Type: text/plain\n"; - $output .= "Last-Modified: " . $rdf_writer->rss_timestamp( %criteria ) . "\n\n"; - $output .= $rdf_writer->make_recentchanges_rss( %criteria ); - return $output if $return_output; - print $output; -} - -=item B<commit_node> - - $guide->commit_node( - id => $node, - cgi_obj => $q, - ); - -As with other methods, parameters C<return_tt_vars> and -C<return_output> can be used to return these things instead of -printing the output to STDOUT. - -The geographical data that you should provide in the L<CGI> object -depends on the handler you chose in C<wiki.conf>. - -=over - -=item * - -B<British National Grid> - provide either C<os_x> and C<os_y> or -C<latitude> and C<longitude>; whichever set of data you give, it will -be converted to the other and both sets will be stored. - -=item * - -B<Irish National Grid> - provide either C<osie_x> and C<osie_y> or -C<latitude> and C<longitude>; whichever set of data you give, it will -be converted to the other and both sets will be stored. - -=item * - -B<UTM ellipsoid> - provide C<latitude> and C<longitude>; these will be -converted to easting and northing and both sets of data will be stored. - -=back - -=cut - -sub commit_node { - my ($self, %args) = @_; - my $node = $args{id}; - my $q = $args{cgi_obj}; - my $return_output = $args{return_output}; - my $wiki = $self->wiki; - my $config = $self->config; - - my $content = $q->param("content"); - $content =~ s/\r\n/\n/gs; - my $checksum = $q->param("checksum"); - - my %metadata = OpenGuides::Template->extract_metadata_vars( - wiki => $wiki, - config => $config, - cgi_obj => $q - ); - - $metadata{opening_hours_text} = $q->param("hours_text") || ""; - - # Pick out the unmunged versions of lat/long if they're set. - # (If they're not, it means they weren't munged in the first place.) - $metadata{latitude} = delete $metadata{latitude_unmunged} - if $metadata{latitude_unmunged}; - $metadata{longitude} = delete $metadata{longitude_unmunged} - if $metadata{longitude_unmunged}; - - # Check to make sure all the indexable nodes are created - foreach my $type (qw(Category Locale)) { - my $lctype = lc($type); - foreach my $index (@{$metadata{$lctype}}) { - $index =~ s/(.*)/\u$1/; - my $node = $type . " " . $index; - # Uppercase the node name before checking for existence - $node =~ s/ (\S+)/ \u$1/g; - unless ( $wiki->node_exists($node) ) { - my $category = $type eq "Category" ? "Category" : "Locales"; - $wiki->write_node( $node, - "@INDEX_LINK [[$node]]", - undef, - { username => "Auto Create", - comment => "Auto created $lctype stub page", - category => $category - } - ); - } - } - } - - foreach my $var ( qw( username comment edit_type ) ) { - $metadata{$var} = $q->param($var) || ""; - } - $metadata{host} = $ENV{REMOTE_ADDR}; - - # CGI::Wiki::Plugin::RSS::ModWiki wants "major_change" to be set. - $metadata{major_change} = ( $metadata{edit_type} eq "Normal edit" ) - ? 1 - : 0; - - my $written = $wiki->write_node($node, $content, $checksum, %metadata ); - - if ($written) { - my $output = $self->redirect_to_node($node); - return $output if $return_output; - print $output; - } else { - my %node_data = $wiki->retrieve_node($node); - my %tt_vars = ( checksum => $node_data{checksum}, - new_content => $content, - stored_content => $node_data{content} ); - foreach my $mdvar ( keys %metadata ) { - if ($mdvar eq "locales") { - $tt_vars{"stored_$mdvar"} = $node_data{metadata}{locale}; - $tt_vars{"new_$mdvar"} = $metadata{locale}; - } elsif ($mdvar eq "categories") { - $tt_vars{"stored_$mdvar"} = $node_data{metadata}{category}; - $tt_vars{"new_$mdvar"} = $metadata{category}; - } elsif ($mdvar eq "username" or $mdvar eq "comment" - or $mdvar eq "edit_type" ) { - $tt_vars{$mdvar} = $metadata{$mdvar}; - } else { - $tt_vars{"stored_$mdvar"} = $node_data{metadata}{$mdvar}[0]; - $tt_vars{"new_$mdvar"} = $metadata{$mdvar}; - } - } - return %tt_vars if $args{return_tt_vars}; - my $output = $self->process_template( - id => $node, - template => "edit_conflict.tt", - tt_vars => %tt_vars, - ); - return $output if $args{return_output}; - print $output; - } -} - - -=item B<delete_node> - - $guide->delete_node( - id => "FAQ", - version => 15, - password => "beer", - ); - -C<version> is optional - if it isn't supplied then all versions of the -node will be deleted; in other words the node will be entirely -removed. - -If C<password> is not supplied then a form for entering the password -will be displayed. - -As with other methods, parameters C<return_tt_vars> and -C<return_output> can be used to return these things instead of -printing the output to STDOUT. - -=cut - -sub delete_node { - my ($self, %args) = @_; - my $node = $args{id} or croak "No node ID supplied for deletion"; - my $return_tt_vars = $args{return_tt_vars} || 0; - my $return_output = $args{return_output} || 0; - - my %tt_vars = ( - not_editable => 1, - not_deletable => 1, - deter_robots => 1, - ); - $tt_vars{delete_version} = $args{version} || ""; - - my $password = $args{password}; - - if ($password) { - if ($password ne $self->config->admin_pass) { - return %tt_vars if $return_tt_vars; - my $output = $self->process_template( - id => $node, - template => "delete_password_wrong.tt", - tt_vars => %tt_vars, - ); - return $output if $return_output; - print $output; - } else { - $self->wiki->delete_node( - name => $node, - version => $args{version}, - ); - # Check whether any versions of this node remain. - my %check = $self->wiki->retrieve_node( name => $node ); - $tt_vars{other_versions_remain} = 1 if $check{version}; - return %tt_vars if $return_tt_vars; - my $output = $self->process_template( - id => $node, - template => "delete_done.tt", - tt_vars => %tt_vars, - ); - return $output if $return_output; - print $output; - } - } else { - return %tt_vars if $return_tt_vars; - my $output = $self->process_template( - id => $node, - template => "delete_confirm.tt", - tt_vars => %tt_vars, - ); - return $output if $return_output; - print $output; - } -} - -sub process_template { - my ($self, %args) = @_; - my %output_conf = ( wiki => $self->wiki, - config => $self->config, - node => $args{id}, - template => $args{template}, - vars => $args{tt_vars}, - cookies => $args{cookies}, - ); - if ( $args{content_type} ) { - $output_conf{content_type} = ""; - my $output = "Content-Type: $args{content_type}\n\n" - . OpenGuides::Template->output( %output_conf ); - } else { - return OpenGuides::Template->output( %output_conf ); - } -} - -sub redirect_to_node { - my ($self, $node, $redirected_from) = @_; - - my $script_url = $self->config->script_url; - my $script_name = $self->config->script_name; - my $formatter = $self->wiki->formatter; - - my $id = $formatter->node_name_to_node_param( $node ); - my $oldid; - $oldid = $formatter->node_name_to_node_param( $redirected_from ) if $redirected_from; - - my $redir_param = "$script_url$script_name?"; - $redir_param .= 'id=' if $oldid; - $redir_param .= $id; - $redir_param .= ";oldid=$oldid" if $oldid; - - return CGI->redirect( $redir_param ); -} - -sub get_cookie { - my $self = shift; - my $config = $self->config; - my $pref_name = shift or return ""; - my %cookie_data = OpenGuides::CGI->get_prefs_from_cookie(config=>$config); - return $cookie_data{$pref_name}; -} - - -=back - -=head1 BUGS AND CAVEATS - -UTF8 data are currently not handled correctly throughout. - -Other bugs are documented at -Lhttp://rt.cpan.org/NoAuth/Bugs.html?Dist=OpenGuides - -=head1 SEE ALSO - -=over 4 - -=item * L<http://london.openguides.org/%7CThe Open Guide to London>, the first and biggest OpenGuides site. - -=item * L<http://openguides.org/%7CThe OpenGuides website>, with a list of all live OpenGuides installs. - -=item * LCGI::Wiki, the Wiki toolkit which does the heavy lifting for OpenGuides - -=back - -=head1 FEEDBACK - -If you have a question, a bug report, or a patch, or you're interested -in joining the development team, please contact openguides-dev@openguides.org -(moderated mailing list, will reach all current developers but you'll have -to wait for your post to be approved) or file a bug report at -Lhttp://rt.cpan.org/NoAuth/Bugs.html?Dist=OpenGuides - -=head1 AUTHOR - -The OpenGuides Project (openguides-dev@openguides.org) - -=head1 COPYRIGHT - - Copyright (C) 2003-2005 The OpenGuides Project. All Rights Reserved. - -The OpenGuides distribution is free software; you can redistribute it -and/or modify it under the same terms as Perl itself. - -=head1 CREDITS - -Programming by Dominic Hargreaves, Earle Martin, Kake Pugh, and Ivor -Williams. Testing and bug reporting by Billy Abbott, Jody Belka, -Kerry Bosworth, Simon Cozens, Cal Henderson, Steve Jolly, and Bob -Walker (among others). Much of the Module::Build stuff copied from -the Siesta project Lhttp://siesta.unixbeard.net/ - -=cut - -1;
Copied: tags/rel0_49/lib/OpenGuides.pm (from rev 670, trunk/lib/OpenGuides.pm)
Deleted: tags/rel0_49/wiki.cgi =================================================================== --- trunk/wiki.cgi 2005-07-23 02:01:06 UTC (rev 666) +++ tags/rel0_49/wiki.cgi 2005-07-24 00:41:54 UTC (rev 671) @@ -1,321 +0,0 @@ -#!/usr/local/bin/perl - -use strict; -use warnings; - -use vars qw( $VERSION ); -$VERSION = '0.48'; - -use CGI qw/:standard/; -use CGI::Carp qw(croak); -use CGI::Wiki; -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 ); - - 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) { - preview_node($node); - } elsif ($action eq 'edit') { - edit_node($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 'index') { - $guide->show_index( - type => $q->param("index_type") || "Full", - value => $q->param("index_value") || "", - format => $format, - ); - } elsif ($action eq 'random') { - my @nodes = $wiki->list_all_nodes(); - $node = $nodes[int(rand(scalar(@nodes) + 1)) + 1]; - print $guide->redirect_to_node($node); - exit 0; - } elsif ($action eq 'find_within_distance') { - $guide->find_within_distance( - id => $node, - metres => $q->param("distance_in_metres") - ); - } 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') { - $guide->list_all_versions( id => $node ); - } elsif ($action 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 ); - $guide->display_rss( %args ); - } elsif ( $feed eq "chef_dan" ) { - display_node_rdf( node => $node ); - } else { - croak "Unknown RSS feed type '$feed'"; - } - } else { # Default is to display a node. - if ( $format and $format eq "rdf" ) { - display_node_rdf( node => $node ); - } 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 { - $guide->display_node( - id => $node, - version => $version, - oldid => $oldid, - ); - - } - } - } -}; - -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>); -} -exit 0; - -############################ 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 => $q->escapeHTML($_->{metadata}{comment}[0]), - 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 preview_node { - my $node = shift; - my $content = $q->param('content'); - $content =~ s/\r\n/\n/gs; - my $checksum = $q->param('checksum'); - - my %tt_metadata_vars = OpenGuides::Template->extract_metadata_vars( - wiki => $wiki, - config => $config, - cgi_obj => $q, - set_coord_field_vars => 1, - ); - foreach my $var ( qw( username comment edit_type ) ) { - $tt_metadata_vars{$var} = $q->escapeHTML($q->param($var)); - } - - if ($wiki->verify_checksum($node, $checksum)) { - my %tt_vars = ( - %tt_metadata_vars, - content => $q->escapeHTML($content), - preview_html => $wiki->format($content), - preview_above_edit_box => get_cookie( "preview_above_edit_box" ), - checksum => $q->escapeHTML($checksum) - ); - process_template("edit_form.tt", $node, %tt_vars); - } else { - my %node_data = $wiki->retrieve_node($node); - my %tt_vars = ( checksum => $node_data{checksum}, - new_content => $content, - stored_content => $node_data{content} ); - foreach my $mdvar ( keys %tt_metadata_vars ) { - if ($mdvar eq "locales") { - $tt_vars{"stored_$mdvar"} = $node_data{metadata}{locale}; - $tt_vars{"new_$mdvar"} = $tt_metadata_vars{locale}; - } elsif ($mdvar eq "categories") { - $tt_vars{"stored_$mdvar"} = $node_data{metadata}{category}; - $tt_vars{"new_$mdvar"} = $tt_metadata_vars{category}; - } elsif ($mdvar eq "username" or $mdvar eq "comment" - or $mdvar eq "edit_type" ) { - $tt_vars{$mdvar} = $tt_metadata_vars{$mdvar}; - } else { - $tt_vars{"stored_$mdvar"} = $node_data{metadata}{$mdvar}[0]; - $tt_vars{"new_$mdvar"} = $tt_metadata_vars{$mdvar}; - } - } - process_template("edit_conflict.tt", $node, %tt_vars); - } -} - -sub edit_node { - my $node = shift; - my %node_data = $wiki->retrieve_node($node); - my ($content, $checksum) = @node_data{ qw( content checksum ) }; - my $username = get_cookie( "username" ); - my $edit_type = get_cookie( "default_edit_type" ) eq "normal" ? - "Normal edit" : "Minor tidying"; - - my %metadata_vars = OpenGuides::Template->extract_metadata_vars( - wiki => $wiki, - config => $config, - metadata => $node_data{metadata} ); - - my %tt_vars = ( content => $q->escapeHTML($content), - checksum => $q->escapeHTML($checksum), - %metadata_vars, - username => $username, - edit_type => $edit_type, - deter_robots => 1, - ); - - process_template("edit_form.tt", $node, %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: text/plain\n\n"; - print $rdf_writer->emit_rdfxml( node => $args{node} ); - exit 0; -} - -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{content_type} = "" 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 } ); -} -
Copied: tags/rel0_49/wiki.cgi (from rev 670, trunk/wiki.cgi)
openguides-commits@lists.openguides.org