User:Trappist the monk/MOSNUM dates.js test
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 [https://en.wikipedia.org/wiki/Special:ComparePages?page1=User%3AOhconfucius%2Fscript%2FMOSNUM+dates.js&page2=User%3ATrappist+the+monk%2Fscript%2FMOSNUM+dates.js 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 {{tlx|use dmy dates}} and {{tlx|use mdy dates}} templates (and their aliases) with a new template that specifies date format and has the current month and year in {{para|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 {{tld|use xxx dates}} accept another parameter {{para|cs1-dates}}. To use this new parameter, User:Ohconfucius/script/MOSNUM dates.js must be tweaked so that it does not discard {{para|cs1-dates}}.
The new code does this:
- normalizes the use dates template name to the canonical form: of
Use xxx dates
wherexxx
is the text stringdmy
ormdy
from the function argumentformat
and where the name is stripped of leading and trailing whitespace - searches the wikitext for
where{{Use xxx dates xxx
is either of the stringsdmy
ormdy
- :when found (because the template name was normalized in step 1) continues to step 3
- :when not found, adds a new {{tld|Use xxx dates|date{{=}}Month year}} to the top of wikitext where
xxx
is the text stringdmy
ormdy
from the function argumentformat
andMonth year
is the current date's month and year; function exits - replaces value assigned to {{para|date}}; reorders parameters to {{para|date}}{{para|cs1-dates}} order when both are present; inserts {{para|date}} if missing; {{para|cs1-dates}} and assigned value retain as is; function exits.
To install User:Trappist the monk/script/MOSNUM dates.js do these things:
- open [{{fullurl:Special:MyPage/common.js|action=edit}} your common.js in edit mode]
- add: {{#tag:syntaxhighlight|importScript('User:Trappist the monk/script/MOSNUM dates.js'); // User:Trappist the monk/script/MOSNUM dates.js|lang=javascript}}
- save and refresh
The testable bits of this page are invisible. To test User:Trappist the monk/script/MOSNUM dates.js:
- 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)
- from the left panel under tools click 'ALL dates to dmy' (or one of the other appropriate links – see script documentation)
- 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 {{tld|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 {{tld|use xxx dates}} after a test should all be {{CURRENTMONTHNAME}} {{CURRENTYEAR}}
To test the script's ability to insert a new {{tld|use xxx dates}} template when there are none
- edit a page that doesn't (my talk page will work)
- from the left panel under tools click 'ALL dates to dmy' (or one of the other appropriate links – see script documentation)
- inspect the diff; comments in the source explain what you should be seeing
Again no need to save; if you do, please revert.
{{ dmy }}
{{dmy}}
{{ mdy }}
{{mdy}}
{{ use dmy }}
{{use dmy}}
{{ use mdy }}
{{use mdy}}
{{ usedmy }}
{{usedmy}}
{{ usemdy }}
{{usemdy}}
{{ use dmy dates }}
{{use dmy dates}}
{{ use mdy dates }}
{{use mdy dates}}
{{ usedmydates }}
{{usedmydates}}
{{ usemdydates }}
{{usemdydates}}
{{ use dmy dates }}
{{use dmy dates}}
{{ use dmy dates | date = January 2017 }}
{{use dmy dates|date=January 2017}}
{{ use dmy dates | date = January 2017 | cs1-dates = ls }}
{{use dmy dates|date=January 2017|cs1-dates=ls}}
{{ use dmy dates | cs1-dates = ls | date = January 2017 }}
{{use dmy dates|cs1-dates=ls|date=January 2017}}
{{ use dmy dates | cs1-dates = ls }}
{{use dmy dates|cs1-dates=ls}}
{{use dmy dates|date=}}
{{use dmy dates|date=|cs1-dates=ls}}
{{use dmy dates|cs1-dates=ls|date=}}
{{use dmy dates|cs1-dates=}}
{{use dmy dates|date=January 2017|cs1-dates=}}
{{use dmy dates|cs1-dates= |date=January 2017}}
{{use dmy dates |unrecognized_param = something that we don't recognize}}