Module:utilities Page
Τεκμηρίωση
επεξεργασίαΑυτό το Module δημιουργήθηκε για να μπορούν να χρησιμοποιηθούν τα "καλούδια" του: http://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Title_objects από χρήστες που δεν θέλουν να φτιάξουν ένα Lua module.
Χρήση: {{#invoke:Page|(function)|παράμετροι}}
Συναρτήσεις
επεξεργασίαΤο function μπορεί να είναι ένα από τα παρακάτω:
- id: Το page_id. 0 εάν δεν υπάρχει η σελίδα.
- interwiki: The interwiki prefix, or the empty string if none.
- namespace: The namespace number.
- fragment: The fragment, or the empty string. May be assigned.
- nsText: The text of the namespace for the page.
- subjectNsText: The text of the subject namespace for the page.
- text: The title of the page, without the namespace or interwiki prefixes.
- Παράδειγμα: Το {{#invoke:Page|text}} εδώ δίνει: Script error: No such module "Page".
- prefixedText: The title of the page, with the namespace and interwiki prefixes.
- fullText: The title of the page, with the namespace and interwiki prefixes and the fragment.
- rootText: If this is a subpage, the title of the root page without prefixes. Otherwise, the same as title.text.
- baseText: If this is a subpage, the title of the page it is a subpage of without prefixes. Otherwise, the same as title.text.
- subpageText: If this is a subpage, just the subpage name. Otherwise, the same as title.text.
- canTalk: Whether the page for this title could have a talk page.
- exists: Whether the page exists. Alias for fileExists for Media-namespace titles.
- fileExists: Whether the file exists. For File- and Media-namespace titles, this is expensive.
- isContentPage: Whether this title is in a content namespace.
- isExternal: Whether this title has an interwiki prefix.
- isLocal: Αν το λήμμα ανήκει στο ίδιο βικιεγχείρημα.
- Κάθε βικιλεξικό (αγγλόφωνο, γαλλόφωνο κλπ) επιστρέφει true ενώ π.χ. το wikipedia επιστρέφει false.
- isRedirect: Whether this is the title for a page that is a redirect.
- isSpecialPage: Whether this is the title for a possible special page (i.e. a page in the Special: namespace).
- isSubpage: Whether this title is a subpage of some other title.
- isTalkPage: Αν είναι σελίδα συζήτησης.
- isSubpageOf( title2 ): Whether this title is a subpage of the given title.
- inNamespace( ns ): Whether this title is in the given namespace. Namespaces may be specified by anything that is a key found in mw.site.namespaces.
- inNamespaces( ... ): Whether this title is in any of the given namespaces. Namespaces may be specified by anything that is a key found in mw.site.namespaces.
- hasSubjectNamespace( ns ): Whether this title's subject namespace is in the given namespace. Namespaces may be specified by anything that is a key found in mw.site.namespaces.
- contentModel: The content model for this title, as a string.
- basePageTitle: The same as mw.title.makeTitle( title.namespace, title.baseText ).
- rootPageTitle: The same as mw.title.makeTitle( title.namespace, title.rootText ).
- talkPageTitle: The same as mw.title.makeTitle( mw.site.namespaces[title.namespace].talk.id, title.text ), or nil if this title cannot have a talk page.
- subjectPageTitle: The same as mw.title.makeTitle( mw.site.namespaces[title.namespace].subject.id, title.text ).
- subPageTitle( text ): The same as mw.title.makeTitle( title.namespace, title.text .. '/' .. text ).
- partialUrl(): Returns title.text encoded as it would be in a URL.
- fullUrl( query, proto ): Returns the full URL (with optional query table/string) for this title. proto may be specified to control the scheme of the resulting url: "http", "https", "relative" (the default), or "canonical".
- localUrl( query ): Returns the local URL (with optional query table/string) for this title.
- canonicalUrl( query ): Returns the canonical URL (with optional query table/string) for this title.
- getContent(): Returns the (unparsed) content of the page, or nil if there is no page.
---- @brief
---- Αυτό το Module δημιουργήθηκε για να μπορούν να χρησιμοποιηθούν τα "καλούδια" του:
---- http://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Title_objects
---- από χρήστες που δεν θέλουν να φτιάξουν ένα Lua module.
---- Χρήση: {{#invoke:Page|(function)|παράμετροι}}
---- Στη θέση του (function) βάζεται μία από τις συναρτήσεις:
---- id, interwiki, namespace, fragment, nsText, subjectNsText, text, prefixedText, fullText ...
---- οι παράμετροι είναι:
---- page = (το λήμμα που θέλετε να διαβάσετε. Αφήστε το κενό αν θέλετε να πάρει τα δεδομένα από το mw.title.getCurrentTitle()
---- this is "text" passed to mw.title.new or "title" passed to mw.title.makeTitle
---- makeTitle = nonblank to call mw.title.makeTitle otherwise mw.title.new is called
---- namespace = (parameter passed to new/makeTitle)
---- fragment = (parameter passed to makeTitle)
---- interwiki = (parameter passed to makeTitle)
---- p1 = first parameter passed to functions within the title object
---- p2 = second parameter " " " "
---- p3 etc. (for inNamespaces)
---- Αντιγραφή από το [[:en:Module:Page]]
---- Sorry, getContents doesn't work for many applications because all templates are destroyed. It does work on plain text though.
local p = {}
function p.main(frame)
local args=frame.args
local parent=frame.getParent(frame)
local pargs={}
if parent then pargs=parent.args end
local makeTitle=args.makeTitle or pargs.makeTitle or ""
local namespace=args.namespace or pargs.namespace or ""
local fragment=args.fragment or pargs.fragment or ""
local interwiki=args.interwiki or pargs.interwiki or ""
local p1 = args.p1 or pargs.p1 or ""
local p2 = args.p2 or pargs.p2 or ""
local p3 = args.p3 or pargs.p3 or ""
local p4 = args.p4 or pargs.p4 or ""
local p5 = args.p5 or pargs.p5 or ""
local p6 = args.p6 or pargs.p6 or ""
local p7 = args.p7 or pargs.p7 or ""
local p8 = args.p8 or pargs.p8 or ""
local p9 = args.p9 or pargs.p9 or ""
local nowiki = args.nowiki or pargs.nowiki or false
local page=args.page or pargs.page or args[1] or pargs[1]
if page=="" then page=nil end
local title -- holds the result of the mw.title.xxx call
if not(page) then
title=mw.title.getCurrentTitle()
if not(title) then return "error: failed to getCurrentTitle()" end
else if makeTitle then
title=mw.title.makeTitle(namespace,page,fragment,interwiki)
if not (title) then return "error: failed to makeTitle(" .. namespace .. "," .. page .. "," .. fragment .. "," .. interwiki .. ")" end
else if id then
title=mw.title.new(id)
if not (title) then return "error: failed to mw.title.new(" .. id .. ")" end
else
title=mw.title.new(page,namespace)
if not (title) then return "error: failed to mw.title.new(" .. page .. "," .. namespace .. ")" end
end -- if id
end -- if makeTitle
end -- if not(page)
local result=title[field]
if type(result)=="function" then
if nowiki then
return frame.preprocess(frame, "<pre><nowiki>" .. tostring(result(title,p1,p2,p3,p4,p5,p6,p7,p8,p9)).. [[</nowiki></pre>]]) -- I *think* these are all page:x() calls
else return frame.preprocess(frame,result(title,p1,p2,p3,p4,p5,p6,p7,p8,p9))
end
else return tostring(result) -- note that nil values will be returned as "nil", not ""
end
end
function p.id(frame)
field="id"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.interwiki(frame)
field="interwiki"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.namespace(frame)
field="namespace"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.fragment(frame)
field="fragment"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.nsText(frame)
field="nsText"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.subjectNsText(frame)
field="subjectNsText"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.text(frame)
field="text"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.prefixedText(frame)
field="prefixedText"
return p.main(frame)
end
function p.fullText(frame)
field="fullText"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.rootText(frame)
field="rootText"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.baseText(frame)
field="baseText"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.subpageText(frame)
field="subpageText"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.canTalk(frame)
field="canTalk"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.exists(frame)
field="exists"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.fileExists(frame)
field="fileExists"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.isContentPage(frame)
field="isContentPage"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.isExternal(frame)
field="isExternal"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.isLocal(frame)
field="isLocal"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.isRedirect(frame)
field="isRedirect"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.isSpecialPage(frame)
field="isSpecialPage"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.isSubpage(frame)
field="isSubpage"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.isTalkPage(frame)
field="isTalkPage"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.isSubpageOf(frame)
field="isSubpageOf"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.inNamespace(frame)
field="inNamespace"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.inNamespaces(frame)
field="inNamespaces"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.hasSubjectNamespace(frame)
field="hasSubjectNamespace"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.contentModel(frame)
field="contentModel"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.basePageTitle(frame)
field="basePageTitle"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.rootPageTitle(frame)
field="rootPageTitle"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.talkPageTitle(frame)
field="talkPageTitle"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.subjectPageTitle(frame)
field="subjectPageTitle"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.subPageTitle(frame)
field="subPageTitle"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.partialUrl(frame)
field="partialUrl"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.fullUrl(frame)
field="fullUrl"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.localUrl(frame)
field="localUrl"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.canonicalUrl(frame)
field="canonicalUrl"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
function p.getContent(frame)
field="getContent"
return p.main(frame) -- I ''think'' that frame, field automatically is available to p.main
end
return p