def show_queryform(wr, request, pagename): _ = request.getText wr(u'<form method="GET" action="%s">\n', actionname(request)) wr(u'<input type="text" size=50 name="args">\n') wr(u'<input type="submit" name="show" value="%s">\n', _("Edit table")) wr(u'</form>\n')
def sendForm(self): request = self.request _ = request.getText ## Begin form request.write(u'<form method="GET" action="%s">\n' % actionname(request)) request.write(u'<input type=hidden name=action value="ViewDot">') request.write(u"<table>\n<tr>\n") # format request.write(u"<td>\n" + _('Output format') + u"<br>\n") for type in self.available_formats: request.write( u'<input type="radio" name="format" ' + u'value="%s"%s%s<br>\n' % (form_escape(type), type == self.format and " checked>" or ">", wikiutil.escape(type))) # graphengine request.write(u"<td>\n" + _('Output graphengine') + u"<br>\n") for type in self.available_graphengines: request.write(u'<input type="radio" name="graphengine" ' + u'value="%s"%s%s<br>\n' % (form_escape(type), type == self.graphengine and " checked>" or ">", wikiutil.escape(type))) request.write( _("Dot file") + "<br>\n" + u'<select name="attachment">\n') # Use request.rootpage, request.page has weird failure modes for page in request.rootpage.getPageList(): # Page#getPageList filters out pages to which the user doesn't have # read access. files = AttachFile._get_files(request, page) for file in files: if file.endswith('.dot') or file.endswith('.gv'): request.write( '<option label="%s" value="%s">%s</option>\n' % (form_escape(file), form_escape("attachment:%s/%s" % (page, file)), wikiutil.escape("%s/%s" % (page, file)))) request.write('</select>\n</table>\n') request.write(u'<input type=submit name=view ' + 'value="%s">\n' % form_escape(_('View'))) request.write(u'<input type=submit name=help ' + 'value="%s"><br>\n' % form_escape(_('Inline'))) request.write(u'</form>\n')
def sendForm(self): request = self.request _ = request.getText ## Begin form request.write(u'<form method="GET" action="%s">\n' % actionname(request)) request.write(u'<input type=hidden name=action value="ViewDot">') request.write(u"<table>\n<tr>\n") # format request.write(u"<td>\n" + _('Output format') + u"<br>\n") for type in self.available_formats: request.write(u'<input type="radio" name="format" ' + u'value="%s"%s%s<br>\n' % (form_escape(type), type == self.format and " checked>" or ">", wikiutil.escape(type))) # graphengine request.write(u"<td>\n" + _('Output graphengine') + u"<br>\n") for type in self.available_graphengines: request.write(u'<input type="radio" name="graphengine" ' + u'value="%s"%s%s<br>\n' % (form_escape(type), type == self.graphengine and " checked>" or ">", wikiutil.escape(type))) request.write(_("Dot file") + "<br>\n" + u'<select name="attachment">\n') # Use request.rootpage, request.page has weird failure modes for page in request.rootpage.getPageList(): # Page#getPageList filters out pages to which the user doesn't have # read access. files = AttachFile._get_files(request, page) for file in files: if file.endswith('.dot') or file.endswith('.gv'): request.write('<option label="%s" value="%s">%s</option>\n' % (form_escape(file), form_escape("attachment:%s/%s" % (page, file)), wikiutil.escape("%s/%s" % (page, file)))) request.write('</select>\n</table>\n') request.write(u'<input type=submit name=view ' + 'value="%s">\n' % form_escape(_('View'))) request.write(u'<input type=submit name=help ' + 'value="%s"><br>\n' % form_escape(_('Inline'))) request.write(u'</form>\n')
def new_link_to(self, request, text=None, querystr=dict(), anchor=None, **kw): if self.page_name == inc_name: # Let's see if we've a link to nonexisting page if getattr(self, '_macro_Include_nonexisting', False): # Modify editlinks with template selection if kw.get('css_class', '') == "include-edit-link": if template: querystr['template'] = template text = '[%s]' % _('create') else: orig_page = macro.request.page.page_name msg = wr('<form method="GET" action="%s">\n', actionname(request, querystr['backto'])) msg += wr('<select name="template">\n') msg += wr('<option value="">%s</option>\n', _("No template")) # Get list of template pages readable by current user filterfn = request.cfg.cache.page_template_regexact.search templates = request.rootpage.getPageList(filter=filterfn) for i in templates: msg += wr('<option value="%s">%s</option>\n', i, i) msg += '</select>\n' msg += '<input type="hidden" name="action" value="newpage">\n' msg += wr('<input type="hidden" name="pagename" value="%s">\n', inc_name) msg += wr('<input type="submit" value="%s">\n', _('create')) msg += wr('</form>\n') return msg # Do not give pagelinks to nonexisting pages if kw.get('css_class', '') == "include-page-link": return text # Add revision information to rev links elif rev: if kw.get('css_class', '') == "include-page-link": querystr['action'] = 'recall' querystr['rev'] = str(rev) text = "%s revision %d]" % (text[:-1], rev) elif kw.get('css_class', '') == "include-edit-link": text = '[%s]' % _("edit current version") return orig_link_to(self, request, text, querystr, anchor, **kw)
def show_editform(wr, request, pagename, args): formatter = request.formatter # Note that metatable_parseargs handles read permission checks pagelist, metakeys, _ = metatable_parseargs(request, args, get_all_keys=True) uneditable_pages = list() # See that the user can write each page for page in pagelist: if not request.user.may.write(page): uneditable_pages.append(page) for page in uneditable_pages: pagelist.remove(page) _ = request.getText if uneditable_pages: reason = _("No save permission to some pages (%s)" % ','.join(uneditable_pages)) request.write(render_warning(reason)) if not pagelist: reason = _("No pages to edit.") request.write(render_error(reason)) return wr(u'<form method="POST" action="%s" enctype="multipart/form-data">\n', actionname(request)) wr(u'<input type="hidden" name="action" value="%s">\n', action_name) wr(formatter.table(1)) wr(formatter.table_row(1, {'rowclass': 'meta_header'})) wr(formatter.table_cell(1, {'class': 'meta_page'})) form = values_to_form(request.values) template = form.get('template', [''])[0] if template: wr('<input type="hidden" name="template" value="%s">', template) # Filter out uneditables, such as inlinks metakeys = editable_p(metakeys) _ = request.getText for key in metakeys + ['']: wr(formatter.table_cell(1, {'class': 'meta_header'})) wr(u'<input class="metakey" type="text" name="%s" value="%s">', u':: %s' % key, key) wr(formatter.table_row(0)) values = dict() valnos = dict() for frompage in pagelist: values[frompage] = dict() for key in metakeys + ['']: values[frompage][key] = list() # If the page has no values for this key, it'll # have one in the table to add a value if not valnos.has_key(frompage): valnos[frompage] = 1 keydata = get_metas(request, frompage, [key], abs_attach=False, includeGenerated=False) for i, val in enumerate(keydata[key]): values[frompage][key].append(val) # Enumerate starts from 0: #values++ # One to add a value: #values++ if valnos[frompage] < i + 2: valnos[frompage] = i + 2 values[frompage][key].append('') for frompage in pagelist: wr(formatter.table_row(1)) wr(formatter.table_cell(1, {'class': 'meta_page', 'rowspan': str(valnos[frompage])})) wr(u'%s', frompage) for i in range(valnos[frompage]): # Add <tr>:s for additional values also if i > 0: wr(formatter.table_row(1)) for key in metakeys + ['']: inputname = frompage + SEPARATOR + key if len(values[frompage][key]) >= (i + 1): val = values[frompage][key][i] else: val = '' # Skip default labels if key == 'label' and val == frompage: val = '' wr(formatter.table_cell(1, {'class': 'meta_cell'})) wr(u'<textarea class="metavalue dynamic" rows="1" name="%s">%s</textarea>', inputname, val) #print frompage, key, inputname, values, '<br>' wr(formatter.table_row(0)) wr(formatter.table_row(1)) wr(formatter.table_cell(1, {'class': 'meta_cell'})) for key in metakeys + ['']: inputname = frompage + SEPARATOR + key if len(values[frompage][key]) >= (i + 1): val = values[frompage][key][i] else: val = '' # Skip default labels if key == 'label' and val == frompage: val = '' wr(formatter.table_cell(1)) wr(u'<input class="metavalue" type="file" name="%s">\n', inputname) wr(formatter.table_row(0)) # Proto JS code to warn on leaving an empty key name # <script language="JavaScript" type="text/javascript"> # function myvalid(me) { # if (me.form.subject.value == "") { # if (confirm("Empty subject, send anyway?")) # return true; # else # return false; # } # return true; # } # </script> # <input type="submit" name="send" value="Send" class="button1"tabindex="7" # onClick="return myvalid(this);" /> wr(formatter.table(0)) wr(u'<input type="submit" name="save" value="%s">\n', _('Save')) wr(u'<input type="submit" name="cancel" value="%s">\n', _('Cancel')) wr(u'</form>\n')
def execute(pagename, request): _ = request.getText form = values_to_form(request.values) if not request.user.may.write(pagename): request.reset() backto = form.get('backto', [None])[0] if backto: request.page = Page(request, backto) request.theme.add_msg(_('You are not allowed to edit this page.'), "error") request.page.send_page() return frm = wr( u'<form id="metaformedit" method="POST" enctype="multipart/form-data" action="%s">\n', actionname(request))+\ wr(u'<input form="metaformedit" type="hidden" name="action" value="MetaEdit">\n')+\ wr(u'<input form="metaformedit" type="hidden" name="gwikiseparator" value="%s">\n', SEPARATOR) btn = '<div class="saveform"><p class="savemessage">' + \ wr('<input type=submit name=saveform form="metaformedit" value="%s">', _(form.get('saveBtnText', ['Save Changes'])[0])) + \ wr('<input form="metaformedit" type=submit name=cancel value="%s">', _('Cancel')) +'</p></div>' # Template to use for any new pages template = form.get('template', [''])[0] if template: frm += wr( '<input form="metaformedit" type="hidden" name="template" value="%s">', template) # Where to after saving page backto = form.get('backto', [''])[0] if backto: frm += wr( '<input form="metaformedit" type="hidden" name="backto" value="%s">', backto) old_header = request.cfg.page_header2 old_footer = request.cfg.page_footer1 # The post-header and pre-footer texts seem to be implemented in themes. # Using post-header instead of page msg to avoid breaking header forms. request.cfg.page_header2 += frm + btn request.cfg.page_footer1 += btn + '</form>' old_page = request.page request.page = FormPage(request, pagename) error = '' newpage = False template_text = '' # If the page does not exist but we'd know how to construct it, # replace the Page content with template and pretend it exists if template and not request.page.exists(): template_page = wikiutil.unquoteWikiname(template) if request.user.may.read(template_page): editor = PageEditor(request, template_page) editor.user = request.user text = editor.get_raw_body() editor.page_name = pagename template_text = editor._expand_variables(text) request.page.set_raw_body(template_text) request.page.exists = lambda **kw: True request.page.lastEditInfo = lambda: {} newpage = True else: error = '<div class="saveform"><p class="savemessage">' + \ _("Cannot read template") + '</p></div>' elif not template and not request.page.exists(): error = '<div class="saveform"><p class="savemessage">' + \ _("No template specified, cannot edit") + '</p></div>' if error: request.cfg.page_header2 = request.cfg.page_header2 + error request.cfg.page_footer1 = request.cfg.page_footer1 # Extra spaces from formatter need to be removed, that's why the # page is not sent as it is out = StringIO.StringIO() request.redirect(out) request.sent_headers = True request.page.send_page() request.redirect() graphdata = request.graphdata vals_on_keys = graphdata.get_vals_on_keys() # If we're making a new page based on a template, make sure that # the values from the evaluated template are included in the form editor if newpage: templatePage = Page(request, template) data = parse_text(request, templatePage, template_text) for page in data: for key in data[page].get('meta', list()): for val in data[page]['meta'][key]: vals_on_keys.setdefault(key, set()).add(val) for key in data[page].get('out', list()): for val in data[page]['out'][key]: vals_on_keys.setdefault(key, set()).add(val) pagemeta = graphdata.get_meta(page) for key in pagemeta: for val in pagemeta[key]: vals_on_keys.setdefault(key, set()).add(val) # Form types def form_selection(request, pagekey, curval, values, description=''): msg = wr('<select form="metaformedit" name="%s">', pagekey) msg += wr('<option value=""> </option>') for keyval, showval in values: msg += wr('<option value="%s"%s>%s</option>', keyval, curval == keyval and ' selected' or '', showval) msg += '</select>' return msg def form_checkbox(request, pagekey, curval, values, description=''): msg = '' for keyval, showval in values: msg += wr( '<input form="metaformedit" type="checkbox" name="%s" value="%s"%s>', pagekey, keyval, curval == keyval and ' checked' or '') + \ '<label>' + format_wikitext(request, showval) +'</label>' return msg def form_radio(request, pagekey, curval, values, description=''): msg = '' for keyval, showval in values: msg += wr( '<input form="metaformedit" type="radio" name="%s" value="%s"%s>', pagekey, keyval, curval == keyval and ' checked' or '') + \ '<label>' + format_wikitext(request, showval) +'</label>' return msg def form_textbox(request, pagekey, curval, values, description=''): return wr('<textarea form="metaformedit" name="%s">%s</textarea>', pagekey, curval) def form_date(request, pagekey, curval, values, description=''): return wr( '<input form="metaformedit" type="text" class="date" name="%s" value="%s">', pagekey, curval) def form_file(request, pagekey, curval, values, description=''): if curval: return wr( '<input form="metaformedit" class="file" type="text" name="%s" value="%s" readonly>', pagekey, curval) else: return wr( '<input form="metaformedit" class="file" type="file" name="%s%s0" value="" readonly>', pagekey, SEPARATOR) formtypes = { 'selection': form_selection, 'checkbox': form_checkbox, 'textbox': form_textbox, 'textarea': form_textbox, 'radio': form_radio, 'date': form_date, 'file': form_file } def repl_subfun(mo): dt, pagekey, val = mo.groups() pagekey = form_unescape(pagekey) msg = dt key = pagekey.split(SEPARATOR)[1] properties = get_properties(request, key) values = list() # Placeholder key key if key in vals_on_keys: for keyval in sorted(vals_on_keys[key]): keyval = keyval.strip() # Is this really needed? If so, probably should make the length configurable.. # if len(keyval) > 30: # showval = keyval[:27] + '...' # else: # showval = keyval showval = keyval values.append((keyval, showval)) formtype = properties.get('hint') constraint = properties.get('constraint') desc = properties.get('description') default = properties.get('default', '') hidden = False if formtype == "hidden": hidden = True if not formtype in formtypes: formtype = "selection" if (not formtype == "radio" and not (formtype == "checkbox" and constraint == "existing")): cloneable = "true" else: cloneable = "false" if desc: msg = msg.replace('</dt>', ' %s</dt>' % \ request.formatter.icon('info')) msg = msg.replace( '<dt>', wr('<dt class="mt-tooltip" title="%s" rel="%s">', key, desc)) msg = msg.replace( '<dd>', wr( '<dd class="metaformedit" data-cloneable="%s" data-default="%s">', cloneable, default)) msg += formtypes[formtype](request, pagekey, val, values) if (not constraint == 'existing' and not formtype in ['textbox', 'textarea', 'file', 'date']): msg += wr('<textarea form="metaformedit" name="%s"></textarea>', pagekey) if hidden: msg = request.formatter.div(1, css_class='comment') + msg + \ request.formatter.div(0) return msg data = out.getvalue() data = value_re.sub(repl_subfun, data) request.write(data) request.page = old_page request.cfg.page_header2 = old_header request.cfg.page_footer1 = old_footer
def new_link_to(self, request, text=None, querystr=dict(), anchor=None, **kw): if self.page_name == inc_name: # Let's see if we've a link to nonexisting page if getattr(self, '_macro_Include_nonexisting', False): # Modify editlinks with template selection if kw.get('css_class', '') == "include-edit-link": if template: querystr['template'] = template text = '[%s]' % _('create') else: orig_page = macro.request.page.page_name msg = wr( '<form method="GET" action="%s">\n', actionname(request, querystr['backto'])) msg += wr('<select name="template">\n') msg += wr('<option value="">%s</option>\n', _("No template")) # Get list of template pages readable by current user filterfn = request.cfg.cache.page_template_regexact.search templates = request.rootpage.getPageList( filter=filterfn) for i in templates: msg += wr( '<option value="%s">%s</option>\n', i, i) msg += '</select>\n' msg += '<input type="hidden" name="action" value="newpage">\n' msg += wr( '<input type="hidden" name="pagename" value="%s">\n', inc_name) msg += wr( '<input type="submit" value="%s">\n', _('create')) msg += wr('</form>\n') return msg # Do not give pagelinks to nonexisting pages if kw.get('css_class', '') == "include-page-link": return text # Add revision information to rev links elif rev: if kw.get('css_class', '') == "include-page-link": querystr['action'] = 'recall' querystr['rev'] = str(rev) text = "%s revision %d]" % (text[:-1], rev) elif kw.get('css_class', '') == "include-edit-link": text = '[%s]' % _("edit current version") return orig_link_to(self, request, text, querystr, anchor, **kw)
def execute(pagename, request): _ = request.getText form = values_to_form(request.values) if not request.user.may.write(pagename): request.reset() backto = form.get('backto', [None])[0] if backto: request.page = Page(request, backto) request.theme.add_msg(_('You are not allowed to edit this page.'), "error") request.page.send_page() return frm = wr( u'<form id="metaformedit" method="POST" enctype="multipart/form-data" action="%s">\n', actionname(request))+\ wr(u'<input form="metaformedit" type="hidden" name="action" value="MetaEdit">\n')+\ wr(u'<input form="metaformedit" type="hidden" name="gwikiseparator" value="%s">\n', SEPARATOR) btn = '<div class="saveform"><p class="savemessage">' + \ wr('<input type=submit name=saveform form="metaformedit" value="%s">', _(form.get('saveBtnText', ['Save Changes'])[0])) + \ wr('<input form="metaformedit" type=submit name=cancel value="%s">', _('Cancel')) +'</p></div>' # Template to use for any new pages template = form.get('template', [''])[0] if template: frm += wr('<input form="metaformedit" type="hidden" name="template" value="%s">', template) # Where to after saving page backto = form.get('backto', [''])[0] if backto: frm += wr('<input form="metaformedit" type="hidden" name="backto" value="%s">', backto) old_header = request.cfg.page_header2 old_footer = request.cfg.page_footer1 # The post-header and pre-footer texts seem to be implemented in themes. # Using post-header instead of page msg to avoid breaking header forms. request.cfg.page_header2 += frm + btn request.cfg.page_footer1 += btn + '</form>' old_page = request.page request.page = FormPage(request, pagename) error = '' newpage = False template_text = '' # If the page does not exist but we'd know how to construct it, # replace the Page content with template and pretend it exists if template and not request.page.exists(): template_page = wikiutil.unquoteWikiname(template) if request.user.may.read(template_page): editor = PageEditor(request, template_page) editor.user = request.user text = editor.get_raw_body() editor.page_name = pagename template_text = editor._expand_variables(text) request.page.set_raw_body(template_text) request.page.exists = lambda **kw: True request.page.lastEditInfo = lambda: {} newpage = True else: error = '<div class="saveform"><p class="savemessage">' + \ _("Cannot read template") + '</p></div>' elif not template and not request.page.exists(): error = '<div class="saveform"><p class="savemessage">' + \ _("No template specified, cannot edit") + '</p></div>' if error: request.cfg.page_header2 = request.cfg.page_header2 + error request.cfg.page_footer1 = request.cfg.page_footer1 # Extra spaces from formatter need to be removed, that's why the # page is not sent as it is out = StringIO.StringIO() request.redirect(out) request.sent_headers = True request.page.send_page() request.redirect() graphdata = request.graphdata vals_on_keys = graphdata.get_vals_on_keys() # If we're making a new page based on a template, make sure that # the values from the evaluated template are included in the form editor if newpage: templatePage = Page(request, template) data = parse_text(request, templatePage, template_text) for page in data: for key in data[page].get('meta', list()): for val in data[page]['meta'][key]: vals_on_keys.setdefault(key, set()).add(val) for key in data[page].get('out', list()): for val in data[page]['out'][key]: vals_on_keys.setdefault(key, set()).add(val) pagemeta = graphdata.get_meta(page) for key in pagemeta: for val in pagemeta[key]: vals_on_keys.setdefault(key, set()).add(val) # Form types def form_selection(request, pagekey, curval, values, description=''): msg = wr('<select form="metaformedit" name="%s">', pagekey) msg += wr('<option value=""> </option>') for keyval, showval in values: msg += wr('<option value="%s"%s>%s</option>', keyval, curval == keyval and ' selected' or '', showval) msg += '</select>' return msg def form_checkbox(request, pagekey, curval, values, description=''): msg = '' for keyval, showval in values: msg += wr( '<input form="metaformedit" type="checkbox" name="%s" value="%s"%s>', pagekey, keyval, curval == keyval and ' checked' or '') + \ '<label>' + format_wikitext(request, showval) +'</label>' return msg def form_radio(request, pagekey, curval, values, description=''): msg = '' for keyval, showval in values: msg += wr( '<input form="metaformedit" type="radio" name="%s" value="%s"%s>', pagekey, keyval, curval == keyval and ' checked' or '') + \ '<label>' + format_wikitext(request, showval) +'</label>' return msg def form_textbox(request, pagekey, curval, values, description=''): return wr('<textarea form="metaformedit" name="%s">%s</textarea>', pagekey, curval) def form_date(request, pagekey, curval, values, description=''): return wr('<input form="metaformedit" type="text" class="date" name="%s" value="%s">', pagekey, curval) def form_file(request, pagekey, curval, values, description=''): if curval: return wr( '<input form="metaformedit" class="file" type="text" name="%s" value="%s" readonly>' , pagekey, curval) else: return wr( '<input form="metaformedit" class="file" type="file" name="%s%s0" value="" readonly>', pagekey, SEPARATOR) formtypes = {'selection': form_selection, 'checkbox': form_checkbox, 'textbox': form_textbox, 'textarea': form_textbox, 'radio': form_radio, 'date': form_date, 'file': form_file} def repl_subfun(mo): dt, pagekey, val = mo.groups() pagekey = form_unescape(pagekey) msg = dt key = pagekey.split(SEPARATOR)[1] properties = get_properties(request, key) values = list() # Placeholder key key if key in vals_on_keys: for keyval in sorted(vals_on_keys[key]): keyval = keyval.strip() # Is this really needed? If so, probably should make the length configurable.. # if len(keyval) > 30: # showval = keyval[:27] + '...' # else: # showval = keyval showval = keyval values.append((keyval, showval)) formtype = properties.get('hint') constraint = properties.get('constraint') desc = properties.get('description') default = properties.get('default', '') hidden = False if formtype == "hidden": hidden = True if not formtype in formtypes: formtype = "selection" if (not formtype == "radio" and not (formtype == "checkbox" and constraint == "existing")): cloneable = "true" else: cloneable = "false" if desc: msg = msg.replace('</dt>', ' %s</dt>' % \ request.formatter.icon('info')) msg = msg.replace('<dt>', wr( '<dt class="mt-tooltip" title="%s" rel="%s">', key, desc)) msg = msg.replace('<dd>', wr('<dd class="metaformedit" data-cloneable="%s" data-default="%s">', cloneable, default)) msg += formtypes[formtype](request, pagekey, val, values) if (not constraint == 'existing' and not formtype in ['textbox', 'textarea', 'file', 'date']): msg += wr('<textarea form="metaformedit" name="%s"></textarea>', pagekey) if hidden: msg = request.formatter.div(1, css_class='comment') + msg + \ request.formatter.div(0) return msg data = out.getvalue() data = value_re.sub(repl_subfun, data) request.write(data) request.page = old_page request.cfg.page_header2 = old_header request.cfg.page_footer1 = old_footer
def execute(pagename, request): _ = request.getText # Start content - IMPORTANT - without content div, there is no # direction support! if not hasattr(request, 'formatter'): formatter = HtmlFormatter(request) else: formatter = request.formatter request.page.formatter = formatter formatter.setPage(request.page) # This action generate data using the user language request.setContentLanguage(request.lang) request.theme.send_title(request.getText('Search by metadata'), pagename=pagename) request.write(formatter.startContent("content")) q = '' mtabq = '' if request.values.has_key('q'): if request.values.has_key('mtab'): mtabq = ''.join(request.values.getlist('q')) else: q = ''.join(request.values.getlist('q')) request.write(u'<form method="GET" action="%s">\n' % actionname(request, pagename)) request.write(u'<input type=hidden name=action value="%s">' % 'MetaSearch') request.write(u'<input type="text" name="q" size=50 value="%s"> ' % (form_escape(q))) request.write(u'<input type="submit" name="mtab" value="Search as MetaTable">') request.write(u'<input type="submit" value="' + _('Search') + '">' + u'\n</form>\n') if q: if regexp_re.match(q): try: page_re = re.compile(q[1:-1]) q = '' except re.error: request.write(render_error(_("Bad regexp!"))) graphdata = request.graphdata graphdata.reverse_meta() keys_on_pages = graphdata.keys_on_pages vals_on_pages = graphdata.vals_on_pages keyhits = set([]) keys = set([]) for key in keys_on_pages: if q: if key == q: keyhits.update(keys_on_pages[key]) keys.add(key) else: if page_re.match(key): keyhits.update(keys_on_pages[key]) keys.add(key) valhits = set([]) vals = set([]) for val in vals_on_pages: if q: if val == q: valhits.update(vals_on_pages[val]) vals.add(val) else: if page_re.match(val): valhits.update(vals_on_pages[val]) vals.add(val) if not q: elemlist(request, formatter, keys, _('keys')) elemlist(request, formatter, vals, _('values')) request.write(formatter.paragraph(1)) request.write(formatter.text(_("Found as key in following pages"))) request.write(formatter.paragraph(0)) request.write(formatter.bullet_list(1)) for page in sorted(keyhits): # Do not include revisions etc so far, enabling this as per request if not graphdata[page].has_key(u'saved'): continue request.write(formatter.listitem(1)) request.write(formatter.pagelink(1, page)) request.write(formatter.text(page)) request.write(formatter.pagelink(0)) request.write(formatter.listitem(0)) request.write(formatter.bullet_list(0)) request.write(formatter.paragraph(1)) request.write(formatter.text(_("Found as value in following pages"))) request.write(formatter.paragraph(0)) request.write(formatter.bullet_list(1)) for page in sorted(valhits): # Do not include revisions etc so far, enabling this as per request if not graphdata[page].has_key(u'saved'): continue request.write(formatter.listitem(1)) request.write(formatter.pagelink(1, page)) request.write(formatter.text(page)) request.write(formatter.pagelink(0)) request.write(formatter.listitem(0)) request.write(formatter.bullet_list(0)) if mtabq: metatab = wikiutil.importPlugin(request.cfg, 'macro', 'MetaTable') request.write("<br>") # Poor but sufficient emulation of macro object mtabHTML = metatab(request.page, mtabq) request.write(mtabHTML) # End content request.write(formatter.endContent()) # end content div # Footer request.theme.send_footer(pagename) request.theme.send_closing_html()
def show_editform(wr, request, pagename, args): formatter = request.formatter # Note that metatable_parseargs handles read permission checks pagelist, metakeys, _ = metatable_parseargs(request, args, get_all_keys=True) uneditable_pages = list() # See that the user can write each page for page in pagelist: if not request.user.may.write(page): uneditable_pages.append(page) for page in uneditable_pages: pagelist.remove(page) _ = request.getText if uneditable_pages: reason = _("No save permission to some pages (%s)" % ','.join(uneditable_pages)) request.write(render_warning(reason)) if not pagelist: reason = _("No pages to edit.") request.write(render_error(reason)) return wr(u'<form method="POST" action="%s" enctype="multipart/form-data">\n', actionname(request)) wr(u'<input type="hidden" name="action" value="%s">\n', action_name) wr(formatter.table(1)) wr(formatter.table_row(1, {'rowclass': 'meta_header'})) wr(formatter.table_cell(1, {'class': 'meta_page'})) form = values_to_form(request.values) template = form.get('template', [''])[0] if template: wr('<input type="hidden" name="template" value="%s">', template) # Filter out uneditables, such as inlinks metakeys = editable_p(metakeys) _ = request.getText for key in metakeys + ['']: wr(formatter.table_cell(1, {'class': 'meta_header'})) wr(u'<input class="metakey" type="text" name="%s" value="%s">', u':: %s' % key, key) wr(formatter.table_row(0)) values = dict() valnos = dict() for frompage in pagelist: values[frompage] = dict() for key in metakeys + ['']: values[frompage][key] = list() # If the page has no values for this key, it'll # have one in the table to add a value if not valnos.has_key(frompage): valnos[frompage] = 1 keydata = get_metas(request, frompage, [key], abs_attach=False, includeGenerated=False) for i, val in enumerate(keydata[key]): values[frompage][key].append(val) # Enumerate starts from 0: #values++ # One to add a value: #values++ if valnos[frompage] < i + 2: valnos[frompage] = i + 2 values[frompage][key].append('') for frompage in pagelist: wr(formatter.table_row(1)) wr( formatter.table_cell(1, { 'class': 'meta_page', 'rowspan': str(valnos[frompage]) })) wr(u'%s', frompage) for i in range(valnos[frompage]): # Add <tr>:s for additional values also if i > 0: wr(formatter.table_row(1)) for key in metakeys + ['']: inputname = frompage + SEPARATOR + key if len(values[frompage][key]) >= (i + 1): val = values[frompage][key][i] else: val = '' # Skip default labels if key == 'label' and val == frompage: val = '' wr(formatter.table_cell(1, {'class': 'meta_cell'})) wr( u'<textarea class="metavalue dynamic" rows="1" name="%s">%s</textarea>', inputname, val) #print frompage, key, inputname, values, '<br>' wr(formatter.table_row(0)) wr(formatter.table_row(1)) wr(formatter.table_cell(1, {'class': 'meta_cell'})) for key in metakeys + ['']: inputname = frompage + SEPARATOR + key if len(values[frompage][key]) >= (i + 1): val = values[frompage][key][i] else: val = '' # Skip default labels if key == 'label' and val == frompage: val = '' wr(formatter.table_cell(1)) wr(u'<input class="metavalue" type="file" name="%s">\n', inputname) wr(formatter.table_row(0)) # Proto JS code to warn on leaving an empty key name # <script language="JavaScript" type="text/javascript"> # function myvalid(me) { # if (me.form.subject.value == "") { # if (confirm("Empty subject, send anyway?")) # return true; # else # return false; # } # return true; # } # </script> # <input type="submit" name="send" value="Send" class="button1"tabindex="7" # onClick="return myvalid(this);" /> wr(formatter.table(0)) wr(u'<input type="submit" name="save" value="%s">\n', _('Save')) wr(u'<input type="submit" name="cancel" value="%s">\n', _('Cancel')) wr(u'</form>\n')