Compare commits

..

2 commits

2 changed files with 11 additions and 6 deletions

View file

@ -11,7 +11,7 @@ import werkzeug
from requests_oauthlib import OAuth1Session
from werkzeug.wrappers.response import Response
from add_links import api, core, mediawiki_api, wikidata_oauth
from add_links import api, core, mediawiki_api, mediawiki_oauth
from add_links.match import NoMatch, get_diff, get_match
app = flask.Flask(__name__)
@ -83,7 +83,7 @@ def search_no_link(q: str) -> tuple[int, list[Hit]]:
@app.before_request
def global_user() -> None:
"""Make username available everywhere."""
flask.g.user = wikidata_oauth.get_username()
flask.g.user = mediawiki_oauth.get_username()
@app.route("/")
@ -268,7 +268,7 @@ def article_page(url_title: str) -> str | Response:
hit_title = flask.request.form["hit"]
try:
do_save(from_title, hit_title)
except wikidata_oauth.LoginNeeded:
except mediawiki_oauth.LoginNeeded:
return flask.redirect(flask.url_for("start_oauth"))
return flask.redirect(
flask.url_for("article_page", url_title=url_title, after=hit_title)
@ -283,10 +283,15 @@ def article_page(url_title: str) -> str | Response:
by_title = {hit["title"]: hit for hit in hits}
found = None
if article_title in by_title:
hit = by_title[article_title]
try:
found = get_diff(from_title, hit["title"], None)
else:
except NoMatch:
pass
if not found:
after = flask.request.args.get("after")
if after:
print(after)
@ -316,7 +321,7 @@ def article_page(url_title: str) -> str | Response:
def do_save(title: str, hit_title: str) -> str:
"""Update page on Wikipedia."""
token = wikidata_oauth.get_token()
token = mediawiki_oauth.get_token()
found = get_match(title, hit_title, None)