jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/423234 )
Change subject: Implement a workaround to generate family file for private wikis ......................................................................
Implement a workaround to generate family file for private wikis
After this change, upon detection of a private wiki during a generate_family_file.py run, the user will be asked for their username and password which enables the script to login into the site, gather siteinfo, and generate the family file successfully.
Bug: T153891 Change-Id: I9993340d76aeed6734f371f40ef65624601c62ea --- M pywikibot/data/api.py M pywikibot/site_detect.py 2 files changed, 20 insertions(+), 4 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py index 1f8ca1f..e1c41ae 100644 --- a/pywikibot/data/api.py +++ b/pywikibot/data/api.py @@ -3079,7 +3079,7 @@ if MediaWikiVersion(self.site.version()) >= MediaWikiVersion('1.27'): login_request["lgtoken"] = self.get_login_token()
- self.site._loginstatus = -2 + self.site._loginstatus = -2 # IN_PROGRESS while True: login_result = login_request.submit() if u"login" not in login_result: diff --git a/pywikibot/site_detect.py b/pywikibot/site_detect.py index a9dea68..56c9b62 100644 --- a/pywikibot/site_detect.py +++ b/pywikibot/site_detect.py @@ -15,6 +15,7 @@ import pywikibot
from pywikibot.comms.http import fetch +from pywikibot import config from pywikibot.exceptions import ServerError from pywikibot.tools import MediaWikiVersion, PY2, PYTHON_VERSION
@@ -172,9 +173,24 @@ self.private_wiki = ('error' in info and info['error']['code'] == 'readapidenied') if self.private_wiki: - return - - info = info['query']['general'] + # user-config.py is not loaded because PYWIKIBOT2_NO_USER_CONFIG + # is set to '2' by generate_family_file.py. + # Prepare a temporary config for login. + username = pywikibot.input( + 'Private wiki detected. Login is required.\n' + 'Please enter your username?') + config.usernames['temporary_family'] = {'temporary_code': username} + # Setup a dummy family so that we can create a site object + fam = pywikibot.Family() + fam.name = 'temporary_family' + fam.scriptpath = lambda code: self.api[:-8] # without /api.php + fam.langs = {'temporary_code': self.server} + site = pywikibot.Site('temporary_code', fam) + site.version = lambda: str(self.version) + # Now the site object is able to login + info = site.siteinfo + else: + info = info['query']['general'] self.version = MediaWikiVersion.from_generator(info['generator']) if self.version < MediaWikiVersion('1.17'): return
pywikibot-commits@lists.wikimedia.org