Edit dogwhistle words

main
Bob Mottram 2022-07-05 18:52:19 +01:00
parent 972c29a9fa
commit 21b5462683
29 changed files with 121 additions and 35 deletions

View File

@ -1097,7 +1097,7 @@ def load_dogwhistles(filename: str) -> {}:
except OSError: except OSError:
print('EX: unable to load dogwhistles from ' + filename) print('EX: unable to load dogwhistles from ' + filename)
return {} return {}
separators = ('->', ',', ';', '|') separators = ('->', '=>', ',', ';', '|', '=')
dogwhistles = {} dogwhistles = {}
for line in dogwhistle_lines: for line in dogwhistle_lines:
line = line.remove_eol(line).strip() line = line.remove_eol(line).strip()
@ -1109,8 +1109,8 @@ def load_dogwhistles(filename: str) -> {}:
category = None category = None
for sep in separators: for sep in separators:
if sep in line: if sep in line:
whistle = line.split(sep, 1)[0] whistle = line.split(sep, 1)[0].strip()
category = line.split(sep, 1)[1] category = line.split(sep, 1)[1].strip()
break break
if not whistle: if not whistle:
whistle = line whistle = line

View File

@ -5106,6 +5106,26 @@ class PubServer(BaseHTTPRequestHandler):
print('EX: _newswire_update unable to delete ' + print('EX: _newswire_update unable to delete ' +
filter_newswire_filename) filter_newswire_filename)
# save dogwhistle words list
dogwhistles_filename = base_dir + '/accounts/dogwhistles.txt'
if fields.get('dogwhistleWords'):
try:
with open(dogwhistles_filename, 'w+',
encoding='utf-8') as fp_dogwhistles:
fp_dogwhistles.write(fields['dogwhistleWords'])
except OSError:
print('EX: unable to write ' + dogwhistles_filename)
self.server.dogwhistles = \
load_dogwhistles(dogwhistles_filename)
else:
if os.path.isfile(dogwhistles_filename):
try:
os.remove(dogwhistles_filename)
except OSError:
print('EX: _newswire_update unable to delete ' +
dogwhistles_filename)
self.server.dogwhistles = {}
# save news tagging rules # save news tagging rules
hashtag_rules_filename = \ hashtag_rules_filename = \
base_dir + '/accounts/hashtagrules.txt' base_dir + '/accounts/hashtagrules.txt'
@ -14978,7 +14998,8 @@ class PubServer(BaseHTTPRequestHandler):
http_prefix, http_prefix,
self.server.default_timeline, self.server.default_timeline,
self.server.theme_name, self.server.theme_name,
access_keys) access_keys,
self.server.dogwhistles)
if msg: if msg:
msg = msg.encode('utf-8') msg = msg.encode('utf-8')
msglen = len(msg) msglen = len(msg)

View File

@ -565,5 +565,7 @@
"Switch to moderation view": "قم بالتبديل إلى عرض الاعتدال", "Switch to moderation view": "قم بالتبديل إلى عرض الاعتدال",
"Minimize attached images": "تصغير الصور المرفقة", "Minimize attached images": "تصغير الصور المرفقة",
"SHOW MEDIA": "عرض الوسائط", "SHOW MEDIA": "عرض الوسائط",
"ActivityPub Specification": "مواصفات ActivityPub" "ActivityPub Specification": "مواصفات ActivityPub",
"Dogwhistle words": "كلمات Dogwhistle",
"Content warnings will be added for the following": "ستتم إضافة تحذيرات المحتوى لما يلي"
} }

View File

@ -565,5 +565,7 @@
"Switch to moderation view": "সংযম দৃশ্যে স্যুইচ করুন", "Switch to moderation view": "সংযম দৃশ্যে স্যুইচ করুন",
"Minimize attached images": "সংযুক্ত ছবি ছোট করুন", "Minimize attached images": "সংযুক্ত ছবি ছোট করুন",
"SHOW MEDIA": "মিডিয়া দেখান", "SHOW MEDIA": "মিডিয়া দেখান",
"ActivityPub Specification": "ActivityPub স্পেসিফিকেশন" "ActivityPub Specification": "ActivityPub স্পেসিফিকেশন",
"Dogwhistle words": "কুকুরের হুইসেল শব্দ",
"Content warnings will be added for the following": "নিম্নলিখিত জন্য বিষয়বস্তু সতর্কতা যোগ করা হবে"
} }

View File

@ -565,5 +565,7 @@
"Switch to moderation view": "Canvia a la visualització de moderació", "Switch to moderation view": "Canvia a la visualització de moderació",
"Minimize attached images": "Minimitzar les imatges adjuntes", "Minimize attached images": "Minimitzar les imatges adjuntes",
"SHOW MEDIA": "MOSTRA ELS MITJANS", "SHOW MEDIA": "MOSTRA ELS MITJANS",
"ActivityPub Specification": "Especificació d'ActivityPub" "ActivityPub Specification": "Especificació d'ActivityPub",
"Dogwhistle words": "Paraules de xiulet",
"Content warnings will be added for the following": "S'afegiran advertències de contingut per al següent"
} }

View File

@ -565,5 +565,7 @@
"Switch to moderation view": "Newid i wedd safoni", "Switch to moderation view": "Newid i wedd safoni",
"Minimize attached images": "Lleihau delweddau sydd ynghlwm", "Minimize attached images": "Lleihau delweddau sydd ynghlwm",
"SHOW MEDIA": "DANGOS CYFRYNGAU", "SHOW MEDIA": "DANGOS CYFRYNGAU",
"ActivityPub Specification": "Manyleb GweithgareddPub" "ActivityPub Specification": "Manyleb GweithgareddPub",
"Dogwhistle words": "Geiriau chwibanogl",
"Content warnings will be added for the following": "Bydd rhybuddion cynnwys yn cael eu hychwanegu ar gyfer y canlynol"
} }

View File

@ -565,5 +565,7 @@
"Switch to moderation view": "Wechseln Sie zur Moderationsansicht", "Switch to moderation view": "Wechseln Sie zur Moderationsansicht",
"Minimize attached images": "Angehängte Bilder minimieren", "Minimize attached images": "Angehängte Bilder minimieren",
"SHOW MEDIA": "MEDIEN ZEIGEN", "SHOW MEDIA": "MEDIEN ZEIGEN",
"ActivityPub Specification": "ActivityPub-Spezifikation" "ActivityPub Specification": "ActivityPub-Spezifikation",
"Dogwhistle words": "Hundepfeife Worte",
"Content warnings will be added for the following": "Inhaltswarnungen werden für Folgendes hinzugefügt"
} }

View File

@ -565,5 +565,7 @@
"Switch to moderation view": "Μετάβαση σε προβολή εποπτείας", "Switch to moderation view": "Μετάβαση σε προβολή εποπτείας",
"Minimize attached images": "Ελαχιστοποιήστε τις συνημμένες εικόνες", "Minimize attached images": "Ελαχιστοποιήστε τις συνημμένες εικόνες",
"SHOW MEDIA": "ΔΕΙΤΕ ΜΕΣΑ", "SHOW MEDIA": "ΔΕΙΤΕ ΜΕΣΑ",
"ActivityPub Specification": "Προδιαγραφές ActivityPub" "ActivityPub Specification": "Προδιαγραφές ActivityPub",
"Dogwhistle words": "Σφυρίχτρα λέξεις",
"Content warnings will be added for the following": "Θα προστεθούν προειδοποιήσεις περιεχομένου για τα ακόλουθα"
} }

View File

@ -565,5 +565,7 @@
"Switch to moderation view": "Switch to moderation view", "Switch to moderation view": "Switch to moderation view",
"Minimize attached images": "Minimize attached images", "Minimize attached images": "Minimize attached images",
"SHOW MEDIA": "SHOW MEDIA", "SHOW MEDIA": "SHOW MEDIA",
"ActivityPub Specification": "ActivityPub Specification" "ActivityPub Specification": "ActivityPub Specification",
"Dogwhistle words": "Dogwhistle words",
"Content warnings will be added for the following": "Content warnings will be added for the following"
} }

View File

@ -565,5 +565,7 @@
"Switch to moderation view": "Cambiar a la vista de moderación", "Switch to moderation view": "Cambiar a la vista de moderación",
"Minimize attached images": "Minimizar imágenes adjuntas", "Minimize attached images": "Minimizar imágenes adjuntas",
"SHOW MEDIA": "MOSTRAR MEDIOS", "SHOW MEDIA": "MOSTRAR MEDIOS",
"ActivityPub Specification": "Especificación de ActivityPub" "ActivityPub Specification": "Especificación de ActivityPub",
"Dogwhistle words": "Palabras de silbato para perros",
"Content warnings will be added for the following": "Se agregarán advertencias de contenido para lo siguiente"
} }

View File

@ -565,5 +565,7 @@
"Switch to moderation view": "Passer en mode modération", "Switch to moderation view": "Passer en mode modération",
"Minimize attached images": "Réduire les images jointes", "Minimize attached images": "Réduire les images jointes",
"SHOW MEDIA": "AFFICHER LES MÉDIAS", "SHOW MEDIA": "AFFICHER LES MÉDIAS",
"ActivityPub Specification": "Spécification ActivityPub" "ActivityPub Specification": "Spécification ActivityPub",
"Dogwhistle words": "Mots de sifflet de chien",
"Content warnings will be added for the following": "Des avertissements de contenu seront ajoutés pour les éléments suivants"
} }

View File

@ -565,5 +565,7 @@
"Switch to moderation view": "Athraigh go dtí an t-amharc modhnóireachta", "Switch to moderation view": "Athraigh go dtí an t-amharc modhnóireachta",
"Minimize attached images": "Íoslaghdaigh íomhánna ceangailte", "Minimize attached images": "Íoslaghdaigh íomhánna ceangailte",
"SHOW MEDIA": "Taispeáin MEÁIN", "SHOW MEDIA": "Taispeáin MEÁIN",
"ActivityPub Specification": "Sonraíocht ActivityPub" "ActivityPub Specification": "Sonraíocht ActivityPub",
"Dogwhistle words": "Focail feadóg mhadra",
"Content warnings will be added for the following": "Cuirfear rabhaidh ábhair leis maidir leis na nithe seo a leanas"
} }

View File

@ -565,5 +565,7 @@
"Switch to moderation view": "मॉडरेशन दृश्य पर स्विच करें", "Switch to moderation view": "मॉडरेशन दृश्य पर स्विच करें",
"Minimize attached images": "संलग्न छवियों को छोटा करें", "Minimize attached images": "संलग्न छवियों को छोटा करें",
"SHOW MEDIA": "मीडिया दिखाएं", "SHOW MEDIA": "मीडिया दिखाएं",
"ActivityPub Specification": "गतिविधिपब विशिष्टता" "ActivityPub Specification": "गतिविधिपब विशिष्टता",
"Dogwhistle words": "कुत्ते की सीटी शब्द",
"Content warnings will be added for the following": "निम्नलिखित के लिए सामग्री चेतावनियां जोड़ दी जाएंगी"
} }

View File

@ -565,5 +565,7 @@
"Switch to moderation view": "Passa alla visualizzazione moderazione", "Switch to moderation view": "Passa alla visualizzazione moderazione",
"Minimize attached images": "Riduci al minimo le immagini allegate", "Minimize attached images": "Riduci al minimo le immagini allegate",
"SHOW MEDIA": "MOSTRA MEDIA", "SHOW MEDIA": "MOSTRA MEDIA",
"ActivityPub Specification": "Specifica ActivityPub" "ActivityPub Specification": "Specifica ActivityPub",
"Dogwhistle words": "Parole da fischietto",
"Content warnings will be added for the following": "Verranno aggiunti avvisi sui contenuti per quanto segue"
} }

View File

@ -565,5 +565,7 @@
"Switch to moderation view": "モデレートビューに切り替えます", "Switch to moderation view": "モデレートビューに切り替えます",
"Minimize attached images": "添付画像を最小限に抑える", "Minimize attached images": "添付画像を最小限に抑える",
"SHOW MEDIA": "メディアを表示", "SHOW MEDIA": "メディアを表示",
"ActivityPub Specification": "ActivityPubの仕様" "ActivityPub Specification": "ActivityPubの仕様",
"Dogwhistle words": "犬笛の言葉",
"Content warnings will be added for the following": "以下のコンテンツ警告が追加されます"
} }

View File

@ -565,5 +565,7 @@
"Switch to moderation view": "검토 보기로 전환", "Switch to moderation view": "검토 보기로 전환",
"Minimize attached images": "첨부된 이미지 최소화", "Minimize attached images": "첨부된 이미지 최소화",
"SHOW MEDIA": "미디어 표시", "SHOW MEDIA": "미디어 표시",
"ActivityPub Specification": "ActivityPub 사양" "ActivityPub Specification": "ActivityPub 사양",
"Dogwhistle words": "개 휘파람 단어",
"Content warnings will be added for the following": "다음에 대한 콘텐츠 경고가 추가됩니다."
} }

View File

@ -565,5 +565,7 @@
"Switch to moderation view": "Biguherîne bo dîtina moderatoriyê", "Switch to moderation view": "Biguherîne bo dîtina moderatoriyê",
"Minimize attached images": "Wêneyên pêvekirî kêm bikin", "Minimize attached images": "Wêneyên pêvekirî kêm bikin",
"SHOW MEDIA": "MEDYA NÎŞAN DE", "SHOW MEDIA": "MEDYA NÎŞAN DE",
"ActivityPub Specification": "Specification ActivityPub" "ActivityPub Specification": "Specification ActivityPub",
"Dogwhistle words": "Peyvên kûçikê",
"Content warnings will be added for the following": "Hişyariyên naverokê dê ji bo jêrîn werin zêdekirin"
} }

View File

@ -565,5 +565,7 @@
"Switch to moderation view": "Overschakelen naar moderatieweergave", "Switch to moderation view": "Overschakelen naar moderatieweergave",
"Minimize attached images": "Bijgevoegde afbeeldingen minimaliseren", "Minimize attached images": "Bijgevoegde afbeeldingen minimaliseren",
"SHOW MEDIA": "TOON MEDIA", "SHOW MEDIA": "TOON MEDIA",
"ActivityPub Specification": "ActivityPub-specificatie" "ActivityPub Specification": "ActivityPub-specificatie",
"Dogwhistle words": "Hondenfluitwoorden",
"Content warnings will be added for the following": "Er worden inhoudswaarschuwingen toegevoegd voor het volgende:"
} }

View File

@ -561,5 +561,7 @@
"Switch to moderation view": "Switch to moderation view", "Switch to moderation view": "Switch to moderation view",
"Minimize attached images": "Minimize attached images", "Minimize attached images": "Minimize attached images",
"SHOW MEDIA": "SHOW MEDIA", "SHOW MEDIA": "SHOW MEDIA",
"ActivityPub Specification": "ActivityPub Specification" "ActivityPub Specification": "ActivityPub Specification",
"Dogwhistle words": "Dogwhistle words",
"Content warnings will be added for the following": "Content warnings will be added for the following"
} }

View File

@ -565,5 +565,7 @@
"Switch to moderation view": "Przełącz na widok moderacji", "Switch to moderation view": "Przełącz na widok moderacji",
"Minimize attached images": "Zminimalizuj załączone obrazy", "Minimize attached images": "Zminimalizuj załączone obrazy",
"SHOW MEDIA": "POKAŻ MEDIA", "SHOW MEDIA": "POKAŻ MEDIA",
"ActivityPub Specification": "Specyfikacja ActivityPub" "ActivityPub Specification": "Specyfikacja ActivityPub",
"Dogwhistle words": "Słowa gwizdka na psa",
"Content warnings will be added for the following": "Ostrzeżenia dotyczące treści zostaną dodane do następujących"
} }

View File

@ -565,5 +565,7 @@
"Switch to moderation view": "Mudar para a visualização de moderação", "Switch to moderation view": "Mudar para a visualização de moderação",
"Minimize attached images": "Minimizar imagens anexadas", "Minimize attached images": "Minimizar imagens anexadas",
"SHOW MEDIA": "MOSTRAR MÍDIA", "SHOW MEDIA": "MOSTRAR MÍDIA",
"ActivityPub Specification": "Especificação do ActivityPub" "ActivityPub Specification": "Especificação do ActivityPub",
"Dogwhistle words": "Palavras de apito",
"Content warnings will be added for the following": "Avisos de conteúdo serão adicionados para os seguintes"
} }

View File

@ -565,5 +565,7 @@
"Switch to moderation view": "Перейти в режим модерации", "Switch to moderation view": "Перейти в режим модерации",
"Minimize attached images": "Свернуть прикрепленные изображения", "Minimize attached images": "Свернуть прикрепленные изображения",
"SHOW MEDIA": "ПОКАЗАТЬ МЕДИА", "SHOW MEDIA": "ПОКАЗАТЬ МЕДИА",
"ActivityPub Specification": "Спецификация ActivityPub" "ActivityPub Specification": "Спецификация ActivityPub",
"Dogwhistle words": "Собачий свисток",
"Content warnings will be added for the following": "Предупреждения о содержании будут добавлены для следующих"
} }

View File

@ -565,5 +565,7 @@
"Switch to moderation view": "Badili hadi mwonekano wa udhibiti", "Switch to moderation view": "Badili hadi mwonekano wa udhibiti",
"Minimize attached images": "Punguza picha zilizoambatishwa", "Minimize attached images": "Punguza picha zilizoambatishwa",
"SHOW MEDIA": "ONESHA VYOMBO VYA HABARI", "SHOW MEDIA": "ONESHA VYOMBO VYA HABARI",
"ActivityPub Specification": "Vipimo vya ActivityPub" "ActivityPub Specification": "Vipimo vya ActivityPub",
"Dogwhistle words": "Maneno ya mbwa",
"Content warnings will be added for the following": "Maonyo ya maudhui yataongezwa kwa yafuatayo"
} }

View File

@ -565,5 +565,7 @@
"Switch to moderation view": "Denetleme görünümüne geç", "Switch to moderation view": "Denetleme görünümüne geç",
"Minimize attached images": "Ekli resimleri simge durumuna küçült", "Minimize attached images": "Ekli resimleri simge durumuna küçült",
"SHOW MEDIA": "MEDYA GÖSTER", "SHOW MEDIA": "MEDYA GÖSTER",
"ActivityPub Specification": "ActivityPub Spesifikasyonu" "ActivityPub Specification": "ActivityPub Spesifikasyonu",
"Dogwhistle words": "İtiraf sözleri",
"Content warnings will be added for the following": "Aşağıdakiler için içerik uyarıları eklenecek"
} }

View File

@ -565,5 +565,7 @@
"Switch to moderation view": "Перейти до режиму модерації", "Switch to moderation view": "Перейти до режиму модерації",
"Minimize attached images": "Мінімізуйте вкладені зображення", "Minimize attached images": "Мінімізуйте вкладені зображення",
"SHOW MEDIA": "ПОКАЗАТИ ЗМІ", "SHOW MEDIA": "ПОКАЗАТИ ЗМІ",
"ActivityPub Specification": "Специфікація ActivityPub" "ActivityPub Specification": "Специфікація ActivityPub",
"Dogwhistle words": "Собачі слова",
"Content warnings will be added for the following": "Попередження про вміст буде додано для наступних"
} }

