Difference between revisions of "User:Pixali/comictemplate/"

Explain xkcd: It's 'cause you're dumb.
Jump to: navigation, search
(rewrote the experimental template to -hopefully- fix the back buttons)
Line 1: Line 1:
<includeonly><!--
+
<!-- The old template with my changes is broken as hell. This is a rewritten version. -->
--><metadesc>Explain xkcd is a wiki dedicated to explaining the webcomic xkcd. Go figure.</metadesc><!--
+
<includeonly>
--><table class="{{{bodyclass|}}}" cellspacing="5"
+
  <metadesc>Explain xkcd is a wiki dedicated to explaining the webcomic xkcd. Go figure.</metadesc>
          style="background-color: #FFFFFF; border: 1px solid #AAAAAA; color: black; font-size: 88%; line-height: 1.5em;
+
 
                margin: 0.5em 0 0.5em 1em; padding: 0.2em; text-align: center; width:98%; {{{bodystyle|}}}"><!--
+
  <!-- Create the 'box' around the comic template -->
 
+
  <table class="{{{bodyclass|}}}" cellspacing="5"
  ### Navigation bar (previous, next...) ###
+
    style="background-color: #FFFFFF; border: 1px solid #AAAAAA; color: black; font-size: 88%; line-height: 1.5em;
 
+
      margin: 0.5em 0 0.5em 1em; padding: 0.2em; text-align: center; width:98%; {{{bodystyle|}}}">
   --><tr><td><!--
+
    
 
+
     <!-- This table will contain a table row (tr) and cell (td) -->
     ### Generate the |< button ###
+
    <tr><td>
### Special case modification: the ifeq has been replaced with switch to make undefined numbers work and make the navigation bar go *poof* when this happens ###
 
    --><ul style="text-align: center; margin-bottom: 10px;" class="no-link-underline"><!--
 
    -->{{#switch: {{{number|-1}}} | 1=&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|<!--
 
-->-1=&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|<!--
 
    --><li style="background-color: #6E7B91;
 
                      border: 1.5px solid #333333; border-radius: 3px 3px 3px 3px; box-shadow: 0 0 5px 0 gray;
 
                      display: inline; font-size: 16px; font-variant: small-caps; font-weight: 600;
 
                      margin: 0 4px; padding: 1.5px 0;"><!--
 
          -->[[1|<span style="color: #FFFFFF; padding: 0 12px;">&#124;&lt;</span>]]<!--
 
        --></li> <!--
 
      ### Create the prev button ###
 
 
 
    --><li style="background-color: #6E7B91;
 
                    border: 1.5px solid #333333; border-radius: 3px 3px 3px 3px; box-shadow: 0 0 5px 0 gray;
 
                    display: inline; font-size: 16px; font-variant: small-caps; font-weight: 600;
 
                    margin: 0 4px; padding: 1.5px 0;"><!--
 
        -->[[{{#expr:{{{number}}} - 1}}|<span style="color: #FFFFFF; padding: 0 12px;">&lt;&nbsp;Prev</span>]]<!--
 
      --></li>}} <!--
 
 
 
      ### Create a centre button with comic number, date (if exists) and link ###
 
 
 
      --><li style="background-color: #6E7B91;
 
                    border: 1.5px solid #333333; border-radius: 3px 3px 3px 3px; box-shadow: 0 0 5px 0 gray;
 
                    display: inline; font-size: 16px; font-variant: small-caps; font-weight: 600;
 
                    margin: 0 4px; padding: 1.5px 0;"
 
            class="plainlinks"><!--
 
### Special case modification; if number is undefined ldomain and lappend must be defined to redirect comic link to elsewhere on xkcd.com ###
 
        -->[{{#ifeq:{{{number|-1}}}|-1|http://{{{ldomain}}}.xkcd.com/{{{lappend}}}/|http://www.xkcd.com/{{{number}}}/}} <!--
 
        --><span style="color: #FFFFFF; padding: 0 12px;">Comic&nbsp;{{#ifeq:{{{number|-1}}}|-1||&#35;}}{{{number|}}}&nbsp;{{#if:{{{date|}}}|({{{date}}})}}</span>]<!--
 
      --></li> <!--
 
 
 
      ### Generate the "next" button, and have it point to the next comic, unless the current number matches LATESTCOMIC ###
 
### Special case modification; if number is left undefined it will default to -1 which results in an invalid comic number which then disables the next button. ###
 
      -->{{#ifexist:{{#expr:{{{number|-1}}} + 1}}<!--
 
      -->|<li style="background-color: #6E7B91;
 
                      border: 1.5px solid #333333; border-radius: 3px 3px 3px 3px; box-shadow: 0 0 5px 0 gray;
 
                      display: inline; font-size: 16px; font-variant: small-caps; font-weight: 600;
 
                      margin: 0 4px; padding: 1.5px 0;"><!--
 
          -->[[{{#expr:{{{number}}} + 1}}|<span style="color: #FFFFFF; padding: 0 12px;">Next&nbsp;&gt;</span>]]<!--
 
        --></li> <!--
 
 
        
 
        
 
+
      <!-- Now make an unordered list which will display as the navigation bar -->
### Generate a button that points to the page specified by LATESTCOMIC: the latest comic. ###
+
      <ul style="text-align: center; margin-bottom: 10px;" class="no-link-underline">
      --><li style="background-color: #6E7B91;
+
       
                      border: 1.5px solid #333333; border-radius: 3px 3px 3px 3px; box-shadow: 0 0 5px 0 gray;
+
        <!-- Generate the |< and prev buttons, but only if {{{number}}} exists and is greater than 1 -->
                      display: inline; font-size: 16px; font-variant: small-caps; font-weight: 600;
+
        {{#ifexpr: {{{number|-1}}} > 1
                      margin: 0 4px; padding: 1.5px 0;"><!--
+
         
          -->[[{{LATESTCOMIC}}|<span style="color: #FFFFFF; padding: 0 12px;">&gt;&#124;</span>]]<!--
+
          <!-- {{{number}}} is greater than 1; make a list item and put a button in it that links to #1 -->
        --></li><!--
+
          | <li style="background-color: #6E7B91;
      -->}}<!--
+
              border: 1.5px solid #333333; border-radius: 3px 3px 3px 3px; box-shadow: 0 0 5px 0 gray;
### Undefined numbers should also make this work now. ###
+
              display: inline; font-size: 16px; font-variant: small-caps; font-weight: 600;
      -->{{#ifexist:{{#expr:{{{number|-1}}} + 1}}||&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}}<!--
+
              margin: 0 4px; padding: 1.5px 0;">
    --></ul><!--
+
            <!-- link to #1 -->
  --></td></tr><!--
+
            [[1|<span style="color: #FFFFFF; padding: 0 12px;">&#124;&lt;</span>]]
 
+
            </li>
 
+
           
 
+
            <!-- We're not done here yet, make the back button next -->
  ### Comic title ###
+
            <li style="background-color: #6E7B91;
 
+
              border: 1.5px solid #333333; border-radius: 3px 3px 3px 3px; box-shadow: 0 0 5px 0 gray;
  -->{{#if:{{{title|}}}|<tr><td style="font-size: 20px; padding-bottom:10px"><!--
+
              display: inline; font-size: 16px; font-variant: small-caps; font-weight: 600;
    -->'''{{{title}}}'''<!--
+
              margin: 0 4px; padding: 1.5px 0;">
  --></td></tr>}}<!--
+
              <!-- link to previous comic -->
 
+
              [[{{#expr:{{{number}}} - 1}}|<span style="color: #FFFFFF; padding: 0 12px;">&lt;&nbsp;Prev</span>]]
  ### Text before comic ###
+
            </li>
 
+
          <!-- {{{number}}} doesn't exist or is less than 1; just put non-breaking spaces here -->
  -->{{#if:{{{before|}}}|<tr><td style="padding-bottom:10px"><!--
+
          | &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    -->{{{before}}}<!--
+
        }}
  --></td></tr>}}<!--
+
        <!-- Regardless of {{{number}}}, we need to make the comic date, link etc. -->
 
+
        <li style="background-color: #6E7B91;
  ### Comic image and title text ###
+
          border: 1.5px solid #333333; border-radius: 3px 3px 3px 3px; box-shadow: 0 0 5px 0 gray;
 
+
          display: inline; font-size: 16px; font-variant: small-caps; font-weight: 600;
  --><tr><td><!--
+
          margin: 0 4px; padding: 1.5px 0;"
  -->{{#if: {{{custom|}}} |<!--
+
            class="plainlinks">
    -->{{{custom|}}}|<!--
+
         
    -->{{#if:{{{image|}}}|[[File:{{{image|}}}|{{{imagesize|}}}|{{{titletext|}}}]]}}}}<!--
+
          <!-- [ and ] makes an external link, vs. [[ and ]] which are internal only. -->
  -->{{#if:{{{imagesize|}}}|<br />[Click comic to enlarge]}}<!--
+
          <!-- Depending whether {{{number}}} exists or not, toggle between using wide link mode or number link mode. -->
  -->{{#if:{{{titletext|}}}|<br /><span style="{{{captionstyle|}}}"><span style="color:grey">Title text:</span> {{{titletext}}}</span>}}<!--
+
          <!-- Wide link mode requires {{{lappend}}} to be set, while {{{ldomain}}} can default to www -->
  --></td></tr><!--
+
          [{{#ifexpr: {{{number|-1}}} >= 1
--></table><!--
+
            <!-- Comic number is probably valid, use number link mode -->
 
+
            | http://www.xkcd.com/{{{number}}}/
  ### Add categories to comic based on date field ###
+
            <!-- Comic number is invalid or doesn't exist, use wide link mode -->
 
+
            | http://{{{ldomain|www}}}.xkcd.com/{{{lappend}}}/
-->{{DEFAULTSORT:&nbsp;{{padleft:{{{number}}}|4}}}}<!-- (default sorting key for all categories: use zero-padding to make sure #9 comes before #10, etc.)
+
          }}
-->{{#ifeq:{{NAMESPACE}}|{{ns:0}}|<!-- (no categorization except for the main namespace)
+
          <!-- Generate the title, with date if it exists -->
  -->{{#ifeq:{{FULLPAGENAME}}|{{int:mainpage}}||<!-- (no categorization when transcluded into the main page)
+
          <span style="color: #FFFFFF; padding: 0 12px;">Comic&nbsp;
    -->[[Category:Comics]]<!--
+
          {{#ifexpr: {{{number|-1}}} >= 1 ||&#35;}}{{{number|}}}&nbsp;{{#if:{{{date|}}}|({{{date}}})}}</span>]
    -->{{#if:{{{date|}}}|<!--
+
        </li>
      -->[[Category:Comics from {{#time:Y|{{{date}}}}}]]<!-- (categorize by year)
+
        <!-- Now make the next and >| buttons provided comic number exists -->
      -->[[Category:Comics from {{#time:F|{{{date}}}}}]]<!-- (categorize by month)
+
        {{#ifexist: {{#expr: {{{number|-1}}} + 1}}
      -->[[Category:{{#time:l|{{{date}}}}} comics]]<!-- (categorize by weekday)
+
          <!-- Comic number is valid, generate the buttons -->
    -->}}<!--
+
          | <li style="background-color: #6E7B91;
  -->}}<!--
+
              border: 1.5px solid #333333; border-radius: 3px 3px 3px 3px; box-shadow: 0 0 5px 0 gray;
-->|}}<!--
+
              display: inline; font-size: 16px; font-variant: small-caps; font-weight: 600;
 
+
              margin: 0 4px; padding: 1.5px 0;">
  ### DOCUMENTATION ###
+
              [[{{#expr:{{{number}}} + 1}}|<span style="color: #FFFFFF; padding: 0 12px;">Next&nbsp;&gt;</span>]]
 
+
            </li>
--></includeonly><noinclude>
+
            <!-- Make a button that points to LATESTCOMIC (which is of course the latest comic) -->
This is the basic infobox-style header template used to display [[xkcd]] comics on their own pages, including the comic number (with external link to xkcd), publication date, title, comic image, and title text. This is an upgraded version that has support for undefined numbers; allowing use with comics that are not present in the main series (for example, [[Radiation]]).
+
            <li style="background-color: #6E7B91;
 +
              border: 1.5px solid #333333; border-radius: 3px 3px 3px 3px; box-shadow: 0 0 5px 0 gray;
 +
              display: inline; font-size: 16px; font-variant: small-caps; font-weight: 600;
 +
              margin: 0 4px; padding: 1.5px 0;">
 +
              [[{{LATESTCOMIC}}|<span style="color: #FFFFFF; padding: 0 12px;">&gt;&#124;</span>]]
 +
            </li>
 +
          <!-- Comic number (plus one) is not valid, don't show the buttons -->
 +
          | &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 +
        }}
 +
      </ul>
 +
    </td></tr>
 +
   
 +
    <!-- Now that the nav bar has been generated, display the rest of the filled-out comic template -->
 +
   
 +
    <!-- Comic title in =BOLD= -->
 +
    {{#if:{{{title|}}}|<tr><td style="font-size: 20px; padding-bottom:10px">
 +
      '''{{{title}}}'''
 +
    </td></tr>}}
 +
   
 +
    <!-- Display the (optional) text just before the comic -->
 +
    {{#if:{{{before|}}}|<tr><td style="padding-bottom:10px">
 +
      {{{before}}}
 +
    </td></tr>}}
 +
   
 +
    <!-- Almost done; just need to display the comic, title text and a bit more -->
 +
    <tr><td>
 +
      <!-- {{{custom}}} will replace the image with whatever it contains if it exists -->
 +
      {{#if: {{{custom|}}}
 +
      | {{{custom|}}}
 +
      <!-- Not going to replace the image, so let's draw that if it exists -->
 +
      | {{#if:{{{image|}}}
 +
        | [[File:{{{image|}}} | {{{imagesize|}}} | {{{titletext|}}}]]
 +
        }}
 +
      }}
 +
      <!-- {{{imagesize}}} will allow the comic to be shrinked if it's especially large -->
 +
      {{#if:{{{imagesize|}}}|<br />[Click comic to enlarge]}}
 +
      <!-- Final bit; if the comic has text on mouse-over, add that in a small print underneath the comic -->
 +
      {{#if:{{{titletext|}}}|<br /><span style="{{{captionstyle|}}}"><span style="color:grey">Title text:</span> {{{titletext}}}</span>}}
 +
    </td></tr>
 +
  </table>
 +
 
 +
  <!-- Categorisation for people who like that kind of thing -->
 +
 
 +
  <!-- Sort this page in categories by number. The padding ensures that #9 comes before #10 -->
 +
  <!-- It otherwise sorts 'alphanumerically'; as in since the first char of 10 is 1, it would normally be placed before 9 -->
 +
  <!-- The padding turns each into 0009 and 0010 etc. and since 0 is less than 1, #9 gets sorted before #10. -->
 +
  {{#ifexpr: {{{number|-1}}} >= 1
 +
  | {{DEFAULTSORT:&nbsp;{{padleft:{{{number}}}|4}}}}
 +
  | <!-- Nothing -->
 +
  }}
 +
 
 +
  <!-- Only categorise if in the main namespace -->
 +
  {{#ifeq:{{NAMESPACE}}|{{ns:0}}
 +
    <!-- Don't try to categorise the main page -->
 +
  | {{#ifeq:{{FULLPAGENAME}}|{{int:mainpage}}
 +
      <!-- Alright, start putting it in the appropriate date categories-->
 +
    || [[Category:Comics]]
 +
      {{#if:{{{date|}}}
 +
      | [[Category:Comics from {{#time:Y|{{{date}}}}}]] <!-- Years    -->
 +
        [[Category:Comics from {{#time:F|{{{date}}}}}]] <!-- Months  -->
 +
        [[Category:{{#time:l|{{{date}}}}} comics]]      <!-- Weekdays -->
 +
      }}
 +
    }}
 +
  |}}
 +
</includeonly><noinclude>
 +
<!-- and now for the documentation. -->
 +
This is the basic infobox-style header template used to display [[xkcd]] comics on their own pages, including the comic number (with external link to xkcd), publication date, title, comic image, and title text.
 +
This is an upgraded version that has support for undefined/invalid numbers; allowing use with comics that are not present in the main series (for example, [[Radiation]]).
  
 
== Sample ==
 
== Sample ==
Line 117: Line 144:
  
 
<pre>{{comic
 
<pre>{{comic
| number    =  
+
| number    =
| date      =  
+
| date      =
| title    =  
+
| title    =
 
| before    =
 
| before    =
| image    =  
+
| image    =
| custom    =  
+
| custom    =
| imagesize =  
+
| imagesize =
| titletext =  
+
| titletext =
| ldomain  =  
+
| ldomain  =
| link      =  
+
| lappend  =
 
}}</pre>
 
}}</pre>
  
Line 133: Line 160:
 
* At least the number, title and image are required.
 
* At least the number, title and image are required.
 
* The date should be written in the form: January 1, 2006
 
* The date should be written in the form: January 1, 2006
* The imagesize field is optional.  
+
* The imagesize field is optional.
 
** The comic's '''width''' will be limited to the set size. Format must be in pixels (eg: "350px")
 
** The comic's '''width''' will be limited to the set size. Format must be in pixels (eg: "350px")
 
** The comic's '''height''' may be set by adding an 'x' to the start (eg: "x350px")
 
** The comic's '''height''' may be set by adding an 'x' to the start (eg: "x350px")
** Warning: If the size is larger than the image, the image will be stretched.  
+
** Warning: If the size is larger than the image, the image will be stretched.
 
* '''before''' is a special field for inserting text before the comic. One use is for extremely large comics (e.g. [[Umwelt]]), to skip to the explanation.
 
* '''before''' is a special field for inserting text before the comic. One use is for extremely large comics (e.g. [[Umwelt]]), to skip to the explanation.
 
* If the '''custom''' field is not empty, the image field will be ignored and be replaced with any text that you put in the '''custom''' field.
 
* If the '''custom''' field is not empty, the image field will be ignored and be replaced with any text that you put in the '''custom''' field.
* if '''number''' is left undefined, most of the navigation bar will be disabled and '''ldomain''' along with '''link''' must be defined to keep the link to xkcd.com valid.
+
* if '''number''' is left undefined, most of the navigation bar will be disabled.
 +
** '''lappend''' must be defined as <pre>...kd.com/'''lappend'''/</pre> to keep the link to xkcd.com valid.
 +
** If the link is to eg. a blog post (blog.xkcd.com) '''ldomain''' can be defined as <pre>blog</pre> to change the subdomain in the link.
  
 
The example in [[User_talk:Pixali/comictemplate/|the talk page]] is produced by the following code:
 
The example in [[User_talk:Pixali/comictemplate/|the talk page]] is produced by the following code:
Line 146: Line 175:
 
| date      = October 4, 2005
 
| date      = October 4, 2005
 
| title    = Example with different link
 
| title    = Example with different link
| image    = monty_python.jpg
+
| image    = schrodinger.jpg
 
| titletext = I went to a dinner where there was a full 10 minutes of Holy Grail quotes exchanged, with no context, in lieu of conversation.  It depressed me badly.
 
| titletext = I went to a dinner where there was a full 10 minutes of Holy Grail quotes exchanged, with no context, in lieu of conversation.  It depressed me badly.
 
| ldomain  = www
 
| ldomain  = www
| link      = radiation
+
| lappend  = radiation
 
}}</pre>
 
}}</pre>
 
</noinclude>
 
</noinclude>

Revision as of 04:03, 6 March 2015


This is the basic infobox-style header template used to display xkcd comics on their own pages, including the comic number (with external link to xkcd), publication date, title, comic image, and title text. This is an upgraded version that has support for undefined/invalid numbers; allowing use with comics that are not present in the main series (for example, Radiation).

Sample

The following is a sample usage of this template: (see talk page)

Usage

{{comic
| number    =
| date      =
| title     =
| before    =
| image     =
| custom    =
| imagesize =
| titletext =
| ldomain   =
| lappend   =
}}

Notes

  • At least the number, title and image are required.
  • The date should be written in the form: January 1, 2006
  • The imagesize field is optional.
    • The comic's width will be limited to the set size. Format must be in pixels (eg: "350px")
    • The comic's height may be set by adding an 'x' to the start (eg: "x350px")
    • Warning: If the size is larger than the image, the image will be stretched.
  • before is a special field for inserting text before the comic. One use is for extremely large comics (e.g. Umwelt), to skip to the explanation.
  • If the custom field is not empty, the image field will be ignored and be replaced with any text that you put in the custom field.
  • if number is left undefined, most of the navigation bar will be disabled.
    • lappend must be defined as
      ...kd.com/'''lappend'''/
      to keep the link to xkcd.com valid.
    • If the link is to eg. a blog post (blog.xkcd.com) ldomain can be defined as
      blog
      to change the subdomain in the link.

The example in the talk page is produced by the following code:

{{User:Pixali/comictemplate/
| date      = October 4, 2005
| title     = Example with different link
| image     = schrodinger.jpg
| titletext = I went to a dinner where there was a full 10 minutes of Holy Grail quotes exchanged, with no context, in lieu of conversation.  It depressed me badly.
| ldomain   = www
| lappend   = radiation
}}