FANDOM


This module produces a list of links to search engines to help editors find sources about a given subject. It implements {{tl|find sources}} and other similar templates. It is highly extensible; new templates and new link types can be added easily and by any user.
 
== Usage ==
=== From wikitext ===
 
Usually, from wikitext this module should be used via a template, e.g. {{tl|find sources}}. However, it is also possible to use it directly from #invoke, like this:
 
 {{#invoke:Find sources|''template''|''search term 1''|''search term 2''|...}}
 
* <var>template</var> is the name of the template that should be called. It must be the full page name of the template, without the namespace, and with the correct capitalisation. So, for [[Template:Find sources]], the template name should be "Find sources"; "find sources" with a lower-case "f" would cause an error. This parameter is required.
* <var>search term 1</var>,  <var>search term 2</var>, etc., are the terms to be searched for in each of the search engine links. The first search term will appear in quotation marks, and subsequent search terms will be added without quotation marks. Each term will be separated by spaces. These parameters are all optional. If no parameters are given, the current page name will be used as a search term.
 
=== From Lua ===
 
Load the module with the following code:
 
<source lang="lua">
local mFindSources = require('Module:Find sources')
</source>
 
You can then produce the list of search links like this:
 
<source lang="lua">
mFindSources._main(template, searchTerms)
</source>
 
* <var>template</var> is the template name, as outlined in the [[#From wikitext]] section above. This parameter is required.
* <var>searchTerms</var> is an array of search terms. Each item in the array corresponds to a numbered search term as outlined in the [[#From wikitext]] section above. This parameter is optional.
 
Example syntax:
 
<source lang="lua">
mFindSources._main('Find sources', {'Albert Einstein', '-"Marilyn Monroe"', 'relativity', 'science'})
</source>
 
=== Available templates ===
 
The following templates are available for use:
 
{{#invoke:Find sources/autodoc|templateTable}}
 
== Making new templates ==
 
There are two basic ingredients to making a new source-finding template. The first is the template configuration module, and the second is the template invocation on the template page.
 
=== Template configuration page ===
 
To find the name of the template configuration page, take the page name of your proposed template without the namespace prefix, and add it to the base page of "Module:Find sources/templates/". For example, for [[Template:Find sources]], the configuration page is located at [[Module:Find sources/templates/Find sources]]. Note that the template must be capitalised exactly as the page name is, otherwise the arguments will not be passed through from the template page to the module.
 
The template configuration page should look something like this:
 
<source lang="lua">
return {
	blurb = "Find sources for $1 – $2",
	introLink = {code = 'google'},
	links = {
		{code = 'google news', display = 'news'},
		{code = 'google newspapers', display = 'newspapers'}
	},
	separator = ', ',
	isUsedInMainspace = true,
	class = 'custom-class',
	style = 'color: green; font-size: 110%;'
}
</source>
 
* '''blurb''' - the text presented to users. There are two parameters available in the blurb, $1 and $2. $1 is the intro link, if specified, and $2 represents the other links. This field is required.
* '''introLink''' - an optional introductory link. If specified, this must be a [[#Link tables|link table]]. If the display value in the link table is not set, the search terms that the user entered will be used instead.
* '''links''' - an array of [[#Link tables|link tables]] defining the main links to be used by the template. This field is required.
* '''separator''' - the text separating the search engine links. This field is optional; the default value is taken from [[MediaWiki:Dot-separator]].
* '''isUsedInMainspace''' - set this to true if the template will be used in the main namespace. If this is not set, when the template is used in the main namespace it will produce an error and be put in [[:Category:Pages with templates in the wrong namespace]].
* '''class''' - a custom HTML class to apply to the template text. The "plainlinks" class is added by default. This field is optional.
* '''style''' - custom CSS to apply to the template text. This field is optional.
 
==== Link tables ====
 
Link tables are used in the "introLink" and "links" fields of the template configuration. They can contain two fields, "code" and "display". The "code" field is compulsory, and must be one of the link codes listed in the table below. The "display" field is optional, and specifies a custom display value for that link to be used by the template. If the display field is not set, a default value is set by the module. For the "introLink" field, the default value is the search text entered by the user; for the "links" field, the default value is defined in the link configuration modules.
 
The following table contains all the available link codes, with descriptions and examples.
 
{{#invoke:Find sources/autodoc|linkTable}}
 
=== Template invocation ===
 
The template invocation on the template page itself should look like this:
 
 &#123;{#invoke:Find sources|''template''}&#125;&lt;noinclude&gt;
 &#123;{#invoke:Find sources/autodoc|''template''}&#125;
 &lt;/noinclude&gt;
 
This activates the template code and also provides automatic documentation. <var>template</var> is the name of the template without the namespace prefix, and must be correctly capitalised.
 
If you want to use custom documentation from a /doc subpage instead of the automatic documentation, use this invocation instead:
 
 &#123;{#invoke:Find sources|''template''}&#125;&lt;noinclude&gt;
 &#123;{documentation}&#125;
 &lt;!-- Categories go on the /doc subpage, and interwikis go on Wikidata. --&gt;
 &lt;/noinclude&gt;
 
== Adding new links ==
 
To make a new link code available to use from source-finding templates, you need to make a link configuration module for it. The page name for this module should start with "Module:Find sources/links/" and end with the link code. Link codes should be short but descriptive, and should be in lower case. For example, the link code for Google search is "google", and the configuration page is at [[Module:Find sources/links/google]].
 
The link configuration page should look something like this:
 
<source lang="lua">
return {
	url = '//www.google.com/search?q=$1',
	display = 'Google',
	separator = ','
}
</source>
 
* '''url''' - The url to perform the search. This field takes a parameter $1, which is the URL-encoded search text entered by the user. This field is required.
* '''display''' - If a display value is not specified in the template configuration, this value is used instead. This field is required.
* '''separator''' - This is used to separate the search terms entered by the user. This is optional, and defaults to "+" (a URL-encoded space).
 
== Automatic documentation ==
 
Automatic documentation is provided for templates based on this module; the documentation is generated by [[Module:Find sources/autodoc]]. The autodoc module uses the following pages:
* [[Template:Find sources documentation]] - the template used for most of the documentation content.
* The [[#Template configuration page|template configuration page]]. Used to find the list of link codes, and to see if the template is used in articles.
* The [[#Template documentation configuration page|template documentation configuration page]]. Used to find template shortcuts.
* The [[#Link documentation configuration page|link documentation configuration page]]. Used to find descriptions of each of the search links.
 
=== Template documentation configuration page ===
 
This page is located at the "/autodoc" subpage of the [[#Template configuration page|template configuration page]]. It is only used to generate the documentation, not to generate any of the actual template output, so it does not need to be protected. It should look something like this:
 
<source lang="lua">
return {
	shortcuts = {'shortcut1', 'shortcut2'},
	description = 'This template is used to provide source links on [[WP:AFD|AfD]] pages',
	docIntro = 'This template produces a series of search-engine links to be used on [[WP:AFD|AfD]] pages.'
}
</source>
 
* '''shortcuts''' - an array of shortcuts that redirect to the template page. These are displayed on the template documentation page using the {{tl|template shortcut}} template.
* '''description''' - a brief description of what the template does. This is displayed on this documentation page in the [[#Available templates|table of available templates]].
* '''docIntro''' - text to be used instead of the first sentence of the template documentation for individual source-finding templates. This is optional, and the default value is "''This template produces a series of links to various search interfaces to help find additional reference material for articles.''"
 
=== Link documentation configuration page ===
 
This page is located at the "/autodoc" subpage of the [[#Adding new links|link configuration page]]. It is only used to generate the documentation, not to generate any of the actual template output, so it does not need to be protected. It should look something like this:
 
<source lang="lua">
return {
	description = '[[Google]], the flagship search engine from Google Inc.',
	notes = 'This is the most commonly used search link.'
}
</source>
 
* '''description''' - a brief description of what the search engine link does. This is used in the template documentation to generate the list of link descriptions, and also to make the descriptions in the [[#Link tables|table of link codes]] above. This is optional, but recommended.
* '''notes''' - notes about the search engine link. These are put in the [[#Link tables|table of link codes]] above, but they are not put in the template documentation for individual source-finding templates. This field is optional.
 
== Configuration ==
 
The messages used in this module can be found at [[Module:Find sources/config]] and [[Module:Find sources/autodoc/config]]. This can be helpful for translating this module for use in other languages. Note that any template and link configuration used must also be translated.
 
<includeonly>{{#ifeq:{{SUBPAGENAME}}|sandbox||
<!-- Categories go here and interwikis go in Wikidata. -->
 
}}</includeonly>

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.