Merge pull request #818 from chrox/master

enable Wikipedia support
pull/823/head
Qingping Hou 10 years ago
commit 63b6d25f72

@ -12,6 +12,7 @@ local ReaderDictionary = EventListener:new{}
function ReaderDictionary:onLookupWord(word, box, highlight) function ReaderDictionary:onLookupWord(word, box, highlight)
self.highlight = highlight self.highlight = highlight
self:stardictLookup(word, box) self:stardictLookup(word, box)
return true
end end
function ReaderDictionary:stardictLookup(word, box) function ReaderDictionary:stardictLookup(word, box)
@ -29,7 +30,7 @@ function ReaderDictionary:stardictLookup(word, box)
local ok, results = pcall(JSON.decode, JSON, results_str) local ok, results = pcall(JSON.decode, JSON, results_str)
if ok and results then if ok and results then
DEBUG("lookup result table:", word, results) DEBUG("lookup result table:", word, results)
self:showDict(results, box) self:showDict(word, results, box)
else else
-- dummy results -- dummy results
results = { results = {
@ -40,41 +41,26 @@ function ReaderDictionary:stardictLookup(word, box)
} }
} }
DEBUG("dummy result table:", word, results) DEBUG("dummy result table:", word, results)
self:showDict(results, box) self:showDict(word, results, box)
end end
end end
end end
function ReaderDictionary:showDict(results, box) function ReaderDictionary:showDict(word, results, box)
if results and results[1] then if results and results[1] then
DEBUG("showing quick lookup dictionary window") DEBUG("showing quick lookup window")
local align = "center"
local region = Geom:new{
x = 0, y = 0,
w = Screen:getWidth(),
h = Screen:getHeight(),
}
if box then
if box.y + box.h/2 < Screen:getHeight()/2 then
region.y = box.y + box.h
region.h = Screen:getHeight() - box.y - box.h
align = "top"
else
region.y = 0
region.h = box.y
align = "bottom"
end
end
UIManager:show(DictQuickLookup:new{ UIManager:show(DictQuickLookup:new{
ui = self.ui, ui = self.ui,
highlight = self.highlight, highlight = self.highlight,
dialog = self.dialog, dialog = self.dialog,
-- original lookup word
word = word,
results = results, results = results,
dictionary = self.default_dictionary, dictionary = self.default_dictionary,
width = Screen:getWidth() - Screen:scaleByDPI(80), width = Screen:getWidth() - Screen:scaleByDPI(80),
height = math.min(region.h*0.7, Screen:getHeight()*0.5), word_box = box,
region = region, -- differentiate between dict and wiki
align = align, wiki = self.wiki,
}) })
end end
end end
@ -82,6 +68,7 @@ end
function ReaderDictionary:onUpdateDefaultDict(dict) function ReaderDictionary:onUpdateDefaultDict(dict)
DEBUG("make default dictionary:", dict) DEBUG("make default dictionary:", dict)
self.default_dictionary = dict self.default_dictionary = dict
return true
end end
function ReaderDictionary:onReadSettings(config) function ReaderDictionary:onReadSettings(config)

@ -294,8 +294,7 @@ function ReaderHighlight:onHoldRelease()
text = _("Highlight"), text = _("Highlight"),
callback = function() callback = function()
self:saveHighlight() self:saveHighlight()
UIManager:close(self.highlight_dialog) self:onClose()
self:handleEvent(Event:new("Tap"))
end, end,
}, },
{ {
@ -303,39 +302,43 @@ function ReaderHighlight:onHoldRelease()
enabled = false, enabled = false,
callback = function() callback = function()
self:addNote() self:addNote()
UIManager:close(self.highlight_dialog) self:onClose()
self:handleEvent(Event:new("Tap"))
end, end,
}, },
}, },
{ {
{
text = _("Wikipedia"),
callback = function()
UIManager:scheduleIn(0.1, function()
self:lookupWikipedia()
end)
end,
},
{ {
text = _("Translate"), text = _("Translate"),
enabled = false, enabled = false,
callback = function() callback = function()
self:translate(self.selected_text) self:translate(self.selected_text)
UIManager:close(self.highlight_dialog) self:onClose()
self:handleEvent(Event:new("Tap"))
end, end,
}, },
},
{
{ {
text = _("Share"), text = _("Share"),
enabled = false, enabled = false,
callback = function() callback = function()
self:shareHighlight() self:shareHighlight()
UIManager:close(self.highlight_dialog) self:onClose()
self:handleEvent(Event:new("Tap"))
end, end,
}, },
},
{
{ {
text = _("More"), text = _("More"),
enabled = false, enabled = false,
callback = function() callback = function()
self:moreAction() self:moreAction()
UIManager:close(self.highlight_dialog) self:onClose()
self:handleEvent(Event:new("Tap"))
end, end,
}, },
}, },
@ -411,6 +414,12 @@ function ReaderHighlight:addNote()
DEBUG("add Note") DEBUG("add Note")
end end
function ReaderHighlight:lookupWikipedia()
if self.selected_text then
self.ui:handleEvent(Event:new("LookupWikipedia", self.selected_text.text))
end
end
function ReaderHighlight:shareHighlight() function ReaderHighlight:shareHighlight()
DEBUG("share highlight") DEBUG("share highlight")
end end
@ -436,4 +445,10 @@ function ReaderHighlight:onSaveSettings()
self.ui.doc_settings:saveSetting("highlight_drawer", self.view.highlight.saved_drawer) self.ui.doc_settings:saveSetting("highlight_drawer", self.view.highlight.saved_drawer)
end end
function ReaderHighlight:onClose()
UIManager:close(self.highlight_dialog)
-- clear highlighted text
self:handleEvent(Event:new("Tap"))
end
return ReaderHighlight return ReaderHighlight

