from DevDiscussion?:

ISO8859-1 and UTF8 --Wed, 07 Apr 2004 13:27:15 -0700 reply

> Just a thought - how about a function like upgradeAll that translates the "contents" of a wiki page (the text you get in the edit form) from ISO8859-1 to UTF-8 ?

Following is a python script, which will do the conversion for you. Although I have tested it successfully, I will not be held responsible for any damage. So please backup your Wiki before you apply this, because it will touch all your pages and may cause some harm.

I added some code to check for errors and to give some useful diagnostics. However, I am not sure, if this is the most elegant way to do this.

Okay. Now here is the code :-):

def changeCharacterEncoding(self,currentEncoding=None,newEncoding=None):
    """
    Change the character encodings of all pages in a Wiki from
    currentEncoding to newEncoding.

    Place this file as CharacterEncoding.py in the Extensions
    directory of your ZWiki installation and add the following
    external method to your ZDB:

      Id:            changeEncoding
      Module Name:   ZWiki.CharacterEncoding
      Function Name: changeCharacterEncoding

    Then you can call this method from your browser. For example,
    the following URL will change the character encoding of all pages
    in the Wiki http://mywiki from ISO-Latin-1 to UTF-8:

      http://mywiki/FrontPage/changeEncoding?currentEncoding=ISO-8859-1&newEncoding=UTF-8

    BEWARE:

      * Don't leave this method accessible to untrusted users.
      * Backup your Wiki before you apply this conversion method.
      * Be sure you are using the correct character encodings.

    """
    # Use plain text for diagnostics
    self.REQUEST.RESPONSE.setHeader('Content-Type', 'text/plain')

    # Are the parameters present?
    if not currentEncoding:
        self.REQUEST.RESPONSE.write('missing currentEncoding')
        return

    if not newEncoding:
        self.REQUEST.RESPONSE.write('missing newEncoding')
        return

    # Is the current encoding known?
    try:
        unicode("dummy", currentEncoding)
    except:
        self.REQUEST.RESPONSE.write('unknown currentEncoding %s'
                                    % currentEncoding)
        return

    # Is the new encoding known?
    try:
        unicode("dummy", newEncoding)
    except:
        self.REQUEST.RESPONSE.write('unknown newEncoding %s' % newEncoding)
        return

    # Change the encoding of all pages
    self.REQUEST.RESPONSE.write('change character encoding from %s to %s\n'
                                % (currentEncoding, newEncoding))
    for page in self.pageObjects():
        page.setText(unicode(page.read(), currentEncoding).encode(newEncoding))
        self.REQUEST.RESPONSE.write('page %s\n' % page.id())

--Andreas

Remark --ArnoPucher, Wed, 14 Jul 2004 22:53:34 -0700 reply

changed

'http://mywiki/FrontPage/changeEncoding?currentEncoding=ISO-8859-1?newEncoding=UTF'

to

'http://mywiki/FrontPage/changeEncoding?currentEncoding=ISO-8859-1&newEncoding=UTF-8'

(the '?newEncoding=UTF' didn't work, has to be a '&')

this neat thingy worked for me converting my wiki from iso-8859-1 to utf-8 - ahhh fewer problems with umlauts (äöüß etc.) - Thanks Andreas ;)