wikimedia-gadgets / Edit-Request-Wizard

This project aims at developing a Wikipedia user script that shows a form for submitting a Wikipedia edit request, with high-quality guidance and error messages, suitable for use by beginners.
MIT License
6 stars 7 forks source link

Include formatted reference in edit request #5

Closed enterprisey closed 2 years ago

enterprisey commented 2 years ago

replace "Rephrased Quote" with "Text to Add", followed by wikitext (including a properly formatted ref tag - use citoid) in a <code>, then the same wikitext directly included, so that it gets rendered

Ankit-Gupta18 commented 2 years ago

@enterprisey Can you please elaborate on the implementation of the second part?

Ankit-Gupta18 commented 2 years ago

image What to replace the place holder?

enterprisey commented 2 years ago

yeah

so first we convert the citoid results to a tag, which is a pain in the butt

  1. take the result you got from citoid, which looks like this: [ { "key": "75UNBXXE", "version": 0, "itemType": "webpage", "url": "http://www.google.com/", "title": "Google", "abstractNote": "Search the world's information, including webpages, images, videos and more. Google has many special features t o help you find exactly what you're looking for.", "accessDate": "2022-07-30", " websiteTitle": "www.google.com", "source": [ "Zotero" ] } ]
  2. fetch https://en.wikipedia.org/w/api.php?action=templatedata&titles=Template:Cite%20web&format=json and look at the pages['1252907'].maps.citoid value. it translates citoid's field names, like websiteTitle, to wikipedia field names, like website.
  3. use the map to translate the object from citoid. throw out fields that don't map to anything: { "url": "http://www.google.com/", "title": "Google", "access-date": "2022-07-30", " website": "www.google.com", }
  4. turn the object into a ref tag: <ref>{{Cite web |title=Google |url=http://www.google.com/ |access-date=2022-07-30 |website=www.google.com}}</ref>

so, if the website is google.com and the fact is asdf, then the wikitext should be as follows:

Text to Add: <syntaxhighlight lang='html'>asdf<ref>{{Cite web |title=Google |url=http://www.google.com/ |access-date=2022-07-30 |website=www.google.com}}</ref></syntaxhighlight>

Rendered: asdf<ref>{{Cite web |title=Google |url=http://www.google.com/ |access-date=2022-07-30 |website=www.google.com}}</ref>
{{reflist-talk}}

Here's how it would look on a wikipedia page: https://en.wikipedia.org/w/index.php?title=User:Enterprisey/sandbox2&oldid=1101384135

enterprisey commented 2 years ago

the placeholder is fine for now

Ankit-Gupta18 commented 2 years ago

yeah

so first we convert the citoid results to a tag, which is a pain in the butt

  1. take the result you got from citoid, which looks like this: [ { "key": "75UNBXXE", "version": 0, "itemType": "webpage", "url": "http://www.google.com/", "title": "Google", "abstractNote": "Search the world's information, including webpages, images, videos and more. Google has many special features t o help you find exactly what you're looking for.", "accessDate": "2022-07-30", " websiteTitle": "www.google.com", "source": [ "Zotero" ] } ]
  2. fetch https://en.wikipedia.org/w/api.php?action=templatedata&titles=Template:Cite%20web&format=json and look at the pages['1252907'].maps.citoid value. it translates citoid's field names, like websiteTitle, to wikipedia field names, like website.
  3. use the map to translate the object from citoid. throw out fields that don't map to anything: { "url": "http://www.google.com/", "title": "Google", "access-date": "2022-07-30", " website": "www.google.com", }
  4. turn the object into a ref tag: <ref>{{Cite web |title=Google |url=http://www.google.com/ |access-date=2022-07-30 |website=www.google.com}}</ref>

so, if the website is google.com and the fact is asdf, then the wikitext should be as follows:

Text to Add: <syntaxhighlight lang='html'>asdf<ref>{{Cite web |title=Google |url=http://www.google.com/ |access-date=2022-07-30 |website=www.google.com}}</ref></syntaxhighlight>

Rendered: asdf<ref>{{Cite web |title=Google |url=http://www.google.com/ |access-date=2022-07-30 |website=www.google.com}}</ref>
{{reflist-talk}}

Here's how it would look on a wikipedia page: https://en.wikipedia.org/w/index.php?title=User:Enterprisey/sandbox2&oldid=1101384135

We have to do this in the backend or frontend?

enterprisey commented 2 years ago

You can do either, whichever one is easier. I suspect the frontend might be a bit easier.