Fixed wrong handling of compact block formatter

This commit is contained in:
Frisk 2023-12-30 17:51:57 +01:00
parent d23ba0ca5d
commit 0610a0e030

View file

@ -647,33 +647,32 @@ def compact_block_block(ctx: Context, change: dict):
link = clean_link(ctx.client.create_article_path("Special:Contributions/{user}".format(user=user))) link = clean_link(ctx.client.create_article_path("Special:Contributions/{user}".format(user=user)))
except ValueError: except ValueError:
link = clean_link(ctx.client.create_article_path(sanitize_to_url(change["title"]))) link = clean_link(ctx.client.create_article_path(sanitize_to_url(change["title"])))
else: if "sitewide" not in change["logparams"]:
if "sitewide" not in change["logparams"]: if "restrictions" in change["logparams"]:
if "restrictions" in change["logparams"]: if "pages" in change["logparams"]["restrictions"] and change["logparams"]["restrictions"]["pages"]:
if "pages" in change["logparams"]["restrictions"] and change["logparams"]["restrictions"]["pages"]: restriction_description = ctx._(" on pages: ")
restriction_description = ctx._(" on pages: ") restricted_pages = ["*{page}*".format(page=i["page_title"]) for i in
restricted_pages = ["*{page}*".format(page=i["page_title"]) for i in change["logparams"]["restrictions"]["pages"]]
change["logparams"]["restrictions"]["pages"]] restriction_description = restriction_description + ", ".join(restricted_pages)
restriction_description = restriction_description + ", ".join(restricted_pages) if "namespaces" in change["logparams"]["restrictions"] and change["logparams"]["restrictions"][
if "namespaces" in change["logparams"]["restrictions"] and change["logparams"]["restrictions"][ "namespaces"]:
"namespaces"]: namespaces = []
namespaces = [] if restriction_description:
if restriction_description: restriction_description = restriction_description + ctx._(" and namespaces: ")
restriction_description = restriction_description + ctx._(" and namespaces: ") else:
restriction_description = ctx._(" on namespaces: ")
for namespace in change["logparams"]["restrictions"]["namespaces"]:
if str(namespace) == "0":
namespaces.append("*{ns}*".format(ns=ctx._("(Main)")))
elif str(namespace) in ctx.client.namespaces: # if we have cached namespace name for given namespace number, add its name to the list
namespaces.append("*{ns}*".format(ns=ctx.client.namespaces[str(namespace)]["*"]))
else: else:
restriction_description = ctx._(" on namespaces: ") namespaces.append("*{ns}*".format(ns=namespace))
for namespace in change["logparams"]["restrictions"]["namespaces"]: restriction_description = restriction_description + ", ".join(namespaces)
if str(namespace) == "0": restriction_description = restriction_description + "."
namespaces.append("*{ns}*".format(ns=ctx._("(Main)"))) if len(restriction_description) > 1020:
elif str(namespace) in ctx.client.namespaces: # if we have cached namespace name for given namespace number, add its name to the list logger.debug(restriction_description)
namespaces.append("*{ns}*".format(ns=ctx.client.namespaces[str(namespace)]["*"])) restriction_description = restriction_description[:1020] + ""
else:
namespaces.append("*{ns}*".format(ns=namespace))
restriction_description = restriction_description + ", ".join(namespaces)
restriction_description = restriction_description + "."
if len(restriction_description) > 1020:
logger.debug(restriction_description)
restriction_description = restriction_description[:1020] + ""
content = ctx._( content = ctx._(
"[{author}]({author_url}) blocked [{user}]({user_url}) {time}{restriction_desc}{comment}").format(author=author, "[{author}]({author_url}) blocked [{user}]({user_url}) {time}{restriction_desc}{comment}").format(author=author,
author_url=author_url, author_url=author_url,