View File

@ -565,5 +565,7 @@
"Switch to moderation view": "באַשטימען צו מאַדעריישאַן מיינונג", "Switch to moderation view": "באַשטימען צו מאַדעריישאַן מיינונג",
"Minimize attached images": "מינאַמייז אַטאַטשט בילדער", "Minimize attached images": "מינאַמייז אַטאַטשט בילדער",
"SHOW MEDIA": "ווייַז מעדיע", "SHOW MEDIA": "ווייַז מעדיע",
"ActivityPub Specification": "ActivityPub באַשרייַבונג" "ActivityPub Specification": "ActivityPub באַשרייַבונג",
"Dogwhistle words": "דאָגווהיסטלע ווערטער",
"Content warnings will be added for the following": "אינהאַלט וואָרנינגז וועט זיין מוסיף פֿאַר די פאלגענדע"
} }

View File

@ -565,5 +565,7 @@
"Switch to moderation view": "切换到审核视图", "Switch to moderation view": "切换到审核视图",
"Minimize attached images": "最小化附加图像", "Minimize attached images": "最小化附加图像",
"SHOW MEDIA": "展示媒体", "SHOW MEDIA": "展示媒体",
"ActivityPub Specification": "ActivityPub 规范" "ActivityPub Specification": "ActivityPub 规范",
"Dogwhistle words": "狗哨的话",
"Content warnings will be added for the following": "将为以下内容添加内容警告"
} }

View File

@ -549,7 +549,7 @@ def html_newswire_mobile(css_cache: {}, base_dir: str, nickname: str,
def html_edit_newswire(css_cache: {}, translate: {}, base_dir: str, path: str, def html_edit_newswire(css_cache: {}, translate: {}, base_dir: str, path: str,
domain: str, port: int, http_prefix: str, domain: str, port: int, http_prefix: str,
default_timeline: str, theme: str, default_timeline: str, theme: str,
access_keys: {}) -> str: access_keys: {}, dogwhistles: {}) -> str:
"""Shows the edit newswire screen """Shows the edit newswire screen
""" """
if '/users/' not in path: if '/users/' not in path:
@ -645,6 +645,22 @@ def html_edit_newswire(css_cache: {}, translate: {}, base_dir: str, path: str,
'name="filteredWordsNewswire" style="height:50vh" ' + \ 'name="filteredWordsNewswire" style="height:50vh" ' + \
'spellcheck="true">' + filter_str + '</textarea>\n' 'spellcheck="true">' + filter_str + '</textarea>\n'
dogwhistle_str = ''
for whistle, category in dogwhistles.items():
if not category:
continue
dogwhistle_str += whistle + ' -> ' + category + '\n'
edit_newswire_form += \
' <br><b><label class="labels">' + \
translate['Dogwhistle words'] + '</label></b>\n'
edit_newswire_form += ' <br><label class="labels">' + \
translate['Content warnings will be added for the following'] + \
':</label>'
edit_newswire_form += ' <textarea id="message" ' + \
'name="dogwhistleWords" style="height:50vh" ' + \
'spellcheck="true">' + dogwhistle_str + '</textarea>\n'
hashtag_rules_str = '' hashtag_rules_str = ''
hashtag_rules_filename = \ hashtag_rules_filename = \
base_dir + '/accounts/hashtagrules.txt' base_dir + '/accounts/hashtagrules.txt'

View File

@ -1566,13 +1566,12 @@ def _add_dogwhistle_warnings(summary: str, content: str,
if not detected: if not detected:
return summary return summary
for whistle, item in detected.items(): for _, item in detected.items():
if not item.get('category'): if not item.get('category'):
continue continue
if 'dogwhistle' not in whistle: whistle_str = item['category']
whistle_str = whistle + ' dogwhistle' if translate.get(whistle_str):
else: whistle_str = translate[whistle_str]
whistle_str = whistle
if summary: if summary:
summary += ', ' + whistle_str summary += ', ' + whistle_str
else: else: