Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
else:
genFactory.handleArg(arg)
if not summary:
mysite = pywikibot.getSite()
if arg.startswith('-category'):
summary = i18n.twtranslate(mysite, 'delete-from-category',{'page': pageName})
elif arg.startswith('-links'):
summary = i18n.twtranslate(mysite, 'delete-linked-pages', {'page': pageName})
elif arg.startswith('-ref'):
summary = i18n.twtranslate(mysite, 'delete-referring-pages', {'page': pageName})
elif arg.startswith('-file'):
summary = i18n.twtranslate(mysite, 'delete-from-file')
mysite = pywikibot.getSite()
if doImages:
if not summary:
summary = i18n.twtranslate(mysite, 'delete-images',
{'page': pageName})
page = pywikibot.Page(mysite, pageName)
generator = pagegenerators.ImagesPageGenerator(page)
if not summary:
summary = pywikibot.input(u'Enter a reason for the %sdeletion:'
% ['', 'un'][undelete])
if not generator:
generator = genFactory.getCombinedGenerator()
if not generator:
# syntax error, show help text from the top of this file
pywikibot.showHelp('delete')
return
if generator:
pywikibot.setAction(summary)
# We are just deleting pages, so we have no need of using a preloading
# page generator to actually get the text of those pages.
"""
# Remove all substed CFD templates
REGEX = (r'.*?'
r'\n?')
match = re.compile(REGEX,
re.IGNORECASE | re.MULTILINE | re.DOTALL)
self.newcat.text = match.sub('', self.newcat.text)
# Remove all language-specified, non substed CFD templates
site_templates = i18n.translate(self.site, cfd_templates) or ()
for template_name in site_templates:
match = re.compile(r'{{%s.*?}}' % template_name, re.IGNORECASE)
self.newcat.text = match.sub('', self.newcat.text)
# Remove leading whitespace
self.newcat.text = self.newcat.text.lstrip()
if not summary:
summary = i18n.twtranslate(self.site,
'category-strip-cfd-templates')
if commit:
self.newcat.save(summary=summary)
page_cap = pywikibot.Page(self.site, page_t.capitalize())
if page_cap.exists():
pywikibot.output(u'%s already exists, skipping...\n'
% page_cap.title(asLink=True))
else:
pywikibot.output(u'[[%s]] doesn\'t exist' % page_cap.title())
if not self.acceptall:
choice = pywikibot.inputChoice(
u'Do you want to create a redirect?',
['Yes', 'No', 'All', 'Quit'], ['y', 'N', 'a', 'q'], 'N')
if choice == 'a':
self.acceptall = True
elif choice == 'q':
self.done = True
if self.acceptall or choice == 'y':
comment = i18n.twtranslate(self.site,
'capitalize_redirects-create-redirect',
{'to': page_t})
try:
page_cap.put(u"#%s %s" % (self.site.redirect(),
page.title(asLink=True,
textlink=True)),
comment)
except:
pywikibot.output(u"An error occurred, skipping...")
header = line[2:-2].strip()
if header is not None:
log_items.setdefault(header, [])
log_items[header].append(line)
if len(log_items) < LOG_SIZE:
return log_text
# sort by keys and keep the first (LOG_SIZE-1) values
keep = [text for (key, text) in
sorted(log_items.items(), reverse=True)[:LOG_SIZE - 1]]
log_text = '\n'.join('\n'.join(line for line in text) for text in keep)
# get permalink to older logs
history = list(self.log_page.revisions(total=LOG_SIZE))
# get the id of the newest log being archived
rotate_revid = history[-1].revid
# append permalink
message = i18n.twtranslate(
self.site,
'category_redirect-older-logs',
{'oldlogs': self.log_page.permalink(oldid=rotate_revid)})
log_text += ('\n\n' + message)
return log_text
def PutNewPage(self, pageObj, pageTxt, msg):
"""Save new page."""
title = pageObj.title(as_link=True, textlink=True)
coloredMsg = ', '.join([self.ColorCodeWord(m) for m in msg])
if pageObj.text == pageTxt:
self.WikiLog('* Error: Text replacement failed in %s (%s)'
% (self.MakeLink(title, False), coloredMsg))
else:
pywikibot.output('Case Replacements: {}'.format(', '.join(msg)))
pageObj.text = pageTxt
try:
pageObj.save(
'{}: {}'.format(
i18n.twtranslate(
self.site, 'casechecker-replacement-summary'),
self.site.mediawiki_message(
'comma-separator').join(msg)))
return True
except KeyboardInterrupt:
raise
except (pywikibot.LockedPage, pywikibot.PageNotSaved):
self.WikiLog('* Error: Could not save updated page %s (%s)'
% (self.MakeLink(title, False), coloredMsg))
return False
if pywikibot.Page(pywikibot.getSite('commons', 'commons'), u'File:' + filename).exists():
#Get a fresh copy, force to get the page so we dont run into edit conflicts
imtxt=imagepage.get(force=True)
#Remove the move to commons templates
if imagepage.site().language() in moveToCommonsTemplate:
for moveTemplate in moveToCommonsTemplate[imagepage.site().language()]:
imtxt = re.sub(u'(?i)\{\{' + moveTemplate + u'[^\}]*\}\}', u'', imtxt)
#add {{NowCommons}}
if imagepage.site().language() in nowCommonsTemplate:
addTemplate = nowCommonsTemplate[imagepage.site().language()] % filename
else:
addTemplate = nowCommonsTemplate['_default'] % filename
commentText = i18n.twtranslate(imagepage.site(),
'commons-file-now-available',
{'localfile': imagepage.title(withNamespace=False),
'commonsfile': filename})
pywikibot.showDiff(imagepage.get(), imtxt + addTemplate)
imagepage.put(imtxt + addTemplate, comment = commentText)
# many arguments for format string
except TypeError:
self.comment = i18n.translate(
self.mysite,
config.disambiguation_comment[self.mysite.family.name],
fallback=True) % disambPage.title()
elif disambPage.isRedirectPage():
# when working on redirects, there's another summary message
if unlink_counter and not new_targets:
self.comment = i18n.twtranslate(
self.mysite,
'solve_disambiguation-redirect-removed',
{'from': disambPage.title(),
'count': unlink_counter})
elif dn and not new_targets:
self.comment = i18n.twtranslate(
self.mysite,
'solve_disambiguation-redirect-adding-dn-template',
{'from': disambPage.title()})
else:
self.comment = i18n.twtranslate(
self.mysite, 'solve_disambiguation-redirect-resolved',
{'from': disambPage.title(),
'to': targets,
'count': len(new_targets)})
else:
if unlink_counter and not new_targets:
self.comment = i18n.twtranslate(
self.mysite, 'solve_disambiguation-links-removed',
{'from': disambPage.title(),
'count': unlink_counter})
elif dn and not new_targets:
})
self.log_text.append(message)
oldtext = cat.text
# remove the old redirect from the old text,
# leaving behind any non-redirect text
oldtext = template_regex.sub('', oldtext)
newtext = ('{{%(redirtemp)s|%(ncat)s}}'
% {'redirtemp': self.template_list[0],
'ncat': double.title(with_ns=False)})
newtext = newtext + oldtext.strip()
try:
cat.text = newtext
cat.save(i18n.twtranslate(self.site,
self.dbl_redir_comment))
except pywikibot.Error as e:
message = i18n.twtranslate(
self.site, 'category_redirect-log-failed',
{'error': e})
self.log_text.append(message)
continue
found, moved = self.move_contents(cat_title,
dest.title(with_ns=False),
editSummary=comment)
if found is None:
message = i18n.twtranslate(
self.site, 'category_redirect-log-move-error', {
'oldcat': cat.title(as_link=True, textlink=True)
})
self.log_text.append(message)
elif found:
record[cat_title][today] = found
if page_name:
if arg.startswith(('-cat', '-subcats')):
summary = i18n.twtranslate(mysite, 'delete-from-category',
{'page': page_name})
elif arg.startswith('-links'):
summary = i18n.twtranslate(mysite,
un + 'delete-linked-pages',
{'page': page_name})
elif arg.startswith('-ref'):
summary = i18n.twtranslate(
mysite, 'delete-referring-pages', {'page': page_name})
elif arg.startswith('-imageused'):
summary = i18n.twtranslate(mysite, un + 'delete-images',
{'page': page_name})
elif arg.startswith('-file'):
summary = i18n.twtranslate(mysite, un + 'delete-from-file')
generator = gen_factory.getCombinedGenerator()
# We are just deleting pages, so we have no need of using a preloading
# page generator to actually get the text of those pages.
if generator:
if summary is None:
summary = pywikibot.input('Enter a reason for the {}deletion:'
.format(['', 'un'][options
.get('undelete', False)]))
bot = DeletionRobot(generator, summary, **options)
bot.run()
return True
else:
pywikibot.bot.suggest_help(missing_generator=True)
return False