Help:Editing/Template: Difference between revisions

Content deleted Content added
imported>Rob Kam
No edit summary
No edit summary
 
(7 intermediate revisions by 2 users not shown)
Line 1:
A '''template''' is a page that gets included in another page, this other page is said to transclude the template. ThisTemplates isare usefulused for text that is often repeated. For example, create a page called "Template:Main article" with the text "The main article for this is at <nowiki>[[{{{1}}}]]</nowiki>." and then to useonly the template insert "<nowiki>{{Main article|Whatever}}</nowiki> where you want that textneeds to appear. Then wherever this text is repeated need only be updated in the template.
 
== Simple templates ==
For example, create a page called ''Template:Main article'' with the text
''The main article for this is at <nowiki>[[{{{1}}}]]</nowiki>.''
and then to use the template insert "<nowiki>{{Main article|Whatever}}</nowiki> where you want that text to appear.
 
To include the page where the template is used in some category, without that template being included in the same category, use <nowiki><includeonly></includeonly></nowiki> tags and for text on the template page to be excluded on the target page use <nowiki><noinclude></noinclude></nowiki> tags.
<nowiki><includeonly>
''The main article for this is at [[{{{1}}}]].''
[[Category:Some category]]
</includeonly>
<noinclude>
Some documentaion here.
[[Category:Templates]]
</noinclude></nowiki>
 
== Using templates from Wikipedia ==
Complex templates are easier obtained from Wikipedia, where considerable work has already gone into developing and debugging these. ObtainUse the[[Special:Import]] requiredto XMLimport datafrom viaWikipedia, (only administrators of a [https://en.wikipedia.org/wiki/Special:Export Special:Export]can do this). Do not include the full history or the file will become too large. TickCheck '' Include all templates and transcluded pages'' so that any dependencies are included. Then on the {{SITENAME}} wiki use [[Special:Import]]. Also be sure to copy any relevant styling to [[MediaWiki:Common.css]].
 
== Customisation ==
Be sure to check for and copy any required JavaScript from MediaWiki:Common.js and any relevant styling from MediaWiki:Common.css. Site specific templates need to be made more generally usable, as follows:
* Replace instances of ''Wikipedia'' in the text with <nowiki>{{ns:Project}}</nowiki>, (or ''Miraheze'' if appropriate).
* Replace instances of ''WikiMedia'' in the text with ''Miraheze''.
* Replace namespace wikilinks e.g. Wikipedia to <nowiki>{{ns:Project}}</nowiki> or meta.
* <!-- https://webmasters.stackexchange.com/questions/112873/how-to-use-mw-site-sitename-in-moduleasbox -->
In Lua modules replace ''Wikipedia'' with ''<nowiki>' .. mw.site.siteName .. '</nowiki>'' for example to alter the text in {{tlx|stub|SISTER=w:}} change in [[Special:MyLanguage/Module:Asbox|module asbox]] line 233 from:
<syntaxhighlight lang="lua">
' is a [[Wikipedia:stub|stub]]. You can help Wikipedia by [',
</syntaxhighlight>
to:
<syntaxhighlight lang="lua">
' is a [[' .. mw.site.namespaces.Project.name .. ':stub|stub]]. You can help ' .. mw.site.siteName .. ' by [',
</syntaxhighlight>.
* Remove assumptions about the structure of the wiki (such as a template producing an error when used in certain namespaces - you can't know what namespace configuration the target wiki will use) from both the code and the documentation.
* Remove or import (making sure to follow this process again) any dependencies that don't exist here.
* Remove any red-linked categories and add the template to [[:Category:Templates]] or an appropriate subcategory.
 
== Icons ==
Because of CC-BY-SA licensing considerations try to acknowledge the source of imported templates.
{{ns:Project}} is [https://www.mediawiki.org/wiki/InstantCommons Instant Commons] enabled, otherwise the images for icons would have to be uploaded locally. A good source for icon images is Wikimedia Commons' [https://commons.wikimedia.org/wiki/Category:Icons_by_subject Category:Icons by subject].
 
== Licensing ==
== Using templates from Miraheze Template Wiki ==
Because of [https://creativecommons.org/licenses/by-sa/3.0/ CC-BY-SA licensing] considerations the previous authors need to be acknowledged. Insert the appropriate source and attribution template at the bottom of the imported pages, (but not sub-pages) e.g. before &lt;/noinclude&gt; from [[:Category:Attribution templates]].
Using templates from Miraheze Template Wiki (MTW) won't prevent the wiki from having its own unique templates. The advantage of using templates from Miraheze Template Wiki is that multiple people will have already put in the effort to make highly complex templates suitable for general use. There are two ways to do this.
# ''See [[:templatewiki:Porting templates|Porting templates]] on MTW.''
# <s>''See [[:templatewiki:Interwiki transcluding templates|Interwiki transcluding templates]] on MTW.''</s> Interwiki transclusion isn't ready yet.
 
== Testing ==
Line 23 ⟶ 55:
 
[[Category:Help:Editing]]
[[Category:MetaWiki glossary]]