175
175
# markup is 1 (old style) or 2 (new style)
176
176
def lineparser(text, markup):
178
p=re.compile('^!!!(.*)$',re.MULTILINE)
179
text = p.sub(r'= \1 =',text)
180
p=re.compile('^!!(.*)$',re.MULTILINE)
181
text = p.sub(r'== \1 ==',text)
182
p=re.compile('^!(.*)$',re.MULTILINE)
183
text = p.sub(r'=== \1 ===',text)
178
p = re.compile('^!!!(.*)$', re.MULTILINE)
179
text = p.sub(r'= \1 =', text)
180
p = re.compile('^!!(.*)$', re.MULTILINE)
181
text = p.sub(r'== \1 ==', text)
182
p = re.compile('^!(.*)$', re.MULTILINE)
183
text = p.sub(r'=== \1 ===', text)
186
p=re.compile('^\s*\[(http:.*(png|jpg|gif))\]',re.MULTILINE)
187
text = p.sub(r'\n\1',text)
186
p = re.compile('^\s*\[(http:.*(png|jpg|gif))\]', re.MULTILINE)
187
text = p.sub(r'\n{{\1}}', text)
190
190
# the links like [http://]
191
p=re.compile('(?<!~)\[(http|https|ftp|nntp|news|mailto|telnet|file)(://.*?)\]',re.MULTILINE)
192
text = p.sub(r'\1\2',text)
191
p = re.compile('(?<!~)\[(http|https|ftp|nntp|news|mailto|telnet|file)(://.*?)\]', re.MULTILINE)
192
text = p.sub(r'\1\2', text)
194
194
# the [links like this]
195
p=re.compile('(?<!~|#)\[([^]\|]*)\]',re.MULTILINE)
196
text = p.sub(r'["\1"]',text)
195
p = re.compile('(?<!~|#)\[([^]\|]*)\]', re.MULTILINE)
196
text = p.sub(r'[[\1]]', text)
198
198
# links like [foo | http://...]
199
q=re.compile('(?<!~|#)\[([^]#]*?)\s*\|\s*([^]#\s]+?://[^]\s]+?)\]',re.MULTILINE)
200
text = q.sub(r'[\2 \1]',text)
199
q = re.compile('(?<!~|#)\[([^]#]*?)\s*\|\s*([^]#\s]+?://[^]\s]+?)\]', re.MULTILINE)
200
text = q.sub(r'[[\2|\1]]', text)
203
p=re.compile('(?<!~|#)\[([^]]*?)\s*\|\s*([^]\s]+?)\]',re.MULTILINE)
204
text = p.sub(r'[:\2:\1]',text)
203
p = re.compile('(?<!~|#)\[([^]]*?)\s*\|\s*([^]\s]+?)\]', re.MULTILINE)
204
text = p.sub(r'[[\2|\1]]', text)
206
206
# XXX: the following constructs are broken. I don't know how
207
207
# to express that in Moin
208
208
# [OtherPage#foo] [named|OtherPage#foo]
211
# #[foo] => [[Anchor(foo)]]foo
212
# #[|foo] => [[Anchor(foo)]]
213
# #[howdy|foo] => [[Anchor(foo)]]howdy
211
# #[foo] => <<Anchor(foo)>>foo
212
# #[|foo] => <<Anchor(foo)>>
213
# #[howdy|foo] => <<Anchor(foo)>>howdy
215
215
# rest should just go along
216
p=re.compile('#\[([^]|]*)\]', re.MULTILINE)
217
text = p.sub(r'[[Anchor(\1)]]\1', text)
218
p=re.compile('#\[\|+([^]\|]*)\]', re.MULTILINE)
219
text = p.sub(r'[[Anchor(\1)]]', text)
220
p=re.compile('#\[([^]\|]*)\|+([^]\|]*)\]', re.MULTILINE)
221
text = p.sub(r'[[Anchor(\2)]]\1', text)
216
p = re.compile('#\[([^]|]*)\]', re.MULTILINE)
217
text = p.sub(r'<<Anchor(\1)>>\1', text)
218
p = re.compile('#\[\|+([^]\|]*)\]', re.MULTILINE)
219
text = p.sub(r'<<Anchor(\1)>>', text)
220
p = re.compile('#\[([^]\|]*)\|+([^]\|]*)\]', re.MULTILINE)
221
text = p.sub(r'<<Anchor(\2)>>\1', text)
224
224
# this might work for old style
226
p=re.compile('^ (.*)$')
227
text = p.sub(r'{{{\n\1\n}}}',text)
226
p = re.compile('^ (.*)$')
227
text = p.sub(r'{{{\n\1\n}}}', text)
229
229
# lists (regexp taken from phpwiki/lib/BlockParser.php:1.37)
230
p=re.compile('^\ {0,4}\
230
p = re.compile('^\ {0,4}\
234
234
| [*] (?!(?=\S)[^*]*(?<=\S)[*](?:\\s|[-)}>"\'\\/:.,;!?_*=]) )\
235
)\ *(?=\S)',re.MULTILINE|re.VERBOSE)
236
text = p.sub(r' * ',text)
237
p=re.compile(' {0,4}(?:\\# (?!\[.*\])) *(?=\S)',re.MULTILINE)
238
text = p.sub(r' 1. ',text)
235
)\ *(?=\S)', re.MULTILINE|re.VERBOSE)
236
text = p.sub(r' * ', text)
237
p = re.compile(' {0,4}(?:\\# (?!\[.*\])) *(?=\S)', re.MULTILINE)
238
text = p.sub(r' 1. ', text)
241
241
# bold (old style)
242
p=re.compile('__(\w*)',re.MULTILINE)
243
text = p.sub(r"'''\1",text)
244
p=re.compile('(\w*)__',re.MULTILINE)
245
text = p.sub(r"\1'''",text)
242
p = re.compile('__(\w*)', re.MULTILINE)
243
text = p.sub(r"'''\1", text)
244
p = re.compile('(\w*)__', re.MULTILINE)
245
text = p.sub(r"\1'''", text)
246
246
# emphasis is the same
248
248
# XXX: this doesn't do anything yet
250
250
# translated from getStartRegexp() in
251
251
# phpwiki/lib/InlineParser.php:418
256
256
# any of the three.
257
any = "(?: " + i + "|" + b + "|" + tt + ")";
257
any = "(?: " + i + "|" + b + "|" + tt + ")"
259
259
# Any of [_*=] is okay if preceded by space or one of [-"'/:]
260
260
# _ or * is okay after = as long as not immediately followed by =
270
270
"(?<= < ) " + any + " (?! > )|" + \
271
271
"(?<= \\( ) " + any + " (?! \\) )" + \
274
274
# Any of the above must be immediately followed by non-whitespace.
275
start_regexp = start + "(?= \S)";
275
start_regexp = start + "(?= \S)"
280
280
# calendar plugin
281
p=re.compile('<\?plugin Calendar month=(\d*) year=(\d*)\?>',re.MULTILINE)
282
text = p.sub(r'[[MonthCalendar(,\2,\1)]]',text)
283
p=re.compile('<\?plugin Calendar\?>',re.MULTILINE)
284
text = p.sub(r'[[MonthCalendar]]',text)
281
p = re.compile('<\?plugin Calendar month=(\d*) year=(\d*)\?>', re.MULTILINE)
282
text = p.sub(r'<<MonthCalendar(,\2,\1)>>', text)
283
p = re.compile('<\?plugin Calendar\?>', re.MULTILINE)
284
text = p.sub(r'<<MonthCalendar>>', text)
287
p=re.compile('<\?plugin\s+BackLinks.*?\?>', re.MULTILINE)
288
text = p.sub(r"[[FullSearch()]]",text)
287
p = re.compile('<\?plugin\s+BackLinks.*?\?>', re.MULTILINE)
288
text = p.sub(r"<<FullSearch()>>", text)
291
p=re.compile('<\?plugin\s+FullTextSearch.*?(s=.*?)?\?>', re.MULTILINE)
292
text = p.sub(r'[[FullSearch()]]',text)
291
p = re.compile('<\?plugin\s+FullTextSearch.*?(s=.*?)?\?>', re.MULTILINE)
292
text = p.sub(r'<<FullSearch()>>', text)
295
p=re.compile('<\?plugin\s+RecentChanges.*?\?>', re.MULTILINE)
296
text = p.sub(r'[[RecentChanges]]',text)
295
p = re.compile('<\?plugin\s+RecentChanges.*?\?>', re.MULTILINE)
296
text = p.sub(r'<<RecentChanges>>', text)
298
298
# tables (old style)
299
p=re.compile('^(\|.*)$',re.MULTILINE)
300
text = p.sub(r'\1|',text)
301
p=re.compile('\|',re.MULTILINE)
302
text = p.sub(r'||',text)
303
p=re.compile('\|\|<',re.MULTILINE)
304
text = p.sub(r'||<(>',text)
305
p=re.compile('\|\|>',re.MULTILINE)
306
text = p.sub(r'||<)>',text)
299
p = re.compile('^(\|.*)$', re.MULTILINE)
300
text = p.sub(r'\1|', text)
301
p = re.compile('\|', re.MULTILINE)
302
text = p.sub(r'||', text)
303
p = re.compile('\|\|<', re.MULTILINE)
304
text = p.sub(r'||<(>', text)
305
p = re.compile('\|\|>', re.MULTILINE)
306
text = p.sub(r'||<)>', text)
309
309
# moinmoin tables are on one line
310
p=re.compile('\|\|\s*\n',re.MULTILINE)
311
text = p.sub(r'||',text)
310
p = re.compile('\|\|\s*\n', re.MULTILINE)
311
text = p.sub(r'||', text)
314
p=re.compile('mailto:',re.MULTILINE)
315
text = p.sub(r'',text)
314
p = re.compile('mailto:', re.MULTILINE)
315
text = p.sub(r'', text)
318
p=re.compile('(?<!~)%%%',re.MULTILINE)
319
text = p.sub(r'[[BR]]',text)
318
p = re.compile('(?<!~)%%%', re.MULTILINE)
319
text = p.sub(r'<<BR>>', text)
322
322
# This must stay the last filter or things will break real bad
323
p=re.compile('~(~?)',re.MULTILINE)
324
text = p.sub(r'\1',text)
323
p = re.compile('~(~?)', re.MULTILINE)
324
text = p.sub(r'\1', text)
350
cursor = db.cursor();
352
stmt="SELECT pagename,content,versiondata FROM page,recent,version WHERE " + pagename + \
353
" page.id=version.id AND version.id=recent.id AND version=latestversion" + \
352
stmt = "SELECT pagename,content,versiondata FROM page,recent,version WHERE " + pagename + \
353
" page.id=version.id AND version.id=recent.id AND version=latestversion" + \
355
355
cursor.execute(stmt)
357
357
# loop over the matching phpwiki pages
358
358
result = cursor.fetchall()
359
for pagename,content,versiondata in result:
359
for pagename, content, versiondata in result:
360
360
utf8pagename = unicode(pagename, 'latin-1')
361
request = RequestCLI(utf8pagename)
361
request = Request(utf8pagename)
362
362
page = PageEditor(utf8pagename, request)
364
364
# overwriting pages if selecting only some
365
365
if not editExistingPages and page.exists():
366
366
print " already exists, skipping"
369
369
# find out in the serialized field what markup type (old
370
370
# style?) this page is in
371
371
match = re.compile('s:6:"markup";s:[0-9]*:"([0-9]*)";').search(versiondata)
372
if match is not None:
373
373
# markup is 1 (old style) or 2 (new style)
374
374
markup = match.group(1)