Edgewall Software

Ticket #962: wiki_page_templates-r3886.patch

File wiki_page_templates-r3886.patch, 4.9 kB (added by cboos, 23 months ago)

Implements the PageTemplates/... idea.

  • htdocs/css/wiki.css

     
    1616 margin: 1em 0 2em; 
    1717 overflow: auto; 
    1818} 
     19#template {vertical-align: middle; padding-top: 1em;} 
    1920 
    2021/* Diff view */ 
    2122#overview .multi { color: #999 } 
  • trac/wiki/web_ui.py

     
    316316 
    317317        if 'text' in req.args: 
    318318            page.text = req.args.get('text') 
     319        elif 'template' in req.args: 
     320            template = req.args.get('template') 
     321            template_page = WikiPage(self.env, template, db=db) 
     322            if template_page.exists: 
     323                page.text = template_page.text 
    319324        if action == 'preview': 
    320325            page.readonly = 'readonly' in req.args 
    321326 
     
    404409        if req.perm.has_permission('WIKI_MODIFY'): 
    405410            attach_href = req.href.attachment('wiki', page.name) 
    406411 
     412 
     413        templates = [t for t in WikiPage.select_names(self.env, 
     414                                                      'PageTemplates/%', db)] 
    407415        data.update({'action': 'view', 
    408416                     'page_html': page_html, 
    409417                     'comment_html': comment_html, 
     
    412420                     'attach_href': attach_href, 
    413421                     # Ask web spiders to not index old versions 
    414422                     'norobots': bool(version), 
    415                      }) 
     423                     'templates': templates}) 
    416424        return 'wiki_view.html', data, None 
    417425 
    418426    # ITimelineEventProvider methods 
  • trac/wiki/model.py

     
    155155                       "ORDER BY version DESC", (self.name, self.version)) 
    156156        for version,time,author,comment,ipnr in cursor: 
    157157            yield version,time,author,comment,ipnr 
     158 
     159    def select_names(cls, env, prefix=None, db=None): 
     160        if not db: 
     161            db = env.get_db_cnx() 
     162        cursor = db.cursor() 
     163        if prefix: 
     164            cursor.execute("SELECT name FROM wiki WHERE name LIKE %s" 
     165                           " ORDER BY name", (prefix,)) 
     166        else: 
     167            cursor.execute("SELECT name FROM wiki ORDER BY name") 
     168        for name, in cursor: 
     169            yield name 
     170 
     171    select_names = classmethod(select_names) 
     172 
  • templates/wiki_edit.html

     
    6262            </select> 
    6363          </div> 
    6464          <p><textarea id="text" class="wikitext" name="text" cols="80" rows="$edit_rows"> 
    65 $page.text 
    66             </textarea> 
     65$page.text</textarea> 
    6766          </p> 
    6867          <script type="text/javascript"> 
    6968            var scrollBarPos = document.getElementById("scroll_bar_pos"); 
  • templates/wiki_view.html

     
    1919        <li><a href="${href.wiki('RecentChanges')}">Index by Date</a></li> 
    2020        <li class="last"> 
    2121          <a href="${req.href.wiki(page.name, action='diff', version=page.version)}">Last Change</a> 
    22         </li>  
     22        </li> 
    2323      </ul> 
    2424      <hr /> 
    2525    </div> 
    2626 
    2727    <div id="content" class="wiki"> 
    28        
     28 
    2929      <py:if test="comment_html"> 
    3030        <table id="info" summary="Revision info"> 
    3131          <tbody> 
     
    5050              <form method="get" action="${href.wiki(page.name)}"> 
    5151                <div> 
    5252                  <input type="hidden" name="action" value="edit" /> 
    53                   <input type="submit" value="${page.exists and 'Edit' or 'Create'} this page" accesskey="e" /> 
     53                  <py:choose> 
     54                    <py:when test="page.exists"> 
     55                      <input type="submit" value="Edit this page" accesskey="e" /> 
     56                    </py:when> 
     57                    <py:otherwise> 
     58                      <input type="submit" value="Create this page" accesskey="e" /> 
     59                      <div py:if="templates" id="template"> 
     60                        <label for="template">Using the template:</label> 
     61                        <select name="template"> 
     62                          <option selected="${not 'PageTemplates/Default' in templates and 'selected' or None}" value="">(blank page)</option> 
     63                          <option py:for="t in templates" py:attrs="form_attrs(selected=t=='PageTemplates/Default')">$t</option> 
     64                        </select> 
     65                      </div> 
     66                    </py:otherwise> 
     67                  </py:choose> 
    5468                </div> 
    5569              </form> 
    5670              <py:if test="page.exists">