Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

User:Chao: Difference between revisions

17,076 editsJoined 5 November 2017
m (test gallery with three categories)
m (proposed optimization for time by abusing variables)
Line 2: Line 2:
   |{{#vardefine:cat3 | [[Category:{{{3}}}]] }}
   |{{#vardefine:cat3 | [[Category:{{{3}}}]] }}
   |{{#vardefine:cat3 | }}
   |{{#vardefine:cat3 | }}
}}{{#ifeq: 0 | {{#ask:
}}{{#ifeq: 0 | {{#var:{{{2}}} {{{3|}}}}}
    [[Category:{{{1}}}]]
    [[Category:{{{2}}}]]
    {{#var:cat3}}
    | format=count
  }}
  |<!-- do nothing if no images -->
  |<!-- do nothing if no images -->
  |{{#switch:{{{4}}}
  |{{#switch:{{{4}}}
Line 26: Line 21:


{{TOC}}
{{TOC}}
<!--
--------------------------------------
  category names
--------------------------------------
-->{{#vardefine:MAIN_CAT |Main Artwork
}}{{#vardefine:BATTLE_CAT|Battle
}}{{#vardefine:PALREF_CAT|Palette Reference
}}{{#vardefine:PORTRT_CAT|Portraits
}}{{#vardefine:CP_CAT    |Chrono Phantasma
}}{{#vardefine:STORY_CAT |Story}}<!--
-------------------------------------
  number of images in each intersection of categories


<syntaxhighlight>
* current variable naming convention:
<!-- MAIN ARTWORK -->
  {{#var:{{#var:MAIN_CAT}}}} = {{#var|Main Artwork}} = the number of
{{ User:Chao | {{{1}}} | Main Artwork | | h2 | Main Artwork }}
  pictures tagged Main Artwork that {{{1}}} has.


<!-- SPRITES -->
* These variables are used and named like this inside Template:Gallery Section
{{#ifeq: 0 | {{#expr:
  as well, so if the naming convention is changed here, they should also be
  {{#ask:[[Category:Kagura Mutsuki]][[Category:Battle]]|format=count}} +
  changed inside Template:Gallery Section.
  {{#ask:[[Category:Kagura Mutsuki]][[Category:Palette Reference]]|format=count}} +
-------------------------------------
  {{#ask:[[Category:Kagura Mutsuki]][[Category:Portraits]]|format=count}}
-->{{#vardefine:{{#var:MAIN_CAT}}
  }}
  |{{#ask:[[Category:{{{1}}}]]
  | <!-- all three subcategories are empty, don't make a section header-->
          [[Category:{{#var:MAIN_CAT}}]]
  | <h2> Sprites </h2>
      |format=count}}
    {{ User:Chao | Kagura Mutsuki | Battle | | h3 | Battle }}
}}{{#vardefine:{{#var:BATTLE_CAT}}
    {{ User:Chao | Kagura Mutsuki | Palette Reference | | h3 | Palette Reference }}
  |{{#ask:[[Category:{{{1}}}]]
    {{ User:Chao | Kagura Mutsuki | Portraits | | h3 | Portraits }}
          [[Category:{{#var:BATTLE_CAT}}]]
      |format=count}}
}}{{#vardefine:{{#var:PALREF_CAT}}
  |{{#ask:[[Category:{{{1}}}]]
          [[Category:{{#var:PALREF_CAT}}]]
      |format=count}}
}}{{#vardefine:{{#var:PORTRT_CAT}}
  |{{#ask:[[Category:{{{1}}}]]
          [[Category:{{#var:PORTRT_CAT}}]]
      |format=count}}
}}{{#vardefine:{{#var:CP_CAT}} {{#var:STORY_CAT}}
  |{{#ask:[[Category:{{{1}}}]]
          [[Category:{{#var:CP_CAT}}]]
          [[Category:{{#var:STORY_CAT}}]]
      |format=count}}
}}
}}
Works for multiple categories (here, "Kagura Mutsuki", "Story", and (the optional) "Chrono Phantasma")
{{ User:Chao | Kagura Mutsuki | Story | Chrono Phantasma | h2 | Chrono Phantasma }}
</syntaxhighlight>
<!-- MAIN ARTWORK -->
<!-- MAIN ARTWORK -->
{{ User:Chao | {{{1}}} | Main Artwork | | h2 | Main Artwork }}
{{ User:Chao | {{{1}}} | {{#var:MAIN_CAT}} | | h2 | Main Artwork }}


<!-- SPRITES -->
<!-- SPRITES -->
{{#ifeq: 0 | {{#expr:
{{#ifeq: 0
  {{#ask:[[Category:Kagura Mutsuki]][[Category:Battle]]|format=count}} +
  | {{#expr: {{#var:{{#var:BATTLE_CAT}}}} + {{#var:{{#var:PALREF_CAT}}}} + {{#var:{{#var:PORTRT_CAT}}}} }}
  {{#ask:[[Category:Kagura Mutsuki]][[Category:Palette Reference]]|format=count}} +  
  {{#ask:[[Category:Kagura Mutsuki]][[Category:Portraits]]|format=count}}
  }}
   | <!-- all three subcategories are empty, don't make a section header-->
   | <!-- all three subcategories are empty, don't make a section header-->
   | <h2> Sprites </h2>  
   | <h2> Sprites </h2>  
     {{ User:Chao | Kagura Mutsuki | Battle | | h3 | Battle }}
     {{ User:Chao | Kagura Mutsuki | {{#var:BATTLE_CAT}} | | h3 | Battle }}
     {{ User:Chao | Kagura Mutsuki | Palette Reference | | h3 | Palette Reference }}
     {{ User:Chao | Kagura Mutsuki | {{#var:PALREF_CAT}} | | h3 | Palette Reference }}
     {{ User:Chao | Kagura Mutsuki | Portraits | | h3 | Portraits }}
     {{ User:Chao | Kagura Mutsuki | {{#var:PORTRT_CAT}} | | h3 | Portraits }}
}}
}}


{{ User:Chao | Kagura Mutsuki | Story | Chrono Phantasma | h2 | Chrono Phantasma }}
{{ User:Chao | Kagura Mutsuki | {{#var:CP_CAT}} | {{#var:STORY_CAT}} | h2 | Chrono Phantasma }}





Revision as of 17:25, 9 November 2017


Main Artwork

... further results

Sprites

Battle

Palette Reference

Portraits

Chrono Phantasma


Technical Notes

Template: Gallery

Creates a gallery from template for the specified character. It will skip sections and subsections that the character does not have images for.

Template Usage

   {{ Gallery | {{PAGENAME}} }}   <-- with the idea that {{PAGENAME}} will evaluate to ie. Kagura Mutsuki
OR {{ Gallery | Kagura Mutsuki }} <-- this will also work

Template Code

<!-- MAIN ARTWORK -->
{{ Gallery Section | {{{1}}} | Main Artwork | | h2 | Main Artwork }}

<!-- SPRITES -->
{{#ifeq: 0 | {{#var:Battle}} + {{#var:Palette Reference}} + {{#var:Third Category}}
  | <!-- all three subcategories are empty, don't make a section header-->
  | <h2> Sprites </h2> 
    {{ Gallery Section | {{{1}}} | Battle | | h2 | Battle }}
    {{ Gallery Section | {{{1}}} | Palette Reference | | h3 | Palette Reference }}
    {{ Gallery Section | {{{1}}} | Portraits | | h2 | Portraits }}
}}

...

<!-- and so on with other categories and sub-categories -->

Template: Gallery Section

Creates a section header with the specified depth (h2, h3, h4, h5), and a gallery of all images that contain the two specified tags. If there are no images in the specified gallery, this code will not do anything. (That is, it is safe to call even when "Kagura Mutsuki" does not have images in "XBlaze" -- an extraneous "XBlaze" header will not appear on Kagura's gallery page.)

Template Usage

{{ Gallery Section
  | Kagura Mutsuki  <-- {{{1}}} Character name (Image category 1)
  | Main Artwork    <-- {{{2}}} Image Category 2
  |                 <-- {{{3}}} Optional Image Category 3
  | h2              <-- {{{4}}} Header depth (h2, h3, h4, h5)
  | Main Artwork    <-- {{{5}}} Section header. 
}}

ie. {{ Gallery Section | Kagura Mutsuki | Main Artwork | | h2 | Main Artwork }}

Template Code

{{#vardefine: {{{2}}} {{{3}}} |
  {{#ask:
    [[Category: {{{1}}} ]]
    [[Category: {{{2}}} ]]
    {{#if:{{{3|}}}
      | [[Category: {{{3}}} ]] | }}
    | format=count
  }}
}}{{#ifeq: 0 | {{#var: {{{2}}} {{{3}}} }} | <!-- do nothing if no images --> |
  {{#switch:{{{4}}}
    |h2=<h2>{{{5}}}</h2>
    |h3=<h3>{{{5}}}</h3>
  }}
  {{#ask:
    [[Category:{{{1}}}]]
    [[Category:{{{2}}}]]
    {{#if:{{{3|}}}
      | [[Category: {{{3}}} ]] | }}
    |?caption
    |format=gallery
    |autocaptions=no
    |captionproperty=?caption
    |perrow=7
    |overlay=yes
  }}
}}



Useful References

Modules

Semantic MediaWiki

DPL

Other things to look into later:

Note: I believe it"s good wikimedia practice to use only ==H2== and beyond (in essence, to avoid using =H1=)