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

Handling of categories with prefix doesn't work #80

Open
JN-Jones opened this issue Aug 5, 2024 · 1 comment
Open

Handling of categories with prefix doesn't work #80

JN-Jones opened this issue Aug 5, 2024 · 1 comment

Comments

@JN-Jones
Copy link

JN-Jones commented Aug 5, 2024

In our wiki we have some categories specifically to group templates. In certain scenarios however this seems to cause issues with the bot. Ie new bot.Category("Template:Infobox") throws Error: not a category page instead of referencing Category:Template:Infobox. This can also be observed with MwnTitle: new bot.Title('Template:Infobox', Namespace.CATEGORY); results in { namespace: 10, title: 'Infobox', fragment: null }. Using an invalid prefix however works as intended: new bot.Title('Invalid:Infobox', Namespace.CATEGORY); results in { namespace: 14, title: 'Infobox', fragment: null }. Prefixing the title correctly with Category: also works: new bot.Title('Category:Template:Infobox', Namespace.CATEGORY); results in { namespace: 14, title: 'Template:Infobox', fragment: null }.

One use case where this issue becomes apparent is when trying to map included categories:

    const article = new bot.Page(PAGE_IN_TEMPLATE_CATEGORY, Namespace.TEMPLATE);
    const categories = (await article.categories()).map(({ category }) => new bot.Category(category));
@siddharthvp
Copy link
Owner

siddharthvp commented Sep 9, 2024

This is mostly intentional. Title's interface matches that of mw.Title in the on-site JS interface - which works similarly and only uses the second constructor arg if the page name passed doesn't already have a namespace.

You can use makeTitle to create a title without namespace auto-inference, and then create a Category object using the Title object.

let title = bot.Title.makeTitle(Namespace.CATEGORY, "Template:Infobox");
let category = new bot.Category(title);

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