[wellwell-devel] [SCM] Interchange wellwell catalog branch, master, updated. f4c4048a0fa8a0c2d0393405d0d3a804410e61a2

Stefan Hornburg racke at rt.icdevgroup.org
Fri Dec 4 14:05:26 UTC 2009


       via  f4c4048a0fa8a0c2d0393405d0d3a804410e61a2 (commit)
       via  96c610251accd616ac45f76ac58c95dcbe7e7f56 (commit)
      from  a1450591e071c97d0d950620f4e769853a92ba41 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit f4c4048a0fa8a0c2d0393405d0d3a804410e61a2
Merge: 96c610251accd616ac45f76ac58c95dcbe7e7f56 a1450591e071c97d0d950620f4e769853a92ba41
Author: Stefan Hornburg (Racke) <racke at linuxia.de>
Date:   Fri Dec 4 15:05:05 2009 +0100

    Merge branch 'master' of ssh://git.icdevgroup.org/var/git/wellwell

commit 96c610251accd616ac45f76ac58c95dcbe7e7f56
Author: Stefan Hornburg (Racke) <racke at linuxia.de>
Date:   Fri Dec 4 15:04:17 2009 +0100

    Vend::Wiki module and wiki plugin added, based on Wiki::Toolkit

-----------------------------------------------------------------------

Summary of changes and diff:
 lib/Vend/Wiki.pm                                   |  274 ++++++++++++++++++++
 plugins/wiki/components/wiki                       |   56 ++++
 plugins/wiki/pages/wiki.itl                        |    6 +
 plugins/wiki/plugin.cfg                            |    9 +
 .../discount_gifts.info => wiki/wiki.info}         |    3 +-
 5 files changed, 347 insertions(+), 1 deletions(-)
 create mode 100644 lib/Vend/Wiki.pm
 create mode 100644 plugins/wiki/components/wiki
 create mode 100644 plugins/wiki/pages/wiki.itl
 create mode 100644 plugins/wiki/plugin.cfg
 copy plugins/{discount_gifts/discount_gifts.info => wiki/wiki.info} (64%)

