විකිපීඩියා:RefToolbar 2.0

විකිපීඩියා වෙතින්

refToolbar 2.0 is a new version of refToolbar designed for the enhanced editing toolbar.

The modified toolbar

To install the script, add the following line to your skin JS page:

importScript('User:Mr.Z-man/refToolbar.js');

If you use any customization options as described below, be sure to add them after the importScript line.

You can also turn on refToolbar by going to the Gadgets tab in your user preferences and checking the checkbox next to "refTools" under "Editing gadgets".

Templates[සංස්කරණය]

An example of a template dialog

On the left side of the Cite panel is a dropdown list of all available templates. Clicking one will open a dialog box with the fields for that template. Buttons on the bottom of the dialog are used to insert the ref into the article, preview the ref, reset the form, and close the dialog without changing the article. Clicking will insert the current date into the adjacent text box. Clicking will attempt to autofill citation details given an ID entered in the adjacent text box. An ISBN, DOI, or PMID can be used for autofilling.

Named refs[සංස්කරණය]

The named refs dialog

Clicking the "Named refs" button will open a dialog listing all of the named references in the article. Choosing one will show the wikitext of the reference with an option to preview how the reference looks after parsing. Clicking the "Insert" button will insert the named reference (<ref name=Foo />) into the last cursor position in the article.

Error checking[සංස්කරණය]

To use error checking, click the Error check symbol, then select the error checks to run. A panel listing any errors found will be inserted underneath the edit area. Additional error checks can be added, see below for details.

Unlike the old version of the script, this version is highly customizable sitewide and on a per-user basis.

Note that while the script is designed to be easily configurable, the configuration options do need to be valid JavaScript code - brackets and parentheses must be matched and strings must be wrapped in quotation marks with quotation marks in the string escaped as necessary.

Configuration is done using a global CiteTB object. Configuration options are stored in CiteTB.Options and CiteTB.UserOptions

Individual users[සංස්කරණය]

No customization is required, the script will use the sitewide defaults "out of the box." All user configuation options override the sitewide options.

Sitewide configuration[සංස්කරණය]

All global configuration is done in the MediaWiki:RefToolbarLocal.js script file. The script will set a default for all options, but it is recommended that site defaults include a value for all options. For all option sample code shown below, change "UserOptions" to "Options" for site configuration. The initial $j('head').one('reftoolbarbase', function() { line and the final }); are not necessary for changes in RefToolbarLocal.js and should be omitted.

Automatic date insertion[සංස්කරණය]

Changing the date format used for automatically added dates (such as accessdate) is done using a simple string replacement system. "Special" words will be replaced with their corresponding date, all other characters will be left as-is.

The current date options available are:

  • <date> — The day of the month (1-31)
  • <zdate> — The day of the month (01-31), zero-padded to 2 digits
  • <month> — The month number (1–12)
  • <zmonth> — The month number (01–12), zero-padded to 2 digits
  • <monthname> — The month name
  • <year> — The 4-digit year

Other options may be available on request. Currently only one format will be used. If there is demand for it, the automatic date system may be extended to allow multiple options in a dropdown selection box. The date is always in UTC.

The fields that have an automatic date option are stored in the "autodate fields" option.

To customize automatic date insertion, options can be set like so:

$j('head').one('reftoolbarbase', function() {
CiteTB.UserOptions['date format'] = "<date> <monthname> <year>";
CiteTB.UserOptions['autodate fields'] = ['accessdate'];
});

Modal dialogs[සංස්කරණය]

To set whether the dialogs should be modal, use the "modal" option. If set to true, opening one of the dialogs will block access to the rest of the edit page until the dialog is closed.

$j('head').one('reftoolbarbase', function() {
CiteTB.UserOptions['modal'] = true;
});

Automatic parsing[සංස්කරණය]

The script can be set to automatically provide a parsed preview when previewing a citation template through the "autoparse" option. Its not recommended to set this to true as a global setting as it may slow the script down for people with slow connections.

