jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/462141 )
Change subject: category.py: Add option -append to listify ......................................................................
category.py: Add option -append to listify
Added option -append to append list to already existing page content when listifying.
Tested: https://www.mediawiki.org/wiki/User:Alangi_Derick/Sandbox/listify3
Bug: T197841 Change-Id: I15860189a2044caecec4750247cee4008a9bb0a9 --- M scripts/category.py 1 file changed, 22 insertions(+), 11 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/category.py b/scripts/category.py index 6cf2cbf..cc1cbc4 100755 --- a/scripts/category.py +++ b/scripts/category.py @@ -28,6 +28,8 @@
Options for "listify" action:
+ * -append - This appends the list to the current page that is already + existing (appending to the bottom by default). * -overwrite - This overwrites the current page with the list even if something is already there. * -showimages - This displays images rather than linking them in the list. @@ -903,11 +905,12 @@
"""Create a list containing all of the members in a category."""
- def __init__(self, catTitle, listTitle, editSummary, overwrite=False, - showImages=False, subCats=False, talkPages=False, - recurse=False): + def __init__(self, catTitle, listTitle, editSummary, append=False, + overwrite=False, showImages=False, subCats=False, + talkPages=False, recurse=False): """Initializer.""" self.editSummary = editSummary + self.append = append self.overwrite = overwrite self.showImages = showImages self.site = pywikibot.Site() @@ -945,13 +948,18 @@ article.toggleTalkPage().title()) else: listString += "*[[:%s]]\n" % article.title() - if self.list.exists() and not self.overwrite: - pywikibot.output( - 'Page {} already exists, aborting.\n' - 'Use -overwrite option to overwrite the output page.' - .format(self.list.title())) - else: - self.list.put(listString, summary=self.editSummary) + if self.list.exists(): + if self.append: + # append content by default at the bottom + listString = self.list.text + '\n' + listString + pywikibot.output('Category list appending...') + elif not self.overwrite: + pywikibot.output( + 'Page {} already exists, aborting.\n' + 'Use -overwrite option to overwrite the output page.' + .format(self.list.title())) + return + self.list.put(listString, summary=self.editSummary)
class CategoryTidyRobot(Bot, CategoryPreprocess): @@ -1332,6 +1340,7 @@ batch = False summary = '' inplace = False + append = False overwrite = False showimages = False talkpages = False @@ -1391,6 +1400,8 @@ inplace = True elif option == 'nodelsum': use_deletion_summary = False + elif option == 'append': + append = True elif option == 'overwrite': overwrite = True elif option == 'showimages': @@ -1505,7 +1516,7 @@ new_cat_title = pywikibot.input( u'Please enter the name of the list to create:') bot = CategoryListifyRobot(old_cat_title, new_cat_title, summary, - overwrite, showimages, subCats=True, + append, overwrite, showimages, subCats=True, talkPages=talkpages, recurse=recurse)
if bot:
pywikibot-commits@lists.wikimedia.org