User:Conrad.Irwin/creation.js/documentation

Definition from Wiktionary, the free dictionary
Jump to: navigation, search
Edit-copy green.svg Documentation for User:Conrad.Irwin/creation.js. [edit]
This page contains usage information, categories, interwiki links and other content describing the template.
To edit the rules for generating new form-of entries, go to User:Conrad.Irwin/creationrules.js.

This script allows the automatic creation of entries for inflected forms of words. This makes it similar to what form bots such as User:MewBot or User:SemperBlottoBot do, but in a way that anyone can use relatively easily.

Enabling accelerated links[edit]

To enable the script, do either (only one) of those things:

  • If you have an account, enable it in the Gadgets tab of your preferences: item "Add accelerated creation links for common inflections of some words."
  • Add the following to your common.js (again, if you have an account):
    importScript('User:Conrad.Irwin/creation.js');
    
  • Go to WT:PREFS and tick "Add accelerated creation links for common inflections of some words". This should work even for users without an account.

Usage[edit]

  • Browse to an entry missing forms that uses one of the accelerated templates or create a new word.
  • Click on any "green links" (these would be "red links" normally)
  • Review the page it would create for you by asking for a preview.
  • Click "Save" on the page it creates for you.

If it doesn't work as advertised, try doing a hard refresh before giving up hope. If this fails, report this at WT:Grease pit.

Making a template use the script[edit]

The basic idea is to wrap a link in a <span> which contains the necessary information to create the page. The script works by looking through a page for HTML elements that contain class="form-of". This acts as a "flag" for the script that says "here is a link you need to look at". The element's class must also contain information about what kind of form it is; this tells the script what kind of entry the link should generate. The parameters are passed in the class name of the span, and one of the class-names of the span (normally the first) must be form-of.

Both Template:head and Module:headword inherently support accelerated links. They include class="form-of lang-langcode" for you, so that you only need to specify the remainder:

  • Template:head has a set of fNaccel= parameters, which specify the class and other details.
  • Module:headword allows you to specify an .accel value as part of the table of inflections to show in the headword.

When you're done, add {{isAccelerated}} to the documentation page of the template. This shows a notice that accelerated links are enabled for this template. It also adds the template to Category:Templates with acceleration.

The following is the currently supported range of parameters that can be used. Italics indicate something you need to fill in yourself.

lang-langcode
The language that it's in. This parameter is mandatory, but Template:head and Module:headword include this for you automatically.
form-form-of
Which particular form the link is for. It can be just about anything, and is often language-specific. Mandatory.
gender-gender
The gender of the form in question. This should only be needed if it needs to be specified on the headword line. It's redundant if the "form of" definition already mentions the gender, so if the definition already says "feminine form of" then you don't need to add this.
origin-pagename
The term that the generated form-of entry should link back to. This defaults to the name of the current page, but you can override it if you need to provide extra diacritics that are not present in the page name.
transliteration-translit
The transliteration for the form. This is only needed if the headword-line template of the generated entry is not able to make one on its own.

When this information has been gathered from the element's class definition, any red links that are inside the element are then modified. The links are made green, and the URL of the link is changed to include information for generating the form-of entry. The wiki software will pick up on this when the link is followed, and will preload the edit window with the given text.

If a link is red but with green dashes underneath, it means that the script understood the parameters that were given in the template, but it did not know how to generate an entry with them. This usually means that the script has no generation rules for a particular language yet, or that the form that you asked for isn't recognised for that language. To fix this, you need to update the rules (below).

Requesting new rules[edit]

If you are not able to edit the script yourself, please file requests for new features on the script's talk page. Specify:

  1. What you want to generate the links for. That includes at least a link to the template whose links you want to make green.
  2. What the generated entries should look like. In particular, which headword-line template it should use, and which form-of template, which parameters they should receive in which situations, and so on. A link to a word that has blue links to all the forms in the template would work best, as an example.
  3. Ideally, a link to a word that has red links to all the forms. This is useful for testing to see if the generated entries are correct.

Adding new rules[edit]

Generation rules are used to create the entry's contents from within the script. They are defined in a separate file, User:Conrad.Irwin/creationrules.js. The creation_rules array contains an entry for each recognised language. This entry is a function that takes two arguments, params and entry.

The params parameter is an array that contains the information about the lemma, the form-of entry to be created, and the information given in the <span class="form-of... of the template. It contains the following values:

lang
The language code. This is whatever was given in the span as the language, but with the lang- at the beginning removed.
pos
The part of speech that the new entry is created for. This is taken from whatever header precedes the template.
form
The name of the form. This is whatever was given in the span as the form name, but with the -form-of at the end removed.
gender
The gender, or null. Whatever was given in the span as the gender, but with the gender- at the beginning removed.
transliteration
The transliteration, or null. Whatever was given in the span as the transliteration, but with the transliteration- at the beginning removed.
origin
The term that the new entry should link back to. If the origin- value was given in the span, it will be that. Otherwise, it's the same as origin_pagename by default.
origin_pagename
The page name of the lemma.
target
The form that the new entry is created for. This is taken automatically from the display form (alt) in the template's link to the form. It is used to give the head= parameter if necessary. This is the same as target_pagename in most cases, but can be different if the display form contains additional diacritics.
target_pagename
The page name of the entry to be created.

The entry parameter contains the different parts of the entry that is being created. Some of them have a default value, while others are null by default. The purpose of the generation function for each language is to provide these values so that the entry is generated according to what is needed for the language. The entry array contains the following values:

lang_header
The name of the level 2 header of the new entry. You rarely need to change this, the default should be correct.
pronunc
The contents of the "Pronunciation" section, if any. Empty by default.
pos_header
The name of the level 3 part-of-speech header for the new entry. This does not usually need to be changed, as it automatically matches the part of speech of the main entry. But you can change it if, for example, you are generating a participle entry and you want to show "Participle" instead of "Verb".
head
The headword template code and all its parameters. By default, it uses {{head|(lang)|(pos) form}}, with head= and tr= as necessary. You need to override this if you need something else.
def
The definition line, without the initial # . You must override this, as there is no default and the script will fail.
declension
The contents of the "Declension" section, if any. Empty by default. This can be used if the new entry is a sub-lemma with its own inflection, such as participles or comparative/superlative forms that inflect themselves.
conjugation
As above, but for "Conjugation".

Subpages[edit]

Conrad.Irwin/creation.js/documentation Conrad.Irwin/creation.js/intro