From 4dfbd002f6065a39f536ac2160dfd035148a7c80 Mon Sep 17 00:00:00 2001 From: Kumi Date: Mon, 19 Aug 2024 17:06:48 +0200 Subject: [PATCH] feat: add redirect handling for /index.php route Added a new route to handle redirects from ///w/index.php. The redirect fetches the main page from the Wiki API and redirects to it. This improves user navigation by dynamically redirecting to the main page of the relevant project and language. --- src/wikimore/app.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/wikimore/app.py b/src/wikimore/app.py index 2899f60..d8bf5f4 100644 --- a/src/wikimore/app.py +++ b/src/wikimore/app.py @@ -293,6 +293,20 @@ logger.debug( ) +@app.route("///w/index.php") +def index_php_redirect(project, lang): + # TODO: Handle query string + + url = f"{app.languages[lang]['projects'][project]}/w/api.php?action=query&format=json&meta=siteinfo&siprop=general" + with urllib.request.urlopen(url) as response: + data = json.loads(response.read().decode()) + main_page = data["query"]["general"]["mainpage"] + + return redirect( + url_for("wiki_article", project=project, lang=lang, title=main_page) + ) + + def main(): port = int(os.environ.get("PORT", 8109)) host = os.environ.get("HOST", "0.0.0.0")