1
# -*- coding: iso-8859-1 -*-
3
MoinMoin - do global changes to all pages in a wiki.
5
The changes being done are hardcoded in function do_edit.
6
As it is, this script is mostly useful for the MoinMoin release maintainer
7
using: moin ... --wiki-url=moinmaster.wikiwikiweb.de/ maint globaledit
9
@copyright: 2004-2006 by MoinMoin:ThomasWaldmann
10
@license: GNU GPL, see COPYING for details.
1
# -*- coding: utf-8 -*-
3
MoinMoin - do global changes to all pages in a wiki.
5
@copyright: 2004-2006 MoinMoin:ThomasWaldmann
6
@license: GNU GPL, see COPYING for details.
14
11
from MoinMoin import PageEditor
15
from MoinMoin.script._util import MoinScript
12
from MoinMoin.script import MoinScript
17
14
class PluginScript(MoinScript):
18
This tool allows you to edit all the pages in a wiki.
20
Detailed Instructions:
21
======================
22
General syntax: moin [options] maint globaledit [globaledit-options]
24
[options] usually should be:
25
--config-dir=/path/to/my/cfg/ --wiki-url=wiki.example.org/
27
[globaledit-options] see below:
28
0. The changes that will be performed are hardcoded in the function
31
1. This script takes no command line arguments.
18
34
def __init__(self, argv, def_values):
19
35
MoinScript.__init__(self, argv, def_values)
21
37
def do_edit(self, pagename, origtext):
22
if pagename in ['LocalSpellingWords', 'LocalBadContent',] or pagename.endswith('Template'):
38
if pagename in ['LocalSpellingWords', 'LocalBadContent', ]:
24
40
language_line = format_line = masterpage = None
40
56
elif l.startswith('#format '):
42
58
elif l.startswith('##master-page:'):
43
masterpage = l.split(':',1)[1].strip()
59
masterpage = l.split(':', 1)[1].strip()
44
60
master_lines.append(l)
45
61
elif l.startswith('##master-date:'):
46
62
master_lines.append(l)
47
elif l.startswith('##acl'):
49
63
elif l.startswith('##'):
50
64
comment_lines.append(l)
51
65
elif l.startswith('#'):
57
71
language_line = '#language en'
58
72
if not format_line:
59
73
format_line = '#format wiki'
74
aclold = '#acl MoinPagesEditorGroup:read,write,delete,revert All:read'
75
if aclold in acl_lines:
76
acl_lines.remove(aclold)
60
77
if not acl_lines and (
61
masterpage is None or masterpage not in ['FrontPage', 'WikiSandBox',] and not masterpage.endswith('Template')):
62
acl_lines = ['#acl MoinPagesEditorGroup:read,write,delete,revert All:read']
78
masterpage is None and not pagename.endswith('Template') or
79
masterpage not in ['FrontPage', 'WikiSandBox', ] and not (pagename.endswith('Template') or masterpage.endswith('Template'))):
80
acl_lines = ['#acl -All:write Default']
63
81
if not master_lines:
64
master_lines = ['##master-page:Unknown-Page', '##master-date:Unknown-Date',]
82
master_lines = ['##master-page:Unknown-Page', '##master-date:Unknown-Date', ]
66
c1old = "## Please edit (or translate) system/help pages on the moinmaster wiki ONLY."
67
c2old = "## For more information, please see MoinMaster:MoinPagesEditorGroup."
68
c1 = "## Please edit system and help pages ONLY in the moinmaster wiki! For more"
69
c2 = "## information, please see MoinMaster:MoinPagesEditorGroup."
70
for c in (c1old, c2old, c1, c2):
84
cold = [u"## Please edit system and help pages ONLY in the moinmaster wiki! For more",
85
u"## information, please see MoinMaster:MoinPagesEditorGroup.",
87
cnew = [u"## Please edit system and help pages ONLY in the master wiki!",
88
u"## For more information, please see MoinMoin:MoinDev/Translation.",
71
91
if c in comment_lines:
72
92
comment_lines.remove(c)
74
comment_lines = [c1, c2, ] + comment_lines
94
comment_lines = cnew + comment_lines
76
96
if content_lines and content_lines[-1].strip(): # not an empty line at EOF
77
97
content_lines.append('')
79
99
if masterpage and masterpage.endswith('Template'):
80
changedtext = master_lines + [format_line, language_line,] + pragma_lines + content_lines
100
changedtext = master_lines + [format_line, language_line, ] + pragma_lines + content_lines
82
changedtext = comment_lines + master_lines + acl_lines + [format_line, language_line,] + pragma_lines + content_lines
102
changedtext = comment_lines + master_lines + acl_lines + [format_line, language_line, ] + pragma_lines + content_lines
83
103
changedtext = '\n'.join(changedtext)
84
104
return changedtext
89
109
origtext = codecs.open('origtext', 'r', 'utf-8').read()
90
origtext = origtext.replace('\r\n','\n')
110
origtext = origtext.replace('\r\n', '\n')
91
111
changedtext = self.do_edit("", origtext)
92
changedtext = changedtext.replace('\n','\r\n')
112
changedtext = changedtext.replace('\n', '\r\n')
93
113
f = codecs.open('changedtext', 'w', 'utf-8')
94
114
f.write(changedtext)
101
121
pagelist = request.rootpage.getPageList(user='')
103
123
for pagename in pagelist:
104
#request = RequestCLI(url=url, pagename=pagename.encode('utf-8'))
124
#request = CLI.Request(url=url, pagename=pagename.encode('utf-8'))
105
125
p = PageEditor.PageEditor(request, pagename, do_editor_backup=0)
106
126
origtext = p.get_raw_body()
107
127
changedtext = self.do_edit(pagename, origtext)