Revision: 5177 Author: cosoleto Date: 2008-04-02 14:48:54 +0000 (Wed, 02 Apr 2008)
Log Message: -----------
* Detect MediaWiki Long Page Error. * Added un notify_unflagged_bot variable (default: true) to disable the warning (it appears repetitively also when getting pages)
Modified Paths: -------------- trunk/pywikipedia/config.py trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/config.py =================================================================== --- trunk/pywikipedia/config.py 2008-04-02 14:01:26 UTC (rev 5176) +++ trunk/pywikipedia/config.py 2008-04-02 14:48:54 UTC (rev 5177) @@ -45,8 +45,8 @@ disambiguation_comment = {} gdab_namespaces = {}
-# Solve captchas in the webbrowser. Setting this to False will result in the -# exception CaptchaError be thrown if a captcha is encountered. +# Solve captchas in the webbrowser. Setting this to False will result in the +# exception CaptchaError be thrown if a captcha is encountered. solve_captcha = True
# Some sites will require password identication to access the HTML pages at @@ -82,6 +82,9 @@ sysopnames[familyName] = {} disambiguation_comment[familyName] = {}
+# Display a warning message if your edits appear in recent changes page +notify_unflagged_bot = True + # Set to True to override the {{bots}} exclusion protocol (at your own risk!) ignore_bot_templates = False
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2008-04-02 14:01:26 UTC (rev 5176) +++ trunk/pywikipedia/wikipedia.py 2008-04-02 14:48:54 UTC (rev 5177) @@ -25,6 +25,7 @@ PageNotSaved: Saving the page has failed EditConflict: PageNotSaved due to edit conflict while uploading SpamfilterError: PageNotSaved due to MediaWiki spam filter + LongPageError: PageNotSaved due to length limit ServerError: Got unexpected response from wiki server BadTitle: Server responded with BadTitle UserBlocked: Client's username or IP has been blocked @@ -183,6 +184,12 @@ self.url = arg self.args = arg,
+class LongPageError(PageNotSaved): + """Saving the page has failed because it is too long.""" + def __init__(self, arg, arg2): + self.length = arg + self.limit = arg2, + class ServerError(Error): """Got unexpected server response"""
@@ -1352,6 +1359,15 @@ if retry_delay > 30: retry_delay = 30 continue + if self.site().has_mediawiki_message('longpageerror'): + long_page_errorR = re.compile( + html2unicode( + self.site().mediawiki_message('longpageerror') + ).replace("$1", "(?P<length>[\d,. ]+)").replace("$2", "(?P<limit>[\d,. ]+)") + ) + match = long_page_errorR.search(data) + if match: + raise LongPageError(match.group('length'), match.group('limit'))
# We are expecting a 302 to the action=view page. I'm not sure why this was removed in r5019 if data.strip() != u"": @@ -4235,7 +4251,7 @@ # Don't show warnings for not logged in users, they will just fail to # do any action if self._isLoggedIn[index]: - if 'bot' not in self._rights[index]: + if 'bot' not in self._rights[index] and config.notify_unflagged_bot: if sysop: output(u'Note: Your sysop account on %s does not have a bot flag. Its edits will be visible in the recent changes.' % self) else: