Revision: 4935 Author: rotem Date: 2008-01-24 18:05:50 +0000 (Thu, 24 Jan 2008)
Log Message: ----------- (patch 1878609) Adding -skipredirects option to movepages.py, and after the move, marking the redirect for deletion if requested and no sysop rights are available.
Modified Paths: -------------- trunk/pywikipedia/movepages.py
Modified: trunk/pywikipedia/movepages.py =================================================================== --- trunk/pywikipedia/movepages.py 2008-01-24 17:58:27 UTC (rev 4934) +++ trunk/pywikipedia/movepages.py 2008-01-24 18:05:50 UTC (rev 4935) @@ -11,7 +11,7 @@
-from and -to The page to move from and the page to move to.
--del After moving the page, delete the redirect. +-del After moving the page, delete the redirect or mark it for deletion.
-prefix Move pages by adding a namespace prefix to the names of the pages. (Will remove the old namespace prefix if any) @@ -19,6 +19,8 @@
-always Don't prompt to make changes, just do them.
+-skipredirects Skip redirect pages (Warning: increases server load) + """ # # (C) Leonardo Gregianin, 2006 @@ -64,20 +66,21 @@ }
class MovePagesBot: - def __init__(self, generator, addprefix, delete, always): + def __init__(self, generator, addprefix, delete, always, skipredirects): self.generator = generator self.addprefix = addprefix self.delete = delete self.always = always + self.skipredirects = skipredirects
- def moveOne(self, page, newPageTitle,delete): + def moveOne(self, page, newPageTitle, delete): try: msg = wikipedia.translate(wikipedia.getSite(), summary) wikipedia.output(u'Moving page %s to [[%s]]' % (page.aslink(), newPageTitle)) if page.move(newPageTitle, msg, throttle=True): if delete: deletemsg = wikipedia.translate(wikipedia.getSite(), deletesummary) - page.delete(deletemsg) + page.delete(deletemsg, mark=True) except wikipedia.NoPage: wikipedia.output(u'Page %s does not exist!' % page.title()) except wikipedia.IsRedirectPage: @@ -89,6 +92,9 @@ # Show the title of the page we're working on. # Highlight the title in purple. wikipedia.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"% page.title()) + if self.skipredirects and page.isRedirectPage(): + wikipedia.output(u'Page %s is a redirect; skipping.' % page.title()) + return pagetitle = page.titleWithoutNamespace() namesp = page.site().namespace(page.namespace()) if self.appendAll: @@ -190,6 +196,7 @@ newName = None delete = False always = False + skipredirects = False
# This factory is responsible for processing command line arguments # that are also used by other scripts and that determine on which pages @@ -201,6 +208,8 @@ delete = True elif arg == '-always': always = True + if arg == '-skipredirects': + skipredirects = True elif arg.startswith('-from:'): oldName = arg[len('-from:'):] elif arg.startswith('-to:'): @@ -217,11 +226,11 @@
if oldName and newName: page = wikipedia.Page(wikipedia.getSite(), oldName) - bot = MovePagesBot(None, prefix, delete, always) + bot = MovePagesBot(None, prefix, delete, always, skipredirects) bot.moveOne(page, newName, delete) elif gen: preloadingGen = pagegenerators.PreloadingGenerator(gen) - bot = MovePagesBot(preloadingGen, prefix, delete, always) + bot = MovePagesBot(preloadingGen, prefix, delete, always, skipredirects) bot.run() else: wikipedia.showHelp('movepages')
pywikipedia-l@lists.wikimedia.org