From b83caa388080cbef85f26286e253cf16c31a60e4 Mon Sep 17 00:00:00 2001 From: Martin Langhoff Date: Mon, 29 Nov 2010 20:01:40 +0000 Subject: Synchronized WPWikiDB class - server.py gets some fixes --- diff --git a/server.py b/server.py index 9b301be..ce75393 100755 --- a/server.py +++ b/server.py @@ -98,8 +98,11 @@ class ArticleIndex: class WPWikiDB: """Retrieves article contents for mwlib.""" - def getRawArticle(self, title): + def getRawArticle(self, title, followRedirects=True): # Retrieve article text, recursively following #redirects. + if title == '': + return '' + oldtitle = "" while True: # Replace underscores with spaces in title. @@ -111,10 +114,16 @@ class WPWikiDB: article_text = "" break - article_text = unicode(wp_load_article(title.encode('utf8')), 'utf8') + article_text = wp_load_article(title.encode('utf8')) + if article_text == None: + # something's wrong + return None + article_text = unicode(article_text, 'utf8') # To see unmodified article_text, uncomment here. # print article_text + if not followRedirects: + break m = re.match(r'^\s*\#?redirect\s*\:?\s*\[\[(.*)\]\]', article_text, re.IGNORECASE|re.MULTILINE) if not m: break diff --git a/tools/expandtemplates.py b/tools/expandtemplates.py index aec43e2..d02e3c1 100755 --- a/tools/expandtemplates.py +++ b/tools/expandtemplates.py @@ -70,11 +70,10 @@ class WPWikiDB: def getRawArticle(self, title, followRedirects=True): # Retrieve article text, recursively following #redirects. - oldtitle = "" - if title == '': return '' - + + oldtitle = "" while True: # Replace underscores with spaces in title. title = title.replace("_", " ") -- cgit v0.9.1