[Moin-devel] CVS: MoinMoin/action LikePages.py,1.15,1.16
J?rgen Hermann
jhermann at users.sourceforge.net
Thu Jun 20 15:37:04 EDT 2002
Update of /cvsroot/moin/MoinMoin/action
In directory usw-pr-cvs1:/tmp/cvs-serv8499/MoinMoin/action
Modified Files:
LikePages.py
Log Message:
LikePages shows similar pages (using difflib.get_close_matches);
Page creation shows LikePages that already exist
Index: LikePages.py
===================================================================
RCS file: /cvsroot/moin/MoinMoin/action/LikePages.py,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -r1.15 -r1.16
*** LikePages.py 20 Jun 2002 21:16:54 -0000 1.15
--- LikePages.py 20 Jun 2002 22:36:55 -0000 1.16
***************
*** 13,17 ****
"""
! import re
from MoinMoin import config, user, util, wikiutil, webapi
from MoinMoin.Page import Page
--- 13,17 ----
"""
! import re, cgi
from MoinMoin import config, user, util, wikiutil, webapi
from MoinMoin.Page import Page
***************
*** 52,79 ****
s_re=re.compile('([%s][%s]+)' % (config.upperletters, config.lowerletters)),
e_re=re.compile('([%s][%s]+)$' % (config.upperletters, config.lowerletters))):
# figure the start and end words
s_match = s_re.match(pagename)
e_match = e_re.search(pagename)
! if not (s_match and e_match):
return None, None, _('<b>You cannot use LikePages on an extended pagename!</b>')
! # extract the words
! start = s_match.group(1)
! end = e_match.group(1)
! subpage = pagename + '/'
!
! # find any matching pages
matches = {}
! for anypage in wikiutil.getPageList(config.text_dir):
! # skip current page
! if anypage == pagename:
! continue
! if anypage.startswith(subpage):
! matches[anypage] = 4
! else:
! if anypage.startswith(start):
! matches[anypage] = 1
! if anypage.endswith(end):
! matches[anypage] = matches.get(anypage, 0) + 2
return start, end, matches
--- 52,99 ----
s_re=re.compile('([%s][%s]+)' % (config.upperletters, config.lowerletters)),
e_re=re.compile('([%s][%s]+)$' % (config.upperletters, config.lowerletters))):
+ from MoinMoin.support import difflib
+
+ # get page lists
+ pagelist = wikiutil.getPageList(config.text_dir)
+ lowerpages = [p.lower() for p in pagelist]
+ similar = difflib.get_close_matches(pagename.lower(), lowerpages, 10)
+
# figure the start and end words
s_match = s_re.match(pagename)
e_match = e_re.search(pagename)
! if not (s_match and e_match or similar):
return None, None, _('<b>You cannot use LikePages on an extended pagename!</b>')
! start = None
! end = None
matches = {}
! if s_match and e_match:
! # extract the words
! start = s_match.group(1)
! end = e_match.group(1)
! subpage = pagename + '/'
!
! # find any matching pages
! for anypage in pagelist:
! # skip current page
! if anypage == pagename:
! continue
! if anypage.startswith(subpage):
! matches[anypage] = 4
! else:
! if anypage.startswith(start):
! matches[anypage] = 1
! if anypage.endswith(end):
! matches[anypage] = matches.get(anypage, 0) + 2
!
! if similar:
! pagemap = {}
! for anypage in pagelist:
! pagemap[anypage.lower()] = anypage
!
! for anypage in similar:
! if anypage == pagename:
! continue
! matches[pagemap[anypage]] = 8
return start, end, matches
***************
*** 83,86 ****
--- 103,107 ----
keys = matches.keys()
keys.sort()
+ _showMatchGroup(matches, keys, 8, pagename)
_showMatchGroup(matches, keys, 4, "%s/..." % pagename)
_showMatchGroup(matches, keys, 3, "%s...%s" % (start, end))
***************
*** 96,100 ****
'matchcount': matchcount,
'matches': (_(' match'), _(' matches'))[matchcount != 1],
! 'title': title} + '</b>'
print "<ul>"
for key in keys:
--- 117,121 ----
'matchcount': matchcount,
'matches': (_(' match'), _(' matches'))[matchcount != 1],
! 'title': cgi.escape(title)} + '</b>'
print "<ul>"
for key in keys:
More information about the Moin-devel
mailing list