http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10951
Revision: 10951
Author: multichill
Date: 2013-01-17 20:20:15 +0000 (Thu, 17 Jan 2013)
Log Message:
-----------
Simple bot to do some category filtering.
Added Paths:
-----------
trunk/pywikipedia/overcat_simple_filter.py
Added: trunk/pywikipedia/overcat_simple_filter.py
===================================================================
--- trunk/pywikipedia/overcat_simple_filter.py (rev 0)
+++ trunk/pywikipedia/overcat_simple_filter.py 2013-01-17 20:20:15 UTC (rev 10951)
@@ -0,0 +1,62 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+'''
+A bot to do some simple over categorization filtering.
+Now it uses the strategy to loop over all images in all the subcategories.
+That might be a very good strategy when the parent category is very full, but later on it will become very inefficient.
+
+'''
+import sys, pywikibot, catlib, pagegenerators
+
+def filterCategory(page):
+ '''
+ Loop over all subcategories of page and filter them
+ '''
+
+ # FIXME: category = catlib.Category(page) doesn't work
+ site = page.site()
+ title = page.title()
+ category = catlib.Category(site, title)
+
+ for subcat in category.subcategories():
+ filterSubCategory(subcat, category)
+
+def filterSubCategory(subcat, category):
+ '''
+ Filter category from all articles and files in subcat
+ '''
+ articleGen = pagegenerators.PreloadingGenerator(pagegenerators.CategorizedPageGenerator(subcat))
+
+ for article in articleGen:
+ pywikibot.output(u'Working on %s' % (article.title(),))
+ articleCategories = article.categories()
+ if category in articleCategories:
+ articleCategories.remove(category)
+ text = article.get()
+ newtext = pywikibot.replaceCategoryLinks(text, articleCategories)
+ pywikibot.showDiff(text, newtext)
+ comment = u'Removing [[%s]]: Is already in the subcategory [[%s]]' % (category.title(), subcat.title())
+ article.put(newtext, comment)
+
+
+def main(args):
+ generator = None;
+ genFactory = pagegenerators.GeneratorFactory()
+
+ for arg in pywikibot.handleArgs():
+ genFactory.handleArg(arg)
+
+ generator = genFactory.getCombinedGenerator()
+ if not generator:
+ return False
+
+ for page in generator:
+ if page.exists() and page.namespace()==14:
+ filterCategory(page)
+
+
+if __name__ == "__main__":
+ try:
+ main(sys.argv[1:])
+ finally:
+ print "All done!"
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10949
Revision: 10949
Author: huji
Date: 2013-01-17 17:24:44 +0000 (Thu, 17 Jan 2013)
Log Message:
-----------
Per xqt's comment on 10937, it is possible to use MW's translation
Modified Paths:
--------------
branches/rewrite/scripts/i18n/pywikibot.py
Modified: branches/rewrite/scripts/i18n/pywikibot.py
===================================================================
--- branches/rewrite/scripts/i18n/pywikibot.py 2013-01-17 08:22:05 UTC (rev 10948)
+++ branches/rewrite/scripts/i18n/pywikibot.py 2013-01-17 17:24:44 UTC (rev 10949)
@@ -8,7 +8,6 @@
'pywikibot-enter-new-text': u'Please enter the new text:',
'pywikibot-enter-page-processing': u'Which page should be processed?',
'pywikibot-enter-xml-filename': u'Please enter the XML dump\'s filename:',
- 'comma-separator': ', ',
},
# Author: Als-Holder
# Author: TTMTT
@@ -20,7 +19,6 @@
'pywikibot-enter-new-text': u'Message displayed to the bot owner to enter the new text.',
'pywikibot-enter-category-name': u'Message displayed to the bot owner to enter the category name.',
'pywikibot-enter-finished-browser': u'Message displayed to the bot owner to press Enter button when browser edits are finished.',
- 'comma-separator': 'Localized comma character with a trailing space',
},
# Author: TTMTT
# Author: Zanatos
@@ -192,7 +190,6 @@
'pywikibot-enter-new-text': u'لطفاً متن جدید را وارد کنید:',
'pywikibot-enter-category-name': u'لطفاً نام رده را وارد کنید:',
'pywikibot-enter-finished-browser': u'هنگامی که در مرورگر پایان یافت دکمهٔ اینتر را بفشارید.',
- 'comma-separator': '، ',
},
# Author: Nedergard
# Author: VezonThunder
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10948
Revision: 10948
Author: xqt
Date: 2013-01-17 08:22:05 +0000 (Thu, 17 Jan 2013)
Log Message:
-----------
Should be allowed to create a DataPage with different language code not equal to wikidata. May be there could be a Page property method that creates the DataPage like
Modified Paths:
--------------
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2013-01-17 07:18:39 UTC (rev 10947)
+++ trunk/pywikipedia/wikipedia.py 2013-01-17 08:22:05 UTC (rev 10948)
@@ -4058,8 +4058,11 @@
site = getSite(site)
self._originSite = site
Page.__init__(self, site, *args, **kwargs)
- if self.site()!=getSite("wikidata",fam="wikidata"):
- raise Error("Site of Wikidata objects must be set as getSite('wikidata',fam='wikidata')")
+
+ @property
+ def site(self):
+ return super(wikidataPage, self).site.data_repository()
+
def setitem(self, summary=None, watchArticle=False, minorEdit=True,
newPage=False, token=None, newToken=False, sysop=False,
captcha=None, botflag=True, maxTries=-1, items={}):