Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Module:Find sources

Permanently protected module
From Wikipedia, the free encyclopedia
Module documentation[view] [edit] [history] [purge]
WarningThis Lua module is used onapproximately 1,600,000 pages, or roughly 2% of all pages.
To avoid major disruption and server load, any changes should be tested in the module's/sandbox or/testcases subpages, or in your ownmodule sandbox. The tested changes can be added to this page in a single edit. Consider discussing changes on thetalk page before implementing them.
Thismodule is rated asready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned onhelp pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed throughsandbox testing rather than repeated trial-and-error editing.
Page template-protectedThis module is currentlyprotected from editing.
See theprotection policy andprotection log for more details. Please discuss any changes on thetalk page; you maysubmit an edit request to ask anadministrator to make an edit if it isuncontroversial or supported byconsensus. You may alsorequest that this page be unprotected.

This module produces a list of links to search engines to help editors find sources about a given subject. It implements{{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.{{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|...}}
  • template 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, forTemplate:Find sources, the template name should be "Find sources"; "find sources" with a lower-case "f" would cause an error. This parameter is required.
  • search term 1,search term 2, 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.

Alternatively the following can be used, which will convert any title to a search query, with the main portion of the title in quotation marks, and any parenthetical disambiguator outside quotation marks.

{{#invoke:Find sources|template|title=title}}
  • template as above, 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, forTemplate:Find sources, the template name should be "Find sources"; "find sources" with a lower-case "f" would cause an error. This parameter is required.
  • title the title to be converted to a search query. This is processed in the same way as the subpage name of the page if no parameters are used.

From Lua

Load the module with the following code:

localmFindSources=require('Module:Find sources')

You can then produce the list of search links like this:

mFindSources._main(template,searchTerms)
  • template is the template name, as outlined in the#From wikitext section above. This parameter is required.
  • searchTerms 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. Alternatively, an empty table with thetitle key set will automatically generate a query as described above. This parameter is optional.

Example syntax:

mFindSources._main('Find sources',{'Albert Einstein','-"Marilyn Monroe"','relativity','science'})

Available templates

The following templates are available for use:

TemplateDescriptionExampleConfiguration
Find general sourcesThe most widely used source-finding template. Until September 2014 it was transcluded on allAfD discussion pages.Find sources: Google (books ·news ·scholar ·free images ·WP refs·FENS ·JSTOR ·TWLmain,documentation
Find sources mainspaceA source-finding template for use in mainspace. Used inTemplate:Notability.Find sources: "Example" – news ·newspapers ·books ·scholar ·JSTORmain,documentation
Find sources medicalNo description availableFind medical sources: Source guidelines ·PubMed ·Cochrane ·DOAJ ·Gale ·OpenMD ·ScienceDirect ·Springer ·Trip ·Wiley ·TWLmain,documentation
Find sources video gamesThe source-finding template transcluded onAfD pages for video games and related topics.Find video game sources: "Example" – news ·newspapers ·books ·scholar ·JSTOR ·free images ·free news sources ·TWL ·NYT ·WP reference ·VG/RS ·VG/RL ·WPVG/Talkmain,documentation

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, forTemplate:Find sources, the configuration page is located atModule: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:

return{blurb="Find sources for $1 – $2",introLink={code='google'},links={{code='google news',display='news'},{code='google newspapers',display='newspapers',tooltip='Search newspapers with Google Books'}},separator=', ',isUsedInMainspace=true,class='custom-class',style='color: green; font-size: 110%;'}
  • 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 alink 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 oflink 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 fromMediaWiki: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 inCategory: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.

Once you have created your template configuration page, you need to add the template toModule:Find sources/templates in order for it to show up in the table of templates on this documentation page.

Link tables

Link tables are used in the "introLink" and "links" fields of the template configuration. They can contain three fields, "code", "display", and "tooltip". The "code" field is required, 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. The "tooltip" field is also optional, and specifies a custom tooltip for the link. HTML reserved characters are escaped by the module. If the field is absent, no tooltip is displayed. 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.

CodeDescriptionExampleNotes
apTheAssociated Press, an American news agencyAssociated Press
archive.orgTheInternet Archive, a digital library of public websites.Archive.org
bbcBBC, British public broadcasterBBC
bingBing, Microsoft's flagship search engine.Bing
britannicaEncyclopedia BritannicaEncyclopedia Britannica
british libraryNational library of the United KingdomBritish Library
ccsearchCC Search: The official search engine ofCreative CommonsCC Search
cochraneCochrane Library: Leading publisher of systematic reviews.Cochrane
doajDOAJ: Directory of Open Access JournalsDOAJ
duckduckgoDuckDuckGo, a search engine that emphasizes protecting searchers' privacy and avoiding the "filter bubble" of personalized search results.DuckDuckGo
eowbNo description availableEncyclopedia of World Biography
free news sourcesNo description availablefree news sources
galeGale Academic OneFile: Academic publisher portal fromGale. Access viaWikipedia LibraryGale Academic OneFile
ginNo description availableGIN guidelines
globe and mailThe website ofThe Globe and Mail, anewspaper of record for Canada.The Globe and Mail
googleGoogle, the flagship search engine from Google Inc.Google
google booksGoogle Books, Google's search engine for books.Google Books
google free imagesGoogle Images, Google's search engine for images. Only images compatible with Wikipedia's licensing are included.Free Google Images
google newsGoogle News, Google's search engine for news sites.Google NewsIn the past this link searched news archives, but this functionality has been removed by Google. Currently, only recent news articles are searched.
google newspapersGoogle Newspapers, a search of Google's digital archive of print newspapers.Google Newspapers
google scholarGoogle Scholar, Google's search engine for academic papers and other scholarly research.Google Scholar
haaretzThe website ofHaaretz, anewspaper of record for Israel.Haaretz
infopleaseNo description availableInfoplease
internet archive scholarTheInternet Archive Scholar, a digital library of open access academic journals.IA scholar
jstorJSTOR, an online library containing digitised versions of academic journals. Requires a subscription.JSTOR
library of congressU.S.Library of CongressLibrary of Congress
mail and guardianThe website of theMail & Guardian, anewspaper of record for South Africa.Mail & Guardian
medrsMEDRS: Ideal sources for biomedical material include recent literature reviews and medical guidelines; learn how to identify reliable sources for medical content.find medical sources
museNo description availableMUSE
new york timesThe website ofThe New York Times, anewspaper of record for the United States.New York Times
new zealand heraldThe website ofThe New Zealand Herald, anewspaper of record for New Zealand.The New Zealand Herald
openlibraryNo description availableOpenLibrary
openmdOpenMD: Search engine for medical literature.OpenMD
pubmedPubMed: Search engine for biomedical literature fromNLM.PubMed
reutersReuters, an international news agencyReuters
sciencedirectScienceDirect:Elsevier's scientific, technical, and medical research portal.ScienceDirect
south china morning postThe website of theSouth China Morning Post, anewspaper of record for Hong Kong.South China Morning Post
springerSpringer Nature's portal for journals, books, and reference works.Springer
statpearlsStatPearls: the largest provider of healthcare continuing education worldwide, providing peer-reviewed practice-guiding knowledge authored by clinical experts.StatPearls
straits timesThe website ofThe Straits Times, anewspaper of record for Singapore.The Straits Times
sydney morning heraldThe website ofThe Sydney Morning Herald, anewspaper of record for Australia.The Sydney Morning Herald
the ageThe website ofThe Age, anewspaper of record for Australia.The Age
the guardianThe Guardian newspaper, U.K.The Guardian
the hinduThe website ofThe Hindu, anewspaper of record for India.The Hindu
the timesThe website ofThe Times, anewspaper of record for the United Kingdom.The Times
times of indiaThe website ofThe Times of India, anewspaper of record for India.The Times of India
tripTrip Database: Search engine for clinical research evidence.Trip Database
uptodateNo description availableUpToDate
vgrlWikipedia:WikiProject Video games/Reference library internal archive search.VGRL
vgrsGoogle RS, acustom Google search engine that limits the search to sites listed inWikipedia:WikiProject Video games/Sources.VGRS
vgtalkA search in the WikiProject Video games talk page and its archives underWikipedia talk:WikiProject Video games.WPVG Talk
wikipedia librarySearch results from dozens of services provided via EBSCOhost to Wikipedians viaWikipedia:The Wikipedia Library.TWL
wikipedia reference searchWikipedia Reference Search, a Google search that only searches sites vetted by Wikipedians.Wikipedia Reference Search
wileyWiley Online Library:Wiley's portal for academic articles, books, and collections.Wiley
wsjThe website ofThe Wall Street Journal, anewspaper of record for the United States.Wall Street Journal

Template invocation

The template invocation on the template page itself should look like this:

{{#invoke:Find sources|template}}<noinclude>{{#invoke:Find sources/autodoc|template}}</noinclude>

This activates the template code and also provides automatic documentation.template 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:

{{#invoke:Find sources|template}}<noinclude>{{documentation}}<!-- Categories go on the /doc subpage, and interwikis go on Wikidata. --></noinclude>

Adding new links

New links are added toModule:Find sources/links. Link codes should be short but descriptive, and should be in lower case. For example, the link code for Google search is "google".

The link configuration page should look something like this:

return{url='//www.google.com/search?as_eq=wikipedia&q=$1',display='Google',description='[[Google]], the flagship search engine from Google Inc.',}
Parameters
ParameterDescription
urlThe 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.
displayIf a display value is not specified in the template configuration, this value is used instead. This field is required.
separatorThis is used to separate the search terms entered by the user. This is optional, and defaults to "+" (a URL-encoded space).
descriptiona 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 thetable of link codes above. This is optional, but recommended.
notesnotes about the search engine link. These are put in thetable of link codes above, but they are not put in the template documentation for individual source-finding templates. This field is optional.

Automatic documentation

Automatic documentation is provided for templates based on this module; the documentation is generated byModule:Find sources/autodoc. The autodoc module uses the following pages:

Template documentation configuration page

This page is located at the "/autodoc" subpage of thetemplate 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:

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.'}
  • shortcuts - an array of shortcuts that redirect to the template page. These are displayed on the template documentation page using the{{template shortcut}} template.
  • description - a brief description of what the template does. This is displayed on this documentation page in thetable 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."

Configuration

The messages used in this module can be found atModule:Find sources/config andModule: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.

The abovedocumentation istranscluded fromModule:Find sources/doc.(edit |history)
Editors can experiment in this module'ssandbox(edit |diff) and testcases(create) pages.
Subpages of this module.

-- This module implements {{find sources}} and other similar templates, and-- also provides a mechanism to easily create new source-finding templates.-- Define constantslocalROOT_PAGE='Module:Find sources'localTEMPLATE_ROOT=ROOT_PAGE..'/templates/'-- for template config moduleslocalLINK_CONFIG=ROOT_PAGE..'/links'-- for link config moduleslocalCONFIG_PAGE=ROOT_PAGE..'/config'-- for global config-- Load required moduleslocalcheckType=require('libraryUtil').checkTypelocalcfg=mw.loadData(CONFIG_PAGE)localp={}localfunctionmaybeLoadData(page)localsuccess,data=pcall(mw.loadData,page)returnsuccessanddataendlocalfunctionsubstituteParams(msg,...)returnmw.message.newRawMessage(msg,...):plain()endlocalfunctionrenderSearchString(searchTerms,separator,transformFunc)-- This takes a table of search terms and turns it into a search string-- that can be used in a URL or in a display value. The transformFunc-- parameter can be used to transform each search term in some way (for-- example, URL-encoding them).localsearchStrings={}fori,sinipairs(searchTerms)dosearchStrings[i]=sendiftransformFuncthenfori,sinipairs(searchStrings)dosearchStrings[i]=transformFunc(s)endendreturntable.concat(searchStrings,separator)endfunctionp._renderLink(code,searchTerms,display,tooltip)-- Renders the external link wikicode for one link, given the link code,-- a table of search terms, and an optional display value and tooltip.-- Get link config.locallinks=maybeLoadData(LINK_CONFIG)locallinkCfg=links[code]ifnotlinkCfgthenerror(string.format("invalid link code '%s'; no link config found at [[%s]]",code,LINK_CONFIG))end-- Make URL.localurldolocalseparator=linkCfg.separatoror"+"localsearchString=renderSearchString(searchTerms,separator,mw.uri.encode)url=substituteParams(linkCfg.url,searchString)endiftooltipthenreturnstring.format('<span title="%s" style="border-bottom: 1px dotted;">[%s %s]</span>',mw.text.encode(tooltip),url,displayorlinkCfg.display)elsereturnstring.format('[%s %s]',url,displayorlinkCfg.display)endendfunctionp._main(template,args)-- The main access point from Lua.checkType('_main',1,template,'string')checkType('_main',2,args,'table',true)args=argsor{}localtitle=mw.title.getCurrentTitle()-- Get the template config.localtemplateCfgPage=TEMPLATE_ROOT..templatelocaltemplateCfg=maybeLoadData(templateCfgPage)ifnottemplateCfgthenerror(string.format("invalid template name '%s'; no template config found at [[%s]]",template,templateCfgPage))end-- Namespace check.ifnottemplateCfg.isUsedInMainspaceandtitle.namespace==0thenlocalformatString='<strong class="error">%s</strong>'ifcfg['namespace-error-category']thenformatString=formatString..'[[%s:%s]]'endreturnstring.format(formatString,cfg['namespace-error'],mw.site.namespaces[14].name,cfg['namespace-error-category'])end-- Get the search terms from the arguments.localsearchTerms={}fori,sinipairs(args)dosearchTerms[i]=sendifnotsearchTerms[1]then-- Use the current subpage name as the default search term, unless-- another title is provided. If the page uses a disambiguator like-- "Foo (bar)", make "Foo" the first term and "bar" the second.localsearchTitle=args.titleortitle.subpageTextlocalterm,dab=searchTitle:match('^(.*) (%b())$')ifdabthendab=dab:sub(2,-2)-- Remove parensendiftermanddabthensearchTerms[1]=termsearchTerms[2]=dabelsesearchTerms[1]=searchTitleendendsearchTerms[1]='"'..searchTerms[1]..'"'-- Make the intro linklocalintroLinkiftemplateCfg.introLinkthenlocalcode=templateCfg.introLink.codelocaldisplay=templateCfg.introLink.displayorrenderSearchString(searchTerms,'&nbsp;')localtooltip=templateCfg.introLink.tooltipintroLink=p._renderLink(code,searchTerms,display,tooltip)elseintroLink=''end-- Make the other linkslocallinks={}localseparator=templateCfg.separatororcfg['default-separator']localsep=''fori,tinipairs(templateCfg.links)dolinks[i]=sep..p._renderLink(t.code,searchTerms,t.display,t.tooltip)..(t.afterDisplayor'')sep=t.separatororseparatorendlinks=table.concat(links)-- Make the blurb.localblurb=substituteParams(templateCfg.blurb,introLink,links)localspan=mw.html.create('span')span:addClass('plainlinks'):addClass(templateCfg.class):cssText(templateCfg.style):wikitext(blurb)returntostring(span)endsetmetatable(p,{__index=function(t,template)-- The main access point from #invoke.-- Invocations will look like {{#invoke:Find sources|template name}},-- where "template name" is a subpage of [[Module:Find sources/templates]].localtname=templateiftname:sub(-8)=='/sandbox'then-- This makes {{Find sources/sandbox|Albert Einstein}} work.tname=tname:sub(1,-9)endreturnfunction(frame)localargs=require('Module:Arguments').getArgs(frame,{wrappers=mw.site.namespaces[10].name..':'..tname})returnt._main(template,args)endend})returnp
Retrieved from "https://en.wikipedia.org/w/index.php?title=Module:Find_sources&oldid=1074289944"
Categories:
Hidden category:

[8]ページ先頭

©2009-2025 Movatter.jp