User:Habst/generateMarks.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
window.params = [];
window.tids = [];
window.coreCss = [];
window.coreMarkTitles = [];
window.coreMarkLatIfs = [];
[...Array(250)].map((_, i) => i + 1).forEach(n => {
  const numAbbr = num => num <= 0 ? '' : numAbbr(Math.floor((num - 1) / 26)) + String.fromCharCode((num - 1) % 26 + 65);
  if (n === 1) params.push(`| mark-lat1 = {{#if:{{{mark-coord1|}}}{{{mark-coordinates1|}}}|{{#invoke:coordinates|coord2text|{{{mark-coord1|}}}{{{mark-coordinates1|}}}|lat}}|{{#if:{{{mark-coord|}}}{{{mark-coordinates|}}}|{{{mark-lat1|}}}|{{{mark-lat1|0.1}}}}}| }}
| mark-lon1 = {{#if:{{{mark-coord1|}}}{{{mark-coordinates1|}}}|{{#invoke:coordinates|coord2text|{{{mark-coord1|}}}{{{mark-coordinates1|}}}|long}}|{{#if:{{{mark-coord|}}}{{{mark-coordinates|}}}|{{{mark-lon1|}}}|{{{mark-lon1|0.1}}}}}| }}
| shape1 = {{if empty|{{#invoke:String2 |split |txt={{{shape1|{{{shapeD|}}} }}}| sep="-"|idx=2 }}|{{{shape1|}}}|{{{shapeD|}}}|image}}
| shape-color1 = #{{OSM Location map/color|{{{shape-color1|{{{shape-colorD|hard red}}} }}} |opacity={{{shape-opacity1|{{{shape-opacityD|}}} }}} }}
| shape-outline1 = {{if empty|{{{shape-outline1|{{{shape-outlineD|hard grey,0}}} }}}|hard grey,0}}
| shape-angle1 = {{if empty|{{{shape-angle1|}}}|{{{shape-angleD|}}}|0}}
| mark1 = {{if empty|{{{mark1|}}}|{{{markD|}}}|Red pog.svg}}
| mark-size1 = {{if empty|{{{mark-size1|}}}|{{{mark-sizeD|}}}|14}}
| mark-dim1 = {{{mark-dim1|{{{mark-dimD|}}} }}}
| label1 = {{{label1|}}}
| labela1 = {{{labela1|}}}
| labelb1 = {{{labelb1|}}}
| label-angle1 = {{if empty|{{{label-angle1|}}}|{{{label-angleD|}}}|0}}
| label-size1 = {{if empty|{{{label-size1|}}}|{{{label-sizeD|}}}|12}}
| label-color1 = #{{OSM Location map/color|{{{label-color1|{{{label-colorD|}}} }}} }}
| label-pos1 = {{if empty|{{{label-pos1|}}}|{{{label-posD|}}}|right}}
| ldx1 = {{if empty|{{{label-offset-x1|}}}|{{{ldx1|}}}|{{{label-offset-xD|}}}|{{{ldxD|}}}|0}}
| ldy1 = {{if empty|{{{label-offset-y1|}}}|{{{ldy1|}}}|{{{label-offset-yD|}}}|{{{ldyD|}}}|0}}
| jdx1={{{jdx1|0}}}
| numbered1 = {{if empty|{{{numbered1|}}}| {{#switch: {{#invoke:String2 |split |txt={{{shape1|{{{shapeD|}}} }}}| sep="-"|idx=1 }}
| n|N=1| l|L=A| 0}} |0}} <!-- either use a given mark-number, or allocate number or letter, or set to zero -->`);
  else params.push(`|     shape${n} = {{if empty|{{#invoke:String2 |split |txt={{{shape${n}|{{{shapeD|{{{shape1|}}} }}} }}}| sep="-"|idx=2 }}|{{{shape40|}}}|{{{shapeD|}}}|{{{shape1|}}}|image}}
|  mark-lat${n} = {{#if:{{{mark-coord${n}|}}}{{{mark-coordinates${n}|}}}|{{#invoke:coordinates|coord2text|{{{mark-coord${n}|}}}{{{mark-coordinates${n}|}}}|lat}}|{{{mark-lat${n}|}}}}}
|  mark-lon${n} = {{#if:{{{mark-coord${n}|}}}{{{mark-coordinates${n}|}}}|{{#invoke:coordinates|coord2text|{{{mark-coord${n}|}}}{{{mark-coordinates${n}|}}}|long}}|{{{mark-lon${n}|}}}}}
|   shape-color${n} = #{{OSM Location map/color|{{{shape-color${n}|{{{shape-colorD|{{{shape-color1|hard red}}} }}} }}} |opacity={{{shape-opacity${n}|{{{shape-opacityD|{{{shape-opacity1|0}}} }}} }}} }}
| shape-outline${n} =  {{{shape-outline${n}|{{{shape-outlineD|{{{shape-outline1|hard grey,0}}} }}} }}}
|   shape-angle${n} = {{if empty|{{{shape-angle${n}|}}}|{{{shape-angleD|}}}|{{{shape-angle1|}}}|0}}
|          mark${n} = {{{mark${n}|{{{markD|{{{mark1|Red pog.svg}}} }}} }}}
|     mark-size${n} = {{if empty|{{{mark-size${n}|}}}|{{{mark-sizeD|}}}|{{{mark-size1|}}}|14}}
|      mark-dim${n} =  {{if empty|{{{mark-dim${n}|}}}|{{{mark-dimD|}}}|{{{mark-dim1|}}}|1}}
|         label${n} =  {{{label${n}|}}}
|        labela${n} = {{{labela${n}|}}}
|        labelb${n} = {{{labelb${n}|}}}
|   label-angle${n} = {{if empty|{{{label-angle${n}|}}}|{{{label-angleD|}}}|{{{label-angle1|}}}|0}}
|    label-size${n} = {{if empty|{{{label-size${n}|}}}|{{{label-sizeD|}}}|{{{label-size1|}}}|12}}
|   label-color${n} = #{{OSM Location map/color|{{{label-color${n}|{{{label-colorD|{{{label-color1|}}} }}} }}} }}
|     label-pos${n} = {{if empty|{{{label-pos${n}|}}}|{{{label-posD|}}}|{{{label-pos1|}}}|right}}
|ldx${n} = {{if empty|{{{label-offset-x${n}|}}}|{{{ldx${n}|}}}|{{{label-offset-xD|}}}|{{{ldxD|}}}|{{{label-offset-x1|}}}|{{{ldx1|}}}|0}}
|ldy${n} = {{if empty|{{{label-offset-y${n}|}}}|{{{ldy${n}|}}}|{{{label-offset-yD|}}}|{{{ldyD|}}}|{{{label-offset-y1|}}}|{{{ldy1|}}}|0}}
|jdx${n} = {{{jdx${n}|0}}}
|      numbered${n} = {{if empty|{{{numbered${n}|}}}|{{#switch: {{#invoke:String2 |split |txt={{{shape${n}|{{{shapeD|{{{shape1|}}} }}} }}}| sep="-"|idx=1 }}
| n| N = ${n}| l| L = ${numAbbr(n)}| 0}} |0}}`);
  
  if (n === 1) tids.push(`| mark-title1 = <includeonly>{{{mark-title1|.}}}</includeonly><noinclude>[[Special:Random]]</noinclude>
| mark-image1 = {{{mark-image1|}}}
| mark-description1 = {{{mark-description1|}}}`);
  else tids.push(`| mark-title${n} = {{{mark-title${n}|}}}
| mark-image${n} = {{{mark-image${n}|}}}
| mark-description${n} = {{{mark-description${n}|}}}`);

  if (n === 1) coreCss.unshift(`{{#if:{{{mark-lat1|}}}| {{OSM Location map/cssmapping
| shape = {{{shape1|circle}}}
| x1 = {{OSM_Location_map/mapxy|x|lon={{{mark-lon1|2.00}}}| lat={{{mark-lat1|52.00}}}|lonbase={{{lon|2}}}|latbase={{{lat|52}}}|width={{{width|400}}}|height={{{height|300}}}|zoom={{{zoom|10}}} }}
| y1 = {{OSM_Location_map/mapxy|y|lon={{{mark-lon1|2.00}}}| lat={{{mark-lat1|52.00}}}|lonbase={{{lon|2}}}|latbase={{{lat|52}}}|width={{{width|400}}}|height={{{height|300}}}|zoom={{{zoom|10}}} }}
| shape-color={{{shape-color1|red}}}
| shape-outline=#{{OSM Location map/color|{{#invoke:String2 |split |{{{shape-outline1|hard grey}}}|sep=,|idx=1}}|opacity={{if empty|{{#invoke:String2 |split |{{{shape-outline1|hard grey}}}|sep=,|idx=3}}|100}} }}
| outline-width={{if empty|{{#invoke:String2 |split |{{{shape-outline1|}}}|sep=,|idx=2}}|1}}
| outline-style={{if empty|{{#invoke:String2 |split |{{{shape-outline1|}}}|sep=,|idx=4}}|solid}}
| shape-angle={{{shape-angle1|20}}}
|    mark-width={{if empty|{{#invoke:String2 |split |{{{mark-size1|12}}}|sep=,|idx=1}}|0}}  
| mark-height = {{if empty|{{#invoke:String2 |split |{{{mark-size1|}}}|sep=,|idx=2}}|{{#if:{{{mark-dim1|}}}|{{#expr:{{#invoke:String2 |split |{{{mark-size1|}}}|sep=,|idx=1}}/ {{{mark-dim1|}}} }} |}}|{{{mark-size1|}}}|10}}
| mark-corner = {{if empty|{{#invoke:String2 |split |{{{mark-size1|}}}|sep=,|idx=3}}|0}} 
| mark = {{{mark1|}}}
|  label ={{replace|{{{label1|}}}{{#if:{{{labela1|}}}|^{{{labela1|}}} }}{{#if:{{{labelb1|}}}|^{{{labelb1|}}} }}|^|<br>}}
| label-angle={{{label-angle1|}}}
| label-size = {{#invoke:String2 |split |txt={{{label-size1|}}}|sep=,}}
|     label-color=#{{OSM Location map/color|{{{label-color1|}}} }}
|     label-pos={{#invoke:String2 |split |txt={{{label-pos1|}}}|sep=,}}
| label-line={{#switch:{{#invoke:String2 |split |txt={{{label-pos1|}}}|sep=,|idx=2}} 
 | with-line= 1 
 | n-line=4 <!-- for line-next: in= line-pos,next-line,[width,style,double-gap]. Out= 2,width,style,1 or double-gap-->
 | mark-line = {{#invoke:String|join|,|2|{{ if empty| {{#invoke:String2 |split |txt={{{label-pos1|}}}|sep=,|idx=3}}|2}}|{{ if empty| {{#invoke:String2 |split |txt={{{label-pos1|}}}|sep=,|idx=4}}|solid}}|{{ if empty| {{#invoke:String2 |split |txt={{{label-pos1|}}}|sep=,|idx=5}}|1}} }}
 | photo-panel = 3!{{if empty|{{#invoke:String2 |split |txt={{{label-pos1|}}}|sep=,|idx=3}}|1.3}}!{{{mark-image1|0}}}!{{if empty|{{#invoke:String2 |split |txt={{{label-pos1|}}}|sep=,|idx=4}}|120}}!{{if empty|{{#invoke:String2 |split |txt={{{label-pos1|}}}|sep=,|idx=5}}|48}} |0}} <!--construct label-line for photo-panel= 3!image-width-dim!image-name!panel-width -->
| x2 = {{#if:{{{mark-lon2|}}}|{{OSM_Location_map/mapxy|x|lon={{{mark-lon2|}}}| lat={{{mark-lat2|1}}}|lonbase={{{lon|2}}}|latbase={{{lat|2}}}|width={{{width|400}}}|height={{{height|300}}}|zoom={{{zoom|10}}} }} |0}}
| y2 = {{#if:{{{mark-lon2|}}}|{{OSM_Location_map/mapxy|y|lon={{{mark-lon2|}}}| lat={{{mark-lat2|1}}}|lonbase={{{lon|2}}}|latbase={{{lat|2}}}|width={{{width|400}}}|height={{{height|300}}}|zoom={{{zoom|10}}} }} |0}}
| ldx={{{ldx1|}}}
| ldy={{{ldy1|}}} 
| jdx={{{jdx1|0}}}
| mark-title={{{mark-title1|}}}
| numbered={{{numbered1|0}}} }}
}}`);
  else coreCss.unshift(`}}{{#if:{{{mark-lat${n}|}}}| {{OSM Location map/cssmapping
| shape = {{{shape${n}|circle}}}
| x1 = {{OSM_Location_map/mapxy|x|lon={{{mark-lon${n}|}}}| lat={{{mark-lat${n}|}}}|lonbase={{{lon|2}}}|latbase={{{lat|52}}}|width={{{width|400}}}|height={{{height|300}}}|zoom={{{zoom|10}}} }}
| y1 = {{OSM_Location_map/mapxy|y|lon={{{mark-lon${n}|}}}| lat={{{mark-lat${n}|}}}|lonbase={{{lon|2}}}|latbase={{{lat|52}}}|width={{{width|400}}}|height={{{height|300}}}|zoom={{{zoom|10}}} }}
| shape-color={{{shape-color${n}|red}}}
| shape-outline=#{{OSM Location map/color|{{#invoke:String2 |split |{{{shape-outline${n}|hard grey}}}|sep=,|idx=1}}|opacity={{if empty|{{#invoke:String2 |split |{{{shape-outline${n}|hard grey}}}|sep=,|idx=3}}|100}} }}
| outline-width={{if empty|{{#invoke:String2 |split |{{{shape-outline${n}|}}}|sep=,|idx=2}}|1}}
| outline-style={{if empty|{{#invoke:String2 |split |{{{shape-outline${n}|}}}|sep=,|idx=4}}|solid}}
| shape-angle={{{shape-angle${n}|20}}}
|    mark-width={{if empty|{{#invoke:String2 |split |{{{mark-size${n}|30}}}|sep=,|idx=1}}|0}}
| mark-height = {{if empty|{{#invoke:String2 |split |{{{mark-size${n}|}}}|sep=,|idx=2}}|{{#if:{{{mark-dim${n}|}}}|{{#expr:{{#invoke:String2 |split |{{{mark-size${n}|}}}|sep=,|idx=1}}/ {{{mark-dim${n}|}}} }} |}}|{{{mark-size${n}|}}}|10}}
| mark-corner = {{if empty|{{#invoke:String2 |split |{{{mark-size${n}|}}}|sep=,|idx=3}}|0}} 
| mark = {{{mark${n}|}}}
|  label ={{replace|{{{label${n}|}}}{{#if:{{{labela${n}|}}}|^{{{labela${n}|}}} }}{{#if:{{{labelb${n}|}}}|^{{{labelb${n}|}}} }}|^|<br>}}
| label-angle={{{label-angle${n}|}}}
| label-size = {{#invoke:String2 |split |txt={{{label-size${n}|}}}|sep=,}}
|     label-color=#{{OSM Location map/color|{{{label-color${n}|}}} }}
|     label-pos={{#invoke:String2 |split |txt={{{label-pos${n}|}}}|sep=,}}
| label-line={{#switch:{{#invoke:String2 |split |txt={{{label-pos${n}|}}}|sep=,|idx=2}} 
 |with-line= 1 
 |n-line=4 
 |mark-line = {{#invoke:String|join|,|2|{{ if empty| {{#invoke:String2 |split |txt={{{label-pos${n}|}}}|sep=,|idx=3}}|2}}|{{ if empty| {{#invoke:String2 |split |txt={{{label-pos${n}|}}}|sep=,|idx=4}}|solid}}|{{ if empty| {{#invoke:String2 |split |txt={{{label-pos${n}|}}}|sep=,|idx=5}}|1}} }}
 |photo-panel = 3!{{if empty|{{#invoke:String2 |split |txt={{{label-pos${n}|}}}|sep=,|idx=3}}|1.3}}!{{{mark-image${n}|0}}}!{{if empty|{{#invoke:String2 |split |txt={{{label-pos${n}|}}}|sep=,|idx=4}}|120}}!{{if empty|{{#invoke:String2 |split |txt={{{label-pos${n}|}}}|sep=,|idx=5}}|48}} |0}}
| x2 = {{#if:{{{mark-lon${n-1}|}}}|{{OSM_Location_map/mapxy|x|lon={{{mark-lon${n-1}|2}}}| lat={{{mark-lat${n-1}|52.00}}}|lonbase={{{lon|2}}}|latbase={{{lat|52}}}|width={{{width|400}}}|height={{{height|300}}}|zoom={{{zoom|10}}} }} |0}}
| y2 = {{#if:{{{mark-lon${n-1}|}}}|{{OSM_Location_map/mapxy|y|lon={{{mark-lon${n-1}|2.00}}}| lat={{{mark-lat${n-1}|52.00}}}|lonbase={{{lon|2}}}|latbase={{{lat|52}}}|width={{{width|400}}}|height={{{height|300}}}|zoom={{{zoom|10}}} }} |0}}
| ldx={{{ldx${n}|}}}
| ldy={{{ldy${n}|}}} 
| jdx={{{jdx${n}|0}}}
| mark-title={{{mark-title${n}|}}}
| numbered={{{numbered${n}|0}}} }}
}}`);
  
  if (n === 1) coreMarkTitles.push(`{{#ifeq:{{{mark-title1|}}}|none|
{{#ifeq:{{{mark-title|}}}|none| {{OSM Location map/MaplinkItem|89|0|dummy value|mark-color=#B80000 }} }} <!-- ensure a first value is sent -->
|{{#if:{{{mark-lat1|}}}|{{#ifeq:{{{mark-title|}}}|none|| {{#if:{{{mark-lat|}}}|,}} }} {{OSM Location map/MaplinkItem|{{{mark-lat1|0}}}|{{{mark-lon1|0}}}|{{{mark-title1|}}}|mark-image={{{mark-image1|}}}|mark-color={{{shape-color1|#B80000}}}|mark-description={{{mark-description1|}}}|group=F{{{lat|}}}{{{lon|}}}{{{mark-lat|}}}{{{mark-lat1|}}} }} }} }}`);
  else coreMarkTitles.push(`{{#ifeq:{{{mark-title${n}|}}}|none||{{#if:{{{mark-lat${n}|}}}|, {{OSM Location map/MaplinkItem|{{{mark-lat${n}|0}}}|{{{mark-lon${n}|0}}}|{{{mark-title${n}|}}}|mark-image={{{mark-image${n}|}}}|mark-color={{{shape-color${n}|#B80000}}}|mark-description={{{mark-description${n}|}}} |group=F{{{lat|}}}{{{lon|}}}{{{mark-lat|}}}{{{mark-lat1|}}} }} }} }}`);

  coreMarkLatIfs.push(`{{#if:{{{mark-lat${n}|}}}|{{#ifexpr:{{#ifeq:{{{numbered${n}|}}}|0|1|0}} or {{#ifeq: {{{mark-title${n}|none}}}|none|1|0}}||{{OSM Location map/coltxt|{{{numbered${n}}}}|{{{shape-color${n}|red}}} }} {{{mark-title${n}|}}} }} }}`);
});

console.log(params.join('\n\n'));
console.log(tids.join('\n'));
console.log(coreCss.join('\n'));
console.log(coreMarkTitles.join('\n\n'));
console.log(coreMarkLatIfs.join(''));