Module:Search/sandbox: Difference between revisions
Appearance
Content deleted Content added
why is long like this |
undo my dumbness |
||
Line 12: | Line 12: | ||
end |
end |
||
local function addlink( |
local function addlink(p, u, a, t, s) |
||
local item = ll:tag('li') |
|||
return '[' .. url .. ' <abbr title="' .. unabbreviated .. '">' .. abbreviation ..'</abbr>]' |
|||
item:wikitext(p .. '[' .. u .. ' ') |
|||
item:tag('abbr') |
|||
:attr('title', a) |
|||
⚫ | |||
⚫ | |||
end |
end |
||
Line 26: | Line 31: | ||
local ret = mw.html.create('div') |
local ret = mw.html.create('div') |
||
:addClass('template-search') |
:addClass('template-search') |
||
:addClass('plainlist') |
|||
:addClass('plainlinks') |
:addClass('plainlinks') |
||
ll = ret:tag('ul') |
|||
local list1 = { |
|||
⚫ | |||
} |
|||
if long then |
if long then |
||
addlink('', 'https://www.google.com/search?q=site%3Awikipedia.org+' .. ssenc, 'Wikipedia over Google', 'gwp', ' ') |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
else |
|||
⚫ | |||
⚫ | |||
addlink('', 'https://www.bing.com/search?q=' .. ssenc, 'Bing', 'b', ')') |
|||
end |
end |
||
⚫ | |||
if long then |
|||
⚫ | |||
⚫ | |||
end |
|||
local list2 = long and { |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} or { |
|||
⚫ | |||
} |
|||
local make_list = require('Module:List').makeList |
|||
⚫ | |||
:wikitext(make_list('unbulleted', list1)) |
|||
if long then ret:wikitext(' | ') end |
|||
ret:wikitext(make_list('unbulleted', list2)) |
|||
⚫ | |||
return frame:extensionTag{ |
return frame:extensionTag{ |
Revision as of 22:14, 8 December 2022
![]() | This is the module sandbox page for Module:Search (diff). |
![]() | This module depends on the following other modules: |
![]() | This module uses TemplateStyles: |
Implements {{search}}
-- This module implements {{search}}
local p = {}
local ll = ''
local function urlencode(text)
-- Return equivalent of {{urlencode:text}}.
local function byte(char)
return string.format('%%%02X', string.byte(char))
end
return text:gsub('[^ %w%-._]', byte):gsub(' ', '+')
end
local function addlink(p, u, a, t, s)
local item = ll:tag('li')
item:wikitext(p .. '[' .. u .. ' ')
item:tag('abbr')
:attr('title', a)
:wikitext(t)
item:wikitext(']' .. s)
end
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {
wrappers = 'Template:Search'
})
local ss = args[1] or 'example phrase'
local ssenc = urlencode(ss)
local long = (args.long or '') ~= ''
local ret = mw.html.create('div')
:addClass('template-search')
:addClass('plainlist')
:addClass('plainlinks')
ll = ret:tag('ul')
if long then
addlink('', 'https://www.google.com/search?q=site%3Awikipedia.org+' .. ssenc, 'Wikipedia over Google', 'gwp', ' ')
addlink('', 'https://www.google.com/search?q=' .. ssenc, 'Google', 'g', ' ')
addlink('', 'https://www.bing.com/search?q=site%3Awikipedia.org+' .. ssenc, 'Wikipedia over Bing', 'bwp', ' ')
addlink('', 'https://www.bing.com/search?q=' .. ssenc, 'Bing', 'b', ' | ')
addlink('', 'https://www.britannica.com/search?nop&query=' .. ssenc, 'Encyclopaedia Britannica', 'eb', ' ')
addlink('', 'https://www.bartleby.com/cgi-bin/texis/webinator/65search?query=' .. ssenc, 'Columbia Encyclopedia', 'co', ' ')
addlink('', 'https://www.google.com/search?q=site%3Ahttp%3A%2F%2Fwww.pcmag.com%2Fencyclopedia_term%2F+' .. ssenc, 'PC Magazine Encyclopedia over Google', 'gct', ' ')
addlink('', 'https://scienceworld.wolfram.com/search/index.cgi?as_q=' .. ssenc, 'World of Science', 'sw', ' ')
addlink('', 'https://archive.org/search.php?query=' .. ssenc, 'Internet Archive', 'arc', ' ')
addlink('', 'https://babel.hathitrust.org/cgi/ls?field1=ocr;q1=' .. ssenc .. ';a=srchls;lmt=ft', 'HathiTrust', 'ht', ')')
else
addlink('(', '//en.wikipedia.org/w/index.php?title=Special:Search&search=' .. ssenc, 'Wikipedia', 'wp', ' ')
addlink('', 'https://www.google.com/search?q=' .. ssenc, 'Google', 'g', ' ')
addlink('', 'https://www.bing.com/search?q=' .. ssenc, 'Bing', 'b', ')')
end
return frame:extensionTag{
name = 'templatestyles', args = { src = 'Module:Search/styles.css' }
} .. tostring(ret)
end
return p