diff --git a/lib/Vend/Wiki.pm b/lib/Vend/Wiki.pm
new file mode 100644
index 0000000..5b2f86d
--- /dev/null
+++ b/lib/Vend/Wiki.pm
@@ -0,0 +1,274 @@
+# Vend::Wiki - Interchange Wiki
+#
+# Copyright (C) 2004-2009 Stefan Hornburg (Racke) <racke at linuxia.de>.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with this program; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+package Vend::Wiki;
+
+use strict;
+use warnings;
+
+use Vend::Config;
+use Vend::Tags;
+
+use Wiki::Toolkit;
+
+# setup wiki configuration directive
+Vend::Config::parse_directive('Wiki', 'Wiki wiki');
+
+# define [wiki] tag
+Vend::Config::parse_tag('UserTag', 'wiki Order function');
+Vend::Config::parse_tag('UserTag', 'wiki HasEndTag');
+Vend::Config::parse_tag('UserTag', 'wiki AddAttr');
+Vend::Config::parse_tag('UserTag', 'wiki MapRoutine Vend::Wiki::wiki');
+
+# define [wiki] global sub for catalog actions
+Vend::Config::parse_subroutine('GlobalSub', 'wiki Vend::Wiki::action');
+
+our %wiki;
+
+sub new {
+	my ($class, @parms) = @_;
+	my $self = {@parms};
+
+	bless $self;
+
+	if ($self->{backend} eq 'sqlite') {
+		unless (-f $self->{dbname}) {
+			# create SqLite file
+			require Wiki::Toolkit::Setup::SQLite;
+			Wiki::Toolkit::Setup::SQLite::setup($self->{dbname});
+		}
+		require Wiki::Toolkit::Store::SQLite;
+		$self->{store} = new Wiki::Toolkit::Store::SQLite(dbname => $self->{dbname});
+	}
+
+	# create Wiki::Toolkit formatter
+	require Wiki::Toolkit::Formatter::Default;
+	$self->{formatter} = new Wiki::Toolkit::Formatter::Default(node_prefix => '?page=');
+		
+	# create Wiki::Toolkit object
+	$self->{object} = new Wiki::Toolkit(store => $self->{store},
+										formatter => $self->{formatter});
+										
+	return $self;
+}
+	
+sub wiki {
+	my ($function, $opt, $body) = @_;
+	my ($ret, $name);
+
+	# default name for the wiki is just wiki
+	$name = $opt->{name} || 'wiki';
+	
+	unless (exists $wiki{$name}) {
+		# initialize Wiki
+		unless (exists $Vend::Cfg->{Wiki}->{$name}) {
+			# Wiki not defined
+			return 'WIKI_NOT_DEFINED';
+		}
+		
+		$wiki{$name} = new Vend::Wiki(%{$Vend::Cfg->{Wiki}->{$name}});
+	}
+
+	if ($function eq 'create_page') {
+		$ret = $wiki{$name}->create_page($opt->{page}, $opt->{content});
+		return $ret;
+	}
+
+	if ($function eq 'modify' || $function eq 'modify_page') {
+		$ret = $wiki{$name}->modify_page($opt->{page}, $opt->{content}, $opt->{checksum});
+		return $ret;
+	}
+	
+	if ($function eq 'display' || $function eq 'display_page') {
+		my %page;
+
+		if ($body) {
+			# run templating on page
+			%page = $wiki{$name}->display_page($opt->{page}, undef, 'raw');
+			return Vend::Tags->uc_attr_list({body => $body, hash => \%page});
+		}
+		else {
+			# just return page content
+			return $wiki{$name}->display_page($opt->{page});
+		}
+	}
+	
+	if ($function eq 'list') {
+		 my @nodes = $wiki{$name}->list_pages();
+
+		 if ($body) {
+			 # run templating on page list
+			 my @list = map {Vend::Tags->uc_attr_list({body => $body,
+													   hash => {page => $_}})} @nodes;
+			 return join('', @list);
+		 } elsif (wantarray) {
+			 return @nodes;
+		 }
+		 else {
+			 return join(',', @nodes);
+		 }
+	}
+	
+	return $function;
+}
+
+# create Wiki page
+#
+# @param name page name
+# @param content page content
+
+sub create_page {
+	my ($self, $name, $content) = @_;
+	my ($ret);
+	
+	$ret = $self->{object}->write_node($name, $content);
+
+	unless ($ret) {
+		::logError("Failed to create page $name.");
+	}
+	
+	return $ret;
+}
+
+# modify Wiki page
+sub modify_page {
+	my ($self, $name, $content, $checksum) = @_;
+	my ($ret);
+	
+	$ret = $self->{object}->write_node($name, $content, $checksum);
+
+	unless ($ret) {
+		die "Page modification failed.";
+	}
+}
+
+## @method retrieve_page($name, $version)
+#
+# Retrieves Wiki page.
+#
+# @param name page name
+# @param version page version
+
+sub retrieve_page {
+	my ($self, $name, $version) = @_;
+	my (%node);
+
+	if ($name =~ /\S/ && $self->{object}->node_exists($name)) {
+		if ($version) {
+			%node = $self->{object}->retrieve_node({name => $name, version => $version});
+		}
+		else {
+			%node = $self->{object}->retrieve_node($name);
+		}
+		return %node;
+	}
+
+	return;
+}
+
+## @method display_page($name, $version, $format)
+# Displays Wiki page.
+#
+# @param name page name
+# @param version page version
+# @param format page format
+
+sub display_page {
+	my ($self, $name, $version, $format) = @_;
+	my (%node);
+
+	if ($name =~ /\S/ && $self->{object}->node_exists($name)) {
+		if ($version) {
+			%node = $self->{object}->retrieve_node({name => $name, version => $version});
+		}
+		else {
+			%node = $self->{object}->retrieve_node($name);
+		}
+
+		if ($format ne 'raw') {
+			return $self->{object}->format($node{content}, $node{metadata});
+		}
+
+		return %node;
+	}
+	else {
+		# boilerplate message for missing pages
+		return ::errmsg(q{This page does not exist yet. You can create a new empty page.});
+	}
+}
+
+# list Wiki pages
+sub list_pages {
+	my ($self) = @_;
+	my (@pages);
+
+	@pages = $self->{object}->list_all_nodes();
+	return @pages;
+}
+
+# default ActionMap for wiki
+sub action {
+ 	my ($path) = @_;
+	my ($action, $url, $page, $name, $key, $value);
+	
+ 	($action, $url) = split(m{/+}, $path, 2);
+
+	# examine configuration for wiki name and relay to configured page
+	while (($key, $value) = each %{$Vend::Cfg->{Wiki}}) {
+		if ($action eq $value->{url}) {
+			$name = $key;
+			$page = $value->{page};
+		}
+	}
+
+	# provide default for target page
+	$page ||= 'wiki';
+
+	# pass wiki parameters to page
+	$CGI::values{name} = $name;
+	$CGI::values{page} ||= $url;
+
+	# actual page
+	$CGI::values{mv_nextpage} = $page;
+	
+ 	return 1;
+}
+
+package Vend::Config;
+
+sub parse_wiki {
+	my ($item, $settings) = @_;
+
+	# parse routine is called once per catalog, regardless of configuration
+	# directives
+	return {} unless $settings;
+
+	my ($name, $param, $value) = split(/\s+/, $settings);
+
+	if ($param eq 'url') {
+		# add pointer for our ActionMap
+		Vend::Config::parse_action('ActionMap', "$value wiki");
+	}
+	
+	$C->{$item}->{$name}->{$param} = $value;
+	#config_error("No code written yet for $var and $value.", $var, $value);
+	return $C->{$item};
+}
+
+1;
diff --git a/plugins/wiki/components/wiki b/plugins/wiki/components/wiki
new file mode 100644
index 0000000..ea7c2f7
--- /dev/null
+++ b/plugins/wiki/components/wiki
@@ -0,0 +1,56 @@
+<p>
+ACTION [cgi action]
+<br>
+PAGE [either][cgi page][or]__PAGE__[/either]
+</p>
+[if cgi action eq create]
+[if cgi content]
+CREATING
+[wiki name="__NAME__" function="create_page" page="[cgi page]" content="[cgi content]"/]
+[/if]
+<form action="[area href="wiki" nosession=1]" method="POST">
+[form_session_id]
+<input type="hidden" name="action" value="[cgi action]">
+<input name="page">
+<br>
+<textarea name="content">
+[value content]
+</textarea>
+<br>
+<input type="submit" value="OK">
+<br>
+</form>
+[elsif cgi action eq edit]
+[if cgi checksum]
+[wiki name="__NAME__" function="modify" page="__PAGE__" content="[cgi content]" checksum="[cgi checksum]"/]
+[else]
+[wiki name="__NAME__" function="display" page="__PAGE__"]
+<form action="[area href="wiki/__PAGE__" nosession=1]" method="POST">
+[form_session_id]
+<input type="hidden" name="action" value="[cgi action]">
+<input type="hidden" name="checksum" value="{CHECKSUM}">
+<input type="hidden" name="page" value="__PAGE__">
+<br>
+<textarea name="content">
+{CONTENT}
+</textarea>
+<br>
+<input type="submit" value="OK">
+<br>
+</form>
+[/wiki]
+[/else]
+[/if]
+[/elsif]
+[else]
+<a href="[area href=wiki form=action=create]">Create page</a>
+
+[wiki name="__NAME__" function="display" page="__PAGE__"/]
+
+<a href="[area href="wiki/__PAGE__" form=action=edit]">Edit page</a>
+[/else]
+[/if]
+
+LIST: [wiki name="__NAME__" function="list"]
+<a href="[area href="wiki/{PAGE}"]">{PAGE}</a><br>
+[/wiki]
\ No newline at end of file
diff --git a/plugins/wiki/pages/wiki.itl b/plugins/wiki/pages/wiki.itl
new file mode 100644
index 0000000..dac13d4
--- /dev/null
+++ b/plugins/wiki/pages/wiki.itl
@@ -0,0 +1,6 @@
+[compose
+	components.body="wiki"
+
+	attributes.wiki.name="[cgi name]"
+	attributes.wiki.page="[cgi page]"
+]
\ No newline at end of file
diff --git a/plugins/wiki/plugin.cfg b/plugins/wiki/plugin.cfg
new file mode 100644
index 0000000..b312815
--- /dev/null
+++ b/plugins/wiki/plugin.cfg
@@ -0,0 +1,9 @@
+Message Loading wiki plugin.
+
+Variable CURPLUGIN wiki
+include plugins/default.cfg
+
+Wiki wiki backend sqlite
+Wiki wiki dbname  database/wiki.db
+
+ActionMap wiki wiki
\ No newline at end of file
diff --git a/plugins/discount_gifts/discount_gifts.info b/plugins/wiki/wiki.info
similarity index 64%
copy from plugins/discount_gifts/discount_gifts.info
copy to plugins/wiki/wiki.info
index 148e86f..ccf5fb2 100644
--- a/plugins/discount_gifts/discount_gifts.info
+++ b/plugins/wiki/wiki.info
@@ -1,3 +1,4 @@
-name = Discount Gifts
+name = Wiki
 version = 0.1
 author = Stefan Hornburg (Racke) <racke at linuxia.de>
+require = Wiki::Toolkit


hooks/post-receive
-- 
Interchange wellwell catalog



More information about the wellwell-devel mailing list