[Pywikipedia-l] SVN: [5376] trunk/pywikipedia/wikipedia.py
nicdumz at svn.wikimedia.org
nicdumz at svn.wikimedia.org
Wed May 14 20:37:14 UTC 2008
Revision: 5376
Author: nicdumz
Date: 2008-05-14 20:37:13 +0000 (Wed, 14 May 2008)
Log Message:
-----------
Adding support for the anti external links captcha.
Modified Paths:
--------------
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2008-05-14 19:52:36 UTC (rev 5375)
+++ trunk/pywikipedia/wikipedia.py 2008-05-14 20:37:13 UTC (rev 5376)
@@ -1259,7 +1259,8 @@
newPage, self.site().getToken(sysop = sysop), sysop = sysop)
def _putPage(self, text, comment=None, watchArticle=False, minorEdit=True,
- newPage=False, token=None, newToken=False, sysop=False):
+ newPage=False, token=None, newToken=False, sysop=False,
+ captchaId=None, captchaAnswer=None ):
"""Upload 'text' as new content of Page by filling out the edit form.
Don't use this directly, use put() instead.
@@ -1277,6 +1278,9 @@
'wpSummary': encodedComment,
'wpTextbox1': encodedText,
}
+ if captchaId:
+ predata["wpCaptchaId"] = captchaId
+ predata["wpCaptchaWord"] = captchaAnswer
# Add server lag parameter (see config.py for details)
if config.maxlag:
predata['maxlag'] = str(config.maxlag)
@@ -1453,6 +1457,18 @@
longpage_limit = match.group('limit')
raise LongPageError(longpage_length, longpage_limit)
+ # We might have been prompted for a captcha if the
+ # account is not autoconfirmed, checking....
+ captchaR = re.compile('<input type="hidden" name="wpCaptchaId" id="wpCaptchaId" value="(?P<id>\d+)" />')
+ match = captchaR.search(data)
+ if match:
+ id = match.group('id')
+ if not config.solve_captcha:
+ raise wikipedia.CaptchaError(id)
+ url = self.site().protocol() + '://' + self.site().hostname() + self.site().captcha_image_address(id)
+ answer = ui.askForCaptcha(url)
+ return self._putPage(text, comment, watchArticle, minorEdit, newPage, token, newToken, sysop, captchaId=id, captchaAnswer = answer)
+
# We are expecting a 302 to the action=view page. I'm not sure why this was removed in r5019
if data.strip() != u"":
# Something went wrong, and we don't know what. Show the
More information about the Pywikipedia-l
mailing list