forum : commentaires courts sous les réponses (un niveau, 500 caractères, liens cliquables)
- table comments + comment_reports (migration idempotente, IP purgée après un an) - bouton « Commenter » dans la barre du message ; 3 derniers visibles, les autres repliés - membres connectés (profils privés compris) ; visiteurs en lecture ; jamais dans le Bulletin - hors limite VISITEUR_MAX et hors comptage des tris - signalement (page Signalements), masquage modérateur, suppression par l'auteur Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cette révision appartient à :
1 Parent
30c14d478f
révision
c3760e2bf0
5 fichiers modifiés
+328
-6
Aucun fichier ne correspond à votre recherche
+83
-3
@@ -36,7 +36,7 @@ import markdown_sur # noqa: E402
|
||||
import profil as profil_mod # noqa: E402
|
||||
import roles # noqa: E402
|
||||
from db import SYSTEME # noqa: E402
|
||||
from forum import PLUS_TARD_MAX # noqa: E402
|
||||
from forum import PLUS_TARD_MAX, COMMENTAIRE_MAX # noqa: E402
|
||||
from forum import CORPS_MAX, TITRE_MAX, FICHE_PHOTOS_MAX, OCTETS_MAX, PHOTOS_MAX, SESSION_JOURS, ETAT_MINUTES, Forum, Invalide, Refus # noqa: E402
|
||||
|
||||
|
||||
@@ -287,6 +287,16 @@ details.ancien{margin:10px 0 0;color:var(--gris)}details.ancien summary{cursor:p
|
||||
.avatar.petit .couronne{top:-7px;width:20px;height:10px}.avatar.grand .couronne{top:-17px;width:56px;height:28px}
|
||||
.avatar .bouclier{position:absolute;right:-6px;bottom:-6px;width:18px;height:19px}.avatar.grand .bouclier{width:30px;height:32px}
|
||||
.msg aside .avatar{margin:0 0 10px}.msg aside a.auteur{color:var(--roche);text-decoration:none}.msg aside a.auteur:hover{text-decoration:underline}
|
||||
.avatar.mini img{width:28px;height:28px}.avatar.mini .couronne{top:-6px;width:16px;height:8px}.avatar.mini .bouclier{width:12px;height:13px;right:-4px;bottom:-4px}
|
||||
.commentaires{margin:16px 0 0;border-left:3px solid var(--pierre);padding-left:14px}.commentaires ul{list-style:none;margin:0;padding:0}
|
||||
.commentaire{display:flex;gap:10px;align-items:flex-start;padding:8px 0;border-top:1px solid #e3e6df}.commentaire:first-child{border-top:0}
|
||||
.commentaire>div{min-width:0;flex:1}.commentaire .meta{margin:0}.commentaire .meta b{font-size:15px}.commentaire .meta a.auteur{color:var(--roche)}
|
||||
.commentaire .texte{margin:2px 0 0;overflow-wrap:anywhere;font-size:15px}.commentaire.cache{opacity:.75;border-left:3px solid var(--gris);padding-left:8px}
|
||||
.commentaire .outils{display:flex;gap:12px;flex-wrap:wrap;align-items:flex-start;font-size:14px}.commentaire .outils form{margin:0}
|
||||
.commentaire .outils summary{padding:2px 0}.commentaire .outils details[open]{flex-basis:100%}
|
||||
button.lien{background:none;border:0;padding:2px 0;color:var(--sapin);font-weight:600;cursor:pointer;margin:0}button.lien:hover{text-decoration:underline;background:none}
|
||||
.plus-commentaires>summary{cursor:pointer;color:var(--sapin);font-weight:600;padding:4px 0}
|
||||
.actions .commenter textarea{min-height:90px}
|
||||
.compte-menu .entete .avatar{margin-top:8px}
|
||||
.bienvenue{max-width:780px}
|
||||
.etapes{display:flex;gap:8px;margin:0 0 18px;color:var(--gris)}.etapes span{flex:1;border-bottom:3px solid var(--pierre);padding-bottom:4px}
|
||||
@@ -428,6 +438,7 @@ def heure_paris(epoch):
|
||||
|
||||
PAR_PAGE = 10
|
||||
VISITEUR_MAX = 100 # messages visibles sans compte dans un sujet (le 1er + les 99 derniers)
|
||||
COMMENTAIRES_VISIBLES = 3 # sous une réponse ; les plus anciens sont repliés (« Voir les N autres commentaires »)
|
||||
|
||||
|
||||
def entier(texte, defaut=1):
|
||||
@@ -528,6 +539,14 @@ def signalements_html(forum, acteur, lien):
|
||||
"<p><a href='%s%d#message-%d'>Ouvrir le message dans le forum</a></p></article>"
|
||||
% (signalement["post_id"], e(date_fr(signalement["created_at"])), signalement["topic_id"],
|
||||
e(signalement["reason"]), e(extrait), e(lien), signalement["topic_id"], signalement["post_id"]))
|
||||
for s in forum.signalements_commentaires(acteur):
|
||||
corps = s["body"]
|
||||
cartes.append("<article class='fiche'><h2>Commentaire #%d</h2><p class='meta'>Signalé le %s · Sujet #%d%s</p>"
|
||||
"<p><strong>Motif</strong></p><p class='message'>%s</p>"
|
||||
"<p><strong>Extrait du commentaire</strong></p><blockquote class='message'>%s</blockquote>"
|
||||
"<p><a href='%s%d#commentaire-%d'>Ouvrir le commentaire dans le forum</a></p></article>"
|
||||
% (s["comment_id"], e(date_fr(s["created_at"])), s["topic_id"], " · déjà masqué" if s["hidden"] else "",
|
||||
e(s["reason"]), e(corps[:300] + ("…" if len(corps) > 300 else "")), e(lien), s["topic_id"], s["comment_id"]))
|
||||
return "".join(cartes) or etat_vide("Aucun signalement à examiner.")
|
||||
|
||||
|
||||
@@ -1460,6 +1479,42 @@ class Handler(BaseHTTPRequestHandler):
|
||||
bio, anciens, "<section><h2>Station</h2>%s</section>" % stations if stations else "", sujets))
|
||||
self.page(c["username"], contenu, user, tete="<meta name='robots' content='noindex'>")
|
||||
|
||||
def commentaire_html(self, user, rs, c):
|
||||
outils = []
|
||||
if user is not None and c["author_id"] == user["id"]:
|
||||
outils.append("<details class='supprimer'><summary>Supprimer</summary><form method='post' action='/commentaire/supprimer'>"
|
||||
"<input type='hidden' name='commentaire' value='%d'><p class='meta'>Le commentaire sera effacé.</p>"
|
||||
"<button class='danger'>Supprimer le commentaire</button></form></details>" % c["id"])
|
||||
if roles.peut(rs, "signaler") and not c["hidden"] and (user is None or c["author_id"] != user["id"]):
|
||||
outils.append("<details class='signaler'><summary>Signaler</summary><form method='post' action='/commentaire/signaler'>"
|
||||
"<input type='hidden' name='commentaire' value='%d'><label>Motif du signalement"
|
||||
"<textarea name='motif' maxlength='500' required></textarea></label>"
|
||||
"<button>Envoyer le signalement</button></form></details>" % c["id"])
|
||||
if roles.peut(rs, "masquer"):
|
||||
outils.append("<form method='post' action='/commentaire/masquer'><input type='hidden' name='commentaire' value='%d'>"
|
||||
"<input type='hidden' name='etat' value='%d'><button class='lien'>%s</button></form>"
|
||||
% (c["id"], 0 if c["hidden"] else 1, "Afficher" if c["hidden"] else "Masquer"))
|
||||
return ("<li class='commentaire%s' id='commentaire-%d'>%s<div><p class='meta'><b>%s</b> · %s%s</p>"
|
||||
"<p class='texte'>%s</p>%s</div></li>"
|
||||
% (" cache" if c["hidden"] else "", c["id"], self.avatar_de(self._auteur(c), "mini"), self.nom_message(user, c),
|
||||
e(date_fr(c["created_at"], True)), " · <span class='etat'>Masqué</span>" if c["hidden"] else "",
|
||||
profil_mod.bio_html(c["body"]).replace("\n", "<br>"),
|
||||
"<div class='outils'>%s</div>" % "".join(outils) if outils else ""))
|
||||
|
||||
def commentaires_html(self, user, rs, comms):
|
||||
"""Sous une réponse : les 3 derniers commentaires visibles, les plus anciens repliés."""
|
||||
if not comms:
|
||||
return ""
|
||||
anciens, recents = comms[:-COMMENTAIRES_VISIBLES], comms[-COMMENTAIRES_VISIBLES:]
|
||||
repli = ""
|
||||
if anciens:
|
||||
n = len(anciens)
|
||||
repli = ("<details class='plus-commentaires'><summary>Voir %s</summary><ul>%s</ul></details>"
|
||||
% ("l’autre commentaire" if n == 1 else "les %d autres commentaires" % n,
|
||||
"".join(self.commentaire_html(user, rs, c) for c in anciens)))
|
||||
return ("<section class='commentaires' aria-label='Commentaires'>%s<ul>%s</ul></section>"
|
||||
% (repli, "".join(self.commentaire_html(user, rs, c) for c in recents)))
|
||||
|
||||
def sujet(self, user, tid):
|
||||
f = self.app.forum
|
||||
rs = f.roles_de(user)
|
||||
@@ -1497,12 +1552,21 @@ class Handler(BaseHTTPRequestHandler):
|
||||
out.append("<p class='info'>Fiche de la station sur vercors.me : %d photo%s épinglée%s sur %d. "
|
||||
"Choisis-les avec « Épingler sur la fiche » sous chaque photo.</p>"
|
||||
% (len(fiche), "s" if len(fiche) > 1 else "", "s" if len(fiche) > 1 else "", FICHE_PHOTOS_MAX))
|
||||
comms = {} if t["fixed"] else f.commentaires(user, [m["id"] for m in msgs]) # pas de commentaires dans le Bulletin
|
||||
for i, m in enumerate(msgs):
|
||||
if i == 1 and caches:
|
||||
out.append("<p class='info'>%d message%s plus ancien%s : connecte-toi pour les voir.</p>" % (caches, "s" if caches > 1 else "", "s" if caches > 1 else ""))
|
||||
gal = galerie_html(f.photos_de(m["id"]), "/photo", None if fiche is None or m["hidden"] else fiche)
|
||||
outils = ""
|
||||
lien = "<a class='copier-lien' href='#message-%d'>Copier le lien</a>" % m["id"]
|
||||
if f.peut_commenter(user, t, m):
|
||||
lien += ("<span class='sep' aria-hidden='true'>|</span>"
|
||||
"<details class='commenter'><summary>Commenter</summary><form method='post' action='/commenter'>"
|
||||
"<input type='hidden' name='post' value='%d'><label for='comm-%d'>Ton commentaire</label>"
|
||||
"<textarea id='comm-%d' name='corps' maxlength='%d' required></textarea>"
|
||||
"<p class='meta'>Texte simple, %d caractères au plus. Les adresses http(s) deviennent des liens.</p>"
|
||||
"<button class='principal'>Publier le commentaire</button></form></details>"
|
||||
% (m["id"], m["id"], m["id"], COMMENTAIRE_MAX, COMMENTAIRE_MAX))
|
||||
if roles.peut(rs, "signaler") and not m["hidden"]:
|
||||
outils += ("<details class='signaler'><summary>Signaler le message</summary><form method='post' action='/signaler'>"
|
||||
"<input type='hidden' name='post' value='%d'><label>Motif du signalement"
|
||||
@@ -1517,14 +1581,15 @@ class Handler(BaseHTTPRequestHandler):
|
||||
"<button class='principal'>Enregistrer la modification</button></form></details>"
|
||||
% (m["id"], m["id"], m["id"], e(m["body"])))
|
||||
out.append("<article class='msg%s' id='message-%d'><aside>%s<b>%s</b>%s<br><span class='meta'>%s%s</span>%s</aside>"
|
||||
"<div class='corps'>%s%s%s%s</div></article>"
|
||||
"<div class='corps'>%s%s%s%s%s</div></article>"
|
||||
% (" cache" if m["hidden"] else "", m["id"], self.avatar_de(self._auteur(m)), self.nom_message(user, m),
|
||||
self.badges(m["author_id"]), e(date_fr(m["created_at"], True)),
|
||||
"", "<br><span class='etat'>Masqué</span>" if m["hidden"] else "",
|
||||
corps_message(m["body"], m["format"]),
|
||||
("<details class='ancien'><summary>Modifié le %s · voir l’ancienne version</summary>%s</details>"
|
||||
% (e(date_fr(m["edited_at"], True)), corps_message(m["ancien_body"] or "", m["format"])) if m["edited_at"] else ""), gal,
|
||||
"<div class='actions'><div class='gauche'>%s</div>%s</div>" % (lien, outils)))
|
||||
"<div class='actions'><div class='gauche'>%s</div>%s</div>" % (lien, outils),
|
||||
self.commentaires_html(user, rs, comms.get(m["id"], []))))
|
||||
gestion = []
|
||||
if roles.peut(rs, "verrouiller") and not t["fixed"]:
|
||||
gestion.append("<form method='post' action='/verrouiller'><input type='hidden' name='sujet' value='%d'>"
|
||||
@@ -1813,6 +1878,21 @@ class Handler(BaseHTTPRequestHandler):
|
||||
f.sujet(user, tid)
|
||||
f.signaler(user, pid, d.get("motif"))
|
||||
return self.rediriger("/t/%d?suite=signalement#message-%d" % (tid, pid))
|
||||
if chemin == "/commenter":
|
||||
pid = int(d.get("post", "0"))
|
||||
cid = f.commenter(user, pid, d.get("corps"), ip)
|
||||
return self.rediriger("/t/%d#commentaire-%d" % (f._post(pid)["topic_id"], cid))
|
||||
if chemin == "/commentaire/supprimer":
|
||||
tid, pid = f.supprimer_commentaire(user, int(d.get("commentaire", "0")))
|
||||
return self.rediriger("/t/%d#message-%d" % (tid, pid))
|
||||
if chemin == "/commentaire/signaler":
|
||||
cid = int(d.get("commentaire", "0"))
|
||||
tid, _ = f.signaler_commentaire(user, cid, d.get("motif"))
|
||||
return self.rediriger("/t/%d?suite=signalement#commentaire-%d" % (tid, cid))
|
||||
if chemin == "/commentaire/masquer":
|
||||
cid = int(d.get("commentaire", "0"))
|
||||
tid, _ = f.masquer_commentaire(user, cid, d.get("etat") == "1")
|
||||
return self.rediriger("/t/%d#commentaire-%d" % (tid, cid))
|
||||
if chemin == "/masquer":
|
||||
f.masquer_message(user, int(d.get("post", "0")), d.get("etat") == "1")
|
||||
return self.rediriger(self.headers.get("Referer") or "/")
|
||||
|
||||
Référencer dans un nouveau ticket
Bloquer un utilisateur