Help:Advanced editing: Difference between revisions

m
Protected "Help:Advanced editing" ([Edit=Allow only autoconfirmed users] (indefinite) [Move=Allow only administrators] (indefinite))
No edit summary
m (Protected "Help:Advanced editing" ([Edit=Allow only autoconfirmed users] (indefinite) [Move=Allow only administrators] (indefinite)))
 
(9 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{proposed policy}}
{{helppage}}
{{helppage}}


Line 15: Line 14:
It is possible to use the <code><nowiki>&lt;font></nowiki></code> tag instead of <code><nowiki>&lt;span></nowiki></code> (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.
It is possible to use the <code><nowiki>&lt;font></nowiki></code> tag instead of <code><nowiki>&lt;span></nowiki></code> (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.
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 [[SmashWiki:Twelve and Twenty-Six Translation Project|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:
*<code>red</code>, <code>yellow</code>, <code>blue</code>, <code>green</code>, <code>purple</code>, etc. Most basic colours can be represented in this way.
*<code>#ffbfbf</code>, <code>#004f8f</code>, <code>#a94b27</code>, 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.
*<code>rgb(255,191,191)</code>, <code>rgb(0,79,143)</code>, <code>rgba(129,50,93,0.5)</code>, 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:web colors|Wikipedia's page on web colours]].


==Code and nowiki tags==
==Code and nowiki tags==
Line 21: Line 28:
*<code><nowiki>&lt;code></nowiki></code> tags apply styling to the content, so text looks monospaced like it does in the editor.
*<code><nowiki>&lt;code></nowiki></code> tags apply styling to the content, so text looks monospaced like it does in the editor.
*<code><nowiki>&lt;nowiki></nowiki></code> tags tell the parser to not treat anything inside as wikicode; for example, internal links remain in the form of <nowiki>[[Link]]</nowiki>.
*<code><nowiki>&lt;nowiki></nowiki></code> tags tell the parser to not treat anything inside as wikicode; for example, internal links remain in the form of <nowiki>[[Link]]</nowiki>.
==Inclusion-control tags==
Often, it's desirable to separate templates into "content" and "documentation". These two tags provide this.
*<code><nowiki><noinclude></noinclude></nowiki></code> 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.
*<code><nowiki><includeonly></includeonly></nowiki></code> 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==
==Substitution templates==
Line 57: Line 69:
|}
|}


Tables are best explained by example. This is the code used to crate the above table (with code and nowiki tags removed):
Tables are best explained by example. This is the code used to create the above table (with code and nowiki tags removed):
<pre>
<pre>
{|class="wikitable"
{|class="wikitable"
Line 86: Line 98:


==Non-breaking space==
==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 strong that should never be broken across two lines. The easiest way to fix this is to use the non-breaking space, or <code><nowiki>&amp;nbsp;</nowiki></code>. 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 <code><nowiki>[[Main&nbsp;Page]]</nowiki></code> will lead to [[Main&nbsp;Page]] as expected.
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 <code><nowiki>&amp;nbsp;</nowiki></code>. 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 <code><nowiki>[[Main&amp;nbsp;Page]]</nowiki></code> will lead to [[Main&nbsp;Page]] as expected.


<code><nowiki>&amp;nbsp;</nowiki></code> 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 are are discarded). The non-breaking space is not discared in this way, and can be used to make cells non-empty but still blank.
<code><nowiki>&amp;nbsp;</nowiki></code> 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==
==Parameterized templates==
Line 107: Line 119:
:Computes a math expression and displays the result.
:Computes a math expression and displays the result.
;<code><nowiki>{{#if:condition|true|false}}</nowiki></code>
;<code><nowiki>{{#if:condition|true|false}}</nowiki></code>
:If "condition" is blank, display "false", otherwise display "true".
: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".
;<code><nowiki>{{#ifeq:one|two|true|false}}</nowiki></code>
;<code><nowiki>{{#ifeq:one|two|true|false}}</nowiki></code>
:If "one" equals "two", display "true", otherwise display "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".
;<code><nowiki>{{#ifexpr:math|true|false}}</nowiki></code>
;<code><nowiki>{{#ifexpr:math|true|false}}</nowiki></code>
:If "math" is true, display "true", otherwise display "false".
:If "math" is true, display "true", otherwise display "false".
Line 116: Line 128:


For a more comprehensive guide, see [[mw:Help:Extension:ParserFunctions|MediaWiki's Help:Extension:ParserFunctions]].
For a more comprehensive guide, see [[mw:Help:Extension:ParserFunctions|MediaWiki's Help:Extension:ParserFunctions]].
==String functions==
Strings (text, basically) have various functions available for manipulation purposes. They can become expensive if overused however.
;<code><nowiki>{{lc:Text}}</nowiki></code>
:Turns all of "Text" into lowercase, resulting in "text". Common if case-insensitive comparison is desired - simply lowercase both sides of the comparison.
;<code><nowiki>{{uc:Text}}</nowiki></code>
:Turns all of "Text" into uppercase, resulting in "TEXT".
;<code><nowiki>{{lcfirst:Text}}</nowiki></code>, <code><nowiki>{{ucfirst:Text}}</nowiki></code>
:Same as lc: and uc:, but only changes the first letter.
;<code><nowiki>{{plural:number|1|2}}</nowiki></code>
: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.
;<code><nowiki>{{#len:Text}}</nowiki></code>
:Displays the length of the given text.
;<code><nowiki>{{#pos:Text|what|start}}</nowiki></code>
:Goes to the "start"th letter and starts looking to the right, displaying position of the first occurrence of "what" in the text. This number is zero-based: 0 indicates the start of the text, 1 is the second letter, etc.
;<code><nowiki>{{#sub:Text|start|length}}</nowiki></code>
:Displays "length" letters from the text, starting with the "start"th one.
;<code><nowiki>{{#replace:Text|x|q}}</nowiki></code>
:Replaces all "x"s in the text with "q"s.
For a more comprehensive guide, see [[mw:Help:Magic words|MediaWiki's Help:Magic words]] and [[mw:Extension:StringFunctions|MediaWiki's Extension:StringFunctions]].


{{helpnav}}
{{helpnav}}
[[Category:Help]]
[[Category:Help]]