Differences between revisions 1 and 2
Revision 1 as of 2007-06-11 05:27:25
Size: 1805
Editor: ZoomQuiet
Comment: 进一步优化LikePages
Revision 2 as of 2009-12-25 07:17:05
Size: 1807
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
 * 根据[http://my.opera.com/zhangyunfeng/blog/show.dml/411044 修改Moin不查找带有日期的页面] 修订过Moin  * 根据[[http://my.opera.com/zhangyunfeng/blog/show.dml/411044|修改Moin不查找带有日期的页面]] 修订过Moin

进一步优化LikePages

  • 根据修改Moin不查找带有日期的页面 修订过Moin

  • 但是发现有不合意的:
    • 此优化是根据待创建页面的名称来决定是否进行搜索匹配的
    • 实际上,还有其它虽然以此页面开头,但是非日历页面的情况,也被一并忽略了
  • 改进! 以最新的Moin1.5.5.8 版本为例修订...

    # -*- coding: utf-8 -*-
    """
        MoinMoin - Create list of LikePages
    
        @copyright: 2004 by Johannes Berg <[email protected]>
        @license: GNU GPL, see COPYING for details.
    """
    
    Dependencies = ['namespace']
    
    from MoinMoin.action import LikePages
    import re
    datere = re.compile(r'\d{4}-\d{2}-\d{2}')
    
    def execute(macro, args):
        request = macro.request
        # we don't want to spend much CPU for spiders requesting nonexisting pages
        if not request.isSpiderAgent:
            pagename = macro.formatter.page.page_name              
    
            # Get matches
            start, end, matches = LikePages.findMatches(pagename, request)
            #return "%s<br/>%s<br/>%s<br/>" % (start, end, matches)
            
            tmpmatch = {}
            for p in matches.keys():
                # 检查匹配页面是否带有日期形式字符串
                if re.search(datere, p):
                    pass
                else:
                    tmpmatch[p]=matches[p]
                    #return 'Calendar Page will not be searched.'  
            matches = tmpmatch
            
            # Render matches
            if matches and not isinstance(matches, (str, unicode)):
                return request.redirectedOutput(LikePages.showMatches, pagename, request, start, end, matches, False)
            return args
    
        return ''

woodpecker-log/2007-06-11 (last edited 2009-12-25 07:17:05 by localhost)