Example #1
0
def macro_InterWiki(macro):
    interwiki_list = wikiutil.load_wikimap(macro.request)
    iwlist = interwiki_list.items()  # this is where we cached it
    iwlist.sort()
    fmt = macro.formatter
    output = []
    output.append(fmt.definition_list(1))
    for tag, url in iwlist:
        output.append(fmt.definition_term(1))
        output.append(fmt.code(1))
        output.append(fmt.url(1, wikiutil.join_wiki(url, 'RecentChanges')))
        output.append(fmt.text(tag))
        output.append(fmt.url(0))
        output.append(fmt.code(0))
        output.append(fmt.definition_term(0))
        output.append(fmt.definition_desc(1))
        output.append(fmt.code(1))
        if '$PAGE' not in url:
            output.append(fmt.url(1, url))
            output.append(fmt.text(url))
            output.append(fmt.url(0))
        else:
            output.append(fmt.text(url))
        output.append(fmt.code(0))
        output.append(fmt.definition_desc(1))
    output.append(fmt.definition_list(0))
    return u''.join(output)
Example #2
0
def macro_InterWiki(macro):
    interwiki_list = wikiutil.load_wikimap(macro.request)
    iwlist = interwiki_list.items()  # this is where we cached it
    iwlist.sort()
    fmt = macro.formatter
    output = []
    output.append(fmt.definition_list(1))
    for tag, url in iwlist:
        output.append(fmt.definition_term(1))
        output.append(fmt.code(1))
        output.append(fmt.url(1, wikiutil.join_wiki(url, "RecentChanges")))
        output.append(fmt.text(tag))
        output.append(fmt.url(0))
        output.append(fmt.code(0))
        output.append(fmt.definition_term(0))
        output.append(fmt.definition_desc(1))
        output.append(fmt.code(1))
        if "$PAGE" not in url:
            output.append(fmt.url(1, url))
            output.append(fmt.text(url))
            output.append(fmt.url(0))
        else:
            output.append(fmt.text(url))
        output.append(fmt.code(0))
        output.append(fmt.definition_desc(1))
    output.append(fmt.definition_list(0))
    return u"".join(output)
Example #3
0
def get_url_ns(request, pagename, link):
    # Find out subpage level to adjust URL:s accordingly
    subrank = pagename.count("/")
    # Namespaced names
    if ":" in link:
        iw_list = wikiutil.load_wikimap(request)
        iwname = link.split(":")
        if iw_list.has_key(iwname[0]):
            return iw_list[iwname[0]] + iwname[1]
        else:
            return "../" * subrank + "./InterWiki"
    # handle categories as ordernodes different
    # so that they would point to the corresponding categories
    if filter_categories(request, [link]):
        return "../" * subrank + "./" + link
    else:
        return "../" * subrank + "./%sProperty" % (link)
Example #4
0
def get_url_ns(request, pagename, link):
    # Find out subpage level to adjust URL:s accordingly
    subrank = pagename.count('/')
    # Namespaced names
    if ':' in link:
        iw_list = wikiutil.load_wikimap(request)
        iwname = link.split(':')
        if iw_list.has_key(iwname[0]):
            return iw_list[iwname[0]] + iwname[1]
        else:
            return '../' * subrank + './InterWiki'
    # handle categories as ordernodes different
    # so that they would point to the corresponding categories
    if filter_categories(request, [link]):
        return '../' * subrank + './' + link
    else:
        return '../' * subrank + './%sProperty' % (link)
Example #5
0
def node_type(request, nodename):
    if ":" in nodename:
        if get_url_re().search(nodename):
            return "url"

        start = nodename.split(":")[0]
        if start in ATTACHMENT_SCHEMAS:
            return "attachment"

        # Check if we know of the wiki an interwiki-style link is
        # trying to refer to. If not, assume that this should not be a
        # link.
        iw_list = wikiutil.load_wikimap(request)
        if iw_list.has_key(start):
            return "interwiki"
        elif start:
            return "none"

    return "page"
Example #6
0
def node_type(request, nodename):
    if ':' in nodename:
        if get_url_re().search(nodename):
            return 'url'

        start = nodename.split(':')[0]
        if start in ATTACHMENT_SCHEMAS:
            return 'attachment'

        # Check if we know of the wiki an interwiki-style link is
        # trying to refer to. If not, assume that this should not be a
        # link.
        iw_list = wikiutil.load_wikimap(request)
        if iw_list.has_key(start):
            return 'interwiki'
        elif start:
            return 'none'

    return 'page'
