jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/563683 )
Change subject: Deprecate Category.copyTo and Category.copyAndKeep methods ......................................................................
Deprecate Category.copyTo and Category.copyAndKeep methods
- Both were imported from compat's catlib.py. - Both are not used in core and are too specialized. - scripts/category.py has _strip_cfd_templates, which provides similar functionality when it is needed there.
Change-Id: I81000f4db448feb837a287ea6355ce48e7d1169e --- M HISTORY.rst M pywikibot/page.py 2 files changed, 88 insertions(+), 85 deletions(-)
Approvals: Xqt: Looks good to me, but someone else must approve Framawiki: Looks good to me, approved jenkins-bot: Verified
diff --git a/HISTORY.rst b/HISTORY.rst index dd4a38b..c189bdb 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -4,6 +4,7 @@ Current release ---------------
+* Category.copyTo and Category.copyAndKeep will be removed in the next release * botirc module has been removed (T212632) * Bugfixes and improvements * Localisation updates diff --git a/pywikibot/page.py b/pywikibot/page.py index e96b27b..44d0a82 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -3033,91 +3033,6 @@ """ return 'hiddencat' in self.properties()
- def copyTo(self, cat, message): - """ - Copy text of category page to a new page. Does not move contents. - - @param cat: New category title (without namespace) or Category object - @type cat: str or pywikibot.page.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: str - @return: True if copying was successful, False if target page - already existed. - @rtype: bool - """ - # 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) - if not isinstance(cat, Category): - target_cat = Category(self.site, 'Category:' + cat) - else: - target_cat = cat - if target_cat.exists(): - pywikibot.warning( - 'Target page %s already exists!' % target_cat.title()) - return False - else: - pywikibot.output('Moving text from %s to %s.' - % (self.title(), target_cat.title())) - authors = ', '.join(self.contributingUsers()) - try: - creation_summary = message % (self.title(), authors) - except TypeError: - creation_summary = message - target_cat.put(self.get(), creation_summary) - return True - - @deprecated_args(cfdTemplates='cfd_templates') - def copyAndKeep(self, catname, cfd_templates, message): - """ - Copy partial category page text (not contents) to a new title. - - Like copyTo above, except this removes a list of templates (like - deletion templates) that appear in the old category text. It also - removes all text between the two HTML comments BEGIN CFD TEMPLATE - and END CFD TEMPLATE. (This is to deal with CFD templates that are - substituted.) - - Returns true if copying was successful, false if target page already - existed. - - @param catname: New category title (without namespace) - @param cfd_templates: A list (or iterator) of templates to be removed - from the page text - @return: True if copying was successful, False if target page - already existed. - @rtype: bool - """ - # I don't see why we need this as part of the framework either - # move to scripts/category.py? - target_cat = Category(self.site, 'Category:' + catname) - if target_cat.exists(): - pywikibot.warning('Target page %s already exists!' - % target_cat.title()) - return False - - pywikibot.output( - 'Moving text from {} to {}.' - .format(self.title(), target_cat.title())) - authors = ', '.join(self.contributingUsers()) - creation_summary = message % (self.title(), authors) - newtext = self.get() - for regex_name in cfd_templates: - matchcfd = re.compile(r'{{%s.*?}}' % regex_name, re.IGNORECASE) - newtext = matchcfd.sub('', newtext) - matchcomment = re.compile( - r'<!--BEGIN CFD TEMPLATE-->.*?<!--END CFD TEMPLATE-->', - re.IGNORECASE | re.MULTILINE | re.DOTALL) - newtext = matchcomment.sub('', newtext) - pos = 0 - while (newtext[pos:pos + 1] == '\n'): - pos = pos + 1 - newtext = newtext[pos:] - target_cat.put(newtext, creation_summary) - return True - @property def categoryinfo(self): """ @@ -3225,6 +3140,93 @@ """DEPRECATED: equivalent to list(self.categories(...)).""" return sorted(set(self.categories()))
+ @deprecated(since='20200111', future_warning=True) + def copyTo(self, cat, message): + """ + Copy text of category page to a new page. Does not move contents. + + @param cat: New category title (without namespace) or Category object + @type cat: str or pywikibot.page.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: str + @return: True if copying was successful, False if target page + already existed. + @rtype: bool + """ + # 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) + if not isinstance(cat, Category): + target_cat = Category(self.site, 'Category:' + cat) + else: + target_cat = cat + if target_cat.exists(): + pywikibot.warning( + 'Target page %s already exists!' % target_cat.title()) + return False + else: + pywikibot.output('Moving text from %s to %s.' + % (self.title(), target_cat.title())) + authors = ', '.join(self.contributingUsers()) + try: + creation_summary = message % (self.title(), authors) + except TypeError: + creation_summary = message + target_cat.put(self.get(), creation_summary) + return True + + @deprecated(since='20200111', future_warning=True) + @deprecated_args(cfdTemplates='cfd_templates') + def copyAndKeep(self, catname, cfd_templates, message): + """ + Copy partial category page text (not contents) to a new title. + + Like copyTo above, except this removes a list of templates (like + deletion templates) that appear in the old category text. It also + removes all text between the two HTML comments BEGIN CFD TEMPLATE + and END CFD TEMPLATE. (This is to deal with CFD templates that are + substituted.) + + Returns true if copying was successful, false if target page already + existed. + + @param catname: New category title (without namespace) + @param cfd_templates: A list (or iterator) of templates to be removed + from the page text + @return: True if copying was successful, False if target page + already existed. + @rtype: bool + """ + # I don't see why we need this as part of the framework either + # move to scripts/category.py? + target_cat = Category(self.site, 'Category:' + catname) + if target_cat.exists(): + pywikibot.warning('Target page %s already exists!' + % target_cat.title()) + return False + + pywikibot.output( + 'Moving text from {} to {}.' + .format(self.title(), target_cat.title())) + authors = ', '.join(self.contributingUsers()) + creation_summary = message % (self.title(), authors) + newtext = self.get() + for regex_name in cfd_templates: + matchcfd = re.compile(r'{{%s.*?}}' % regex_name, re.IGNORECASE) + newtext = matchcfd.sub('', newtext) + matchcomment = re.compile( + r'<!--BEGIN CFD TEMPLATE-->.*?<!--END CFD TEMPLATE-->', + re.IGNORECASE | re.MULTILINE | re.DOTALL) + newtext = matchcomment.sub('', newtext) + pos = 0 + while (newtext[pos:pos + 1] == '\n'): + pos = pos + 1 + newtext = newtext[pos:] + target_cat.put(newtext, creation_summary) + return True +
class User(Page):
pywikibot-commits@lists.wikimedia.org