Index: trac/perm.py
===================================================================
--- trac/perm.py	(revision 4557)
+++ trac/perm.py	(working copy)
@@ -19,6 +19,7 @@
 """Management of permissions."""
 
 from trac.config import ExtensionOption, OrderedExtensionsOption
+from trac.resource import IResourceMapper
 from trac.core import *
 from trac.util.compat import set
 
@@ -51,6 +52,13 @@
         """
 
 
+class IPermissionProvider(Interface):
+    """Interface for components providing permissions for resource realms."""
+
+    def get_permissions(realm):
+        """Return an iterable of permissions for this realm."""
+
+
 class IPermissionStore(Interface):
     """Extension point interface for components that provide storage and
     management of permissions."""
@@ -179,6 +187,52 @@
         return groups
 
 
+class LegacyPermissions(Component):
+    """Provide new-style permissions to legacy permission consumers."""
+    implements(IPermissionRequestor)
+
+    resource_mappers = ExtensionPoint(IResourceMapper)
+    permission_providers = ExtensionPoint(IPermissionProvider)
+
+    def __init__(self):
+        self._permission_cache = None
+
+    # IPermissionRequestor methods
+
+    def get_permission_actions(self):
+        if not self._permission_cache:
+            from trac.util.compat import set
+
+            all_legacy_permissions = PermissionSystem(self.env).get_all_permissions()
+
+            all_permissions = []
+            mapping = {}
+            for mapper in self.resource_mappers:
+                for realm, _ in mapper.get_resource_factories():
+                    for provider in self.permission_providers:
+                        perms = provider.get_permissions(realm)
+                        mapping.setdefault(realm, []).extend(perms)
+            
+            for realm, permissions in mapping.iteritems():
+                out = []
+                prefix = realm.upper() + '_'
+                for perm in permissions:
+                    if isinstance(perm, basestring):
+                        out.append(prefix + perm)
+                    else:
+                        # TODO Might need to merge permissions if there are
+                        # multiples??? eg. (ADMIN, (VIEW, MODIFY)) and (ADMIN,
+                        # (DELETE, EXPLODE))... Not sure.
+                        meta, perms = perm
+                        out.append((prefix + meta, [prefix + p for p in perms]))
+                all_permissions.extend(out)
+
+            self._permission_cache = all_permissions
+
+        return self._permission_cache
+
+
+
 class DefaultPermissionPolicy(Component): 
     """Default permission policy using the IPermissionStore system.""" 
  
@@ -331,7 +385,7 @@
         self._perms = {}
 
     def __contains__(self, action):
-        if '_' not in action:
+        if '_' not in action and self.context.realm:
             action = self.context.realm.upper() + '_' + action
         if action in self._perms:
             return self._perms[action]
Index: trac/wiki/api.py
===================================================================
--- trac/wiki/api.py	(revision 4556)
+++ trac/wiki/api.py	(working copy)
@@ -32,6 +32,7 @@
 from trac.util import reversed
 from trac.util.html import html
 from trac.resource import IResourceMapper, Context
+from trac.perm import IPermissionProvider
 
 
 class IWikiChangeListener(Interface):
@@ -141,7 +142,8 @@
 class WikiSystem(Component):
     """Represents the wiki system."""
 
-    implements(IWikiChangeListener, IWikiSyntaxProvider, IResourceMapper)
+    implements(IWikiChangeListener, IWikiSyntaxProvider, IResourceMapper,
+               IPermissionProvider)
 
     change_listeners = ExtensionPoint(IWikiChangeListener)
     macro_providers = ExtensionPoint(IWikiMacroProvider)
@@ -256,6 +258,15 @@
         return self._link_resolvers
     link_resolvers = property(_get_link_resolvers)
 
+    # IPermissionProvider methods
+
+    def get_permissions(self, realm):
+        if realm == 'wiki':
+            actions = ['CREATE', 'DELETE', 'MODIFY', 'VIEW', 'ATTACH']
+            return actions + [('ADMIN', actions)]
+        return []
+
+
     # IWikiChangeListener methods
 
     def wiki_page_added(self, page):
Index: trac/wiki/web_ui.py
===================================================================
--- trac/wiki/web_ui.py	(revision 4556)
+++ trac/wiki/web_ui.py	(working copy)
@@ -24,7 +24,6 @@
 from trac.attachment import Attachment, AttachmentModule
 from trac.core import *
 from trac.mimeview.api import Mimeview, IContentConverter
-from trac.perm import IPermissionRequestor
 from trac.search import ISearchSource, search_to_sql, shorten_result
 from trac.timeline.api import ITimelineEventProvider, TimelineEvent
 from trac.util import get_reporter_id
@@ -45,7 +44,7 @@
 
 class WikiModule(Component):
 
-    implements(INavigationContributor, IPermissionRequestor, IRequestHandler,
+    implements(INavigationContributor, IRequestHandler,
                ITimelineEventProvider, ISearchSource, IContentConverter)
 
     page_manipulators = ExtensionPoint(IWikiPageManipulator)
@@ -66,19 +65,13 @@
         return 'wiki'
 
     def get_navigation_items(self, req):
-        if 'WIKI_VIEW' in req.perm:
+        if 'VIEW' in req.perm:
             yield ('mainnav', 'wiki',
                    html.A('Wiki', href=req.href.wiki(), accesskey=1))
             yield ('metanav', 'help',
                    html.A('Help/Guide', href=req.href.wiki('TracGuide'),
                           accesskey=6))
 
-    # IPermissionRequestor methods
-
-    def get_permission_actions(self):
-        actions = ['WIKI_CREATE', 'WIKI_DELETE', 'WIKI_MODIFY', 'WIKI_VIEW']
-        return actions + [('WIKI_ADMIN', actions)]
-
     # IRequestHandler methods
 
     def match_request(self, req):
@@ -134,7 +127,7 @@
         elif action == 'history':
             return self._render_history(context)
         else:
-            context.perm.require('WIKI_VIEW')
+            context.perm.require('VIEW')
 
             format = req.args.get('format')
             if format:
@@ -161,9 +154,9 @@
         db = context.db
 
         if page.readonly:
-            context.perm.require('WIKI_ADMIN')
+            context.perm.require('ADMIN')
         else:
-            context.perm.require('WIKI_DELETE')
+            context.perm.require('DELETE')
 
         if req.args.has_key('cancel'):
             req.redirect(req.href.wiki(page.name))
@@ -191,16 +184,16 @@
         db = context.db
 
         if page.readonly:
-            context.perm.require('WIKI_ADMIN')
+            context.perm.require('ADMIN')
         elif not page.exists:
-            context.perm.require('WIKI_CREATE')
+            context.perm.require('CREATE')
         else:
-            context.perm.require('WIKI_MODIFY')
+            context.perm.require('MODIFY')
 
         page.text = req.args.get('text')
-        if 'WIKI_ADMIN' in context.perm:
+        if 'ADMIN' in context.perm:
             # Modify the read-only flag if it has been changed and the user is
-            # WIKI_ADMIN
+            # ADMIN
             page.readonly = int(req.args.has_key('readonly'))
 
         # Give the manipulators a pass at post-processing the page
@@ -222,9 +215,9 @@
         db = context.db
 
         if page.readonly:
-            context.perm.require('WIKI_ADMIN')
+            context.perm.require('ADMIN')
         else:
-            context.perm.require('WIKI_DELETE')
+            context.perm.require('DELETE')
 
         version = None
         if 'delete_version' in req.args:
@@ -248,7 +241,7 @@
         req = context.req
         db = context.db
 
-        context.perm.require('WIKI_VIEW')
+        context.perm.require('VIEW')
 
         data = self.page_data(context, 'diff')
 
@@ -345,7 +338,7 @@
         return 'wiki_diff.html', data, None
 
     def _render_editor(self, context, action='edit'):
-        context.perm.require('WIKI_MODIFY')
+        context.perm.require('MODIFY')
 
         page = context.resource
         req = context.req
@@ -387,7 +380,7 @@
         This information is used to present a changelog/history for a given
         page.
         """
