Merge remote-tracking branch 'origin/master'

This commit is contained in:
Frisk 2020-11-30 01:43:48 +01:00
commit 22f58df474
No known key found for this signature in database
GPG key ID: 213F7C15068AF8AC
4 changed files with 321 additions and 73 deletions

View file

@ -443,6 +443,7 @@ async def discussion_handler():
else: else:
logger.exception("Exception on Feeds formatter") logger.exception("Exception on Feeds formatter")
await generic_msg_sender_exception_logger(traceback.format_exc(), "Exception in feed formatter", Post=str(post)[0:1000], Wiki=db_wiki["wiki"]) await generic_msg_sender_exception_logger(traceback.format_exc(), "Exception in feed formatter", Post=str(post)[0:1000], Wiki=db_wiki["wiki"])
# Lets stack the messages
for messages in message_list.values(): for messages in message_list.values():
messages = stack_message_list(messages) messages = stack_message_list(messages)
for message in messages: for message in messages:

View file

@ -42,14 +42,16 @@ async def compact_formatter(action, change, parsed_comment, categories, recent_c
wiki=WIKI_SCRIPT_PATH, pageid=change["pageid"], diff=change["revid"], oldrev=change["old_revid"], wiki=WIKI_SCRIPT_PATH, pageid=change["pageid"], diff=change["revid"], oldrev=change["old_revid"],
article=change["title"])) article=change["title"]))
edit_size = change["newlen"] - change["oldlen"] edit_size = change["newlen"] - change["oldlen"]
sign = ""
if edit_size > 0: if edit_size > 0:
sign = "+" sign = "+"
else: bold = ""
sign = "" if abs(edit_size) > 500:
bold = "**"
if action == "edit": if action == "edit":
content = "📝 "+_("[{author}]({author_url}) edited [{article}]({edit_link}){comment} ({sign}{edit_size})").format(author=author, author_url=author_url, article=change["title"], edit_link=edit_link, comment=parsed_comment, edit_size=edit_size, sign=sign) content = "📝 "+_("[{author}]({author_url}) edited [{article}]({edit_link}){comment} {bold}({sign}{edit_size}){bold}").format(author=author, author_url=author_url, article=change["title"], edit_link=edit_link, comment=parsed_comment, edit_size=edit_size, sign=sign, bold=bold)
else: else:
content = "🆕 "+_("[{author}]({author_url}) created [{article}]({edit_link}){comment} ({sign}{edit_size})").format(author=author, author_url=author_url, article=change["title"], edit_link=edit_link, comment=parsed_comment, edit_size=edit_size, sign=sign) content = "🆕 "+_("[{author}]({author_url}) created [{article}]({edit_link}){comment} {bold}({sign}{edit_size}){bold}").format(author=author, author_url=author_url, article=change["title"], edit_link=edit_link, comment=parsed_comment, edit_size=edit_size, sign=sign, bold=bold)
elif action =="upload/upload": elif action =="upload/upload":
file_link = link_formatter(create_article_path(change["title"], WIKI_ARTICLE_PATH)) file_link = link_formatter(create_article_path(change["title"], WIKI_ARTICLE_PATH))
content = "🖼️ "+_("[{author}]({author_url}) uploaded [{file}]({file_link}){comment}").format(author=author, content = "🖼️ "+_("[{author}]({author_url}) uploaded [{file}]({file_link}){comment}").format(author=author,
@ -151,43 +153,73 @@ async def compact_formatter(action, change, parsed_comment, categories, recent_c
content = ""+_("[{author}]({author_url}) unblocked [{blocked_user}]({user_url}){comment}").format(author=author, author_url=author_url, blocked_user=user, user_url=link, comment=parsed_comment) content = ""+_("[{author}]({author_url}) unblocked [{blocked_user}]({user_url}){comment}").format(author=author, author_url=author_url, blocked_user=user, user_url=link, comment=parsed_comment)
elif action == "curseprofile/comment-created": elif action == "curseprofile/comment-created":
link = link_formatter(create_article_path("Special:CommentPermalink/{commentid}".format(commentid=change["logparams"]["4:comment_id"]), WIKI_ARTICLE_PATH)) link = link_formatter(create_article_path("Special:CommentPermalink/{commentid}".format(commentid=change["logparams"]["4:comment_id"]), WIKI_ARTICLE_PATH))
content = "✉️ "+_("[{author}]({author_url}) left a [comment]({comment}) on {target} profile").format(author=author, author_url=author_url, comment=link, target=change["title"].split(':')[1]+"'s" if change["title"].split(':')[1] != change["user"] else _("their own profile")) target_user = change["title"].split(':', 1)[1]
if target_user != author:
content = "✉️ "+ _("[{author}]({author_url}) left a [comment]({comment}) on {target}'s profile".format(author=author, author_url=author_url, comment=link, target=target_user))
else:
content = "✉️ "+ _("[{author}]({author_url}) left a [comment]({comment}) on their own profile".format(author=author, author_url=author_url, comment=link))
elif action == "curseprofile/comment-replied": elif action == "curseprofile/comment-replied":
link = link_formatter(create_article_path("Special:CommentPermalink/{commentid}".format(commentid=change["logparams"]["4:comment_id"]), WIKI_ARTICLE_PATH)) link = link_formatter(create_article_path("Special:CommentPermalink/{commentid}".format(commentid=change["logparams"]["4:comment_id"]), WIKI_ARTICLE_PATH))
content = "📩 "+_("[{author}]({author_url}) replied to a [comment]({comment}) on {target} profile").format(author=author, target_user = change["title"].split(':', 1)[1]
author_url=author_url, if target_user != author:
comment=link, content = "📩 "+ _(
target=change["title"].split(':')[1] if change["title"].split(':')[1] !=change["user"] else _("their own")) "[{author}]({author_url}) replied to a [comment]({comment}) on {target}'s profile".format(author=author,
author_url=author_url,
comment=link,
target=target_user))
else:
content = "📩 "+ _(
"[{author}]({author_url}) replied to a [comment]({comment}) on their own profile".format(author=author,
comment=link,
author_url=author_url))
elif action == "curseprofile/comment-edited": elif action == "curseprofile/comment-edited":
link = link_formatter(create_article_path("Special:CommentPermalink/{commentid}".format(commentid=change["logparams"]["4:comment_id"]), WIKI_ARTICLE_PATH)) link = link_formatter(create_article_path("Special:CommentPermalink/{commentid}".format(commentid=change["logparams"]["4:comment_id"]), WIKI_ARTICLE_PATH))
content = "📧 "+_("[{author}]({author_url}) edited a [comment]({comment}) on {target} profile").format(author=author, target_user = change["title"].split(':', 1)[1]
author_url=author_url, if target_user != author:
comment=link, content = "📧 "+ _(
target=change["title"].split(':')[1] if change["title"].split(':')[1] !=change["user"] else _("their own")) "[{author}]({author_url}) edited a [comment]({comment}) on {target}'s profile".format(author=author,
author_url=author_url,
comment=link,
target=target_user))
else:
content = "📧 "+ _(
"[{author}]({author_url}) edited a [comment]({comment}) on their own profile".format(author=author,
comment=link,
author_url=author_url))
elif action == "curseprofile/comment-purged": elif action == "curseprofile/comment-purged":
link = link_formatter(create_article_path("Special:CommentPermalink/{commentid}".format(commentid=change["logparams"]["4:comment_id"]), WIKI_ARTICLE_PATH)) target_user = change["title"].split(':', 1)[1]
content = "👁️ "+_("[{author}]({author_url}) purged a comment on {target} profile").format(author=author, if target_user != author:
author_url=author_url, content = "👁️ " + _("[{author}]({author_url}) purged a comment on {target}'s profile".format(author=author, author_url=author_url,target=target_user))
target= else:
change["title"].split(':')[ content = "👁️ " + _("[{author}]({author_url}) purged a comment on their own profile".format(author=author, author_url=author_url))
1] if
change["title"].split(':')[
1] != change[
"user"] else _(
"their own"))
elif action == "curseprofile/comment-deleted": elif action == "curseprofile/comment-deleted":
content = "🗑️ "+_("[{author}]({author_url}) deleted a comment on {target} profile").format(author=author, if "4:comment_id" in change["logparams"]:
author_url=author_url, link = link_formatter(create_article_path("Special:CommentPermalink/{commentid}".format(commentid=change["logparams"]["4:comment_id"]), WIKI_ARTICLE_PATH))
target=change["title"].split(':')[1] if change["title"].split(':')[1] !=change["user"] else _("their own")) else:
link = link_formatter(create_article_path(change["title"], WIKI_ARTICLE_PATH))
target_user = change["title"].split(':', 1)[1]
if target_user != author:
content = "🗑️ "+ _("[{author}]({author_url}) deleted a [comment]({comment}) on {target}'s profile".format(author=author,author_url=author_url, comment=link, target=target_user))
else:
content = "🗑️ "+ _("[{author}]({author_url}) deleted a [comment]({comment}) on their own profile".format(author=author, author_url=author_url, comment=link))
elif action == "curseprofile/profile-edited": elif action == "curseprofile/profile-edited":
link = link_formatter(create_article_path("UserProfile:{user}".format(user=change["title"].split(":")[1]), WIKI_ARTICLE_PATH)) target_user = change["title"].split(':', 1)[1]
target = _("[{target}]({target_url})'s").format(target=change["title"].split(':')[1], target_url=link) if change["title"].split(':')[1] != author else _("[their own]({target_url})").format(target_url=link) link = link_formatter(create_article_path("UserProfile:{user}".format(user=target_user), WIKI_ARTICLE_PATH))
content = "📌 "+_("[{author}]({author_url}) edited the {field} on {target} profile. *({desc})*").format(author=author, if target_user != author:
author_url=author_url, content = "📌 "+_("[{author}]({author_url}) edited the {field} on [{target}]({target_url})'s profile. *({desc})*").format(author=author,
target=target, author_url=author_url,
field=profile_field_name(change["logparams"]['4:section'], False, message_target[0][0]), target=target_user,
desc=BeautifulSoup(change["parsedcomment"], "lxml").get_text()) target_url=link,
field=profile_field_name(change["logparams"]['4:section'], False),
desc=BeautifulSoup(change["parsedcomment"], "lxml").get_text())
else:
content = "📌 " + _("[{author}]({author_url}) edited the {field} on [their own]({target_url}) profile. *({desc})*").format(
author=author,
author_url=author_url,
target_url=link,
field=profile_field_name(change["logparams"]['4:section'], False),
desc=BeautifulSoup(change["parsedcomment"], "lxml").get_text())
elif action in ("rights/rights", "rights/autopromote"): elif action in ("rights/rights", "rights/autopromote"):
link = link_formatter(create_article_path("User:{user}".format(user=change["title"].split(":")[1]), WIKI_ARTICLE_PATH)) link = link_formatter(create_article_path("User:{user}".format(user=change["title"].split(":")[1]), WIKI_ARTICLE_PATH))
old_groups = [] old_groups = []
@ -356,6 +388,150 @@ async def compact_formatter(action, change, parsed_comment, categories, recent_c
author=author, author_url=author_url, wiki_name=change["logparams"].get("wiki", _("Unknown")), author=author, author_url=author_url, wiki_name=change["logparams"].get("wiki", _("Unknown")),
comment=parsed_comment comment=parsed_comment
) )
elif action == "pagetranslation/mark":
link = create_article_path(change["title"], WIKI_ARTICLE_PATH)
if "?" in link:
link = link + "&oldid=" + change["logparams"]["revision"]
else:
link = link + "?oldid=" + change["logparams"]["revision"]
link = link_formatter(link)
content = "🌐 " + _("[{author}]({author_url}) marked [{article}]({article_url}) for translation{comment}").format(
author=author, author_url=author_url,
article=change["title"], article_url=link,
comment=parsed_comment
)
elif action == "pagetranslation/unmark":
link = link_formatter(create_article_path(change["title"], WIKI_ARTICLE_PATH))
content = "🌐 " + _("[{author}]({author_url}) removed [{article}]({article_url}) from the translation system{comment}").format(
author=author, author_url=author_url,
article=change["title"], article_url=link,
comment=parsed_comment
)
elif action == "pagetranslation/moveok":
link = link_formatter(create_article_path(change["logparams"]["target"], WIKI_ARTICLE_PATH))
content = "🌐 " + _("[{author}]({author_url}) completed moving translation pages from *{article}* to [{target}]({target_url}){comment}").format(
author=author, author_url=author_url,
article=change["title"], target=change["logparams"]["target"], target_url=link,
comment=parsed_comment
)
elif action == "pagetranslation/movenok":
link = link_formatter(create_article_path(change["title"], WIKI_ARTICLE_PATH))
target_url = link_formatter(create_article_path(change["logparams"]["target"], WIKI_ARTICLE_PATH))
content = "🌐 " + _("[{author}]({author_url}) encountered a problem while moving [{article}]({article_url}) to [{target}]({target_url}){comment}").format(
author=author, author_url=author_url,
article=change["title"], article_url=link,
target=change["logparams"]["target"], target_url=target_url,
comment=parsed_comment
)
elif action == "pagetranslation/deletefok":
link = link_formatter(create_article_path(change["title"], WIKI_ARTICLE_PATH))
content = "🌐 " + _("[{author}]({author_url}) completed deletion of translatable page [{article}]({article_url}){comment}").format(
author=author, author_url=author_url,
article=change["title"], article_url=link,
comment=parsed_comment
)
elif action == "pagetranslation/deletefnok":
link = link_formatter(create_article_path(change["title"], WIKI_ARTICLE_PATH))
target_url = link_formatter(create_article_path(change["logparams"]["target"], WIKI_ARTICLE_PATH))
content = "🌐 " + _("[{author}]({author_url}) failed to delete [{article}]({article_url}) which belongs to translatable page [{target}]({target_url}){comment}").format(
author=author, author_url=author_url,
article=change["title"], article_url=link,
target=change["logparams"]["target"], target_url=target_url,
comment=parsed_comment
)
elif action == "pagetranslation/deletelok":
link = link_formatter(create_article_path(change["title"], WIKI_ARTICLE_PATH))
content = "🌐 " + _("[{author}]({author_url}) completed deletion of translation page [{article}]({article_url}){comment}").format(
author=author, author_url=author_url,
article=change["title"], article_url=link,
comment=parsed_comment
)
elif action == "pagetranslation/deletelnok":
link = link_formatter(create_article_path(change["title"], WIKI_ARTICLE_PATH))
target_url = link_formatter(create_article_path(change["logparams"]["target"], WIKI_ARTICLE_PATH))
content = "🌐 " + _("[{author}]({author_url}) failed to delete [{article}]({article_url}) which belongs to translation page [{target}]({target_url}){comment}").format(
author=author, author_url=author_url,
article=change["title"], article_url=link,
target=change["logparams"]["target"], target_url=target_url,
comment=parsed_comment
)
elif action == "pagetranslation/encourage":
link = link_formatter(create_article_path(change["title"], WIKI_ARTICLE_PATH))
content = "🌐 " + _("[{author}]({author_url}) encouraged translation of [{article}]({article_url}){comment}").format(
author=author, author_url=author_url,
article=change["title"], article_url=link,
comment=parsed_comment
)
elif action == "pagetranslation/discourage":
link = link_formatter(create_article_path(change["title"], WIKI_ARTICLE_PATH))
content = "🌐 " + _("[{author}]({author_url}) discouraged translation of [{article}]({article_url}){comment}").format(
author=author, author_url=author_url,
article=change["title"], article_url=link,
comment=parsed_comment
)
elif action == "pagetranslation/prioritylanguages":
link = link_formatter(create_article_path(change["title"], WIKI_ARTICLE_PATH))
if "languages" in change["logparams"]:
languages = "`, `".join(change["logparams"]["languages"].split(","))
if change["logparams"]["force"] == "on":
content = "🌐 " + _("[{author}]({author_url}) limited languages for [{article}]({article_url}) to `{languages}`{comment}").format(
author=author, author_url=author_url,
article=change["title"], article_url=link,
languages=languages, comment=parsed_comment
)
else:
content = "🌐 " + _("[{author}]({author_url}) set the priority languages for [{article}]({article_url}) to `{languages}`{comment}").format(
author=author, author_url=author_url,
article=change["title"], article_url=link,
languages=languages, comment=parsed_comment
)
else:
content = "🌐 " + _("[{author}]({author_url}) removed priority languages from [{article}]({article_url}){comment}").format(
author=author, author_url=author_url,
article=change["title"], article_url=link,
comment=parsed_comment
)
elif action == "pagetranslation/associate":
link = link_formatter(create_article_path(change["title"], WIKI_ARTICLE_PATH))
content = "🌐 " + _("[{author}]({author_url}) added translatable page [{article}]({article_url}) to aggregate group \"{group}\"{comment}").format(
author=author, author_url=author_url,
article=change["title"], article_url=link,
group=change["logparams"]["aggregategroup"], comment=parsed_comment
)
elif action == "pagetranslation/dissociate":
link = link_formatter(create_article_path(change["title"], WIKI_ARTICLE_PATH))
content = "🌐 " + _("[{author}]({author_url}) removed translatable page [{article}]({article_url}) from aggregate group \"{group}\"{comment}").format(
author=author, author_url=author_url,
article=change["title"], article_url=link,
group=change["logparams"]["aggregategroup"], comment=parsed_comment
)
elif action == "translationreview/message":
link = create_article_path(change["title"], WIKI_ARTICLE_PATH)
if "?" in link:
link = link + "&oldid=" + change["logparams"]["revision"]
else:
link = link + "?oldid=" + change["logparams"]["revision"]
link = link_formatter(link)
content = "🌐 " + _("[{author}]({author_url}) reviewed translation [{article}]({article_url}){comment}").format(
author=author, author_url=author_url,
article=change["title"], article_url=link,
comment=parsed_comment
)
elif action == "translationreview/group":
link = link_formatter(create_article_path(change["title"], WIKI_ARTICLE_PATH))
if "old-state" in change["logparams"]:
content = "🌐 " + _("[{author}]({author_url}) changed the state of `{language}` translations of [{article}]({article_url}) from `{old_state}` to `{new_state}`{comment}").format(
author=author, author_url=author_url, language=change["logparams"]["language"],
article=change["logparams"]["group-label"], article_url=link,
old_state=change["logparams"]["old-state"], new_state=change["logparams"]["new-state"],
comment=parsed_comment
)
else:
content = "🌐 " + _("[{author}]({author_url}) changed the state of `{language}` translations of [{article}]({article_url}) to `{new_state}`{comment}").format(
author=author, author_url=author_url, language=change["logparams"]["language"],
article=change["logparams"]["group-label"], article_url=link,
new_state=change["logparams"]["new-state"], comment=parsed_comment
)
elif action == "renameuser/renameuser": elif action == "renameuser/renameuser":
link = link_formatter(create_article_path("User:"+change["logparams"]["newuser"], WIKI_ARTICLE_PATH)) link = link_formatter(create_article_path("User:"+change["logparams"]["newuser"], WIKI_ARTICLE_PATH))
edits = change["logparams"]["edits"] edits = change["logparams"]["edits"]
@ -372,7 +548,7 @@ async def compact_formatter(action, change, parsed_comment, categories, recent_c
content = "👁️ "+_("An action has been hidden by administration.") content = "👁️ "+_("An action has been hidden by administration.")
else: else:
logger.warning("No entry for {event} with params: {params}".format(event=action, params=change)) logger.warning("No entry for {event} with params: {params}".format(event=action, params=change))
if not settings["support"]: if not settings.get("support", None):
return return
else: else:
content = ""+_("Unknown event `{event}` by [{author}]({author_url}), report it on the [support server](<{support}>).").format(event=action, author=author, author_url=author_url, support=settings["support"]) content = ""+_("Unknown event `{event}` by [{author}]({author_url}), report it on the [support server](<{support}>).").format(event=action, author=author, author_url=author_url, support=settings["support"])
@ -472,7 +648,7 @@ async def embed_formatter(action, change, parsed_comment, categories, recent_cha
logger.warning("Request for additional image information have failed. The preview will not be shown.") logger.warning("Request for additional image information have failed. The preview will not be shown.")
if action in ("upload/overwrite", "upload/revert"): if action in ("upload/overwrite", "upload/revert"):
if additional_info_retrieved: if additional_info_retrieved:
article_encoded = change["title"].replace(" ", "_").replace("%", "%25").replace("\\", "%5C").replace("&", "%26") article_encoded = change["title"].replace(" ", "_").replace("%", "%25").replace("\\", "%5C").replace("&", "%26").replace(')', '\\)')
try: try:
revision = img_info[num+1] revision = img_info[num+1]
except IndexError: except IndexError:
@ -532,8 +708,11 @@ async def embed_formatter(action, change, parsed_comment, categories, recent_cha
english_length = english_length.rstrip("s").strip() english_length = english_length.rstrip("s").strip()
block_time = _("for {num} {translated_length}").format(num=english_length_num, translated_length=ngettext(english_length, english_length + "s", int(english_length_num))) block_time = _("for {num} {translated_length}").format(num=english_length_num, translated_length=ngettext(english_length, english_length + "s", int(english_length_num)))
except (AttributeError, ValueError): except (AttributeError, ValueError):
date_time_obj = datetime.datetime.strptime(change["logparams"]["expiry"], '%Y-%m-%dT%H:%M:%SZ') if "expiry" in change["logparams"]:
block_time = _("until {}").format(date_time_obj.strftime("%Y-%m-%d %H:%M:%S UTC")) date_time_obj = datetime.datetime.strptime(change["logparams"]["expiry"], '%Y-%m-%dT%H:%M:%SZ')
block_time = _("until {}").format(date_time_obj.strftime("%Y-%m-%d %H:%M:%S UTC"))
else:
block_time = _("unknown expiry time") # THIS IS HERE JUST TEMPORARY AS A HOT FIX TO #157, will be changed with release of 1.13
if "sitewide" not in change["logparams"]: if "sitewide" not in change["logparams"]:
restriction_description = "" restriction_description = ""
if "restrictions" in change["logparams"]: if "restrictions" in change["logparams"]:
@ -569,49 +748,67 @@ async def embed_formatter(action, change, parsed_comment, categories, recent_cha
user = change["title"].split(':', 1)[1] user = change["title"].split(':', 1)[1]
embed["title"] = _("Unblocked {blocked_user}").format(blocked_user=user) embed["title"] = _("Unblocked {blocked_user}").format(blocked_user=user)
elif action == "curseprofile/comment-created": elif action == "curseprofile/comment-created":
if settings["appearance"]["embed"]["show_edit_changes"]: if message_target[0][1] == 3:
parsed_comment = await recent_changes.pull_comment(change["logparams"]["4:comment_id"], WIKI_API_PATH, rate_limiter) parsed_comment = await recent_changes.pull_comment(change["logparams"]["4:comment_id"], WIKI_API_PATH, rate_limiter)
link = create_article_path("Special:CommentPermalink/{commentid}".format(commentid=change["logparams"]["4:comment_id"]), WIKI_ARTICLE_PATH) link = create_article_path("Special:CommentPermalink/{commentid}".format(commentid=change["logparams"]["4:comment_id"]), WIKI_ARTICLE_PATH)
embed["title"] = _("Left a comment on {target}'s profile").format(target=change["title"].split(':')[1]) if change["title"].split(':')[1] != \ target_user = change["title"].split(':', 1)[1]
change["user"] else _( if target_user != change["user"]:
"Left a comment on their own profile") embed["title"] = _("Left a comment on {target}'s profile").format(target=target_user)
else:
embed["title"] = _("Left a comment on their own profile")
elif action == "curseprofile/comment-replied": elif action == "curseprofile/comment-replied":
if settings["appearance"]["embed"]["show_edit_changes"]: if message_target[0][1] == 3:
parsed_comment = await recent_changes.pull_comment(change["logparams"]["4:comment_id"], WIKI_API_PATH, rate_limiter) parsed_comment = await recent_changes.pull_comment(change["logparams"]["4:comment_id"], WIKI_API_PATH, rate_limiter)
link = create_article_path("Special:CommentPermalink/{commentid}".format(commentid=change["logparams"]["4:comment_id"]), WIKI_ARTICLE_PATH) link = create_article_path("Special:CommentPermalink/{commentid}".format(commentid=change["logparams"]["4:comment_id"]), WIKI_ARTICLE_PATH)
embed["title"] = _("Replied to a comment on {target}'s profile").format(target=change["title"].split(':')[1]) if change["title"].split(':')[1] != \ target_user = change["title"].split(':', 1)[1]
change["user"] else _( if target_user != change["user"]:
"Replied to a comment on their own profile") embed["title"] = _("Replied to a comment on {target}'s profile").format(target=target_user)
else:
embed["title"] = _("Replied to a comment on their own profile")
elif action == "curseprofile/comment-edited": elif action == "curseprofile/comment-edited":
if settings["appearance"]["embed"]["show_edit_changes"]: if message_target[0][1] == 3:
parsed_comment = await recent_changes.pull_comment(change["logparams"]["4:comment_id"], WIKI_API_PATH, rate_limiter) parsed_comment = await recent_changes.pull_comment(change["logparams"]["4:comment_id"], WIKI_API_PATH, rate_limiter)
link = create_article_path("Special:CommentPermalink/{commentid}".format(commentid=change["logparams"]["4:comment_id"]), WIKI_ARTICLE_PATH) link = create_article_path("Special:CommentPermalink/{commentid}".format(commentid=change["logparams"]["4:comment_id"]), WIKI_ARTICLE_PATH)
embed["title"] = _("Edited a comment on {target}'s profile").format(target=change["title"].split(':')[1]) if change["title"].split(':')[1] != \ target_user = change["title"].split(':', 1)[1]
change["user"] else _( if target_user != change["user"]:
"Edited a comment on their own profile") embed["title"] = _("Edited a comment on {target}'s profile").format(target=target_user)
else:
embed["title"] = _("Edited a comment on their own profile")
elif action == "curseprofile/profile-edited": elif action == "curseprofile/profile-edited":
link = create_article_path("UserProfile:{target}".format(target=change["title"].split(':')[1]), WIKI_ARTICLE_PATH) target_user = change["title"].split(':', 1)[1]
embed["title"] = _("Edited {target}'s profile").format(target=change["title"].split(':')[1]) if change["user"] != change["title"].split(':')[1] else _("Edited their own profile") link = create_article_path("UserProfile:{target}".format(target=target_user), WIKI_ARTICLE_PATH)
if target_user != change["user"]:
embed["title"] = _("Edited {target}'s profile").format(target=target_user)
else:
embed["title"] = _("Edited their own profile")
if not change["parsedcomment"]: # If the field is empty if not change["parsedcomment"]: # If the field is empty
parsed_comment = _("Cleared the {field} field").format(field=profile_field_name(change["logparams"]['4:section'], True, message_target[0][0])) parsed_comment = _("Cleared the {field} field").format(field=profile_field_name(change["logparams"]['4:section'], True, message_target[0][0]))
else: else:
parsed_comment = _("{field} field changed to: {desc}").format(field=profile_field_name(change["logparams"]['4:section'], True, message_target[0][0]), desc=BeautifulSoup(change["parsedcomment"], "lxml").get_text()) parsed_comment = _("{field} field changed to: {desc}").format(field=profile_field_name(change["logparams"]['4:section'], True, message_target[0][0]), desc=BeautifulSoup(change["parsedcomment"], "lxml").get_text())
elif action == "curseprofile/comment-purged": elif action == "curseprofile/comment-purged":
link = create_article_path("Special:CommentPermalink/{commentid}".format(commentid=change["logparams"]["4:comment_id"]), WIKI_ARTICLE_PATH) link = create_article_path(change["title"], WIKI_ARTICLE_PATH)
embed["title"] = _("Purged a comment on {target}'s profile").format(target=change["title"].split(':')[1]) target_user = change["title"].split(':', 1)[1]
if target_user != change["user"]:
embed["title"] = _("Purged a comment on {target}'s profile").format(target=target_user)
else:
embed["title"] = _("Purged a comment on their own profile")
elif action == "curseprofile/comment-deleted": elif action == "curseprofile/comment-deleted":
if "4:comment_id" in change["logparams"]: if "4:comment_id" in change["logparams"]:
link = create_article_path("Special:CommentPermalink/{commentid}".format(commentid=change["logparams"]["4:comment_id"]), WIKI_ARTICLE_PATH) link = create_article_path("Special:CommentPermalink/{commentid}".format(commentid=change["logparams"]["4:comment_id"]), WIKI_ARTICLE_PATH)
else: else:
link = create_article_path(change["title"], WIKI_ARTICLE_PATH) link = create_article_path(change["title"], WIKI_ARTICLE_PATH)
embed["title"] = _("Deleted a comment on {target}'s profile").format(target=change["title"].split(':')[1]) target_user = change["title"].split(':', 1)[1]
if target_user != change["user"]:
embed["title"] = _("Deleted a comment on {target}'s profile").format(target=target_user)
else:
embed["title"] = _("Deleted a comment on their own profile")
elif action in ("rights/rights", "rights/autopromote"): elif action in ("rights/rights", "rights/autopromote"):
link = create_article_path("User:{}".format(change["title"].split(":")[1]), WIKI_ARTICLE_PATH) link = create_article_path("User:{}".format(change["title"].split(":")[1]), WIKI_ARTICLE_PATH)
if action == "rights/rights": if action == "rights/rights":
embed["title"] = _("Changed group membership for {target}").format(target=change["title"].split(":")[1]) embed["title"] = _("Changed group membership for {target}").format(target=change["title"].split(":")[1])
else: else:
change["user"] = _("System")
author_url = "" author_url = ""
embed.set_author(_("System"), author_url)
embed["title"] = _("{target} got autopromoted to a new usergroup").format( embed["title"] = _("{target} got autopromoted to a new usergroup").format(
target=change["title"].split(":")[1]) target=change["title"].split(":")[1])
if len(change["logparams"]["oldgroups"]) < len(change["logparams"]["newgroups"]): if len(change["logparams"]["oldgroups"]) < len(change["logparams"]["newgroups"]):
@ -785,6 +982,69 @@ async def embed_formatter(action, change, parsed_comment, categories, recent_cha
elif action == "managewiki/unlock": elif action == "managewiki/unlock":
embed["title"] = _("Unlocked a \"{wiki}\" wiki").format(wiki=change["logparams"].get("wiki", _("Unknown"))) embed["title"] = _("Unlocked a \"{wiki}\" wiki").format(wiki=change["logparams"].get("wiki", _("Unknown")))
link = create_article_path("", WIKI_ARTICLE_PATH) link = create_article_path("", WIKI_ARTICLE_PATH)
elif action == "pagetranslation/mark":
link = create_article_path(change["title"], WIKI_ARTICLE_PATH)
if "?" in link:
link = link + "&oldid=" + change["logparams"]["revision"]
else:
link = link + "?oldid=" + change["logparams"]["revision"]
embed["title"] = _("Marked \"{article}\" for translation").format(article=change["title"])
elif action == "pagetranslation/unmark":
link = create_article_path(change["title"], WIKI_ARTICLE_PATH)
embed["title"] = _("Removed \"{article}\" from the translation system").format(article=change["title"])
elif action == "pagetranslation/moveok":
link = create_article_path(change["logparams"]["target"], WIKI_ARTICLE_PATH)
embed["title"] = _("Completed moving translation pages from \"{article}\" to \"{target}\"").format(article=change["title"], target=change["logparams"]["target"])
elif action == "pagetranslation/movenok":
link = create_article_path(change["title"], WIKI_ARTICLE_PATH)
embed["title"] = _("Encountered a problem while moving \"{article}\" to \"{target}\"").format(article=change["title"], target=change["logparams"]["target"])
elif action == "pagetranslation/deletefok":
link = create_article_path(change["title"], WIKI_ARTICLE_PATH)
embed["title"] = _("Completed deletion of translatable page \"{article}\"").format(article=change["title"])
elif action == "pagetranslation/deletefnok":
link = create_article_path(change["title"], WIKI_ARTICLE_PATH)
embed["title"] = _("Failed to delete \"{article}\" which belongs to translatable page \"{target}\"").format(article=change["title"], target=change["logparams"]["target"])
elif action == "pagetranslation/deletelok":
link = create_article_path(change["title"], WIKI_ARTICLE_PATH)
embed["title"] = _("Completed deletion of translation page \"{article}\"").format(article=change["title"])
elif action == "pagetranslation/deletelnok":
link = create_article_path(change["title"], WIKI_ARTICLE_PATH)
embed["title"] = _("Failed to delete \"{article}\" which belongs to translation page \"{target}\"").format(article=change["title"], target=change["logparams"]["target"])
elif action == "pagetranslation/encourage":
link = create_article_path(change["title"], WIKI_ARTICLE_PATH)
embed["title"] = _("Encouraged translation of \"{article}\"").format(article=change["title"])
elif action == "pagetranslation/discourage":
link = create_article_path(change["title"], WIKI_ARTICLE_PATH)
embed["title"] = _("Discouraged translation of \"{article}\"").format(article=change["title"])
elif action == "pagetranslation/prioritylanguages":
link = create_article_path(change["title"], WIKI_ARTICLE_PATH)
if "languages" in change["logparams"]:
languages = "`, `".join(change["logparams"]["languages"].split(","))
if change["logparams"]["force"] == "on":
embed["title"] = _("Limited languages for \"{article}\" to `{languages}`").format(article=change["title"], languages=languages)
else:
embed["title"] = _("Priority languages for \"{article}\" set to `{languages}`").format(article=change["title"], languages=languages)
else:
embed["title"] = _("Removed priority languages from \"{article}\"").format(article=change["title"])
elif action == "pagetranslation/associate":
link = create_article_path(change["title"], WIKI_ARTICLE_PATH)
embed["title"] = _("Added translatable page \"{article}\" to aggregate group \"{group}\"").format(article=change["title"], group=change["logparams"]["aggregategroup"])
elif action == "pagetranslation/dissociate":
link = create_article_path(change["title"], WIKI_ARTICLE_PATH)
embed["title"] = _("Removed translatable page \"{article}\" from aggregate group \"{group}\"").format(article=change["title"], group=change["logparams"]["aggregategroup"])
elif action == "translationreview/message":
link = create_article_path(change["title"], WIKI_ARTICLE_PATH)
if "?" in link:
link = link + "&oldid=" + change["logparams"]["revision"]
else:
link = link + "?oldid=" + change["logparams"]["revision"]
embed["title"] = _("Reviewed translation \"{article}\"").format(article=change["title"])
elif action == "translationreview/group":
link = create_article_path(change["title"], WIKI_ARTICLE_PATH)
embed["title"] = _("Changed the state of `{language}` translations of \"{article}\"").format(language=change["logparams"]["language"], article=change["title"])
if "old-state" in change["logparams"]:
embed.add_field(_("Old state"), change["logparams"]["old-state"], inline=True)
embed.add_field(_("New state"), change["logparams"]["new-state"], inline=True)
elif action == "renameuser/renameuser": elif action == "renameuser/renameuser":
edits = change["logparams"]["edits"] edits = change["logparams"]["edits"]
if edits > 0: if edits > 0:
@ -794,14 +1054,14 @@ async def embed_formatter(action, change, parsed_comment, categories, recent_cha
link = create_article_path("User:"+change["logparams"]["newuser"], WIKI_ARTICLE_PATH) link = create_article_path("User:"+change["logparams"]["newuser"], WIKI_ARTICLE_PATH)
elif action == "suppressed": elif action == "suppressed":
link = create_article_path("", WIKI_ARTICLE_PATH) link = create_article_path("", WIKI_ARTICLE_PATH)
embed["title"] = _("Action has been hidden by administration.") embed["title"] = _("Action has been hidden by administration")
embed["author"]["name"] = _("Unknown") embed["author"]["name"] = _("Unknown")
else: else:
logger.warning("No entry for {event} with params: {params}".format(event=action, params=change)) logger.warning("No entry for {event} with params: {params}".format(event=action, params=change))
link = create_article_path("Special:RecentChanges", WIKI_ARTICLE_PATH) link = create_article_path("Special:RecentChanges", WIKI_ARTICLE_PATH)
embed["title"] = _("Unknown event `{event}`").format(event=action) embed["title"] = _("Unknown event `{event}`").format(event=action)
embed["color"] = 0 embed["color"] = 0
if settings["support"]: if settings.get("support", None):
change_params = "[```json\n{params}\n```]({support})".format(params=json.dumps(change, indent=2), support=settings["support"]) change_params = "[```json\n{params}\n```]({support})".format(params=json.dumps(change, indent=2), support=settings["support"])
if len(change_params) > 1000: if len(change_params) > 1000:
embed.add_field(_("Report this on the support server"), settings["support"]) embed.add_field(_("Report this on the support server"), settings["support"])
@ -824,6 +1084,8 @@ async def embed_formatter(action, change, parsed_comment, categories, recent_cha
else: else:
tag_displayname.append(tag) tag_displayname.append(tag)
embed.add_field(_("Tags"), ", ".join(tag_displayname)) embed.add_field(_("Tags"), ", ".join(tag_displayname))
if len(embed["title"]) > 254:
embed["title"] = embed["title"][0:253]+""
logger.debug("Current params in edit action: {}".format(change)) logger.debug("Current params in edit action: {}".format(change))
if categories and not (len(categories["new"]) == 0 and len(categories["removed"]) == 0): if categories and not (len(categories["new"]) == 0 and len(categories["removed"]) == 0):
new_cat = (_("**Added**: ") + ", ".join(list(categories["new"])[0:16]) + ("\n" if len(categories["new"])<=15 else _(" and {} more\n").format(len(categories["new"])-15))) if categories["new"] else "" new_cat = (_("**Added**: ") + ", ".join(list(categories["new"])[0:16]) + ("\n" if len(categories["new"])<=15 else _(" and {} more\n").format(len(categories["new"])-15))) if categories["new"] else ""

View file

@ -19,7 +19,7 @@ class UpdateDB:
if update[2] is None: if update[2] is None:
sql = "UPDATE rcgcdw SET rcid = ? WHERE wiki = ? AND ( rcid != -1 OR rcid IS NULL )" sql = "UPDATE rcgcdw SET rcid = ? WHERE wiki = ? AND ( rcid != -1 OR rcid IS NULL )"
else: else:
sql = "UPDATE rcgcdw SET postid = ? WHERE wiki = ?" sql = "UPDATE rcgcdw SET postid = ? WHERE wiki = ? AND ( postid != '-1' OR postid IS NULL )"
db_cursor.execute(sql, (update[1], update[0],)) db_cursor.execute(sql, (update[1], update[0],))
db_connection.commit() db_connection.commit()
self.clear_list() self.clear_list()

View file

@ -17,21 +17,6 @@ from bs4 import BeautifulSoup
logger = logging.getLogger("rcgcdb.wiki") logger = logging.getLogger("rcgcdb.wiki")
supported_logs = {"protect/protect", "protect/modify", "protect/unprotect", "upload/overwrite", "upload/upload",
"delete/delete", "delete/delete_redir", "delete/restore", "delete/revision", "delete/event",
"import/upload", "import/interwiki", "merge/merge", "move/move", "move/move_redir",
"protect/move_prot", "block/block", "block/unblock", "block/reblock", "rights/rights",
"rights/autopromote", "abusefilter/modify", "abusefilter/create", "interwiki/iw_add",
"interwiki/iw_edit", "interwiki/iw_delete", "curseprofile/comment-created",
"curseprofile/comment-edited", "curseprofile/comment-deleted", "curseprofile/comment-purged",
"curseprofile/profile-edited", "curseprofile/comment-replied", "contentmodel/change", "sprite/sprite",
"sprite/sheet", "sprite/slice", "managetags/create", "managetags/delete", "managetags/activate",
"managetags/deactivate", "tag/update", "cargo/createtable", "cargo/deletetable",
"cargo/recreatetable", "cargo/replacetable", "upload/revert", "newusers/create",
"newusers/autocreate", "newusers/create2", "newusers/byemail", "newusers/newusers",
"managewiki/settings", "managewiki/delete", "managewiki/lock", "managewiki/unlock",
"managewiki/namespaces", "managewiki/namespaces-delete", "managewiki/rights", "managewiki/undelete"}
@dataclass @dataclass
class Wiki: class Wiki: