Revision: 6420 Author: nicdumz Date: 2009-02-23 05:29:01 +0000 (Mon, 23 Feb 2009)
Log Message: ----------- * modifying Category.copyTo so it accepts either a category name or a Category object as a copy target * Category.copyTo seemed to expect a formatted string as a message. Why is that? This was not documented, so I changed it in a way that it either accepts a formatted string, or uses the given message. Documented :)
Modified Paths: -------------- branches/rewrite/pywikibot/page.py
Modified: branches/rewrite/pywikibot/page.py =================================================================== --- branches/rewrite/pywikibot/page.py 2009-02-23 05:11:14 UTC (rev 6419) +++ branches/rewrite/pywikibot/page.py 2009-02-23 05:29:01 UTC (rev 6420) @@ -1416,11 +1416,16 @@ return False return True
- def copyTo(self, catname, message): + def copyTo(self, cat, message): """ Copy text of category page to a new page. Does not move contents.
- @param catname: New category title (without namespace) + @param cat: New category title (without namespace) or Category object + @type cat: unicode or Category + @param message: message to use for category creation message + If two %s are provided in message, will be replaced + by (self.title, authorsList) + @type message: unicode @return: True if copying was successful, False if target page already existed.
@@ -1428,8 +1433,11 @@ # This seems far too specialized to be in the top-level framework # move to category.py? (Although it doesn't seem to be used there, # either) - catname = self.site().category_namespace() + ':' + catname - targetCat = Category(self.site(), catname) + if not isinstance(cat, Category): + cat = self.site().category_namespace() + ':' + cat + targetCat = Category(self.site(), cat) + else: + targetCat=cat if targetCat.exists(): pywikibot.output(u'Target page %s already exists!' % targetCat.title(), @@ -1439,7 +1447,10 @@ pywikibot.output('Moving text from %s to %s.' % (self.title(), targetCat.title())) authors = ', '.join(self.contributingUsers()) - creationSummary = message % (self.title(), authors) + try: + creationSummary = message % (self.title(), authors) + except TypeError: + creationSummary=message targetCat.put(self.get(), creationSummary) return True