def environment_created(self): """Add default wiki pages when environment is created.""" self.log.info("Installing default wiki pages") with self.env.db_transaction: for name in self.load_pages(self.default_pages_dir): if name not in ('InterMapTxt', 'SandBox', 'WikiStart'): page = model.WikiPage(self.env, name) page.readonly = 1 page.save(None, None)
def _do_rename(self, name, new_name): page = model.WikiPage(self.env, name) try: page.rename(new_name) except TracError as e: raise AdminCommandError(e) printout( _(" '%(name1)s' renamed to '%(name2)s'", name1=name, name2=new_name))
def page_info(self, page): from trac.wiki import model """ Return tuple of (model.WikiPage, title) """ page = model.WikiPage(self.env, page) title = '' if page.exists: text = page.text ret = re.search('=\s+([^=]*)=', text) title = ret and ret.group(1) or '' return (page, title)
def export_page(self, page, filename): wikipage = model.WikiPage(self.env, page) if wikipage.exists: if not filename: printout(wikipage.text) else: if os.path.isfile(filename): raise AdminCommandError( _("File '%(name)s' exists", name=path_to_unicode(filename))) with open(filename, 'w', encoding='utf-8') as f: f.write(wikipage.text) else: raise AdminCommandError(_("Page '%(page)s' not found", page=page))
def rebuildAll(self, env, prefix, glossary_index, author = "<author>"): """ Rebuilds the index from all Glossary/* pages in the wiki. """ pre_text = self.text index_name = "/".join([prefix, glossary_index]) for p in wiki.WikiSystem(env).get_pages(prefix): if p != index_name: self.addPageLink(model.WikiPage(env, p), author) #============================================================ # Avoid nasty 'Page not modified' error #============================================================ if pre_text == self.text: return self.save(author, "Rebuilt index", '127.0.0.1')
def do_rename(db): if model.WikiPage(self.env, new_name, db=db).exists: raise AdminCommandError(_('The page %(name)s already exists.', name=new_name)) page = model.WikiPage(self.env, name, db=db) page.rename(new_name)