--The purpose of this module is to take a list of linked page, and use it to determine the next and previous page in the list as well as the total number of pages. local p = function anonymize(name) return mw.ustring.gsub(name,"^"..mw.site.siteName,"Project") or nameend
function out(name) return mw.ustring.gsub(name,"^Project",mw.site.siteName) or nameend
function keyize(pagename) -- there was a complaint about "_" breaking things. Do all lookups with _ in place of any space. -- also spaces in the index file (non-module) were causing trouble pagename = mw.text.trim(pagename) pagename = mw.ustring.gsub(pagename, " ", "_") pagename = mw.uri.decode(pagename) pagename = anonymize(pagename) return pagenameend
function p.main(frame,displacement,varstoreturn) local parent=frame.getParent(frame) local currentpage,indexmodule,defaultpage,noerr ---- args in the #invoke itself trump args in the parent frame currentpage = frame.args.page and mw.text.trim(frame.args.page) defaultpage = frame.args.defaultpage and mw.text.trim(frame.args.defaultpage) indexmodule = frame.args.index and mw.text.trim(frame.args.index) displacement = displacement or frame.args.displacement -- can be passed from the other function names at the end noerr=frame.args.noerr -- used as boolean anonymizereturn = frame.args.anonymize -- used as boolean ---- args in the parent frame come next if parent then currentpage=currentpage or (parent.args.page and mw.text.trim(parent.args.page)) indexmodule=indexmodule or (parent.args.index and mw.text.trim(parent.args.index)) -- index is a module return defaultpage=defaultpage or (parent.args.defaultpage and mw.text.trim(parent.args.defaultpage)) noerr=noerr or parent.args.noerr anonymizereturn = anonymizereturn or parent.args.anonymize end ---- default values if parameters aren't provided defaultpage=defaultpage or "" -- don't know where to send people by default if not(indexmodule) then return " error:no index parameter specified" end if not(currentpage) then local pp=mw.title.getCurrentTitle if not pp then if noerr then return "","","" else return " error:failed to access getCurrentTitle" -- this shouldn't happen anyway, I don't think.... end end currentpage=pp.fullText end currentpage=anonymize(currentpage) --- convert "Wikipedia:, "Meta:" etc. into "Project: local index= if mw.ustring.sub(indexmodule,1,6)
function p.next_page(frame) local returnpage,pagenumber,totalpages,errcode=p.main(frame,1,true) return returnpageendp.next = p.next_page -- Same as above, but returns the previous pagefunction p.last_page(frame) local returnpage,pagenumber,totalpages,errcode=p.main(frame,-1,true) return returnpageendp.last = p.last_page function p.page_number(frame) local returnpage,pagenumber,totalpages,errcode=p.main(frame,0,true) if errcode then return returnpage else return pagenumber endendp.page = p.page_number
function p.total_pages(frame) local returnpage,pagenumber,totalpages,errcode=p.main(frame,0,true) if errcode then return returnpage else return totalpages endendp.total = p.total_pages
return p