Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirects to not-existant articles handled inconsistently #75

Closed
JN-Jones opened this issue Aug 1, 2024 · 2 comments
Closed

Redirects to not-existant articles handled inconsistently #75

JN-Jones opened this issue Aug 1, 2024 · 2 comments

Comments

@JN-Jones
Copy link

JN-Jones commented Aug 1, 2024

I have a simple article that redirects to a missing article. When creating the page instance and immediately calling getRedirectTarget or isRedirect the call throws a MwnErrorMissingPage error because the api (obviously) returns that the target doesn't exist. However when first calling text on the page instance, getRedirectTarget uses the text of the article to determine the (intended) redirect target and correctly returns it. Imho the (externally observed) behaviour shouldn't change based on other calls I might've done before, ideally returning the target either way.

While checking the function I've seen that there's also a regex in place, however that didn't work at all for me and it also doesn't consider localizations (eg in a german wiki #weiterleitung and #redirect are valid).

@siddharthvp
Copy link
Owner

All valid points. Unfortunately, the read operations in MwnPage are a mess. In addition, many of the methods in this class use action=parse which invokes the MediaWiki parser instead of reading pre-parsed data from the db. All of this needs to be resolved in a v3 release as they involve breaking changes. For now, I'd suggest using lower-level methods, bot.read() or bot.query(), to get the data directly.

@JN-Jones
Copy link
Author

JN-Jones commented Aug 1, 2024

For now I've switched back to an implementation from an old bot of mine which simply uses a regex instead of the library provided ones:

  private getRedirectTargetFromText = async () => {
    const text = await this.page.text();
    const match = text.match(/\s*#(redirect|weiterleitung)\s*\[\[([^|]*)(\|.*)?\]\]/is);
    if (match !== null && match.length > 3) {
      return match[2];
    }

    return false;
  };

Obviously currently only handles english and german, which would need to be adjusted, but maybe this would be an idea? At least in the wiki the bot is currently running this catches all cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants