If you don't mind a suggestion, Nic, I think it is better to use the Wiki server to resolve magic words than to do it on the client side; otherwise, we continue to face the problem of our client struggling to keep up with changes in namespaces, etc. Why not use the API "action=expandtemplates" feature here? Or, better yet, stick with the rewrite branch. :-)
Russ
----- Original Message ----- From: nicdumz@svn.wikimedia.org To: pywikipedia-svn@lists.wikimedia.org Sent: Sunday, June 21, 2009 9:58 AM Subject: [Pywikipedia-svn] SVN: [6978] trunk/pywikipedia/wikipedia.py
Revision: 6978 Author: nicdumz Date: 2009-06-21 13:58:28 +0000 (Sun, 21 Jun 2009)
Log Message:
Adding a Site.resolvemagicwords member. For now, only resolves {{ns:xx}} words, but is meant to be expanded.
This solves issue #2805572
Modified Paths:
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py
--- trunk/pywikipedia/wikipedia.py 2009-06-21 10:46:10 UTC (rev 6977) +++ trunk/pywikipedia/wikipedia.py 2009-06-21 13:58:28 UTC (rev 6978) @@ -1811,6 +1811,9 @@ # from text before processing thistxt = removeDisabledParts(thistxt)
# resolve {{ns:-1}} or {{ns:Help}}
thistxt = self.site().resolvemagicwords(thistxt)
for match in Rlink.finditer(thistxt): title = match.group('title') title = title.replace("_", " ").strip(" ")
@@ -5898,6 +5901,32 @@ + '\s*:?\s*[[(.+?)(?:|.*?)?]]', re.IGNORECASE | re.UNICODE | re.DOTALL)
- def resolvemagicwords(self, wikitext):
"""Replace the {{ns:xx}} marks in a wikitext with the namespace
names"""
defaults = []
for namespace in self.family.namespaces.itervalues():
value = namespace.get('_default', None)
if value:
if isinstance(value, list):
defaults += value
else:
defaults.append(value)
named = re.compile(u'{{ns:(' + '|'.join(defaults) + ')}}', re.I)
def replacenamed(match):
return self.normalizeNamespace(match.group(1))
wikitext = named.sub(replacenamed, wikitext)
numbered = re.compile('{{ns:(-?\d{1,2})}}', re.I)
def replacenumbered(match):
return self.namespace(int(match.group(1)))
return named.sub(replacenumbered, wikitext)
- # The following methods are for convenience, so that you can access # methods of the Family class easier. def encoding(self):
Pywikipedia-svn mailing list Pywikipedia-svn@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikipedia-svn
2009/6/25 Russell Blau russblau@imapmail.org:
If you don't mind a suggestion, Nic, I think it is better to use the Wiki server to resolve magic words than to do it on the client side; otherwise, we continue to face the problem of our client struggling to keep up with changes in namespaces, etc. Why not use the API "action=expandtemplates" feature here? Or, better yet, stick with the rewrite branch. :-)
I agree, 100%. But I did not want to include yet-another bastard-hackish API method in our trunk/; and there was a bug report since the absence of this feature was causing interwiki.py bugs... :/ That's why I included this, even if it's unsatisfactory.
But yes, in the perfect world, we'd all be running API-rewritten code ;)
Actually, if you ask, I would be in favor of "freezing" trunk, to force us to work on the rewrite branch. No more bugfixes or new features until the release of the rewrite branch? :p