<commit_before>(in-package #:cliki2)
(in-readtable cliki2)

(defclass deleted-article (proto-article)
  ((canonical-title :index-type   string-unique-index
                    :index-reader deleted-article-with-title))
  (:metaclass persistent-class))

(defun find-deleted-article (title)
  (deleted-article-with-title (canonicalize title)))

(defun find-article-any (title)
  (or (find-article title) (find-deleted-article title)))

(defmethod pprint-article-summary-li ((article deleted-article) separator)
  #H[<li>] (pprint-article-link (title article)) #H[ ${separator} </li>])

(defclass revision-undelete (revision) ()
  (:metaclass persistent-class))

(defun %move-revisions (old-article new-article)
  (dolist (r (revisions old-article))
    (setf (slot-value r 'article) new-article)))

(deftransaction toggle-delete (old-article-id authorship)
  (let* ((old-article (store-object-with-id old-article-id))
         (new-article (make-instance (if (typep old-article 'article)
                                         'deleted-article
                                         'article)
                                     :title     (title old-article)
                                     :revisions (revisions old-article))))
    ;; use add-revision with empty content to de-index deleted article
    (if (typep old-article 'article)
        (push (add-revision old-article "Deleted article" "" authorship)
              (revisions new-article))
        (add-revision new-article "Undeleted article"
                      (revision-content (second (revisions old-article)))
                      authorship 'revision-undelete))
    (dolist (r (revisions old-article))
      (setf (slot-value r 'article) new-article))
    (delete-object old-article)
    new-article))

(defhandler /site/delete (title)
  (awhen (and (not (youre-banned?))
              (not (find-deleted-article title))
              (find-article title))
    (toggle-delete (store-object-id it) (connection-authorship-info)))
  (link-to title))

(deftransaction permadelete (deleted-article-id)
  (let ((deleted-article (store-object-with-id deleted-article-id)))
    (dolist (r (revisions deleted-article))
      (setf *recent-revisions* (remove r *recent-revisions*))
      (delete-object r))
    (delete-object deleted-article)))

(defhandler /site/permadelete (title)
  (awhen (and (not (youre-banned?))
               (account-is? *account* :moderator :administrator)
               (find-deleted-article title))
    (permadelete (store-object-id it)))
  #/)<commit_msg>Update recent revisions list after article permadelete.<commit_after>(in-package #:cliki2)
(in-readtable cliki2)

(defclass deleted-article (proto-article)
  ((canonical-title :index-type   string-unique-index
                    :index-reader deleted-article-with-title))
  (:metaclass persistent-class))

(defun find-deleted-article (title)
  (deleted-article-with-title (canonicalize title)))

(defun find-article-any (title)
  (or (find-article title) (find-deleted-article title)))

(defmethod pprint-article-summary-li ((article deleted-article) separator)
  #H[<li>] (pprint-article-link (title article)) #H[ ${separator} </li>])

(defclass revision-undelete (revision) ()
  (:metaclass persistent-class))

(defun %move-revisions (old-article new-article)
  (dolist (r (revisions old-article))
    (setf (slot-value r 'article) new-article)))

(deftransaction toggle-delete (old-article-id authorship)
  (let* ((old-article (store-object-with-id old-article-id))
         (new-article (make-instance (if (typep old-article 'article)
                                         'deleted-article
                                         'article)
                                     :title     (title old-article)
                                     :revisions (revisions old-article))))
    ;; use add-revision with empty content to de-index deleted article
    (if (typep old-article 'article)
        (push (add-revision old-article "Deleted article" "" authorship)
              (revisions new-article))
        (add-revision new-article "Undeleted article"
                      (revision-content (second (revisions old-article)))
                      authorship 'revision-undelete))
    (dolist (r (revisions old-article))
      (setf (slot-value r 'article) new-article))
    (delete-object old-article)
    new-article))

(defhandler /site/delete (title)
  (awhen (and (not (youre-banned?))
              (not (find-deleted-article title))
              (find-article title))
    (toggle-delete (store-object-id it) (connection-authorship-info)))
  (link-to title))

(deftransaction permadelete (deleted-article-id)
  (let ((deleted-article (store-object-with-id deleted-article-id)))
    (dolist (r (revisions deleted-article))
      (setf *recent-revisions* (remove r *recent-revisions*))
      (delete-object r))
    (delete-object deleted-article)))

(defhandler /site/permadelete (title)
  (awhen (and (not (youre-banned?))
              (account-is? *account* :moderator :administrator)
              (find-deleted-article title))
    (permadelete (store-object-id it))
    (init-recent-revisions))
  #/)
{'fraction_non_alphanumeric': 0.13538045577443028, 'fraction_numerical': 0.000772499034376207, 'mean_word_length': 2.6549047282992237, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5363946', 'n_tokens_mistral': 1587, 'n_tokens_neox': 1556, 'n_words': 361}