Topic on Project:Support desk

is the current page in a special category?

17
Paul Hema (talkcontribs)

Moin,

how can I find out whether the current page is assigned to a special category?


Example: {{#if: {{PAGENAME}} #isincategory: test | yes | no }}(I want to check whether the current page is in the category "test")


Thanks, Paul

Jackmcbarn (talkcontribs)

This isn't possible, and we'll never be able to do it because it would result in paradoxes. For example, {{#if: {{PAGENAME}} #isincategory: test | blah | [[Category:test]] }} would always be wrong.

88.130.125.20 (talkcontribs)

I don't see why such a paradoxon (it is not a contradiction) should be a problem.

Jackmcbarn (talkcontribs)

It is a contradiction. If the page were in Category:test, then it wouldn't be placed in it, but if it weren't in it, it would be placed in it.

88.130.125.20 (talkcontribs)

Ahh, I somehow missed the last part of the expression. Anyways, "if the page is not in category x, then put it in category x" only is a weird way of writing things, but it is no contradiction. Before this line is parsed, MediaWiki does not know the page is in the cat, but after it is parsed, it does know. Adding the category to the page in the normal way also adds it to the category and if you try to put the same page into the same category a second time, then this second category also will do nothing at all - just like the condition in your example won't add the page to the category again, if it already is in it. Apart from that Paul never said that based on the "is in category" condition he wanted to put the page in exactly this category. I see a row of valid usecases there. So why is what he is trying to do not working?

Possible answers I could think of are: Because this condition is just not implemented (I have not found any documentation of #isincategory:). Or: At the time the above code is executed, MediaWiki just does not (or not yet) know, which categories the article is in.

Jackmcbarn (talkcontribs)

Indeed, there's no such thing as #isincategory. I only used it in my example because the OP did as well. "At the time the above code is executed, MediaWiki just does not (or not yet) know, which categories the article is in." This is true, and it can't know in time because of the above paradox.

88.130.125.20 (talkcontribs)

That does not answer the question. :-) Let me rephrase: At which point are parser conditions evaluated? Or is there not one certain point, at which this happens?

Somewhere else in the rendering process MediaWiki parses the page for categories, in which the page is. When is this point? Before or after the other one? If it was after the parser condition check, parser conditions could easily put a page in a category. And also if it was before I would not say it must directly be completely impossible to later add a cat anyway. (In fact there also are several hooks, which amongst other things allow you to put a page inside a category - and this also in the case that the page itself does not contain a reference to this category).

Jackmcbarn (talkcontribs)

Parser conditions are evaluated before a page is put into categories.

Paul Hema (talkcontribs)

Thanks for the discussion.

There is no #isincategory :-) unfortunately

88.130.90.201 (talkcontribs)

Then you should open a BUGREPORT and request such a parser function as a new feature! :-)

Jackmcbarn (talkcontribs)

No you shouldn't. As I just explained, such a feature will not be added.

88.130.90.201 (talkcontribs)

An in-category check is useful and should be added.

Jackmcbarn (talkcontribs)

As I explained at length, it will not be.

88.130.90.201 (talkcontribs)

It's ok. You are right and I am left in peace.

Florianschmidtwelzow (talkcontribs)

Hello both :)

@88.130.90.201: Feel free to open a bug report, if you think, the reasons, Jackmcbarn already gave you, are false or incomplete. But maybe it's correct, what he said, so the bug report will be closed as wontfix ;) Sometimes the opinion of a developer isn't false :)

Subfader (talkcontribs)
88.130.90.201 (talkcontribs)

Seems like Extension:PageInCat is the recommended replacement of HasCategory. It can do exactly what Paul asks for - and maybe even more!

Reply to "is the current page in a special category?"