Jump to content

User:PerfektesChaos/js/jsonXMLutils

From Wikipedia, the free encyclopedia

JavaScript gadget – several tools for JSON and XML template documentation.

Usage

[edit]

Include the following lines into your common.js, global.js etc.:

mw.loader.load( "//en.wiki.x.io/w/index.php?title=User:PerfektesChaos/js/jsonXMLutils/r.js&action=raw&bcache=1&maxage=604800&ctype=text/javascript",
                "text/javascript" );

TemplateData

[edit]

Generation from scratch

[edit]

At every stage in template namespace there is a button offered to create a new TemplateData JSON structure:

  • in edit mode on top of page, close to (disabled) MediaWiki button for TemplateData maintenance.
  • in view mode at the end of the page, close to categories.

If clicked, a textarea field is opened. When in edit mode, the regular edit form is searched for template programming. If characteristical parameters like {{{1}}} are detected, the field is intialised with a parameter list in alphabetical order.

The textarea can be filled interactively with any list of parameters, the significant part of a transclusion, a copy master, or simply a list with parameter names on single lines.

When happy, clicking the [submit] button creates a JSON pattern instead of the textarea, following the sequence in textarea.

Analyzing and pretty print

[edit]

Existence of a TemplateData definition is recognized and the current JSON code may be formatted in standard format. That can be copied back to the place of definition.

Also the data will be

  • analyzed semantically, e.g. for invalid language codes or values of type – outdated values will be updated;
  • analyzed syntactically, e.g. for invalid JSON data types;
  • analyzed structurally, e.g. for unknown (mistyped) names of TemplateData components;

The result, if any, is prepended as nonconformity report.

An empty schema is provided for recommended fields, if not yet present.

A button is offered

  • in edit mode on top of page, close to MediaWiki button for TemplateData maintenance.
  • in view mode at the end of the page, close to categories.

Retrieving XML pendant

[edit]

Based upon TemplateData information the corresponding XML can be generated and copied into target page.

A button is available close to the button for JSON pretty print.

Vorlagenmeister

[edit]

Vorlagenmeister uses XML for description of template parameters, building interactive form for filling in current parameter data since 2007.

Page view

[edit]

XML code will be re-displayed with syntax highlighting on /XML subpages.

Lines are expected to be in monospace formatting already, by indentation of at least one space.

Source code editing

[edit]

CodeEditor will be activated on /XML subpages.

Other languages

[edit]

This gadget is prepared for multilingual support.

  • If you like a version in your own language, please forward translations to me:
    • This documentation page.
    • The I18N.texts mapping on top of source code.
    • Further ISO 639 language codes your translation might support.

Intermediately, programmers can override any I18N.texts component by providing a respective component at:

mw.libs.jsonXMLutils = {  config = { /* ... */ }  };

Codes

[edit]
Source code
ResourceLoader
Namespaces
  • 10   *   templates
  • (-1 Gadgets)
mw.libs jsonXMLutils