User:Addyrielle/Helpful notes

This page has some helpful notes for my own use =).


 * C o  l  o  u  r  c  h  a  r  t  !

{{User:Addyrielle/Template:Showhide_notes|title= General Notes (Click "Show" to view) |content=

General Notes
Links to another section on the same page.

Page name Links to a section of a page. Matches must be exact in spelling, case, and punctuation. If you link to a non-existent section, it will just take you to the top of the page.

Redirecting - put this on the first line of the article.


 * 1) REDIRECT Page name you want to redirect to
 * 2) REDIRECT Page name

-

Images

Float right:



OR



Resize:



underline strike through

To comment on a page for future editors

--

Variables

Code                                                     Effect

33

4

August 				08

August 				August

August

27 					13

Tuesday 				Thursday

2024 				2009

14:00

15,770

342,569

How to edit a page

760062

/wiki/Pagename

v 	http://en.wikipedia.org/wiki/Sandbox?action=edit

http://meta.wikimedia.org/wiki/Pagename

http://meta.wikimedia.org/w/index.php?title=Pagename&query_string

http://meta.wikimedia.org

--

Lists


 * 1) One
 * 2) Two
 * 3) Two point one
 * 4) Three

*One *Two **Two point one *Three

}}

{{User:Addyrielle/Template:Showhide_notes|title= From Wikipedia's Help:Template (Click "Show" to view) |content=

From Wikipedia's Help:Template (Using and Constructing Templates in Mediawiki)
Template


 * A page created explicitly for transclusion - the MediaWiki process of including the contents of 1 page within another page.


 * Any page can be transcluded, but templates are designed specifically for that purpose, usually for repetitive material that might need to show up on lots of different pages. Commonly used for boilerplate messages, standard warnings/notices, infoboxes, etc.
 * Templates may contain plain text, wikitext, HTML &/or CSS, or even other templates, & they have some limited programming capacities: customizable values (called parameters), calculation & branchings (using parser functions), & access to wiki-specific variables (magic words), like dates, times, & page names.


 * Template names are just like other page names: case sensitive for the first letter, with spaces indistinguishable from underscores. The 1 exception is the use of number sign in links - #; in transclusion the number sign, & any characters that follow it, are ignored (rather than taking you to a section).

This consists of the template name & various parameters that are passed to the template, where each parameter is separated by a vertical bar (or pipe), & the entirety is surrounded by doubled "". Not all templates have parameters, and not all templates that have parameters need to have values provided, so sometimes is sufficient to use a template. If a parameter is needed, but a value not provided by the user, the template may render with something like in the text, where the '...' might be a number or parameter name. This is to inform you that a named or unnamed parameter is missing, & can be avoided by using default values for the parameter.
 * To transclude a template into another page, use the following syntax (called a template tag):


 * Parameters come in two basic forms:


 * unnamed parameters: values that are put into the template in the order they appear:


 * named parameters: values associated with a particular named key in the template:


 * These may be mixed:


 * By convention named parameters are listed last, though that's not a requirement.


 * Whitespace characters (spaces, tabs, returns) are stripped from the beginnings & ends of named parameter values (unnamed parameters are unaffected), but not from the middle.


 * Examples can be seen here.

--

Substitution

Generally, templates are processed into readable text when you browse a page. This is the normal intention of a template: since the template is reevaluated each time it's used, changes to the template can propagate across many pages quickly & effortlessly. Occasionally, however, this is not appropriate. Eg, a user may want a template which returns a date or time that remains fixed, rather than changing each time the page is browsed. For those cases there is substitution, which is done by adding subst: before the template name in the template tag. substitution does exactly what its name suggests: rather than processing the template each time the page is browsed, substitution processes the template at the time the edit is saved, & replaces the template tag with the processed results.

In general, substitution processes one level, so if the template in question contains other template tags, those template tags will be substituted in, rather than the processed results of those tags. This is a sometimes useful trick when debugging complex templates.

-

Other Usage Information


 * To quote a template, creating a link to the template rather than actually invoking the template, use the " undefined " template (the template link template). For example, using the text " tc " creates a link to Template:Tc without actually doing what the template normally does.


 * Templates may seem small compared to other pages on Wikimedia, but editing them can consume a tremendously disproportionate amount of system resources, particularly when they are transcluded onto large numbers of pages. When a change is made to a template, the MediaWiki software automatically places every page in which the template is transcluded onto the job queue to update the template links and ensure that any new page views will reflect the change. For very popular templates, it is better to create a copy in user space, make & test any needed changes there, present it on the template talk page to make sure there are no objections, & then introduce it as a single edit.

}}

