Index: lib/TWiki/Plugins/EmptyPlugin.pm =================================================================== --- lib/TWiki/Plugins/EmptyPlugin.pm (revision 4530) +++ lib/TWiki/Plugins/EmptyPlugin.pm (working copy) @@ -640,4 +640,20 @@ sub DISABLE_renderFormFieldForEditHandler { } +=pod + + +---++ restExample($session) -> $text + +This is an example of a sub to be called by the ==rest== script. The parameter is: + * =$session= - The TWiki object associated to this session. + +Additional parameters can be recovered via de query object in the $session. + +=cut + +sub restExample { + return "This is an example of a REST invocation"; +} + 1; Index: lib/TWiki/UI/Rest.pm =================================================================== --- lib/TWiki/UI/Rest.pm (revision 0) +++ lib/TWiki/UI/Rest.pm (revision 0) @@ -0,0 +1,116 @@ +# TWiki Enterprise Collaboration Platform, http://TWiki.org/ +# +# Copyright (C) 1999-2005 Peter Thoeny, peter@thoeny.com +# and TWiki Contributors. All Rights Reserved. TWiki Contributors +# are listed in the AUTHORS file in the root of this distribution. +# NOTE: Please extend that file, not this notice. +# +# Additional copyrights apply to some or all of the code in this +# file as follows: +# Based on parts of Ward Cunninghams original Wiki and JosWiki. +# Copyright (C) 1998 Markus Peter - SPiN GmbH (warpi@spin.de) +# Some changes by Dave Harris (drh@bhresearch.co.uk) incorporated +# +# 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. For +# more details read LICENSE in the root of this distribution. +# +# 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. +# +# As per the GPL, removal of this notice is prohibited. + +=begin twiki + +---+ package TWiki::UI::Rest + +Rest delegate for view function + +=cut + +package TWiki::UI::Rest; + +use strict; +use integer; + +use TWiki; +use TWiki::User; +use TWiki::UI; +use TWiki::Time; + +=pod + +---++ StaticMethod gateway( $session, $web, $topic, $scriptUrl, $query ) +=rest= command handler. +This method is designed to be invoked via the =TWiki::UI::run= method. + +Execute a plugin method. If $topic==$cfg{HomeTopicName} (i.e: WebHome) or null, +it'll print the result directly to the stream, otherwise the control is redirected +to the given topic. + +The view is controlled by CGI parameters as follows: + +| =plugin= | Plugin to be invoked | +| =method= | Method to execute | + +Any additional parameter is passed directly to the method (i.e: The method +can get any other parameter using the $query object) + +---+++ Invocation Examples: + +==http://my.host/bin/rest/SomeWeb/WebHome?plugin=EmptyPlugin&method=testRest== + +Will invoke TWiki::Plugin::EmptyPlugin::testRest, and print the result +directly to the stream. + +==http://my.host/bin/rest/SomeWeb/SomeTopic?plugin=EmptyPlugin&method=testRest== + +Will invoke TWiki::Plugin::EmptyPlugin::testRest, and redirect the control +to SomeWeb.SomeTopic + +=cut +sub gateway { + my $session = shift; + $session->enterContext( 'rest' ); + + my $query = $session->{cgiQuery}; + my $web = $session->{webName}; + my $topic = $session->{topicName}; + + my $method = $query->param( 'method' ); + + if (TWiki::isValidWikiWord($plugin)) { + my $class = TWiki::Sandbox::untaintUnchecked('TWiki::Plugins::'.$plugin); + + my $m = TWiki::Sandbox::untaintUnchecked($class.'::'.$method); + + eval "use $class"; + if( $@ ) { + die "$class compile failed: $@"; + } + + no strict 'refs'; + local $TWiki::Plugins::SESSION=$session; + my $result=''; + $result=&$m($session) if defined(&$m); + use strict 'refs'; + + return if !defined($result); + + if ($topic eq $TWiki::cfg{HomeTopicName}) { + $session->writeCompletePage( $result ); + } else { + my $url=$session->getScriptUrl( $web, $topic, 'view' ); + $session->redirect($url); + } + } else { + $session->writeCompletePage( 'Unknown Command'.$plugin.'::'.$method); + } + + $session->leaveContext( 'rest' ); +} + +1; Property changes on: lib/TWiki/UI/Rest.pm ___________________________________________________________________ Name: svn:executable + * Index: bin/rest =================================================================== --- bin/rest (revision 0) +++ bin/rest (revision 0) @@ -0,0 +1,30 @@ +#!/usr/bin/perl -wT +# +# TWiki Collaboration Platform, http://TWiki.org/ +# +# For licensing info read license.txt file in the TWiki root. +# 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, published at +# http://www.gnu.org/copyleft/gpl.html + +BEGIN { + # Set default current working directory (needed for mod_perl) + if( $ENV{"SCRIPT_FILENAME"} && $ENV{"SCRIPT_FILENAME"} =~ /^(.+)\/[^\/]+$/ ) { + chdir $1; + } + # Set library paths in @INC, at compile time + unshift @INC, '.'; + require 'setlib.cfg'; +} + +use TWiki::UI::Rest; + +TWiki::UI::run(\&TWiki::UI::Rest::gateway); + Property changes on: bin/rest ___________________________________________________________________ Name: svn:executable + * Index: data/TWiki/TWikiTemplates.txt =================================================================== --- data/TWiki/TWikiTemplates.txt (revision 4530) +++ data/TWiki/TWikiTemplates.txt (working copy) @@ -60,6 +60,7 @@ | body_text | when the body text is being processed in a view | | footer_text | when the footer text is being processed in a view | | oops | in oops script | +| rest | in rest script | ---+++ Finding Templates Index: data/TWiki/TWikiPlugins.txt =================================================================== --- data/TWiki/TWikiPlugins.txt (revision 4530) +++ data/TWiki/TWikiPlugins.txt (working copy) @@ -134,6 +134,10 @@ TWiki:Codev/StepByStepRenderingOrder helps you decide which rendering handler to use. +---+++ RESTful interface + +By using the ==rest== script (see TWikiScripts for more info), external systems or other TWikiApplications can interact with a plugin in a RESTful manner. + ---+++ Hints on Writing Fast Plugins * Delay the Plugin initialization to the actual function which is handling the tag. This way all the expensive initialization is done only when needed. Index: data/TWiki/TWikiScripts.txt =================================================================== --- data/TWiki/TWikiScripts.txt (revision 4530) +++ data/TWiki/TWikiScripts.txt (working copy) @@ -126,6 +126,32 @@ ---++ =preview= This script is _deprecated_. Its functions are covered by the =save= script. + +---++ =rest= + +Can be invoked in a similar way as the view script (see *Invocation Examples*, bellow) to execute a plugin method. It'll print the result directly to the stream unless a web and a topic different than %HOMETOPIC% is specified, in which case the control is redirected +to the given topic. + +The view is controlled by CGI parameters as follows: + +| =plugin= | Plugin to be invoked | +| =method= | Method to execute | + +Any additional parameter is passed directly to the method (i.e: The method +can get any other parameter using the $query object) + +---+++ Invocation Examples: + +==http://my.host/bin/rest/SomeWeb/WebHome?plugin=EmptyPlugin&method=testRest== + +Will invoke TWiki::Plugin::EmptyPlugin::testRest, and print the result +directly to the stream. + +==http://my.host/bin/rest/SomeWeb/SomeTopic?plugin=EmptyPlugin&method=testRest== + +Will invoke TWiki::Plugin::EmptyPlugin::testRest, and redirect the control +to SomeWeb.SomeTopic + ---++ =rdiff= ---++ =register= Index: data/TestCases/TestCaseRestTest.txt =================================================================== --- data/TestCases/TestCaseRestTest.txt (revision 0) +++ data/TestCases/TestCaseRestTest.txt (revision 0) @@ -0,0 +1,14 @@ +%META:TOPICINFO{author="RafaelAlvarez" date="1120278054" format="1.1" version="1.1"}% +%META:TOPICPARENT{name="WebHome"}% + +---+!! %TOPIC% + +Description: _Verify that the ==rest== script is working properly_ + +Click the link below. If the script is working, a page with the text "This is an example of a REST invocation" should appear. + +[[%SCRIPTURL%/rest%SCRIPTSUFFIX%/%WEB%/WebHome?plugin=EmptyPlugin&method=restExample&debugenableplugin=EmptyPlugin][Call the Plugin]] + + + + Property changes on: data/TestCases/TestCaseRestTest.txt ___________________________________________________________________ Name: svn:executable + *