Attachment 'MoinMoin_script_import_wikipage.patch'
Download 1 # HG changeset patch
2 # User Pascal Volk <user@localhost.localdomain.org>
3 # Date 1275749390 0
4 # Node ID 7cd4adbd6c50d4e7296c63f4e64dda2418650074
5 # Parent 282ff1a50c4d76c576fe9d8c4e92067eafda35c5
6 implemented moin import wikipage
7
8 diff -r 282ff1a50c4d -r 7cd4adbd6c50 MoinMoin/script/__init__.py
9 --- a/MoinMoin/script/__init__.py Fri Jun 04 21:17:02 2010 +0400
10 +++ b/MoinMoin/script/__init__.py Sat Jun 05 14:49:50 2010 +0000
11 @@ -201,6 +201,7 @@
12 moin ... export dump ...
13
14 moin ... import irclog ...
15 +moin ... import wikipage ...
16
17 moin ... index build ...
18
19 diff -r 282ff1a50c4d -r 7cd4adbd6c50 MoinMoin/script/import/wikipage.py
20 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
21 +++ b/MoinMoin/script/import/wikipage.py Sat Jun 05 14:49:50 2010 +0000
22 @@ -0,0 +1,78 @@
23 +# coding: utf-8
24 +"""
25 +MoinMoin - import wiki pages from local files into the wiki.
26 +
27 +@copyright: 2010 MoinMoin:PascalVolk
28 +@license: GNU GPL, see COPYING for details.
29 +"""
30 +
31 +from MoinMoin.PageEditor import PageEditor
32 +from MoinMoin.script import MoinScript, fatal, log
33 +from MoinMoin.wikiutil import clean_input, decodeUnknownInput
34 +
35 +
36 +class IAmRoot(object):
37 + def __getattr__(self, name):
38 + return lambda *args, **kwargs: True
39 +
40 +
41 +class PluginScript(MoinScript):
42 + """Purpose:
43 +========
44 +This script imports the wiki page from given file into the wiki.
45 +
46 +Detailed Instructions:
47 +======================
48 +General syntax: moin [options] import wikipage [wikipage-options]
49 +
50 +[options] usually should be:
51 + --config-dir=/path/to/cfg --wiki-url=http://wiki.example.org/ --page=Page
52 +"""
53 +
54 + def __init__(self, argv, def_values):
55 + MoinScript.__init__(self, argv, def_values)
56 + self.parser.add_option('--acl', dest='acl', default='', metavar='ACL',
57 + help='Set a specific ACL for the wiki page')
58 + self.parser.add_option('--author', dest='author', metavar='AUTHOR',
59 + default='PageImporter',
60 + help='Use AUTHOR for edit history / RecentChanges')
61 + self.parser.add_option('--comment', dest='comment', metavar='COMMENT',
62 + default='', help='COMMENT for edit history / RecentChanges')
63 + self.parser.add_option('--file', dest='file', default='',
64 + metavar='FILE', help='Read the wiki page from the given file')
65 + self.parser.add_option('--no-backup', dest='revision_backup',
66 + default=True, action='store_false',
67 + help="Suppress making a page backup per revision")
68 +
69 + def mainloop(self):
70 + self.init_request()
71 + request = self.request
72 + request.user.may = IAmRoot()
73 +
74 + if not self.options.page:
75 + fatal('You must specify a wiki page name (--page=Page)!')
76 + if not self.options.file:
77 + fatal('You must specify a FILE to read from (--file=FILE)!')
78 +
79 + try:
80 + fileObj = open(self.options.file, 'rb')
81 + except IOError, err:
82 + fatal(str(err))
83 + page_content = decodeUnknownInput(fileObj.read()).rstrip()
84 + fileObj.close()
85 +
86 + if not self.options.acl:
87 + acl = ''
88 + else:
89 + acl = '#acl %s\n' % self.options.acl
90 + comment = clean_input(self.options.comment)
91 +
92 + pe = PageEditor(request, self.options.page, do_editor_backup=0,
93 + uid_override=self.options.author,
94 + do_revision_backup=int(self.options.revision_backup))
95 + try:
96 + pe.saveText(acl + page_content, 0, comment=comment)
97 + except PageEditor.Unchanged:
98 + log("info: wikipage was not modified - ignored update.")
99 + except PageEditor.SaveError, err:
100 + log("error: %r" % err)
101
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.