--

{{User:Addyrielle/Template:Showhide_notes|title= Creating & Editing Templates (Click "Show" to view) |content=

Creating & Editing Templates
Anything that can be included on a normal page or article can be included on a template, including other templates (though as a practical matter templates will often have relatively small contents). Beyond that, templates have access to programming features - parameters, parser functions, & magic words - which allow for context dependent use,[2] & special tags that help control which info is transcluded & which isn't.

When creating templates, it's best to follow a few simple principles:


 * Choose a short, descriptive name. Some people suggest that template names be completely small caps, some that spaces in template names should be avoided, but there's currently no hard guideline.


 * Make sure your template is properly documented and included in the correct categories. Categorizing your template and documenting it will make it easier for other editors to find & use.


 * To add documentation, put the template inside 'noinclude' tags on the template page. This will create a documentation subpage that you can edit


 * Categories that apply to the template itself should be added to the template page (inside 'noinclude' tags, with the template). Categories that are to be transcluded to the transclusion page should be placed on the template page inside 'includeonly' tags.


 * Try to make your template modular: i.e. capable of standing on its own & in a variety of different page contexts, without breaking, producing poor output, or messing up a page's layout. In general, you want your template to be transparently useful to other editors - the more effort they have to put into understanding how your template is used, the less they will be willing to use it.

Parser functions

Parser functions are the WikiMedia toolkit for simple branchings, calculations, text manipulations, etc. As a group, they take one or more parameters & return a wikitext value based on the parameters. There are 2 basic forms for Parser functions (distinguished by whether a pound sign follows the opening brackets):


 * Core parser functions, of the form . These functions are part of the core wikimedia software, & should be available in all projects.


 * Parser functions from the parserFunctions extension, of the form . These functions are part of the parserFunctions extension, and may not be available everywhere.

Parser functions: primarily used for the evaluation of parameters or magic words, in order to produce different results in different contexts.

Core parser functions generally deal with text manipulation and WikiMedia specific tasks.

The parserFunctions extension gives more more programming-oriented parser functions.

Parameters

Parameters are special codes that allow wikitext to be fed to a template; the template can be constructed to produce different outcomes depending on the values of the parameters it receives. Parameters may have names, or may be referenced by the position of values provided in the template tag (the order of the parameters in the template itself is irrelevant). Parameters in a template take the form, where the tripled curled-braces surround the name of a named parameter or the number of a positional parameter. Values entered for parameters can be quite long, and if needed the transclusion of an entire page may be used as the value for a parameter.

Eg: Assume there's a template called 'peoplepets' that produces some text about ppl & their pets. A template tag for this template might look like this:

1.

2.

The contents of the template itself, on the page Template:Peoplepets, looks like this:

and own a    named  who is  years old.

Thus, the two template tags above will transclude the following text, respectively:

1. John and Mary own a small dog named Fido who is 6 years old. 2. Bill and Susan own a fat cat named Queenie who is 7 years old.

Things to note:


 * Numbering of positional parameters skips over named parameters (eg: 'age' above)


 * The leading & trailing spaces around the values of named parameters in the template tags are stripped by the template.


 * This isn't true for unnamed parameters, which preserve trailing & leading whitespace. However, browsers render multiple whitespace characters as a single space, so the extra spaces around 'Fido', 'fat' & the other unnamed parameter values aren't immediately visible. This can be confusing if unnamed parameters are used for something other than display, such as links.


 * Order in which parameter values are used in the template doesn't matter.


 * Number of a positional parameter is treated as though it were a name: could have been written  . This is useful when positional parameters need to be entered out of order.


 * Values may be empty. Here the second positional parameter & the 'age' parameter have empty values:

Template tag:

Produces (note the missing words): John and own a small dog named Fido who is years old.


 * Values can remain unprovided. Here the 'kind' parameter has been omitted:

Template tag:

Produces (this displays the missing variable): John and Mary own a small named Fido who is 6 years old.

---

Parameter defaults

Default values can be specified for parameters using the vertical pipe character: |. The above example template could be rewritten as follows (in which 'friend' is the default value for positional parameter 2, the 4th positional parameter defaults to emptiness, & 'kind' of the pet defaults to 'dog'):

and own a    named  who is  years old.

A template tag like the following: will then produce the phrase Bill and friend own a dog named Queenie who is 7 years old.

-

Dummy Parameters & Tag Layout

Parameters that aren't used in the template are ignored if they are provided by the template tag. This was intended to prevent transclusions from breaking if a template is changed in a way that removes a parameter. This has an added benefit, however, of making some template tags more readable, through spacing, or by adding comments. Using :

Adding comments using template :

Results in:
 * a b c
 * d e f
 * g h i

(The "row number" bits don't show up). Dummy named parameters can be used in any template tag; just choose an unused parameter name & add it into the tag as 'unusedname = value'. One special case of a named dummy parameter is to use an empty string as the parameter name. This acts like a named parameter in that it isn't counted when assessing the unnamed parameter positions, but it doesn't risk accidentally conflicting with an actual named parameter.

Restrictions on parameters and parameter values


 * Unnamed parameters can't be assigned a value containing an equals sign (=); the parser will treat the equals sign as the assignment of a named parameter. There are several indirect means around this limitation:


 * In the template, write the value as the default of an undefined parameter: +, where the ellipsis can be number of an unused positional parameter, or can be a blank string (a null parameter).


 * In the article, assign the values to the template parameters with one of the following methods:


 * +, where the '1=' notation explicitly names the first unnamed parameter.


 * + Use the special template =, e.g.


 * + Use the HTML entity for an equals sign: &#x3d;. This is only useful for text representation; If the equals sign needs to be processed as an actual equals sign (as in another template) this approach won't work.


 * Parameter values cannot contain vertical pipe (|) characters; the parser will treat the pipe character as a separator rather than as text. Pipes are possible within wikilinks (country= USA ) or nested templates (e.g. volume= 30 acre.ft ). Indirect means around this limitation are as follows:
 * Use the special template |, which returns a valid pipe character. Use this method if you need something that'll be read as an actual pipe character
 * Use the HTML entity for a vertical pipe: &#124;. This is only useful for text representation; If the pipe needs to be processed as an actual pipe this approach won't work.


 * Parameter values can't contain unmatched sequential curled brackets. The parser will try to parse them as the beginning or ending of a template tag or parameter, and will throw errors. Parameters can, however, contain other parameters, magic words, or template tags (again, this can be circumvented using 'nowiki' tags or HTML entities).


 * Parameters don't get expanded when they are inside nowiki tags or XML-style extension tags. Thus, the following will not work within a template -  ... - because the parameter is not expanded.

Because template tags, parser functions, magic words, & parameters are all defined using curled braces, there are times when their combined use can be ambiguous. For example, the construction might be interpreted as:

1. (template tag whose name is specified by the named parameter NAMESPACE)

2. (parameter whose name is specified by the value of the magic word NAMESPACE).

In general, wherever the parser finds more than 3 opening braces in a row, it'll assume it is a parameter if the matching closing braces are 3-in-a-row, or as a template tag if only two of the matching closing braces are contiguous. In some cases it is advisable to add a space in the opening brackets to clarify the construction. For instance, the construction from above will always default to the first interpretation; it might be better to use  or  as required so that the intention of the code is clear to others.

Nesting templates

Templates may contain other templates - called 'nesting'. As the template is processed, the wikitext produced by any nested templates is transcluded into the nesting template, so that the final product is essentially processed from the most deeply nested template out. While fairly straight-forward in application, it involves some noteworthy quirks and tricks.

To pass a parameter value to a nested template, place a parameter tag as the value of one of the nested template's parameters.

Examples:


 * Template:A contains "the quick brown jumped over...". This takes the value passed to the third positional parameter of Template:A and passes it as the first positional parameter of Template:B, then returns the wikitext produced by B as part of the phrase.


 * Template:A contains "the quick brown jumped over...". As above, except the third positional parameter of Template:A is passed to the named parameter 'waldo' of Template:B.

Template parameters themselves can be chosen conditionally.


 * Example: Template:A contains "the quick brown jumped over...". Template:A passes the word 'fox' to a parameter of Template:B that's named in A's third positional parameter.

The Wikimedia software will allow a template to call itself, but will stop after one iteration to prevent an infinite loop.

When a nested template contains unmatched curled-brackets - as in - the unmatched brackets are treated as text during processing, & don't affect the parsing of brackets in the nesting template. If the nested template is substituted, however, the substitution is processed first, and this will change how braces are parsed in the nesting template. This has little practical use, but can occasionally introduce unexpected errors.

--

Noinclude, Includeonly, & Onlyinclude

 * Several tags are available to control what does & doesn't get transcluded.[3] The three tags are noinclude, includeonly, and onlyinclude (e.g. affected wikitext ).


 * Perhaps the most common issue with the use of these blocks is unwanted spaces or lines. It's important to remember that the effect of these tags ends immediately after the last angle bracket, not on the next line or with the next visible character.


 * These tags can be nested inside each other, though (for a given page) this really only applies to the 'onlyinclude' tag; nesting 'includeonly' and 'noinclude' tags is fairly pointless.


 * Note further that expansions may not occur the way expected. For instance, ~ ~ will be displayed as Adrielle =) in the template, and will be transcluded as ~, but it won't be expanded in either case (as user name or the name/date combination). The template would have to be substituted to get this wikitext to expand.

---

Noinclude

The 'noinclude' tag: used to prevent text on the template page from being transcluded onto other pages; Often used for:


 * documentation


 * categories that apply to the template itself


 * interwiki links to related templates on other wikis.

Its use is straightforward: If this text were in a template page, this part would be transcluded but this text would not be transcluded

One of the peculiarities of 'noinclude' tags is that the text contained in them is actually processed, even though it is not included in the rendered output, & this consumes system resources. For templates that are not heavily used, this is rarely a problem, but on some templates excess text (& interwiki links in particular) can create a tremendous overhead for the system. As a rule, interwikis and documentation should be placed on a /doc subpage (like that auto-generated by the template).

--

Includeonly

The 'includeonly' tag: opposite of the 'noinclude' tag. Text within an include only block is only included when the page is transcluded, is doesn't appear on the template page itself. Frequently used for:


 * categories that apply to the transclusion page


 * hiding messy text/error messages that occur on the template page itself (often because parameters that need a value are undefined)

Its use is straightforward: If this text were in a template page, this part would appear on the template page and on the transclusion page but this text would only appear on the transclusion page

-

Onlyinclude

The 'onlyinclude' tag only includes stuff that's btwn the tags; anything else on the page - even text within 'includeonly' tags, will appear on the template page but won't be included. This isn't frequently used, but might be useful when only a small bit of text in the middle of an otherwise large page is to be transcluded. It is used like this:

If this text were in a template page, this part would be visible there, but would not be transcluded This text would not be visible on the template page, nor would it be transcluded this text is all that would be transcluded

---

Magic words
3 types:

1. Parser functions

2. Behavioural switches - involves page structure modifications (of little use on templates)

3. Variables (or system variables) - often used on templates. These magic words provide info directly from the system itself: local dates & times, info about current pages, & even info about the wiki itself.

System variables take the format where the enclosed text is always entirely capitalized. A small number of system variables take a parameter as well, using the standard colon separator -.

PAGENAME & NAMESPACE variables are particularly useful, & frequently used, to change template behavior based on context. Eg, if the template transcludes a category link (e.g. cleanup templates, which transclude a link categorizing the page as a page which needs cleanup), it will often check the NAMESPACE variable to make sure that talk pages, user pages, or anywhere else the tag might incidentally be placed do not themselves get categorized as pages needing cleanup.

-

Other editing information


 * If the first included character of a template is one of the Wiki markup characters :;*#, then it is processed as though it's at the start of a line (even when the template tag isn't). This allows the creation of various kinds of lists in templates where the template may not always be in the correct place for a list. To avoid this effect use #  or a numeric character reference (NCR) or HTML entity such as &#58; for a colon. This NCR is also useful in conjunction with definition lists.

---
 * When a page called for transclusion is a redirect page, the redirect target is included instead.
 * A page that consists of nothing but the transclusion of another page is similar to a redirect, with minor differences. This method can be used to create functional "double redirects", should a need for such arise.
 * For debugging templates the following techniques are sometimes helpful


 * using 'subst:' - can show more clearly what's happening when the template is transcluded.


 * using 'msgnw:' - this keyword (short for "message, nowiki") transcludes the wikitext of the template page, more or less, rather than the processed contents. it is not perfect: lists are rendered, comments are removed, & single newlines are replaced with spaces (which is particularly confounding when transcluding wikitext tables).

}}

