Ladsgroup has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/147381

Change subject: Add option of user_agent in user-config.py
......................................................................

Add option of user_agent in user-config.py

The default will be username and if the person doesn't
want to add any kind of contacting information, just set it to " "

Change-Id: If1bfcbb62e0bf126abc2b5847d03e7e004c7bfe4
---
M pywikibot/comms/http.py
M pywikibot/config2.py
2 files changed, 13 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/81/147381/1

diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index 4f69291..a6bc024 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -43,11 +43,13 @@
     import Queue
     import urlparse
     import cookielib
+    from urllib2 import quote
 else:
     from ssl import SSLError as SSLHandshakeError
     import queue as Queue
     import urllib.parse as urlparse
     from http import cookiejar as cookielib
+    from urlparse import quote
 
 from pywikibot import config
 from pywikibot.exceptions import FatalServerError, Server504Error
@@ -147,10 +149,14 @@
         baseuri = urlparse.urljoin("%(proto)s://%(host)s" % locals(), uri)
     else:
         baseuri = uri
-
     # set default user-agent string
     kwargs.setdefault("headers", {})
     kwargs["headers"].setdefault("user-agent", useragent)
+    # add contact information to user agent
+    if config.user_agent == "":
+        kwargs["headers"]["user-agent"] += " (User:%s)" % 
quote(site.username())
+    if config.user_agent.strip():
+        kwargs["headers"]["user-agent"] += " (%s)" % quote(config.user_agent)
     request = threadedhttp.HttpRequest(baseuri, *args, **kwargs)
     http_queue.put(request)
     while not request.lock.acquire(False):
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index 2d3ce38..718faeb 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -57,6 +57,12 @@
 sysopnames = {}
 disambiguation_comment = {}
 
+# The contact information that has been added to user agent. The default is 
username
+# For more information see https://meta.wikimedia.org/wiki/User-agent_policy
+# If you don't want to add any contacting information to user agent, 
+# you can set it to " " in user-config.py
+user_agent = ""
+
 # The default interface for communicating with the site
 # currently the only defined interface is 'APISite', so don't change this!
 site_interface = 'APISite'

-- 
To view, visit https://gerrit.wikimedia.org/r/147381
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If1bfcbb62e0bf126abc2b5847d03e7e004c7bfe4
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to