view MoinMoin/script/import/ @ 5692:7cd4adbd6c50

implemented moin import wikipage
author Pascal Volk <>
date Sat, 05 Jun 2010 14:49:50 +0000
children bbb286a9c138
line wrap: on
line source
# coding: utf-8
MoinMoin - import wiki pages from local files into the wiki.

@copyright: 2010 MoinMoin:PascalVolk
@license: GNU GPL, see COPYING for details.

from MoinMoin.PageEditor import PageEditor
from MoinMoin.script import MoinScript, fatal, log
from MoinMoin.wikiutil import clean_input, decodeUnknownInput

class IAmRoot(object):
    def __getattr__(self, name):
        return lambda *args, **kwargs: True

class PluginScript(MoinScript):
This script imports the wiki page from given file into the wiki.

Detailed Instructions:
General syntax: moin [options] import wikipage [wikipage-options]

[options] usually should be:
    --config-dir=/path/to/cfg --wiki-url= --page=Page

    def __init__(self, argv, def_values):
        MoinScript.__init__(self, argv, def_values)
        self.parser.add_option('--acl', dest='acl', default='', metavar='ACL',
                help='Set a specific ACL for the wiki page')
        self.parser.add_option('--author', dest='author', metavar='AUTHOR',
                help='Use AUTHOR for edit history / RecentChanges')
        self.parser.add_option('--comment', dest='comment', metavar='COMMENT',
                default='', help='COMMENT for edit history / RecentChanges')
        self.parser.add_option('--file', dest='file', default='',
                metavar='FILE', help='Read the wiki page from the given file')
        self.parser.add_option('--no-backup', dest='revision_backup',
                default=True, action='store_false',
                help="Suppress making a page backup per revision")

    def mainloop(self):
        request = self.request
        request.user.may = IAmRoot()

        if not
            fatal('You must specify a wiki page name (--page=Page)!')
        if not self.options.file:
            fatal('You must specify a FILE to read from (--file=FILE)!')

            fileObj = open(self.options.file, 'rb')
        except IOError, err:
        page_content = decodeUnknownInput(

        if not self.options.acl:
            acl = ''
            acl = '#acl %s\n' % self.options.acl
        comment = clean_input(self.options.comment)

        pe = PageEditor(request,, do_editor_backup=0,
            pe.saveText(acl + page_content, 0, comment=comment)
        except PageEditor.Unchanged:
            log("info: wikipage was not modified - ignored update.")
        except PageEditor.SaveError, err:
            log("error: %r" % err)