Skip to content

Commit

Permalink
Item1156: Create Release01x00 branch
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/branches/Release01x00@2727 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
KennethLavrsen authored and KennethLavrsen committed Feb 26, 2009
1 parent af6570d commit d399d97
Show file tree
Hide file tree
Showing 8 changed files with 562 additions and 0 deletions.
51 changes: 51 additions & 0 deletions PreferencesPlugin/data/System/DefaultPreferencesForm.txt
@@ -0,0 +1,51 @@
|*Name*|*Type*|*Size*|*Value*|*Tooltip message* |*Attributes*|
| WEBBGCOLOR | text | 20 | #FFD8AA | HTML Color | S |
| FAVICON | text | 30 | %PUBURL%/%WEB%/WebPreferences/favicon.ico | URL of an icon image | S |
| WEBCOPYRIGHT | textarea | | Copyright &copy; 1999-%GMTIME{"$year"}% by the contributing authors. \nAll material on this collaboration platform is the property of the contributing authors. <br /> \nIdeas, requests, problems regarding <nop>%WIKITOOLNAME%? <a href="mailto:%WIKIWEBMASTER%?subject=%WIKITOOLNAME%&#32;Feedback&#32;on&#32;%WEB%.%TOPIC%">Send feedback</a> | Long form copyright | S |
| WEBRSSCOPYRIGHT | text | 30 | Copyright %GMTIME{"$year"}% by contributing authors | Short form copyright | S |
| NOSEARCHALL | select | 1 | off,on | Exclude web from a =web="all"= search| S |
| NOAUTOLINK | select | 1 | off,on | Boolean | S |
| INCLUDEWARNING | text | 30 | on, off | Boolean | S |
| LINKTOOLTIPINFO | text | 30 | | Format of tooltip info | S |
| EDITBOXWIDTH | text | 30 | 70 | Horizontal size of text edit box. | S |
| EDITBOXHEIGHT | text | 30 | 15 | Vertical size of text edit box. | S |
| EDITBOXSTYLE | text | 30 | width: 99% | CSS style | S |
| PREVIEWBGIMAGE | text | 30 | %PUBURLPATH%/%SYSTEMWEB%/PreviewBackground/preview2bg.gif | Image URL | S |
| FORCENEWREVISIONCHECKBOX | select | 1 | , checked="checked" | Select checked to enable | S |
| DONTNOTIFYCHECKBOX | select | 1 | ,checked="checked" | Select checked to enable | S |
| ATTACHLINKBOX | select | 1 | ,checked="checked" | Select checked to enable | S |
| ATTACHEDFILELINKFORMAT | text | 30 | \t* [[%ATTACHURL%/$name][$name]]: $comment | Text | S |
| ATTACHEDIMAGEFORMAT | textarea | | \t* $comment: <br /><img src="%ATTACHURLPATH%/$name" alt="$comment" $size /> | Text | S |
| WIKITOOLNAME | text | 30 | Foswiki | Site name | S |
| WEBLOGONAME | text | 30 | banner.gif | Filename of a logo image | S |
| WEBLOGOIMG | text | 30 | %PUBURL%/%BASEWEB%/%WEBPREFSTOPIC%/%WEBLOGONAME% | URL of a logo image | S |
| WEBLOGOURL | text | 30 | %SCRIPTURL%/view%SCRIPTSUFFIX%/%BASEWEB%/%HOMETOPIC% | URL under the logo | S |
| WEBLOGOALT | text | 30 | Home | Logo tooltip text of the logo | S |
| WIKILOGOIMG | text | 30 | %PUBURL%/%SYSTEMWEB%/ProjectLogos/horzTWiki.gif | URL of a logo image | S |
| WIKILOGOURL | text | 30 | http://Foswiki.org/ | URL under the logo| S |
| WIKILOGOALT | text | 30 | Powered by Foswiki | Logo tooltip text of the logo | S |
| WIKIWEBLIST | textarea | | [[%MAINWEB%.%HOMETOPIC%][%MAINWEB%]] %SEP% [[%SYSTEMWEB%.%HOMETOPIC%][%SYSTEMWEB%]] %SEP% [[Sandbox.%HOMETOPIC%][Sandbox]] | | S |
| ATTACHFILESIZELIMIT | text | 30 | 3000 | Maximum size of attachments in KB, 0 for no limit | S |
| BROADCASTMESSAGE | textarea| | | Broadcast message on every page, for skins that support it. | S |
| SEARCHDEFAULTTTYPE | select | 1 | keyword,literal,regex | Default type for search | S |
| SEARCHVARDEFAULTTYPE | select | 1 | keyword,literal,regex | Default for =%<nop>SEARCH{}%= macro | S |
| SEARCHSTOPWORDS | textarea | | a, all, am, an, and, any, as, at, b, be, by, c, d, e, for, from, g, h, how, i, i'm, i.e., in, is, isn't, it, it's, its, j, k, l, m, n, o, of, on, or, p, q, r, s, t, that, that's, the, this, to, u, v, w, was, wasn't, what, what's, when, where, who, who's, will, with, x, y, z | Stop words, e.g., common words and characters to exclude from a keyword search | S |
| WIKIWEBMASTER | text | 30 | webmaster@example.com | Wiki administrator e-mail address | S |
| WIKIWEBMASTERNAME | text | 30 | Wiki Administrator | Wiki administrator name (first name and last name, e.g. =Fred Smith=) | S |
| HTTP_EQUIV_ON_VIEW| textarea | 30x1 | <link rel='alternate' type='application/rss+xml' title='RSS Feed' href='%SCRIPTURL%/view%SCRIPTSUFFIX%/%WEB%/WebRss' /> | http-equiv== meta tags for ==view==, ==rdiff==, ==attach==, ==search*== scripts | S |
| HTTP_EQUIV_ON_EDIT| textarea | 30x1 | = | http-equiv== meta tags for ==edit== script | S |
| HTTP_EQUIV_ON_PREVIEW| textarea | 30x1 | = | http-equiv== meta tags for ==preview== script | S |
| SKIN | text | 30 | pattern | Skin overriding the default Foswiki templates. | S |
| WEBTOPICLIST | textarea | 40x3 | [[WebChanges][Changes]] %SEP% [[WebIndex][Index]] %SEP% [[WebSearch][Search]] %SEP% Go <input type="text" name="topic" size="16" /> | Usually a list of topics | S |
| FOSWIKI_LAYOUT_URL | text | 30 | %PUBURL%/%SYSTEMWEB%/PatternSkin/layout.css | URL of a CSS | S |
| FOSWIKI_STYLE_URL | text | 30 | %PUBURL%/%SYSTEMWEB%/PatternSkin/style.css | URL of a CSS | S |
| USERLAYOUTURL | text | 30 | | URL of a CSS | S |
| USERSTYLEURL | text | 30 | | URL of a CSS | S |
| DS_THEME | text | 30 | gray | Theme: (gray, monochrome, tabstyle | S |
| DS_QUICKLINKSHEADING | text | 30 | | Quicklinks headings | S |
| DS_QUICKLINKS | text | 30 | | Quicklinks submenu | S |
| DISABLEDPLUGINS | text | 30 | EmptyPlugin, DefaultPlugin, TestFixturePlugin | Comma-separated list | S |
| INSTALLEDPLUGINS | text | 30 | | Plugin execution order, comma-separated list | S |
| READTOPICPREFS | select | 1 | on,off | Boolean | S |
| TOPICOVERRIDESUSER | select | 1 | on, off | Boolean | S |
| FINALPREFERENCES | textarea | 60x5 | ATTACHFILESIZELIMIT, PREVIEWBGIMAGE, WIKITOOLNAME, WIKIWEBMASTER, SMTPMAILHOST, SMTPSENDERHOST, ALLOWWEBMANAGE, READTOPICPREFS, TOPICOVERRIDESUSER | Multiple select | S |
57 changes: 57 additions & 0 deletions PreferencesPlugin/data/System/PreferencesPlugin.txt
@@ -0,0 +1,57 @@
%META:TOPICINFO{author="ProjectContributor" date="1115527529" format="1.0" version="$Rev$"}%
---+!! <nop>%TOPIC%

Allows editing of preferences using fields predefined in a %SYSTEMWEB%.DataForms. However, the edit fields are inlined in the text, similar to how tables are edited in Foswiki:Extensions/EditTablePlugin.

%TOC%

Insert the =%<nop>EDITPREFERENCES%= preference (see below) anywhere in your topic. It will be replaced by a button that allows editing each preference in its predefined input format (or a text box, when no format is defined for this preference).

In edit mode, the edit button is replaced by Save and Cancel buttons, with their obvious meanings.

---++ Syntax Rules

* =%<nop>EDITPREFERENCES{ "topic" }%=
* _topic_ references a [[%SYSTEMWEB%.DataForms][DataForm]] defining the format of the edit fields for preferences. It may be prefixed by a web.
* If a [[%SYSTEMWEB%.PreferenceSettings][preference setting]] is not mentioned in the form referenced by _topic_, a text input box of the specified length is provided.
* Otherwise, the input can be through textareas, select, radio, checkbox, date, or text, as provided by %SYSTEMWEB%.DataForms.
* =%<nop>EDITPREFERENCES%=
* Edit existing preferences in the topic using a simple text field.
---++ Examples
* =%<nop>EDITPREFERENCES%=
* =%<nop>EDITPREFERENCES{ "%<nop>SYSTEMWEB%.DefaultPreferencesForm" }%=

---++ Plugin Settings
* One line description, shown in the %SYSTEMWEB%.TextFormattingRules topic:
* Set SHORTDESCRIPTION = Allows editing of preferences using fields predefined in a form

---++ Plugin Installation Instructions
%$INSTALL_INSTRUCTIONS%
* If the installation was successful, an edit button should appear below:
%EDITPREFERENCES%

---++ Plugin Info

| Copyright: | Copyright (C) TWiki:Main.ThomasWeigert and TWiki Contributors |
| License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) |
| Plugin Version: | %$VERSION% (15 Dec 2008) |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 15 Dec 2008: | Arthur Clemens added reading of =Local= preferences. Foswiki version |
| 05 Nov 2007: | Kenneth Lavrsen fixed problem when settings are hidden in html comments. These settings are now ignored. |
| 23 Jun 2007: | Crawford Currie added testcases, recoded to work without a form definition, fixed for TWiki 4.2 |
| 08 Feb 2007: | Arthur Clemens added access keys for Save and Cancel, bold style for editable preference names, and a descriptive Save button label. |
| 15 Apr 2006: | Adding css classes to buttons. Removed debug print statement causing 500s on !SunOne. Prevent extra space in settings on saves. Switched to earlier handler. Converted all SCRIPTURL to SCRIPTURLPATH, and added support. The only SCRIPTURLs should be the one in the BASE tag and those in mail notification templates. Because the forms package was throwing an exception when it failed to create a form, the edit preferences plugin was aborting the whole of the session whenever the form specified in EDITPREFERENCES didn't exist. Changed it so that the Form constructor does not throw, but returns undef on a non-existant form, and changed preferences plugin to be tolerant of missing forms (ie defaults all fields to text if the form is missing, of is a Set exists which is not in the form). |
| 26 May 2005: | Crawford Currie recoded to use code from Form.pm to render form fields. |
| 08 May 2005: | Add plugin preference to define default input length |
| 07 May 2005: | Initial version |
| Foswiki Dependency: | $Foswiki::Plugins::VERSION 1.026 |
| CPAN Dependencies: | none |
| Other Dependencies: | none |
| Perl Version: | 5.008 |
| Plugin Home: | http://foswiki.org/Extensions/%TOPIC% |
| Feedback: | http://foswiki.org/Extensions/%TOPIC%Dev |

---
*Related Topics:* %SYSTEMWEB%.DefaultPreferences, %USERSWEB%.SitePreferences, %SYSTEMWEB%.DataForms


274 changes: 274 additions & 0 deletions PreferencesPlugin/lib/Foswiki/Plugins/PreferencesPlugin.pm
@@ -0,0 +1,274 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2005-2007 Foswiki Contributors.
# All Rights Reserved. Foswiki Contributors are listed in the
# AUTHORS file in the root of this distribution.
# NOTE: Please extend that file, not this notice.
#
# 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.
#
# For licensing info read LICENSE file in the Foswiki root.

# Still do to:
# Handle continuation lines (see Prefs::parseText). These should always
# go into a text area.

package Foswiki::Plugins::PreferencesPlugin;

use strict;

require Foswiki::Func; # The plugins API
require Foswiki::Plugins; # For the API version

use vars qw( $VERSION $RELEASE @shelter );

# This should always be $Rev$ so that Foswiki can determine the checked-in
# status of the plugin. It is used by the build automation tools, so
# you should leave it alone.
$VERSION = '$Rev$';

# This is a free-form string you can use to "name" your own plugin version.
# It is *not* used by the build automation tools, but is reported as part
# of the version number in PLUGINDESCRIPTIONS.
$RELEASE = 'Foswiki-1.0';

my $MARKER = "\007";

# Markers used during form generation
my $START_MARKER = $MARKER.'STARTPREF'.$MARKER;
my $END_MARKER = $MARKER.'ENDPREF'.$MARKER;

sub initPlugin {
# check for Plugins.pm versions
if( $Foswiki::Plugins::VERSION < 1.026 ) {
Foswiki::Func::writeWarning( 'Version mismatch between PreferencesPlugin and Plugins.pm' );
return 0;
}
@shelter = ();

return 1;
}

sub beforeCommonTagsHandler {
### my ( $text, $topic, $web ) = @_;
my $topic = $_[1];
my $web = $_[2];
return unless ( $_[0] =~ m/%EDITPREFERENCES(?:{(.*?)})?%/ );

require CGI;
require Foswiki::Attrs;
my $formDef;
my $attrs = new Foswiki::Attrs( $1 );
if( defined( $attrs->{_DEFAULT} )) {
my( $formWeb, $form ) = Foswiki::Func::normalizeWebTopicName(
$web, $attrs->{_DEFAULT} );

# SMELL: Unpublished API. No choice, though :-(
require Foswiki::Form; # SMELL
$formDef =
new Foswiki::Form( $Foswiki::Plugins::SESSION, $formWeb, $form );
}

my $query = Foswiki::Func::getCgiQuery();

my $action = lc( $query->param( 'prefsaction' ));
$query->Delete( 'prefsaction' );
$action =~ s/\s.*$//;

if ( $action eq 'edit' ) {
Foswiki::Func::setTopicEditLock( $web, $topic, 1 );

# Replace setting values by form fields but not inside comments Item4816
my $outtext = '';
my $insidecomment = 0;
foreach my $token ( split/(<!--|-->)/, $_[0] ) {
if ( $token =~ /<!--/ ) {
$insidecomment++;
} elsif ( $token =~ /-->/ ) {
$insidecomment-- if ( $insidecomment > 0 );
} elsif ( !$insidecomment ) {
$token =~ s(^((?:\t| )+\*\s(Set|Local)\s*)(\w+)\s*\=(.*$(\n[ \t]+[^\s*].*$)*))
($1._generateEditField($web, $topic, $3, $4, $formDef))gem;
}
$outtext .= $token;
}
$_[0] = $outtext;

$_[0] =~ s/%EDITPREFERENCES({.*?})?%/
_generateControlButtons($web, $topic)/ge;
my $viewUrl = Foswiki::Func::getScriptUrl(
$web, $topic, 'viewauth' );
my $startForm = CGI::start_form(
-name => 'editpreferences',
-method => 'post',
-action => $viewUrl );
$startForm =~ s/\s+$//s;
my $endForm = CGI::end_form();
$endForm =~ s/\s+$//s;
$_[0] =~ s/^(.*?)$START_MARKER(.*)$END_MARKER(.*?)$/$1$startForm$2$endForm$3/s;
$_[0] =~ s/$START_MARKER|$END_MARKER//gs;
}

if( $action eq 'cancel' ) {
Foswiki::Func::setTopicEditLock( $web, $topic, 0 );

} elsif( $action eq 'save' ) {

my( $meta, $text ) = Foswiki::Func::readTopic( $web, $topic );
# SMELL: unchecked implicit untaint of value?
$text =~ s(^((?:\t| )+\*\s(Set|Local)\s)(\w+)\s\=\s(.*)$)
($1._saveSet($query, $web, $topic, $3, $4, $formDef))mgeo;
Foswiki::Func::saveTopic( $web, $topic, $meta, $text );
Foswiki::Func::setTopicEditLock( $web, $topic, 0 );
# Finish with a redirect so that the *new* values are seen
my $viewUrl = Foswiki::Func::getScriptUrl( $web, $topic, 'view' );
Foswiki::Func::redirectCgiQuery( undef, $viewUrl );
return;
}
# implicit action="view", or drop through from "save" or "cancel"
$_[0] =~ s/%EDITPREFERENCES({.*?})?%/_generateEditButton($web, $topic)/ge;
}

