Difference between revisions of "Issue:Conditional clause in output?"

From FollowTheScore
Jump to: navigation, search
m (Status = answered)
 
(3 intermediate revisions by the same user not shown)
Line 4: Line 4:
 
  |Version    = 1.8.6
 
  |Version    = 1.8.6
 
  |Description =  
 
  |Description =  
  |Status      = open
+
  |Status      = answered
 
}}
 
}}
  
Line 124: Line 124:
  
 
[[User:Gero|Gero]] 22:00, 5 July 2009 (UTC)
 
[[User:Gero|Gero]] 22:00, 5 July 2009 (UTC)
 +
:I dunno exactly what to add. I tried like this
 +
<pre>
 +
function substTagParm($tag, $pagename, $article, $imageUrl, $nr, $titleMaxLength) {
 +
global $wgLang;
 +
if (strchr($tag,'%')<0) return $tag;
 +
        $sTag = '%PAGES%';
 +
        ...
 +
</pre>
 +
:But don't mind, if the way I've set it up is ok, I don't mind the little extra template check. --[[User:Subfader|Subfader]] 22:43, 5 July 2009 (UTC)

Latest revision as of 23:45, 5 July 2009

Description:
Extension / Version: DPL   /   1.8.6
Type / Status: Change Request   /   answered

Problem

Hi, I want to use an conditional clause in the output. The output should be different if there is no result, one result or multiple results. Example:

This calls images in Category:Test Images. It can later be used on category pages using category = PAGENAME. E.g. I Have disabled the Media section on Category pages cos the navigation sucks.
Atm it returns a gallery where the image links to its desc page and a list of links to the pages that use that image.

  • Cookie.jpg is only used on one article only.
  • Bob Ross.gif is used two articles.
  • Placeholder.png is not used on any page.
There are 4 images in Category:Test Images.


How it works:

{{#dpl:
|category=Test Images
|namespace=Image
|ordermethod=firstedit
|order=descending
|count=10
|resultsheader=There are %TOTALPAGES% images in this category.
|format=«gallery»\n,\n%PAGE%¦²{User:Subfader/Examples/Images used/Template¦%PAGE%}²,,\n«/gallery»
}}

The template to generate the article links =

{{#dpl:
|debug=0
|namespace=
|imageused={{{1}}}
|count=2
|format=,[[%PAGE%]]<br>,,
}}


Now the plan is:

  • If the image is only used on page: Gallery text = Link to the page that uses the image (standard case for my usage)
  • If the image is used on more than one page: Gallery text = [[:File:%PAGE%#filelinks|X pages link to this image]] (if counting the page links is expensive then "Multiple" is ok too)
  • If the image is unused: Gallery text = "This image is unused."


Reply

Found a solution myself :)

There are 4 images in this category.

It uses another template to return the number of pagelinks. So now it works like this:

Images used:

{{#dpl:
|category=Test Images
|namespace=Image
|ordermethod=firstedit
|order=descending
|count=10
|resultsheader=There are %TOTALPAGES% images in this category.
|format=«gallery»\n,\n%PAGE%¦²{#ifexpr:²{User:Subfader/Examples/Images used/Template/Res¦%PAGE%}² < 1
¦(This image is not used on articles.)
¦²{#ifexpr:²{User:Subfader/Examples/Images used/Template/Res¦%PAGE%}² = 1
¦²{User:Subfader/Examples/Images used/Template¦%PAGE%}²
¦([[:%PAGE%#filelinks|²{User:Subfader/Examples/Images used/Template/Res¦%PAGE%}² pages use this image.]])
}²}²,,\n«/gallery»
}}

which uses Images used/Template:

{{#dpl:
|debug=0
|namespace=
|imageused={{{1}}}
|count=2
|format=,[[%PAGE%]]<br>,,
}}

which uses Images_used/Template/Res:

{{#dpl:
|debug=0
|namespace=
|imageused={{{1}}}
|noresultsheader=0
|resultsheader=%TOTALPAGES%
|format=,,,
}}

Could you check if this correct? Maybe there's an easier way with including only one template.
Feel free to close this bug and add this as new example :)

Reply

I understand that in yopur case the output formatting shall depend on the amount of results found. This is not covered by the "oneresultheader etc ..". So, I think, your solution is a good way to do it.

Under performance aspects one would wish to use %PAGES% within an #ifexpr in the format statement. But at the moment the %PAGES% and the %TOTALPAGES% variables are only available within header and footer. The reason is that in some rare cases a regular expression could reduce the number of result lines delivered by the SQL statement. But in most cases %PAGES% is internally known before the formatting process is started.

So one could try to make an improvement here. If you know how to make small modifications to the php source in DPLMain.php you could change this (look near line 2600 and see function "substTagParm in DPL.php near line 175 ) If we offered %PAGES% within the format statemenmt the subquery would not be needed I think ...

Do you want to try and let me know?

Gero 22:00, 5 July 2009 (UTC)

I dunno exactly what to add. I tried like this
	function substTagParm($tag, $pagename, $article, $imageUrl, $nr, $titleMaxLength) {
		global $wgLang;
		if (strchr($tag,'%')<0) return $tag;
	        $sTag = '%PAGES%';
	        ...
But don't mind, if the way I've set it up is ok, I don't mind the little extra template check. --Subfader 22:43, 5 July 2009 (UTC)