Revision: 8376
Author:   russblau
Date:     2010-08-04 14:02:17 +0000 (Wed, 04 Aug 2010)

Log Message:
-----------
Fix bug 3036372 (Missing argument in page.put) - this allows use of the 
"botflag" parameter to .put and .save to override the default behavior, which 
is to set the Bot flag on any edit by a bot account and not to set it on edits 
by non-bot accounts. Use of this flag may be contrary to bot policies on some 
wikis!

Modified Paths:
--------------
    branches/rewrite/pywikibot/page.py
    branches/rewrite/pywikibot/site.py

Modified: branches/rewrite/pywikibot/page.py
===================================================================
--- branches/rewrite/pywikibot/page.py  2010-08-01 13:52:56 UTC (rev 8375)
+++ branches/rewrite/pywikibot/page.py  2010-08-04 14:02:17 UTC (rev 8376)
@@ -638,8 +638,8 @@
         # no restricting template found
         return True
 
-    def save(self, comment=None, watch=None, minor=True, force=False,
-             async=False, callback=None):
+    def save(self, comment=None, watch=None, minor=True, botflag=None,
+             force=False, async=False, callback=None):
         """Save the current contents of page's text to the wiki.
 
         @param comment: The edit summary for the modification (optional, but
@@ -651,6 +651,8 @@
         @type watch: bool or None
         @param minor: if True, mark this edit as minor
         @type minor: bool
+        @param botflag: if True, mark this edit as made by a bot (default:
+            True if user has bot status, False if not)
         @param force: if True, ignore botMayEdit() setting
         @type force: bool
         @param async: if True, launch a separate thread to save
@@ -675,18 +677,22 @@
             raise pywikibot.PageNotSaved(
                 "Page %s not saved; editing restricted by {{bots}} template"
                 % self.title(asLink=True))
+        if botflag is None:
+            botflag = ("bot" in self.site.userinfo["rights"])
         if async:
-            pywikibot.async_request(self._save, comment, minor, watchval,
-                                    async, callback)
+            pywikibot.async_request(self._save, comment=comment, minor=minor,
+                                    watchval=watchval, botflag=botflag,
+                                    async=async, callback=callback)
         else:
-            self._save(comment, minor, watchval, async, callback)
+            self._save(comment=comment, minor=minor, watchval=watchval,
+                       botflag=botflag, async=async, callback=callback)
 
-    def _save(self, comment, minor, watchval, async, callback):
+    def _save(self, comment, minor, watchval, botflag, async, callback):
         err = None
         link = self.title(asLink=True)
         try:
             done = self.site.editpage(self, summary=comment, minor=minor,
-                                        watch=watchval)
+                                      watch=watchval, bot=botflag)
             if not done:
                 pywikibot.warning(u"Page %s not saved" % link)
                 raise pywikibot.PageNotSaved(link)
@@ -707,7 +713,7 @@
             callback(self, err)
 
     def put(self, newtext, comment=u'', watchArticle=None, minorEdit=True,
-            force=False, async=False, callback=None):
+            botflag=None, force=False, async=False, callback=None):
         """Save the page with the contents of the first argument as the text.
 
         This method is maintained primarily for backwards-compatibility.
@@ -719,11 +725,12 @@
 
         """
         self.text = newtext
-        return self.save(comment, watchArticle, minorEdit, force,
-                         async, callback)
+        return self.save(comment=comment, watch=watchArticle,
+                        minor=minorEdit, botflag=botflag, force=force,
+                        async=async, callback=callback)
 
     def put_async(self, newtext, comment=u'', watchArticle=None,
-                  minorEdit=True, force=False, callback=None):
+                  minorEdit=True, botflag=None, force=False, callback=None):
         """Put page on queue to be saved to wiki asynchronously.
 
         Asynchronous version of put (takes the same arguments), which places
@@ -733,8 +740,8 @@
 
         """
         return self.put(newtext, comment=comment, watchArticle=watchArticle,
-                        minorEdit=minorEdit, force=force, async=True,
-                        callback=callback)
+                        minorEdit=minorEdit, botflag=botflag, force=force,
+                        async=True, callback=callback)
 
     def watch(self, unwatch=False):
         """Add or remove this page to/from bot account's watchlist.

Modified: branches/rewrite/pywikibot/site.py
===================================================================
--- branches/rewrite/pywikibot/site.py  2010-08-01 13:52:56 UTC (rev 8375)
+++ branches/rewrite/pywikibot/site.py  2010-08-04 14:02:17 UTC (rev 8376)
@@ -2288,7 +2288,7 @@
     }
 
     def editpage(self, page, summary, minor=True, notminor=False,
-                 recreate=True, createonly=False, watch=None):
+                 bot=True, recreate=True, createonly=False, watch=None):
         """Submit an edited Page object to be saved to the wiki.
 
         @param page: The Page to be saved; its .text property will be used
@@ -2308,6 +2308,7 @@
             * unwatch: remove the page from the watchlist
             * preferences: use the preference settings (Default)
             * nochange: don't change the watchlist
+        @param botflag: if True, mark edit with bot flag
         @return: True if edit succeeded, False if it failed
 
         """
@@ -2331,23 +2332,23 @@
         if lastrev is not None and page.latestRevision() != lastrev:
             raise EditConflict(
                 "editpage: Edit conflict detected; saving aborted.")
-        req = api.Request(site=self, action="edit",
-                          title=page.title(withSection=False),
-                          text=text, token=token, summary=summary)
+        params = dict(action="edit",
+                      title=page.title(withSection=False),
+                      text=text, token=token, summary=summary)
+        if bot:
+            params["bot"] = ""
         if lastrev is not None:
-            req["basetimestamp"] = page._revisions[lastrev].timestamp
+            params["basetimestamp"] = page._revisions[lastrev].timestamp
         if minor:
-            req['minor'] = ""
+            params['minor'] = ""
         elif notminor:
-            req['notminor'] = ""
-        if 'bot' in self.userinfo['groups']:
-            req['bot'] = ""
+            params['notminor'] = ""
         if recreate:
-            req['recreate'] = ""
+            params['recreate'] = ""
         if createonly:
-            req['createonly'] = ""
+            params['createonly'] = ""
         if watch in ["watch", "unwatch", "preferences", "nochange"]:
-            req['watch'] = watch
+            params['watchlist'] = watch
         elif watch:
             pywikibot.warning(
                 u"editpage: Invalid watch value '%(watch)s' ignored."
@@ -2355,7 +2356,8 @@
 ## FIXME: API gives 'badmd5' error
 ##        md5hash = md5()
 ##        md5hash.update(urllib.quote_plus(text.encode(self.encoding())))
-##        req['md5'] = md5hash.digest()
+##        params['md5'] = md5hash.digest()
+        req = api.Request(site=self, **params)
         while True:
             try:
                 result = req.submit()



_______________________________________________
Pywikipedia-svn mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikipedia-svn

Reply via email to