@ -0,0 +1,63 @@
local ReaderDictionary = require("apps/reader/modules/readerdictionary")
local EventListener = require("ui/widget/eventlistener")
local NetworkMgr = require("ui/networkmgr")
local Translator = require("ui/translator")
local Wikipedia = require("ui/wikipedia")
local UIManager = require("ui/uimanager")
local Geom = require("ui/geometry")
local Screen = require("ui/screen")
local JSON = require("JSON")
local DEBUG = require("dbg")
local _ = require("gettext")
-- Wikipedia as a special dictionary
local ReaderWikipedia = ReaderDictionary:new{
-- identify itself
wiki = true,
no_page = _("No wiki page found."),
}
function ReaderWikipedia:onLookupWikipedia(word, box)
-- detect language of the text
local ok, lang = pcall(Translator.detect, Translator, word)
-- prompt users to turn on Wifi if network is unreachable
if not ok and lang and lang:find("Network is unreachable") then
NetworkMgr:promptWifiOn()
return
end
-- convert "zh-CN" and "zh-TW" to "zh"
lang = lang:match("(.*)-") or lang
-- strip punctuation characters around selected word
word = string.gsub(word, "^%p+", '')
word = string.gsub(word, "%p+$", '')
-- seems lower case phrase has higher hit rate
word = string.lower(word)
local results = {}
local ok, pages = pcall(Wikipedia.wikintro, Wikipedia, word, lang)
if ok and pages then
for pageid, page in pairs(pages) do
local result = {
dict = _("Wikipedia"),
word = page.title,
definition = page.extract or self.no_page,
}
table.insert(results, result)
end
DEBUG("lookup result:", word, results)
self:showDict(word, results, box)
else
DEBUG("error:", pages)
-- dummy results
results = {
{
dict = _("Wikipedia"),
word = word,
definition = self.no_page,
}
}
DEBUG("dummy result table:", word, results)
self:showDict(word, results, box)
end
end
return ReaderWikipedia

