From 21b54626836b52e807f6328d3d513996b2c4d604 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 5 Jul 2022 18:52:19 +0100 Subject: [PATCH] Edit dogwhistle words --- content.py | 6 +++--- daemon.py | 23 ++++++++++++++++++++++- translations/ar.json | 4 +++- translations/bn.json | 4 +++- translations/ca.json | 4 +++- translations/cy.json | 4 +++- translations/de.json | 4 +++- translations/el.json | 4 +++- translations/en.json | 4 +++- translations/es.json | 4 +++- translations/fr.json | 4 +++- translations/ga.json | 4 +++- translations/hi.json | 4 +++- translations/it.json | 4 +++- translations/ja.json | 4 +++- translations/ko.json | 4 +++- translations/ku.json | 4 +++- translations/nl.json | 4 +++- translations/oc.json | 4 +++- translations/pl.json | 4 +++- translations/pt.json | 4 +++- translations/ru.json | 4 +++- translations/sw.json | 4 +++- translations/tr.json | 4 +++- translations/uk.json | 4 +++- translations/yi.json | 4 +++- translations/zh.json | 4 +++- webapp_column_right.py | 18 +++++++++++++++++- webapp_post.py | 9 ++++----- 29 files changed, 121 insertions(+), 35 deletions(-) diff --git a/content.py b/content.py index 2a079839d..23d2285a4 100644 --- a/content.py +++ b/content.py @@ -1097,7 +1097,7 @@ def load_dogwhistles(filename: str) -> {}: except OSError: print('EX: unable to load dogwhistles from ' + filename) return {} - separators = ('->', ',', ';', '|') + separators = ('->', '=>', ',', ';', '|', '=') dogwhistles = {} for line in dogwhistle_lines: line = line.remove_eol(line).strip() @@ -1109,8 +1109,8 @@ def load_dogwhistles(filename: str) -> {}: category = None for sep in separators: if sep in line: - whistle = line.split(sep, 1)[0] - category = line.split(sep, 1)[1] + whistle = line.split(sep, 1)[0].strip() + category = line.split(sep, 1)[1].strip() break if not whistle: whistle = line diff --git a/daemon.py b/daemon.py index cfba86ea1..e14789e01 100644 --- a/daemon.py +++ b/daemon.py @@ -5106,6 +5106,26 @@ class PubServer(BaseHTTPRequestHandler): print('EX: _newswire_update unable to delete ' + 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 hashtag_rules_filename = \ base_dir + '/accounts/hashtagrules.txt' @@ -14978,7 +14998,8 @@ class PubServer(BaseHTTPRequestHandler): http_prefix, self.server.default_timeline, self.server.theme_name, - access_keys) + access_keys, + self.server.dogwhistles) if msg: msg = msg.encode('utf-8') msglen = len(msg) diff --git a/translations/ar.json b/translations/ar.json index 5340cc17b..cc1c0383c 100644 --- a/translations/ar.json +++ b/translations/ar.json @@ -565,5 +565,7 @@ "Switch to moderation view": "قم بالتبديل إلى عرض الاعتدال", "Minimize attached images": "تصغير الصور المرفقة", "SHOW MEDIA": "عرض الوسائط", - "ActivityPub Specification": "مواصفات ActivityPub" + "ActivityPub Specification": "مواصفات ActivityPub", + "Dogwhistle words": "كلمات Dogwhistle", + "Content warnings will be added for the following": "ستتم إضافة تحذيرات المحتوى لما يلي" } diff --git a/translations/bn.json b/translations/bn.json index 553d29482..7fb7c941d 100644 --- a/translations/bn.json +++ b/translations/bn.json @@ -565,5 +565,7 @@ "Switch to moderation view": "সংযম দৃশ্যে স্যুইচ করুন", "Minimize attached images": "সংযুক্ত ছবি ছোট করুন", "SHOW MEDIA": "মিডিয়া দেখান", - "ActivityPub Specification": "ActivityPub স্পেসিফিকেশন" + "ActivityPub Specification": "ActivityPub স্পেসিফিকেশন", + "Dogwhistle words": "কুকুরের হুইসেল শব্দ", + "Content warnings will be added for the following": "নিম্নলিখিত জন্য বিষয়বস্তু সতর্কতা যোগ করা হবে" } diff --git a/translations/ca.json b/translations/ca.json index 67933223f..bfd994db7 100644 --- a/translations/ca.json +++ b/translations/ca.json @@ -565,5 +565,7 @@ "Switch to moderation view": "Canvia a la visualització de moderació", "Minimize attached images": "Minimitzar les imatges adjuntes", "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" } diff --git a/translations/cy.json b/translations/cy.json index 7247eee33..ff2ab6fc4 100644 --- a/translations/cy.json +++ b/translations/cy.json @@ -565,5 +565,7 @@ "Switch to moderation view": "Newid i wedd safoni", "Minimize attached images": "Lleihau delweddau sydd ynghlwm", "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" } diff --git a/translations/de.json b/translations/de.json index f19a7411d..962cfcbb9 100644 --- a/translations/de.json +++ b/translations/de.json @@ -565,5 +565,7 @@ "Switch to moderation view": "Wechseln Sie zur Moderationsansicht", "Minimize attached images": "Angehängte Bilder minimieren", "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" } diff --git a/translations/el.json b/translations/el.json index ea496a1fc..8a3cee2df 100644 --- a/translations/el.json +++ b/translations/el.json @@ -565,5 +565,7 @@ "Switch to moderation view": "Μετάβαση σε προβολή εποπτείας", "Minimize attached images": "Ελαχιστοποιήστε τις συνημμένες εικόνες", "SHOW MEDIA": "ΔΕΙΤΕ ΜΕΣΑ", - "ActivityPub Specification": "Προδιαγραφές ActivityPub" + "ActivityPub Specification": "Προδιαγραφές ActivityPub", + "Dogwhistle words": "Σφυρίχτρα λέξεις", + "Content warnings will be added for the following": "Θα προστεθούν προειδοποιήσεις περιεχομένου για τα ακόλουθα" } diff --git a/translations/en.json b/translations/en.json index d283394d6..6b19ef3b2 100644 --- a/translations/en.json +++ b/translations/en.json @@ -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" + "ActivityPub Specification": "ActivityPub Specification", + "Dogwhistle words": "Dogwhistle words", + "Content warnings will be added for the following": "Content warnings will be added for the following" } diff --git a/translations/es.json b/translations/es.json index c021c76a8..2a0f58af5 100644 --- a/translations/es.json +++ b/translations/es.json @@ -565,5 +565,7 @@ "Switch to moderation view": "Cambiar a la vista de moderación", "Minimize attached images": "Minimizar imágenes adjuntas", "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" } diff --git a/translations/fr.json b/translations/fr.json index 02adc075e..493cc8346 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -565,5 +565,7 @@ "Switch to moderation view": "Passer en mode modération", "Minimize attached images": "Réduire les images jointes", "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" } diff --git a/translations/ga.json b/translations/ga.json index 89e4839e1..d980c9432 100644 --- a/translations/ga.json +++ b/translations/ga.json @@ -565,5 +565,7 @@ "Switch to moderation view": "Athraigh go dtí an t-amharc modhnóireachta", "Minimize attached images": "Íoslaghdaigh íomhánna ceangailte", "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" } diff --git a/translations/hi.json b/translations/hi.json index 25da4a044..95f4c8a66 100644 --- a/translations/hi.json +++ b/translations/hi.json @@ -565,5 +565,7 @@ "Switch to moderation view": "मॉडरेशन दृश्य पर स्विच करें", "Minimize attached images": "संलग्न छवियों को छोटा करें", "SHOW MEDIA": "मीडिया दिखाएं", - "ActivityPub Specification": "गतिविधिपब विशिष्टता" + "ActivityPub Specification": "गतिविधिपब विशिष्टता", + "Dogwhistle words": "कुत्ते की सीटी शब्द", + "Content warnings will be added for the following": "निम्नलिखित के लिए सामग्री चेतावनियां जोड़ दी जाएंगी" } diff --git a/translations/it.json b/translations/it.json index b120d93ea..f5b7cb4e6 100644 --- a/translations/it.json +++ b/translations/it.json @@ -565,5 +565,7 @@ "Switch to moderation view": "Passa alla visualizzazione moderazione", "Minimize attached images": "Riduci al minimo le immagini allegate", "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" } diff --git a/translations/ja.json b/translations/ja.json index 2ecea1bcb..5210d836c 100644 --- a/translations/ja.json +++ b/translations/ja.json @@ -565,5 +565,7 @@ "Switch to moderation view": "モデレートビューに切り替えます", "Minimize attached images": "添付画像を最小限に抑える", "SHOW MEDIA": "メディアを表示", - "ActivityPub Specification": "ActivityPubの仕様" + "ActivityPub Specification": "ActivityPubの仕様", + "Dogwhistle words": "犬笛の言葉", + "Content warnings will be added for the following": "以下のコンテンツ警告が追加されます" } diff --git a/translations/ko.json b/translations/ko.json index 8dbfbb256..b0a9e2b55 100644 --- a/translations/ko.json +++ b/translations/ko.json @@ -565,5 +565,7 @@ "Switch to moderation view": "검토 보기로 전환", "Minimize attached images": "첨부된 이미지 최소화", "SHOW MEDIA": "미디어 표시", - "ActivityPub Specification": "ActivityPub 사양" + "ActivityPub Specification": "ActivityPub 사양", + "Dogwhistle words": "개 휘파람 단어", + "Content warnings will be added for the following": "다음에 대한 콘텐츠 경고가 추가됩니다." } diff --git a/translations/ku.json b/translations/ku.json index fbbe26b22..7df2289a8 100644 --- a/translations/ku.json +++ b/translations/ku.json @@ -565,5 +565,7 @@ "Switch to moderation view": "Biguherîne bo dîtina moderatoriyê", "Minimize attached images": "Wêneyên pêvekirî kêm bikin", "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" } diff --git a/translations/nl.json b/translations/nl.json index 775c8d284..8a94c779d 100644 --- a/translations/nl.json +++ b/translations/nl.json @@ -565,5 +565,7 @@ "Switch to moderation view": "Overschakelen naar moderatieweergave", "Minimize attached images": "Bijgevoegde afbeeldingen minimaliseren", "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:" } diff --git a/translations/oc.json b/translations/oc.json index 98d73eedc..42e21d93b 100644 --- a/translations/oc.json +++ b/translations/oc.json @@ -561,5 +561,7 @@ "Switch to moderation view": "Switch to moderation view", "Minimize attached images": "Minimize attached images", "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" } diff --git a/translations/pl.json b/translations/pl.json index feb0e953e..75da3fdba 100644 --- a/translations/pl.json +++ b/translations/pl.json @@ -565,5 +565,7 @@ "Switch to moderation view": "Przełącz na widok moderacji", "Minimize attached images": "Zminimalizuj załączone obrazy", "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" } diff --git a/translations/pt.json b/translations/pt.json index b2725ce50..2adeebaa0 100644 --- a/translations/pt.json +++ b/translations/pt.json @@ -565,5 +565,7 @@ "Switch to moderation view": "Mudar para a visualização de moderação", "Minimize attached images": "Minimizar imagens anexadas", "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" } diff --git a/translations/ru.json b/translations/ru.json index bf21f25f3..e12bb1799 100644 --- a/translations/ru.json +++ b/translations/ru.json @@ -565,5 +565,7 @@ "Switch to moderation view": "Перейти в режим модерации", "Minimize attached images": "Свернуть прикрепленные изображения", "SHOW MEDIA": "ПОКАЗАТЬ МЕДИА", - "ActivityPub Specification": "Спецификация ActivityPub" + "ActivityPub Specification": "Спецификация ActivityPub", + "Dogwhistle words": "Собачий свисток", + "Content warnings will be added for the following": "Предупреждения о содержании будут добавлены для следующих" } diff --git a/translations/sw.json b/translations/sw.json index 21d05b2b8..02682a5b5 100644 --- a/translations/sw.json +++ b/translations/sw.json @@ -565,5 +565,7 @@ "Switch to moderation view": "Badili hadi mwonekano wa udhibiti", "Minimize attached images": "Punguza picha zilizoambatishwa", "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" } diff --git a/translations/tr.json b/translations/tr.json index 95b1bba51..2eadf668a 100644 --- a/translations/tr.json +++ b/translations/tr.json @@ -565,5 +565,7 @@ "Switch to moderation view": "Denetleme görünümüne geç", "Minimize attached images": "Ekli resimleri simge durumuna küçült", "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" } diff --git a/translations/uk.json b/translations/uk.json index 86e92abaa..58723e75a 100644 --- a/translations/uk.json +++ b/translations/uk.json @@ -565,5 +565,7 @@ "Switch to moderation view": "Перейти до режиму модерації", "Minimize attached images": "Мінімізуйте вкладені зображення", "SHOW MEDIA": "ПОКАЗАТИ ЗМІ", - "ActivityPub Specification": "Специфікація ActivityPub" + "ActivityPub Specification": "Специфікація ActivityPub", + "Dogwhistle words": "Собачі слова", + "Content warnings will be added for the following": "Попередження про вміст буде додано для наступних" } diff --git a/translations/yi.json b/translations/yi.json index 1ab354557..1a3f2fcf8 100644 --- a/translations/yi.json +++ b/translations/yi.json @@ -565,5 +565,7 @@ "Switch to moderation view": "באַשטימען צו מאַדעריישאַן מיינונג", "Minimize attached images": "מינאַמייז אַטאַטשט בילדער", "SHOW MEDIA": "ווייַז מעדיע", - "ActivityPub Specification": "ActivityPub באַשרייַבונג" + "ActivityPub Specification": "ActivityPub באַשרייַבונג", + "Dogwhistle words": "דאָגווהיסטלע ווערטער", + "Content warnings will be added for the following": "אינהאַלט וואָרנינגז וועט זיין מוסיף פֿאַר די פאלגענדע" } diff --git a/translations/zh.json b/translations/zh.json index 0f1f7d9ae..e953072ec 100644 --- a/translations/zh.json +++ b/translations/zh.json @@ -565,5 +565,7 @@ "Switch to moderation view": "切换到审核视图", "Minimize attached images": "最小化附加图像", "SHOW MEDIA": "展示媒体", - "ActivityPub Specification": "ActivityPub 规范" + "ActivityPub Specification": "ActivityPub 规范", + "Dogwhistle words": "狗哨的话", + "Content warnings will be added for the following": "将为以下内容添加内容警告" } diff --git a/webapp_column_right.py b/webapp_column_right.py index 5e41fe570..5339f63f9 100644 --- a/webapp_column_right.py +++ b/webapp_column_right.py @@ -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, domain: str, port: int, http_prefix: str, default_timeline: str, theme: str, - access_keys: {}) -> str: + access_keys: {}, dogwhistles: {}) -> str: """Shows the edit newswire screen """ 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" ' + \ 'spellcheck="true">' + filter_str + '\n' + dogwhistle_str = '' + for whistle, category in dogwhistles.items(): + if not category: + continue + dogwhistle_str += whistle + ' -> ' + category + '\n' + + edit_newswire_form += \ + '
\n' + edit_newswire_form += '
' + edit_newswire_form += ' \n' + hashtag_rules_str = '' hashtag_rules_filename = \ base_dir + '/accounts/hashtagrules.txt' diff --git a/webapp_post.py b/webapp_post.py index bbb2b21e8..e1b118bbb 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -1566,13 +1566,12 @@ def _add_dogwhistle_warnings(summary: str, content: str, if not detected: return summary - for whistle, item in detected.items(): + for _, item in detected.items(): if not item.get('category'): continue - if 'dogwhistle' not in whistle: - whistle_str = whistle + ' dogwhistle' - else: - whistle_str = whistle + whistle_str = item['category'] + if translate.get(whistle_str): + whistle_str = translate[whistle_str] if summary: summary += ', ' + whistle_str else: