jenkins-bot has submitted this change and it was merged.
Change subject: Namespace filtering in replace.py ......................................................................
Namespace filtering in replace.py
The namespace filtering (-namespace, -ns) was broken in core for replace.py, leading to changes intended for one (or more) namespace(s) bleeding into others.
This commit reintroduces the logic from the compat tree.
This commmit also removes the redundant handling of -page/PageTitles; that argument is handled by pagegenerators.
Bug: 57303
Change-Id: I05845e6962fbae92719e2a128bb93de6044c2ed5 --- M pywikibot/pagegenerators.py M scripts/replace.py 2 files changed, 7 insertions(+), 13 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py index 025c732..b525839 100644 --- a/pywikibot/pagegenerators.py +++ b/pywikibot/pagegenerators.py @@ -208,11 +208,15 @@ if self.site is None: self.site = pywikibot.Site()
- def getCombinedGenerator(self): + def getCombinedGenerator(self, gen=None): """Return the combination of all accumulated generators.
Only call this after all arguments have been parsed. """ + + if gen: + self.gens.insert(0, gen) + namespaces = [int(n) for n in self.namespaces] for i in range(len(self.gens)): if isinstance(self.gens[i], pywikibot.data.api.QueryGenerator): diff --git a/scripts/replace.py b/scripts/replace.py index 75b0ccf..d109a36 100755 --- a/scripts/replace.py +++ b/scripts/replace.py @@ -464,7 +464,6 @@ # if -xml flag is present xmlFilename = None useSql = False - PageTitles = [] # will become True when the user presses a ('yes to all') or uses the # -always flag. acceptall = False @@ -505,12 +504,6 @@ xmlFilename = arg[5:] elif arg == '-sql': useSql = True - elif arg.startswith('-page'): - if len(arg) == 5: - PageTitles.append(pywikibot.input( - u'Which page do you want to change?')) - else: - PageTitles.append(arg[6:]) elif arg.startswith('-excepttitle:'): exceptions['title'].append(arg[13:]) elif arg.startswith('-requiretitle:'): @@ -545,7 +538,6 @@ else: commandline_replacements.append(arg) pywikibot.Site().login() - gen = genFactory.getCombinedGenerator() if (len(commandline_replacements) % 2): raise pywikibot.Error('require even number of replacements.') elif (len(commandline_replacements) == 2 and fix is None): @@ -677,10 +669,8 @@ %s LIMIT 200""" % (whereClause, exceptClause) gen = pagegenerators.MySQLPageGenerator(query) - elif PageTitles: - pages = [pywikibot.Page(pywikibot.Site(), PageTitle) - for PageTitle in PageTitles] - gen = iter(pages) + + gen = genFactory.getCombinedGenerator(gen)
if not gen: # syntax error, show help text from the top of this file
pywikibot-commits@lists.wikimedia.org