--

From Belthazar's Eggy Forum Post
Thanks to the lovely Belthazar =D

Essentially, the is a parameter placeholder - the parameters are the things you put between the pipe symbols in a template call. For example, is a template. If I call the template with, then the 2009, 4 and Fizz are all parameters - by default, they're numbered in order: 1, 2 and 3.

If you look at the renderegg template page, you'll notice it reads:

When the wiki software parses this, it inserts the first parameter wherever a appears, the second wherever a  appears, and the third wherever a  appears, etc. So if I insert the parameters from my example above, this becomes:

(Note: this example might be a little confusing, because the Renderegg template actually calls a series of sub-templates depending on what year it is, and how many eggs you have. And the sub-templates have named parameters rather than numbered parameters. But you get what I mean, I hope. I can continue the explanation, but I don't think you need to understand nested sub-templates to understand parameters.)

So, getting back to my idea, what I've done is replaced the template name itself with a parameter placeholder. That is, instead of calling, I'm using.

Move up a layer to the page where I call this pseudo-template, I've got. "Renderegg" here is parameter number 1, so the wiki software inserts it wherever a appears on the called page, and so we get.

Yes.. I think I am following, though, how does it insert Flategg with just the 1 parameter?

-

Same deal - you're calling the dummy page with a completely different call, and this time you're inserting "Flategg" as the parameter. So would replace every occurrence of  in the page Pagename with "Flategg" just as  would replace every occurrence of  in the page Pagename with "Renderegg".

Essentially, your dummy page would be exactly the text of your current Renderegg page (sans the opening blurb) but with in place of the template name. Then you'd reproduce the list on the Renderegg page by putting, and on the Flategg page by putting.

(Mind you, there is a simpler solution - just have everything on one page. Instead of having all the rendered images and all the flat images on separate pages, just have them together. As in Flat1, Render1, Flat2, Render2, etc. It'd require re-doing the templates a little, but it's not too complicated. As to whether it's preferable is another matter altogether. =D ) - 1. Dummy page Let's call it George, so it's clear I'm using a unique name. Here you'd have a full list of all the entrants, written out just as the pages currently look, but with no opening blurb and in place of the template name. This is the page you do all the editing. Like so:

==Pirate1==

==Pirate2==

Design 3 does not have enough bananas.

==Pirate3==

Maybe even a 'd Category tag at the bottom or something.

2. Renderegg page Here we call our list of data as though it's a template, using "Renderegg" as parameter number 1. The data will be transcluded, but with all occurrences of " " replaced by "Renderegg". There's no need to edit this page once it's been created - it just automagically updates when you update the dummy page. Viz:

Opening blurb. Welcome to Renderegg page, etc.

3. Flategg page Exactly the same, only we have a unique opening blurb, and the data page is called using "Flategg" as the parameter instead. Note it's exactly the same data, so exactly the same page, only this time we're replacing " " with "Flategg" when it gets included. Again, there's no need to edit this page after it gets created. Viz:

Opening blurb. Welcome to Flategg page, etc.

Including one page inside another doesn't change the one page, meaning we can still include it in other pages. That's the wonder of templates. =)

---

They're called templates rather than scripts, and anyone can view them (though you have to be a logged-in user to edit them). You'll find them at Template:Renderegg and Template:Flategg

The sub-templates is where things get a little complicated. As I noted above, the Renderegg template reads:

When parsed, the wiki software inserts parameters 1, 2 and 3 where the placeholders are - this is a function of the MediaWiki software itself, and not of the template. I'm reasonably sure it's open source if you want to get a hold of that and inspect how it does thing.

Now, you'll notice once the paramteres have been added, that this template is calling another sub-template. So, say I call the Renderegg template with {{Renderegg|2009|1|Fizz) (i.e. it's 2009 and Fizz has made one egg), when I substitute the values, I get:

