diff --git a/extensions/base/mediawiki.py b/extensions/base/mediawiki.py index fbc0676..7ce5c19 100644 --- a/extensions/base/mediawiki.py +++ b/extensions/base/mediawiki.py @@ -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))) except ValueError: link = clean_link(ctx.client.create_article_path(sanitize_to_url(change["title"]))) - else: - if "sitewide" not in change["logparams"]: - if "restrictions" in change["logparams"]: - if "pages" in change["logparams"]["restrictions"] and change["logparams"]["restrictions"]["pages"]: - restriction_description = ctx._(" on pages: ") - restricted_pages = ["*{page}*".format(page=i["page_title"]) for i in - change["logparams"]["restrictions"]["pages"]] - restriction_description = restriction_description + ", ".join(restricted_pages) - if "namespaces" in change["logparams"]["restrictions"] and change["logparams"]["restrictions"][ - "namespaces"]: - namespaces = [] - if restriction_description: - restriction_description = restriction_description + ctx._(" and namespaces: ") + if "sitewide" not in change["logparams"]: + if "restrictions" in change["logparams"]: + if "pages" in change["logparams"]["restrictions"] and change["logparams"]["restrictions"]["pages"]: + restriction_description = ctx._(" on pages: ") + restricted_pages = ["*{page}*".format(page=i["page_title"]) for i in + change["logparams"]["restrictions"]["pages"]] + restriction_description = restriction_description + ", ".join(restricted_pages) + if "namespaces" in change["logparams"]["restrictions"] and change["logparams"]["restrictions"][ + "namespaces"]: + namespaces = [] + if restriction_description: + 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: - 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: - 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] + "…" + 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._( "[{author}]({author_url}) blocked [{user}]({user_url}) {time}{restriction_desc}{comment}").format(author=author, author_url=author_url,