This question about Developing extensions (plugins skins etc.): Answered

Plugin-Template for Unicode (utf8) Plugins

Question/Problem

Is there a Plugin-Template (like the EmptyPlugin) where one can see how you decode/encode foswiki's paremeters and the plugin's output if you want to (or have to) write a Plugin where all your string handling (inside the plugin) is done with Perl-Unicode-Strings (instead of Foswiki-Binary-Octets in {Site}{CharSet})?

Here is the code I use

package Foswiki::Plugins::EmptyUnicodePlugin;
use strict;
use warnings;
use utf8;               # Plugin-Perl-File is UTF-8 encoded
use Encode;
use Foswiki::Func    ();
use version; our $VERSION = version->declare("v0.0.1");
our ($RELEASE,$SHORTDESCRIPTION) = ('0.0.1','Empty Unicode Plugin');
our $NO_PREFS_IN_TOPIC = 1;

my $fw_enc;
sub fw_to   { Encode::encode($fw_enc,$_[0]); } # String -> Foswiki-Octet
sub fw_from { Encode::decode($fw_enc,$_[0]); } # Foswiki-Octet -> String

sub initPlugin {
    $fw_enc = $Foswiki::cfg{'Site'}{'CharSet'}; # save Foswiki-Charset
    Foswiki::Func::registerTagHandler(fw_to("ÄXAMPLEUNICODETAG"), 
      \&_EXAMPLEUNICODETAG );
    return 1;
}

sub _EXAMPLEUNICODETAG {
    my($session,$params)=(shift,shift);
    my $value=fw_from($params->{'value'}); # Convert param to Perl String
    $value=uc($value);                     # do some STRING Operation
    return fw_to($value);                  # convert result back to octet
}

1;

Questions concerning the code

  1. Is this a good/bad idea?
  2. What is the designated approach to do this?

-- ChristianLudwig - 17 Aug 2013

There are no examples of this, because no-one has sat down and worked through all the problems.

Basically, plugins have to work on the basis that all initernal data has been converted to the site charset by the time they get it. External data (data from the request) will be encoded differently depending on the source of the request. An XMLHttpRequest, for example, always uses UTF-8 encoding, irrespective of the site charset. A form submission, on the other hand, will encode using the charset selected in the output page (usually the site charset).

So yes, some examples would be a really good idea.

-- CrawfordCurrie - 21 Aug 2013

 

QuestionForm edit

Subject Developing extensions (plugins skins etc.)
Extension What is extension
Version Foswiki 1.1.6
Status Answered
Related Topics
Topic revision: r2 - 21 Aug 2013, CrawfordCurrie
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy