def __init__(self, row): # row :=: (0:title, 1:ns, 2:ctime, 3:mtime, # 4:redir_to_title, 5:redir_to_ns, # 6:size) self.__row = row self.__subject = article.Subject(self.__row[0], self.__row[1]) self.__rd_subject = None if self.__row[4] is not None: self.__rd_subject = article.Subject(self.__row[4], self.__row[5])
def get(self, subject): art_id = self.__getArticleId(subject) is_redirect = self.__isRedirect(subject) cursor = self.__connection.cursor() if is_redirect: # the article is a redirection cursor.execute("""\ SELECT rd_title, rd_ns FROM redirect WHERE art_id = %d """ % art_id) title, ns = cursor.fetchone() rd_subject = article.Subject(title, ns) art = article.RedirectArticle(subject, rd_subject) else: # get the article content cursor.execute("""\ SELECT cont_text FROM content WHERE art_id = %d """ % art_id) content = cursor.fetchone()[0] # get all the categories the article owned to cursor.execute("""\ SELECT cat_art_title FROM category WHERE art_id = %d """ % art_id) categories = tuple(row[0] for row in cursor) if subject.getNamespace() == CATEGORY_NS: # the article is a category article # ...get all subjects of a category cursor.execute( """ SELECT art_title, art_ns FROM article, category WHERE cat_art_title = ? AND category.art_id = article.art_id ORDER BY art_ns, art_title ASC """, (subject.getTitle(), )) subjects = {} for row in cursor: title, ns = row subjects.setdefault(ns, []).append(article.Subject(title, ns)) art = article.CategoryArticle(subject, content, subjects, categories) else: # it is a normal article art = article.UserArticle(subject, content, categories) cursor.close() return art
def cat2ref(cat_st): title = article.norm_subj_elem(cat_st) subject = article.Subject(title, manager.CATEGORY_NS) link_cls = "wiki-undefined" if self.__art_mgr.contains(subject): link_cls = "wiki-defined" href = u'/' + unicode(subject) return title, subject, link_cls, href
def subjects(self): subjects = [] for title in self.__callbacks.keys(): subjects.append( article.DefaultArticleStats(article.Subject(title, SYSTEM_NS))) return {SYSTEM_NS: subjects}
parser.add_option('-t', '--tmpl', dest='tmpl', default=DEFAULT_TEMPLATE) (options, args) = parser.parse_args() wiki_stylesheet = options.css wiki_connection = sqlite3.connect(options.db, isolation_level="IMMEDIATE") if TEST: from db_create import createDb createDb(wiki_connection) wiki_artmgr = sqldb.SqlArticleManager(wiki_connection) wiki_manager = manager.WikiManager(wiki_artmgr) userNsMgr = manager.UserNsManager(wiki_artmgr) systemNsMgr = manager.SystemNsManager() _systemList = SystemList(article.Subject('List', manager.SYSTEM_NS), wiki_manager) systemNsMgr.register('List', _systemList) wiki_manager.registerNsMgr(manager.DEFAULT_NS, userNsMgr) wiki_manager.registerNsMgr(manager.CATEGORY_NS, userNsMgr) wiki_manager.registerNsMgr(manager.TEMPLATE_NS, userNsMgr) wiki_manager.registerNsMgr(manager.SYSTEM_NS, systemNsMgr) wiki_formatter = formatter.HtmlBuilder() wiki_parser = wikiparser.WikiParser(wiki_formatter, wiki_manager) page_factory = wikipage.WikiPageFactory(WIKI_NAME, __copyright__, wiki_parser, wiki_formatter, wiki_manager, options.tmpl) server_address = ('', int(options.port))