Edgewall Software

Ticket #8453: hide_wiki.diff

File hide_wiki.diff, 7.0 KB (added by shookie@…, 3 years ago)

implementation diff

  • trac/env.py

     
    174174 
    175175         (since 0.10.5)""") 
    176176 
     177    wiki_prefix = Option('wiki', 'uri_prefix', 'wiki', 
     178                         """Defines the uri prefix that gets the wiki handler""") 
     179    wiki_start =  Option('wiki', 'wiki_start', 'WikiStart', 
     180                         """Defines the wiki start page name""") 
     181 
    177182    def __init__(self, path, create=False, options=[]): 
    178183        """Initialize the Trac environment. 
    179184         
  • trac/templates/theme.html

     
    3333    ${navigation('mainnav')} 
    3434 
    3535    <div id="main"> 
    36       <div id="ctxtnav" class="nav"> 
     36      <div py:if="(not ctxtnav.hide_ctxtnav_from_anonymous) or authname != 'anonymous'" id="ctxtnav" class="nav"> 
    3737        <h2>Context Navigation</h2> 
    3838          <ul py:if="chrome.ctxtnav"> 
    3939              <li py:for="i, elm in enumerate(chrome.ctxtnav)" 
  • trac/wiki/admin.py

     
    198198        db = self.env.get_db_cnx() 
    199199        self.load_pages(pkg_resources.resource_filename('trac.wiki',  
    200200                                                        'default-pages'), 
    201                         db, ignore=['WikiStart', 'checkwiki.py'], 
     201                        db, ignore=[self.env.wiki_start, 'checkwiki.py'], 
    202202                        create_only=['InterMapTxt']) 
    203203        db.commit() 
  • trac/wiki/api.py

     
    265265            pagename, version = pagename.split('@', 1) 
    266266        if version and query: 
    267267            query = '&' + query[1:] 
    268         pagename = pagename.rstrip('/') or 'WikiStart' 
     268        pagename = pagename.rstrip('/') or self.env.wiki_start 
    269269        if formatter.resource and formatter.resource.realm == 'wiki' \ 
    270270                              and not pagename.startswith('/'): 
    271271            prefix = formatter.resource.id 
  • trac/wiki/web_ui.py

     
    6565    PAGE_TEMPLATES_PREFIX = 'PageTemplates/' 
    6666    DEFAULT_PAGE_TEMPLATE = 'DefaultPage' 
    6767 
     68    def __init__(self): 
     69        """Init instance variables""" 
     70        self.match_request_regex = re.compile(r'/' + self.env.wiki_prefix + r'(?:/(.+))?$') 
     71 
     72 
    6873    # IContentConverter methods 
    6974    def get_supported_conversions(self): 
    7075        yield ('txt', _('Plain Text'), 'txt', 'text/x-trac-wiki', 'text/plain', 
     
    99104 
    100105    # IRequestHandler methods 
    101106 
     107     
     108 
    102109    def match_request(self, req): 
    103         match = re.match(r'/wiki(?:/(.+))?$', req.path_info) 
     110        match = self.match_request_regex.match(req.path_info) 
    104111        if match: 
    105112            if match.group(1): 
    106113                req.args['page'] = match.group(1) 
     
    108115 
    109116    def process_request(self, req): 
    110117        action = req.args.get('action', 'view') 
    111         pagename = req.args.get('page', 'WikiStart') 
     118        pagename = req.args.get('page', self.env.wiki_start) 
    112119        version = req.args.get('version') 
    113120        old_version = req.args.get('old_version') 
    114121 
     
    492499                         conversion[3]) 
    493500 
    494501        data = self._page_data(req, page) 
    495         if page.name == 'WikiStart': 
     502        if page.name == self.env.wiki_start: 
    496503            data['title'] = '' 
    497504 
    498505        if not page.exists: 
     
    568575     
    569576    def _wiki_ctxtnav(self, req, page): 
    570577        """Add the normal wiki ctxtnav entries.""" 
    571         add_ctxtnav(req, _('Start Page'), req.href.wiki('WikiStart')) 
     578        add_ctxtnav(req, _('Start Page'), req.href.wiki(self.env.wiki_start)) 
    572579        add_ctxtnav(req, _('Index'), req.href.wiki('TitleIndex')) 
    573580        if page.exists: 
    574581            add_ctxtnav(req, _('History'), req.href.wiki(page.name,  
  • trac/web/api.py

     
    160160    This class provides a convenience API over WSGI. 
    161161    """ 
    162162 
    163     def __init__(self, environ, start_response): 
     163    def __init__(self, environ, start_response, wiki_prefix='wiki'): 
    164164        """Create the request wrapper. 
    165165         
    166166        @param environ: The WSGI environment dict 
     
    189189        self.base_url = self.environ.get('trac.base_url') 
    190190        if not self.base_url: 
    191191            self.base_url = self._reconstruct_url() 
    192         self.href = Href(self.base_path) 
    193         self.abs_href = Href(self.base_url) 
     192        self.href = Href(self.base_path, wiki_prefix) 
     193        self.abs_href = Href(self.base_url, wiki_prefix) 
    194194 
    195195    def __getattr__(self, name): 
    196196        """Performs lazy attribute lookup by delegating to the functions in the 
  • trac/web/chrome.py

     
    322322        """Show IP addresses for resource edits (e.g. wiki). 
    323323        (''since 0.11.3'').""") 
    324324 
     325    hide_ctxtnav_from_anonymous = BoolOption('ctxtnav', 'hide_ctxtnav_from_anonymous', 'false', 
     326        """Hide the context navigation bar from anonymous visitors.""") 
     327 
    325328    templates = None 
    326329 
    327330    # A dictionary of default context data for templates 
     
    654657        d['chrome'] = { 
    655658            'footer': Markup(self.env.project_footer) 
    656659        } 
     660        d['ctxtnav'] = { 'hide_ctxtnav_from_anonymous': self.hide_ctxtnav_from_anonymous } 
     661 
    657662        if req: 
    658663            d['chrome'].update(req.chrome) 
    659664        else: 
  • trac/web/href.py

     
    115115    '/trac/browser/trunk/README.txt?format=txt' 
    116116    """ 
    117117 
    118     def __init__(self, base): 
     118    def __init__(self, base, wiki_prefix='wiki'): 
     119        self.wiki_prefix = wiki_prefix 
    119120        self.base = base 
    120121        self._derived = {} 
    121122 
     
    133134                params.append((name, value)) 
    134135 
    135136        if args: 
     137            if args[0] == 'wiki': 
     138                args = (self.wiki_prefix,) + (args[1:]) 
    136139            lastp = args[-1] 
    137140            if lastp and type(lastp) is dict: 
    138141                for k,v in lastp.items(): 
  • trac/web/main.py

     
    431431    except Exception, e: 
    432432        env_error = e 
    433433 
    434     req = Request(environ, start_response) 
     434    req = Request(environ, start_response, env.wiki_prefix) 
    435435    try: 
    436436        return _dispatch_request(req, env, env_error) 
    437437    finally: