Revision: 8610 Author: russblau Date: 2010-10-05 20:53:50 +0000 (Tue, 05 Oct 2010)
Log Message: ----------- Fix bug 3080070: templatesWithParams return params in wrong order
Modified Paths: -------------- branches/rewrite/pywikibot/page.py
Modified: branches/rewrite/pywikibot/page.py =================================================================== --- branches/rewrite/pywikibot/page.py 2010-10-05 16:21:42 UTC (rev 8609) +++ branches/rewrite/pywikibot/page.py 2010-10-05 20:53:50 UTC (rev 8610) @@ -920,7 +920,7 @@ result = [] for template in templates: link = pywikibot.Link(template[0], self.site, - defaultNamespace=10) + defaultNamespace=10) try: if link.canonical_title() not in titles: continue @@ -928,15 +928,26 @@ # this is a parser function or magic word, not template name continue args = template[1] + intkeys = {} + named = {} positional = [] - named = {} for key in sorted(args): try: - int(key) + intkeys[int(key)] = args[key] except ValueError: named[key] = args[key] + for i in xrange(1, len(intkeys)+1): + # only those args with consecutive integer keys can be + # treated as positional; an integer could also be used + # (out of order) as the key for a named argument + # example: {{tmp|one|two|5=five|three}} + if i in intkeys: + positional.append(intkeys[i]) else: - positional.append(args[key]) + for k in intkeys: + if k < 1 or k >= i: + named[str(k)] = intkeys[k] + break for name in named: positional.append("%s=%s" % (name, named[name])) result.append((pywikibot.Page(link, self.site), positional))
pywikipedia-svn@lists.wikimedia.org