JasonHK留言 | 贡献
导入1个版本
第12行: 第12行:
,page_head='<span class="ilh-page">'
,page_head='<span class="ilh-page">'
,page_tail=COMMON_TAIL
,page_tail=COMMON_TAIL
,comment_head='<span class="noprint ilh-comment">('
,comment_head='<span class="noprint ilh-comment"><span class="ilh-paren">('..COMMON_TAIL
,comment_tail=')'..COMMON_TAIL
,comment_tail='<span class="ilh-paren">)'..COMMON_TAIL..COMMON_TAIL
,lang_head='<span class="ilh-lang">'
,lang_head='<span class="ilh-lang">'
,lang_tail=COMMON_TAIL
,lang_tail=COMMON_TAIL
第29行: 第29行:
end
end
local args = getArgs(frame)
local args = getArgs(frame)
-- 使用{{#ifexist}}而不是Lua的exists来兼容MediaWiki的自动简繁重定向
-- 见[[Special:PermaLink/85517269#不蓝不绿的绿链问题]]
local existsFunc = function (pageName)
return frame:callParserFunction('#ifexist',{pageName,'true','false'})
end
if langData[args['lang-code']] == nil then
if langData[args['lang-code']] == nil then
第40行: 第45行:
end
end


return ilh._ilh(args)
return ilh._ilh(args,existsFunc)
end
end


function ilh._ilh(args)
function ilh._ilh(args,existsFunc)
--frameArgs = getArgs(frame, {frameOnly=true})
--frameArgs = getArgs(frame, {frameOnly=true})


第55行: 第60行:
context["nocat"]=yesno( args["nocat"] , false )
context["nocat"]=yesno( args["nocat"] , false )


context["isExist"]= (args["$exist$"] and args["$exist$"]==1) or ilh.isExist(context["localPage"])
context["isExist"]= (args["$exist$"] and args["$exist$"]==1) or (existsFunc(context["localPage"])=='true')
local curPage_obj=mw.title.getCurrentTitle()
local curPage_obj=mw.title.getCurrentTitle()
第148行: 第153行:
return mw.title.equals(mainPage_obj,curpage_obj) --and curpage_obj.namespace==4
return mw.title.equals(mainPage_obj,curpage_obj) --and curpage_obj.namespace==4
end
end
--确定页面存在
---exists是高开销方法,需要更高效的实现
--带保护的包装方法
--由于exists和解析器函数ifexist都是高开销方法
--而ifexist达到限制时默认返回结果为false的操作
--而exists会直接抛出错误而中断执行
--所以将相应调用包裹,压制exists的抛错,按照ifexist的理念,返回false
--正常情况下则一切正常
function ilh.isExist(pageName)
local execStatus,result=pcall(ilh._isExist,pageName)
if execStatus then
return result
else
return false
end
end
--真实方法
function ilh._isExist(pageName)
local localPage_obj=mw.title.makeTitle(0,pageName)
return localPage_obj.exists
end
--end


return ilh
return ilh