Topic on Extension talk:ParserFunctions

#ifexist and empty pages

5
Peachey88 (Flood) (talkcontribs)

Hi, would it be possible to have a function similar to #ifexist but that also checks that the page is not empty ?

For example, some templates (like fr:Modèle:Wikiprojet for TODO subpages) currently use #ifexist to chech that the page exists before including it and putting decorations around it (rounded frame, explanations, ...). It could be useful to be able to check also that the page is not empty before including it.

This post was posted by Peachey88 (Flood), but signed as NicoV.

Peachey88 (Flood) (talkcontribs)

This can already be done using the {{PAGESIZE}} magic word. It will give you the page size, and you can use ParserFunctions #ifexpr to set some minimum size threshold before performing some other action. I hope that info helps.

This post was posted by Peachey88 (Flood), but signed as Badon.

NicoV (talkcontribs)

Yes, thanks. I could use {{PAGESIZE}}, but I wanted to avoid using a magic word marked as expensive for a template that is used on many talk pages (probably several 100.000). Would it be a problem?

And a minor disagreement: I would need to repeat the text that is inserted when the subpage is not filled, something like {{#ifexist: {{FULLPAGENAME}}/Subpage | {{#ifexpr: {{PAGESIZE:{{FULLPAGENAME}}/Subpage}} > 0 | {{/Subpage}} | Other text }} | Other text}} Anyway, thanks for the answer.

--NicoV 09:59, 14 January 2012 (UTC)

Subfader (talkcontribs)
  1. ifexist is expensive too ;)
Ftiercel (talkcontribs)

I have a solution for both.

  • First, you can make an AND on two expressions like this: {{#ifeq: {{#expr: {{#ifexist: {{FULLPAGENAME}}/Subpage | 1 | 0}} and {{#ifexpr: {{PAGESIZE:{{FULLPAGENAME}}/Subpage}} > 0 | 1 | 0 }}}} | 1 | {{/Subpage}} | Other text}}

It's pretty hard to read but it works.

  • Then, you can test if a page is empty with a string comparison: {{#ifeq: {{/Subpage}}a | a | Other text | {{/Subpage}}}}

Beware! It is not equal when the page doesn't exist!

Reply to "#ifexist and empty pages"