[Zope3-checkins] CVS: zopeproducts/zwiki/browser - wiki_add.pt:1.1 wiki_search.pt:1.1 configure.zcml:1.3 wiki.py:1.3

Stephan Richter srichter@cbu.edu
Thu, 10 Apr 2003 07:32:10 -0400


Update of /cvs-repository/zopeproducts/zwiki/browser
In directory cvs.zope.org:/tmp/cvs-serv2884/browser

Modified Files:
	configure.zcml wiki.py 
Added Files:
	wiki_add.pt wiki_search.pt 
Log Message:
- Added Search Functionality using a custom TextIndex called WikiTextIndex.

- Added more complex Wiki Creator. It asks you whether you want to install
  the search capabilities automatically and whether you want a FrontPage
  to start with.

There is still an open issue that events do not seem to arrive, and 
therefore I have to refresh the index manually; this really sucks, since I
do not even have to start with the E-mail subscriptions then.


=== Added File zopeproducts/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 zopeproducts/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>


=== zopeproducts/zwiki/browser/configure.zcml 1.2 => 1.3 ===
--- zopeproducts/zwiki/browser/configure.zcml:1.2	Thu Apr 10 02:28:14 2003
+++ zopeproducts/zwiki/browser/configure.zcml	Thu Apr 10 07:31:39 2003
@@ -22,25 +22,36 @@
       <browser:page name="action.html" attribute="action" />
   </browser:view>
 
+  <browser:addform
+      label="Add Wiki"
+      name="AddWiki"
+      schema="zopeproducts.zwiki.interfaces.IWiki"
+      content_factory="zopeproducts.zwiki.wiki.Wiki"
+      permission="zope.ManageContent"
+      class=".wiki.AddWiki"
+      template="wiki_add.pt"
+      menu="add_content" title="Wiki"/>
+
   <browser:page
       name="toc.html"
       for="zopeproducts.zwiki.interfaces.IWiki"
       class=".wiki.TableOfContents"
       template="wiki_toc.pt"
       permission="zopeproducts.zwiki.ViewWikiPage"
-      menu="zmi_views"
-      title="TOC"/>
+      menu="zmi_views" title="TOC"/>
+
+  <browser:page
+      name="search.html" 
+      for="zopeproducts.zwiki.interfaces.IWiki"
+      class=".wiki.WikiSearch"
+      template="wiki_search.pt"
+      permission="zopeproducts.zwiki.ViewWikiPage"
+      menu="zmi_views" title="Search"/>
 
   <browser:defaultView
       name="toc.html"
       for="zopeproducts.zwiki.interfaces.IWiki"/>
 
-  <browser:menuItem menu="add_content"
-      for="zope.app.interfaces.container.IAdding"
-      title="Wiki"
-      action="Wiki"
-      description="A simple Wiki."/>
-
   <browser:icon
       name="zmi_icon"
       for="zopeproducts.zwiki.interfaces.IWiki"
@@ -135,7 +146,8 @@
 
   <browser:menuItems menu="wikipage_actions" 
       for="zopeproducts.zwiki.interfaces.IWiki">
-    <browser:menuItem title="TOC" action="@@toc.html"/>
+    <browser:menuItem title="Table of Contents" action="@@toc.html"/>
+    <browser:menuItem title="Search" action="@@search.html"/>
   </browser:menuItems>
 
   <!-- Register a browser-specific traverser --> 
@@ -145,5 +157,15 @@
       for="zopeproducts.zwiki.interfaces.IWikiPage"
       class="zopeproducts.zwiki.traversal.WikiPageTraverser" 
       permission="zope.Public" />
+
+  <!-- Register WikiTextIndex as component -->
+
+  <browser:menuItem
+    menu="add_component"
+    for="zope.app.interfaces.container.IAdding"
+    action="zopeproducts.zwiki.index.WikiTextIndex"
+    title="Wiki Text Index"
+    description="A Wiki-specific full-text index"
+    />
 
 </zopeConfigure>


=== zopeproducts/zwiki/browser/wiki.py 1.2 => 1.3 ===
--- zopeproducts/zwiki/browser/wiki.py:1.2	Thu Apr 10 02:28:14 2003
+++ zopeproducts/zwiki/browser/wiki.py	Thu Apr 10 07:31:39 2003
@@ -15,17 +15,89 @@
 
 $Id$
 """
-from zope.component import getAdapter
+from zope.component import \
+     getAdapter, getService, getServiceManager, createObject
 from zope.proxy.context import ContextWrapper
-from zope.app.traversing import objectName
+from zope.proxy.introspection import removeAllProxies
+from zope.app.services.servicenames import HubIds
+from zope.app.traversing import objectName, getPath
 from zope.app.browser.container.adding import Adding
 
 from zopeproducts.zwiki.interfaces import IWikiPageHierarchy
-
+from zopeproducts.zwiki.index import WikiTextIndex
+from zope.app.index.subscribers 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 = ContextWrapper(sm['default'], sm, name='default')
+            hub = ContextWrapper(pkg['HubIds-1'], sm, name='HubIds-1')
+            # Create, subscribe and add a Registration object.
+            reg = Registration()
+            pkg.setObject('WikiReg', reg)
+            reg = ContextWrapper(reg, pkg, name='WikiReg')
+            reg.subscribe()
+            # Create, subscribe and add an WikiTextIndex object
+            index = WikiTextIndex()
+            pkg.setObject('WikiTextIndex', index)
+            index = ContextWrapper(index, pkg, name='WikiTextIndex')
+            index.subscribe(hub, True)
+
+        if self.request.get('frontpage'):
+            page = removeAllProxies(createObject(None, 'WikiPage'))
+            page.type = u'Structured Text (STX)'
+            page.source = u'This is the FrontPage of the Wiki.'
+            content.setObject('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'] = objectName(object)
+        return result
 
 
 class TableOfContents: