XZise has submitted this change and it was merged.
Change subject: [Bug 55198] Add noredirect option and don't let the bot crash in
redirects
......................................................................
[Bug 55198] Add noredirect option and don't let the bot crash in redirects
noredirect option is easy to implement, fixing redirects is easy by adding
get_redirect = True
Change-Id: I529717bfe10e83233e63f12037a2966cb1178bc9
---
M scripts/pagefromfile.py
1 file changed, 11 insertions(+), 3 deletions(-)
Approvals:
XZise: Looks good to me, approved
diff --git a/scripts/pagefromfile.py b/scripts/pagefromfile.py
index 7b204c2..98df996 100644
--- a/scripts/pagefromfile.py
+++ b/scripts/pagefromfile.py
@@ -28,6 +28,8 @@
titleend, in the page
-nocontent If page has this statment it doesn't append
(example: -nocontent:"{{infobox")
+-noredirect if you don't want to upload on redirect page
+ it is True by default and bot adds pages to redirected pages
-summary:xxx Use xxx as the edit summary for the upload - if
a page exists, standard messages are appended
after xxx for appending, prepending, or replacement
@@ -81,6 +83,7 @@
'minor': False,
'autosummary': False,
'nocontent': '',
+ 'redirect': True
})
super(PageFromFileRobot, self).__init__(**kwargs)
@@ -112,8 +115,11 @@
contents = re.sub('^[\r\n]*', '', contents)
if page.exists():
+ if not self.getOption('redirect') and page.isRedirectPage():
+ pywikibot.output(u"Page %s is redirect, skipping!" % title)
+ return
+ pagecontents = page.get(get_redirect=True)
if self.getOption('nocontent') != u'':
- pagecontents = page.get()
if pagecontents.find(self.getOption('nocontent')) != -1 or \
pagecontents.find(self.getOption('nocontent').lower()) != -1:
pywikibot.output(u'Page has %s so it is skipped' %
self.getOption('nocontent'))
@@ -121,12 +127,12 @@
if self.getOption('append') == 'top':
pywikibot.output(u"Page %s already exists, appending on top!"
% title)
- contents = contents + page.get()
+ contents = contents + pagecontents
comment = comment_top
elif self.getOption('append') == 'bottom':
pywikibot.output(u"Page %s already exists, appending on
bottom!"
% title)
- contents = page.get() + contents
+ contents = pagecontents + contents
comment = comment_bottom
elif self.getOption('force'):
pywikibot.output(u"Page %s already exists, ***overwriting!"
@@ -260,6 +266,8 @@
elif arg == "-safe":
options['force'] = False
options['append'] = None
+ elif arg == "-noredirect":
+ options['redirect'] = False
elif arg == '-notitle':
notitle = True
elif arg == '-minor':
--
To view, visit
https://gerrit.wikimedia.org/r/160023
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I529717bfe10e83233e63f12037a2966cb1178bc9
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>