User:PerfektesChaos/js/citoidWikitext/software/wikiProject
Creating a plug-in for a particular wiki project to run citoidWikitext.
Project dependant template specfications and other adaptions need to be provided. The plug-in will receive the common results of the investigation, and shall determine whether and how that shall be inserted into the wikitext source.
Project identifier
[edit]Each WMF wiki has a unique identifier by database name, which is available for JavaScript by wgDBname
configuration specifier.
Typical values are:
enwiki
for English Wikipediadewiki
for German Wikipediafrwikisource
for French Wikisource
This code is referred on this page as wikiDB placeholder.
Requirements
[edit]- Every plug-in is supposed to provide the Resource Loader module identification
ext.gadget.citoidWikitext/
wikiDB as soon as possible; beginning withloading
andready
when built. - The function
mw.libs.citoidWikitext.
wikiDB.fire()
has to be supported as specified below.
Source code location
[edit]There are three ways to provide the plugin code.
- By default, registered projects are expected at the tool’s root directory:
w:en:User:PerfektesChaos/js/citoidWikitext/
wikiDB/r.js
- That may consist of two statements:
- declare loader state to be still
loading
- load from any other place, e.g. project’s MediaWiki space or trusted user page or anywhere else.
- declare loader state to be still
- By previous external activities, Resource Loader module identification may have been satisfied.
- This may be used to provide own forks, e.g. for testing or debugging, and goes for all modules.
- A
string
value at the JS variable component was set in advance:mw.libs.citoidWikitext.
wikiDB
- This is supposed to be a URL which resolves to something which is returning
text/javascript
MIME type.
Minimum functionality
[edit]Plug-in object
[edit]A JS variable component is set to be an object
(non-null):
mw.libs.citoidWikitext.
wikiDB
.fire()
[edit]Within the plug-in object the following function has been defined:
mw.libs.citoidWikitext.
wikiDB.fire( results )
results
– Array of citoid server resultsresults[ 0 ]
– combined and enhanced result- Further elements of
results
are distinctive results, when multiple query URLs have been sent to server.
- Return value: Array,
string
, orfalse
.false
– no meaningful text insertion could be derived from these results.- Array, with elements:
[ 0 ]
– Array, with elements describing the entire template:[ 0 ]
–string
, with template title or any page name[ 1 ]
–boolean
, on multi-line insertiontrue
– permit multiple linesfalse
– always compact
[ 2 ]
–boolean
, on bibSection optiontrue
– offer bibSection unordered listfalse
– do not mention
[ n ]
– Array, with elements describing one single parameter for n>0:[ 0 ]
–string
, with parameter name (currently no unnamed parameters expected, but might be supported byfalse
)[ 1 ]
–boolean
, on empty valuestrue
– show empty parameter assignment, even in compact modefalse
– never show empty parameter assignment
[ 2 ]
–string
, with parameter value, orfalse
ornull
string
, with preformatted insertion text- No bibSection option.
It is up to the wiki project to determine how to react on a result.
Stated as ready
[edit]The Resource Loader module identification
ext.gadget.citoidWikitext/
wikiDB
pretends to be ready
.
Extended functionality
[edit]Templates on input
[edit]The plug-in object may contain a component templates
as object:
mw.libs.citoidWikitext.
wikiDB.templates
That object may contain functions like this:
mw.libs.citoidWikitext.
wikiDB.templates.Google_books()
This function will be called, if a template of this name has been chosen for input.
- One string as input parameter, starting with first pipe or terminating brackets of template transclusion.
- Supposed to return a URL or other keyword/data, or false.
The .core.fold()
utility below might help.
Common library
[edit]For the benefit of plug-in programmers, a set of public components of the application object is provided.
- .core.fold()
- Derive simple template parameter assignments; not nested, no links.
- Available from beginning.
- One string as input parameter, starting with first pipe or terminating brackets of template transclusion.
- Returns object, with parameter components identified by strings
- .opus.fetch( assembly, access )
- Retrieve string value from query result
- assembly – object, with query result
- access – string, with component name
- .opus.figures( apply )
- Format list of comma-separated hyphen-joined number ranges
- apply – string, or not
- .opus.fork( array )
- Duplicate template definition Array
- array – Array with basic citoid query
- .opus.format( assembly )
- Guess URL content type, like PDF
- assembly – object, with citoid server result
- .opus.freeze( amount )
- Retrieve ISO 8601 string of current date and time
- amount – Number of digits; 10: date
The .opus
components are available for result evaluation only.
Sandbox
[edit]If the project sandbox like WP:Sandbox shall be equipped by default, it needs to be registered at d:Q3938.