User:Shahadat/findargdups

From Justapedia, unleashing the power of collective wisdom
Jump to navigation Jump to search

Why does this script exist?

Pages 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

  1. Open your common.js script page in edit mode.
  2. Paste the following line:
    importScript('User:Shahadat/findargdups.js'); // [[User:Shahadat/findargdups]]
    
  3. Reload the script page (press ctrl+R or the equivalent for your browser).

To install on another Justapedia, use

mw.loader.load('//justapedia.org/w/index.php?title=User:Shahadat/findargdups.js&action=raw&ctype=text/javascript');

How to use

  1. Find a page with duplicate arguments in Category:Pages using duplicate arguments in template calls.
  2. Open the page in edit mode, and press "Show preview" without making any changes.
  3. 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.
  4. Select the Find dups link in the Tools section on the left side of the page.
  5. If duplicate template arguments were found by the script, you will see an alert popup telling you where to look.
  6. Fix the problem, and save the page. The script will create an edit summary for you.

Caveats

If 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

For editors interested in better understanding how the script works, the following is a general overview of how it works. The script does the following:

  1. Copies the contents of the edit window to a local string (mytxt)
  2. Removes triple brace enclosed template variables, like {{{foo|}}}.
  3. Replaces braces not preceded or followed by a brace with the HTML equivalent.
  4. Replaces all carriage returns and newlines and tabs with spaces, and replace duplicate spaces with a single space.
  5. Splits mytxt into an array of strings where the split points are any double braces.
  6. 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.
  7. Loops through the list of unnested templates (tlist)
    1. Inserts equivalent numeric arguments for any unnamed arguments for each template in tlist.
    2. Sorts the template arguments
    3. Issues an alert popup for any duplicate arguments
  8. If any duplicates were found, changes the edit summary to a useful default.

Changing the default edit summary

To 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:Shahadat/findargdups.js'); // [[User:Shahadat/findargdups]]

To disable this feature, use an empty string (findargdupseditsummary = '';).

Adding an additional results box

On 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:Shahadat/findargdups.js'); // [[User:Shahadat/findargdups]]

Bubble notification when no duplicates are found

By 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:Shahadat/findargdups.js'); // [[User:Shahadat/findargdups]]

To disable this message, define findargdupsnonefound to be an empty string (findargdupsnonefound = '';)

Translating messages and link text

To 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:Shahadat/findargdups|findargdups]]';
findargdupsnonefound = 'Aucun doublon n\'a été trouvé !';
mw.loader.load('//justapedia.org/w/index.php?title=User:Shahadat/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:Shahadat/findargdups|findargdups]]';
mw.loader.load('//justapedia.org/w/index.php?title=User:Shahadat/findargdups.js&action=raw&ctype=text/javascript');

Script Attribution