Why does this script exist?
editPages transcluding templates called with duplicate arguments are listed in Category:Pages using duplicate arguments in template calls. Examples of duplicate arguments are {{Foo|name=Bob|birth_date=Today|name=Jack}}
or {{Foo|Bob|Today|1=Jack}}
This script assists editors with finding the duplicate arguments within a particular page.
How to install
edit- Open your common.js script page in edit mode.
- Paste the following line:
importScript('User:Frietjes/findargdups.js'); // [[User:Frietjes/findargdups]]
- Reload the script page (press
ctrl+R
or the equivalent for your browser).
To install on another Wikipedia, use
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Frietjes/findargdups.js&action=raw&ctype=text/javascript');
How to use
edit- Find a page with duplicate arguments in Category:Pages using duplicate arguments in template calls.
- Open the page in edit mode, and press "Show preview" without making any changes.
- Look for the following message at the top of the page: Warning: $1 (edit) is calling $2 with more than one value for the "$3" parameter. Only the last value provided will be used. (Help)
- If the above warning does not appear at all, then the problem has already been fixed. Save the page without making any edits to force the server to re-process the page to remove it from the category.
- If the text in place of "$1" in the above warning is a link to a template, then the problem lies in that template. Open that template in edit mode and continue with the next step.
- If the text in place of "$1" in the above warning is a self-link (i.e., the page's own name in bold), then continue with the next step.
- Select the
Find dups
link in theTools
section on the left side of the page. - If duplicate template arguments were found by the script, you will see an alert popup telling you where to look.
- Fix the problem, and save the page. The script will create an edit summary for you.
Caveats
editIf the warning message appears for the page you are currently editing, but the script fails to provide a popup, then you have encountered a case not considered by the script's author, or a bug, and you should report this on the talk page so it can be fixed (or a reason can be given for not fixing it).
Technical details
editFor editors interested in better understanding how the script works, the following is a general overview of how it works. The script does the following:
- Copies the contents of the edit window to a local string (
mytxt
) - Removes triple brace enclosed template variables, like
{{{foo|}}}
. - Replaces braces not preceded or followed by a brace with the HTML equivalent.
- Replaces all carriage returns and newlines and tabs with spaces, and replace duplicate spaces with a single space.
- Splits
mytxt
into an array of strings where the split points are any double braces. - Loops through the array of strings, pulling out unnested templates and pushing them into an array of strings called
tlist
. This step is performed repeatedly (up to 10 times) to try to unnest all the templates on the page. - Loops through the list of unnested templates (
tlist
)- Inserts equivalent numeric arguments for any unnamed arguments for each template in
tlist
. - Sorts the template arguments
- Issues an alert popup for any duplicate arguments
- Inserts equivalent numeric arguments for any unnamed arguments for each template in
- If any duplicates were found, changes the edit summary to a useful default.
Changing the default edit summary
editTo change the default edit summary, define findargdupseditsummary
in your common.js script page before the script is imported. For example,
findargdupseditsummary = 'Remove from [[:Category:Pages using duplicate arguments in template calls]]';
importScript('User:Frietjes/findargdups.js'); // [[User:Frietjes/findargdups]]
To disable this feature, use an empty string (findargdupseditsummary = '';
).
Adding an additional results box
editOn some browsers, like Google Chrome, the text in the alert box cannot be copied/selected for searching. To add an additional results box with selectable text, define findargdupsresultsbox
in your common.js script page before the script is imported. For example,
findargdupsresultsbox = 'yes';
importScript('User:Frietjes/findargdups.js'); // [[User:Frietjes/findargdups]]
Bubble notification when no duplicates are found
editBy default, the script issues a bubble notification when no duplicates are found. If you would like to change this message, define findargdupsnonefound
in your common.js script page before the script is imported. For example,
findargdupsnonefound = 'No dupes!';
importScript('User:Frietjes/findargdups.js'); // [[User:Frietjes/findargdups]]
To disable this message, define findargdupsnonefound
to be an empty string (findargdupsnonefound = '';
)
Translating messages and link text
editTo change the default messages and link text, define findargdupseditsummary
, findargdupslinktext
, findargdupsmorefound
, and findargdupsnonefound
in your common.js script page before the script is imported. For example, for French,
findargdupslinktext = 'Arguments dupliqués';
findargdupsmoretext = 'Il existe d\'autres arguments dupliqués, corrigez en quelques-uns et exécutez à nouveau !';
findargdupseditsummary = 'Nettoyage des [[:Catégorie:Page utilisant des arguments dupliqués dans les appels de modèle|arguments dupliqués dans les appels de modèle]] avec [[:en:User:Frietjes/findargdups|findargdups]]';
findargdupsnonefound = 'Aucun doublon n\'a été trouvé !';
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Frietjes/findargdups.js&action=raw&ctype=text/javascript');
or for Latvian
findargdupslinktext = 'Atrast dublikātus';
findargdupsmoretext = 'Atrasti vēl vairāki dublikāti, salabo dažus un palaid vēlreiz!';
findargdupseditsummary = 'Izlaboti [[:Kategorija:Lapas ar vairākiem viena argumenta izsaukumiem veidnēs|argumenti]], izmantojot [[:en:User:Frietjes/findargdups|findargdups]]';
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Frietjes/findargdups.js&action=raw&ctype=text/javascript');