Example #7
0
def node_type(request, nodename):
    if ':' in nodename:
        if get_url_re().search(nodename):
            return 'url'

        start = nodename.split(':')[0]
        if start in ATTACHMENT_SCHEMAS:
            return 'attachment'

        # Check if we know of the wiki an interwiki-style link is
        # trying to refer to. If not, assume that this should not be a
        # link.
        iw_list = wikiutil.load_wikimap(request)
        if iw_list.has_key(start):
            return 'interwiki'
        elif start:
            return 'none'

    return 'page'
Example #8
0
def load_graph(request, pagename, urladd, load_origin=True):
    if not request.user.may.read(pagename):
        return None

    def add_adata_link(adata, edge, type):
        # Add edge if it does not already exist
        e = adata.edges.get(*edge)
        if not e:
            e = adata.edges.add(*edge)
            e.linktype = set([type])
        else:
            e.linktype.add(type)
        return adata

    cat_re = category_regex(request)
    temp_re = template_regex(request)

    page = request.graphdata.getpage(pagename)
    if not page:
        return None

    # Make graph, initialise head node
    adata = Graph()
    if load_origin:
        adata = _add_node(request, pagename, adata, urladd, "page")
    else:
        adata.nodes.add(pagename)

    # Add links to page
    links = request.graphdata.get_in(pagename)
    for linktype in links:
        for src in links[linktype]:
            # Filter Category, Template pages
            if cat_re.search(src) or temp_re.search(src):
                continue
            # Add page and its metadata
            # Currently pages can have links in them only
            # from local pages, thus nodetype == page
            adata = _add_node(request, src, adata, urladd, "page")
            adata = add_adata_link(adata, (src, pagename), linktype)
    # Add links from page
    links = request.graphdata.get_out(pagename)
    for linktype in links:
        # print "add_node", pagename, dst
        for i, dst in enumerate(links[linktype]):
            # Filter Category, Template pages
            if cat_re.search(dst) or temp_re.search(dst):
                continue

            # Fix links to everything but pages
            label = ""
            gwikiurl = ""
            tooltip = ""
            nodetype = node_type(request, dst)

            if nodetype == "attachment":
                # get the absolute name ie both page and filename
                gwikiurl = absolute_attach_name(pagename, dst)
                att_parts = gwikiurl.split(":")[1].split("/")
                att_page = "/".join(att_parts[:-1])
                att_file = att_parts[-1]

                if pagename == att_page:
                    label = "Attachment: %s" % (att_file)
                else:
                    label = "Attachment: %s/%s" % (att_page, att_file)

                _, exists = attachment_file(request, att_page, att_file)

                # For existing attachments, have link to view it
                if exists:
                    gwikiurl = "./%s?action=AttachFile&do=get&target=%s" % (att_page, att_file)
                    tooltip = request.getText("View attachment")
                # For non-existing, have a link to upload it
                else:
                    gwikiurl = "./%s?action=AttachFile&rename=%s" % (att_page, att_file)
                    tooltip = request.getText("Add attachment")

            elif nodetype == "interwiki":
                # Get effective URL:s to interwiki URL:s
                iwname = dst.split(":")
                iw_list = wikiutil.load_wikimap(request)

                gwikiurl = iw_list[iwname[0]] + iwname[1]
                tooltip = iwname[1] + " " + request.getText("page on") + " " + iwname[0] + " " + request.getText("wiki")

            elif nodetype == "url":
                # URL:s have the url already, keep it
                gwikiurl = dst
                tooltip = dst

            elif nodetype == "none":
                # Was not a valid link after all, eg. an
                # interwiki-style link, but the wiki name was not in
                # intermap.
                continue

            # Add page and its metadata
            adata = _add_node(request, dst, adata, urladd, nodetype)
            adata = add_adata_link(adata, (pagename, dst), linktype)
            if label or gwikiurl or tooltip:
                node = adata.nodes.get(dst)

            # Add labels, gwikiurls and tooltips
            if label:
                node.gwikilabel = label
            if gwikiurl:
                node.gwikiURL = gwikiurl
            if tooltip:
                node.gwikitooltip = tooltip

    return adata
Example #9
0
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 = '''
         <tr>
          <td colspan=2>
           <select id="sctPagename" size="1" onchange="OnChangePagename(this.value);">
           %s
           </select>
          <td>
         </tr>
''' % "\n".join(['<option value="%s">%s</option>' % (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(
        ['<option value="%s">%s</option>' % (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
    request.write(u'''
<!--
 * FCKeditor - The text editor for internet
 * Copyright (C) 2003-2004 Frederico Caldeira Knabben
 *
 * Licensed under the terms of the GNU Lesser General Public License:
 *   http://www.opensource.org/licenses/lgpl-license.php
 *
 * For further information visit:
 *   http://www.fckeditor.net/
 *
 * File Name: fck_link.html
 *  Link dialog window.
 *
 * Version:  2.0 FC (Preview)
 * Modified: 2005-02-18 23:55:22
 *
 * File Authors:
 *   Frederico Caldeira Knabben ([email protected])
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta name="robots" content="index,nofollow">
<html>
 <head>
  <title>Link Properties</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="robots" content="noindex,nofollow" />
  <script src="%(url_prefix_static)s/applets/FCKeditor/editor/dialog/common/fck_dialog_common.js" type="text/javascript"></script>
  <script src="%(url_prefix_static)s/applets/moinFCKplugins/moinlink/fck_link.js" type="text/javascript"></script>
  <script src="%(url_prefix_static)s/applets/moinFCKplugins/moinurllib.js" type="text/javascript"></script>
 </head>
 <body scroll="no" style="OVERFLOW: hidden">
  <div id="divInfo" style="DISPLAY: none">
   <span fckLang="DlgLnkType">Link Type</span><br />
   <select id="cmbLinkType" onchange="SetLinkType(this.value);">
    <option value="wiki" selected="selected">WikiPage</option>
    <option value="interwiki">Interwiki</option>
    <option value="url" fckLang="DlgLnkTypeURL">URL</option>
   </select>
   <br />
   <br />
   <div id="divLinkTypeWiki">
    <table height="100%%" cellSpacing="0" cellPadding="0" width="100%%" border="0">
     <tr>
      <td>
       <form action=%(action)s method="GET">
       <input type="hidden" name="action" value="fckdialog">
       <input type="hidden" name="dialog" value="link">
       <input type="hidden" id="basepage" name="basepage" value="%(basepage)s">
       <table cellSpacing="0" cellPadding="0" align="center" border="0">
        <tr>
         <td>
          <span fckLang="PageDlgName">Page Name</span><br>
          <input id="txtPagename" name="pagename" size="30" value="%(name)s">
         </td>
         <td valign="bottom">
           <input id=btnSearchpage type="submit" value="Search">
         </td>
        </tr>
        %(page_list)s
       </table>
       </form>
      </td>
     </tr>
    </table>
   </div>
   <div id="divLinkTypeInterwiki">
    <table height="100%%" cellSpacing="0" cellPadding="0" width="100%%" border="0">
     <tr>
      <td>
       <table cellSpacing="0" cellPadding="0" align="center" border="0">
        <tr>
         <td>
          <span fckLang="WikiDlgName">Wiki:PageName</span><br>
          <select id="sctInterwiki" size="1">
          %(interwiki)s
          </select>:
          <input id="txtInterwikipagename"></input>
         </td>
        </tr>
       </table>
      </td>
     </tr>
    </table>
   </div>
   <div id="divLinkTypeUrl">
    <table cellspacing="0" cellpadding="0" width="100%%" border="0">
     <tr>
      <td nowrap="nowrap">
       <span fckLang="DlgLnkProto">Protocol</span><br />
       <select id="cmbLinkProtocol">
        <option value="http://" selected="selected">http://</option>
        <option value="https://">https://</option>
        <option value="ftp://">ftp://</option>
        <option value="file://">file://</option>
        <option value="news://">news://</option>
        <option value="mailto:">mailto:</option>
        <option value="" fckLang="DlgLnkProtoOther">&lt;other&gt;</option>
       </select>
      </td>
      <td nowrap="nowrap">&nbsp;</td>
      <td nowrap="nowrap" width="100%%">
       <span fckLang="DlgLnkURL">URL</span><br />
       <input id="txtUrl" style="WIDTH: 100%%" type="text" onkeyup="OnUrlChange();" onchange="OnUrlChange();" />
      </td>
     </tr>
    </table>
    <br />
   </div>
  </div>
 </body>
</html>
''' % locals())
Example #10
0
def load_graph(request, pagename, urladd, load_origin=True):
    if not request.user.may.read(pagename):
        return None

    def add_adata_link(adata, edge, type):
        # Add edge if it does not already exist
        e = adata.edges.get(*edge)
        if not e:
            e = adata.edges.add(*edge)
            e.linktype = set([type])
        else:
            e.linktype.add(type)
        return adata

    cat_re = category_regex(request)
    temp_re = template_regex(request)

    page = request.graphdata.getpage(pagename)
    if not page:
        return None

    # Make graph, initialise head node
    adata = Graph()
    if load_origin:
        adata = _add_node(request, pagename, adata, urladd, 'page')
    else:
        adata.nodes.add(pagename)

    # Add links to page
    links = request.graphdata.get_in(pagename)
    for linktype in links:
        for src in links[linktype]:
            # Filter Category, Template pages
            if cat_re.search(src) or temp_re.search(src):
                continue
            # Add page and its metadata
            # Currently pages can have links in them only
            # from local pages, thus nodetype == page
            adata = _add_node(request, src, adata, urladd, 'page')
            adata = add_adata_link(adata, (src, pagename), linktype)
    # Add links from page
    links = request.graphdata.get_out(pagename)
    for linktype in links:
        #print "add_node", pagename, dst
        for i, dst in enumerate(links[linktype]):
            # Filter Category, Template pages
            if cat_re.search(dst) or temp_re.search(dst):
                continue

            # Fix links to everything but pages
            label = ''
            gwikiurl = ''
            tooltip = ''
            nodetype = node_type(request, dst)

            if nodetype == 'attachment':
                # get the absolute name ie both page and filename
                gwikiurl = absolute_attach_name(pagename, dst)
                att_parts = gwikiurl.split(':')[1].split('/')
                att_page = '/'.join(att_parts[:-1])
                att_file = att_parts[-1]

                if pagename == att_page:
                    label = "Attachment: %s" % (att_file)
                else:
                    label = "Attachment: %s/%s" % (att_page, att_file)

                _, exists = attachment_file(request, 
                                            att_page, att_file)

                # For existing attachments, have link to view it
                if exists:
                    gwikiurl = "./%s?action=AttachFile&do=get&target=%s" % \
                        (att_page, att_file)
                    tooltip = request.getText('View attachment')
                # For non-existing, have a link to upload it
                else:
                    gwikiurl = "./%s?action=AttachFile&rename=%s" % \
                        (att_page, att_file)
                    tooltip = request.getText('Add attachment')

            elif nodetype == 'interwiki':
                # Get effective URL:s to interwiki URL:s
                iwname = dst.split(':')
                iw_list = wikiutil.load_wikimap(request)
                
                gwikiurl = iw_list[iwname[0]] + iwname[1]
                tooltip = iwname[1] + ' ' + \
                    request.getText('page on') + \
                    ' ' + iwname[0] + ' ' + \
                    request.getText('wiki')

            elif nodetype == 'url':
                # URL:s have the url already, keep it
                gwikiurl = dst
                tooltip = dst

            elif nodetype == 'none':
                # Was not a valid link after all, eg. an
                # interwiki-style link, but the wiki name was not in
                # intermap.
                continue

            # Add page and its metadata
            adata = _add_node(request, dst, adata, urladd, nodetype)
            adata = add_adata_link(adata, (pagename, dst), linktype)
            if label or gwikiurl or tooltip:
                node = adata.nodes.get(dst)

            # Add labels, gwikiurls and tooltips
            if label:
                node.gwikilabel = label
            if gwikiurl:
                node.gwikiURL = gwikiurl
            if tooltip:
                node.gwikitooltip = tooltip

    return adata
Example #11
0
def link_dialog(request):
    # list of wiki pages
    name = request.values.get("pagename", "")
    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 = '''
         <tr>
          <td colspan=2>
           <select id="sctPagename" size="1" onchange="OnChangePagename(this.value);">
           %s
           </select>
          <td>
         </tr>
''' % "\n".join([
            '<option value="%s">%s</option>' % (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(
        ['<option value="%s">%s</option>' % (key, key) for key in resultlist])

    # wiki url
    url_prefix_static = request.cfg.url_prefix_static
    scriptname = request.script_root + '/'
    action = scriptname
    basepage = request.page.page_name
    request.write(u'''
<!--
 * FCKeditor - The text editor for internet
 * Copyright (C) 2003-2004 Frederico Caldeira Knabben
 *
 * Licensed under the terms of the GNU Lesser General Public License:
 *   http://www.opensource.org/licenses/lgpl-license.php
 *
 * For further information visit:
 *   http://www.fckeditor.net/
 *
 * File Name: fck_link.html
 *  Link dialog window.
 *
 * Version:  2.0 FC (Preview)
 * Modified: 2005-02-18 23:55:22
 *
 * File Authors:
 *   Frederico Caldeira Knabben ([email protected])
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta name="robots" content="index,nofollow">
<html>
 <head>
  <title>Link Properties</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="robots" content="noindex,nofollow" />
  <script src="%(url_prefix_static)s/applets/FCKeditor/editor/dialog/common/fck_dialog_common.js" type="text/javascript"></script>
  <script src="%(url_prefix_static)s/applets/moinFCKplugins/moinlink/fck_link.js" type="text/javascript"></script>
  <script src="%(url_prefix_static)s/applets/moinFCKplugins/moinurllib.js" type="text/javascript"></script>
 </head>
 <body scroll="no" style="OVERFLOW: hidden">
  <div id="divInfo" style="DISPLAY: none">
   <span fckLang="DlgLnkType">Link Type</span><br />
   <select id="cmbLinkType" onchange="SetLinkType(this.value);">
    <option value="wiki" selected="selected">WikiPage</option>
    <option value="interwiki">Interwiki</option>
    <option value="url" fckLang="DlgLnkTypeURL">URL</option>
   </select>
   <br />
   <br />
   <div id="divLinkTypeWiki">
    <table height="100%%" cellSpacing="0" cellPadding="0" width="100%%" border="0">
     <tr>
      <td>
       <form action=%(action)s method="GET">
       <input type="hidden" name="action" value="fckdialog">
       <input type="hidden" name="dialog" value="link">
       <input type="hidden" id="basepage" name="basepage" value="%(basepage)s">
       <table cellSpacing="0" cellPadding="0" align="center" border="0">
        <tr>
         <td>
          <span fckLang="PageDlgName">Page Name</span><br>
          <input id="txtPagename" name="pagename" size="30" value="%(name)s">
         </td>
         <td valign="bottom">
           <input id=btnSearchpage type="submit" value="Search">
         </td>
        </tr>
        %(page_list)s
       </table>
       </form>
      </td>
     </tr>
    </table>
   </div>
   <div id="divLinkTypeInterwiki">
    <table height="100%%" cellSpacing="0" cellPadding="0" width="100%%" border="0">
     <tr>
      <td>
       <table cellSpacing="0" cellPadding="0" align="center" border="0">
        <tr>
         <td>
          <span fckLang="WikiDlgName">Wiki:PageName</span><br>
          <select id="sctInterwiki" size="1">
          %(interwiki)s
          </select>:
          <input id="txtInterwikipagename"></input>
         </td>
        </tr>
       </table>
      </td>
     </tr>
    </table>
   </div>
   <div id="divLinkTypeUrl">
    <table cellspacing="0" cellpadding="0" width="100%%" border="0">
     <tr>
      <td nowrap="nowrap">
       <span fckLang="DlgLnkProto">Protocol</span><br />
       <select id="cmbLinkProtocol">
        <option value="http://" selected="selected">http://</option>
        <option value="https://">https://</option>
        <option value="ftp://">ftp://</option>
        <option value="file://">file://</option>
        <option value="news://">news://</option>
        <option value="mailto:">mailto:</option>
        <option value="" fckLang="DlgLnkProtoOther">&lt;other&gt;</option>
       </select>
      </td>
      <td nowrap="nowrap">&nbsp;</td>
      <td nowrap="nowrap" width="100%%">
       <span fckLang="DlgLnkURL">URL</span><br />
       <input id="txtUrl" style="WIDTH: 100%%" type="text" onkeyup="OnUrlChange();" onchange="OnUrlChange();" />
      </td>
     </tr>
    </table>
    <br />
   </div>
  </div>
 </body>
</html>
''' % locals())