# Use the post-rendering handler to plug our formatted editor units
# into the text
sub postRenderingHandler {
### my ( $text ) = @_;

$_[0] =~ s/SHELTER$MARKER(\d+)/$shelter[$1]/g;
}

# Pluck the default value of a named field from a form definition
sub _getField {
my( $formDef, $name ) = @_;
foreach my $f ( @{$formDef->{fields}} ) {
if( $f->{name} eq $name ) {
return $f;
}
}
return undef;
}

# Generate a field suitable for editing this type. Use of the core
# function 'renderFieldForEdit' ensures that we will pick up
# extra edit types defined in other plugins.
sub _generateEditField {
my( $web, $topic, $name, $value, $formDef ) = @_;
$value =~ s/^\s*(.*?)\s*$/$1/ge;

my ($extras, $html);

if( $formDef ) {
my $fieldDef;
if (defined(&Foswiki::Form::getField)) {
# TWiki 4.2 and later
$fieldDef = $formDef->getField( $name );
} else {
# TWiki < 4.2
$fieldDef = _getField( $formDef, $name );
}
if ( $fieldDef ) {
if( defined(&Foswiki::Form::renderFieldForEdit)) {
# TWiki < 4.2 SMELL: use of unpublished core function
( $extras, $html ) =
$formDef->renderFieldForEdit( $fieldDef, $web, $topic, $value);
} else {
# TWiki 4.2 and later SMELL: use of unpublished core function
( $extras, $html ) =
$fieldDef->renderForEdit( $web, $topic, $value );
}
}
}
unless( $html ) {
# No form definition, default to text field.
$html = CGI::textfield( -class=>'foswikiAlert foswikiInputField',
-name => $name,
-size => 80, -value => $value );
}

push( @shelter, $html );

return $START_MARKER.
CGI::span({class=>'foswikiAlert',
style=>'font-weight:bold;'},
$name . ' = SHELTER' . $MARKER . $#shelter).$END_MARKER;
}

# Generate the button that replaces the EDITPREFERENCES tag in view mode
sub _generateEditButton {
my( $web, $topic ) = @_;

my $viewUrl = Foswiki::Func::getScriptUrl(
$web, $topic, 'viewauth' );
my $text = CGI::start_form(
-name => 'editpreferences',
-method => 'post',
-action => $viewUrl );
$text .= CGI::input({
type => 'hidden',
name => 'prefsaction',
value => 'edit'});
$text .= CGI::submit(-name => 'edit',
-value=>'Edit Preferences',
-class=>'foswikiButton');
$text .= CGI::end_form();
$text =~ s/\n//sg;
return $text;
}

# Generate the buttons that replace the EDITPREFERENCES tag in edit mode
sub _generateControlButtons {
my( $web, $topic ) = @_;

my $text = $START_MARKER.CGI::submit(-name=>'prefsaction',
-value=>'Save new settings',
-class=>'foswikiSubmit',
-accesskey=>'s');
$text .= '&nbsp;';
$text .= CGI::submit(-name=>'prefsaction', -value=>'Cancel',
-class=>'foswikiButtonCancel',
-accesskey=>'c').$END_MARKER;
return $text;
}

# Given a Set in the topic being saved, look in the query to see
# if there is a new value for the Set and generate a new
# Set statement.
sub _saveSet {
my( $query, $web, $topic, $name, $value, $formDef ) = @_;

my $newValue = $query->param( $name ) || $value;

if( $formDef ) {
my $fieldDef = _getField( $formDef, $name );
my $type = $fieldDef->{type} || '';
if( $type && $type =~ /^checkbox/ ) {
my $val = '';
my $vals = $fieldDef->{value};
foreach my $item ( @$vals ) {
my $cvalue = $query->param( $name.$item );
if( defined( $cvalue ) ) {
if( ! $val ) {
$val = '';
} else {
$val .= ', ' if( $cvalue );
}
$val .= $item if( $cvalue );
}
}
$newValue = $val;
}
}
# if no form def, it's just treated as text

return $name.' = '.$newValue;
}

1;
Empty file.
@@ -0,0 +1,3 @@
data/System/PreferencesPlugin.txt 0644
data/System/DefaultPreferencesForm.txt 0644
lib/Foswiki/Plugins/PreferencesPlugin.pm 0444

0 comments on commit d399d97

Please sign in to comment.