http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10768
Revision: 10768
Author: drtrigon
Date: 2012-12-07 20:14:41 +0000 (Fri, 07 Dec 2012)
Log Message:
-----------
new feature; user sandbox clean-up from trunk
Modified Paths:
--------------
branches/rewrite/scripts/clean_sandbox.py
Modified: branches/rewrite/scripts/clean_sandbox.py
===================================================================
--- branches/rewrite/scripts/clean_sandbox.py 2012-12-06 09:07:42 UTC (rev 10767)
+++ branches/rewrite/scripts/clean_sandbox.py 2012-12-07 20:14:41 UTC (rev 10768)
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
"""
-This bot cleans a sandbox by replacing the current contents with
+This bot cleans a (user) sandbox by replacing the current contents with
predefined text.
This script understands the following command-line arguments:
@@ -14,6 +14,17 @@
hours and limits it between 5 and 15 minutes.
The minimum delay time is 5 minutes.
+ -user Use this parameter to run the script in the user name-
+ space.
+ > ATTENTION: on most wiki THIS IS FORBIDEN FOR BOTS ! <
+ > (please talk with your admin first) <
+ Since it is considered bad style to edit user page with-
+ out permission, the 'user_sandboxTemplate' for given
+ language has to be set-up (no fall-back will be used).
+ All pages containing that template will get cleaned.
+ Please be also aware that the rules when to clean the
+ user sandbox differ from those for project sandbox.
+
"""
#
# (C) Leonardo Gregianin, 2006
@@ -21,6 +32,7 @@
# (C) Andre Engels, 2007
# (C) Siebrand Mazeland, 2007
# (C) xqt, 2009-2012
+# (C) Dr. Trigon, 2012
#
# Distributed under the terms of the MIT license.
#
@@ -103,13 +115,21 @@
'zh': u'Project:沙盒',
}
+user_content = {
+ 'de': u'{{Benutzer:DrTrigonBot/Spielwiese}}',
+ }
+user_sandboxTemplate = {
+ 'de': u'User:DrTrigonBot/Spielwiese',
+ }
+
class SandboxBot(pywikibot.Bot):
availableOptions = {
'hours': 1,
'no_repeat': True,
'delay': None,
'delay_td': None,
+ 'user': False,
}
def __init__(self, **kwargs):
@@ -123,6 +143,15 @@
self.site = pywikibot.Site()
self.site.login()
+ if self.getOption('user'):
+ localSandboxTitle = pywikibot.translate(self.site, user_sandboxTemplate)
+ localSandbox = pywikibot.Page(self.site, localSandboxTitle)
+ content.update(user_content)
+ sandboxTitle[self.site.lang] = [item.title() \
+ for item in localSandbox.getReferences(onlyTemplateInclusion=True)]
+ if self.site.lang not in user_sandboxTemplate:
+ content[self.site.code] = None
+ pywikibot.output(u'Not properly set-up to run in user namespace!')
if sandboxTitle.get(self.site.code) is None or \
content.get(self.site.code) is None:
pywikibot.output(u'This bot is not configured for the given site ' \
@@ -155,9 +184,18 @@
elif subst and sandboxPage.userName() == mySite.user():
pywikibot.output(u'The sandbox might be clean, no change necessary.')
elif pos <> 0 and not subst:
- sandboxPage.put(translatedContent, translatedMsg)
- pywikibot.showDiff(text, translatedContent)
- pywikibot.output(u'Standard content was changed, sandbox cleaned.')
+ if self.getOption('user'):
+ endpos = pos + len(translatedContent.strip())
+ if (pos < 0) or (endpos == len(text)):
+ pywikibot.output(u'The user sandbox is still clean, no change necessary.')
+ else:
+ sandboxPage.put(text[:endpos], translatedMsg)
+ pywikibot.showDiff(text, text[:endpos])
+ pywikibot.output(u'Standard content was changed, user sandbox cleaned.')
+ else:
+ sandboxPage.put(translatedContent, translatedMsg)
+ pywikibot.showDiff(text, translatedContent)
+ pywikibot.output(u'Standard content was changed, sandbox cleaned.')
else:
edit_delta = datetime.datetime.utcnow() - \
pywikibot.Timestamp.fromISOformat(sandboxPage.editTime())
@@ -193,6 +231,8 @@
opts['no_repeat'] = False
elif arg.startswith('-delay:'):
opts['delay'] = int(arg[7:])
+ elif arg == '-user':
+ opts['user'] = True
else:
pywikibot.showHelp('clean_sandbox')
return
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10767
Revision: 10767
Author: xqt
Date: 2012-12-06 09:07:42 +0000 (Thu, 06 Dec 2012)
Log Message:
-----------
mw 1.21wmf5
Modified Paths:
--------------
branches/rewrite/pywikibot/family.py
trunk/pywikipedia/family.py
Modified: branches/rewrite/pywikibot/family.py
===================================================================
--- branches/rewrite/pywikibot/family.py 2012-12-06 09:00:54 UTC (rev 10766)
+++ branches/rewrite/pywikibot/family.py 2012-12-06 09:07:42 UTC (rev 10767)
@@ -823,7 +823,7 @@
"""Return MediaWiki version number as a string."""
# Don't use this, use versionnumber() instead. This only exists
# to not break family files.
- return '1.21wmf4'
+ return '1.21wmf5'
def versionnumber(self, code):
"""Return an int identifying MediaWiki version.
Modified: trunk/pywikipedia/family.py
===================================================================
--- trunk/pywikipedia/family.py 2012-12-06 09:00:54 UTC (rev 10766)
+++ trunk/pywikipedia/family.py 2012-12-06 09:07:42 UTC (rev 10767)
@@ -4090,7 +4090,7 @@
"""Return MediaWiki version number as a string."""
# Don't use this, use versionnumber() instead. This only exists
# to not break family files.
- return '1.21wmf4'
+ return '1.21wmf5'
def versionnumber(self, code, version=None):
"""Return an int identifying MediaWiki version.
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10766
Revision: 10766
Author: xqt
Date: 2012-12-06 09:00:54 +0000 (Thu, 06 Dec 2012)
Log Message:
-----------
strip trailing whitespace, some PEP8
Modified Paths:
--------------
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2012-12-06 08:58:32 UTC (rev 10765)
+++ trunk/pywikipedia/wikipedia.py 2012-12-06 09:00:54 UTC (rev 10766)
@@ -4018,6 +4018,7 @@
return (u'purged' in r)
+
class wikidataPage(Page):
"""A subclass of Page representing a page on wikidata.
@@ -4027,14 +4028,16 @@
"""
def __init__(self, site, title, insite=False):
- Page.__init__(self, getSite('wikidata',fam='wikidata'), title, insite, defaultNamespace=0)
- def setitem(self,summary=None, watchArticle=False, minorEdit=True,
+ Page.__init__(self, getSite('wikidata', fam='wikidata'), title, insite,
+ defaultNamespace=0)
+
+ def setitem(self, summary=None, watchArticle=False, minorEdit=True,
newPage=False, token=None, newToken=False, sysop=False,
- captcha=None, botflag=True, maxTries=-1,items={}):
+ captcha=None, botflag=True, maxTries=-1, items={}):
"""Setting items on a specific page
items : a dictionary of item(s) you want to add, use of these ways:
- items={'type':u'item', 'label':'fa', 'value':'OK'}) #for change Persian language label of a page to "OK"
- items={'type':u'description', 'language':'en', 'value':'OK'}) #for change English language description of a page to "OK"
+ items={'type':u'item', 'label':'fa', 'value':'OK'}) #for change Persian language label of a page to "OK"
+ items={'type':u'description', 'language':'en', 'value':'OK'}) #for change English language description of a page to "OK"
items={'type':u'sitelink', 'site':'de', 'title':'OK'}) #for change German language sitelink of a page to "OK"
"""
retry_attempt = 0
@@ -4045,7 +4048,7 @@
'summary': self._encodeArg(summary, 'summary'),
}
params['site'] = 'enwiki' #I'm working on making more flexible so i'll change that
- params['action'] = u'wbset'+items['type']
+ params['action'] = u'wbset' + items['type']
params['format'] = 'jsonfm'
if items['type'] == u'item':
params['data'] = u'{"labels":{"%(label)s":{"language":"%(label)s","value":"%(value)s"}}}' \
@@ -4133,6 +4136,8 @@
if data['success'] == u"1":
return 302, response.msg, data['success']
return response.code, response.msg, data
+
+
class ImagePage(Page):
"""A subclass of Page representing an image descriptor wiki page.
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10764
Revision: 10764
Author: valhallasw
Date: 2012-12-03 16:31:53 +0000 (Mon, 03 Dec 2012)
Log Message:
-----------
Bugfix for r10752
Do not import pywikibot from files that may be imported from wikipedia.py,
as pywikibot is only fully populated *after* wikipedia.py has been fully
imported...
Test case: mylang = family = 'commons'
>>> import wikipedia
Traceback (most recent call last):
File "/home/project/d/e/l/delinker/cdh/delinker.py", line 5, in <module>
import wikipedia, config
File "/home/project/d/e/l/delinker/cdh/wikipedia.py", line 8346, in <module>
getSite(noLogin=True)
File "/home/project/d/e/l/delinker/cdh/pywikibot/support.py", line 115, in wrapper
return method(*__args, **__kw)
File "/home/project/d/e/l/delinker/cdh/wikipedia.py", line 8106, in getSite
_sites[key] = Site(code=code, fam=fam, user=user)
File "/home/project/d/e/l/delinker/cdh/pywikibot/support.py", line 115, in wrapper
return method(*__args, **__kw)
File "/home/project/d/e/l/delinker/cdh/wikipedia.py", line 5356, in __init__
if self.__code not in self.languages():
File "/home/project/d/e/l/delinker/cdh/wikipedia.py", line 5471, in languages
return self.family.iwkeys
File "/home/project/d/e/l/delinker/cdh/family.py", line 3851, in iwkeys
return pywikibot.Family(self.interwiki_forward).langs.keys()
AttributeError: 'module' object has no attribute 'Family'
Modified Paths:
--------------
trunk/pywikipedia/family.py
Modified: trunk/pywikipedia/family.py
===================================================================
--- trunk/pywikipedia/family.py 2012-12-02 19:54:40 UTC (rev 10763)
+++ trunk/pywikipedia/family.py 2012-12-03 16:31:53 UTC (rev 10764)
@@ -12,7 +12,7 @@
import urllib
from datetime import timedelta, datetime
-import pywikibot
+import wikipedia as pywikibot
# Parent class for all wiki families