@ -29,6 +29,7 @@ local ReaderHighlight = require("apps/reader/modules/readerhighlight")
local ReaderScreenshot = require("apps/reader/modules/readerscreenshot") local ReaderScreenshot = require("apps/reader/modules/readerscreenshot")
local ReaderFrontLight = require("apps/reader/modules/readerfrontlight") local ReaderFrontLight = require("apps/reader/modules/readerfrontlight")
local ReaderDictionary = require("apps/reader/modules/readerdictionary") local ReaderDictionary = require("apps/reader/modules/readerdictionary")
local ReaderWikipedia = require("apps/reader/modules/readerwikipedia")
local ReaderHyphenation = require("apps/reader/modules/readerhyphenation") local ReaderHyphenation = require("apps/reader/modules/readerhyphenation")
local ReaderActivityIndicator = require("apps/reader/modules/readeractivityindicator") local ReaderActivityIndicator = require("apps/reader/modules/readeractivityindicator")
local ReaderLink = require("apps/reader/modules/readerlink") local ReaderLink = require("apps/reader/modules/readerlink")
@ -142,6 +143,13 @@ function ReaderUI:init()
ui = self, ui = self,
document = self.document, document = self.document,
}) })
-- wikipedia
table.insert(self, ReaderWikipedia:new{
dialog = self.dialog,
view = self[1],
ui = self,
document = self.document,
})
-- screenshot controller -- screenshot controller
table.insert(self.active_widgets, ReaderScreenshot:new{ table.insert(self.active_widgets, ReaderScreenshot:new{
dialog = self.dialog, dialog = self.dialog,

@ -171,10 +171,6 @@ function Screen:scaleByDPI(px)
return math.ceil(px * self:getDPI()/167) return math.ceil(px * self:getDPI()/167)
end end
function Screen:rescaleByDPI(px)
return math.ceil(px * 167/self:getDPI())
end
function Screen:getRotationMode() function Screen:getRotationMode()
return self.cur_rotation_mode return self.cur_rotation_mode
end end

@ -54,6 +54,8 @@ function Font:getFace(font, size)
font = self.cfont font = self.cfont
end end
-- original size before scaling by screen DPI
local orig_size = size
local size = Screen:scaleByDPI(size) local size = Screen:scaleByDPI(size)
local face = self.faces[font..size] local face = self.faces[font..size]
@ -72,7 +74,7 @@ function Font:getFace(font, size)
self.faces[font..size] = face self.faces[font..size] = face
--DEBUG("getFace, found: "..realname.." size:"..size) --DEBUG("getFace, found: "..realname.." size:"..size)
end end
return { size = size, ftface = face, hash = font..size } return { size = size, orig_size = orig_size, ftface = face, hash = font..size }
end end
function Font:_readList(target, dir, effective_dir) function Font:_readList(target, dir, effective_dir)

@ -19,20 +19,20 @@ local function kindleEnableWifi(toggle)
end end
local function koboEnableWifi(toggle) local function koboEnableWifi(toggle)
if toggle == 1 if toggle == 1 then
local path = "/etc/wpa_supplicant/wpa_supplicant.conf" local path = "/etc/wpa_supplicant/wpa_supplicant.conf"
os.execute("insmod /drivers/ntx508/wifi/sdio_wifi_pwr.ko 2>/dev/null") os.execute("insmod /drivers/ntx508/wifi/sdio_wifi_pwr.ko 2>/dev/null")
os.execute("insmod /drivers/ntx508/wifi/dhd.ko") os.execute("insmod /drivers/ntx508/wifi/dhd.ko")
os.execute("ifconfig eth0 up") os.execute("ifconfig eth0 up")
os.execute("wlarm_le -i eth0 up") os.execute("wlarm_le -i eth0 up")
os.execute("wpa_supplicant -s -i eth0 -c "..path.." -C /var/run/wpa_supplicant -B") os.execute("wpa_supplicant -s -i eth0 -c "..path.." -C /var/run/wpa_supplicant -B")
os.execute("udhcpc -S -i eth0 -s /etc/udhcpc.d/default.script -t15 -T10 -A3 -b -q >/dev/null 2>&1") os.execute("udhcpc -S -i eth0 -s /etc/udhcpc.d/default.script -t15 -T10 -A3 -b -q >/dev/null 2>&1")
else else
os.execute("killall udhcpc wpa_supplicant 2>/dev/null") os.execute("killall udhcpc wpa_supplicant 2>/dev/null")
os.execute("wlarm_le -i eth0 down") os.execute("wlarm_le -i eth0 down")
os.execute("ifconfig eth0 down") os.execute("ifconfig eth0 down")
os.execute("rmmod -r dhd") os.execute("rmmod -r dhd")
os.execute("rmmod -r sdio_wifi_pwr") os.execute("rmmod -r sdio_wifi_pwr")
end end
end end

@ -1,5 +1,6 @@
local InfoMessage = require("ui/widget/infomessage") local InfoMessage = require("ui/widget/infomessage")
local ConfirmBox = require("ui/widget/confirmbox") local ConfirmBox = require("ui/widget/confirmbox")
local NetworkMgr = require("ui/networkmgr")
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
local Device = require("ui/device") local Device = require("ui/device")
local DEBUG = require("dbg") local DEBUG = require("dbg")
@ -63,8 +64,13 @@ function OTAManager:checkUpdate()
local r, c, h = http.request{ local r, c, h = http.request{
url = ota_zsync_file, url = ota_zsync_file,
sink = ltn12.sink.file(io.open(local_zsync_file, "w"))} sink = ltn12.sink.file(io.open(local_zsync_file, "w"))}
-- parse OTA package version -- prompt users to turn on Wifi if network is unreachable
if h == nil then
NetworkMgr:promptWifiOn()
return
end
if c ~= 200 then return end if c ~= 200 then return end
-- parse OTA package version
local ota_package = nil local ota_package = nil
local zsync = io.open(local_zsync_file, "r") local zsync = io.open(local_zsync_file, "r")
if zsync then if zsync then

@ -73,8 +73,8 @@ function RenderText:getGlyph(face, charcode, bold, bgcolor, fgcolor)
local rendered_glyph = face.ftface:renderGlyph(charcode, bgcolor, fgcolor, bold) local rendered_glyph = face.ftface:renderGlyph(charcode, bgcolor, fgcolor, bold)
if face.ftface:checkGlyph(charcode) == 0 then if face.ftface:checkGlyph(charcode) == 0 then
for index, font in pairs(Font.fallbacks) do for index, font in pairs(Font.fallbacks) do
-- rescale face size by DPI since it will be scaled in getFace again -- use original size before scaling by screen DPI
local fb_face = Font:getFace(font, Screen:rescaleByDPI(face.size)) local fb_face = Font:getFace(font, face.orig_size)
if fb_face.ftface:checkGlyph(charcode) ~= 0 then if fb_face.ftface:checkGlyph(charcode) ~= 0 then
rendered_glyph = fb_face.ftface:renderGlyph(charcode, bgcolor, fgcolor, bold) rendered_glyph = fb_face.ftface:renderGlyph(charcode, bgcolor, fgcolor, bold)
--DEBUG("fallback to font", font) --DEBUG("fallback to font", font)

@ -0,0 +1,87 @@
local socket = require('socket')
local url = require('socket.url')
local http = require('socket.http')
local https = require('ssl.https')
local ltn12 = require('ltn12')
local JSON = require("JSON")
local DEBUG = require("dbg")
--[[
-- Translate text using Google Translate.
-- http://translate.google.com/translate_a/t?client=z&ie=UTF-8&oe=UTF-8&hl=en&tl=en&text=hello
--]]
local Translator = {
trans_servers = {
"http://translate.google.cn",
"http://translate.google.com",
},
trans_path = "/translate_a/t",
trans_params = {
client = "z", -- client z returns normal JSON result
ie = "UTF-8",
oe = "UTF-8",
hl = "en",
tl = "en",
sl = nil, -- we don't specify source languagae to detect language
},
default_lang = "en",
}
function Translator:getTransServer()
return G_reader_settings:readSetting("trans_server") or self.trans_servers[1]
end
--[[
-- return decoded JSON table from translate server
--]]
function Translator:loadPage(target_lang, source_lang, text)
local request, sink = {}, {}
local query = ""
self.trans_params.tl = target_lang
self.trans_params.sl = source_lang
for k,v in pairs(self.trans_params) do
query = query .. k .. '=' .. v .. '&'
end
local parsed = url.parse(self:getTransServer())
parsed.path = self.trans_path
parsed.query = query .. "text=" .. url.escape(text)
-- HTTP request
request['url'] = url.build(parsed)
request['method'] = 'GET'
request['sink'] = ltn12.sink.table(sink)
DEBUG("request", request)
http.TIMEOUT, https.TIMEOUT = 10, 10
local httpRequest = parsed.scheme == 'http' and http.request or https.request
local code, headers, status = socket.skip(1, httpRequest(request))
-- raise error message when network is unavailable
if headers == nil then
error("Network is unreachable")
end
local content = table.concat(sink)
if content ~= "" then
local ok, result = pcall(JSON.decode, JSON, content)
if ok and result then
--DEBUG("translate result", result)
return result
else
DEBUG("error:", result)
end
end
end
function Translator:detect(text)
local result = self:loadPage("en", nil, text)
if result then
local src_lang = result.src
DEBUG("detected language:", src_lang)
return src_lang
else
return self.default_lang
end
end
return Translator

@ -249,7 +249,9 @@ function UIManager:setDirty(widget, refresh_type)
if not refresh_type then if not refresh_type then
refresh_type = "auto" refresh_type = "auto"
end end
self._dirty[widget] = refresh_type if widget then
self._dirty[widget] = refresh_type
end
end end
function UIManager:insertZMQ(zeromq) function UIManager:insertZMQ(zeromq)

@ -147,7 +147,7 @@ function Button:showHide(show)
end end
function Button:onTapSelect() function Button:onTapSelect()
if self.enabled then if self.enabled and self.callback then
self[1].invert = true self[1].invert = true
UIManager:setDirty(self.show_parent, "partial") UIManager:setDirty(self.show_parent, "partial")
UIManager:scheduleIn(0.1, function() UIManager:scheduleIn(0.1, function()

@ -37,6 +37,8 @@ local DictQuickLookup = InputContainer:new{
content_face = Font:getFace("cfont", DDICT_FONT_SIZE), content_face = Font:getFace("cfont", DDICT_FONT_SIZE),
width = nil, width = nil,
height = nil, height = nil,
-- box of highlighted word, quick lookup window tries to not hide the word
word_box = nil,
title_padding = Screen:scaleByDPI(5), title_padding = Screen:scaleByDPI(5),
title_margin = Screen:scaleByDPI(2), title_margin = Screen:scaleByDPI(2),
@ -85,6 +87,26 @@ function DictQuickLookup:init()
end end
function DictQuickLookup:update() function DictQuickLookup:update()
-- calculate window dimension and try to not hide highlighted word
self.align = "center"
self.region = Geom:new{
x = 0, y = 0,
w = Screen:getWidth(),
h = Screen:getHeight(),
}
if self.word_box then
local box = self.word_box
if box.y + box.h/2 < Screen:getHeight()/2 then
self.region.y = box.y + box.h
self.region.h = Screen:getHeight() - box.y - box.h
self.align = "top"
else
self.region.y = 0
self.region.h = box.y
self.align = "bottom"
end
end
self.height = math.min(self.region.h*0.7, Screen:getHeight()*0.5)
-- dictionary title -- dictionary title
self.dict_title = FrameContainer:new{ self.dict_title = FrameContainer:new{
padding = self.title_padding, padding = self.title_padding,
@ -150,9 +172,10 @@ function DictQuickLookup:update()
{ {
{ {
text = _("Wikipedia"), text = _("Wikipedia"),
enabled = false,
callback = function() callback = function()
self.ui:handleEvent(Event:new("HighlightWiki")) UIManager:scheduleIn(0.1, function()
self:lookupWikipedia()
end)
end, end,
}, },
{ {
@ -225,7 +248,7 @@ function DictQuickLookup:update()
} }
self[1] = WidgetContainer:new{ self[1] = WidgetContainer:new{
align = self.align, align = self.align,
dimen = self.region:copy(), dimen = self.region,
FrameContainer:new{ FrameContainer:new{
bordersize = 0, bordersize = 0,
padding = Screen:scaleByDPI(5), padding = Screen:scaleByDPI(5),
@ -336,6 +359,7 @@ function DictQuickLookup:lookupInputWord(hint)
self:onClose() self:onClose()
self.input_dialog = InputDialog:new{ self.input_dialog = InputDialog:new{
title = _("Input lookup word"), title = _("Input lookup word"),
input = hint,
input_hint = hint or "", input_hint = hint or "",
input_type = "text", input_type = "text",
buttons = { buttons = {
@ -369,7 +393,8 @@ end
function DictQuickLookup:inputLookup() function DictQuickLookup:inputLookup()
local word = self.input_dialog:getInputText() local word = self.input_dialog:getInputText()
if word and word ~= "" then if word and word ~= "" then
self.ui:handleEvent(Event:new("LookupWord", word)) local event = self.wiki and "LookupWikipedia" or "LookupWord"
self.ui:handleEvent(Event:new(event, word))
end end
end end
@ -378,4 +403,8 @@ function DictQuickLookup:closeInputDialog()
UIManager:close(self.input_dialog) UIManager:close(self.input_dialog)
end end
function DictQuickLookup:lookupWikipedia()
self.ui:handleEvent(Event:new("LookupWikipedia", self.word, self.word_box))
end
return DictQuickLookup return DictQuickLookup

@ -151,6 +151,12 @@ function InputText:delChar()
UIManager:setDirty(self.parent, "partial") UIManager:setDirty(self.parent, "partial")
end end
function InputText:clear()
self.text = ""
self:initTextBox()
UIManager:setDirty(self.parent, "partial")
end
function InputText:getText() function InputText:getText()
return self.text return self.text
end end

@ -41,6 +41,7 @@ function VirtualKey:init()
self.callback = function () self.keyboard:setLayout(self.key or self.label) end self.callback = function () self.keyboard:setLayout(self.key or self.label) end
elseif self.label == "Backspace" then elseif self.label == "Backspace" then
self.callback = function () self.keyboard:delChar() end self.callback = function () self.keyboard:delChar() end
self.hold_callback = function () self.keyboard:clear() end
else else
self.callback = function () self.keyboard:addChar(self.key) end self.callback = function () self.keyboard:addChar(self.key) end
end end
@ -83,6 +84,12 @@ function VirtualKey:init()
range = self.dimen, range = self.dimen,
}, },
}, },
HoldSelect = {
GestureRange:new{
ges = "hold",
range = self.dimen,
},
},
} }
end end
end end
@ -96,6 +103,15 @@ function VirtualKey:onTapSelect()
return true return true
end end
function VirtualKey:onHoldSelect()
self[1].invert = true
if self.hold_callback then
self.hold_callback()
end
UIManager:scheduleIn(0.5, function() self:invert(false) end)
return true
end
function VirtualKey:invert(invert) function VirtualKey:invert(invert)
self[1].invert = invert self[1].invert = invert
UIManager:setDirty(self.keyboard, "partial") UIManager:setDirty(self.keyboard, "partial")
@ -191,7 +207,7 @@ function VirtualKeyboard:init()
for i = 1, string.len(GLOBAL_INPUT_VALUE) do for i = 1, string.len(GLOBAL_INPUT_VALUE) do
self:addChar(string.sub(GLOBAL_INPUT_VALUE,i,i)) self:addChar(string.sub(GLOBAL_INPUT_VALUE,i,i))
end end
end end
end end
function VirtualKeyboard:initLayout(layout) function VirtualKeyboard:initLayout(layout)
@ -303,4 +319,11 @@ function VirtualKeyboard:delChar()
UIManager:setDirty(self.inputbox, "partial") UIManager:setDirty(self.inputbox, "partial")
end end
function VirtualKeyboard:clear()
DEBUG("clear input")
self.inputbox:clear()
UIManager:setDirty(self, "partial")
UIManager:setDirty(self.inputbox, "partial")
end
return VirtualKeyboard return VirtualKeyboard

@ -0,0 +1,84 @@
local socket = require('socket')
local url = require('socket.url')
local http = require('socket.http')
local https = require('ssl.https')
local ltn12 = require('ltn12')
local JSON = require("JSON")
local DEBUG = require("dbg")
--[[
-- Query wikipedia using Wikimedia Web API.
-- http://en.wikipedia.org/w/api.php?action=query&prop=extracts&format=json&exintro=&explaintext=&redirects=&titles=hello
--]]
local Wikipedia = {
wiki_server = "http://%s.wikipedia.org",
wiki_path = "/w/api.php",
wiki_params = {
action = "query",
prop = "extracts",
format = "json",
exintro = "",
explaintext = "",
redirects = "",
},
default_lang = "en",
}
function Wikipedia:getWikiServer(lang)
return string.format(self.wiki_server, lang or self.default_lang)
end
--[[
-- return decoded JSON table from Wikipedia
--]]
function Wikipedia:loadPage(text, lang, intro, plain)
local request, sink = {}, {}
local query = ""
self.wiki_params.exintro = intro and "" or nil
self.wiki_params.explaintext = plain and "" or nil
for k,v in pairs(self.wiki_params) do
query = query .. k .. '=' .. v .. '&'
end
local parsed = url.parse(self:getWikiServer(lang))
parsed.path = self.wiki_path
parsed.query = query .. "titles=" .. url.escape(text)
-- HTTP request
request['url'] = url.build(parsed)
request['method'] = 'GET'
request['sink'] = ltn12.sink.table(sink)
DEBUG("request", request)
http.TIMEOUT, https.TIMEOUT = 10, 10
local httpRequest = parsed.scheme == 'http' and http.request or https.request
local code, headers, status = socket.skip(1, httpRequest(request))
-- raise error message when network is unavailable
if headers == nil then
error("Network is unreachable")
end
local content = table.concat(sink)
if content ~= "" then
local ok, result = pcall(JSON.decode, JSON, content)
if ok and result then
DEBUG("wiki result", result)
return result
else
DEBUG("error:", result)
end
end
end
-- extract intro passage in wiki page
function Wikipedia:wikintro(text, lang)
local result = self:loadPage(text, lang, true, true)
if result then
local query = result.query
if query then
return query.pages
end
end
end
return Wikipedia

@ -1 +1 @@
Subproject commit 48e46a9b01eb31888cb818b3f402045025f05069 Subproject commit 1075c61f74888d0ab291c8a3d0ed55d9dde8457b

@ -6,7 +6,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: https://github.com/koreader/koreader-base/issues\n" "Report-Msgid-Bugs-To: https://github.com/koreader/koreader-base/issues\n"
"POT-Creation-Date: 2014-08-19 08:01+0000\n" "POT-Creation-Date: 2014-08-20 07:18+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
@ -17,24 +17,14 @@ msgid ""
" does not exist" " does not exist"
msgstr "" msgstr ""
#: frontend/apps/filemanager/filemanagersearch.lua:435
msgid ""
" found"
msgstr ""
#: frontend/apps/filemanager/filemanagersearch.lua:437
msgid ""
" matching "
msgstr ""
#: plugins/evernote.koplugin/main.lua:334 #: plugins/evernote.koplugin/main.lua:334
msgid "" msgid ""
" others." " others."
msgstr "" msgstr ""
#: frontend/ui/uimanager.lua:516 #: frontend/ui/uimanager.lua:518
#: frontend/ui/uimanager.lua:522 #: frontend/ui/uimanager.lua:524
#: frontend/ui/uimanager.lua:528 #: frontend/ui/uimanager.lua:530
msgid "" msgid ""
" pages" " pages"
msgstr "" msgstr ""
@ -59,8 +49,8 @@ msgid ""
"5 deg" "5 deg"
msgstr "" msgstr ""
#: frontend/apps/reader/modules/readerhighlight.lua:302 #: frontend/apps/reader/modules/readerhighlight.lua:301
#: frontend/ui/widget/dictquicklookup.lua:159 #: frontend/ui/widget/dictquicklookup.lua:183
msgid "" msgid ""
"Add Note" "Add Note"
msgstr "" msgstr ""
@ -70,19 +60,19 @@ msgid ""
"Apply" "Apply"
msgstr "" msgstr ""
#: frontend/apps/filemanager/filemanagersetdefaults.lua:249 #: frontend/apps/filemanager/filemanagersetdefaults.lua:267
msgid "" msgid ""
"Are you sure to save the settings to \"defaults.persistent.lua\"?" "Are you sure to save the settings to \"defaults.persistent.lua\"?"
msgstr "" msgstr ""
#: frontend/apps/filemanager/filemanagersearch.lua:483 #: frontend/apps/filemanager/filemanagersearch.lua:569
#: frontend/apps/filemanager/filemanagersearch.lua:584 #: frontend/apps/filemanager/filemanagersearch.lua:670
msgid "" msgid ""
"Author(s): " "Author(s):"
msgstr "" msgstr ""
#: frontend/apps/reader/modules/readertypeset.lua:66 #: frontend/apps/reader/modules/readertypeset.lua:66
#: frontend/ui/device/screen.lua:262 #: frontend/ui/device/screen.lua:258
msgid "" msgid ""
"Auto" "Auto"
msgstr "" msgstr ""
@ -98,27 +88,27 @@ msgid ""
"Bookmarks" "Bookmarks"
msgstr "" msgstr ""
#: frontend/apps/filemanager/filemanagersearch.lua:620 #: frontend/apps/filemanager/filemanagersearch.lua:706
msgid "" msgid ""
"Browse " "Browse"
msgstr "" msgstr ""
#: frontend/apps/filemanager/filemanagersearch.lua:195 #: frontend/apps/filemanager/filemanagersearch.lua:209
msgid "" msgid ""
"Browse series" "Browse series"
msgstr "" msgstr ""
#: frontend/apps/filemanager/filemanagersearch.lua:209 #: frontend/apps/filemanager/filemanagersearch.lua:223
msgid "" msgid ""
"Browse tags" "Browse tags"
msgstr "" msgstr ""
#: frontend/apps/filemanager/filemanagersearch.lua:225 #: frontend/apps/filemanager/filemanagersearch.lua:239
#: frontend/apps/filemanager/filemanagersetdefaults.lua:134 #: frontend/apps/filemanager/filemanagersetdefaults.lua:125
#: frontend/apps/filemanager/filemanagersetdefaults.lua:192 #: frontend/apps/filemanager/filemanagersetdefaults.lua:183
#: frontend/apps/reader/modules/readergoto.lua:36 #: frontend/apps/reader/modules/readergoto.lua:36
#: frontend/ui/widget/confirmbox.lua:29 #: frontend/ui/widget/confirmbox.lua:29
#: frontend/ui/widget/dictquicklookup.lua:344 #: frontend/ui/widget/dictquicklookup.lua:369
#: frontend/ui/widget/touchmenu.lua:547 #: frontend/ui/widget/touchmenu.lua:547
#: plugins/evernote.koplugin/main.lua:124 #: plugins/evernote.koplugin/main.lua:124
#: plugins/zsync.koplugin/main.lua:274 #: plugins/zsync.koplugin/main.lua:274
@ -167,14 +157,14 @@ msgid ""
"Copy" "Copy"
msgstr "" msgstr ""
#: frontend/ui/uimanager.lua:516 #: frontend/ui/uimanager.lua:518
#: frontend/ui/uimanager.lua:522 #: frontend/ui/uimanager.lua:524
#: frontend/ui/uimanager.lua:528 #: frontend/ui/uimanager.lua:530
msgid "" msgid ""
"Custom " "Custom "
msgstr "" msgstr ""
#: frontend/ui/device/screen.lua:293 #: frontend/ui/device/screen.lua:289
msgid "" msgid ""
"Custom DPI" "Custom DPI"
msgstr "" msgstr ""
@ -184,7 +174,7 @@ msgid ""
"Cut" "Cut"
msgstr "" msgstr ""
#: frontend/apps/filemanager/filemanagersetdefaults.lua:331 #: frontend/apps/filemanager/filemanagersetdefaults.lua:349
msgid "" msgid ""
"Default settings successfully saved!" "Default settings successfully saved!"
msgstr "" msgstr ""
@ -236,7 +226,7 @@ msgid ""
"Downloading may take several minutes..." "Downloading may take several minutes..."
msgstr "" msgstr ""
#: frontend/ui/uimanager.lua:503 #: frontend/ui/uimanager.lua:505
msgid "" msgid ""
"E-ink full refresh rate" "E-ink full refresh rate"
msgstr "" msgstr ""
@ -272,12 +262,12 @@ msgid ""
"Evernote" "Evernote"
msgstr "" msgstr ""
#: frontend/ui/uimanager.lua:511 #: frontend/ui/uimanager.lua:513
msgid "" msgid ""
"Every 6 pages" "Every 6 pages"
msgstr "" msgstr ""
#: frontend/ui/uimanager.lua:506 #: frontend/ui/uimanager.lua:508
msgid "" msgid ""
"Every page" "Every page"
msgstr "" msgstr ""
@ -323,7 +313,7 @@ msgid ""
"File manager menu" "File manager menu"
msgstr "" msgstr ""
#: frontend/apps/filemanager/filemanagersearch.lua:451 #: frontend/apps/filemanager/filemanagersearch.lua:537
msgid "" msgid ""
"File not found!" "File not found!"
msgstr "" msgstr ""
@ -333,7 +323,7 @@ msgid ""
"FileManager" "FileManager"
msgstr "" msgstr ""
#: frontend/apps/filemanager/filemanagersearch.lua:236 #: frontend/apps/filemanager/filemanagersearch.lua:247
msgid "" msgid ""
"Find books" "Find books"
msgstr "" msgstr ""
@ -405,7 +395,7 @@ msgid ""
msgstr "" msgstr ""
#: frontend/apps/reader/modules/readerhighlight.lua:294 #: frontend/apps/reader/modules/readerhighlight.lua:294
#: frontend/ui/widget/dictquicklookup.lua:137 #: frontend/ui/widget/dictquicklookup.lua:159
msgid "" msgid ""
"Highlight" "Highlight"
msgstr "" msgstr ""
@ -425,17 +415,17 @@ msgid ""
"Indentation" "Indentation"
msgstr "" msgstr ""
#: frontend/ui/widget/dictquicklookup.lua:338 #: frontend/ui/widget/dictquicklookup.lua:362
msgid "" msgid ""
"Input lookup word" "Input lookup word"
msgstr "" msgstr ""
#: frontend/ui/uimanager.lua:492 #: frontend/ui/uimanager.lua:494
msgid "" msgid ""
"Input page number for a full refresh" "Input page number for a full refresh"
msgstr "" msgstr ""
#: frontend/ui/device/screen.lua:300 #: frontend/ui/device/screen.lua:296
msgid "" msgid ""
"Input screen DPI" "Input screen DPI"
msgstr "" msgstr ""
@ -465,7 +455,7 @@ msgid ""
"Language" "Language"
msgstr "" msgstr ""
#: frontend/ui/device/screen.lua:285 #: frontend/ui/device/screen.lua:281
msgid "" msgid ""
"Large" "Large"
msgstr "" msgstr ""
@ -511,18 +501,18 @@ msgid ""
"Logout" "Logout"
msgstr "" msgstr ""
#: frontend/ui/widget/dictquicklookup.lua:350 #: frontend/ui/widget/dictquicklookup.lua:375
msgid "" msgid ""
"Lookup" "Lookup"
msgstr "" msgstr ""
#: frontend/ui/device/screen.lua:277 #: frontend/ui/device/screen.lua:273
msgid "" msgid ""
"Medium" "Medium"
msgstr "" msgstr ""
#: frontend/apps/reader/modules/readerhighlight.lua:333 #: frontend/apps/reader/modules/readerhighlight.lua:338
#: frontend/ui/widget/dictquicklookup.lua:166 #: frontend/ui/widget/dictquicklookup.lua:190
msgid "" msgid ""
"More" "More"
msgstr "" msgstr ""
@ -533,16 +523,19 @@ msgid ""
"Night mode" "Night mode"
msgstr "" msgstr ""
#: frontend/apps/reader/modules/readerdictionary.lua:39 #: frontend/apps/filemanager/filemanagersearch.lua:521
msgid ""
"No"
msgstr ""
#: frontend/apps/reader/modules/readerdictionary.lua:40
msgid "" msgid ""
"No definition found." "No definition found."
msgstr "" msgstr ""
#: frontend/apps/filemanager/filemanagersearch.lua:433 #: frontend/apps/filemanager/filemanagersearch.lua:519
msgid "" msgid ""
"No match for \" .. self.search_value)\n" "No match for"
" else\n"
" dummy = _(\"No "
msgstr "" msgstr ""
#: reader.lua:91 #: reader.lua:91
@ -550,12 +543,17 @@ msgid ""
"No reader engine for this file" "No reader engine for this file"
msgstr "" msgstr ""
#: frontend/apps/reader/modules/readerwikipedia.lua:16
msgid ""
"No wiki page found."
msgstr ""
#: plugins/evernote.koplugin/main.lua:350 #: plugins/evernote.koplugin/main.lua:350
msgid "" msgid ""
"Note: " "Note: "
msgstr "" msgstr ""
#: frontend/apps/filemanager/filemanagersetdefaults.lua:200 #: frontend/apps/filemanager/filemanagersetdefaults.lua:191
#: frontend/apps/reader/modules/readerfrontlight.lua:115 #: frontend/apps/reader/modules/readerfrontlight.lua:115
#: frontend/ui/widget/confirmbox.lua:28 #: frontend/ui/widget/confirmbox.lua:28
#: frontend/ui/widget/touchmenu.lua:553 #: frontend/ui/widget/touchmenu.lua:553
@ -623,8 +621,8 @@ msgid ""
"Paste" "Paste"
msgstr "" msgstr ""
#: frontend/apps/filemanager/filemanagersearch.lua:489 #: frontend/apps/filemanager/filemanagersearch.lua:575
#: frontend/apps/filemanager/filemanagersearch.lua:590 #: frontend/apps/filemanager/filemanagersearch.lua:676
msgid "" msgid ""
"Path: " "Path: "
msgstr "" msgstr ""
@ -676,7 +674,7 @@ msgid ""
"Render Quality" "Render Quality"
msgstr "" msgstr ""
#: frontend/ui/device/screen.lua:259 #: frontend/ui/device/screen.lua:255
msgid "" msgid ""
"Screen DPI" "Screen DPI"
msgstr "" msgstr ""
@ -697,12 +695,12 @@ msgid ""
"Scroll Mode" "Scroll Mode"
msgstr "" msgstr ""
#: frontend/apps/filemanager/filemanagersearch.lua:191 #: frontend/apps/filemanager/filemanagersearch.lua:205
msgid "" msgid ""
"Search Books" "Search Books"
msgstr "" msgstr ""
#: frontend/apps/filemanager/filemanagersearch.lua:510 #: frontend/apps/filemanager/filemanagersearch.lua:596
msgid "" msgid ""
"Search Results" "Search Results"
msgstr "" msgstr ""
@ -712,10 +710,10 @@ msgid ""
"Search books" "Search books"
msgstr "" msgstr ""
#: frontend/apps/filemanager/filemanagersearch.lua:485 #: frontend/apps/filemanager/filemanagersearch.lua:571
#: frontend/apps/filemanager/filemanagersearch.lua:586 #: frontend/apps/filemanager/filemanagersearch.lua:672
msgid "" msgid ""
"Series: " "Series:"
msgstr "" msgstr ""
#: frontend/ui/widget/configdialog.lua:582 #: frontend/ui/widget/configdialog.lua:582
@ -773,7 +771,7 @@ msgid ""
"Settings" "Settings"
msgstr "" msgstr ""
#: frontend/apps/reader/modules/readerhighlight.lua:322 #: frontend/apps/reader/modules/readerhighlight.lua:330
msgid "" msgid ""
"Share" "Share"
msgstr "" msgstr ""
@ -793,16 +791,21 @@ msgid ""
"Show page overlap" "Show page overlap"
msgstr "" msgstr ""
#: frontend/apps/filemanager/filemanagersearch.lua:453 #: frontend/apps/filemanager/filemanagersearch.lua:539
msgid "" msgid ""
"Size: " "Size:"
msgstr "" msgstr ""
#: frontend/ui/device/screen.lua:269 #: frontend/ui/device/screen.lua:265
msgid "" msgid ""
"Small" "Small"
msgstr "" msgstr ""
#: frontend/apps/filemanager/filemanagersetdefaults.lua:78
msgid ""
"Some changes will just work on the next restart. Wrong settings might crash Koreader! Continue?"
msgstr ""
#: frontend/apps/filemanager/filemanagermenu.lua:92 #: frontend/apps/filemanager/filemanagermenu.lua:92
msgid "" msgid ""
"Start with last opened file" "Start with last opened file"
@ -853,10 +856,10 @@ msgid ""
"Table of contents" "Table of contents"
msgstr "" msgstr ""
#: frontend/apps/filemanager/filemanagersearch.lua:484 #: frontend/apps/filemanager/filemanagersearch.lua:570
#: frontend/apps/filemanager/filemanagersearch.lua:585 #: frontend/apps/filemanager/filemanagersearch.lua:671
msgid "" msgid ""
"Tags: " "Tags:"
msgstr "" msgstr ""
#: frontend/ui/data/strings.lua:12 #: frontend/ui/data/strings.lua:12
@ -864,13 +867,13 @@ msgid ""
"Text Align" "Text Align"
msgstr "" msgstr ""
#: frontend/ui/device/screen.lua:254 #: frontend/ui/device/screen.lua:250
msgid "" msgid ""
"This will take effect on next restart." "This will take effect on next restart."
msgstr "" msgstr ""
#: frontend/apps/filemanager/filemanagersearch.lua:482 #: frontend/apps/filemanager/filemanagersearch.lua:568
#: frontend/apps/filemanager/filemanagersearch.lua:583 #: frontend/apps/filemanager/filemanagersearch.lua:669
msgid "" msgid ""
"Title: " "Title: "
msgstr "" msgstr ""
@ -880,7 +883,7 @@ msgid ""
"Toggle" "Toggle"
msgstr "" msgstr ""
#: frontend/apps/reader/modules/readerhighlight.lua:313 #: frontend/apps/reader/modules/readerhighlight.lua:320
msgid "" msgid ""
"Translate" "Translate"
msgstr "" msgstr ""
@ -906,7 +909,10 @@ msgid ""
"View Mode" "View Mode"
msgstr "" msgstr ""
#: frontend/ui/widget/dictquicklookup.lua:152 #: frontend/apps/reader/modules/readerhighlight.lua:311
#: frontend/apps/reader/modules/readerwikipedia.lua:28
#: frontend/apps/reader/modules/readerwikipedia.lua:41
#: frontend/ui/widget/dictquicklookup.lua:174
msgid "" msgid ""
"Wikipedia" "Wikipedia"
msgstr "" msgstr ""
@ -926,17 +932,12 @@ msgid ""
"Writing screen to " "Writing screen to "
msgstr "" msgstr ""
#: frontend/apps/filemanager/filemanagersetdefaults.lua:77
msgid ""
"Wrong settings might crash Koreader! Continue?"
msgstr ""
#: frontend/apps/filemanager/filemanagermenu.lua:40 #: frontend/apps/filemanager/filemanagermenu.lua:40
msgid "" msgid ""
"You have unsaved default settings. Save them now?" "You have unsaved default settings. Save them now?"
msgstr "" msgstr ""
#: frontend/apps/filemanager/filemanagersearch.lua:152 #: frontend/apps/filemanager/filemanagersearch.lua:155
msgid "" msgid ""
"You must specify at least one field to search at! (SEARCH_XXX = true in defaults.lua)" "You must specify at least one field to search at! (SEARCH_XXX = true in defaults.lua)"
msgstr "" msgstr ""
@ -1022,6 +1023,11 @@ msgid ""
"default" "default"
msgstr "" msgstr ""
#: frontend/apps/filemanager/filemanagersearch.lua:521
msgid ""
"found"
msgstr ""
#: frontend/ui/data/strings.lua:62 #: frontend/ui/data/strings.lua:62
msgid "" msgid ""
"full" "full"
@ -1067,6 +1073,11 @@ msgid ""
"manual" "manual"
msgstr "" msgstr ""
#: frontend/apps/filemanager/filemanagersearch.lua:523
msgid ""
"matching"
msgstr ""
#: frontend/ui/data/strings.lua:38 #: frontend/ui/data/strings.lua:38
msgid "" msgid ""
"medium" "medium"

Loading…
Cancel
Save