changeset 2199:2560c2182307

macro.Action: link only if action is valid
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sun, 06 May 2007 17:52:08 +0200
parents c3e140e98158
children e60ae8a23a49
files MoinMoin/macro/Action.py
diffstat 1 files changed, 21 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/macro/Action.py	Sat May 05 22:18:58 2007 +0200
+++ b/MoinMoin/macro/Action.py	Sun May 06 17:52:08 2007 +0200
@@ -22,7 +22,7 @@
 
 
 class ActionLink:
-    """ ActionLink - link to page with action """
+    """ ActionLink - link to page with valid action """
 
     arguments = ['action', 'text']
 
@@ -30,6 +30,17 @@
         self.macro = macro
         self.request = macro.request
         self.args = self.getArgs(args)
+        
+    def getValidActions(self):  
+        """ lists all valid actions """
+        from MoinMoin import action
+        actions = [x for x in action.modules
+                   if not x in self.macro.request.cfg.actions_excluded]
+        loc_actions = [x for x in wikiutil.wikiPlugins('action', self.macro.cfg)
+                       if not x in self.macro.request.cfg.actions_excluded]
+        if loc_actions:
+            actions.append(loc_actions)
+        return actions
 
     def getArgs(self, argstr):
         """ Temporary function until Oliver Graf args parser is finished
@@ -59,16 +70,16 @@
         # Use translated text or action name
         text = self.args.get('text', action)
         text = _(text, formatted=False)
-
-        # Escape user input
-        action = wikiutil.escape(action, 1)
         text = wikiutil.escape(text, 1)
-
-        # Create link
-        page = self.macro.formatter.page
-        link = page.link_to(self.request, text, querystr='action=%s' % action)
-        return link
-
+        if action in self.getValidActions():
+            # Escape user input
+            action = wikiutil.escape(action, 1)
+            # Create link
+            page = self.macro.formatter.page
+            link = page.link_to(self.request, text, querystr='action=%s' % action)
+            return link
+        else:
+            return text
 
 def execute(macro, args):
     """ Temporary glue code to use with moin current macro system """