$j('head').one('reftoolbarbase', function() {
CiteTB.UserOptions['autoparse'] = false;
});

Template expansion[සංස්කරණය]

To be able to retrieve more references on a page, the script can also expand templates and parser functions on the page (except templates inside of ref tags) so that references from templates or references that use the {{#tag:ref}} syntax will be available when inserting named refs or for error checking functions. This can also slow the script down for people with slow connections.

$j('head').one('reftoolbarbase', function() {
CiteTB.UserOptions['expandtemplates'] = false;
});

Month names[සංස්කරණය]

The month names used for automatic date insertion are also customizable, for translation to other languages, or to use abbreviations.

$j('head').one('reftoolbarbase', function() {
CiteTB.UserOptions['months'] = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
});

Citation templates[සංස්කරණය]

Citation templates can be added using an object syntax. To add a new template, simply create a new citeTemplate object. Each template has 4 required parameters.

  1. The template name (e.g. "cite web")
  2. A short name for the template, used for the template list in the script (this name should be a unique name for each template object, even if 2 template objects are based on the same template)
  3. A list of "basic" template options, using the syntax described below
  4. A list of the the remaining options, any option the template supports that isn't in the "basic" list.

For sitewide settings, templates should be included in the RefToolbarLocal page. Users can also add their own templates with this system by adding them to their user script page. If the script is installed on the user script page (as opposed to using a gadget), the templates must be below where the script is imported.

Object syntax for fields[සංස්කරණය]

Each field is described as an object in a list, using JavaScript Object Notation. The available options are:

  • field – The actual field name as used in the template. This is the only required attribute.
  • label – The text that will be given as the label on the form. If not provided, the 'field' attribute will be used with the first letter capitalized
  • tooltip – If given, a ? will be put after the label that the user can mouse over to see a more detailed description of the field.

The object system allows other options to be added later as the script is modified to support them. Potential future features include automatic fill-in from ISBN/PMID/etc, type checking (require a parameter to be a string, number, date, etc.), and required fields.

Autofilling[සංස්කරණය]

The script can autofill citation details given an identifier for the work. Currently DOI, PMID, and ISBN are supported. To add autofill support to a template, set the "autofillid" param on a field that will be used for the ID code, for example {"field": "doi", "autofillid": "doi"}, The ID type should be given in lowercase. Then add "autofillprop" for the properties to be automatically filled, such as {"field": "title", "autofillprop": "title"},. The properties available vary depending on the ID. The table below shows the available properties for each ID. See the sample code below for a simplified example and MediaWiki:RefToolbarLocal.js for a full example as it is currently used here.

Property PMID DOI ISBN
title YesY YesY YesY
lastN/firstN YesY YesY YesY
authorN YesY YesY YesY
coauthors YesY YesY YesY
authors YesY YesY YesY
journal YesY YesY  
volume YesY YesY  
issue YesY YesY  
pages YesY YesY  
date YesY YesY  
year     YesY
publisher     YesY
location     YesY
edition     YesY

For multiple authors, the autofill system accepts several possible options and combinations of options. In order that the script checks for:

  1. lastN / firstN - Authors split by last name and first name, with 2 fields for each author. If there are more authors than fields, the rest will be put into coauthors.
  2. authorN - One field for each author. If there are more authors than fields, the rest will be put into coauthors.
  3. authors - All authors will be combined into 1 field.

Note that if lastN / firstN or authorN is used, coauthors should also be used in case there are more authors than available fields.

Sample code[සංස්කරණය]

$j('head').one('reftoolbarbase', function() {
new citeTemplate('cite example', 'Example',
[ // Basic fields
{"field": "last", "label":"Last name", "autofillprop":"last1"},
{"field": "first", "label":"First name", "autofillprop":"first1"}, 
{"field": "title", "autofillprop":"title"},
{"field": "url", "label":"URL"},
{"field": "work", "tooltip": "If this is part of a larger work"},
{"field": "isbn", "label":"ISBN", "autofillid":"isbn"},
{"field": "publisher", "autofillprop":"publisher"},
{"field": "accessdate"}
],
[ // Expanded fields
{"field": "author"},
{"field": "authorlink", "label":"Author's article", "tooltip":"If the author has an article, the name of the article"},
{"field": "coauthors", "autofillprop":"coauthors"},
{"field": "page"},
{"field": "pages"},
{"field": "language"},
{"field": "format"},
{"field": "date"},
]);
});

Error checking functions[සංස්කරණය]

Error checking functions can be added in a way similar to citation templates. The citeErrorCheck object requires one parameter, an object. This object should contain certain the information as described below. Currently all attributes are required. In the future, optional attributes may be added to support other features.

  • testname – A short name for the test, should be unique and should not contain spaces
  • desc – A description for the test
  • func – The function that will be called to execute the test (see below for details)
  • type – The type of test, see below for the options

There are currently 3 types of error checks. The differences between them are described below:

refcheck
The function given is passed each ref individually, it should return a single error object or not return.
reflist
The function is passed the entire list of references, it should return an array of error objects.
search
The function is passed the wikitext of the article, it should return an array of error objects.

An error object is a JavaScript object that should contain 2 attributes. The 'msg' attribute should be an error message describing the problem and the 'err' attribute should be a portion of the wikitext showing the error, such as the content of the reference with the problem.

Some example code for a simple function that checks whether each reference uses a template could be:

$j('head').one('reftoolbarbase', function() {
new citeErrorCheck({'type':'refcheck', 'testname':'notemplate', 'desc': "Check for references not using a template",
'func': function(ref) {
  if (!ref.shorttag && ref.content.search('{{') == -1) {
    return {'msg': "Does not use a <a href='http://en.wikipedia.org/wiki/Wikipedia:Citation_templates'>citation template</a>",
      'err': ref.content
    };
  }
}}
);
});

Porting to another wiki[සංස්කරණය]

This script is designed to be easily portable to other wikis that use a similar (template-based) reference system.

You should not need to copy the main script itself. You can, but it means that you will have to check for changes and manually update to receive bug fixes and new features. You do need to copy MediaWiki:RefToolbarLocal.js (you can also use the smaller sample configuration) to your wiki (this requires sysop access on the wiki the script is being ported to). Then you can customize the options, templates, error functions, and translate the messages as necessary.

Then, copy this script to MediaWiki:Gadget-refToolbar.js.

Create a corresponding MediaWiki:Gadget-refToolbar page, and add the following line to MediaWiki:Gadgets-definition:

* refToolbar|refToolbar.js

Note that the script has not yet been tested using RTL languages.

Information for developers[සංස්කරණය]

This section covers information relevant for developers that might not be covered above.

Descriptions of the citeTemplate and citeErrorCheck objects are described in detail in above sections.

The CiteTB object:

The CiteTB object is used to reduce the number of variables and functions put into the global scope. It contains all the functions and variables used by the script, except for the citeTemplate/citeErrorFunction object definitions. Most of this object is not loaded except on edit pages.

Reference objects:

Reference objects are created for each reference currently on the page, and whenever a reference is added by the script. Reference objects have several attributes:
  • refname – The 'name' attribute of the ref tag
  • refgroup – The 'group' attribute of the ref tag
  • content – The content inside of the ref tags
  • shorttag – true or false, whether the ref is a short tag with no content or a full reference tag

The script uses the jQuery library, which is well documented at http://docs.jquery.com. It also uses the WikiEditor code used by the UsabilityInitiative; this is partially documented at usability:Toolbar customization, but is mostly undocumented.

(Possible) future features[සංස්කරණය]

  • Automatic fixing of certain reference errors
  • Editing of existing references in-place
"https://si.wikipedia.org/w/index.php?title=විකිපීඩියා:RefToolbar_2.0&oldid=141459" වෙතින් සම්ප්‍රවේශනය කෙරිණි