-        context.perm.require('WIKI_VIEW')
+        context.perm.require('VIEW')
 
         page = context.resource
         req = context.req
@@ -430,7 +423,7 @@
             data['title'] = ''
 
         if not page.exists:
-            if 'WIKI_CREATE' not in context.perm:
+            if 'CREATE' not in context.perm:
                 raise HTTPNotFound('Page %s not found', page.name)
 
         latest_page = WikiPage(self.env, page.name)
@@ -454,7 +447,7 @@
         # Show attachments
         attachments = list(Attachment.select(self.env, 'wiki', page.name))
         attach_href = None
-        if 'WIKI_MODIFY' in context.perm:
+        if 'MODIFY' in context.perm:
             attach_href = req.href.attachment('wiki', page.name)
 
         prefix = self.PAGE_TEMPLATES_PREFIX
@@ -486,7 +479,7 @@
     # ITimelineEventProvider methods
 
     def get_timeline_filters(self, req):
-        if 'WIKI_VIEW' in req.perm:
+        if 'VIEW' in req.perm:
             yield ('wiki', 'Wiki changes')
 
     def get_timeline_events(self, req, start, stop, filters):
@@ -522,7 +515,7 @@
     # ISearchSource methods
 
     def get_search_filters(self, req):
-        if 'WIKI_VIEW' in req.perm:
+        if 'VIEW' in req.perm:
             yield ('wiki', 'Wiki')
 
     def get_search_results(self, req, terms, filters):
