User:Kaniivel/Reference Organizer
Reference Organizer | |
---|---|
Description | Reference Organizer displays all article's references in graphical user interface, where you can choose whether the references should be defined in the body of article or in the reference list template (list-defined format). You can also sort the references in various ways (optionally keeping the sort order), and rename the references. |
Author(s) | Kaniivel |
Status | No known bugs, stay tuned for new options and even better functionality |
Updated | May 7, 2017 |
Source | User:Kaniivel/RefConsolidate_start.js, User:Kaniivel/RefConsolidate.js |
GitHub repository | refcon |
Reference Organizer is a Wikipedia user script that allows organizing references according to user preferences.
The script parses the article for references, it detects and stacks identical and duplicate references. The result is then presented in graphical user interface (GUI). You can choose which references should be defined in the body of article and which ones in the reference list template ({{reflist}}) – all, none, based on reference citation count, or by ticking the references individually. You can also sort the references in various ways (and optionally keep the sort order in the reference list template) and rename the references. In the next step you are presented with the "Show changes" view, and you can choose whether to save the changes made by the script.
When installed, this tool can be accessed from the "More" menu.
Please refer to the Help:List-defined references page for a description of reference list markup, as opposed to references being defined in the body of article.
Reference Organizer's code is partially based on Wikipedia gadget ProveIt.
To use this script: Copy the text below, then click here, paste the line, and hit the Publish changes button.
importScript( 'User:Kaniivel/RefConsolidate_start.js' );
How to run the script
[edit]Once you have copied the line above into your common.js file and saved it, you will see link "Organize refs" under the menu "More" in article and user namespaces. Clicking on the link executes the script.
How to use the script's graphical interface
[edit]Please refer to the numbers on the right hand side image:
- Use the titlebar to grab the window and move it around. You can also move the window behind the screen's edge.
- Use cross sign to exit the window without changing anything.
- Grab from the lower right corner of the window to pull it larger (or smaller, depending on the web browser you use).
- The Abort button does the same thing as the cross sign: closes the window without changing anything.
- Push the Continue button when you are done to continue into the Show Changes view.
- Clicking on the headers sorts references according to the clicked header. The first click sorts in ascending order, the second click in descending order.
- The green check sign () before a reference line indicates that there are no problems with the reference name – it's not empty, does not contain illegal characters (", <, >), and is unique. The red cross sign () indicates problems with the reference name. If there are any red cross signs, the Continue button is disabled, and you can only move forward once you have corrected the erroneous reference names.
- The number in the second column shows the order in which the references were parsed into the window. The actual order of the references in the article may differ.
- You can use the name column to rename the references. The references that had no name at the time of parsing the article are assigned random five-character names.
- The Reference column contains the reference content string. This is the text between
<ref>...</ref>
tags. - The Uses column shows how many citations the reference has in the article. If it is zero, it means that the reference is defined in the reference list template, but does not have any (detected) citations.
- Checkbox at the end of each reference line indicates the place where the reference is defined. If it is checked, it means that the reference is defined inside the reference list template(s). If it empty, it means the reference is defined inside the article body. You can tick the checkboxes to individually select the references locations.
- Or you can use the "References location" options at the bottom of the window to assign the locations for all references/all references with a certain number of citations.
- The option group "Other choices" contains the following options:
- Ticking the first checkbox tells the script to use the current sort order for the references inside the reference list template(s).
- Ticking the second checkbox tells the script to keep reference names even when they are not needed (e.g. the reference is defined in the body of article and used only once; or the article body defined reference code is duplicated for every reference).
- Ticking the third checkbox tells the script to save all article body defined references as duplicate copies. This option is useful when you want to take a subsection of the article and start a new article with it. It is suggested to use this with the second option; after you have copied all text with references into the new article, you can run Reference Organizer on the new article, to deduplicate the references or move the references into the reference list template(s) there.
Prerequisites for running the script
[edit]- The script is looking for template {{reflist}} in article text to determine where to read references from and where to put references list. It does not look for
<references />
tag. If references list in article is given with<references />
tag then you have the option to change it with {{reflist}} before running the script. - The script looks for
<ref>...</ref>
tags to read in references. It does not process{{#tag:ref...}}
tags. If both forms of the references tag are present in the same article, the script will most likely not work correctly. - If there is no {{reflist}} tag in article, then you should add it before running the script. Otherwise the script will not work.
Functionality
[edit]- The script supports multiple {{reflist}} tags in article. For example one after infobox and another one at the end of the article.
- The script supports reference groups (parameter
|group=
of the template {{reflist}}, parametergroup=
inside<ref>...</ref>
tag). - The script supports reference names with whitespace or with apostrophes (').
- The script tries to find and eliminate duplicate references:
- If the reference name and content are both duplicates, it keeps just one copy of the reference.
- If there are two or more references with the same name but different content, it keeps one reference with the original name and renames the other references. New names consist of old name + underscore + randomly generated namepart.
- If there are two or more references with the same content but different names, it keeps one reference and eliminates the other ones (citations are renamed to use the existing reference).
- Nameless references with the exact same content are consolidated under single name. If content of a nameless reference already exists under a named reference, the named reference's name will be used for creating a citation.
- The script keeps user given reference names.
- The script keeps all references with unique content, even if they are not used in article.
- If a reference does not have a name, the script gives it a randomly generated name of five characters.
- The script cleans reference content and names of multiple whitespace and newline characters, it trims leading/trailing whitespace.
- The script keeps all parameters of template {{reflist}}.
- The script's code is written with portability to other wikis in mind:
- All wiki-specific data (e.g. template {{reflist}} name and its parameters names) is kept in separate configuration file.
- It allows to set multiple aliases for template {{reflist}} and its parameters. For example if the wiki in question has both {{reflist}} and some other reflist template names that are pointing to the same template.
Checking the script's output
[edit]The script only works correctly if there are no errors in the references wikitext in an article. If there are errors, the script could detect references incorrectly, which can in turn cause all sorts of problems: missing references, garbled text, multiple references made into one reference, etc. Typical reference errors that cause the script to misbehave include:
- Unclosed
<ref>...</ref>
tag - Unpaired single or double quotes inside
<ref>...</ref>
tag parameter string (e.g.<ref name="name>
) - Redundant double braces (
}}
) inside reflist template'srefs=
parameter - ...
Article text that contains references that are enclosed between HTML comments (<!-- -->
) causes "not used in the content" cite error – because the script detects commented out references and moves them into reflist template along with all other references, where they are in the open (not commented out), while their citations remain commented out.
It is therefore important that the script user checks if everything is alright with references before saving the article.
Sometimes it is easy to notice errors: you will see red cite errors or garbled text. In other cases everything looks nominal and you would see errors only if you would examine the references code up close. One sign of a potential problem with references could be reference names that contain underscores. This means the script detected (either true or false) duplicate reference names and renamed them.
Errors can be also caused by unexpected character sequences inside reference code that the script is unable to handle. Please let the script developer know if you happen to encounter any such errors.
User options
[edit]If you want to output citations in the template {{R}} format – for example, instead of the code <ref name="refname" />
you'd get shorter {{r|refname}}
– add the following lines into your common.js file (or any other skin-specific .js file):
if ( typeof( refConsolidateConfig ) === 'undefined' ) refConsolidateConfig = {};
refConsolidateConfig.usetemplateR = true;
For now it is not recommended to use the option! The script does not parse citations that are in the template {{R}} format. Once the citations are output into the template {{R}} format, they are no longer detectable, and the script stops working correctly with the article.
Using the script in other wikis
[edit]To use the script in other wikis, copy the file RefConsolidate_start.js and make adjustments according to the comments in the code.
After that you can call the file from your common.js. For example, if the file was saved under filename User:SomeUser/RefConsolidate_start.js
(as here), you would put the following line into your User:SomeUser/common.js
:
importScript( 'User:Kaniivel/RefConsolidate_start.js' );
Code repository
[edit]The script has a code repository in GitHub: https://github.com/Cumbril/refcon. Contributions are welcome!