--- category_orig.py 2007-03-25 17:36:17.000000000 +0300 +++ category.py 2007-05-10 15:57:53.000000000 +0300 @@ -445,6 +445,80 @@ self.cat.delete(reason, False) else: self.cat.delete(reason, True) + + +class CategoryRemoveOverlapRobot: + ''' + Removes the category tag from all pages in a given category which belongs to the other + given category or one of it's subcategories + For example: Remove category tag from every page in Foo if the page belongs to + category Bar or one of Bar's subcategories: + CategoryRemoveRobot2(Foo, Bar) + ''' + deletion_reason_remove = { + 'de':u'Bot: Kategorie wurde aufgelöst', + 'en':u'Robot: Category was disbanded', + 'fi':u'Robotti poisti luokan', + 'he':u'רובוט: הקטגוריה פורקה', + 'ia':u'Robot: Categoria esseva dissolvite', + 'pt':u'Bot: Categoria foi unida', + 'sv':u'Robot: Kategorin upplöstes', + } + + msg_remove={ + 'da':u'Robot: Fjerner fra %s', + 'de':u'Bot: Entferne aus %s', + 'en':u'Robot: Removing from %s', + 'es':u'Bot: Eliminada de la %s', + 'fi':u'Robotti poisti luokasta %s', + 'he':u'רובוט: מסיר מהקטגוריה %s', + 'ia':u'Robot: Eliminate de %s', + 'is':u'Vélmenni: Fjarlægi [[Flokkur:%s]]', + 'nl':u'Bot: Verwijderd uit %s', + 'pt':u'Bot: Removendo [[Categoria:%s]]', + 'sr':u'Бот: Уклањање из категорије [[Категорија:%s|%s]]', + 'sv':u'Robot: Tar bort från %s', + } + + def __init__(self, catTitle, catTitle2, batchMode = False, editSummary = '', useSummaryForDeletion = False): + self.editSummary = editSummary + self.cat = catlib.Category(wikipedia.getSite(), 'Category:' + catTitle) + self.cat2 = catlib.Category(wikipedia.getSite(), 'Category:' + catTitle2) + # get edit summary message + self.useSummaryForDeletion = useSummaryForDeletion + if self.editSummary: + wikipedia.setAction(self.editSummary) + else: + wikipedia.setAction(wikipedia.translate(wikipedia.getSite(), self.msg_remove) % self.cat.title()) + + def run(self): + articles = self.cat.articles(recurse = 0) + articles2 = self.cat2.articles(recurse = 0) + if len(articles) == 0: + wikipedia.output(u'There are no articles in category %s' % self.cat.title()) + else: + for article in articles: + #Check if we should remove category tag + for article2 in articles2: + if article2 == article: + catlib.change_category(article, self.cat, None) + #print article + + print "Checking subcategories..." + # Check if the article belongs to some subcategory of Bar + subcategories = self.cat2.subcategories(recurse = True) + + if len(subcategories) == 0: + wikipedia.output(u'There are no subcategories in category %s' % self.cat.title()) + else: + for subcategory in subcategories: # Every subcategory + subarticles = subcategory.articles(recurse = True) + for subarticle in subarticles: # Every article in subcategory + for article in articles: # Every article we have to check + if article == subarticle: + catlib.change_category(article, self.cat, None) + #print article + class CategoryTidyRobot: """ @@ -711,6 +785,8 @@ action = 'add' elif arg == 'remove': action = 'remove' + elif arg == 'remove_overlap': + action = 'remove_overlap' elif arg == 'move': action = 'move' elif arg == 'tidy': @@ -749,6 +825,11 @@ oldCatTitle = wikipedia.input(u'Please enter the name of the category that should be removed:') bot = CategoryRemoveRobot(oldCatTitle, batchMode, editSummary, useSummaryForDeletion) bot.run() + elif action == 'remove_overlap': + oldCatTitle = wikipedia.input(u'Please enter the name of the category that should be removed:') + fromCatTitle = wikipedia.input(u'Please enter the name of the category where the page should belong too:') + bot = CategoryRemoveOverlapRobot(oldCatTitle, fromCatTitle, batchMode, editSummary, useSummaryForDeletion) + bot.run() elif action == 'move': if (fromGiven == False): oldCatTitle = wikipedia.input(u'Please enter the old name of the category:')