Jump to content

User:Legobot/userspace.py

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Legoktm (talk | contribs) at 06:40, 3 March 2012 (posting code). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
#!/usr/bin/python
#
# (C) 2012, Legoktm, under the MIT License
# Utilizes the rewrite branch of Pywikipedia
# Checks the new pages list to see whether it should have been made in the userspace, and if so, moves it.
#

import pywikibot
from pywikibot import pagegenerators
site = pywikibot.getSite()

def main():
	#get page list
	gen = pagegenerators.NewpagesPageGenerator()
	for page in gen:
		creator = getVersionHistory(reverseOrder=True, total=1)[0][2]
		if page.title().startswith(creator + '/'):
			old = page.title()
			page.move('User:' + page.title(), reason='Moving accidentally created subpage into userspace')
			#delete newly created redirect
			oldpage = pywikibot.Page(site, old)
			oldpage.put('{{db-r2}}', 'BOT: Nominating for deletion per [[WP:CSD#R2|CSD]]')
		else:
			continue

if __name__ == "__main__":
	main()