http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10963
Revision: 10963 Author: xqt Date: 2013-01-20 20:56:04 +0000 (Sun, 20 Jan 2013) Log Message: ----------- enable namespace filter for all referring pages
Modified Paths: -------------- trunk/pywikipedia/template.py
Modified: trunk/pywikipedia/template.py =================================================================== --- trunk/pywikipedia/template.py 2013-01-20 16:20:49 UTC (rev 10962) +++ trunk/pywikipedia/template.py 2013-01-20 20:56:04 UTC (rev 10963) @@ -108,7 +108,8 @@ import re, sys, string import wikipedia as pywikibot from pywikibot import i18n -import config, pagegenerators, catlib +import config, catlib +import pagegenerators as pg import replace
def UserEditFilterGenerator(generator, username, timestamp=None, skip=False): @@ -282,11 +283,10 @@ templates = {} subst = False remove = False - namespaces = [] editSummary = '' addedCat = '' acceptAll = False - genFactory = pagegenerators.GeneratorFactory() + genFactory = pg.GeneratorFactory() # If xmlfilename is None, references will be loaded from the live wiki. xmlfilename = None user = None @@ -340,23 +340,25 @@ oldTemplates = [] ns = pywikibot.getSite().template_namespace() for templateName in templates.keys(): - oldTemplate = pywikibot.Page(pywikibot.getSite(), templateName, defaultNamespace=10) + oldTemplate = pywikibot.Page(pywikibot.getSite(), templateName, + defaultNamespace=10) oldTemplates.append(oldTemplate)
if xmlfilename: gen = XmlDumpTemplatePageGenerator(oldTemplates, xmlfilename) + elif user: + gen = UserEditFilterGenerator(gen, user, timestamp, skip) else: gen = genFactory.getCombinedGenerator() if not gen: - gens = [] - gens = [pagegenerators.ReferringPageGenerator( - t, onlyTemplateInclusion=True) for t in oldTemplates] - gen = pagegenerators.CombinedPageGenerator(gens) - gen = pagegenerators.DuplicateFilterPageGenerator(gen) + gens = [pg.ReferringPageGenerator(t, onlyTemplateInclusion=True) + for t in oldTemplates] + gen = pg.CombinedPageGenerator(gens) + gen = pg.NamespaceFilterPageGenerator(gen, + map(int, genFactory.namespaces)) + gen = pg.DuplicateFilterPageGenerator(gen)
- if user: - gen = UserEditFilterGenerator(gen, user, timestamp, skip) - preloadingGen = pagegenerators.PreloadingGenerator(gen) + preloadingGen = pg.PreloadingGenerator(gen)
bot = TemplateRobot(preloadingGen, templates, subst, remove, editSummary, acceptAll, addedCat)
pywikipedia-svn@lists.wikimedia.org