def getAttachUrl(pagename, filename, request, addts=0, escaped=0, do='get'): """ Get URL that points to attachment `filename` of page `pagename`. If 'addts' is true, a timestamp with the file's modification time is added, so that browsers reload a changed file. """ if htdocs_access(request): # direct file access via webserver timestamp = '' if addts: try: timestamp = '?ts=%s' % os.path.getmtime( getFilename(request, pagename, filename)) except IOError: pass url = "%s/%s/attachments/%s%s" % ( request.cfg.attachments['url'], wikiutil.quoteWikinameFS(pagename), wikiutil.url_quote(filename), timestamp) else: # send file via CGI if do not in ['get', 'view']: do = 'get' url = "%s/%s?action=%s&do=%s&target=%s" % ( request.getScriptname(), wikiutil.quoteWikinameURL(pagename), action_name, do, wikiutil.url_quote_plus(filename)) if escaped: url = wikiutil.escape(url) return url
def mailAccountData(self, cleartext_passwd=None, subject=None, text_intro=None, text_msg=None, text_data=None): """ Mail a user who forgot his password a message enabling him to login again. """ from MoinMoin.mail import sendmail _ = self._request.getText if not self.email: return False, "user has no E-Mail address in his profile." tok = self.generate_recovery_token() if subject is None: subject = _('[%(sitename)s] Your wiki account data') subject = subject % dict(sitename=self._cfg.sitename or "Wiki") if text_intro is None: text_intro = '' if text_msg is None: text_msg = _("""\ Somebody has requested to email you a password recovery token. If you lost your password, please go to the password reset URL below or go to the password recovery page again and enter your username and the recovery token. """) if text_data is None: text_data = _("""\ Login Name: %s Password recovery token: %s Password reset URL: %s?action=recoverpass&name=%s&token=%s """) # note: text_intro is for custom stuff, we do not have i18n for it anyway text = text_intro + '\n' + _(text_msg) + '\n' + _(text_data) % ( self.name, tok, self._request.url, # use full url, including current page url_quote_plus(self.name), tok, ) mailok, msg = sendmail.sendmail(self._request, [self.email], subject, text, mail_from=self._cfg.mail_from) return mailok, msg
def send_link_rel(request, pagename): files = _get_files(request, pagename) if len(files) > 0 and not htdocs_access(request): scriptName = request.getScriptname() pagename_quoted = wikiutil.quoteWikinameURL(pagename) for file in files: url = "%s/%s?action=%s&do=view&target=%s" % ( scriptName, pagename_quoted, action_name, wikiutil.url_quote_plus(file)) request.write(u'<link rel="Appendix" title="%s" href="%s">\n' % ( wikiutil.escape(file), wikiutil.escape(url)))
def render(self): _ = self.request.getText pagename, attname = AttachFile.absoluteName(self.target, self.formatter.page.page_name) attachment_fname = AttachFile.getFilename(self.request, pagename, attname) if not os.path.exists(attachment_fname): linktext = _('Upload new attachment "%(filename)s"') return wikiutil.link_tag(self.request, ('%s?action=AttachFile&rename=%s' % ( wikiutil.quoteWikinameURL(pagename), wikiutil.url_quote_plus(attname))), linktext % {'filename': attname}) url = AttachFile.getAttachUrl(pagename, attname, self.request) mime_type, enc = mimetypes.guess_type(attname) if mime_type in ["application/x-shockwave-flash", "application/x-dvi", "application/postscript", "application/pdf", "application/ogg", "application/vnd.visio", "image/x-ms-bmp", "image/svg+xml", "image/tiff", "image/x-photoshop", "audio/mpeg", "audio/midi", "audio/x-wav", "video/fli", "video/mpeg", "video/quicktime", "video/x-msvideo", "chemical/x-pdb", "x-world/x-vrml", ]: return self.embed(mime_type, url) else: msg = 'Not supported mimetype %(mimetype)s ' % {"mimetype": mime_type} return "%s%s%s" % (self.macro.formatter.sysmsg(1), self.macro.formatter.text(msg), self.macro.formatter.sysmsg(0))
def mailAccountData(self, cleartext_passwd=None, subject=None, text_intro=None, text_msg=None, text_data=None): """ Mail a user who forgot his password a message enabling him to login again. """ from MoinMoin.mail import sendmail _ = self._request.getText if not self.email: return False, "user has no E-Mail address in his profile." tok = self.generate_recovery_token() if subject is None: subject = _('[%(sitename)s] Your wiki account data') subject = subject % dict(sitename=self._cfg.sitename or "Wiki") if text_intro is None: text_intro = '' if text_msg is None: text_msg = _("""\ Somebody has requested to email you a password recovery token. If you lost your password, please go to the password reset URL below or go to the password recovery page again and enter your username and the recovery token. """) if text_data is None: text_data = _("""\ Login Name: %s Password recovery token: %s Password reset URL: %s?action=recoverpass&name=%s&token=%s """) # note: text_intro is for custom stuff, we do not have i18n for it anyway text = text_intro + '\n' + _(text_msg) + '\n' + _(text_data) % ( self.name, tok, self._request.url, # use full url, including current page url_quote_plus(self.name), tok, ) mailok, msg = sendmail.sendmail(self._request, [self.email], subject, text, mail_from=self._cfg.mail_from) return mailok, msg
def mailAccountData(self, cleartext_passwd=None): """ Mail a user who forgot his password a message enabling him to login again. """ from MoinMoin.mail import sendmail from MoinMoin.wikiutil import getLocalizedPage _ = self._request.getText tok = self.generate_recovery_token() text = '\n' + _("""\ Login Name: %s Password recovery token: %s Password reset URL: %s?action=recoverpass&name=%s&token=%s """) % ( self.name, tok, self._request.url_root, url_quote_plus(self.name), tok, ) text = _("""\ Somebody has requested to email you a password recovery token. If you lost your password, please go to the password reset URL below or go to the password recovery page again and enter your username and the recovery token. """) + text subject = _('[%(sitename)s] Your wiki account data', ) % { 'sitename': self._cfg.sitename or "Wiki" } mailok, msg = sendmail.sendmail(self._request, [self.email], subject, text, mail_from=self._cfg.mail_from) return mailok, msg
def mailAccountData(self, cleartext_passwd=None): """ Mail a user who forgot his password a message enabling him to login again. """ from MoinMoin.mail import sendmail from MoinMoin.wikiutil import getLocalizedPage _ = self._request.getText tok = self.generate_recovery_token() text = '\n' + _("""\ Login Name: %s Password recovery token: %s Password reset URL: %s?action=recoverpass&name=%s&token=%s """) % ( self.name, tok, self._request.url_root, url_quote_plus(self.name), tok, ) text = _("""\ Somebody has requested to email you a password recovery token. If you lost your password, please go to the password reset URL below or go to the password recovery page again and enter your username and the recovery token. """) + text subject = _('[%(sitename)s] Your wiki account data', ) % {'sitename': self._cfg.sitename or "Wiki"} mailok, msg = sendmail.sendmail(self._request, [self.email], subject, text, mail_from=self._cfg.mail_from) return mailok, msg
def execute(macro, args): request = macro.request _ = request.getText # prevent recursion if request.mode_getpagelinks: return '' # Get allpages switch from the form allpages = int(request.form.get('allpages', [0])[0]) != 0 # Control bar - filter the list of pages # TODO: we should make this a widget and use on all page listing pages controlbar = '''<div class="controlbar"> <a href="%(qpagename)s?allpages=%(allpages)d">%(label)s</a> </div>''' % { 'qpagename': wikiutil.quoteWikinameURL(macro.formatter.page.page_name), 'allpages': not allpages, 'label': (_('Include system pages'), _('Exclude system pages'))[allpages], } # Get page dict readable by current user pages = request.rootpage.getPageDict() # build a dict of wanted pages wanted = {} for name, page in pages.items(): # Skip system pages, because missing translations are not wanted pages, # unless you are a translator and clicked "Include system pages" if not allpages and wikiutil.isSystemPage(request, name): continue # Add links to pages which does not exists in pages dict links = page.getPageLinks(request) for link in links: if not link in pages: if link in wanted: wanted[link][name] = 1 else: wanted[link] = {name: 1} # Check for the extreme case when there are no wanted pages if not wanted: return u"%s<p>%s</p>" % (controlbar ,_("No wanted pages in this wiki.")) # Return a list of page links wantednames = wanted.keys() wantednames.sort() result = [] result.append(macro.formatter.number_list(1)) for name in wantednames: if not name: continue result.append(macro.formatter.listitem(1)) # Add link to the wanted page result.append(macro.formatter.pagelink(1, name, generated=1)) result.append(macro.formatter.text(name)) result.append(macro.formatter.pagelink(0, name)) # Add links to pages that want this page, highliting # the link in those pages. where = wanted[name].keys() where.sort() if macro.formatter.page.page_name in where: where.remove(macro.formatter.page.page_name) querystr='highlight=%s' % wikiutil.url_quote_plus(name) wherelinks = [pages[pagename].link_to(request, querystr=querystr) for pagename in where] result.append(": " + ', '.join(wherelinks)) result.append(macro.formatter.listitem(0)) result.append(macro.formatter.number_list(0)) return u'%s%s' % (controlbar, u''.join(result))
def _build_filelist(request, pagename, showheader, readonly, mime_type='*'): _ = request.getText # access directory attach_dir = getAttachDir(request, pagename) files = _get_files(request, pagename) if mime_type != '*': files = [fname for fname in files if mime_type == mimetypes.guess_type(fname)[0]] str = "" if files: if showheader: str = str + _( "To refer to attachments on a page, use '''{{{attachment:filename}}}''', \n" "as shown below in the list of files. \n" "Do '''NOT''' use the URL of the {{{[get]}}} link, \n" "since this is subject to change and can break easily." ) str = str + "<ul>" label_del = _("del") label_move = _("move") label_get = _("get") label_edit = _("edit") label_view = _("view") label_unzip = _("unzip") label_install = _("install") for file in files: fsize = float(os.stat(os.path.join(attach_dir,file).encode(config.charset))[6]) # in byte fsize = "%.1f" % (fsize / 1024) baseurl = request.getScriptname() action = action_name urlpagename = wikiutil.quoteWikinameURL(pagename) urlfile = wikiutil.url_quote_plus(file) base, ext = os.path.splitext(file) get_url = getAttachUrl(pagename, file, request, escaped=1) parmdict = {'baseurl': baseurl, 'urlpagename': urlpagename, 'action': action, 'urlfile': urlfile, 'label_del': label_del, 'label_move': label_move, 'base': base, 'label_edit': label_edit, 'label_view': label_view, 'label_unzip': label_unzip, 'label_install': label_install, 'get_url': get_url, 'label_get': label_get, 'file': wikiutil.escape(file).replace(' ', '%20'), 'fsize': fsize, 'pagename': pagename} del_link = '' if request.user.may.delete(pagename) and not readonly: del_link = '<a href="%(baseurl)s/%(urlpagename)s' \ '?action=%(action)s&do=del&target=%(urlfile)s">%(label_del)s</a> | ' % parmdict if request.user.may.delete(pagename) and not readonly: move_link = '<a href="%(baseurl)s/%(urlpagename)s' \ '?action=%(action)s&do=move&target=%(urlfile)s">%(label_move)s</a> | ' % parmdict else: move_link = '' if ext == '.draw': viewlink = '<a href="%(baseurl)s/%(urlpagename)s?action=%(action)s&drawing=%(base)s">%(label_edit)s</a>' % parmdict else: viewlink = '<a href="%(baseurl)s/%(urlpagename)s?action=%(action)s&do=view&target=%(urlfile)s">%(label_view)s</a>' % parmdict if (packages.ZipPackage(request, os.path.join(attach_dir, file).encode(config.charset)).isPackage() and request.user.isSuperUser()): viewlink += ' | <a href="%(baseurl)s/%(urlpagename)s?action=%(action)s&do=install&target=%(urlfile)s">%(label_install)s</a>' % parmdict elif (zipfile.is_zipfile(os.path.join(attach_dir,file).encode(config.charset)) and request.user.may.read(pagename) and request.user.may.delete(pagename) and request.user.may.write(pagename)): viewlink += ' | <a href="%(baseurl)s/%(urlpagename)s?action=%(action)s&do=unzip&target=%(urlfile)s">%(label_unzip)s</a>' % parmdict parmdict['viewlink'] = viewlink parmdict['del_link'] = del_link parmdict['move_link'] = move_link str = str + ('<li>[%(del_link)s%(move_link)s' '<a href="%(get_url)s">%(label_get)s</a> | %(viewlink)s]' ' (%(fsize)s KB) attachment:<strong>%(file)s</strong></li>') % parmdict str = str + "</ul>" else: if showheader: str = '%s<p>%s</p>' % (str, _("No attachments stored for %(pagename)s") % {'pagename': pagename}) return str
def execute(pagename, request): """ show misc. infos about a page """ if not request.user.may.read(pagename): Page(request, pagename).send_page() return def general(page, pagename, request): _ = request.getText f = request.formatter request.write(f.heading(1, 1), f.text(_('General Information')), f.heading(0, 1)) request.write(f.paragraph(1), f.text(_("Page size: %d") % page.size()), f.paragraph(0)) from MoinMoin.support.python_compatibility import hash_new digest = hash_new('sha1', page.get_raw_body().encode(config.charset)).hexdigest().upper() request.write(f.paragraph(1), f.rawHTML('%(label)s <tt>%(value)s</tt>' % { 'label': _("SHA digest of this page's content is:"), 'value': digest, }), f.paragraph(0)) # show attachments (if allowed) attachment_info = action.getHandler(request, 'AttachFile', 'info') if attachment_info: request.write(attachment_info(pagename, request)) # show subscribers subscribers = page.getSubscribers(request, include_self=1, return_users=1) if subscribers: request.write(f.paragraph(1)) request.write(f.text(_('The following users subscribed to this page:'))) for lang in subscribers: request.write(f.linebreak(), f.text('[%s] ' % lang)) for user in subscribers[lang]: # do NOT disclose email addr, only WikiName userhomepage = Page(request, user.name) if userhomepage.exists(): request.write(f.rawHTML(userhomepage.link_to(request) + ' ')) else: request.write(f.text(user.name + ' ')) request.write(f.paragraph(0)) # show links links = page.getPageLinks(request) if links: request.write(f.paragraph(1)) request.write(f.text(_('This page links to the following pages:'))) request.write(f.linebreak()) for linkedpage in links: request.write(f.rawHTML("%s%s " % (Page(request, linkedpage).link_to(request), ",."[linkedpage == links[-1]]))) request.write(f.paragraph(0)) def history(page, pagename, request): # show history as default _ = request.getText default_count, limit_max_count = request.cfg.history_count try: max_count = int(request.form.get('max_count', [default_count])[0]) except: max_count = default_count max_count = min(max_count, limit_max_count) # open log for this page from MoinMoin.util.dataset import TupleDataset, Column history = TupleDataset() history.columns = [ Column('rev', label='#', align='right'), Column('mtime', label=_('Date'), align='right'), Column('size', label=_('Size'), align='right'), Column('diff', label='<input type="submit" value="%s">' % (_("Diff"))), Column('editor', label=_('Editor'), hidden=not request.cfg.show_names), Column('comment', label=_('Comment')), Column('action', label=_('Action')), ] # generate history list def render_action(text, query, **kw): kw.update(dict(rel='nofollow')) return page.link_to(request, text, querystr=query, **kw) # read in the complete log of this page log = editlog.EditLog(request, rootpagename=pagename) count = 0 pgactioncount = 0 for line in log.reverse(): rev = int(line.rev) actions = [] if line.action in ('SAVE', 'SAVENEW', 'SAVE/REVERT', 'SAVE/RENAME', ): size = page.size(rev=rev) actions.append(render_action(_('view'), {'action': 'recall', 'rev': '%d' % rev})) if pgactioncount == 0: rchecked = ' checked="checked"' lchecked = '' elif pgactioncount == 1: lchecked = ' checked="checked"' rchecked = '' else: lchecked = rchecked = '' diff = '<input type="radio" name="rev1" value="%d"%s><input type="radio" name="rev2" value="%d"%s>' % (rev, lchecked, rev, rchecked) if rev > 1: diff += render_action(' ' + _('to previous'), {'action': 'diff', 'rev1': rev-1, 'rev2': rev}) comment = line.comment if not comment: if '/REVERT' in line.action: comment = _("Revert to revision %(rev)d.") % {'rev': int(line.extra)} elif '/RENAME' in line.action: comment = _("Renamed from '%(oldpagename)s'.") % {'oldpagename': line.extra} pgactioncount += 1 else: # ATT* rev = '-' diff = '-' filename = wikiutil.url_unquote(line.extra) comment = "%s: %s %s" % (line.action, filename, line.comment) size = 0 if line.action != 'ATTDEL': from MoinMoin.action import AttachFile if AttachFile.exists(request, pagename, filename): size = AttachFile.size(request, pagename, filename) if line.action == 'ATTNEW': actions.append(render_action(_('view'), {'action': 'AttachFile', 'do': 'view', 'target': '%s' % filename})) elif line.action == 'ATTDRW': actions.append(render_action(_('edit'), {'action': 'AttachFile', 'drawing': '%s' % filename.replace(".draw", "")})) actions.append(render_action(_('get'), {'action': 'AttachFile', 'do': 'get', 'target': '%s' % filename})) if request.user.may.delete(pagename): actions.append(render_action(_('del'), {'action': 'AttachFile', 'do': 'del', 'target': '%s' % filename})) history.addRow(( rev, request.user.getFormattedDateTime(wikiutil.version2timestamp(line.ed_time_usecs)), str(size), diff, line.getEditor(request) or _("N/A"), wikiutil.escape(comment) or ' ', " ".join(actions), )) count += 1 if count >= max_count: break # print version history from MoinMoin.widget.browser import DataBrowserWidget request.write(unicode(html.H2().append(_('Revision History')))) if not count: # there was no entry in logfile request.write(_('No log entries found.')) return history_table = DataBrowserWidget(request) history_table.setData(history) div = html.DIV(id="page-history") div.append(html.INPUT(type="hidden", name="action", value="diff")) div.append(history_table.render(method="GET")) form = html.FORM(method="GET", action="") form.append(div) request.write(unicode(form)) # main function _ = request.getText page = Page(request, pagename) title = page.split_title() request.emit_http_headers() request.setContentLanguage(request.lang) f = request.formatter request.theme.send_title(_('Info for "%s"') % (title, ), page=page) menu_items = [ (_('Show "%(title)s"') % {'title': _('Revision History')}, {'action': 'info'}), (_('Show "%(title)s"') % {'title': _('General Page Infos')}, {'action': 'info', 'general': '1'}), (_('Show "%(title)s"') % {'title': _('Page hits and edits')}, {'action': 'info', 'hitcounts': '1'}), ] request.write(f.div(1, id="content")) # start content div request.write(f.paragraph(1)) for text, querystr in menu_items: request.write("[%s] " % page.link_to(request, text=text, querystr=querystr, rel='nofollow')) request.write(f.paragraph(0)) try: show_hitcounts = int(request.form.get('hitcounts', [0])[0]) != 0 except ValueError: show_hitcounts = False try: show_general = int(request.form.get('general', [0])[0]) != 0 except ValueError: show_general = False if show_hitcounts: from MoinMoin.stats import hitcounts request.write(hitcounts.linkto(pagename, request, 'page=' + wikiutil.url_quote_plus(pagename))) elif show_general: general(page, pagename, request) else: history(page, pagename, request) request.write(f.div(0)) # end content div request.theme.send_footer(pagename) request.theme.send_closing_html()
def do_info(pagename, request): if not request.user.may.read(pagename): Page(request, pagename).send_page(request) return def general(page, pagename, request): _ = request.getText request.write('<h2>%s</h2>\n' % _('General Information')) # show page size request.write(("<p>%s</p>" % _("Page size: %d")) % page.size()) # show SHA digest fingerprint import sha digest = sha.new(page.get_raw_body().encode(config.charset)).hexdigest().upper() request.write('<p>%(label)s <tt>%(value)s</tt></p>' % { 'label': _("SHA digest of this page's content is:"), 'value': digest, }) # show attachments (if allowed) attachment_info = getHandler(request, 'AttachFile', 'info') if attachment_info: request.write(attachment_info(pagename, request)) # show subscribers subscribers = page.getSubscribers(request, include_self=1, return_users=1) if subscribers: request.write('<p>', _('The following users subscribed to this page:')) for lang in subscribers.keys(): request.write('<br>[%s] ' % lang) for user in subscribers[lang]: # do NOT disclose email addr, only WikiName userhomepage = Page(request, user.name) if userhomepage.exists(): request.write(userhomepage.link_to(request) + ' ') else: request.write(user.name + ' ') request.write('</p>') # show links links = page.getPageLinks(request) if links: request.write('<p>', _('This page links to the following pages:'), '<br>') for linkedpage in links: request.write("%s%s " % (Page(request, linkedpage).link_to(request), ",."[linkedpage == links[-1]])) request.write("</p>") def history(page, pagename, request): # show history as default _ = request.getText # open log for this page from MoinMoin.logfile import editlog from MoinMoin.util.dataset import TupleDataset, Column history = TupleDataset() history.columns = [ Column('rev', label='#', align='right'), Column('mtime', label=_('Date'), align='right'), Column('size', label=_('Size'), align='right'), Column('diff', label='<input type="submit" value="%s">' % (_("Diff"))), Column('editor', label=_('Editor'), hidden=not request.cfg.show_names), Column('comment', label=_('Comment')), Column('action', label=_('Action')), ] # generate history list revisions = page.getRevList() versions = len(revisions) may_revert = request.user.may.revert(pagename) # read in the complete log of this page log = editlog.EditLog(request, rootpagename=pagename) count = 0 for line in log.reverse(): rev = int(line.rev) actions = "" if line.action in ['SAVE','SAVENEW','SAVE/REVERT',]: if count == 0: # latest page actions = '%s %s' % (actions, page.link_to(request, text=_('view'), querystr='')) actions = '%s %s' % (actions, page.link_to(request, text=_('raw'), querystr='action=raw')) actions = '%s %s' % (actions, page.link_to(request, text=_('print'), querystr='action=print')) else: actions = '%s %s' % (actions, page.link_to(request, text=_('view'), querystr='action=recall&rev=%d' % rev)) actions = '%s %s' % (actions, page.link_to(request, text=_('raw'), querystr='action=raw&rev=%d' % rev)) actions = '%s %s' % (actions, page.link_to(request, text=_('print'), querystr='action=print&rev=%d' % rev)) if may_revert: actions = '%s %s' % (actions, page.link_to(request, text=_('revert'), querystr='action=revert&rev=%d' % (rev,))) if count == 0: rchecked=' checked="checked"' lchecked = '' elif count == 1: lchecked=' checked="checked"' rchecked = '' else: lchecked = rchecked = '' diff = '<input type="radio" name="rev1" value="%d"%s><input type="radio" name="rev2" value="%d"%s>' % (rev,lchecked,rev,rchecked) comment = line.comment if not comment and line.action.find('/REVERT') != -1: comment = _("Revert to revision %(rev)d.") % {'rev': int(line.extra)} size = page.size(rev=rev) else: # ATT* rev = '-' diff = '-' filename = wikiutil.url_unquote(line.extra) comment = "%s: %s %s" % (line.action, filename, line.comment) size = 0 if line.action != 'ATTDEL': from MoinMoin.action import AttachFile page_dir = AttachFile.getAttachDir(request, pagename) filepath = os.path.join(page_dir, filename) try: # FIXME, wrong path on non-std names size = os.path.getsize(filepath) except: pass if line.action == 'ATTNEW': actions = '%s %s' % (actions, page.link_to(request, text=_('view'), querystr='action=AttachFile&do=view&target=%s' % filename)) elif line.action == 'ATTDRW': actions = '%s %s' % (actions, page.link_to(request, text=_('edit'), querystr='action=AttachFile&drawing=%s' % filename.replace(".draw",""))) actions = '%s %s' % (actions, page.link_to(request, text=_('get'), querystr='action=AttachFile&do=get&target=%s' % filename)) actions = '%s %s' % (actions, page.link_to(request, text=_('del'), querystr='action=AttachFile&do=del&target=%s' % filename)) # XXX use?: wikiutil.escape(filename) history.addRow(( rev, request.user.getFormattedDateTime(wikiutil.version2timestamp(line.ed_time_usecs)), str(size), diff, line.getEditor(request) or _("N/A"), wikiutil.escape(comment) or ' ', actions, )) count += 1 if count >= 100: break # print version history from MoinMoin.widget.browser import DataBrowserWidget request.write('<h2>%s</h2>\n' % _('Revision History')) if not count: # there was no entry in logfile request.write(_('No log entries found.')) return # TODO: this form activates revert, which should use POST, but # other actions should use get. Maybe we should put the revert # into the page view itself, and not in this form. request.write('<form method="GET" action="">\n') request.write('<div id="page-history">\n') request.write('<input type="hidden" name="action" value="diff">\n') history_table = DataBrowserWidget(request) history_table.setData(history) history_table.render() request.write('</div>\n') request.write('</form>\n') _ = request.getText page = Page(request, pagename) qpagename = wikiutil.quoteWikinameURL(pagename) title = page.split_title(request) request.http_headers() # This action uses page or wiki language TODO: currently # page.language is broken and not available now, when we fix it, # this will be automatically fixed. lang = page.language or request.cfg.language_default request.setContentLanguage(lang) wikiutil.send_title(request, _('Info for "%s"') % (title,), pagename=pagename) historylink = wikiutil.link_tag(request, '%s?action=info' % qpagename, _('Show "%(title)s"') % {'title': _('Revision History')}) generallink = wikiutil.link_tag(request, '%s?action=info&general=1' % qpagename, _('Show "%(title)s"') % {'title': _('General Page Infos')}) hitcountlink = wikiutil.link_tag(request, '%s?action=info&hitcounts=1' % qpagename, _('Show chart "%(title)s"') % {'title': _('Page hits and edits')}) request.write('<div id="content">\n') # start content div request.write("<p>[%s] [%s] [%s]</p>" % (historylink, generallink, hitcountlink)) show_hitcounts = int(request.form.get('hitcounts', [0])[0]) != 0 show_general = int(request.form.get('general', [0])[0]) != 0 if show_hitcounts: from MoinMoin.stats import hitcounts request.write(hitcounts.linkto(pagename, request, 'page=' + wikiutil.url_quote_plus(pagename))) elif show_general: general(page, pagename, request) else: history(page, pagename, request) request.write('</div>\n') # end content div wikiutil.send_footer(request, pagename)
def execute(macro, args): request = macro.request _ = request.getText formatter = macro.formatter kwAllowed = ['width', 'height', 'alt'] pp, pp_count, kw, kw_count = explore_args(args, kwAllowed) if not pp_count or pp_count and not pp[0]: msg = 'Not enough arguments given to ImageLink macro! Try <<ImageLink(example.png, WikiName, width=200)>>.' return "%s%s%s" % (formatter.sysmsg(1), formatter.text(msg), formatter.sysmsg(0)) image = pp[0] if pp_count >= 2 and pp[1]: target = pp[1] if target.startswith('attachment:') or target.startswith('inline:'): if target.startswith('attachment:'): target = (target.split('attachment:'))[1] pagename, attname = AttachFile.absoluteName(target, formatter.page.page_name) target = AttachFile.getAttachUrl(pagename, target, request) elif target.startswith('inline:'): target = (target.split('inline:'))[1] pagename, attname = AttachFile.absoluteName(target, formatter.page.page_name) target = AttachFile.getAttachUrl(pagename, target, request, do='view') if not AttachFile.exists(request, pagename, attname): linktext = _('Upload new attachment "%(filename)s"', formatted=False) return wikiutil.link_tag(request, ('%s?action=AttachFile&rename=%s' % ( wikiutil.quoteWikinameURL(pagename), wikiutil.url_quote_plus(attname))), linktext % {'filename': attname}) kw['src'] = AttachFile.getAttachUrl(pagename, image, request) elif pp_count == 1: pagename, attname = AttachFile.absoluteName(image, formatter.page.page_name) target = AttachFile.getAttachUrl(pagename, image, request) else: target = None if _is_URL(image): kw['src'] = image else: pagename, attname = AttachFile.absoluteName(image, formatter.page.page_name) kw['src'] = AttachFile.getAttachUrl(pagename, attname, request) if not AttachFile.exists(request, pagename, attname): linktext = _('Upload new attachment "%(filename)s"', formatted=False) return wikiutil.link_tag(request, ('%s?action=AttachFile&rename=%s' % ( wikiutil.quoteWikinameURL(pagename), wikiutil.url_quote_plus(attname))), linktext % {'filename': attname}) if 'alt' not in kw: if target is None or _is_URL(target): if _is_URL(image): # Get image name http://here.com/dir/image.png -> image.png kw['alt'] = wikiutil.taintfilename(formatter.text(image.split('/')[-1])) else: kw['alt'] = attname else: kw['alt'] = target if target is None: target = kw['src'] if pp_count == 1: return "%s%s%s" % (formatter.url(1, kw['src']), formatter.image(**kw), formatter.url(0)) if _is_URL(target) or 'action=AttachFile&do=get&target=' in target or 'action=AttachFile&do=view&target=' in target: return "%s%s%s" % (formatter.url(1, target), formatter.image(**kw), formatter.url(0)) else: if ":" in target: if target.startswith('wiki:'): target = target[5:] wikitag, wikiurl, wikitail, error = wikiutil.resolve_wiki(request, target) url = wikiurl + wikiutil.quoteWikinameURL(wikitail) return "%s%s%s" % (formatter.url(1, url), formatter.image(**kw), formatter.url(0)) else: return "%s%s%s" % (formatter.pagelink(1, target), formatter.image(**kw), formatter.pagelink(0))
def execute(macro, args): request = macro.request _ = request.getText formatter = macro.formatter kwAllowed = ['width', 'height', 'alt'] pp, pp_count, kw, kw_count = explore_args(args, kwAllowed) if not pp_count or pp_count and not pp[0]: msg = 'Not enough arguments given to ImageLink macro! Try <<ImageLink(example.png, WikiName, width=200)>>.' return "%s%s%s" % (formatter.sysmsg(1), formatter.text(msg), formatter.sysmsg(0)) image = pp[0] if pp_count >= 2 and pp[1]: target = pp[1] if target.startswith('attachment:') or target.startswith('inline:'): if target.startswith('attachment:'): target = (target.split('attachment:'))[1] pagename, attname = AttachFile.absoluteName( target, formatter.page.page_name) target = AttachFile.getAttachUrl(pagename, target, request) elif target.startswith('inline:'): target = (target.split('inline:'))[1] pagename, attname = AttachFile.absoluteName( target, formatter.page.page_name) target = AttachFile.getAttachUrl(pagename, target, request, do='view') if not AttachFile.exists(request, pagename, attname): linktext = _('Upload new attachment "%(filename)s"', formatted=False) return wikiutil.link_tag(request, ('%s?action=AttachFile&rename=%s' % (wikiutil.quoteWikinameURL(pagename), wikiutil.url_quote_plus(attname))), linktext % {'filename': attname}) kw['src'] = AttachFile.getAttachUrl(pagename, image, request) elif pp_count == 1: pagename, attname = AttachFile.absoluteName(image, formatter.page.page_name) target = AttachFile.getAttachUrl(pagename, image, request) else: target = None if _is_URL(image): kw['src'] = image else: pagename, attname = AttachFile.absoluteName(image, formatter.page.page_name) kw['src'] = AttachFile.getAttachUrl(pagename, attname, request) if not AttachFile.exists(request, pagename, attname): linktext = _('Upload new attachment "%(filename)s"', formatted=False) return wikiutil.link_tag(request, ('%s?action=AttachFile&rename=%s' % (wikiutil.quoteWikinameURL(pagename), wikiutil.url_quote_plus(attname))), linktext % {'filename': attname}) if 'alt' not in kw: if target is None or _is_URL(target): if _is_URL(image): # Get image name http://here.com/dir/image.png -> image.png kw['alt'] = wikiutil.taintfilename( formatter.text(image.split('/')[-1])) else: kw['alt'] = attname else: kw['alt'] = target if target is None: target = kw['src'] if pp_count == 1: return "%s%s%s" % (formatter.url( 1, kw['src']), formatter.image(**kw), formatter.url(0)) if _is_URL( target ) or 'action=AttachFile&do=get&target=' in target or 'action=AttachFile&do=view&target=' in target: return "%s%s%s" % (formatter.url( 1, target), formatter.image(**kw), formatter.url(0)) else: if ":" in target: if target.startswith('wiki:'): target = target[5:] wikitag, wikiurl, wikitail, error = wikiutil.resolve_wiki( request, target) url = wikiurl + wikiutil.quoteWikinameURL(wikitail) return "%s%s%s" % (formatter.url( 1, url), formatter.image(**kw), formatter.url(0)) else: return "%s%s%s" % (formatter.pagelink( 1, target), formatter.image(**kw), formatter.pagelink(0))