imported>Oetterer K (Schützte „Modul:Foundationclass/classDoc“: Automatic protection of selected project pages ([Bearbeiten=Nur Administratoren erlauben] (unbeschränkt) [Verschieben=Nur Administratoren erlauben] (unbeschränkt))) |
Version vom 7. Oktober 2022, 16:56 Uhr
This module is rated as beta, and is ready for widespread use. It is still new and should be used with some caution to ensure the results are as expected. |
This module implements template some methods for Module:Foundationclass's documentation.
Usage[Quelltext bearbeiten]
# note: contents means the text which should be pasted into an articles textbox to produce a page {{#invoke:Foundationclass/classDoc|base}} -- returns the contents of a class module's base page {{#invoke:Foundationclass/classDoc|baseDoc}} -- returns the contents of a class module's base page's doc page (aka the documentation of a base page) {{#invoke:Foundationclass/classDoc|categorize}} -- returns the categories, suited for the calling page {{#invoke:Foundationclass/classDoc|category}} -- returns the contents of a category page {{#invoke:Foundationclass/classDoc|class}} -- returns the contents/template text for a class module {{#invoke:Foundationclass/classDoc|classDoc}} -- returns the contents of a class module's doc page (aka documentation of a class page) {{#invoke:Foundationclass/classDoc|configDoc}} -- returns the contents of a class module's config page's doc page {{#invoke:Foundationclass/classDoc|form}} -- returns the contents of a form page {{#invoke:Foundationclass/classDoc|gardeningCategory}} -- returns the contents of a gardening category page {{#invoke:Foundationclass/classDoc|template}} -- returns the contents of a template page {{#invoke:Foundationclass/classDoc|templateDoc}} -- returns the contents of a template page's doc page
These methods can also be called by other modules. When doing so, you can actually define the module name and the class name. They will substitute the placeholders in the documentation text:
local classDoc = require('Modul:Foundationclass/classDoc')
classDoc.base(moduleName)
classDoc.baseDoc(moduleName)
classDoc.category(moduleName)
classDoc.class(moduleName, className)
classDoc.classDoc(moduleName, className)
classDoc.configDoc(moduleName)
classDoc.form(moduleName)
classDoc.gardeningCategory(moduleName)
classDoc.template(moduleName)
classDoc.templateDoc(moduleName)
However, what you want to be doing instead of calling these methods is, generating the content yourself. That you do like this:
-- instead of calling classDoc.class(moduleName, className), you use
local content = mw.message.new('classengine-template-module-class-page'):rawParams(_private[self].pagename, coreData.className):plain()
-- instead of calling classDoc.classDoc(moduleName, className), you use
local content = mw.message.new('classengine-template-module-class-documentation-page'):rawParams(_private[self].pagename, coreData.className, moduleCategory, classCategory):plain()
-- in case of non module pages, you might need to take care of the escaped template, wiki, and parser function calls. this you do with:
local frame = mw.getCurrentFrame()
content = frame:preprocess(content)
local placeholder = {
defaultClassName = 'ClassName',
defaultModuleName = 'Name',
}
local _globalCFG = mw.loadData('Module:Foundationclass/globalconfig')
local p = {}
function p.base(frame)
if not frame or frame == mw.getCurrentFrame() then
return mw.message.new('classengine-template-module-page'):rawParams(placeholder.defaultModuleName):plain()
else
-- this is not needed any more and exists due to backward compatibility reasons
return mw.message.new('classengine-template-module-page'):rawParams(frame):plain()
end
end
function p.baseDoc(frame)
if not frame or frame == mw.getCurrentFrame() then
return mw.text.nowiki(frame:preprocess(mw.message.new('classengine-template-module-documentation-page'):rawParams(placeholder.defaultModuleName, (_globalCFG.moduleCategory or 'none')):plain()))
else
-- this is not needed any more and exists due to backward compatibility reasons
return mw.getCurrentFrame():preprocess(mw.message.new('classengine-template-module-documentation-page'):rawParams(frame, (_globalCFG.moduleCategory or 'none')):plain())
end
end
-- we need a function to be called by some generic category pages to be categorized in project's supercategory
-- since foundationclass has no base module, we put it here
-- the category pages of the classes call their base module's categorize
-- this is called by project gardening supercategory and the meta category pages (forms, modules, templates, properties)
function p.categorize(frame)
local FoundationClass = require('Module:Foundationclass')
return FoundationClass:categorize()
end
function p.category(frame)
if not frame or frame == mw.getCurrentFrame() then
return mw.text.nowiki(frame:preprocess(mw.message.new('classengine-template-category-page'):rawParams(placeholder.defaultModuleName, (_globalCFG.projectSuperCategory or 'none')):plain()))
else
-- this is not needed any more and exists due to backward compatibility reasons
return mw.getCurrentFrame():preprocess(mw.message.new('classengine-template-category-page'):rawParams(frame, (_globalCFG.projectSuperCategory or 'none')):plain())
end
end
function p.class(frame, className)
local className = className or placeholder.defaultClassName
if not frame or frame == mw.getCurrentFrame() then
return mw.message.new('classengine-template-module-class-page'):rawParams(placeholder.defaultModuleName, className):plain()
else
-- this is not needed any more and exists due to backward compatibility reasons
return mw.message.new('classengine-template-module-class-page'):rawParams(frame, className):plain()
end
end
function p.classDoc(frame, className)
local className = className or placeholder.defaultClassName
local moduleCategory = _globalCFG.moduleCategory or 'none'
local classCategory = _globalCFG.classCategory or 'none'
if not frame or frame == mw.getCurrentFrame() then
return mw.text.nowiki(frame:preprocess(mw.message.new('classengine-template-module-class-documentation-page'):rawParams(placeholder.defaultModuleName, className, moduleCategory, classCategory):plain()))
else
-- this is not needed any more and exists due to backward compatibility reasons
return mw.getCurrentFrame():preprocess(mw.message.new('classengine-template-module-class-documentation-page'):rawParams(frame, className, moduleCategory, classCategory):plain())
end
end
function p.configDoc(frame)
local moduleCategory = _globalCFG.moduleCategory or 'none'
local classCategory = _globalCFG.classCategory or 'none'
if not frame or frame == mw.getCurrentFrame() then
return mw.text.nowiki(frame:preprocess(mw.message.new('classengine-template-module-config-documentation-page'):rawParams(placeholder.defaultModuleName, moduleCategory, classCategory):plain()))
else
-- this is not needed any more and exists due to backward compatibility reasons
return mw.getCurrentFrame():preprocess(mw.message.new('classengine-template-module-config-documentation-page'):rawParams(frame, moduleCategory, classCategory):plain())
end
end
function p.form(frame)
if not frame or frame == mw.getCurrentFrame() then
return mw.text.nowiki(frame:preprocess(mw.message.new('classengine-template-form-page'):rawParams(placeholder.defaultModuleName, (_globalCFG.formCategory or 'none')):plain()))
else
-- this is not needed any more and exists due to backward compatibility reasons
return mw.getCurrentFrame():preprocess(mw.message.new('classengine-template-form-page'):rawParams(frame, (_globalCFG.formCategory or 'none')):plain())
end
end
function p.gardeningCategory(frame)
if not frame or frame == mw.getCurrentFrame() then
return mw.text.nowiki(frame:preprocess(mw.message.new('classengine-template-gardeningcategory-page'):rawParams(placeholder.defaultModuleName, (_globalCFG.gardeningSuperCategory or 'none')):plain()))
else
-- this is not needed any more and exists due to backward compatibility reasons
return mw.getCurrentFrame():preprocess(mw.message.new('classengine-template-gardeningcategory-page'):rawParams(frame, (_globalCFG.gardeningCategory or 'none')):plain())
end
end
function p.template(frame)
if not frame or frame == mw.getCurrentFrame() then
return mw.text.nowiki(frame:preprocess(mw.message.new('classengine-template-template-page'):rawParams(placeholder.defaultModuleName):plain()))
else
-- this is not needed any more and exists due to backward compatibility reasons
return mw.getCurrentFrame():preprocess(mw.message.new('classengine-template-template-page'):rawParams(frame):plain())
end
end
function p.templateDoc(frame)
if not frame or frame == mw.getCurrentFrame() then
return mw.text.nowiki(frame:preprocess(mw.message.new('classengine-template-template-documentation-page'):rawParams(placeholder.defaultModuleName, (_globalCFG.templateCategory or 'none')):plain()))
else
-- this is not needed any more and exists due to backward compatibility reasons
return mw.getCurrentFrame():preprocess(mw.message.new('classengine-template-template-documentation-page'):rawParams(frame, (_globalCFG.templateCategory or 'none')):plain())
end
end
return p