Description

You might say that this is the policy, however I think seperating categories by "," is quite natural and if I remember correctly it worked with non Xapian setup (not sure though).

Steps to reproduce

Use the example markup below and click on the categories to find that the page is not listed in the category.

Example

  1. Without leading ---- (not sure that would be considered bug or feature)

     CategoryHomepage
  2. Multiple categories seperated by "," only recognizes the last category
     ----
     CategoryHomepage, CategoryDiscussion

Details

MoinMoin Version

1.7.2

OS and Version

Linus SLE10 / x64

Python Version

2.4

Server Setup

twisted on linux

Server Details

Xapian on, version 1.04

Workaround

Categories must be preceded by ---- and seperated by " " rather than ","

If somebody is in the same situation the following script might be helpfull (use at your own risk). It loops over all pages that have "false" category entries as described above. It helped me alot, just updated 306 pages :-)

   1 #!/usr/bin/env python
   2 
   3 import sys
   4 import re
   5 import time
   6 
   7 # wiki config directory
   8 if 'win' in sys.platform:
   9     WIKICONF = 'd:/caewiki'
  10     SUPERUSER = u'FranzZieher'
  11 else:
  12     WIKICONF = '/s330/moin/caewiki'
  13     SUPERUSER = u'zieherf'
  14 
  15 sys.path.append(WIKICONF)
  16 
  17 from MoinMoin import user
  18 from MoinMoin import config
  19 from MoinMoin.request import request_cli
  20 
  21 _REQUEST = None
  22 
  23 def getRequest():
  24     """Create request object
  25     """
  26     global _REQUEST
  27     if _REQUEST:
  28         return _REQUEST
  29     request = request_cli.Request()
  30     u = user.User(request,None,SUPERUSER)
  31     request.user = user.User(request,u.id)
  32     _REQUEST = request
  33     return request
  34 
  35 getRequest()
  36 print _REQUEST.user.name
  37 
  38 from MoinMoin.PageEditor import PageEditor
  39 from MoinMoin.Page import Page
  40 from MoinMoin.search import searchPages
  41 
  42 class UpdatePageCategory(object):
  43 
  44     def __init__(self,request,page):
  45         self.request = request
  46         self.page = page
  47         self.text = None   # new text (one string)
  48         self.modLines = {} # modified lines
  49         self.modLineNo = [] # modified line numbers
  50 
  51     def modText(self):
  52         """Must create new page text, self.text!
  53         """
  54         raise NotImplementedError
  55 
  56     def saveText(self):
  57         """Save text of modified page
  58         """
  59         page = PageEditor(self.request,self.page.page_name)
  60         ppath,rev,flag = page.get_rev()
  61 
  62         if not self.text:
  63             print "Page content has not been updated yet, aborting!"
  64             return
  65 
  66         print "----------------------------------------------"
  67         print "Updating PAGE %s" % self.page.page_name
  68         print "----------------------------------------------"
  69         if self.modLines:
  70             try:
  71                 for lno in self.modLineNo:
  72                     print "%d:%s" % (lno,self.modLines[lno])
  73                 msg = page.saveText(self.text,rev)
  74                 print msg
  75                 print "Revision %d saved!" % (rev)
  76             except page.Unchanged:
  77                 print "Page content did not change, not saved!"
  78 
  79         else:
  80             print "Non modifications found, page not modified"
  81         print ""
  82 
  83 class ModPage(UpdatePageCategory):
  84 
  85     def modText(self,pat=r"^( *[.]* *)(Category[A-Za-z]+.*$)",insertRule=False):
  86         """No numbers allowed by default in the search pattern
  87         Remove all characters before the first Category entry.
  88         """
  89         rec = re.compile(pat)
  90         lines = self.page.getlines()
  91         for lno,l in enumerate(self.page.getlines()):
  92             m = rec.match(l)
  93             if m:
  94                 lines[lno] = ' '.join([x.strip() for x in m.groups()[1].split(',')])
  95                 if insertRule:
  96                     lines[lno] = '----\n' + lines[lno]
  97                 self.modLineNo.append(lno)
  98                 self.modLines[lno] = lines[lno]
  99 
 100         self.text = '\n'.join(lines)
 101             
 102 # -------------------------------------------------------------------
 103 
 104 def main():
 105 
 106     request = getRequest()
 107 
 108     # single category pages first
 109     res1 = searchPages(request,'r:"\n----\n+ *[. ]*Category[A-Z][A-Za-z]+ *\n" m:text',regex=True)
 110     res2 = searchPages(request,'r:"\n+ *[. ]*Category[A-Z][A-Za-z]+ *\n" m:text',regex=True)
 111 
 112     pn1 = [p.page_name for p in res1.hits]
 113     pn2 = [p.page_name for p in res2.hits]
 114 
 115     # all pagenames that need an '----'
 116     pn3 = list(set(pn2) - set(pn1))
 117    
 118     print "=========================================="
 119     print " Single page categories without ----"
 120     print "=========================================="
 121     print "Number of pages to upgrade: %d" % len(pn3)
 122     print ""
 123     for pn in pn3:
 124         page = Page(request,pn)
 125         modPage = ModPage(request,page)
 126         modPage.modText(insertRule=True)
 127         modPage.saveText()
 128         time.sleep(1)
 129 
 130     # multiple categories
 131     # single category pages first
 132     res1 = searchPages(request,'r:"\n----\n+ *[. ]*Category[A-Z][A-Za-z]+, .*\n" m:text',regex=True)
 133     res2 = searchPages(request,'r:"\n+ *[. ]*Category[A-Z][A-Za-z]+, .*\n" m:text',regex=True)
 134 
 135     pn1 = [p.page_name for p in res1.hits]
 136     pn2 = [p.page_name for p in res2.hits]
 137 
 138     # all pagenames that need an '----'
 139     pn3 = list(set(pn2) - set(pn1))
 140     
 141     print "========================================================="
 142     print " Multiple page categories seperated by , and without ----"
 143     print "========================================================="
 144     print "Number of pages to upgrade: %d" % len(pn3)
 145     print ""
 146     for pn in pn3:
 147         page = Page(request,pn)
 148         modPage = ModPage(request,page)
 149         modPage.modText(insertRule=True)
 150         modPage.saveText()
 151         time.sleep(1)
 152 
 153     print "========================================================="
 154     print " Multiple page categories seperated by , and with ----"
 155     print "========================================================="
 156     print "Number of pages to upgrade: %d" % len(pn1)
 157     print ""
 158     for pn in pn1:
 159         page = Page(request,pn)
 160         modPage = ModPage(request,page)
 161         modPage.modText(insertRule=False)
 162         modPage.saveText()
 163         time.sleep(1)
 164 
 165 if __name__ == '__main__':
 166     main()

Discussion

The standard search engine (without Xapian) tolerated "," and also not having ---- preceding the category entries (as far as I remember). So, if that is intented -- no big deal.

Plan


CategoryMoinMoinNoBug

MoinMoin: MoinMoinBugs/CategoriesNotRecognized (last edited 2008-12-29 23:53:33 by FranzZieher)