jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1312261?usp=email )
Change subject: [fix] Use i18n._altlang for Accept-Language in weblinkchecker.py
......................................................................
[fix] Use i18n._altlang for Accept-Language in weblinkchecker.py
The Accept-Language header sent when checking external links was
hardcoded to prefer German, regardless of which wiki the bot was
running on. This built the header dynamically instead: the site's
own language first, then known fallbacks via i18n._altlang(), then
English, with decreasing quality values.
Tested with 'ru' (no fallback, just adds English) and 'bar'
(correctly falls back to 'de' before English).
Bug: T417572
Change-Id: Iea819c7dbda85f108fc9c2eb0d093c79fcd822bd
---
M scripts/weblinkchecker.py
1 file changed, 12 insertions(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/weblinkchecker.py b/scripts/weblinkchecker.py
index 2fd637c..3193611 100755
--- a/scripts/weblinkchecker.py
+++ b/scripts/weblinkchecker.py
@@ -251,10 +251,21 @@
self.history = history
# use preferred site encodings
encodings = ','.join(self.page.site.encodings())
+
+ # build Accept-Language header: site language first, then its
+ # known fallback languages, then English, each with a
+ # decreasing quality value
+ lang = self.page.site.lang
+ langs = [lang, *i18n._altlang(lang), 'en']
+ accept_language = ','.join(
+ code if i == 0 else f'{code};q={max(0.1, 1 - i * 0.2):.1f}'
+ for i, code in enumerate(langs)
+ )
+
self.header = {
'Accept': 'text/xml,application/xml,application/xhtml+xml,'
'text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
- 'Accept-Language': 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3',
+ 'Accept-Language': accept_language,
'Accept-Charset': f'{encodings};q=0.8,*;q=0.7',
'Keep-Alive': '30',
'Connection': 'keep-alive',
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1312261?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Iea819c7dbda85f108fc9c2eb0d093c79fcd822bd
Gerrit-Change-Number: 1312261
Gerrit-PatchSet: 3
Gerrit-Owner: Nihar_Chakravarti <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]