Attachment 'explorer.diff'

Download

   1 --- explorer.py.orig	2009-03-05 20:24:38.000000000 +0800
   2 +++ explorer.py	2009-03-05 23:09:39.000000000 +0800
   3 @@ -21,7 +21,6 @@
   4      from MoinMoin.Page import Page
   5  
   6      name = 'explorer'
   7 -    
   8  
   9      # ========================================
  10      # Toolbars and UI text definition
  11 @@ -678,7 +677,8 @@
  12          """
  13          node.parents.append(self.name)
  14          self.subnodes[node.type].append(node.name)
  15 -        self.subnodes_size += node.size
  16 +        #self.subnodes_size += node.size
  17 +        self.subnodes_size = 0
  18  
  19  
  20      def remove_sub_node(self, node):
  21 @@ -686,7 +686,8 @@
  22          """
  23          node.parents.remove(self.name)
  24          self.subnodes[node.type].remove(node.name)
  25 -        self.subnodes_size -= node.size
  26 +        #self.subnodes_size -= node.size
  27 +        self.subnodes_size = 0
  28  
  29  
  30      def reset(self):
  31 @@ -716,6 +717,19 @@
  32      from MoinMoin.Page import Page
  33      
  34      release = '1.0.3'
  35 +    
  36 +    # filter_depth: How far should filter string be applied to the wiki_tree
  37 +    # by {FengMingyu, XieLuyun}@kingsoft.com
  38 +    # wiki_tree:
  39 +    #   level   nodes
  40 +    #   0       (root, but no display_name)
  41 +    #   1       first level pages/categories/attachments
  42 +    #   2       second level pages/categories/attachments
  43 +    #   .
  44 +    #   .
  45 +    #   .
  46 +    FILTER_DEPTH = 3
  47 +    filter_depth = 0
  48  
  49      # fake _ function to get gettext recognize those texts:
  50      _ = lambda x: x
  51 @@ -910,8 +924,9 @@
  52  
  53              pos = page_name.rfind('/')
  54              if pos > 0:  # page is subpage
  55 -                node.display_name = page_name[pos+1:]
  56 -                self.add_to_parent(node, page_name[:pos])
  57 +                pass
  58 +                #node.display_name = page_name[pos+1:]
  59 +                #self.add_to_parent(node, page_name[:pos])
  60              else:
  61                  # Add the page to the categories it belongs to
  62                  parent_categories = self.categories_formatter.getCategories(page)
  63 @@ -933,8 +948,13 @@
  64              node = WikiNode(self.request, node_name, self.wikiutil.url_quote('%s_node' % node_name, ''), is_attachment=is_attachment)
  65              self.wiki_tree[node_name] = node
  66              self.touched.add(node_name)
  67 -        return node
  68 +            
  69 +            pos = node_name.rfind('/')
  70 +            if pos > 0:
  71 +                node.display_name = node_name[pos+1:]
  72 +                self.add_to_parent(node, node_name[:pos])
  73  
  74 +        return node
  75  
  76      def add_to_parent(self, node, parent_name, parent = None):
  77          """ Add a node to a parent node
  78 @@ -976,9 +996,10 @@
  79              while node.attachments:
  80                  self.remove_page(node.attachments[0])
  81  
  82 -            while node.parents:
  83 -                self.remove_from_parent(node, node.parents[0])
  84 -
  85 +            if not node.pages:
  86 +                while node.parents:
  87 +                    self.remove_from_parent(node, node.parents[0])
  88 +            
  89              if node.categories or node.pages or (page_name in [self.root, self.orphaned, self.underlay]):
  90                  node.reset()
  91                  self.touched.add(page_name)
  92 @@ -1132,7 +1153,6 @@
  93              return ""
  94          return self.wiki_tree[self.page_name].categories_html
  95  
  96 -
  97      def tree_html(self):
  98          """ Returns wiki tree html code
  99          """
 100 @@ -1155,7 +1175,17 @@
 101          if self.cookie.has_key('expand_subtree'):
 102              self.expand_subtree = self.cookie['expand_subtree'].value
 103              self.cookie[self.expand_subtree] = 1
 104 -        return self.subtree_html(self.root)
 105 +        
 106 +        # Get user's node filter
 107 +        self.node_filter = u''
 108 +        if self.cookie.has_key('explorer_tree_node_filter'):
 109 +            self.node_filter = self.cookie['explorer_tree_node_filter'].value.lower()
 110 +        
 111 +        #print 'node_filter:' + self.node_filter
 112 +        self.filter_depth = 0
 113 +        html = self.subtree_html(self.root)
 114 +        filter_html = u'''<input id="filterinput" type="text" alt="Filter" size="15" name="filterinput" value="%s" onkeydown="if(event.keyCode == 13) { document.cookie = '%s' + '=' + this.value + '; path=/'; window.location.reload(true); }"/>''' % (self.node_filter, 'explorer_tree_node_filter')
 115 +        return filter_html + html
 116  
 117  
 118      def subtree_html(self, node_name, path=None, display_all=False):
 119 @@ -1169,6 +1199,18 @@
 120          @return: wiki tree html
 121          """
 122          node = self.wiki_tree[node_name]
 123 +        
 124 +        # filter node by user preference
 125 +        self.filter_depth += 1
 126 +        if self.filter_depth < self.FILTER_DEPTH:
 127 +            #print 'node_name:' + node_name
 128 +            #print 'node.display_name:' + node.display_name
 129 +            #print 'self.filter_depth:%d' % self.filter_depth
 130 +            #print not node.display_name.lower().startswith(self.node_filter)
 131 +            if node.display_name and not node.display_name.lower().startswith(self.node_filter):
 132 +                self.filter_depth -= 1
 133 +                return u''
 134 +
 135          if node.exists:
 136              if self.acl_caching:
 137                  if self.userid in node.may_read:
 138 @@ -1212,6 +1254,10 @@
 139                      if sub_node_name not in path:  # don't allow recursion
 140                          items.append(self.subtree_html(sub_node_name, path, display_all))
 141                  items.append(u'</ul>')
 142 +
 143 +        # fall back
 144 +        self.filter_depth -= 1
 145 +
 146          return u'\n'.join(items)
 147  
 148  

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2009-03-05 15:45:33, 5.2 KB) [[attachment:explorer.diff]]
  • [get | view] (2009-03-05 15:44:21, 17.5 KB) [[attachment:explorer_bug.png]]
  • [get | view] (2009-03-05 15:44:34, 19.9 KB) [[attachment:explorer_expected.png]]
  • [get | view] (2009-03-05 15:44:46, 3.2 KB) [[attachment:explorer_filter.png]]
  • [get | view] (2009-03-05 15:44:58, 3.1 KB) [[attachment:explorer_orig.png]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.