diff --git a/extensions/base/mediawiki.py b/extensions/base/mediawiki.py index dab7165..51e38ce 100644 --- a/extensions/base/mediawiki.py +++ b/extensions/base/mediawiki.py @@ -64,7 +64,7 @@ def embed_edit(ctx: Context, change: dict) -> DiscordMessage: article=sanitize_to_url(change["title"]) ) embed["title"] = "{redirect}{article} ({new}{minor}{bot}{space}{editsize})".format( - redirect="⤷ " if "redirect" in change else "", + redirect="⤷ " if change.get("redirect", False) else "", article=sanitize_to_markdown(change["title"]), editsize="+" + str(editsize) if editsize > 0 else editsize, new=ctx._("(N!) ") if action == "new" else "", @@ -75,12 +75,12 @@ def embed_edit(ctx: Context, change: dict) -> DiscordMessage: try: if action == "new": changed_content = ctx.client.make_api_request( - "?action=compare&format=json&fromslots=main&torev={diff}&fromtext-main=&topst=1&prop=diff".format( - diff=change["revid"]), "compare", "*") + "?action=compare&format=json&formatversion=2&fromslots=main&torev={diff}&fromtext-main=&topst=1&prop=diff".format( + diff=change["revid"]), "compare", "body") else: changed_content = ctx.client.make_api_request( - "?action=compare&format=json&fromrev={oldrev}&torev={diff}&topst=1&prop=diff".format( - diff=change["revid"], oldrev=change["old_revid"]), "compare", "*") + "?action=compare&format=json&formatversion=2&fromrev={oldrev}&torev={diff}&topst=1&prop=diff".format( + diff=change["revid"], oldrev=change["old_revid"]), "compare", "body") except (ServerError, MediaWikiError): changed_content = None if changed_content: @@ -630,7 +630,7 @@ def embed_block_block(ctx: Context, change: dict): 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)]["*"])) + namespaces.append("*{ns}*".format(ns=ctx.client.namespaces[str(namespace)]["name"])) else: namespaces.append("*{ns}*".format(ns=namespace)) restriction_description = restriction_description + ", ".join(namespaces) @@ -678,7 +678,7 @@ def compact_block_block(ctx: Context, change: dict): 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)]["*"])) + namespaces.append("*{ns}*".format(ns=ctx.client.namespaces[str(namespace)]["name"])) else: namespaces.append("*{ns}*".format(ns=namespace)) restriction_description = restriction_description + ", ".join(namespaces) diff --git a/extensions/hooks/talk_notify.py b/extensions/hooks/talk_notify.py index 4d1e4a9..1e04c61 100644 --- a/extensions/hooks/talk_notify.py +++ b/extensions/hooks/talk_notify.py @@ -49,7 +49,7 @@ talk_notify = settings.get("hooks", {}).get("talk_notify", {}) def talk_notify_hook(context: Context, change: dict): if not talk_notify.get("default", []) or context.event not in ("edit", "new"): return - if "minor" in change or change["ns"] == 3: + if change.get("minor", False) or change["ns"] == 3: return ignore = change["ns"] % 2 == 0 if ignore and talk_notify.get("extra_pages", {}): diff --git a/src/misc.py b/src/misc.py index 46d764f..fd797ab 100644 --- a/src/misc.py +++ b/src/misc.py @@ -245,14 +245,14 @@ def safe_read(request, *keys): def parse_mw_request_info(request_data: dict, url: str): """A function parsing request JSON message from MediaWiki logging all warnings and raising on MediaWiki errors""" # any([True for k in request_data.keys() if k in ("error", "errors")]) - errors: list = request_data.get("errors", {}) # Is it ugly? I don't know tbh + errors: dict = request_data.get("errors", {}) # Is it ugly? I don't know tbh if errors: raise MediaWikiError(str(errors)) - warnings: list = request_data.get("warnings", {}) + warnings: dict = request_data.get("warnings", {}) if warnings: - for warning in warnings: - misc_logger.warning("MediaWiki returned the following warning: {code} - {text} on {url}.".format( - code=warning["code"], text=warning.get("text", warning.get("*", "")), url=url + for module, warning_data in warnings.items(): + misc_logger.warning("MediaWiki returned the following warning on module {module}: {text} on {url}.".format( + module=module, text=warning_data.get("warnings", ""), url=url )) return request_data diff --git a/src/wiki.py b/src/wiki.py index 54141be..e067a19 100644 --- a/src/wiki.py +++ b/src/wiki.py @@ -259,10 +259,10 @@ class Wiki(object): abuselog = request_json["query"]["abuselog"] # While LYBL approach would be more performant when abuselog is not in request body, I prefer this approach for its clarity except KeyError: if "warnings" in request_json: - warnings = request_json.get("warnings", {"query": {"*": ""}}) - if "Unrecognized value for parameter \"list\": abuselog." in warnings["query"]["*"]: + warnings = request_json.get("warnings", {"query": {"warnings": ""}}) + if "Unrecognized value for parameter \"list\": abuselog." in warnings["query"]["warnings"]: settings["show_abuselog"] = False - logger.warning("AbuseLog extension is not enabled on the wiki. Disabling the function...") + logger.warning("AbuseLog extension is not enabled on the wiki. Disabling the function for this session...") else: abuselog_last_id = self.prepare_abuse_log(abuselog) return rc_last_id, abuselog_last_id @@ -432,13 +432,13 @@ class Wiki(object): if startup_info: if "tags" in startup_info and "allmessages" in startup_info: for tag in startup_info["tags"]: - try: + if tag["displayname"]: self.tags[tag["name"]] = (BeautifulSoup(tag["displayname"], "lxml")).get_text() - except KeyError: + else: self.tags[tag["name"]] = None # Tags with no display name are hidden and should not appear on RC as well for message in startup_info["allmessages"]: - if "missing" not in message: # ignore missing strings - self.mw_messages[message["name"]] = message["*"] + if message.get("missing", False) is False: # ignore missing strings + self.mw_messages[message["name"]] = message["content"] else: logging.warning("Could not fetch the MW message translation for: {}".format(message["name"])) for key, message in self.mw_messages.items():