Jump to content

User:Trappist the monk/MOSNUM dates.js test

From Wikipedia, the free encyclopedia

This is a test and demonstration page intended to check changes made to User:Trappist the monk/script/MOSNUM dates.js in support of auto date formatting; see Help talk:Citation Style 1#auto date formatting. Diff between User:Ohconfucius/script/MOSNUM dates.js script and this new version is here. These changes being acceptable, and auto date formatting provided by Module:Citation/CS1 and subsidiary modules, the changes implemented in User:Trappist the monk/script/MOSNUM dates.js need to be migrated to User:Ohconfucius/script/MOSNUM dates.js.

The current version of User:Ohconfucius/script/MOSNUM dates.js overwrites any existing {{use dmy dates}} and {{use mdy dates}} templates (and their aliases) with a new template that specifies date format and has the current month and year in |date=. Any other parameters are discarded. Because the cs1|2 modules need to know details more fine-grained than dmy or mdy, it is proposed that the {{use xxx dates}} accept another parameter |cs1-dates=. To use this new parameter, User:Ohconfucius/script/MOSNUM dates.js must be tweaked so that it does not discard |cs1-dates=.

The new code does this:

  1. normalizes the use dates template name to the canonical form: of Use xxx dates where xxx is the text string dmy or mdy from the function argument format and where the name is stripped of leading and trailing whitespace
  2. searches the wikitext for {{Use xxx dates where xxx is either of the strings dmy or mdy
    when found (because the template name was normalized in step 1) continues to step 3
    when not found, adds a new {{Use xxx dates|date=Month year}} to the top of wikitext where xxx is the text string dmy or mdy from the function argument format and Month year is the current date's month and year; function exits
  3. replaces value assigned to |date=; reorders parameters to |date=|cs1-dates= order when both are present; inserts |date= if missing; |cs1-dates= and assigned value retain as is; function exits.

To install User:Trappist the monk/script/MOSNUM dates.js do these things:

  1. open your common.js in edit mode
  2. add:
    importScript('User:Trappist the monk/script/MOSNUM dates.js'); // [[User:Trappist the monk/script/MOSNUM dates.js]]
    
  3. save and refresh

The testable bits of this page are invisible. To test User:Trappist the monk/script/MOSNUM dates.js:

  1. open this page in source edit mode (I don't know if this (or the original) script works with ve because I don't use ve)
  2. from the left panel under tools click 'ALL dates to dmy' (or one of the other appropriate links – see script documentation)
  3. inspect the diff; comments in the source explain what you should be seeing

No need to save the results; if you do, please revert.

This code change only modifies that part of the original script that handles the {{use xxx dates}} templates (or their redirects). The changes are confined to function ohc_use_dates_template().

All dates in this test page are January 2017 so new dates in the {{use xxx dates}} after a test should all be November 2024

To test the script's ability to insert a new {{use xxx dates}} template when there are none

  1. edit a page that doesn't (my talk page will work)
  2. from the left panel under tools click 'ALL dates to dmy' (or one of the other appropriate links – see script documentation)
  3. inspect the diff; comments in the source explain what you should be seeing

Again no need to save; if you do, please revert.