1+ /**
2+ * @(#)LogEntries.java 0.01 02/06/2024
3+ * Copyright (C) 2024-20XX MER-C and contributors
4+ *
5+ * This program is free software; you can redistribute it and/or
6+ * modify it under the terms of the GNU General Public License
7+ * as published by the Free Software Foundation; either version 3
8+ * of the License, or (at your option) any later version. Additionally
9+ * this file is subject to the "Classpath" exception.
10+ *
11+ * This program is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ * GNU General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU General Public License
17+ * along with this program; if not, write to the Free Software Foundation,
18+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+ */
20+
21+ package org .wikipedia ;
22+
23+ import java .time .format .DateTimeFormatter ;
24+ import java .util .*;
25+
26+ /**
27+ * Utility class for {@link Wiki.LogEntry}. For utility methods and data specific
28+ * to {@link Wiki.Revision}s, see {@link Revisions}.
29+ * @author MER-C
30+ * @version 0.01
31+ */
32+ public class LogEntries
33+ {
34+ /**
35+ * Turns a list of revisions into human-readable wikitext. Be careful, as
36+ * slowness may result when copying large amounts of wikitext produced by
37+ * this method, or by the wiki trying to parse it. Takes the form of:
38+ *
39+ * <p>*2009-01-01 00:00 User (talk | contribs) [action] [target] (comment)
40+ * @param logs a bunch of log entries
41+ * @return those log entries formatted as wikitext
42+ */
43+ public static String toWikitext (Iterable <Wiki .LogEntry > logs )
44+ {
45+ StringBuilder buffer = new StringBuilder (100000 );
46+ buffer .append ("<div style=\" font-family: monospace; font-size: 120%\" >\n " );
47+ for (Wiki .LogEntry log : logs )
48+ {
49+ // timestamp
50+ buffer .append ("*" );
51+ buffer .append (DateTimeFormatter .ISO_OFFSET_DATE_TIME .format (log .getTimestamp ()));
52+ buffer .append (" " );
53+
54+ // user
55+ String user2 = log .getUser ();
56+ if (user2 == null || user2 .equals (Wiki .Event .USER_DELETED ))
57+ buffer .append (Events .DELETED_EVENT_HTML );
58+ else
59+ {
60+ buffer .append (Users .generateWikitextSummaryLinksShort (user2 ));
61+ buffer .append (" " );
62+ }
63+
64+ // action
65+ buffer .append (log .getAction ());
66+ buffer .append (" " );
67+
68+ // target
69+ String target = log .getTitle ();
70+ if (target != null )
71+ {
72+ buffer .append ("[[:" );
73+ buffer .append (target );
74+ buffer .append ("]] " );
75+ }
76+
77+ // comment
78+ String summary = log .getComment ();
79+ if (summary == null || summary .equals (Wiki .Event .COMMENT_DELETED ))
80+ buffer .append (Events .DELETED_EVENT_HTML );
81+ else
82+ {
83+ // kill wikimarkup
84+ buffer .append ("(<nowiki>" );
85+ buffer .append (summary );
86+ buffer .append ("</nowiki>)" );
87+ }
88+
89+ // details
90+ Map details = log .getDetails ();
91+ if (details != null && !details .isEmpty ())
92+ {
93+ buffer .append (" " );
94+ buffer .append (details .toString ());
95+ }
96+ buffer .append ("\n " );
97+ }
98+ buffer .append ("</div>" );
99+ return buffer .toString ();
100+ }
101+ }
0 commit comments