[Pywikipedia-l] SVN: [6115] branches/rewrite/pywikibot/page.py
russblau at svn.wikimedia.org
russblau at svn.wikimedia.org
Sun Nov 23 16:52:21 UTC 2008
Revision: 6115
Author: russblau
Date: 2008-11-23 16:52:20 +0000 (Sun, 23 Nov 2008)
Log Message:
-----------
templatesWithParams
Modified Paths:
--------------
branches/rewrite/pywikibot/page.py
Modified: branches/rewrite/pywikibot/page.py
===================================================================
--- branches/rewrite/pywikibot/page.py 2008-11-23 12:41:02 UTC (rev 6114)
+++ branches/rewrite/pywikibot/page.py 2008-11-23 16:52:20 UTC (rev 6115)
@@ -756,7 +756,25 @@
parameters as the second entry.
"""
- return self.site().templates_with_params(self)
+ templates = pywikibot.textlib.extract_templates_and_params(self.text)
+ # backwards-compatibility: convert the dict returned as the second
+ # element into a list in the format used by old scripts
+ result = []
+ for template in templates:
+ args = template[1]
+ positional = []
+ named = {}
+ for key in sorted(args.keys()):
+ try:
+ int(key)
+ except ValueError:
+ named[key] = args[key]
+ else:
+ positional.append(args[key])
+ for pos in positional:
+ named.append("%s=%s" % (pos, positional[pos]))
+ result.append(template[0], named)
+ return result
def categories(self, nofollow_redirects=None, withSortKey=False):
"""Iterate categories that the article is in.
More information about the Pywikipedia-l
mailing list