Module:Search/sandbox: Difference between revisions
Appearance
Content deleted Content added
put that one back |
ok here we go here is some rewreite |
||
Line 1: | Line 1: | ||
-- This module implements {{search}} |
-- This module implements {{search}} |
||
local p = {} |
local p = {} |
||
local ll = '' |
|||
local function urlencode(text) |
local function urlencode(text) |
||
Line 12: | Line 10: | ||
end |
end |
||
local function |
local function make_link(url, expansion, display_text, after) |
||
return mw.ustring.format( |
|||
local item = ll:tag('li') |
|||
'[%s <abbr title="%s">%s</abbr>]%s', |
|||
item:wikitext(p .. '[' .. u .. ' ') |
|||
url, |
|||
item:tag('abbr') |
|||
expansion, |
|||
:attr('title', a) |
|||
display_text, |
|||
:wikitext(t) |
|||
after or '' |
|||
item:wikitext(']' .. s) |
|||
⚫ | |||
end |
end |
||
Line 25: | Line 24: | ||
wrappers = 'Template:Search' |
wrappers = 'Template:Search' |
||
}) |
}) |
||
local ss = args[1] or 'example phrase' |
|||
local |
local search_phrase_encoded = urlencode(args[1] or 'example phrase') |
||
local short_module_args = { |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
local long_module_args = { |
|||
class = 'template-search plainlinks', |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
local long = (args.long or '') ~= '' |
local long = (args.long or '') ~= '' |
||
local ubl = require('Module:List').unbulleted |
|||
⚫ | |||
local list = ubl(long and long_module_args or short_module_args) |
|||
local ret = mw.html.create('div') |
|||
⚫ | |||
:addClass('plainlist') |
|||
:addClass('plainlinks') |
|||
ll = ret:tag('ul') |
|||
⚫ | |||
if long then |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
else |
|||
⚫ | |||
⚫ | |||
⚫ | |||
end |
|||
⚫ | |||
return frame:extensionTag{ |
return frame:extensionTag{ |
||
name = 'templatestyles', args = { src = 'Module:Search/styles.css' } |
name = 'templatestyles', args = { src = 'Module:Search/sandbox/styles.css' } |
||
} .. |
} .. '(' .. list .. ')' |
||
end |
end |
||
Revision as of 06:17, 9 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 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 make_link(url, expansion, display_text, after)
return mw.ustring.format(
'[%s <abbr title="%s">%s</abbr>]%s',
url,
expansion,
display_text,
after or ''
)
end
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {
wrappers = 'Template:Search'
})
local search_phrase_encoded = urlencode(args[1] or 'example phrase')
local short_module_args = {
class = 'template-search plainlinks',
make_link('//en.wikipedia.org/w/index.php?title=Special:Search&search=' .. search_phrase_encoded, 'Wikipedia', 'wp'),
make_link('https://www.google.com/search?q=' .. search_phrase_encoded, 'Google', 'g'),
make_link('https://www.bing.com/search?q=' .. search_phrase_encoded, 'Bing', 'b'),
}
local long_module_args = {
class = 'template-search plainlinks',
make_link('//en.wikipedia.org/w/index.php?title=Special:Search&search=' .. search_phrase_encoded, 'Wikipedia', 'wp'),
make_link('https://www.google.com/search?q=site%3Awikipedia.org+' .. search_phrase_encoded, 'Wikipedia over Google', 'gwp'),
make_link('https://www.google.com/search?q=' .. search_phrase_encoded, 'Google', 'g'),
make_link('https://www.bing.com/search?q=site%3Awikipedia.org+' .. search_phrase_encoded, 'Wikipedia over Bing', 'bwp'),
make_link('https://www.bing.com/search?q=' .. search_phrase_encoded, 'Bing', 'b', 'template-search-long-middle', ' |'),
make_link('https://www.britannica.com/search?nop&query=' .. search_phrase_encoded, 'Encyclopaedia Britannica', 'eb'),
make_link('https://www.bartleby.com/cgi-bin/texis/webinator/65search?query=' .. search_phrase_encoded, 'Columbia Encyclopedia', 'co'),
make_link('https://www.google.com/search?q=site%3Ahttp%3A%2F%2Fwww.pcmag.com%2Fencyclopedia_term%2F+' .. search_phrase_encoded, 'PC Magazine Encyclopedia over Google', 'gct'),
make_link('https://scienceworld.wolfram.com/search/index.cgi?as_q=' .. search_phrase_encoded, 'World of Science', 'sw'),
make_link('https://archive.org/search.php?query=' .. search_phrase_encoded, 'Internet Archive', 'arc'),
make_link('https://babel.hathitrust.org/cgi/ls?field1=ocr;q1=' .. search_phrase_encoded .. ';a=srchls;lmt=ft', 'HathiTrust', 'ht'),
}
local long = (args.long or '') ~= ''
local ubl = require('Module:List').unbulleted
local list = ubl(long and long_module_args or short_module_args)
return frame:extensionTag{
name = 'templatestyles', args = { src = 'Module:Search/sandbox/styles.css' }
} .. '(' .. list .. ')'
end
return p