def _write_to_db(self, text, action, comment, ip, proper_name): """ Write the text to the page tables in the database. """ ourtime = time.time() self.request.save_time = ourtime self.request.cursor.execute("""SELECT name, propercased_name from curPages where name=%(page_name)s and wiki_id=%(wiki_id)s""", {'page_name':self.page_name, 'wiki_id':self.request.config.wiki_id}) exists = self.request.cursor.fetchone() if not proper_name: if exists: proper_name = exists[1] else: proper_name = self.given_name if not self.request.user.id: user_id = 'anon:%s' % i else: user_id = self.request.user.id if exists: self.request.cursor.execute("""UPDATE curPages set name=%(page_name)s, text=%(text)s, editTime=%(ourtime)s, userEdited=%(id)s, propercased_name=%(proper_name)s where name=%(page_name)s and wiki_id=%(wiki_id)s""", {'page_name': self.page_name, 'text': text, 'ourtime': ourtime, 'id': user_id, 'proper_name':proper_name, 'wiki_id':self.request.config.wiki_id}, isWrite=True) else: self.request.cursor.execute("""INSERT into curPages (name, text, cachedText, editTime, cachedTime, userEdited, propercased_name, wiki_id) values (%(page_name)s, %(text)s, NULL, %(ourtime)s, NULL, %(id)s, %(proper_name)s, %(wiki_id)s)""", {'page_name':self.page_name, 'text':text, 'ourtime':ourtime, 'id':user_id, 'proper_name':proper_name, 'wiki_id':self.request.config.wiki_id}, isWrite=True) # then we need to update the allPages table for Recent Changes # and page-centric info. self.request.cursor.execute("""INSERT into allPages (name, text, editTime, userEdited, editType, comment, userIP, propercased_name, wiki_id) values (%(page_name)s, %(text)s, %(ourtime)s, %(id)s, %(action)s, %(comment)s, %(ip)s, %(proper_name)s, %(wiki_id)s)""", {'page_name':self.page_name, 'proper_name':proper_name, 'text':text, 'ourtime':ourtime, 'id':user_id, 'action':action, 'comment':wikiutil.escape(comment),'ip':ip, 'wiki_id':self.request.config.wiki_id}, isWrite=True) # set in-memory page text/cached page text self.set_raw_body(text, set_cache=True) import caching cache = caching.CacheEntry(self.page_name, self.request) if config.memcache and not exists: pagecount = wikidb.getPageCount(self.request) + 1 self.request.mc.set('active_page_count', pagecount) # set trigger for clearing possible dependencies (e.g. [[Include]]) # we want this to be a post-commit trigger so that we don't # have stale data for pagename in caching.depend_on_me(self.page_name, self.request, exists, action=action): self.request.postCommitActions.append( (caching.CacheEntry(pagename, self.request).clear,)) if exists: type = 'page save' else: type = 'page save new' self.buildCache(type=type) # check if this is a user page and keep track of it, if so changed_state = (action == 'SAVENEW' or action == 'DELETE') is_user_page = self.page_name.startswith( config.user_page_prefix.lower()) if is_user_page and changed_state: user.userPageChangedState(self, action)
def _write_to_db(self, text, action, comment, ip, proper_name): """ Write the text to the page tables in the database. """ ourtime = time.time() self.request.save_time = ourtime self.request.cursor.execute( """SELECT name, propercased_name from curPages where name=%(page_name)s and wiki_id=%(wiki_id)s""", { 'page_name': self.page_name, 'wiki_id': self.request.config.wiki_id }) exists = self.request.cursor.fetchone() if not proper_name: if exists: proper_name = exists[1] else: proper_name = self.given_name if not self.request.user.id: user_id = 'anon:%s' % i else: user_id = self.request.user.id if exists: self.request.cursor.execute("""UPDATE curPages set name=%(page_name)s, text=%(text)s, editTime=%(ourtime)s, userEdited=%(id)s, propercased_name=%(proper_name)s where name=%(page_name)s and wiki_id=%(wiki_id)s""", { 'page_name': self.page_name, 'text': text, 'ourtime': ourtime, 'id': user_id, 'proper_name': proper_name, 'wiki_id': self.request.config.wiki_id }, isWrite=True) else: self.request.cursor.execute("""INSERT into curPages (name, text, cachedText, editTime, cachedTime, userEdited, propercased_name, wiki_id) values (%(page_name)s, %(text)s, NULL, %(ourtime)s, NULL, %(id)s, %(proper_name)s, %(wiki_id)s)""", { 'page_name': self.page_name, 'text': text, 'ourtime': ourtime, 'id': user_id, 'proper_name': proper_name, 'wiki_id': self.request.config.wiki_id }, isWrite=True) # then we need to update the allPages table for Recent Changes # and page-centric info. self.request.cursor.execute("""INSERT into allPages (name, text, editTime, userEdited, editType, comment, userIP, propercased_name, wiki_id) values (%(page_name)s, %(text)s, %(ourtime)s, %(id)s, %(action)s, %(comment)s, %(ip)s, %(proper_name)s, %(wiki_id)s)""", { 'page_name': self.page_name, 'proper_name': proper_name, 'text': text, 'ourtime': ourtime, 'id': user_id, 'action': action, 'comment': wikiutil.escape(comment), 'ip': ip, 'wiki_id': self.request.config.wiki_id }, isWrite=True) # set in-memory page text/cached page text self.set_raw_body(text, set_cache=True) import caching cache = caching.CacheEntry(self.page_name, self.request) if config.memcache and not exists: pagecount = wikidb.getPageCount(self.request) + 1 self.request.mc.set('active_page_count', pagecount) # set trigger for clearing possible dependencies (e.g. [[Include]]) # we want this to be a post-commit trigger so that we don't # have stale data for pagename in caching.depend_on_me(self.page_name, self.request, exists, action=action): self.request.postCommitActions.append( (caching.CacheEntry(pagename, self.request).clear, )) if exists: type = 'page save' else: type = 'page save new' self.buildCache(type=type) # check if this is a user page and keep track of it, if so changed_state = (action == 'SAVENEW' or action == 'DELETE') is_user_page = self.page_name.startswith( config.user_page_prefix.lower()) if is_user_page and changed_state: user.userPageChangedState(self, action)