[Zope3-checkins] CVS: Zope3/src/zope/products/zwiki/browser -
__init__.py:1.1 add.pt:1.1 comment_page.pt:1.1
configure.zcml:1.1 parents_page.pt:1.1 subscriptions.pt:1.1
view_page.pt:1.1 wiki.py:1.1 wiki_add.pt:1.1
wiki_icon.gif:1.1 wiki_search.pt:1.1 wiki_toc.pt:1.1
wikipage.py:1.1 wikipage_icon.gif:1.1
K.Narasimha Murthy
nmurthy at zeomega.com
Tue Dec 16 05:05:55 EST 2003
Update of /cvs-repository/Zope3/src/zope/products/zwiki/browser
In directory cvs.zope.org:/tmp/cvs-serv10613/browser
Added Files:
__init__.py add.pt comment_page.pt configure.zcml
parents_page.pt subscriptions.pt view_page.pt wiki.py
wiki_add.pt wiki_icon.gif wiki_search.pt wiki_toc.pt
wikipage.py wikipage_icon.gif
Log Message:
Moved zwiki product from zopeproducts to zope.products, fixed the bugs and fixed test cases.
=== Added File Zope3/src/zope/products/zwiki/browser/__init__.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Browser Views for the zwiki for Zope 3 Product
$Id: __init__.py,v 1.1 2003/12/16 10:05:53 nmurthy Exp $
"""
=== Added File Zope3/src/zope/products/zwiki/browser/add.pt ===
<html metal:use-macro="views/standard_macros/dialog">
<body>
<div metal:fill-slot="body">
<form action="action.html" method="POST">
<table class="TypeListing" cellpadding="3">
<caption>Add Content</caption>
<tbody tal:repeat="info view/addingInfo">
<tr>
<td class="Selector">
<input type="radio" name="type_name"
tal:attributes="value info/action; id info/action" />
</td>
<td class="TypeName">
<label style="font-weight: bold;"
tal:attributes="for info/action">
<span tal:replace="info/title" >Folder</span>
</label>
<div class="TypeDescription" tal:content="info/description">
Folders are generic containers for content, including other
folders.
</div>
</td>
</tr>
</tbody>
<tbody tal:condition="nothing">
<tr>
<td class="Selector">
<input type="radio" name="type_name" value="" />
</td>
<td class="TypeName">
<img alt="Folder" src="../../ZMI/www/document_icon.gif" />
Document
</td>
</tr>
<tr>
<td class="Selector"><br /></td>
<td class="TypeDescription">
Documents are simple textual content.
</td>
</tr>
</tbody>
<tr>
<td><br/></td>
<td>
<input type="text" name="id"
tal:condition="view/namesAccepted"
tal:attributes="value request/id | nothing"
/>
<input type="submit" value=" Add " />
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
=== Added File Zope3/src/zope/products/zwiki/browser/comment_page.pt ===
<html metal:use-macro="views/standard_macros/page">
<head>
<style metal:fill-slot="style_slot">
</style>
</head>
<body>
<div metal:fill-slot="body">
<form action="addComment.html" method="post" i18n:domain="wiki">
<div class="row">
<div class="label" i18n:translate="">Comment</div>
<div class="field">
<textarea name="comment" cols="60" rows="10"></textarea>
</div>
</div>
<div class="row">
<div class="label" i18n:translate="">
Wiki Source as reference
</div>
<div class="field">
<textarea name="source" cols="60" rows="5"
tal:content="view/source"></textarea>
</div>
</div>
<div class="row">
<div class="controls">
<input type="submit" value="Refresh"
i18n:attributes="value refresh-button" />
<input type="submit" name="submit" value="Submit"
i18n:attributes="value submit-button" />
</div>
</div>
</form>
</div>
</body>
</html>
=== Added File Zope3/src/zope/products/zwiki/browser/configure.zcml ===
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
i18n_domain="zwiki"
>
<include package=".skin" />
<browser:menu
id="add_wiki"
title="Menu of objects to be added to wikis."/>
<!-- Custom adding view. -->
<browser:view
for="zope.products.zwiki.interfaces.IWiki"
name="+"
class=".wiki.WikiAdding"
permission="zope.products.zwiki.AddWikiPage"
allowed_attributes="addingInfo"
menu="zmi_actions"
title="Add"
>
<browser:page name="index.html" template="add.pt" />
<browser:page name="action.html" attribute="action" />
</browser:view>
<browser:addform
label="Add Wiki"
name="AddWiki"
schema="zope.products.zwiki.interfaces.IWiki"
content_factory="zope.products.zwiki.wiki.Wiki"
permission="zope.ManageContent"
class=".wiki.AddWiki"
template="wiki_add.pt"
menu="add_content" title="Wiki"/>
<browser:page
name="toc.html"
for="zope.products.zwiki.interfaces.IWiki"
class=".wiki.TableOfContents"
template="wiki_toc.pt"
permission="zope.products.zwiki.ViewWikiPage"
menu="zmi_views" title="TOC"/>
<browser:page
name="search.html"
for="zope.products.zwiki.interfaces.IWiki"
class=".wiki.WikiSearch"
template="wiki_search.pt"
permission="zope.products.zwiki.ViewWikiPage"
menu="zmi_views" title="Search"/>
<browser:pages
for="zope.products.zwiki.interfaces.IWiki"
class=".wikipage.MailSubscriptions"
permission="zope.products.zwiki.EditWikiPage">
<browser:page name="subscriptions.html" template="subscriptions.pt"
menu="zmi_views" title="Subscriptions" />
<browser:page name="changeSubscriptions.html" attribute="change" />
</browser:pages>
<browser:defaultView
name="toc.html"
for="zope.products.zwiki.interfaces.IWiki"/>
<browser:icon
name="zmi_icon"
for="zope.products.zwiki.interfaces.IWiki"
file="wiki_icon.gif"
/>
<!-- WikiPage browser configuration -->
<browser:addform
label="Add Wiki Page"
name="AddWikiPage"
schema="zope.products.zwiki.interfaces.IWikiPage"
content_factory="zope.products.zwiki.wikipage.WikiPage"
permission="zope.products.zwiki.AddWikiPage"
fields="source type"
class=".wikipage.AddWikiPage"
menu="add_wiki"
title="Wiki Page"/>
<browser:editform
schema="zope.products.zwiki.interfaces.IWikiPage"
for="zope.products.zwiki.interfaces.IWikiPage"
label="Change Wiki Page"
name="edit.html"
permission="zope.products.zwiki.EditWikiPage"
fields="source type"
class=".wikipage.EditWikiPage"
menu="zmi_views" title="Edit" />
<browser:pages
for="zope.products.zwiki.interfaces.IWikiPage"
class=".wikipage.GenericWikiPageViews"
permission="zope.products.zwiki.ViewWikiPage">
<browser:page name="breadcrumbs" attribute="breadcrumbs" />
<browser:page name="author" attribute="author" />
<browser:page name="modified" attribute="modified" />
<browser:page name="jumpto.html" attribute="jumpTo" />
<browser:page name="toc.html" attribute="toc" />
</browser:pages>
<browser:pages
for="zope.products.zwiki.interfaces.IWikiPage"
class=".wikipage.ViewWikiPage"
permission="zope.products.zwiki.ViewWikiPage">
<browser:page name="view.html" template="view_page.pt"
menu="zmi_views" title="View" />
</browser:pages>
<browser:pages
for="zope.products.zwiki.interfaces.IWikiPage"
class=".wikipage.EditWikiParents"
permission="zope.products.zwiki.ReparentWikiPage">
<browser:page name="parents.html" template="parents_page.pt"
menu="zmi_views" title="Parents" />
<browser:page name="setParents.html" attribute="setParents" />
</browser:pages>
<browser:pages
for="zope.products.zwiki.interfaces.IWikiPage"
class=".wikipage.WikiPageComment"
permission="zope.products.zwiki.CommentWikiPage">
<browser:page name="commentForm.html" template="comment_page.pt"
menu="zmi_views" title="Add Comment" />
<browser:page name="addComment.html" attribute="comment" />
</browser:pages>
<browser:pages
for="zope.products.zwiki.interfaces.IWikiPage"
class=".wikipage.MailSubscriptions"
permission="zope.products.zwiki.EditWikiPage">
<browser:page name="subscriptions.html" template="subscriptions.pt"
menu="zmi_views" title="Subscriptions" />
<browser:page name="changeSubscriptions.html" attribute="change" />
</browser:pages>
<browser:defaultView
name="view.html"
for="zope.products.zwiki.interfaces.IWikiPage"/>
<browser:icon
name="zmi_icon"
for="zope.products.zwiki.interfaces.IWikiPage"
file="wikipage_icon.gif"
/>
<!-- Make a special WikiPage menu -->
<browser:menu
id="wikipage_actions"
title="Menu for Wiki Page related actions."
/>
<browser:menuItems menu="wikipage_actions"
for="zope.products.zwiki.interfaces.IWikiPage">
<browser:menuItem title="View" action="@@view.html"/>
<browser:menuItem title="Comment" action="@@commentForm.html"/>
<browser:menuItem title="Edit" action="@@edit.html"/>
<browser:menuItem title="Parents" action="@@parents.html"/>
<browser:menuItem title="TOC" action="@@toc.html"/>
<browser:menuItem title="Subscriptions" action="@@subscriptions.html"/>
</browser:menuItems>
<browser:menuItems menu="wikipage_actions"
for="zope.products.zwiki.interfaces.IWiki">
<browser:menuItem title="Table of Contents" action="@@toc.html"/>
<browser:menuItem title="Search" action="@@search.html"/>
<browser:menuItem title="Subscriptions" action="@@subscriptions.html"/>
</browser:menuItems>
<!-- Register a browser-specific traverser -->
<browser:page
name="_traverse"
for="zope.products.zwiki.interfaces.IWikiPage"
class="zope.products.zwiki.traversal.WikiPageTraverser"
permission="zope.Public" />
<!-- Register WikiTextIndex as component -->
<browser:menuItem
menu="add_component"
for="zope.app.interfaces.container.IAdding"
action="zope.products.zwiki.index.WikiTextIndex"
title="Wiki Text Index"
description="A Wiki-specific full-text index"
/>
</configure>
=== Added File Zope3/src/zope/products/zwiki/browser/parents_page.pt ===
<html metal:use-macro="views/standard_macros/page">
<head>
<style metal:fill-slot="style_slot">
</style>
</head>
<body i18n:domain="wiki">
<div metal:fill-slot="body">
<form action="setParents.html" method="post">
<table cellspacing="0" cellpadding="2" border="0">
<tr>
<td i18n:translate="">Parents</td>
<td>
<select name="parents:list" multiple="">
<div tal:repeat="parent view/availableWikis" tal:omit-tag="">
<option tal:content="parent" selected=""
tal:condition="python: parent in view.parents()">
Wiki1
</option>
<option tal:content="parent"
tal:condition="python: parent not in view.parents()">
Wiki1
</option>
</div>
</select>
</td>
</tr>
</table>
<input type="submit" name="submit" value="Reparent"
i18n:attributes="value reparent-button" />
</form>
<h3 i18n:translate="">Branch</h3>
<p tal:replace="structure view/branch" />
</div>
</body>
</html>
=== Added File Zope3/src/zope/products/zwiki/browser/subscriptions.pt ===
<html metal:use-macro="views/standard_macros/page">
<head>
<style metal:fill-slot="style_slot">
</style>
</head>
<body>
<div metal:fill-slot="body">
<form action="changeSubscriptions.html" method="post"
i18n:domain="wiki">
<div class="row">
<div class="label" i18n:translate="">Current Subscriptions</div>
<div class="field">
<div tal:repeat="email view/subscriptions">
<input type="checkbox" name="remails:list"
value="" tal:attributes="value email">
<div tal:replace="email">zope3 at zope3.org</div>
</div>
<input type="submit" name="REMOVE" value="Remove"
i18n:attributes="value remove-button">
</div>
</div>
<div class="row">
<div class="label" i18n:translate="">
Enter new Users (separate by 'Return')
</div>
<div class="field">
<textarea name="emails" cols="40" rows="10"></textarea>
</div>
</div>
<div class="row">
<div class="controls">
<input type="submit" value="Refresh"
i18n:attributes="value refresh-button" />
<input type="submit" name="ADD" value="Add"
i18n:attributes="value add-button" />
</div>
</div>
</form>
</div>
</body>
</html>
=== Added File Zope3/src/zope/products/zwiki/browser/view_page.pt ===
<html metal:use-macro="views/standard_macros/page">
<head>
<style metal:fill-slot="style_slot">
</style>
</head>
<body>
<div metal:fill-slot="body">
<div tal:replace="structure view/render">
This is the rendered Wiki
</div>
</div>
</body>
</html>
=== Added File Zope3/src/zope/products/zwiki/browser/wiki.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Browser View Components for Wikis
$Id: wiki.py,v 1.1 2003/12/16 10:05:53 nmurthy Exp $
"""
from __future__ import generators
from datetime import datetime
from zope.component import \
getAdapter, getService, getServiceManager, createObject
from zope.proxy import removeAllProxies
from zope.app.interfaces.dublincore import ICMFDublinCore
from zope.app.services.servicenames import HubIds
from zope.app.traversing import getName, getPath
from zope.app.browser.container.adding import Adding
from zope.products.zwiki.interfaces import IWikiPageHierarchy
from zope.products.zwiki.index import WikiTextIndex
from zope.app.services.hub import Registration
class WikiAdding(Adding):
"""Custom adding view for NewsSite objects."""
menu_id = "add_wiki"
class AddWiki(object):
"""Add a Wiki"""
def createAndAdd(self, data):
content = super(AddWiki, self).createAndAdd(data)
if self.request.get('textindex'):
# Get the environment
sm = getServiceManager(content)
pkg = sm['default']
hub = pkg['HubIds-1']
# Create, subscribe and add a Registration object.
if 'WikiReg' not in pkg:
reg = Registration()
pkg['WikiReg'] = reg
reg.subscribe()
# Create, subscribe and add an WikiTextIndex object
if 'WikiTextIndex' not in pkg:
index = WikiTextIndex()
pkg['WikiTextIndex'] = index
index.subscribe(hub, True)
if self.request.get('frontpage'):
page = removeAllProxies(createObject(None, 'WikiPage'))
page.type = u'reStructured Text (reST)'
page.source = u'This is the FrontPage of the Wiki.'
dc = getAdapter(page, ICMFDublinCore)
dc.created = datetime.now()
dc.modified = datetime.now()
dc.creators = [u'wiki']
content['FrontPage'] = page
return content
class WikiSearch(object):
"""Search Wiki Pages"""
def __init__(self, context, request):
super(WikiSearch, self).__init__(context, request)
self.hub = getService(context, HubIds)
def query(self):
queryText = self.request.get('queryText', '')
sm = getServiceManager(self.context)
results, total = sm['default']['WikiTextIndex'].query(queryText)
result = {
'results': list(self._resultIterator(results)),
'total': total,
}
return result
def _resultIterator(self, results):
for hubid, score in results:
yield self._cookInfo(hubid, score)
def _cookInfo(self, hubid, score):
location = self.hub.getPath(hubid)
scoreLabel = "%.1f%%" % (100.0 * score)
result = {
'location': location,
'score': score,
'scoreLabel': scoreLabel,
}
try:
object = self.hub.getObject(hubid)
except NotFoundError:
pass
else:
result['name'] = getName(object)
return result
class TableOfContents:
"""Table of contents for a Wiki"""
def toc(self):
"""Generate a table of contents."""
children = []
for name, page in self.context.items():
hier = getAdapter(page, IWikiPageHierarchy)
if hier.getParents() == ():
children.append((page, hier.findChildren()))
return self._branchHTML(children)
def _branchHTML(self, children):
html = '<ul>\n'
for child, subs in children:
html += ' <li><a href="%s">%s</a></li>\n' %(getName(child),
getName(child))
if subs:
html += self._branchHTML(subs)
html += '</ul>\n'
return html
=== Added File Zope3/src/zope/products/zwiki/browser/wiki_add.pt ===
<html metal:use-macro="views/standard_macros/page">
<head>
<style metal:fill-slot="style_slot">
</style>
</head>
<body>
<div metal:fill-slot="body">
<p tal:define="status view/update"
tal:condition="status"
tal:content="status" />
<form action="." tal:attributes="action request/URL"
method="post" i18n:domain="wiki">
<div class="row">
<div class="field">
<h1><input type="checkbox" name="textindex:int" value="1"
checked=""/>
Create Wiki Text Index
</h1>
This is strongly recommended. Without the text index you cannot
search your objects properly. Of cource, you can always add
an index later as well.
</div>
</div>
<div class="row">
<div class="field">
<h1><input type="checkbox" name="frontpage:int" value="1"
checked=""/>
Create "Front Page" Wiki Page
</h1>
This is not absolutely necessary, but it is nice to have, since
it gets you started right away. Note that you have to have at
least one WikiPage for the 'wiki' skin to be useful.
</div>
</div>
<div class="row">
<div class="controls">
<input type="submit" value="Refresh"
i18n:attributes="value refresh-button" />
<input type="submit" name="UPDATE_SUBMIT" value="Submit"
i18n:attributes="value submit-button" />
</div>
</div>
</form>
</div>
</body>
</html>
=== Added File Zope3/src/zope/products/zwiki/browser/wiki_icon.gif ===
<Binary-ish file>
=== Added File Zope3/src/zope/products/zwiki/browser/wiki_search.pt ===
<html metal:use-macro="views/standard_macros/page">
<head>
<style metal:fill-slot="style_slot">
</style>
</head>
<body i18n:domain="wiki">
<div metal:fill-slot="body">
<h1 i18n:translate="">Wiki Search</h1>
<form action="search.html" method="get">
<input type="text" name="queryText" value=""
tal:attributes="value request/queryText|nothing" />
<input type="submit" value="Query" />
</form>
<div tal:condition="request/queryText|nothing" tal:omit-tag="">
<div tal:define="result view/query" tal:omit-tag="">
<div tal:condition="not:result/total">
No hits. Please try another query.
</div>
<div tal:condition="result/total">
<div tal:repeat="info result/results">
<a href="location"
tal:attributes="href info/name"
tal:content="info/name">FrontPage</a>;
(Score: <span tal:replace="info/scoreLabel" />)
</div>
</div>
</div>
</div>
</div>
</body>
</html>
=== Added File Zope3/src/zope/products/zwiki/browser/wiki_toc.pt ===
<html metal:use-macro="views/standard_macros/page">
<head>
<style metal:fill-slot="style_slot">
</style>
</head>
<body i18n:domain="wiki">
<div metal:fill-slot="body">
<h1 i18n:translate="">Wiki Table of Contents</h1>
<p tal:replace="structure view/toc">This is a table of contents.</p>
</div>
</body>
</html>
=== Added File Zope3/src/zope/products/zwiki/browser/wikipage.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Browser View Components for WikiPages
$Id: wikipage.py,v 1.1 2003/12/16 10:05:53 nmurthy Exp $
"""
import re
from urllib import quote, unquote
from datetime import datetime
from zope.app.browser.form.submit import Update
from zope.app.browser.form.vocabularywidget import VocabularyFieldEditWidget
from zope.app.browser.form.widget import ListWidget
from zope.app.form.widget import CustomWidget
from zope.app.interfaces.dublincore import ICMFDublinCore
from zope.app.traversing import getParent, getPath, getName
from zope.component import getAdapter, getView, getService, createObject
from zope.products.zwiki.interfaces import \
IWikiPageHierarchy, IMailSubscriptions
urlchars = r'[A-Za-z0-9/:@_%~#=&\.\-\?\+\$,]+'
urlendchar = r'[A-Za-z0-9/]'
url = r'["=]?((about|gopher|http|https|ftp|mailto|file):%s)' %urlchars
bracketedexpr = r'\[([^\n\]]+)\]'
protectedLine = r'(?m)^!(.*)$'
U = 'A-Z\xc0-\xdf'
L = 'a-z\xe0-\xff'
b = '(?<![%s0-9])' % (U+L)
wikiname1 = r'(?L)%s[%s]+[%s]+[%s][%s]*[0-9]*' % (b,U,L,U,U+L)
wikiname2 = r'(?L)%s[%s][%s]+[%s][%s]*[0-9]*' % (b,U,U,L,U+L)
wikilink = r'!?(%s|%s|%s|%s)' % (wikiname1,wikiname2,bracketedexpr,url)
localwikilink = r'!?(%s|%s|%s)' % (wikiname1, wikiname2, bracketedexpr)
interwikilink = r'!?((?P<local>%s):(?P<remote>%s))' % \
(localwikilink, urlchars+urlendchar)
class GenericWikiPageViews:
"""Some generic Wiki page views."""
def breadcrumbs(self):
"""Get the path of this page."""
hier = getAdapter(self.context, IWikiPageHierarchy)
path = hier.path()
html = []
for page in path:
html.append('<a href="../%s">%s</a>' %(getName(page),
getName(page)))
return ' / '.join(html)
def author(self):
"""Get user who last modified the Wiki Page."""
creators = getAdapter(self.context, ICMFDublinCore).creators
if not creators:
return 'unknown'
return creators[0]
def modified(self):
"""Get last modification date."""
date = getAdapter(self.context, ICMFDublinCore).modified
if date is None:
date = getAdapter(self.context, ICMFDublinCore).created
if date is None:
return ''
formatter = self.request.locale.getDateTimeFormatter('medium')
return formatter.format(date)
def jumpTo(self, jumpto):
"""Try to get quickly to another Wiki page"""
wiki = getParent(self.context)
if jumpto in wiki:
return self.request.response.redirect('../'+jumpto)
else:
return self.request.response.redirect('.')
def toc(self):
"""Simply forwards to the real TOC in the Wiki."""
return self.request.response.redirect('../@@toc.html')
class AddWikiPage(object):
type_widget = CustomWidget(VocabularyFieldEditWidget, size=1)
def nextURL(self):
return '../'+self.context.contentName
class EditWikiPage(object):
type_widget = CustomWidget(VocabularyFieldEditWidget, size=1)
def update(self):
status = super(EditWikiPage, self).update()
if Update in self.request:
self.request.response.redirect('./@@view.html')
return status
class ViewWikiPage:
"""A rendered View of the wiki page."""
def renderWikiLinks(self, source):
"""Add Wiki Links to the source"""
html = str(source)
html = re.sub(protectedLine, self._protectLine, html)
html = re.sub(interwikilink, self._interwikilinkReplace, html)
html = re.sub(wikilink, self._wikilinkReplace, html)
return html
def render(self):
"""Render the wiki page source."""
types = getService(self.context, "SourceTypeRegistry")
source = types.createObject(self.context.type,
self.context.source)
view = getView(source, '', self.request)
html = view.render(self.context)
html = self.renderWikiLinks(html)
return html
def _protectLine(self, match):
return re.sub(wikilink, r'!\1', match.group(1))
def _wikilinkReplace(self, match, allowed=0, state=None, text=''):
# tasty spaghetti regexps! better suggestions welcome ?
"""
Replace an occurrence of the wikilink regexp or one of the
special [] constructs with a suitable hyperlink
To be used as a re.sub repl function *and* get a proper value
for literal context, 'allowed', etc, enclose this function
with the value using 'thunk_substituter'.
"""
# In a literal?
if state is not None:
if within_literal(match.start(1), match.end(1)-1, state, text):
return match.group(1)
# matches beginning with ! should be left alone
if re.match('^!', match.group(0)):
return match.group(1)
m = morig = match.group(1)
wiki = getParent(self.context)
# if it's a bracketed expression,
if re.match(bracketedexpr, m):
# strip the enclosing []'s
m = re.sub(bracketedexpr, r'\1', m)
# extract a (non-url) path if there is one
pathmatch = re.match(r'(([^/]*/)+)([^/]+)', m)
if pathmatch:
path, id = pathmatch.group(1), pathmatch.group(3)
else:
path, id = '', m
# or if there was a path assume it's to some non-wiki
# object and skip the usual existence checking for
# simplicity. Could also attempt to navigate the path in
# zodb to learn more about the destination
if path:
return '<a href="%s%s">%s%s</a>' % (path, id, path, id)
# otherwise fall through to normal link processing
# if it's an ordinary url, link to it
if re.match(url,m):
# except, if preceded by " or = it should probably be left alone
if re.match('^["=]', m): # "
return m
else:
return '<a href="../%s">%s</a>' % (m, m)
# it might be a structured text footnote ?
elif re.search(r'(?si)<a name="%s"' % (m),text):
return '<a href="#%s">[%s]</a>' % (m,m)
# a wikiname - if a page (or something) of this name exists, link to
# it
elif m in wiki:
return '<a href="../%s">%s</a>' % (quote(m), m)
# otherwise, provide a "?" creation link
else:
return '%s<a href="../+/AddWikiPage=%s">?</a>' %(
morig, quote(m))
def _interwikilinkReplace(self, match, allowed=0, state=None, text=''):
"""Replace an occurrence of interwikilink with a suitable hyperlink.
To be used as a re.sub repl function *and* get a proper value
for literal context, 'allowed', etc.
"""
# matches beginning with ! should be left alone This is a bit naughty,
# but: since we know this text will likely be scanned with
# _wikilink_replace right after this pass, leave the ! in place for it
# to find. Otherwise the localname will get wiki-linked.
if re.match('^!', match.group(0)):
return match.group(0)
localname = match.group('local')
remotename = match.group('remote') # named groups come in handy here!
# NB localname could be [bracketed]
if re.match(bracketedexpr,localname):
localname = re.sub(bracketedexpr, r'\1', localname)
# look for a RemoteWikiURL definition
if hasattr(getParent(self.context), localname):
localpage = getattr(self.aq_parent,localname)
# local page found - search for "RemoteWikiUrl: url"
m = re.search(remotewikiurl, str(localpage))
if m is not None:
# NB: pages are stored html-quoted XXX eh ? they are ?
# something's not right somewhere.. I have lost my grip on
# this whole quoting issue.
remoteurl = html_unquote(m.group(1))
# we have a valid inter-wiki link
link = '<a href="%s%s">%s:%s</a>' % \
(remoteurl, remotename, localname, remotename)
# protect it from any later wiki-izing passes
return re.sub(wikilink, r'!\1', link)
# otherwise, leave alone
return match.group(0)
class EditWikiParents:
def parents(self):
hier = getAdapter(self.context, IWikiPageHierarchy)
return hier.parents
def availableWikis(self):
wiki = getParent(self.context)
return wiki.keys()
def setParents(self, parents):
hier = getAdapter(self.context, IWikiPageHierarchy)
hier.reparent(parents)
return self.request.response.redirect('./@@parents.html')
def _branchHTML(self, children):
html = '<ul>\n'
for child, subs in children:
html += ' <li><a href="../%s">%s</a></li>\n' %(getName(child),
getName(child))
if subs:
html += self._branchHTML(subs)
html += '</ul>\n'
return html
def branch(self):
hier = getAdapter(self.context, IWikiPageHierarchy)
children = hier.findChildren()
return self._branchHTML(children)
class WikiPageComment:
def comment(self, comment):
types = getService(self.context, "SourceTypeRegistry")
source = types.createObject(self.context.type, self.context.source)
comment = source.createComment(
comment,
self.context.getCommentCounter(),
self.request.user.getTitle(),
datetime.now().strftime('%m/%d/%Y %H:%M:%S'))
self.context.comment(comment)
return self.request.response.redirect('.')
def source(self):
return '> ' + self.context.source.replace('\n', '\n> ')
class MailSubscriptions:
def subscriptions(self):
return getAdapter(self.context, IMailSubscriptions).getSubscriptions()
def change(self):
if 'ADD' in self.request:
emails = self.request['emails'].split('\n')
getAdapter(self.context,
IMailSubscriptions).addSubscriptions(emails)
elif 'REMOVE' in self.request:
emails = self.request['remails']
print emails
if isinstance(emails, (str, unicode)):
emails = [emails]
getAdapter(self.context,
IMailSubscriptions).removeSubscriptions(emails)
self.request.response.redirect('.')
=== Added File Zope3/src/zope/products/zwiki/browser/wikipage_icon.gif ===
<Binary-ish file>
More information about the Zope3-Checkins
mailing list