{{Renderegg/1|filename=Fizz|year=2009}}

So, this is calling a second template called Template:Renderegg/1. There's a separate sub-template for each number of eggs. I've used the /1 template because it's pretty short... as opposed to (say) the /14 template. =)

So, the /1 template reads: {{Renderegg/{{{year}}}}}{{{filename}}}-1.png

Passing in the values from before (note here that the sub-template has named parameters, which were also named in the template call above) we get

{{Renderegg/2009}}Fizz-1.png

Note, this is calling yet another sub-template, Template:Renderegg/2009. This one simply reads:

Image:Egg-rendered-2009-

So, we've reached the end of our string of sub-templates. Now for the magic of templates, the entire text of the template is back-substituted wherever the template call occurs (this process is called "inclusion" or "transclusion" depending on which part of the wiki you're looking at). So if we substitute this into our /1 sub-template above, we get



which you'll recognise as being an image link. Clever, hey? The higher-numbered sub-templates have links for images two, three, four, and so on, which means that rather than having to type out fourteen image links to get fourteen images, we can just type {{Renderegg|2009|14|Dread Pirate Westley}} and it'll generate all the code itself from substitution of the templates and sub-templates.

The Flategg template and sub-templates are exactly the same, except they have "flat" wherever it says "render" or "rendered".

Possibly an easier way to think of it is as a more powerful version of Word's find/replace function. I've asked it to find every ocurrence of the word on a page and replaced it with a image link. The more powerful bit comes in the parameters. Parameters let you do clever things.