Help:Advanced editing

From SmashWiki, the Super Smash Bros. wiki
Jump to: navigation, search
Notice.png This page is a SmashWiki help page, intended to be a guide to helping users understand SmashWiki and its functionalities. When editing this page, please ensure that your revision reflects consensus. If in doubt, consider discussing changes on the talk page.

This page is intended as a "second step" to users who are familliar with basic editing and wish to learn more complex wikicode.

A common theme amongst these tips is to always preview before saving. All of these features have the potential to do strange, confusing, and sometimes scary things to pages if not perfectly synced.

Fonts and colours

The simplest way of changing the font or the colour of text is the <span> tag. Here are some simple examples:

  • <span style="color:red">RED</span> becomes RED
  • <span style="color:#5f9f2f">some hex colour</span> becomes some hex colour
  • <span style="font-family:Times New Roman,serif">It has serifs</span> becomes It has serifs
  • <span style="font-family:Impact;color:blue">IMPACT</span> becomes IMPACT

It is possible to use the <font> tag instead of <span> (which works slightly differently), but be warned that it's deprecated in HTML5, which means that you shouldn't be using it even if it works right now because it's planned to be deleted altogether.

Note that changing fonts and text colours should be reserved for signatures and user pages. Articles should be as easy-to-read as possible, which includes no font or colour changes. The main exception is when replication of an official source's visuals is the primary goal, such as the 1226 translation project.

Choice of colours

As with most web markup, there is a list of several "default" colours available in addition to the ability to specify effectively any colour. Examples include:

  • red, yellow, blue, green, purple, etc. Most basic colours can be represented in this way.
  • #ffbfbf, #004f8f, #a94b27, etc. These are known as "hex colours" and can be used to specify any computer-representable colour. In this form, the first two hexadecimal digits represent the amount of red from 0 to 255, while the second pair is green and the third pair is blue.
  • rgb(255,191,191), rgb(0,79,143), rgba(129,50,93,0.5), etc. This technique uses numbers in decimal instead of in hexadecimal, making it slightly easier to understand at the expense of taking up more space. It also has an optional opacity value (seen in third example of "rgba" instead of "rgb"), where 1.0 is "completely opaque" and 0.0 is "completely transparent", allowing for a wider range of effects.

For more information, see Wikipedia's page on web colours.

Code and nowiki tags

On pages such as this one, <code> and <nowiki> tags are used to display code on pages.

  • <code> tags apply styling to the content, so text looks monospaced like it does in the editor.
  • <nowiki> tags tell the parser to not treat anything inside as wikicode; for example, internal links remain in the form of [[Link]].

Inclusion-control tags

Often, it's desirable to separate templates into "content" and "documentation". These two tags provide this.

  • <noinclude></noinclude> tags specify that the content within will show up on the template's page, but not when the template is used. For example, template documentation and categories should be wrapped in this, as otherwise a template in Category:Templates would place any page it's used on into that category.
  • <includeonly></includeonly> tags specify that the content within will only show up when the template is used, and not when the template itself is viewed. For example, a template that requires input to function properly may be broken when viewed on its page (potentially causing false problem reports such as broken links); surrounding the template in this will prevent this. Note however that this makes the template impossible to preview, so it must be temporarily removed when editing (and then re-added before saving).

Substitution templates

Certain symbols have multiple usages:

  • The ' symbol is used as both an apostrophe and as bold and italic formatting.
  • The | symbol is used in internal links, but also in tables and parser functions.

There are several cases where the wiki software cannot tell what the intent of a symbol is - for example, attempting to display pieces of a table in a parser function may be seen as part of the parser function itself. To temper these issues, these templates exist:

  • {{'}}, which adds '
  • {{!}}, which adds |
  • {{!!}}, which adds ||

Using these templates will solve most conflation errors.

Tables

Tables are likely the most common advanced form of wikicode and can be tricky to get right even for experienced users.

Table syntax involves a combination of pipes, braces, and exclamation marks:

Code Meaning
{| Marks the beginning of a table.
|- Marks a new row.
| Marks a new cell (on a new line).
|| Marks a new cell (on the same line).
! Marks a new header cell (on a new line).
!! Marks a new header cell (on the same line, use if and only if the line starts with a ! cell).
|} Marks the end of a table.

Tables are best explained by example. This is the code used to create the above table (with code and nowiki tags removed):

{|class="wikitable"
|-
!Code!!Meaning
|-
| {| ||Marks the beginning of a table.
|-
| |- ||Marks a new row.
|-
| |  ||Marks a new cell (on a new line).
|-
| || ||Marks a new cell (on the same line).
|-
| !  ||Marks a new header cell (on a new line).
|-
| !! ||Marks a new header cell (on the same line, use if and only if the line starts with a ! cell).
|-
| |} ||Marks the end of a table.
|}

When working with tables, spacing is best described as "touchy". Sometimes the amount of spaces between two cells or rows is irrelevant, while other times it breaks the table altogether. Typically this is only an issue when combining tables with templates; most of the time, for text-only tables, spacing is collapsed. As a result, while it's not necessary to provide spacing between code and content, it can help readibility of the page source.

Note the class="wikitable" in the above example. wikitable is a combination of CSS styling used for most tables on the wiki for a consistent look. Without it, tables will not have any borders or colour, appearing as text hanging in the middle of nowhere.

For a more comprehensive guide, see MediaWiki's Help:Tables.

Non-breaking space

Sometimes, it is undesireable for a space to ever be broken by a new line. For example, certain tables may have long links or other text string that should never be broken across two lines. The easiest way to fix this is to use the non-breaking space, or &nbsp;. Putting this code in text creates a space that is not considered a legal line break location. In addition, it is treated as a normal space by links, so [[Main&nbsp;Page]] will lead to Main Page as expected.

&nbsp; is also a convenient way to specify "blank space" as opposed to "nothing" for tables. There is a difference between "nothing" and "contains a space" for table cells, but adding spaces to a cell will have no effect (they are assumed to exist only for source readability purposes and so are discarded). The non-breaking space is not discared in this way, and can be used to make cells non-empty but still blank.

Parameterized templates

Templates do not have to show the exact same text every time they are used. A common example is the {{SSBB}} template, which links to a "Character (SSBB)" page based on the text supplied to it. This is done by adding parameters to templates.

In their simplest form, a parameter is a number or word in triple braces, such as {{{example}}}. The code for inputting into a template is {{{TemplateName|example=Input goes here}}. In this case, every time {{{example}}} is written in the template, it will be replaced with Input goes here.

The parameters {{{1}}}, {{{2}}}, {{{3}}}, etc. are unnamed parameters. For example, in {{TemplateName|spam|eggs}}, {{{1}}} is spam and {{{2}}} is eggs. These can be combined with named parameters, but unnamed parameters cannot be listed after named ones.

It is possible to specify a default value for parameters, so something sensible appears if they are not specified. For example, {{{value|Unknown}}} will appear as Unknown if a template usage does not provide value. It is common to see {{{param|}}}, which is a blank default value, and so does not display anything at all if unspecified. Default values always appear on the template page itself and so are a good tool for previewing template edits (for example, set the default value to something you may input in a usage and preview to see how it looks).

Parameter defaults can be "stacked". For example, {{{name1|{{{name2|default}}}}}} will display name1 if it's given, name2 if it's not, and default if neither. This can be extended quite a ways, but try to avoid stacks too high, as it becomes difficult to keep track of all the braces.

Parser functions

Some complex template require rudimentary decision-making abilities - for example, only display "SSBM" if a character appears in that game. Parser functions provide this sort of coding. There are several parser functions available, with the more common ones being:

{{#expr:math}}
Computes a math expression and displays the result.
{{#if:condition|true|false}}
If "condition" is blank, display "false", otherwise display "true". Common usage includes "display a table row if it has a value, otherwise don't show the row at all" and "use a template if it has a value, otherwise add the page to a maintenance category".
{{#ifeq:one|two|true|false}}
If "one" equals "two", display "true", otherwise display "false". This is a case-sensitive string comparison, so "0.0" does not equal "0", and "Character" does not equal "character".
{{#ifexpr:math|true|false}}
If "math" is true, display "true", otherwise display "false".
{{#switch:something|1=A|2=B|3|4|5=C|#default=Q}}
Take "something". If it's "1", display "A". If it's "2", display "B". If it's "3", "4", or "5", display "C". Otherwise, display "Q".

For a more comprehensive guide, see MediaWiki's Help:Extension:ParserFunctions.

String functions

Strings (text, basically) have various functions available for manipulation purposes. They can become expensive if overused however.

{{lc:Text}}
Turns all of "Text" into lowercase, resulting in "text". Common if case-insensitive comparison is desired - simply lowercase both sides of the comparison.
{{uc:Text}}
Turns all of "Text" into uppercase, resulting in "TEXT".
{{lcfirst:Text}}, {{ucfirst:Text}}
Same as lc: and uc:, but only changes the first letter.
{{plural:number|1|2}}
If "number" equals 1, display "1", otherwise display "2". A shortcut for a common piece of logic: determining whether a word should be displayed as plural.
{{#len:Text}}
Displays the length of the given text.
{{#pos:Text|what|start}}
Goes to the "start"th letter and starts looking to the right, displaying position of the first occurance of "what" in the text. This number is zero-based: 0 indicates the start of the text, 1 is the second letter, etc.
{{#sub:Text|start|length}}
Displays "length" letters from the text, starting with the "start"th one.
{{#replace:Text|x|q}}
Replaces all "x"s in the text with "q"s.

For a more comprehensive guide, see MediaWiki's Help:Magic words and MediaWiki's Extension:StringFunctions.