# -*- coding: iso-8859-1 -*- """ MoinMoin - feed some FCKeditor dialogues @copyright: 2005-2006 Bastian Blank, Florian Festi, Thomas Waldmann @license: GNU GPL, see COPYING for details. """ from MoinMoin import config, wikiutil import re ############################################################################## ### Macro dialog ############################################################################## def macro_dialog(request): help = get_macro_help(request) request.emit_http_headers() request.write( ''' Insert Macro
Macro Name
''') helptexts = [] for macro in macro_list(request): if macro in help: match = help[macro] prototype = match.group('prototype') helptext = match.group('help') else: prototype = macro helptext = "" helptexts.append( '''''' % (prototype, prototype, helptext)) request.write(''.join(helptexts)) request.write('''
''') def macro_list(request): from MoinMoin import macro macros = macro.getNames(request.cfg) macros.sort() return macros def get_macro_help(request): """ Read help texts from SystemPage('HelpOnMacros')""" helppage = wikiutil.getLocalizedPage(request, "HelpOnMacros") content = helppage.get_raw_body() macro_re = re.compile( r"\|\|(<.*?>)?\{\{\{" + r"<<(?P(?P\w*).*)>>" + r"\}\}\}\s*\|\|" + r"[^|]*\|\|[^|]*\|\|<[^>]*>" + r"\s*(?P.*?)\s*\|\|\s*(?P.*?)\s*(<<[^>]*>>)*\s*\|\|$", re.U|re.M) help = {} for match in macro_re.finditer(content): help[match.group('macro')] = match return help ############################################################################## ### Link dialog ############################################################################## def page_list(request): from MoinMoin import search name = request.form.get("pagename", [""])[0] if name: searchresult = search.searchPages(request, 't:"%s"' % name) pages = [p.page_name for p in searchresult.hits] else: pages = [name] request.emit_http_headers() request.write( ''' Insert Page Link
Page Name
''' % "".join(["\n" % p for p in pages])) def link_dialog(request): request.emit_http_headers() # list of wiki pages name = request.form.get("pagename", [""])[0] if name: from MoinMoin import search # XXX error handling! searchresult = search.searchPages(request, 't:"%s"' % name) pages = [p.page_name for p in searchresult.hits] pages.sort() pages[0:0] = [name] page_list = ''' ''' % "\n".join(['' % (page, page) for page in pages]) else: page_list = "" # list of interwiki names interwiki_list = wikiutil.load_wikimap(request) interwiki = interwiki_list.keys() interwiki.sort() iwpreferred = request.cfg.interwiki_preferred[:] if not iwpreferred or iwpreferred and iwpreferred[-1] is not None: resultlist = iwpreferred for iw in interwiki: if not iw in iwpreferred: resultlist.append(iw) else: resultlist = iwpreferred[:-1] interwiki = "\n".join( ['' % (key, key) for key in resultlist]) # wiki url url_prefix_static = request.cfg.url_prefix_static scriptname = request.getScriptname() if not scriptname or scriptname[-1] != "/": scriptname += "/" action = scriptname basepage = request.page.page_name.encode(config.charset) request.write(''' Link Properties ''' % locals()) ############################################################################## ### Attachment dialog ############################################################################## def attachment_dialog(request): request.emit_http_headers() # list of wiki pages name = request.form.get("pagename", [""])[0] if name: from MoinMoin import search # XXX error handling! searchresult = search.searchPages(request, 't:"%s"' % name) pages = [p.page_name for p in searchresult.hits] pages.sort() pages[0:0] = [name] page_list = ''' ''' % "\n".join(['' % (page, page) for page in pages]) else: page_list = "" # wiki url url_prefix_static = request.cfg.url_prefix_static scriptname = request.getScriptname() if not scriptname or scriptname[-1] != "/": scriptname += "/" action = scriptname request.write(''' Attachment Properties
Attachment Name
''' % locals()) ############################################################################## ### Image dialog ############################################################################## def image_dialog(request): request.emit_http_headers() url_prefix_static = request.cfg.url_prefix_static request.write(''' Link Properties
Protocol
  URL or File Name (attachment:)
''' % locals()) ############################################################################# ### Main ############################################################################# def execute(pagename, request): dialog = request.form.get("dialog", [""])[0] if dialog == "macro": macro_dialog(request) elif dialog == "macrolist": macro_list(request) elif dialog == "pagelist": page_list(request) elif dialog == "link": link_dialog(request) elif dialog == "attachment": attachment_dialog(request) elif dialog == 'image': image_dialog(request) else: from MoinMoin.Page import Page request.theme.add_msg("Dialog unknown!", "error") Page(request, pagename).send_page()